Skip to content

Commit be97a4b

Browse files
mjguzikbrauner
authored andcommitted
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>
1 parent dc816f8 commit be97a4b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

fs/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,7 @@ static void iput_final(struct inode *inode)
18791879
int drop;
18801880

18811881
WARN_ON(inode->i_state & I_NEW);
1882+
VFS_BUG_ON_INODE(atomic_read(&inode->i_count) != 0, inode);
18821883

18831884
if (op->drop_inode)
18841885
drop = op->drop_inode(inode);
@@ -1893,6 +1894,12 @@ static void iput_final(struct inode *inode)
18931894
return;
18941895
}
18951896

1897+
/*
1898+
* Re-check ->i_count in case the ->drop_inode() hooks played games.
1899+
* Note we only execute this if the verdict was to drop the inode.
1900+
*/
1901+
VFS_BUG_ON_INODE(atomic_read(&inode->i_count) != 0, inode);
1902+
18961903
state = inode->i_state;
18971904
if (!drop) {
18981905
WRITE_ONCE(inode->i_state, state | I_WILL_FREE);

0 commit comments

Comments
 (0)