aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
authorMateusz Guzik <mjguzik@gmail.com>2025-10-01 03:00:10 +0200
committerChristian Brauner <brauner@kernel.org>2025-10-20 20:22:25 +0200
commitbe97a4b63ca8c3ed8f5c3f5606a15a8379c78afb (patch)
tree100d145c595885eac56d969ad9555faa2473e81f /fs/inode.c
parentdc816f8d925cac34922ea73abd94ae23a96cacac (diff)
downloadrandom-be97a4b63ca8c3ed8f5c3f5606a15a8379c78afb.tar.gz
fs: assert on ->i_count in iput_final()
Notably make sure the count is 0 after the return from ->drop_inode(), provided we are going to drop. Inspired by suspicious games played by f2fs. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/inode.c b/fs/inode.c
index ec9339024ac36e..fa82cb810af440 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1879,6 +1879,7 @@ static void iput_final(struct inode *inode)
int drop;
WARN_ON(inode->i_state & I_NEW);
+ VFS_BUG_ON_INODE(atomic_read(&inode->i_count) != 0, inode);
if (op->drop_inode)
drop = op->drop_inode(inode);
@@ -1893,6 +1894,12 @@ static void iput_final(struct inode *inode)
return;
}
+ /*
+ * Re-check ->i_count in case the ->drop_inode() hooks played games.
+ * Note we only execute this if the verdict was to drop the inode.
+ */
+ VFS_BUG_ON_INODE(atomic_read(&inode->i_count) != 0, inode);
+
state = inode->i_state;
if (!drop) {
WRITE_ONCE(inode->i_state, state | I_WILL_FREE);