mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
fsnotify: fix fsnotify hooks in pseudo filesystems
commit29044dae2e
upstream. Commit49246466a9
("fsnotify: move fsnotify_nameremove() hook out of d_delete()") moved the fsnotify delete hook before d_delete() so fsnotify will have access to a positive dentry. This allowed a race where opening the deleted file via cached dentry is now possible after receiving the IN_DELETE event. To fix the regression in pseudo filesystems, convert d_delete() calls to d_drop() (see commit46c46f8df9
("devpts_pty_kill(): don't bother with d_delete()") and move the fsnotify hook after d_drop(). Add a missing fsnotify_unlink() hook in nfsdfs that was found during the audit of fsnotify hooks in pseudo filesystems. Note that the fsnotify hooks in simple_recursive_removal() follow d_invalidate(), so they require no change. Link: https://lore.kernel.org/r/20220120215305.282577-2-amir73il@gmail.com Reported-by: Ivan Delalande <colona@arista.com> Link: https://lore.kernel.org/linux-fsdevel/YeNyzoDM5hP5LtGW@visor/ Fixes:49246466a9
("fsnotify: move fsnotify_nameremove() hook out of d_delete()") Cc: stable@vger.kernel.org # v5.3+ Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
6ceac38e9b
commit
abae88fb37
@ -1805,8 +1805,8 @@ void configfs_unregister_group(struct config_group *group)
|
|||||||
configfs_detach_group(&group->cg_item);
|
configfs_detach_group(&group->cg_item);
|
||||||
d_inode(dentry)->i_flags |= S_DEAD;
|
d_inode(dentry)->i_flags |= S_DEAD;
|
||||||
dont_mount(dentry);
|
dont_mount(dentry);
|
||||||
|
d_drop(dentry);
|
||||||
fsnotify_rmdir(d_inode(parent), dentry);
|
fsnotify_rmdir(d_inode(parent), dentry);
|
||||||
d_delete(dentry);
|
|
||||||
inode_unlock(d_inode(parent));
|
inode_unlock(d_inode(parent));
|
||||||
|
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
@ -1947,10 +1947,10 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
|
|||||||
configfs_detach_group(&group->cg_item);
|
configfs_detach_group(&group->cg_item);
|
||||||
d_inode(dentry)->i_flags |= S_DEAD;
|
d_inode(dentry)->i_flags |= S_DEAD;
|
||||||
dont_mount(dentry);
|
dont_mount(dentry);
|
||||||
fsnotify_rmdir(d_inode(root), dentry);
|
|
||||||
inode_unlock(d_inode(dentry));
|
inode_unlock(d_inode(dentry));
|
||||||
|
|
||||||
d_delete(dentry);
|
d_drop(dentry);
|
||||||
|
fsnotify_rmdir(d_inode(root), dentry);
|
||||||
|
|
||||||
inode_unlock(d_inode(root));
|
inode_unlock(d_inode(root));
|
||||||
|
|
||||||
|
@ -621,8 +621,8 @@ void devpts_pty_kill(struct dentry *dentry)
|
|||||||
|
|
||||||
dentry->d_fsdata = NULL;
|
dentry->d_fsdata = NULL;
|
||||||
drop_nlink(dentry->d_inode);
|
drop_nlink(dentry->d_inode);
|
||||||
fsnotify_unlink(d_inode(dentry->d_parent), dentry);
|
|
||||||
d_drop(dentry);
|
d_drop(dentry);
|
||||||
|
fsnotify_unlink(d_inode(dentry->d_parent), dentry);
|
||||||
dput(dentry); /* d_alloc_name() in devpts_pty_new() */
|
dput(dentry); /* d_alloc_name() in devpts_pty_new() */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,7 +1247,8 @@ static void nfsdfs_remove_file(struct inode *dir, struct dentry *dentry)
|
|||||||
clear_ncl(d_inode(dentry));
|
clear_ncl(d_inode(dentry));
|
||||||
dget(dentry);
|
dget(dentry);
|
||||||
ret = simple_unlink(dir, dentry);
|
ret = simple_unlink(dir, dentry);
|
||||||
d_delete(dentry);
|
d_drop(dentry);
|
||||||
|
fsnotify_unlink(dir, dentry);
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
WARN_ON_ONCE(ret);
|
WARN_ON_ONCE(ret);
|
||||||
}
|
}
|
||||||
@ -1336,8 +1337,8 @@ void nfsd_client_rmdir(struct dentry *dentry)
|
|||||||
dget(dentry);
|
dget(dentry);
|
||||||
ret = simple_rmdir(dir, dentry);
|
ret = simple_rmdir(dir, dentry);
|
||||||
WARN_ON_ONCE(ret);
|
WARN_ON_ONCE(ret);
|
||||||
|
d_drop(dentry);
|
||||||
fsnotify_rmdir(dir, dentry);
|
fsnotify_rmdir(dir, dentry);
|
||||||
d_delete(dentry);
|
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
inode_unlock(dir);
|
inode_unlock(dir);
|
||||||
}
|
}
|
||||||
|
@ -599,9 +599,9 @@ static int __rpc_rmdir(struct inode *dir, struct dentry *dentry)
|
|||||||
|
|
||||||
dget(dentry);
|
dget(dentry);
|
||||||
ret = simple_rmdir(dir, dentry);
|
ret = simple_rmdir(dir, dentry);
|
||||||
|
d_drop(dentry);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
fsnotify_rmdir(dir, dentry);
|
fsnotify_rmdir(dir, dentry);
|
||||||
d_delete(dentry);
|
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -612,9 +612,9 @@ static int __rpc_unlink(struct inode *dir, struct dentry *dentry)
|
|||||||
|
|
||||||
dget(dentry);
|
dget(dentry);
|
||||||
ret = simple_unlink(dir, dentry);
|
ret = simple_unlink(dir, dentry);
|
||||||
|
d_drop(dentry);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
fsnotify_unlink(dir, dentry);
|
fsnotify_unlink(dir, dentry);
|
||||||
d_delete(dentry);
|
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user