[syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry

24 views
Skip to first unread message

syzbot

unread,
Feb 20, 2024, 1:41:16 AMFeb 20
to dmitry....@gmail.com, eric.s...@oracle.com, jmo...@namei.org, linux-i...@vger.kernel.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, robert...@huawei.com, se...@hallyn.com, syzkall...@googlegroups.com, zo...@linux.ibm.com
Hello,

syzbot found the following issue on:

HEAD commit: 4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
kernel config: https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/34924e0466d4/disk-4f5e5092.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/29d0b1935c61/vmlinux-4f5e5092.xz
kernel image: https://storage.googleapis.com/syzbot-assets/2e033c3d8679/bzImage-4f5e5092.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+7bc44a...@syzkaller.appspotmail.com

=====================================================
BUG: KMSAN: uninit-value in ima_add_template_entry+0x52b/0x870 security/integrity/ima/ima_queue.c:172
ima_add_template_entry+0x52b/0x870 security/integrity/ima/ima_queue.c:172
ima_store_template security/integrity/ima/ima_api.c:122 [inline]
ima_store_measurement+0x371/0x8d0 security/integrity/ima/ima_api.c:376
process_measurement+0x2c6e/0x3ef0 security/integrity/ima/ima_main.c:367
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

<Zero or more stacks not recorded to save memory>

Uninit was stored to memory at:
sha256_transform lib/crypto/sha256.c:117 [inline]
sha256_transform_blocks+0x2dbf/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
sha256_transform lib/crypto/sha256.c:117 [inline]
sha256_transform_blocks+0x2dbf/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:91 [inline]
sha256_transform_blocks+0xf33/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:92 [inline]
sha256_transform_blocks+0xf7d/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:93 [inline]
sha256_transform_blocks+0xfb5/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
LOAD_OP lib/crypto/sha256.c:56 [inline]
sha256_transform lib/crypto/sha256.c:82 [inline]
sha256_transform_blocks+0x2c35/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
memcpy_to_iter lib/iov_iter.c:65 [inline]
iterate_kvec include/linux/iov_iter.h:85 [inline]
iterate_and_advance2 include/linux/iov_iter.h:251 [inline]
iterate_and_advance include/linux/iov_iter.h:271 [inline]
_copy_to_iter+0x125a/0x2520 lib/iov_iter.c:186
copy_page_to_iter+0x419/0x870 lib/iov_iter.c:381
copy_folio_to_iter include/linux/uio.h:181 [inline]
filemap_read+0xbf4/0x14d0 mm/filemap.c:2654
generic_file_read_iter+0x136/0xad0 mm/filemap.c:2784
__kernel_read+0x724/0xce0 fs/read_write.c:434
integrity_kernel_read+0x77/0x90 security/integrity/iint.c:221
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:485 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1743/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was created at:
__alloc_pages+0x9a6/0xe00 mm/page_alloc.c:4590
alloc_pages_mpol+0x62b/0x9d0 mm/mempolicy.c:2133
alloc_pages mm/mempolicy.c:2204 [inline]
folio_alloc+0x1da/0x380 mm/mempolicy.c:2211
filemap_alloc_folio+0xa5/0x430 mm/filemap.c:975
page_cache_ra_unbounded+0x2cc/0x960 mm/readahead.c:247
do_page_cache_ra mm/readahead.c:299 [inline]
page_cache_ra_order+0xe31/0xee0 mm/readahead.c:544
ondemand_readahead+0x157d/0x1750 mm/readahead.c:666
page_cache_sync_ra+0x724/0x760 mm/readahead.c:693
page_cache_sync_readahead include/linux/pagemap.h:1300 [inline]
filemap_get_pages+0x4c4/0x2bd0 mm/filemap.c:2498
filemap_read+0x59e/0x14d0 mm/filemap.c:2594
generic_file_read_iter+0x136/0xad0 mm/filemap.c:2784
__kernel_read+0x724/0xce0 fs/read_write.c:434
integrity_kernel_read+0x77/0x90 security/integrity/iint.c:221
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:485 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1743/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3643 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3798
do_filp_open+0x20d/0x590 fs/namei.c:3825
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

CPU: 1 PID: 9243 Comm: syz-executor.3 Not tainted 6.8.0-rc4-syzkaller-00180-g4f5e5092fdbf #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
=====================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

Roberto Sassu

unread,
Feb 20, 2024, 5:41:08 AMFeb 20
to syzbot, dmitry....@gmail.com, eric.s...@oracle.com, jmo...@namei.org, linux-i...@vger.kernel.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, robert...@huawei.com, se...@hallyn.com, syzkall...@googlegroups.com, zo...@linux.ibm.com, linux-...@vger.kernel.org
If I understood what the report is saying (ima_calc_file_hash_tfm()):

while (offset < i_size) {
int rbuf_len;

rbuf_len = integrity_kernel_read(file, offset, rbuf, PAGE_SIZE);
if (rbuf_len < 0) {
rc = rbuf_len;
break;
}
if (rbuf_len == 0) { /* unexpected EOF */
rc = -EINVAL;
break;
}
offset += rbuf_len;

rc = crypto_shash_update(shash, rbuf, rbuf_len);
if (rc)
break;
}

we are reading a non-initialized rbuf, which should not happen because
integrity_kernel_read() returned a positive value (success).

The other information we have is that the filesystem in question uses
generic_file_read_iter() as read_iter method.

I would add the VFS people in CC, in case they have some ideas.

Thanks

Roberto

syzbot

unread,
Mar 2, 2024, 5:01:25 PMMar 2
to dmitry....@gmail.com, eric.s...@oracle.com, jmo...@namei.org, linux-...@vger.kernel.org, linux-i...@vger.kernel.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, robert...@huawei.com, robert...@huaweicloud.com, se...@hallyn.com, syzkall...@googlegroups.com, zo...@linux.ibm.com
syzbot has found a reproducer for the following issue on:

HEAD commit: 5ad3cb0ed525 Merge tag 'for-v6.8-rc2' of git://git.kernel...
git tree: upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=15fdefac180000
kernel config: https://syzkaller.appspot.com/x/.config?x=80c7a82a572c0de3
dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11917b26180000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1256096a180000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/a148235ac5b1/disk-5ad3cb0e.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/4b06f4d02ad6/vmlinux-5ad3cb0e.xz
kernel image: https://storage.googleapis.com/syzbot-assets/7fff06beed25/bzImage-5ad3cb0e.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/adece4ed9c9c/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+7bc44a...@syzkaller.appspotmail.com

erofs: (device loop0): mounted with root inode @ nid 36.
=====================================================
BUG: KMSAN: uninit-value in ima_add_template_entry+0x52b/0x870 security/integrity/ima/ima_queue.c:172
ima_add_template_entry+0x52b/0x870 security/integrity/ima/ima_queue.c:172
ima_store_template security/integrity/ima/ima_api.c:122 [inline]
ima_store_measurement+0x371/0x8d0 security/integrity/ima/ima_api.c:376
process_measurement+0x2c6e/0x3ef0 security/integrity/ima/ima_main.c:367
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

<Zero or more stacks not recorded to save memory>

Uninit was stored to memory at:
sha256_transform lib/crypto/sha256.c:117 [inline]
sha256_transform_blocks+0x2dbf/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
sha256_transform lib/crypto/sha256.c:117 [inline]
sha256_transform_blocks+0x2dbf/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:91 [inline]
sha256_transform_blocks+0xf33/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:92 [inline]
sha256_transform_blocks+0xf7d/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
BLEND_OP lib/crypto/sha256.c:61 [inline]
sha256_transform lib/crypto/sha256.c:93 [inline]
sha256_transform_blocks+0xfb5/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

Uninit was stored to memory at:
LOAD_OP lib/crypto/sha256.c:56 [inline]
sha256_transform lib/crypto/sha256.c:82 [inline]
sha256_transform_blocks+0x2c35/0x2e80 lib/crypto/sha256.c:127
lib_sha256_base_do_update include/crypto/sha256_base.h:63 [inline]
sha256_update+0x2fb/0x340 lib/crypto/sha256.c:136
crypto_sha256_update+0x37/0x60 crypto/sha256_generic.c:39
crypto_shash_update+0x75/0xa0 crypto/shash.c:70
ima_calc_file_hash_tfm security/integrity/ima/ima_crypto.c:496 [inline]
ima_calc_file_shash security/integrity/ima/ima_crypto.c:516 [inline]
ima_calc_file_hash+0x1816/0x3cc0 security/integrity/ima/ima_crypto.c:573
ima_collect_measurement+0x44d/0xdd0 security/integrity/ima/ima_api.c:290
process_measurement+0x2936/0x3ef0 security/integrity/ima/ima_main.c:359
ima_file_check+0xb3/0x100 security/integrity/ima/ima_main.c:557
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_open fs/namei.c:3647 [inline]
path_openat+0x4d09/0x5ad0 fs/namei.c:3802
do_filp_open+0x20d/0x590 fs/namei.c:3829
do_sys_openat2+0x1bf/0x2f0 fs/open.c:1404
do_sys_open fs/open.c:1419 [inline]
__do_sys_open fs/open.c:1427 [inline]
__se_sys_open fs/open.c:1423 [inline]
__x64_sys_open+0x275/0x2d0 fs/open.c:1423
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x63/0x6b

CPU: 0 PID: 5012 Comm: syz-executor394 Not tainted 6.8.0-rc6-syzkaller-00238-g5ad3cb0ed525 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
=====================================================


---
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

Tetsuo Handa

unread,
Mar 3, 2024, 9:54:58 AMMar 3
to syzbot, syzkall...@googlegroups.com, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, linux-...@vger.kernel.org, linux...@lists.ozlabs.org
On 2024/02/20 19:40, Roberto Sassu wrote:
> On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
>> Hello,
>>
>> syzbot found the following issue on:
>>
>> HEAD commit: 4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
>> git tree: upstream
>> console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
>> kernel config: https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
>> dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
>> compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

> I would add the VFS people in CC, in case they have some ideas.

This is an erofs bug. Since the filesystem image in the reproducer
is crafted, decompression generates bogus result and
z_erofs_transform_plain() misbehaves.

You can obtain a single-threaded reproducer from
https://syzkaller.appspot.com/x/repro.c?x=1256096a180000 with below diff.

----------------------------------------
--- old/1256096a180000.c
+++ new/1256096a180000.c
@@ -676,6 +676,6 @@
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
/*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
/*offset=*/0ul);
- loop();
+ execute_one();
return 0;
}
----------------------------------------

