WSL2-Linux-Kernel/Documentation/filesystems
Al Viro dfda2a5eb6 rename(): fix the locking of subdirectories
commit 22e111ed6c83dcde3037fc81176012721bc34c0b upstream.

	We should never lock two subdirectories without having taken
->s_vfs_rename_mutex; inode pointer order or not, the "order" proposed
in 28eceeda13 "fs: Lock moved directories" is not transitive, with
the usual consequences.

	The rationale for locking renamed subdirectory in all cases was
the possibility of race between rename modifying .. in a subdirectory to
reflect the new parent and another thread modifying the same subdirectory.
For a lot of filesystems that's not a problem, but for some it can lead
to trouble (e.g. the case when short directory contents is kept in the
inode, but creating a file in it might push it across the size limit
and copy its contents into separate data block(s)).

	However, we need that only in case when the parent does change -
otherwise ->rename() doesn't need to do anything with .. entry in the
first place.  Some instances are lazy and do a tautological update anyway,
but it's really not hard to avoid.

Amended locking rules for rename():
	find the parent(s) of source and target
	if source and target have the same parent
		lock the common parent
	else
		lock ->s_vfs_rename_mutex
		lock both parents, in ancestor-first order; if neither
		is an ancestor of another, lock the parent of source
		first.
	find the source and target.
	if source and target have the same parent
		if operation is an overwriting rename of a subdirectory
			lock the target subdirectory
	else
		if source is a subdirectory
			lock the source
		if target is a subdirectory
			lock the target
	lock non-directories involved, in inode pointer order if both
	source and target are such.

That way we are guaranteed that parents are locked (for obvious reasons),
that any renamed non-directory is locked (nfsd relies upon that),
that any victim is locked (emptiness check needs that, among other things)
and subdirectory that changes parent is locked (needed to protect the update
of .. entries).  We are also guaranteed that any operation locking more
than one directory either takes ->s_vfs_rename_mutex or locks a parent
followed by its child.

Cc: stable@vger.kernel.org
Fixes: 28eceeda13 "fs: Lock moved directories"
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 08:54:26 +01:00
..
caching
cifs ksmbd: update SMB3 multi-channel support in ksmbd.rst 2021-08-13 08:18:15 +09:00
ext4 ext4, doc: fix incorrect h_reserved size 2022-04-27 14:39:01 +02:00
nfs
spufs
9p.rst
adfs.rst
affs.rst
afs.rst
api-summary.rst block: move fs/block_dev.c to block/bdev.c 2021-09-07 08:39:40 -06:00
autofs-mount-control.rst autofs: use flexible array in ioctl structure 2023-07-23 13:47:33 +02:00
autofs.rst autofs: use flexible array in ioctl structure 2023-07-23 13:47:33 +02:00
automount-support.rst
befs.rst
bfs.rst
btrfs.rst
ceph.rst
coda.rst
configfs.rst
cramfs.rst
dax.rst docs: convert dax.txt to rst 2021-06-04 11:31:02 -06:00
debugfs.rst debugfs: remove return value of debugfs_create_bool() 2021-05-21 20:59:03 +02:00
devpts.rst
directory-locking.rst rename(): fix the locking of subdirectories 2024-02-23 08:54:26 +01:00
dlmfs.rst
dnotify.rst
ecryptfs.rst
efivarfs.rst
erofs.rst erofs: introduce chunk-based file on-disk format 2021-08-20 22:38:01 +08:00
ext2.rst docs: fix a cross-ref 2021-06-13 17:02:46 -06:00
ext3.rst
f2fs.rst f2fs: support fault injection for dquot_initialize() 2022-06-09 10:23:13 +02:00
fiemap.rst
files.rst
fscrypt.rst fscrypt: allow 256-bit master keys with AES-256-XTS 2021-11-18 19:16:11 +01:00
fsverity.rst
fuse-io.rst
fuse.rst
gfs2-glocks.rst
gfs2-uevents.rst
gfs2.rst
hfs.rst
hfsplus.rst
hpfs.rst
idmappings.rst docs: update mapping documentation 2022-07-02 16:41:15 +02:00
index.rst Merge git://github.com/Paragon-Software-Group/linux-ntfs3 2021-09-04 11:15:50 -07:00
inotify.rst
isofs.rst
journalling.rst
locking.rst rename(): fix the locking of subdirectories 2024-02-23 08:54:26 +01:00
locks.rst
mount_api.rst
netfs_library.rst netfs: Documentation for helper library 2021-04-23 10:14:32 +01:00
nilfs2.rst
ntfs.rst
ntfs3.rst Doc/fs/ntfs3: Fix rst format and make it cleaner 2021-09-20 18:53:12 +03:00
ocfs2-online-filecheck.rst
ocfs2.rst
omfs.rst
orangefs.rst
overlayfs.rst ovl: skip checking lower file's i_writecount on truncate 2021-08-17 11:47:44 +02:00
path-lookup.rst Merge branch 'work.namei' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-07-03 11:41:14 -07:00
path-lookup.txt
porting.rst rename(): fix the locking of subdirectories 2024-02-23 08:54:26 +01:00
proc.rst procfs/dmabuf: add inode number to /proc/*/fdinfo 2021-07-01 11:06:04 -07:00
qnx6.rst
quota.rst
ramfs-rootfs-initramfs.rst Documentation: Fix intiramfs script name 2021-07-18 23:48:14 +09:00
relay.rst
romfs.rst
seq_file.rst
sharedsubtree.rst
splice.rst
squashfs.rst
sysfs.rst
sysv-fs.rst
tmpfs.rst
ubifs-authentication.rst
ubifs.rst
udf.rst
vfat.rst docs: filesystems: Fix a mundane typo 2021-03-25 11:51:23 -06:00
vfs.rst docs: Correct missing "d_" prefix for dentry_operations member d_weak_revalidate 2023-03-22 13:31:22 +01:00
virtiofs.rst
xfs-delayed-logging-design.rst
xfs-self-describing-metadata.rst
zonefs.rst