linux/Documentation
Al Viro cbb5ec8f75 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>
History 2024-01-31 16:21:03 -08:00
..
ABI PM / devfreq: Fix buffer overflow in trans_stat_show 2024-01-31 16:20:54 -08:00
accel accel/qaic: Add QAIC_DETACH_SLICE_BO IOCTL 2023-09-22 09:58:49 -06:00
accounting docs: psi: use correct config name 2023-07-31 09:54:17 -06:00
admin-guide docs: kernel_abi.py: fix command injection 2024-01-31 16:21:00 -08:00
arch arm64: errata: Add Cortex-A510 speculative unprivileged load workaround 2024-01-31 16:21:01 -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 Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
core-api Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
cpu-freq Docs/subsystem-apis: Remove '[The ]Linux' prefixes from titles of listed documents 2023-01-24 15:27:08 -07:00
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 dt-bindings: gpio: xilinx: Fix node address in gpio 2024-01-25 15:45:28 -08:00
doc-guide docs: doc-guide: mention 'make refcheckdocs' 2023-10-22 20:38:55 -06:00
driver-api PCI/P2PDMA: Remove reference to pci_p2pdma_map_sg() 2024-01-25 15:45:16 -08:00
fault-injection Documentation: Fix typos 2023-08-18 11:29:03 -06:00
fb Documentation: Fix typos 2023-08-18 11:29:03 -06:00
features Documentation: Drop IA64 from feature descriptions 2023-09-11 08:13:18 +00:00
filesystems rename(): fix the locking of subdirectories 2024-01-31 16:21:03 -08:00
firmware-guide ACPI: docs: enumeration: Clarify ACPI bus concepts 2023-10-06 17:29:53 +02:00
firmware_class firmware: revamp firmware documentation 2017-01-11 09:42:59 +01:00
fpga Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
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 HID: Add introduction about HID for non-kernel programmers 2023-08-07 13:24:36 +02:00
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: fix spelling error in i2c-address-translators 2023-12-27 20:05:44 +01:00
iio docs: iio: add documentation for BNO055 driver 2022-09-21 18:42:56 +01:00
images docs: add SVG version of the Linux logo 2022-06-01 09:32:45 -06:00
infiniband RDMA/core: Remove FMR device ops 2020-06-02 20:32:54 -03:00
input input: docs: pxrc: remove reference to phoenix-sim 2023-08-28 12:43:32 -06:00
isdn Documentation: isdn: correct spelling 2023-02-10 16:28:13 -08:00
kbuild Kbuild updates for v6.7 2023-11-04 08:07:19 -10:00
kernel-hacking Documentation: Add document for false sharing 2023-04-10 16:46:11 -06:00
leds - New Drivers 2023-07-03 11:26:05 -07:00
litmus-tests LKMM scripting updates for v6.4 2023-04-24 12:02:25 -07:00
livepatch Documentation: Fix typos 2023-08-18 11:29:03 -06:00
locking Documentation: Fix typos 2023-08-18 11:29:03 -06:00
maintainer docs: move riscv under arch 2023-10-10 13:37:43 -06:00
mhi docs: Add documentation for MHI bus 2020-03-19 07:41:04 +01:00
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 docs: add some directories to the main documentation index 2019-07-15 11:03:03 -03:00
netlink netlink: specs: devlink: add forgotten port function caps enum values 2023-11-01 22:13:43 -07:00
networking Revert "net: ipv6/addrconf: clamp preferred_lft to the minimum required" 2024-01-02 14:58:46 -08:00
nvdimm nvdimm: fixes to maintainter-entry-profile 2020-05-25 10:19:19 -06:00
nvme docs, nvme: add a feature and quirk policy document 2022-12-28 05:37:12 -10:00
PCI docs: move powerpc under arch 2023-10-10 13:35:55 -06:00
pcmcia Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
peci Docs/subsystem-apis: Remove '[The ]Linux' prefixes from titles of listed documents 2023-01-24 15:27:08 -07:00
power Documentation: Fix typos 2023-08-18 11:29:03 -06:00
process docs: netdev: try to guide people on dealing with silence 2023-11-21 14:35:43 -08: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 SCSI misc on 20230902 2023-09-02 12:02:41 -07:00
security docs: security: Confidential computing intro and threat model for x86 virtualization 2023-09-23 01:14:21 -06:00
sound Linux 6.6-rc7 2023-10-23 19:38:22 +01:00
sphinx docs: kernel_abi.py: fix command injection 2024-01-31 16:21:00 -08:00
sphinx-static docs: Add more information to the HTML sidebar 2023-02-08 13:28:27 -07:00
spi Documentation: Fix typos 2023-08-18 11:29:03 -06:00
staging Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
target scsi: target: docs: Remove tcm_mod_builder.py 2023-06-28 22:01:32 -04:00
timers Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
tools rtla: fix a example in rtla-timerlat-hist.rst 2023-09-22 14:44:04 +02:00
trace Documentation: coresight: fix make refcheckdocs warning 2023-11-16 09:52:39 +00:00
translations docs: kernel_feat.py: fix potential command injection 2024-01-20 11:53:02 +01: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 Documentation: Fix typos 2023-08-18 11:29:03 -06:00
watchdog Documentation: Fix typos 2023-08-18 11:29:03 -06:00
wmi Documentation work keeps chugging along; stuff for 6.6 includes: 2023-08-30 20:05:42 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
atomic_bitops.txt wait_on_bit: add an acquire memory barrier 2022-08-26 09:30:25 -07:00
atomic_t.txt Documentation: Fixed a typo in atomic_t.txt 2023-01-03 20:47:04 -08:00
Changes docs: add back 'Documentation/Changes' file (as symlink) 2016-12-14 16:30:12 -08:00
CodingStyle doc: re-add CodingStyle and SubmittingPatches 2016-10-24 08:12:35 -02:00
conf.py Documentation: conf.py: Add __force to c_id_attributes 2023-05-19 08:58:10 -06:00
docutils.conf doc-rst: Add missing newline at end of file 2019-06-20 14:16:56 -06:00
dontdiff scripts: remove bin2c 2023-01-26 12:43:33 +09:00
index.rst docs: create a top-level arch/ directory 2023-03-23 13:27:27 -06:00
Kconfig Documentation: Avoid duplicate Kconfig inclusion 2023-01-19 13:56:34 -07:00
Makefile docs: Integrate rustdoc generation into htmldocs 2023-07-21 15:08:46 -06:00
memory-barriers.txt docs: memory-barriers: Add note on compiler transformation and address deps 2023-10-09 09:40:53 -07:00
SubmittingPatches doc: re-add CodingStyle and SubmittingPatches 2016-10-24 08:12:35 -02:00
subsystem-apis.rst docs: move leds under section Human interfaces 2023-09-22 05:24:20 -06:00