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
Makefile
acl.c
acl.h
balloc.c
bitmap.c
block_validity.c
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
extents.c
extents_status.c
extents_status.h
file.c Added new ext4 debugging ioctls to allow userspace to get information 2019-09-21 13:37:39 -07:00
fsmap.c
fsmap.h
fsync.c
hash.c
ialloc.c ext4: fix leak of quota reservations 2019-12-17 19:56:53 +01:00
indirect.c
inline.c
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
mballoc.h
migrate.c
mmp.c
move_extent.c
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
resize.c
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
truncate.h
verity.c
xattr.c
xattr.h
xattr_security.c
xattr_trusted.c
xattr_user.c