linux/fs/ext4
Baokun Li 0c0b4a49d3 ext4: fix mb_cache_entry's e_refcnt leak in ext4_xattr_block_cache_find()
Syzbot reports a warning as follows:

============================================
WARNING: CPU: 0 PID: 5075 at fs/mbcache.c:419 mb_cache_destroy+0x224/0x290
Modules linked in:
CPU: 0 PID: 5075 Comm: syz-executor199 Not tainted 6.9.0-rc6-gb947cc5bf6d7
RIP: 0010:mb_cache_destroy+0x224/0x290 fs/mbcache.c:419
Call Trace:
 <TASK>
 ext4_put_super+0x6d4/0xcd0 fs/ext4/super.c:1375
 generic_shutdown_super+0x136/0x2d0 fs/super.c:641
 kill_block_super+0x44/0x90 fs/super.c:1675
 ext4_kill_sb+0x68/0xa0 fs/ext4/super.c:7327
[...]
============================================

This is because when finding an entry in ext4_xattr_block_cache_find(), if
ext4_sb_bread() returns -ENOMEM, the ce's e_refcnt, which has already grown
in the __entry_find(), won't be put away, and eventually trigger the above
issue in mb_cache_destroy() due to reference count leakage.

So call mb_cache_entry_put() on the -ENOMEM error branch as a quick fix.

Reported-by: syzbot+dd43bd0f7474512edc47@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=dd43bd0f7474512edc47
Fixes: fb265c9cb4 ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases")
Cc: stable@kernel.org
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240504075526.2254349-2-libaokun@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2024-05-07 15:59:18 -04: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: add some kunit stub for mballoc kunit test 2023-10-05 22:32:16 -04:00
bitmap.c ext4: remove useless conditional branch code 2023-04-19 23:39:08 -04:00
block_validity.c ext4: add correct group descriptors and reserved GDT blocks to system zone 2023-08-27 11:27:12 -04:00
crypto.c fscrypt: support crypto data unit size less than filesystem block size 2023-09-25 22:34:33 -07:00
dir.c ext4: fix spelling errors in comments 2022-05-11 15:19:06 -04:00
ext4_extents.h ext4: fix sparse warnings 2021-08-30 23:36:50 -04:00
ext4_jbd2.c ext4: move ext4_check_bdev_write_error() into nojournal mode 2024-01-04 23:42:21 -05:00
ext4_jbd2.h ext4: split ext4_journal_start trace for debug 2022-12-01 10:46:54 -05:00
ext4.h ext4: use correct criteria name instead stale integer number in comment 2024-05-03 00:12:32 -04:00
extents_status.c Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
extents_status.h ext4: make ext4_es_insert_extent() return void 2023-06-26 19:35:12 -04:00
extents.c ext4: set the type of max_zeroout to unsigned int to avoid overflow 2024-05-02 23:48:31 -04:00
fast_commit.c ext4: make state in ext4_mb_mark_bb to be bool 2023-10-05 22:32:15 -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: replace deprecated strncpy with alternatives 2024-05-02 23:55:10 -04:00
fsmap.c ext4: port block device access to file 2024-02-25 12:05:26 +01: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: convert to new timestamp accessors 2023-10-18 13:26:21 +02:00
indirect.c ext4: remove unnecessary parameter "needed" in ext4_discard_preallocations 2024-01-18 10:52:45 -05:00
inline.c mm: add folio_zero_tail() and use it in ext4 2023-12-10 16:51:36 -08:00
inode-test.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
inode.c ext4: remove the redundant folio_wait_stable() 2024-05-07 15:48:04 -04:00
ioctl.c ext4: replace deprecated strncpy with alternatives 2024-05-02 23:55:10 -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: add test_mb_mark_used_cost to estimate cost of mb_mark_used 2024-05-03 00:12:32 -04:00
mballoc.c ext4: fix potential unnitialized variable 2024-05-07 15:44:40 -04:00
mballoc.h ext4: convert ac_buddy_page to ac_buddy_folio 2024-05-07 15:38:17 -04:00
migrate.c ext4: avoid deadlock in fs reclaim with page writeback 2023-05-13 18:05:04 -04:00
mmp.c ext4: replace read-only check for shutdown check in mmp code 2023-07-29 18:37:53 -04:00
move_extent.c ext4: remove unnecessary parameter "needed" in ext4_discard_preallocations 2024-01-18 10:52:45 -05:00
namei.c ext4: avoid excessive credit estimate in ext4_tmpfile() 2024-05-02 14:49:16 -04:00
orphan.c ext4: remove trailing newline from ext4_msg() message 2022-12-08 21:49:23 -05:00
page-io.c fs: convert block_write_full_page to block_write_full_folio 2023-12-29 11:58:35 -08:00
readpage.c ext4: use folio_end_read() 2023-10-18 14:34:16 -07:00
resize.c ext4: enable meta_bg only when new desc blocks are needed 2024-03-07 13:32:54 -05:00
super.c ext4: replace deprecated strncpy with alternatives 2024-05-02 23:55:10 -04: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 - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07: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
xattr.c ext4: fix mb_cache_entry's e_refcnt leak in ext4_xattr_block_cache_find() 2024-05-07 15:59:18 -04:00
xattr.h ext4: move ext4_xattr_handlers to .rodata 2023-10-09 16:24:16 +02:00