Skip to content

Commit e9d50b7

Browse files
committed
Merge patch series "fs: add iput_not_last()"
Add iput_not_last() and switch landlock over to it to remove false-positives from might_sleep() annotations in iput(). Link: https://patch.msgid.link/[email protected] * patches from https://patch.msgid.link/[email protected]: landlock: fix splats from iput() after it started calling might_sleep() fs: add iput_not_last() Signed-off-by: Christian Brauner <[email protected]>
2 parents 3cd1548 + 56325e8 commit e9d50b7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

fs/inode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,18 @@ void iput(struct inode *inode)
19671967
}
19681968
EXPORT_SYMBOL(iput);
19691969

1970+
/**
1971+
* iput_not_last - put an inode assuming this is not the last reference
1972+
* @inode: inode to put
1973+
*/
1974+
void iput_not_last(struct inode *inode)
1975+
{
1976+
VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 2, inode);
1977+
1978+
WARN_ON(atomic_sub_return(1, &inode->i_count) == 0);
1979+
}
1980+
EXPORT_SYMBOL(iput_not_last);
1981+
19701982
#ifdef CONFIG_BLOCK
19711983
/**
19721984
* bmap - find a block number in a file

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,7 @@ extern int current_umask(void);
28242824

28252825
extern void ihold(struct inode * inode);
28262826
extern void iput(struct inode *);
2827+
void iput_not_last(struct inode *);
28272828
int inode_update_timestamps(struct inode *inode, int flags);
28282829
int generic_update_time(struct inode *, int);
28292830

security/landlock/fs.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,11 +1335,10 @@ static void hook_sb_delete(struct super_block *const sb)
13351335
* At this point, we own the ihold() reference that was
13361336
* originally set up by get_inode_object() and the
13371337
* __iget() reference that we just set in this loop
1338-
* walk. Therefore the following call to iput() will
1339-
* not sleep nor drop the inode because there is now at
1340-
* least two references to it.
1338+
* walk. Therefore there are at least two references
1339+
* on the inode.
13411340
*/
1342-
iput(inode);
1341+
iput_not_last(inode);
13431342
} else {
13441343
spin_unlock(&object->lock);
13451344
rcu_read_unlock();

0 commit comments

Comments
 (0)