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

From: Hillf Danton
Date: Wed May 29 2024 - 07:55:01 EST


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

--- x/fs/open.c
+++ y/fs/open.c
@@ -906,9 +906,13 @@ static int do_dentry_open(struct file *f
{
static const struct file_operations empty_fops = {};
struct inode *inode = f->f_path.dentry->d_inode;
+ struct dentry *d = f->f_path.dentry;
int error;

+ if (!lockref_get_not_zero(&d->d_lockref))
+ return -ENODEV;
path_get(&f->f_path);
+ dput(d);
f->f_inode = inode;
f->f_mapping = inode->i_mapping;
f->f_wb_err = filemap_sample_wb_err(f->f_mapping);
--