linux-stable/Documentation
Al Viro 22e111ed6c rename(): fix the locking of subdirectories
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>
2023-11-25 02:53:20 -05:00
..
ABI vhost,virtio,vdpa: features, fixes, cleanups 2023-11-05 09:02:32 -10:00
accel
accounting
admin-guide IOMMU Updates for Linux v6.7 2023-11-09 13:37:28 -08:00
arch arm64 fixes: 2023-11-10 12:22:14 -08:00
block The number of commits for documentation is not huge this time around, but 2023-11-01 17:11:41 -10:00
bpf bpf: Add __bpf_kfunc_{start,end}_defs macros 2023-11-01 22:33:53 -07:00
cdrom
core-api Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
cpu-freq
crypto crypto: ahash - remove support for nonzero alignmask 2023-10-27 18:04:29 +08:00
dev-tools Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
devicetree Input updates for 6.7 merge window: 2023-11-09 14:18:42 -08:00
doc-guide docs: doc-guide: mention 'make refcheckdocs' 2023-10-22 20:38:55 -06:00
driver-api media updates for v6.7-rc1 2023-11-06 15:06:06 -08:00
fault-injection
fb
features
filesystems rename(): fix the locking of subdirectories 2023-11-25 02:53:20 -05:00
firmware-guide
firmware_class
fpga
gpu Merge tag 'drm-misc-next-2023-10-27' of git://anongit.freedesktop.org/drm/drm-misc into drm-next 2023-10-31 10:47:50 +10:00
hid
hwmon hwmon: (aquacomputer_d5next) Add support for Aquacomputer High Flow USB and MPS Flow 2023-10-29 22:22:48 -07:00
i2c Documentation: i2c: add fault code for not supporting 10 bit addresses 2023-10-29 21:03:35 +01:00
iio
images
infiniband
input
isdn
kbuild Kbuild updates for v6.7 2023-11-04 08:07:19 -10:00
kernel-hacking
leds
litmus-tests
livepatch
locking
maintainer
mhi
misc-devices eeprom: remove doc and MAINTAINERS section after driver was removed 2023-10-18 10:01:34 +02:00
mm Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
netlabel
netlink netlink: specs: devlink: add forgotten port function caps enum values 2023-11-01 22:13:43 -07:00
networking Including fixes from netfilter and bpf. 2023-11-09 17:09:35 -08:00
nvdimm
nvme
PCI
pcmcia
peci
power
process Driver core changes for 6.7-rc1 2023-11-03 15:15:47 -10:00
RCU Merge branches 'rcu/torture', 'rcu/fixes', 'rcu/docs', 'rcu/refscale', 'rcu/tasks' and 'rcu/stall' into rcu/next 2023-10-23 15:24:11 +02:00
rust Rust changes for v6.7 2023-10-30 20:30:49 -10:00
scheduler asm-generic updates for v6.7 2023-11-01 15:28:33 -10:00
scsi
security
sound Linux 6.6-rc7 2023-10-23 19:38:22 +01:00
sphinx Documentation/sphinx: Remove the repeated word "the" in comments. 2023-10-22 20:33:38 -06:00
sphinx-static
spi
staging
target
timers
tools
trace Documentation: tracing: Add a note about argument and retval access 2023-11-10 19:59:03 +09:00
translations media updates for v6.7-rc1 2023-11-06 15:06:06 -08:00
usb USB/Thunderbolt changes for 6.7-rc1 2023-11-03 16:00:42 -10:00
userspace-api drm next and fixes for 6.7-rc1 2023-11-07 17:10:02 -08:00
virt KVM/arm64 updates for 6.7 2023-10-31 16:37:07 -04:00
w1
watchdog
wmi
.gitignore
atomic_bitops.txt
atomic_t.txt
Changes
CodingStyle
conf.py
docutils.conf
dontdiff
index.rst
Kconfig
Makefile
memory-barriers.txt
SubmittingPatches
subsystem-apis.rst