linux-stable/Documentation
Al Viro 362be9ec32 rename(): fix the locking of subdirectories
commit 22e111ed6c 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-01-31 16:17:02 -08:00
..
ABI PM / devfreq: Fix buffer overflow in trans_stat_show 2024-01-31 16:16:58 -08:00
PCI
RCU There's not a huge amount of activity in the docs tree this time around, 2022-10-03 10:23:32 -07:00
accounting sched/psi: Allow unprivileged polling of N*2s period 2023-07-27 08:50:38 +02:00
admin-guide docs: kernel_abi.py: fix command injection 2024-01-31 16:17:00 -08:00
arc
arm EFI updates for v6.1 2022-10-09 08:56:54 -07:00
arm64 arm64: errata: Add Cortex-A520 speculative unprivileged load workaround 2023-10-10 22:00:39 +02:00
block blk-crypto: don't use struct request_queue for public interfaces 2023-05-11 23:03:00 +09:00
bpf bpf, docs: Fix modulo zero, division by zero, overflow, and underflow 2023-03-10 09:33:50 +01:00
cdrom
core-api overflow: Fix kern-doc markup for functions 2022-10-25 14:57:42 -07:00
cpu-freq
crypto
dev-tools docs/scripts/gdb: add necessary make scripts_gdb step 2023-03-10 09:33:58 +01:00
devicetree dt-bindings: gpio: xilinx: Fix node address in gpio 2024-01-25 15:27:50 -08:00
doc-guide Rust introduction for v6.1-rc1 2022-10-03 16:39:37 -07:00
driver-api PCI/P2PDMA: Remove reference to pci_p2pdma_map_sg() 2024-01-25 15:27:44 -08:00
fault-injection lkdtm: replace ll_rw_block with submit_bh 2023-07-19 16:21:53 +02:00
fb
features
filesystems rename(): fix the locking of subdirectories 2024-01-31 16:17:02 -08:00
firmware-guide Merge branches 'acpi-misc', 'acpi-tools' and 'acpi-docs' 2022-10-03 20:03:49 +02:00
firmware_class
fpga
gpu drm/vmwgfx: Remove vmwgfx_hashtab 2023-01-18 11:58:28 +01:00
hid
hwmon hwmon: (ftsteutates) Fix scaling of measurements 2023-03-10 09:33:10 +01:00
i2c
ia64
iio
images
infiniband
input Merge branch 'next' into for-linus 2022-10-09 22:30:23 -07:00
isdn
kbuild Documentation: kbuild: Add description of git for reproducible builds 2022-10-28 00:16:29 +09:00
kernel-hacking Documentation: Fix spelling mistake in hacking.rst 2022-10-24 11:27:51 -06:00
leds
litmus-tests
livepatch
locking
loongarch docs/LoongArch: Add booting description 2022-12-08 14:59:15 +08:00
m68k
maintainer
mhi
mips
misc-devices
mm mm: multi-gen LRU: rename lrugen->lists[] to lrugen->folios[] 2023-09-19 12:27:54 +02:00
netlabel
networking tcp: enforce receive buffer memory limits by allowing the tcp window to shrink 2023-10-19 23:08:54 +02:00
nios2
nvdimm
openrisc
parisc
pcmcia
peci
power
powerpc
process docs: Set minimal gtags / GNU GLOBAL version to 6.6.5 2023-07-05 18:27:38 +01:00
riscv riscv: Move early dtb mapping into the fixmap region 2023-05-01 08:26:28 +09:00
rust
s390 vfio/mdev: embedd struct mdev_parent in the parent data structure 2022-10-04 12:06:58 -06:00
scheduler
scsi scsi: core: Fix the scsi_set_resid() documentation 2023-09-13 09:43:00 +02:00
security KEYS: encrypted: fix key instantiation with user-provided data 2022-12-21 17:48:11 +01:00
sh
sound ALSA: hda/sigmatel: add pin overrides for Intel DP45SG motherboard 2023-04-20 12:35:05 +02:00
sparc
sphinx docs: kernel_abi.py: fix command injection 2024-01-31 16:17:00 -08:00
sphinx-static
spi
staging
target
timers
tools A handful of relatively simple documentation fixes, plus a set of patches 2022-10-13 10:58:32 -07:00
trace tracing/probes: Add symstr type for dynamic events 2023-08-03 10:23:54 +02:00
translations docs/zh_CN: Add LoongArch booting description's translation 2022-12-08 15:03:14 +08:00
usb
userspace-api media: uapi: HEVC: Add num_delta_pocs_of_ref_rps_idx field 2023-09-13 09:42:20 +02:00
virt x86/sev: Change snp_guest_issue_request()'s fw_err argument 2023-11-20 11:52:13 +01:00
w1
watchdog
x86 x86/sev: Add SEV-SNP guest feature negotiation support 2023-02-01 08:34:50 +01:00
xtensa
.gitignore
Changes
CodingStyle
Kconfig
Makefile
SubmittingPatches
arch.rst
atomic_bitops.txt
atomic_t.txt
conf.py There's not a huge amount of activity in the docs tree this time around, 2022-10-03 10:23:32 -07:00
docutils.conf
dontdiff
index.rst Rust introduction for v6.1-rc1 2022-10-03 16:39:37 -07:00
memory-barriers.txt
subsystem-apis.rst