With CONFIG_EROFS_FS_DEBUG=y, the reproducer hits DBG_BUGON().
With debug printk() shown below, you can get output shown below.

----------------------------------------
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index d4cee95af14c..f221133a0731 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -323,7 +323,11 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
u8 *kin;

- DBG_BUGON(rq->outputsize > rq->inputsize);
+ if (rq->outputsize > rq->inputsize) {
+ pr_err("rq->inputsize=%u rq->outputsize=%u\n", rq->inputsize, rq->outputsize);
+ pr_err("rq->pageofs_in=%u rq->pageofs_out=%u\n", rq->pageofs_in, rq->pageofs_out);
+ pr_err("nrpages_in=%u nrpages_out=%u\n", nrpages_in, nrpages_out);
+ }
if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
cur = bs - (rq->pageofs_out & (bs - 1));
pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
@@ -352,7 +356,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
do {
no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
- DBG_BUGON(no >= nrpages_out);
+ if (no >= nrpages_out)
+ pr_err("no=%u nrpages_out=%u\n", no, nrpages_out);
cnt = min(insz - pi, PAGE_SIZE - po);
if (rq->out[no] == rq->in[ni]) {
memmove(kin + po,
@@ -366,7 +371,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
} while (pi < insz);
kunmap_local(kin);
}
- DBG_BUGON(ni > nrpages_in);
+ if (ni > nrpages_in)
+ pr_err("ni=%u nrpages_in=%u\n", ni, nrpages_in);
return 0;
}

