Linux-Security-Module Archive mirror
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: syzbot <syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com>,
	 dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com,
	jmorris@namei.org,  linux-integrity@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 linux-security-module@vger.kernel.org, paul@paul-moore.com,
	 roberto.sassu@huawei.com, serge@hallyn.com,
	syzkaller-bugs@googlegroups.com,  zohar@linux.ibm.com,
	linux-fsdevel@vger.kernel.org
Subject: Re: [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry
Date: Tue, 20 Feb 2024 11:40:43 +0100	[thread overview]
Message-ID: <40746a9ae6d2e76d748ec0bf7710bba7e49a53ac.camel@huaweicloud.com> (raw)
In-Reply-To: <0000000000002be12a0611ca7ff8@google.com>

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
> 
> 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+7bc44a489f0ef0670bd5@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

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

> 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 syzkaller@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


  reply	other threads:[~2024-02-20 10:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20  6:41 [syzbot] [integrity?] [lsm?] KMSAN: uninit-value in ima_add_template_entry syzbot
2024-02-20 10:40 ` Roberto Sassu [this message]
2024-03-02 22:01 ` [syzbot] [lsm?] [integrity?] " syzbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40746a9ae6d2e76d748ec0bf7710bba7e49a53ac.camel@huaweicloud.com \
    --to=roberto.sassu@huaweicloud.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=jmorris@namei.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=syzbot+7bc44a489f0ef0670bd5@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).