]> git.baikalelectronics.ru Git - kernel.git/commit
fsnotify: invalidate dcache before IN_DELETE event
authorAmir Goldstein <amir73il@gmail.com>
Thu, 20 Jan 2022 21:53:04 +0000 (23:53 +0200)
committerJan Kara <jack@suse.cz>
Mon, 24 Jan 2022 13:16:46 +0000 (14:16 +0100)
commit73e2904dcc71c6b9d8fecffd22aa4b59fe19456d
treeb5a234c3f7ac0031f492a986ade1030ce19119d4
parentc0213fe6d6812db290bbc1c47b57d8b6da5cd617
fsnotify: invalidate dcache before IN_DELETE event

Apparently, there are some applications that use IN_DELETE event as an
invalidation mechanism and expect that if they try to open a file with
the name reported with the delete event, that it should not contain the
content of the deleted file.

Commit c2262d9f1121 ("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, create a new hook fsnotify_delete() that takes
the unlinked inode as an argument and use a helper d_delete_notify() to
pin the inode, so we can pass it to fsnotify_delete() after d_delete().

Backporting hint: this regression is from v5.3. Although patch will
apply with only trivial conflicts to v5.4 and v5.10, it won't build,
because fsnotify_delete() implementation is different in each of those
versions (see fsnotify_link()).

A follow up patch will fix the fsnotify_unlink/rmdir() calls in pseudo
filesystem that do not need to call d_delete().

Link: https://lore.kernel.org/r/20220120215305.282577-1-amir73il@gmail.com
Reported-by: Ivan Delalande <colona@arista.com>
Link: https://lore.kernel.org/linux-fsdevel/YeNyzoDM5hP5LtGW@visor/
Fixes: c2262d9f1121 ("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>
fs/btrfs/ioctl.c
fs/namei.c
include/linux/fsnotify.h