----------------------------------------

----------------------------------------
[ 138.991810][ T2983] loop0: detected capacity change from 0 to 16
[ 139.804002][ T2983] erofs: (device loop0): mounted with root inode @ nid 36.
[ 139.810464][ T87] erofs: rq->inputsize=4096 rq->outputsize=8194
[ 139.821540][ T87] erofs: rq->pageofs_in=0 rq->pageofs_out=0
[ 139.824347][ T87] erofs: nrpages_in=1 nrpages_out=3
[ 139.827008][ T87] erofs: ni=3 nrpages_in=1
[ 139.873777][ T2983] =====================================================
[ 139.881268][ T2983] BUG: KMSAN: uninit-value in ima_add_template_entry+0x626/0xa80
----------------------------------------

#syz set subsystems: erofs

Gao Xiang

unread,
Mar 3, 2024, 6:53:54 PMMar 3
to Tetsuo Handa, syzbot, syzkall...@googlegroups.com, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, linux-...@vger.kernel.org, linux...@lists.ozlabs.org


On 2024/3/3 22:54, Tetsuo Handa wrote:
> On 2024/02/20 19:40, Roberto Sassu wrote:
>> On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
>>> Hello,
>>>
>>> syzbot found the following issue on:
>>>
>>> HEAD commit: 4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
>>> git tree: upstream
>>> console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
>>> kernel config: https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
>>> dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
>>> compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
>
>> I would add the VFS people in CC, in case they have some ideas.
>
> This is an erofs bug. Since the filesystem image in the reproducer
> is crafted, decompression generates bogus result and
> z_erofs_transform_plain() misbehaves.

