Skip to contentSkip to conversation

fuse: fix race conditions on fi->nlookup

PATCH In review yangyun 3 participants 3 messages Aug 10, 2024 – Aug 22, 2024

Subsystems (2)
lore
Share & tools
lore

yangyun

author
#0 lore raw

PATCH 1/1 fuse: fix race conditions on fi->nlookup

Lock on fi->nlookup is missed in fuse_fill_super_submount(). Add lock on it to prevent race conditions.

Fixes 1866d779d5d2 ("fuse: Allow fuse_fill_super_common() for submounts")
---
 fs/fuse/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/fuse/inode.c +2 -0
index 99e44ea7d875..2e220f245ceb 100644
@@ -1593,7 +1593,9 @@ static int fuse_fill_super_submount(struct super_block *sb,
 	 * that, though, so undo it here.
 	 */
 	fi = get_fuse_inode(root);
+	spin_lock(&fi->lock);
 	fi->nlookup--;
+	spin_unlock(&fi->lock);
 
 	sb->s_d_op = &fuse_dentry_operations;
 	sb->s_root = d_make_root(root);
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · yangyun

Lock on fi->nlookup is missed in fuse_fill_super_submount(). Add lock on it to prevent race conditions.

Fixes 1866d779d5d2 ("fuse: Allow fuse_fill_super_common() for submounts")
---
 fs/fuse/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/fuse/inode.c +0 -0
index 99e44ea7d875..2e220f245ceb 100644

fs/fuse/inode.c static int fuse_fill_super_submount(struct super_block *sb, · line 1601

Quoted 9 lines
fs/fuse/inode.c +2 -0
@@ -1593,7 +1593,9 @@ static int fuse_fill_super_submount(struct super_block *sb,
 	 * that, though, so undo it here.
 	 */
 	fi = get_fuse_inode(root);
+	spin_lock(&fi->lock);
 	fi->nlookup--;
+	spin_unlock(&fi->lock);
 
 	sb->s_d_op = &fuse_dentry_operations;
 	sb->s_root = d_make_root(root);

LGTM

maintainer
#2 lore raw
In reply to yangyun
Quoted 3 lines · yangyun

Lock on fi->nlookup is missed in fuse_fill_super_submount(). Add lock on it to prevent race conditions.

It's okay to do this without lockinghere, because this is a brand new superblock and and a brand new root inode for that superblock, so there's no possible access from outside this function.

So just a comment should suffice.

Thanks,
Miklos