--- 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);