Yes, thanks for looking into this. It seems it was introduced by
a new commit 1ca01520148a this cycle, let me find more clues and
make a fix for this.

Thanks,
Gao Xiang

Gao Xiang

unread,
Mar 3, 2024, 10:53:52 PMMar 3
to linux...@lists.ozlabs.org, LKML, linux-...@vger.kernel.org, Tetsuo Handa, Roberto Sassu, syzkall...@googlegroups.com, Gao Xiang, syzbot+7bc44a...@syzkaller.appspotmail.com
syzbot reports a KMSAN reproducer [1] which generates a crafted
filesystem image and causes IMA to read uninitialized page cache.

Later, (rq->outputsize > rq->inputsize) will be formally supported
after either large uncompressed pclusters (> block size) or big
lclusters are landed. However, currently there is no way to generate
such filesystems by using mkfs.erofs.

Thus, let's mark this condition as unsupported for now.

[1] https://lore.kernel.org/r/0000000000002b...@google.com

Reported-by: syzbot+7bc44a...@syzkaller.appspotmail.com
Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
Signed-off-by: Gao Xiang <hsia...@linux.alibaba.com>
---
fs/erofs/decompressor.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index d4cee95af14c..2ec9b2bb628d 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -323,7 +323,8 @@ static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
u8 *kin;

- DBG_BUGON(rq->outputsize > rq->inputsize);
+ if (rq->outputsize > rq->inputsize)
+ return -EOPNOTSUPP;
if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
cur = bs - (rq->pageofs_out & (bs - 1));
pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
--
2.39.3

Gao Xiang

unread,
Mar 4, 2024, 1:04:37 AMMar 4
to linux...@lists.ozlabs.org, syzkall...@googlegroups.com, syzbot+7bc44a...@syzkaller.appspotmail.com, Tetsuo Handa, LKML, Roberto Sassu

syzbot

unread,
Mar 4, 2024, 1:51:04 AMMar 4
to hsia...@linux.alibaba.com, linux...@lists.ozlabs.org, linux-...@vger.kernel.org, penguin...@i-love.sakura.ne.jp, robert...@huaweicloud.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+7bc44a...@syzkaller.appspotmail.com

