OpenCloudOS-Kernel/fs/btrfs
Amir Goldstein 8c16d4b7aa fsnotify: invalidate dcache before IN_DELETE event
commit a37d9a17f0 upstream.

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 49246466a9 ("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: 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>
Signed-off-by: Alex Shi <alexsshi@tencent.com>
2024-06-11 20:52:41 +08:00
..
tests tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
Kconfig btrfs: Fix build error while LIBCRC32C is module 2019-07-17 17:03:30 +02:00
Makefile btrfs: migrate the block group lookup code 2019-09-09 14:59:04 +02:00
acl.c btrfs: cleanup btrfs_setxattr_trans and drop transaction parameter 2019-04-29 19:02:44 +02:00
async-thread.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
async-thread.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
backref.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
backref.h btrfs: fiemap: preallocate ulists for btrfs_check_shared 2019-07-01 13:34:53 +02:00
block-group.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
block-group.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
block-rsv.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
block-rsv.h btrfs: migrate the global_block_rsv helpers to block-rsv.c 2019-07-02 12:30:55 +02:00
btrfs_inode.h btrfs: remove assumption about csum type form btrfs_print_data_csum_error() 2019-07-01 13:35:02 +02:00
check-integrity.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
check-integrity.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
compression.c btrfs: move cond_wake_up functions out of ctree 2019-09-09 14:59:15 +02:00
compression.h btrfs: compression: replace set_level callbacks by a common helper 2019-09-09 14:59:11 +02:00
ctree.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ctree.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
delalloc-space.c Btrfs: fix qgroup double free after failure to reserve metadata for delalloc 2019-10-17 20:13:44 +02:00
delalloc-space.h btrfs: migrate the delalloc space stuff to it's own home 2019-07-04 17:26:17 +02:00
delayed-inode.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
delayed-inode.h Btrfs: delayed-inode: use rb_first_cached for ins_root and del_root 2018-10-15 17:23:33 +02:00
delayed-ref.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
delayed-ref.h btrfs: migrate the delayed refs rsv code 2019-07-04 17:26:17 +02:00
dev-replace.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dev-replace.h btrfs: get fs_info from trans in btrfs_run_dev_replace 2019-04-29 19:02:43 +02:00
dir-item.c btrfs: remove unused parameter fs_info from btrfs_extend_item 2019-04-29 19:02:50 +02:00
disk-io.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
disk-io.h btrfs: Make reada_tree_block_flagged private 2019-09-09 14:59:11 +02:00
export.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
export.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
extent-tree.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
extent_io.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
extent_io.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
extent_map.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
extent_map.h btrfs: Remove impossible condition from mergable_maps 2019-02-25 14:13:21 +01:00
file-item.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
file.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
free-space-cache.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
free-space-cache.h btrfs: move struct io_ctl to free-space-cache.h 2019-09-09 14:59:15 +02:00
free-space-tree.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
free-space-tree.h btrfs: move basic block_group definitions to their own header 2019-09-09 14:59:03 +02:00
inode-item.c btrfs: Make btrfs_find_name_in_ext_backref return struct btrfs_inode_extref 2019-09-09 14:59:16 +02:00
inode-map.c btrfs: qgroup: Always free PREALLOC META reserve in btrfs_delalloc_release_extents() 2019-10-15 18:50:07 +02:00
inode-map.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
inode.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ioctl.c fsnotify: invalidate dcache before IN_DELETE event 2024-06-11 20:52:41 +08:00
locking.c btrfs: move cond_wake_up functions out of ctree 2019-09-09 14:59:15 +02:00
locking.h btrfs: Remove unused locking functions 2019-09-09 14:58:59 +02:00
lzo.c btrfs: compression: replace set_level callbacks by a common helper 2019-09-09 14:59:11 +02:00
misc.h btrfs: move math functions to misc.h 2019-09-09 14:59:15 +02:00
ordered-data.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
ordered-data.h btrfs: don't assume ordered sums to be 4 bytes 2019-07-01 13:35:00 +02:00
orphan.c btrfs: replace GPL boilerplate by SPDX -- sources 2018-04-12 16:29:51 +02:00
print-tree.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
print-tree.h btrfs: print-tree: debugging output enhancement 2018-04-20 19:18:16 +02:00
props.c btrfs: rename the btrfs_calc_*_metadata_size helpers 2019-09-09 14:59:13 +02:00
props.h btrfs: delete unused function btrfs_set_prop_trans 2019-04-29 19:02:54 +02:00
qgroup.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
qgroup.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
raid56.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
raid56.h btrfs: constify map parameter for nr_parity_stripes and nr_data_stripes 2019-07-01 13:34:58 +02:00
rcu-string.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
reada.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ref-verify.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
ref-verify.h btrfs: ref-verify: Use btrfs_ref to refactor btrfs_ref_tree_mod() 2019-04-29 19:02:49 +02:00
relocation.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
root-tree.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
scrub.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
send.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
send.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
space-info.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
space-info.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
struct-funcs.c btrfs: tie extent buffer and it's token together 2019-09-09 14:59:16 +02:00
super.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sysfs.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
sysfs.h btrfs: sysfs: move helper macros to sysfs.c 2019-09-09 14:59:08 +02:00
transaction.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
transaction.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
tree-checker.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
tree-checker.h btrfs: get fs_info from eb in btrfs_check_chunk_valid 2019-04-29 19:02:39 +02:00
tree-defrag.c btrfs: open code now trivial btrfs_set_lock_blocking 2019-02-25 14:13:27 +01:00
tree-log.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
tree-log.h btrfs: get fs_info from trans in btrfs_set_log_full_commit 2019-04-29 19:02:41 +02:00
ulist.c btrfs: replace GPL boilerplate by SPDX -- sources 2018-04-12 16:29:51 +02:00
ulist.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
uuid-tree.c tkernel: add base tlinux kernel interfaces 2024-06-11 20:09:33 +08:00
volumes.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
volumes.h ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
xattr.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
xattr.h btrfs: cleanup btrfs_setxattr_trans and drop transaction parameter 2019-04-29 19:02:44 +02:00
zlib.c btrfs: compression: replace set_level callbacks by a common helper 2019-09-09 14:59:11 +02:00
zstd.c btrfs: move cond_wake_up functions out of ctree 2019-09-09 14:59:15 +02:00