Skip to content

Commit 4e32c25

Browse files
braunertorvalds
authored andcommitted
libfs: fix get_stashed_dentry()
get_stashed_dentry() tries to optimistically retrieve a stashed dentry from a provided location. It needs to ensure to hold rcu lock before it dereference the stashed location to prevent UAF issues. Use rcu_dereference() instead of READ_ONCE() it's effectively equivalent with some lockdep bells and whistles and it communicates clearly that this expects rcu protection. Link: https://lore.kernel.org/r/20240906-vfs-hotfix-5959800ffa68@brauner Fixes: 07fd7c3 ("libfs: add path_from_stashed()") Reported-by: [email protected] Fixes: [email protected] Reported-by: [email protected] Fixes: [email protected] Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b831f83 commit 4e32c25

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/libfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,12 +2117,12 @@ struct timespec64 simple_inode_init_ts(struct inode *inode)
21172117
}
21182118
EXPORT_SYMBOL(simple_inode_init_ts);
21192119

2120-
static inline struct dentry *get_stashed_dentry(struct dentry *stashed)
2120+
static inline struct dentry *get_stashed_dentry(struct dentry **stashed)
21212121
{
21222122
struct dentry *dentry;
21232123

21242124
guard(rcu)();
2125-
dentry = READ_ONCE(stashed);
2125+
dentry = rcu_dereference(*stashed);
21262126
if (!dentry)
21272127
return NULL;
21282128
if (!lockref_get_not_dead(&dentry->d_lockref))
@@ -2219,7 +2219,7 @@ int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
22192219
const struct stashed_operations *sops = mnt->mnt_sb->s_fs_info;
22202220

22212221
/* See if dentry can be reused. */
2222-
path->dentry = get_stashed_dentry(*stashed);
2222+
path->dentry = get_stashed_dentry(stashed);
22232223
if (path->dentry) {
22242224
sops->put_data(data);
22252225
goto out_path;

0 commit comments

Comments
 (0)