kernel_samsung_a53x/Documentation/filesystems
Al Viro a46e2b980e 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 28eceeda130f "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: 28eceeda130f "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-11-18 12:12:59 +01:00
..
caching Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cifs Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ext4 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nfs Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
spufs Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
9p.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
adfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
affs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
afs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
api-summary.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
autofs-mount-control.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
autofs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
automount-support.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
befs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
btrfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ceph.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
coda.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
configfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cramfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dax.txt Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
debugfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
devpts.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
directory-locking.rst rename(): fix the locking of subdirectories 2024-11-18 12:12:59 +01:00
dlmfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dnotify.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ecryptfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
efivarfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
erofs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ext2.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ext3.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
f2fs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fiemap.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
files.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fscrypt.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fsverity.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fuse-io.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
fuse.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gfs2-glocks.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gfs2-uevents.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
gfs2.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hfsplus.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hpfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
incfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
index.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
inotify.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
isofs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
journalling.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
locking.rst rename(): fix the locking of subdirectories 2024-11-18 12:12:59 +01:00
locks.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mandatory-locking.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mount_api.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nilfs2.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ntfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ocfs2-online-filecheck.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ocfs2.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
omfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
orangefs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
overlayfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
path-lookup.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
path-lookup.txt Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
porting.rst rename(): fix the locking of subdirectories 2024-11-18 12:12:59 +01:00
proc.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qnx6.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
quota.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ramfs-rootfs-initramfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
relay.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
romfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seq_file.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sharedsubtree.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
splice.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
squashfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysv-fs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tmpfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ubifs-authentication.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ubifs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
udf.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vfat.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vfs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
virtiofs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xfs-delayed-logging-design.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xfs-self-describing-metadata.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
zonefs.rst Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00