linux-stable/fs
Shida Zhang bf9b9a091e ext4: fix rec_len verify error
commit 7fda67e8c3 upstream.

With the configuration PAGE_SIZE 64k and filesystem blocksize 64k,
a problem occurred when more than 13 million files were directly created
under a directory:

EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt?  Run e2fsck -D.
EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt?  Run e2fsck -D.
EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum

When enough files are created, the fake_dirent->reclen will be 0xffff.
it doesn't equal to the blocksize 65536, i.e. 0x10000.

But it is not the same condition when blocksize equals to 4k.
when enough files are created, the fake_dirent->reclen will be 0x1000.
it equals to the blocksize 4k, i.e. 0x1000.

The problem seems to be related to the limitation of the 16-bit field
when the blocksize is set to 64k.
To address this, helpers like ext4_rec_len_{from,to}_disk has already
been introduced to complete the conversion between the encoded and the
plain form of rec_len.

So fix this one by using the helper, and all the other in this file too.

Cc: stable@kernel.org
Fixes: dbe8944404 ("ext4: Calculate and verify checksums for htree nodes")
Suggested-by: Andreas Dilger <adilger@dilger.ca>
Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/20230803060938.1929759-1-zhangshida@kylinos.cn
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-10 21:43:40 +02:00
..
9p 9p: missing chunk of "fs/9p: Don't update file type when updating file attributes" 2022-06-25 11:46:24 +02:00
adfs fs/adfs: super: fix use-after-free bug 2019-08-06 19:05:21 +02:00
affs affs: initialize fsdata in affs_truncate() 2023-02-06 07:46:28 +01:00
afs treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
autofs4 autofs: fix memory leak of waitqueues in autofs_catatonic_mode 2023-09-23 10:47:03 +02:00
befs
bfs
btrfs btrfs: properly report 0 avail for very full file systems 2023-10-10 21:43:40 +02:00
cachefiles cachefiles: Handle readpage error correctly 2020-11-05 11:07:05 +01:00
ceph ceph: fix use-after-free bug for inodes when flushing capsnaps 2023-06-14 10:35:26 +02:00
cifs cifs: add a warning when the in-flight count goes negative 2023-09-23 10:46:54 +02:00
coda coda: add error handling for fget 2019-08-06 19:05:23 +02:00
configfs configfs: fix a race in configfs_{,un}register_subsystem() 2022-03-02 11:33:56 +01:00
cramfs
crypto fscrypt: don't ignore minor_hash when hash is 0 2021-07-20 16:17:45 +02:00
debugfs debugfs: fix use-after-free on symlink traversal 2019-05-08 07:20:49 +02:00
devpts fs/devpts: always delete dcache dentry-s in dput() 2019-03-23 14:35:21 +01:00
dlm fs: dlm: return positive pid value for F_GETLK 2023-08-11 11:33:45 +02:00
ecryptfs Revert "ecryptfs: replace BUG_ON with error handling code" 2021-05-26 11:47:00 +02:00
efivarfs efivarfs: revert "fix memory leak in efivarfs_create()" 2020-12-02 08:34:44 +01:00
efs
exofs exofs_mount(): fix leaks on failure exits 2019-12-05 15:37:28 +01:00
exportfs exportfs: fix 'passing zero to ERR_PTR()' warning 2020-01-27 14:46:06 +01:00
ext2 ext2: fix datatype of block number in ext2_xattr_set2() 2023-09-23 10:47:04 +02:00
ext4 ext4: fix rec_len verify error 2023-10-10 21:43:40 +02:00
f2fs f2fs: fix information leak in f2fs_move_inline_dirents() 2023-03-11 16:26:44 +01:00
fat treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
freevxfs
fscache
fuse fuse: revalidate: don't invalidate if interrupted 2023-08-11 11:33:47 +02:00
gfs2 gfs2: Fix possible data races in gfs2_show_options() 2023-08-30 16:35:11 +02:00
hfs hfs: fix missing hfs_bnode_get() in __hfs_bnode_create 2023-03-11 16:26:44 +01:00
hfsplus treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
hostfs
hpfs
hugetlbfs hugetlbfs: hugetlb_fault_mutex_hash() cleanup 2021-06-03 08:36:25 +02:00
isofs treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
jbd2 jbd2: fix assertion 'jh->b_frozen_data == NULL' failure when journal aborted 2022-08-25 11:11:23 +02:00
jffs2 jffs2: reduce stack usage in jffs2_build_xattr_subsystem() 2023-08-11 11:33:41 +02:00
jfs jfs: fix invalid free of JFS_IP(ipimap)->i_imap in diUnmount 2023-09-23 10:47:04 +02:00
kernfs kernfs: fix use-after-free in __kernfs_remove 2022-11-03 23:50:53 +09:00
lockd fs: lockd: avoid possible wrong NULL parameter 2023-09-23 10:46:57 +02:00
minix fs/minix: reject too-large maximum file size 2020-08-21 09:48:15 +02:00
ncpfs
nfs NFS/pNFS: Report EINVAL errors from connect() to the server 2023-10-10 21:43:38 +02:00
nfs_common nfs_common: need lock during iterate through the list 2020-12-29 13:47:01 +01:00
nfsd nfsd: fix change_info in NFSv4 RENAME replies 2023-09-23 10:47:05 +02:00
nilfs2 nilfs2: fix potential use after free in nilfs_gccache_submit_read_data() 2023-10-10 21:43:40 +02:00
nls fs/nls: make load_nls() take a const parameter 2023-09-23 10:46:53 +02:00
notify fsnotify: fix wrong lockdep annotations 2022-06-14 16:53:48 +02:00
ntfs ntfs: check overflow when iterating ATTR_RECORDs 2022-11-25 17:36:55 +01:00
ocfs2 fs: ocfs2: namei: check return value of ocfs2_add_entry() 2023-09-23 10:46:55 +02:00
omfs treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
openpromfs
orangefs orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string() 2023-01-18 09:26:33 +01:00
overlayfs ovl: fix missing negative dentry check in ovl_rename() 2021-10-17 10:08:32 +02:00
proc procfs: block chmod on /proc/thread-self/comm 2023-09-23 10:47:00 +02:00
pstore pstore/ram: Check start of empty przs during init 2023-09-23 10:47:01 +02:00
qnx4 qnx4: work around gcc false positive warning bug 2021-10-06 15:05:08 +02:00
qnx6
quota quota: fix warning in dqgrab() 2023-08-30 16:35:09 +02:00
ramfs ramfs: fix nommu mmap with gaps in the page cache 2020-10-29 09:07:11 +01:00
reiserfs reiserfs: Check the return value from __getblk() 2023-09-23 10:46:54 +02:00
romfs romfs: fix uninitialized memory leak in romfs_dev_read() 2020-08-26 10:29:54 +02:00
squashfs revert "squashfs: harden sanity check in squashfs_read_xattr_id_table" 2023-02-22 12:46:05 +01:00
sysfs fs: sysfs_emit_at: Remove PAGE_SIZE alignment check 2023-03-22 13:26:13 +01:00
sysv fs/sysv: Null check to prevent null-ptr-deref bug 2023-08-11 11:33:56 +02:00
tracefs tracefs: Only clobber mode/uid/gid on remount if asked 2022-09-20 11:51:31 +02:00
ubifs treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
udf udf: Handle error when adding extent to a file 2023-09-23 10:46:54 +02:00
ufs fs/ufs: avoid potential u32 multiplication overflow 2020-08-21 09:48:22 +02:00
xfs treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
aio.c aio: fix mremap after fork null-deref 2023-02-22 12:46:05 +01:00
anon_inodes.c
attr.c attr: block mode changes of symlinks 2023-09-23 10:47:05 +02:00
bad_inode.c
binfmt_aout.c
binfmt_elf.c fs/binfmt_elf.c: allocate initialized memory in fill_thread_core_info() 2020-06-03 08:18:03 +02:00
binfmt_elf_fdpic.c fs: binfmt_elf_efpic: fix personality for ELF-FDPIC 2023-10-10 21:43:40 +02:00
binfmt_em86.c
binfmt_flat.c binfmt_flat: do not stop relocating GOT entries prematurely on riscv 2022-06-14 16:53:43 +02:00
binfmt_misc.c binfmt_misc: fix shift-out-of-bounds in check_special_flags 2023-01-18 09:26:29 +01:00
binfmt_script.c exec: load_script: Do not exec truncated interpreter path 2019-11-06 12:42:59 +01:00
block_dev.c block: reexpand iov_iter after read/write 2021-05-22 10:57:43 +02:00
buffer.c mm: fs: initialize fsdata passed to write_begin/write_end interface 2022-11-25 17:36:55 +01:00
char_dev.c chardev: fix error handling in cdev_device_add() 2023-01-18 09:26:24 +01:00
compat.c
compat_binfmt_elf.c
compat_ioctl.c fix compat handling of FICLONERANGE, FIDEDUPERANGE and FS_IOC_FIEMAP 2020-01-09 10:17:58 +01:00
coredump.c coredump: fix crash when umh is disabled 2020-05-20 08:16:58 +02:00
dax.c dax: pass NOWAIT flag to iomap_apply 2020-03-11 18:02:43 +01:00
dcache.c
dcookies.c
direct-io.c fs: direct-io: fix missing sdio->boundary 2021-04-16 11:57:48 +02:00
drop_caches.c fs: avoid softlockups in s_inodes iterators 2020-01-12 12:11:59 +01:00
eventfd.c
eventpoll.c ep_create_wakeup_source(): dentry name can change under you... 2020-10-14 09:51:09 +02:00
exec.c exec: Force single empty string when argv is empty 2022-06-06 08:20:57 +02:00
fcntl.c
fhandle.c
file.c fs: prevent out-of-bounds array speculation when closing a file descriptor 2023-03-17 08:30:36 +01:00
file_table.c fs: add fget_many() and fput_many() 2021-12-08 08:46:55 +01:00
filesystems.c fs/filesystems.c: downgrade user-reachable WARN_ONCE() to pr_warn_once() 2020-04-24 08:00:43 +02:00
fs-writeback.c writeback: fix call of incorrect macro 2023-05-17 11:11:48 +02:00
fs_pin.c
fs_struct.c
inode.c fs: fix UAF/GPF bug in nilfs_mdt_destroy 2022-10-26 13:16:51 +02:00
internal.h
ioctl.c
iomap.c iomap: Fix pipe page leakage during splicing 2019-12-17 20:38:57 +01:00
Kconfig
Kconfig.binfmt
libfs.c libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value 2023-01-18 09:26:10 +01:00
locks.c locks: print unsigned ino in /proc/locks 2020-01-09 10:17:55 +01:00
Makefile
mbcache.c
mount.h
mpage.c
namei.c fs: Fix error checking for d_hash_and_lookup() 2023-09-23 10:46:54 +02:00
namespace.c VFS: Fix memory leak caused by concurrently mounting fs with subtype 2022-05-15 19:40:27 +02:00
no-block.c
nsfs.c
open.c cifs_atomic_open(): fix double-put on late allocation failure 2020-03-20 10:54:16 +01:00
pipe.c pipe: increase minimum default pipe size to 2 pages 2021-08-15 13:03:31 +02:00
pnode.c pnode: terminate at peers of source 2023-01-18 09:26:35 +01:00
pnode.h
posix_acl.c
proc_namespace.c
read_write.c vfs: avoid problematic remapping requests into partial EOF block 2019-12-01 09:13:51 +01:00
readdir.c readdir: make sure to verify directory entry for legacy interfaces too 2021-04-28 12:08:41 +02:00
select.c kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data() 2021-03-24 11:05:05 +01:00
seq_file.c seq_file: disallow extremely large seq buffer allocations 2021-07-20 16:17:55 +02:00
signalfd.c signalfd: use wake_up_pollfree() 2021-12-14 10:16:55 +01:00
splice.c Revert "fs: check FMODE_LSEEK to control internal pipe splicing" 2022-10-26 13:16:56 +02:00
stack.c
stat.c stat: fix inconsistency between struct stat and struct compat_stat 2022-04-27 13:15:30 +02:00
statfs.c statfs: enforce statfs[64] structure initialization 2023-05-30 12:38:36 +01:00
super.c vfs: make freeze_super abort when sync_filesystem returns error 2022-02-23 11:57:33 +01:00
sync.c
timerfd.c
userfaultfd.c userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK 2020-01-04 13:59:58 +01:00
utimes.c
xattr.c fs: don't audit the capability check in simple_xattr_list() 2023-01-18 09:26:09 +01:00