linux/fs/ext4
Deepanshu Kartikey de985264ee ext4: detect invalid INLINE_DATA + EXTENTS flag combination
commit 1d3ad18394 upstream.

syzbot reported a BUG_ON in ext4_es_cache_extent() when opening a verity
file on a corrupted ext4 filesystem mounted without a journal.

The issue is that the filesystem has an inode with both the INLINE_DATA
and EXTENTS flags set:

    EXT4-fs error (device loop0): ext4_cache_extents:545: inode #15:
    comm syz.0.17: corrupted extent tree: lblk 0 < prev 66

Investigation revealed that the inode has both flags set:
    DEBUG: inode 15 - flag=1, i_inline_off=164, has_inline=1, extents_flag=1

This is an invalid combination since an inode should have either:
- INLINE_DATA: data stored directly in the inode
- EXTENTS: data stored in extent-mapped blocks

Having both flags causes ext4_has_inline_data() to return true, skipping
extent tree validation in __ext4_iget(). The unvalidated out-of-order
extents then trigger a BUG_ON in ext4_es_cache_extent() due to integer
underflow when calculating hole sizes.

Fix this by detecting this invalid flag combination early in ext4_iget()
and rejecting the corrupted inode.

Cc: stable@kernel.org
Reported-and-tested-by: syzbot+038b7bf43423e132b308@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=038b7bf43423e132b308
Suggested-by: Zhang Yi <yi.zhang@huawei.com>
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Message-ID: <20250930112810.315095-1-kartikey406@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-10-23 16:20:19 +02:00
..
.kunitconfig ext4: add .kunitconfig fragment to enable ext4-specific tests 2021-02-11 23:16:30 -05:00
acl.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
acl.h Revert "ext4: apply umask if ACL support is disabled" 2024-05-02 18:25:39 -04:00
balloc.c ext4: reorder capability check last 2025-05-29 11:02:15 +02:00
bitmap.c ext4: move checksum length calculation of inode bitmap into ext4_inode_bitmap_csum_[verify/set]() functions 2024-09-03 22:12:15 -04:00
block_validity.c ext4: make block validity check resistent to sb bh corruption 2025-05-02 07:59:25 +02:00
crypto.c ext4: Move CONFIG_UNICODE defguards into the code flow 2024-06-07 17:00:45 +02:00
dir.c ext4: fix OOB read when checking dotdot dir 2025-04-10 14:39:39 +02:00
ext4.h ext4: add ext4_sb_bread_nofail() helper function for ext4_free_branches() 2025-10-19 16:33:59 +02:00
ext4_extents.h ext4: fix sparse warnings 2021-08-30 23:36:50 -04:00
ext4_jbd2.c ext4: wait for ongoing I/O to complete before freeing blocks 2025-10-23 16:20:19 +02:00
ext4_jbd2.h ext4: avoid journaling sb update on error if journal is destroying 2025-09-09 18:58:20 +02:00
extents.c ext4: correct the error handle in ext4_fallocate() 2025-08-01 09:48:46 +01:00
extents_status.c ext4: drop all delonly descriptions 2024-09-02 15:26:15 -04:00
extents_status.h ext4: drop ext4_es_is_delonly() 2024-09-02 15:26:14 -04:00
fast_commit.c ext4: use handle to mark fc as ineligible in __track_dentry_update() 2024-10-04 17:35:54 -04:00
fast_commit.h ext4: add missing validation of fast-commit record lengths 2022-12-08 21:49:24 -05:00
file.c ext4: fix checks for orphan inodes 2025-10-15 12:00:22 +02:00
fsmap.c ext4: correctly handle queries for metadata mappings 2025-10-19 16:33:59 +02:00
fsmap.h ext4: fsmap: fix the block/inode bitmap comment 2021-06-24 09:48:29 -04:00
fsync.c ext4: drop EXT4_MF_FS_ABORTED flag 2023-07-29 18:37:53 -04:00
hash.c ext4: remove redundant checks of s_encoding 2023-08-27 11:27:13 -04:00
ialloc.c ext4: fix race in buffer_head read fault injection 2024-12-05 14:01:15 +01:00
indirect.c ext4: add ext4_sb_bread_nofail() helper function for ext4_free_branches() 2025-10-19 16:33:59 +02:00
inline.c ext4: do not BUG when INLINE_DATA_FL lacks system.data xattr 2025-08-20 18:30:41 +02:00
inode-test.c ext4: add missing MODULE_DESCRIPTION() 2024-07-05 16:07:24 -04:00
inode.c ext4: detect invalid INLINE_DATA + EXTENTS flag combination 2025-10-23 16:20:19 +02:00
ioctl.c introduce fd_file(), convert all accessors to it. 2024-08-12 22:00:43 -04:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile ext4: move ext4 crypto code to its own file crypto.c 2022-05-21 22:24:24 -04:00
mballoc-test.c ext4: initialize superblock fields in the kballoc-test.c kunit tests 2025-08-20 18:30:52 +02:00
mballoc.c ext4: fix largest free orders lists corruption on mb_optimize_scan switch 2025-08-20 18:30:52 +02:00
mballoc.h ext4: fix FS_IOC_GETFSMAP handling 2024-12-05 14:02:41 +01:00
migrate.c ext4: fix i_data_sem unlock order in ext4_ind_migrate() 2024-09-03 22:14:17 -04:00
mmp.c ext4: fix race in buffer_head read fault injection 2024-12-05 14:01:15 +01:00
move_extent.c ext4: fix an off-by-one issue during moving extents 2025-10-19 16:33:59 +02:00
namei.c ext4: introduce linear search for dentries 2025-09-19 16:35:42 +02:00
orphan.c ext4: free orphan info with kvfree 2025-10-19 16:34:00 +02:00
page-io.c ext4: do not convert the unwritten extents if data writeback fails 2025-05-29 11:02:19 +02:00
readpage.c ext4: reduce stack usage in ext4_mpage_readpages() 2024-08-26 21:47:03 -04:00
resize.c ext4: fix race in buffer_head read fault injection 2024-12-05 14:01:15 +01:00
super.c ext4: avoid potential buffer over-read in parse_apply_sb_mount_options() 2025-10-19 16:33:59 +02:00
symlink.c ext4_get_link(): fix breakage in RCU mode 2024-02-25 02:10:32 -05:00
sysfs.c ext4: add positive int attr pointer to avoid sysfs variables overflow 2024-05-02 23:48:30 -04:00
truncate.h ext4: Convert to use mapping->invalidate_lock 2021-07-13 14:29:00 +02:00
verity.c fs: Convert aops->write_begin to take a folio 2024-08-07 11:33:21 +02:00
xattr.c ext4: validate ea_ino and size in check_xattrs 2025-10-19 16:34:00 +02:00
xattr.h ext4: annotate struct ext4_xattr_inode_array with __counted_by() 2024-08-26 23:40:06 -04:00
xattr_hurd.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_security.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_trusted.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00
xattr_user.c fs: port xattr to mnt_idmap 2023-01-19 09:24:28 +01:00