linux/fs/ext4
Eric Biggers f0edd3abee ext4: fix race conditions in ->d_compare() and ->d_hash()
commit ec772f0130 upstream.

Since ->d_compare() and ->d_hash() can be called in RCU-walk mode,
->d_parent and ->d_inode can be concurrently modified, and in
particular, ->d_inode may be changed to NULL.  For ext4_d_hash() this
resulted in a reproducible NULL dereference if a lookup is done in a
directory being deleted, e.g. with:

	int main()
	{
		if (fork()) {
			for (;;) {
				mkdir("subdir", 0700);
				rmdir("subdir");
			}
		} else {
			for (;;)
				access("subdir/file", 0);
		}
	}

... or by running the 't_encrypted_d_revalidate' program from xfstests.
Both repros work in any directory on a filesystem with the encoding
feature, even if the directory doesn't actually have the casefold flag.

I couldn't reproduce a crash in ext4_d_compare(), but it appears that a
similar crash is possible there.

Fix these bugs by reading ->d_parent and ->d_inode using READ_ONCE() and
falling back to the case sensitive behavior if the inode is NULL.

Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Fixes: b886ee3e77 ("ext4: Support case-insensitive file name lookups")
Cc: <stable@vger.kernel.org> # v5.2+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://lore.kernel.org/r/20200124041234.159740-1-ebiggers@kernel.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-11 04:35:32 -08:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile ext4: add basic fs-verity support 2019-08-12 19:33:50 -07:00
acl.c
acl.h
balloc.c ext4: clean up kerneldoc warnigns when building with W=1 2019-06-19 16:30:03 -04:00
bitmap.c
block_validity.c ext4: fix potential use after free after remounting with noblock_validity 2019-08-28 11:13:24 -04:00
dir.c ext4: fix race conditions in ->d_compare() and ->d_hash() 2020-02-11 04:35:32 -08:00
ext4.h Added new ext4 debugging ioctls to allow userspace to get information 2019-09-21 13:37:39 -07:00
ext4_extents.h
ext4_jbd2.c
ext4_jbd2.h ext4: use jbd2_inode dirty range scoping 2019-06-20 17:26:26 -04:00
extents.c ext4: fix warning inside ext4_convert_unwritten_extents_endio 2019-08-22 22:53:46 -04:00
extents_status.c ext4: use percpu_counters for extent_status cache hits/misses 2019-08-28 11:19:23 -04:00
extents_status.h ext4: use percpu_counters for extent_status cache hits/misses 2019-08-28 11:19:23 -04:00
file.c Added new ext4 debugging ioctls to allow userspace to get information 2019-09-21 13:37:39 -07:00
fsmap.c ext4: fix miscellaneous sparse warnings 2019-05-12 04:49:47 -04:00
fsmap.h
fsync.c
hash.c ext4: fix kernel oops caused by spurious casefold flag 2019-09-03 01:43:17 -04:00
ialloc.c ext4: fix leak of quota reservations 2019-12-17 19:56:53 +01:00
indirect.c ext4: clean up kerneldoc warnigns when building with W=1 2019-06-19 16:30:03 -04:00
inline.c ext4: set error return correctly when ext4_htree_store_dirent fails 2019-08-12 14:29:38 -04:00
inode.c ext4: iomap that extends beyond EOF should be marked dirty 2020-01-04 19:17:13 +01:00
ioctl.c Added new ext4 debugging ioctls to allow userspace to get information 2019-09-21 13:37:39 -07:00
mballoc.c ext4: clean up kerneldoc warnigns when building with W=1 2019-06-19 16:30:03 -04:00
mballoc.h
migrate.c
mmp.c
move_extent.c ext4: use jbd2_inode dirty range scoping 2019-06-20 17:26:26 -04:00
namei.c ext4: fix ext4_empty_dir() for directories with holes 2019-12-31 16:46:16 +01:00
page-io.c ext4: fix deadlock allocating crypto bounce page from mempool 2020-02-11 04:35:32 -08:00
readpage.c ext4: add fs-verity read support 2019-08-12 19:33:51 -07:00
resize.c Add as a feature case-insensitive directories (the casefold feature) 2019-05-07 21:12:44 -07:00
super.c ext4: validate the debug_want_extra_isize mount option at parse time 2019-12-31 16:46:19 +01:00
symlink.c
sysfs.c ext4: add basic fs-verity support 2019-08-12 19:33:50 -07:00
truncate.h
verity.c ext4: add basic fs-verity support 2019-08-12 19:33:50 -07:00
xattr.c
xattr.h
xattr_security.c
xattr_trusted.c
xattr_user.c