Re: [syzbot] [ntfs3?] KASAN: slab-use-after-free Read in chrdev_open

From: Hillf Danton
Date: Sat Jun 15 2024 - 02:48:52 EST


#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 83a7eefedc9b

--- x/fs/open.c
+++ y/fs/open.c
@@ -952,7 +952,18 @@ static int do_dentry_open(struct file *f
if (!open)
open = f->f_op->open;
if (open) {
+ struct super_block *sb = inode->i_sb;
+
+ error = -EINVAL;
+ for (;;) {
+ int a = atomic_read(&sb->s_active);
+ if (a < 1)
+ goto cleanup_all;
+ if (a == atomic_cmpxchg(&sb->s_active, a, a+1))
+ break;
+ }
error = open(inode, f);
+ deactivate_super(sb);
if (error)
goto cleanup_all;
}
--