Tested on:

commit: 4288d8d1 erofs: fix uninitialized page cache reported ..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
console output: https://syzkaller.appspot.com/x/log.txt?x=10893754180000
kernel config: https://syzkaller.appspot.com/x/.config?x=db27810a659d0b3d
dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40

Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.

Roberto Sassu

unread,
Mar 4, 2024, 3:15:46 AMMar 4
to Tetsuo Handa, syzbot, syzkall...@googlegroups.com, Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, linux-...@vger.kernel.org, linux...@lists.ozlabs.org, linux-i...@vger.kernel.org, zo...@linux.ibm.com
On Sun, 2024-03-03 at 23:54 +0900, Tetsuo Handa wrote:
> On 2024/02/20 19:40, Roberto Sassu wrote:
> > On Mon, 2024-02-19 at 22:41 -0800, syzbot wrote:
> > > Hello,
> > >
> > > syzbot found the following issue on:
> > >
> > > HEAD commit: 4f5e5092fdbf Merge tag 'net-6.8-rc5' of git://git.kernel.o..
> > > git tree: upstream
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=135ba81c180000
> > > kernel config: https://syzkaller.appspot.com/x/.config?x=e3dd779fba027968
> > > dashboard link: https://syzkaller.appspot.com/bug?extid=7bc44a489f0ef0670bd5
> > > compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
>
> > I would add the VFS people in CC, in case they have some ideas.
>
> This is an erofs bug. Since the filesystem image in the reproducer
> is crafted, decompression generates bogus result and
> z_erofs_transform_plain() misbehaves.

Thank you Tetsuo, and Gao Xiang for fixing it!

Roberto

Sandeep Dhavale

unread,
Mar 5, 2024, 4:28:04 AMMar 5
to Gao Xiang, linux...@lists.ozlabs.org, syzbot+7bc44a...@syzkaller.appspotmail.com, Tetsuo Handa, syzkall...@googlegroups.com, LKML, Roberto Sassu, linux-...@vger.kernel.org
LGTM.
Reviewed-by: Sandeep Dhavale <dha...@google.com>

Thanks,
Sandeep.

Yue Hu

unread,
Mar 5, 2024, 4:28:08 AMMar 5
to Gao Xiang, linux...@lists.ozlabs.org, syzbot+7bc44a...@syzkaller.appspotmail.com, Tetsuo Handa, syzkall...@googlegroups.com, LKML, Roberto Sassu, linux-...@vger.kernel.org
Reviewed-by: Yue Hu <huy...@coolpad.com>

Chao Yu

unread,
Mar 6, 2024, 8:05:01 PMMar 6
to Gao Xiang, linux...@lists.ozlabs.org, syzbot+7bc44a...@syzkaller.appspotmail.com, Tetsuo Handa, syzkall...@googlegroups.com, LKML, Roberto Sassu, linux-...@vger.kernel.org
On 2024/3/4 11:53, Gao Xiang wrote:
> syzbot reports a KMSAN reproducer [1] which generates a crafted
> filesystem image and causes IMA to read uninitialized page cache.
>
> Later, (rq->outputsize > rq->inputsize) will be formally supported
> after either large uncompressed pclusters (> block size) or big
> lclusters are landed. However, currently there is no way to generate
> such filesystems by using mkfs.erofs.
>
> Thus, let's mark this condition as unsupported for now.
>
> [1] https://lore.kernel.org/r/0000000000002b...@google.com
>
> Reported-by: syzbot+7bc44a...@syzkaller.appspotmail.com
> Fixes: 1ca01520148a ("erofs: refine z_erofs_transform_plain() for sub-page block support")
> Signed-off-by: Gao Xiang <hsia...@linux.alibaba.com>

Reviewed-by: Chao Yu <ch...@kernel.org>

Thanks,
Reply all
Reply to author
Forward
0 new messages