Skip to content

Commit abae88f

Browse files
amir73ilgregkh
authored andcommitted
fsnotify: fix fsnotify hooks in pseudo filesystems
commit 29044da upstream. Commit 4924646 ("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 commit 46c46f8 ("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: 4924646 ("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>
1 parent 6ceac38 commit abae88f

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎fs/configfs/dir.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,8 @@ void configfs_unregister_group(struct config_group *group)
18051805
configfs_detach_group(&group->cg_item);
18061806
d_inode(dentry)->i_flags |= S_DEAD;
18071807
dont_mount(dentry);
1808+
d_drop(dentry);
18081809
fsnotify_rmdir(d_inode(parent), dentry);
1809-
d_delete(dentry);
18101810
inode_unlock(d_inode(parent));
18111811

18121812
dput(dentry);
@@ -1947,10 +1947,10 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
19471947
configfs_detach_group(&group->cg_item);
19481948
d_inode(dentry)->i_flags |= S_DEAD;
19491949
dont_mount(dentry);
1950-
fsnotify_rmdir(d_inode(root), dentry);
19511950
inode_unlock(d_inode(dentry));
19521951

1953-
d_delete(dentry);
1952+
d_drop(dentry);
1953+
fsnotify_rmdir(d_inode(root), dentry);
19541954

19551955
inode_unlock(d_inode(root));
19561956

‎fs/devpts/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ void devpts_pty_kill(struct dentry *dentry)
621621

622622
dentry->d_fsdata = NULL;
623623
drop_nlink(dentry->d_inode);
624-
fsnotify_unlink(d_inode(dentry->d_parent), dentry);
625624
d_drop(dentry);
625+
fsnotify_unlink(d_inode(dentry->d_parent), dentry);
626626
dput(dentry); /* d_alloc_name() in devpts_pty_new() */
627627
}
628628

‎fs/nfsd/nfsctl.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,8 @@ static void nfsdfs_remove_file(struct inode *dir, struct dentry *dentry)
12471247
clear_ncl(d_inode(dentry));
12481248
dget(dentry);
12491249
ret = simple_unlink(dir, dentry);
1250-
d_delete(dentry);
1250+
d_drop(dentry);
1251+
fsnotify_unlink(dir, dentry);
12511252
dput(dentry);
12521253
WARN_ON_ONCE(ret);
12531254
}
@@ -1336,8 +1337,8 @@ void nfsd_client_rmdir(struct dentry *dentry)
13361337
dget(dentry);
13371338
ret = simple_rmdir(dir, dentry);
13381339
WARN_ON_ONCE(ret);
1340+
d_drop(dentry);
13391341
fsnotify_rmdir(dir, dentry);
1340-
d_delete(dentry);
13411342
dput(dentry);
13421343
inode_unlock(dir);
13431344
}

‎net/sunrpc/rpc_pipe.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ static int __rpc_rmdir(struct inode *dir, struct dentry *dentry)
599599

600600
dget(dentry);
601601
ret = simple_rmdir(dir, dentry);
602+
d_drop(dentry);
602603
if (!ret)
603604
fsnotify_rmdir(dir, dentry);
604-
d_delete(dentry);
605605
dput(dentry);
606606
return ret;
607607
}
@@ -612,9 +612,9 @@ static int __rpc_unlink(struct inode *dir, struct dentry *dentry)
612612

613613
dget(dentry);
614614
ret = simple_unlink(dir, dentry);
615+
d_drop(dentry);
615616
if (!ret)
616617
fsnotify_unlink(dir, dentry);
617-
d_delete(dentry);
618618
dput(dentry);
619619
return ret;
620620
}

0 commit comments

Comments
 (0)