linux-stable/fs/ext4
yangerkun 7362dd8a9b ext4: fix potential infinite loop in ext4_dx_readdir()
commit 42cb447410 upstream.

When ext4_htree_fill_tree() fails, ext4_dx_readdir() can run into an
infinite loop since if info->last_pos != ctx->pos this will reset the
directory scan and reread the failing entry.  For example:

1. a dx_dir which has 3 block, block 0 as dx_root block, block 1/2 as
   leaf block which own the ext4_dir_entry_2
2. block 1 read ok and call_filldir which will fill the dirent and update
   the ctx->pos
3. block 2 read fail, but we has already fill some dirent, so we will
   return back to userspace will a positive return val(see ksys_getdents64)
4. the second ext4_dx_readdir will reset the world since info->last_pos
   != ctx->pos, and will also init the curr_hash which pos to block 1
5. So we will read block1 too, and once block2 still read fail, we can
   only fill one dirent because the hash of the entry in block1(besides
   the last one) won't greater than curr_hash
6. this time, we forget update last_pos too since the read for block2
   will fail, and since we has got the one entry, ksys_getdents64 can
   return success
7. Latter we will trapped in a loop with step 4~6

Cc: stable@kernel.org
Signed-off-by: yangerkun <yangerkun@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Link: https://lore.kernel.org/r/20210914111415.3921954-1-yangerkun@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-06 15:05:09 +02:00
..
acl.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
acl.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
balloc.c ext4: fix potential race between online resizing and write operations 2020-03-11 18:02:42 +01:00
bitmap.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
block_validity.c ext4: check journal inode extents more carefully 2021-03-24 11:04:54 +01:00
dir.c ext4: fix potential infinite loop in ext4_dx_readdir() 2021-10-06 15:05:09 +02:00
ext4.h ext4: check journal inode extents more carefully 2021-03-24 11:04:54 +01:00
ext4_extents.h ext4: fix EXT_MAX_EXTENT/INDEX to check for zeroed eh_max 2020-06-20 10:25:15 +02:00
ext4_jbd2.c ext4: shutdown should not prevent get_write_access 2018-04-24 09:36:30 +02:00
ext4_jbd2.h ext4: use jbd2_inode dirty range scoping 2019-07-31 07:28:47 +02:00
extents.c ext4: fix kernel infoleak via ext4_extent_header 2021-07-20 16:17:28 +02:00
extents_status.c ext4: remove check for zero nr_to_scan in ext4_es_scan() 2021-07-20 16:17:28 +02:00
extents_status.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c ext4: fix ext4_dax_read/write inode locking sequence for IOCB_NOWAIT 2020-02-28 16:35:55 +01:00
fsmap.c ext4: limit entries returned when counting fsmap records 2020-10-29 09:07:11 +01:00
fsmap.h ext4: support GETFSMAP ioctls 2017-04-30 00:36:53 -04:00
fsync.c ext4: fix race between ext4_sync_parent() and rename() 2020-06-20 10:25:15 +02:00
hash.c ext4: remove useless test and assignment in strtohash functions 2017-08-24 15:11:34 -04:00
ialloc.c ext4: fix avefreec in find_group_orlov 2021-07-20 16:17:29 +02:00
indirect.c ext4: check journal inode extents more carefully 2021-03-24 11:04:54 +01:00
inline.c ext4: fix race writing to an inline_data file while its xattrs are changing 2021-09-22 11:45:14 +02:00
inode.c ext4: fix bh ref count on error paths 2021-04-07 12:47:00 +02:00
ioctl.c ext4: fix superblock checksum failure when setting password salt 2021-01-23 15:48:44 +01:00
Kconfig
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mballoc.c ext4: use ext4_grp_locked_error in mb_find_extent 2021-07-20 16:17:29 +02:00
mballoc.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
migrate.c ext4: fix race between writepages and enabling EXT4_EXTENTS_FL 2020-02-28 16:36:13 +01:00
mmp.c ext4: don't assume that mmp_nodename/bdevname have NUL 2020-02-28 16:35:52 +01:00
move_extent.c ext4: use jbd2_inode dirty range scoping 2019-07-31 07:28:47 +02:00
namei.c ext4: fix potential htree corruption when growing large_dir directories 2021-08-15 13:03:31 +02:00
page-io.c ext4: fix deadlock allocating crypto bounce page from mempool 2020-02-14 16:32:19 -05:00
readpage.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
resize.c ext4: fix error handling code in add_new_gdb 2020-11-05 11:07:04 +01:00
super.c ext4: cleanup in-core orphan list if ext4_truncate() failed to get a transaction handle 2021-07-20 16:17:28 +02:00
symlink.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sysfs.c ext4: sysfs: print ext4_super_block fields as little-endian 2018-09-05 09:26:36 +02:00
truncate.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xattr.c ext4: add reclaim checks to xattr code 2021-03-30 14:40:12 +02:00
xattr.h ext4: add extra checks to ext4_xattr_block_get() 2018-04-24 09:36:31 +02:00
xattr_security.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xattr_trusted.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xattr_user.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00