[syzbot] [crypto?] KMSAN: kernel-infoleak in rng_recvmsg

10 views
Skip to first unread message

syzbot

unread,
Aug 8, 2025, 4:07:31 AM8/8/25
to da...@davemloft.net, her...@gondor.apana.org.au, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 6e64f4580381 Merge tag 'input-for-v6.17-rc0' of git://git...
git tree: upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=14a181a2580000
kernel config: https://syzkaller.appspot.com/x/.config?x=b6003cf8ecb92ff2
dashboard link: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=117fa1a2580000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=105e9058580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/3d9a1192a7cc/disk-6e64f458.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/8f363fe8f54a/vmlinux-6e64f458.xz
kernel image: https://storage.googleapis.com/syzbot-assets/10b73833a575/bzImage-6e64f458.xz

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

=====================================================
BUG: KMSAN: kernel-infoleak in instrument_copy_to_user include/linux/instrumented.h:114 [inline]
BUG: KMSAN: kernel-infoleak in copy_to_user_iter lib/iov_iter.c:24 [inline]
BUG: KMSAN: kernel-infoleak in iterate_ubuf include/linux/iov_iter.h:30 [inline]
BUG: KMSAN: kernel-infoleak in iterate_and_advance2 include/linux/iov_iter.h:300 [inline]
BUG: KMSAN: kernel-infoleak in iterate_and_advance include/linux/iov_iter.h:328 [inline]
BUG: KMSAN: kernel-infoleak in _copy_to_iter+0xf0e/0x33f0 lib/iov_iter.c:185
instrument_copy_to_user include/linux/instrumented.h:114 [inline]
copy_to_user_iter lib/iov_iter.c:24 [inline]
iterate_ubuf include/linux/iov_iter.h:30 [inline]
iterate_and_advance2 include/linux/iov_iter.h:300 [inline]
iterate_and_advance include/linux/iov_iter.h:328 [inline]
_copy_to_iter+0xf0e/0x33f0 lib/iov_iter.c:185
copy_to_iter include/linux/uio.h:220 [inline]
memcpy_to_msg include/linux/skbuff.h:4202 [inline]
_rng_recvmsg crypto/algif_rng.c:101 [inline]
rng_recvmsg+0x1af/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

<Zero or more stacks not recorded to save memory>

Uninit was stored to memory at:
crypto_sha3_finup+0x136/0xe00 crypto/sha3_generic.c:202
crypto_shash_op_and_zero crypto/shash.c:105 [inline]
crypto_shash_finup+0x327/0xe80 crypto/shash.c:171
jent_hash_time+0x247/0x590 crypto/jitterentropy-kcapi.c:138
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
crypto_shash_finup+0xc5a/0xe80 crypto/shash.c:162
crypto_shash_update include/crypto/hash.h:994 [inline]
jent_hash_time+0x1de/0x590 crypto/jitterentropy-kcapi.c:136
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
put_unaligned_le64 include/linux/unaligned.h:43 [inline]
crypto_sha3_finup+0xc98/0xe00 crypto/sha3_generic.c:213
crypto_shash_op_and_zero crypto/shash.c:105 [inline]
crypto_shash_finup+0x327/0xe80 crypto/shash.c:171
jent_hash_time+0x247/0x590 crypto/jitterentropy-kcapi.c:138
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
keccakf_round crypto/sha3_generic.c:-1 [inline]
keccakf+0x1efb/0x2110 crypto/sha3_generic.c:155
crypto_sha3_finup+0x772/0xe00 crypto/sha3_generic.c:210
crypto_shash_op_and_zero crypto/shash.c:105 [inline]
crypto_shash_finup+0x327/0xe80 crypto/shash.c:171
jent_hash_time+0x247/0x590 crypto/jitterentropy-kcapi.c:138
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
crypto_sha3_finup+0x5be/0xe00 crypto/sha3_generic.c:207
crypto_shash_op_and_zero crypto/shash.c:105 [inline]
crypto_shash_finup+0x327/0xe80 crypto/shash.c:171
jent_hash_time+0x247/0x590 crypto/jitterentropy-kcapi.c:138
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
crypto_sha3_finup+0x136/0xe00 crypto/sha3_generic.c:202
crypto_shash_op_and_zero crypto/shash.c:105 [inline]
crypto_shash_finup+0x327/0xe80 crypto/shash.c:171
jent_hash_time+0x247/0x590 crypto/jitterentropy-kcapi.c:138
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:
crypto_shash_finup+0xc5a/0xe80 crypto/shash.c:162
crypto_shash_update include/crypto/hash.h:994 [inline]
jent_hash_time+0x1de/0x590 crypto/jitterentropy-kcapi.c:136
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438
jent_measure_jitter+0x547/0x770 crypto/jitterentropy.c:541
jent_gen_entropy+0x209/0x450 crypto/jitterentropy.c:569
jent_read_entropy+0x353/0xeb0 crypto/jitterentropy.c:615
jent_kcapi_random+0x6c/0x250 crypto/jitterentropy-kcapi.c:284
crypto_rng_generate include/crypto/rng.h:144 [inline]
_rng_recvmsg crypto/algif_rng.c:97 [inline]
rng_recvmsg+0x149/0x2d0 crypto/algif_rng.c:114
sock_recvmsg_nosec net/socket.c:1065 [inline]
sock_recvmsg+0x2df/0x390 net/socket.c:1087
sock_read_iter+0x2c8/0x360 net/socket.c:1157
new_sync_read fs/read_write.c:491 [inline]
vfs_read+0x857/0xf00 fs/read_write.c:572
ksys_read fs/read_write.c:715 [inline]
__do_sys_read fs/read_write.c:724 [inline]
__se_sys_read fs/read_write.c:722 [inline]
__x64_sys_read+0x1fb/0x4d0 fs/read_write.c:722
x64_sys_call+0x2f9c/0x3e20 arch/x86/include/generated/asm/syscalls_64.h:1
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xd9/0x210 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f

Local variable intermediary created at:
jent_hash_time+0x9b/0x590 crypto/jitterentropy-kcapi.c:110
jent_condition_data+0x4f0/0x510 crypto/jitterentropy.c:438

Bytes 0-23 of 24 are uninitialized
Memory access of size 24 starts at ffff88811855fb70
Data copied to user address 00002000000001c0

CPU: 1 UID: 0 PID: 5820 Comm: syz-executor170 Not tainted 6.16.0-syzkaller-11952-g6e64f4580381 #0 PREEMPT(none)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/12/2025
=====================================================


---
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 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.

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

Edward Adam Davis

unread,
Aug 9, 2025, 3:20:02 AM8/9/25
to syzbot+e8bcd7...@syzkaller.appspotmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
#syz test

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index c24d4ff2b4a8..9e9e069f55af 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -107,7 +107,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
{
struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state;
SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm);
- u8 intermediary[SHA3_256_DIGEST_SIZE];
+ u8 intermediary[SHA3_256_DIGEST_SIZE] = { 0 };
__u64 j = 0;
int ret;


syzbot

unread,
Aug 9, 2025, 5:52:05 AM8/9/25
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
Tested-by: syzbot+e8bcd7...@syzkaller.appspotmail.com

Tested on:

commit: c30a1353 Merge tag 'bpf-fixes' of git://git.kernel.org..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14edb2f0580000
kernel config: https://syzkaller.appspot.com/x/.config?x=9ee158fa735566e2
dashboard link: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
compiler: Debian clang version 20.1.7 (++20250616065708+6146a88f6049-1~exp1~20250616065826.132), Debian LLD 20.1.7
patch: https://syzkaller.appspot.com/x/patch.diff?x=10a421a2580000

Note: testing is done by a robot and is best-effort only.

Edward Adam Davis

unread,
Aug 9, 2025, 6:00:02 AM8/9/25
to syzbot+e8bcd7...@syzkaller.appspotmail.com, da...@davemloft.net, her...@gondor.apana.org.au, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Initialize the intermediary array member to 0 to prevent the kernel from
leaking uninitialized data to user space.

Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
Tested-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <ead...@qq.com>
---
crypto/jitterentropy-kcapi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.43.0

Herbert Xu

unread,
Aug 16, 2025, 5:17:13 AM8/16/25
to Edward Adam Davis, syzbot+e8bcd7...@syzkaller.appspotmail.com, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
This is not a leak! The stack memroy is hashed and fed into the
entropy pool. If you can recover the original kernel memory from
the result, then we have much bigger problems :)

Please find a way to mark this as a false positive.

Thanks,
--
Email: Herbert Xu <her...@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Herbert Xu

unread,
Aug 17, 2025, 4:52:00 AM8/17/25
to Edward Adam Davis, syzbot+e8bcd7...@syzkaller.appspotmail.com, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Sat, Aug 16, 2025 at 05:17:01PM +0800, Herbert Xu wrote:
> On Sat, Aug 09, 2025 at 05:59:43PM +0800, Edward Adam Davis wrote:
>
> > diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
> > index c24d4ff2b4a8..9e9e069f55af 100644
> > --- a/crypto/jitterentropy-kcapi.c
> > +++ b/crypto/jitterentropy-kcapi.c
> > @@ -107,7 +107,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
> > {
> > struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state;
> > SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm);
> > - u8 intermediary[SHA3_256_DIGEST_SIZE];
> > + u8 intermediary[SHA3_256_DIGEST_SIZE] = { 0 };
>
> This is not a leak! The stack memroy is hashed and fed into the
> entropy pool. If you can recover the original kernel memory from
> the result, then we have much bigger problems :)
>
> Please find a way to mark this as a false positive.

I think kmsan_unpoison_memory is the function that you should call.

Cheers,

Edward Adam Davis

unread,
Aug 17, 2025, 6:59:33 AM8/17/25
to her...@gondor.apana.org.au, da...@davemloft.net, ead...@qq.com, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
This is not a leak! The stack memroy is hashed and fed into the
entropy pool. We can't recover the original kernel memory from it.
Signed-off-by: Edward Adam Davis <ead...@qq.com>
---
V1 -> V2: mark it as unpoison

crypto/jitterentropy-kcapi.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index 1266eb790708..4020a6e41b0e 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -117,6 +117,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
pr_warn_ratelimited("Unexpected digest size\n");
return -EINVAL;
}
+ kmsan_unpoison_memory(intermediary, SHA3_256_DIGEST_SIZE);

/*
* This loop fills a buffer which is injected into the entropy pool.
--
2.43.0

Herbert Xu

unread,
Aug 17, 2025, 7:41:09 AM8/17/25
to Edward Adam Davis, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
Please change SHA3_256_DIGEST_SIZE to sizeof(intermediary).

Thanks,

Edward Adam Davis

unread,
Aug 18, 2025, 8:17:40 AM8/18/25
to her...@gondor.apana.org.au, da...@davemloft.net, ead...@qq.com, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
On Sun, 17 Aug 2025 19:40:56 +0800, Herbert Xu wrote:
> > diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
> > index 1266eb790708..4020a6e41b0e 100644
> > --- a/crypto/jitterentropy-kcapi.c
> > +++ b/crypto/jitterentropy-kcapi.c
> > @@ -117,6 +117,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
> > pr_warn_ratelimited("Unexpected digest size\n");
> > return -EINVAL;
> > }
> > + kmsan_unpoison_memory(intermediary, SHA3_256_DIGEST_SIZE);
>
> Please change SHA3_256_DIGEST_SIZE to sizeof(intermediary).
Why?
Their values are equal, so why use sizeof to calculate?
Similarly, "if (sizeof(intermediary) != crypto_shash_digestsize(desc->tfm)) {",
why not just use SHA3_256_DIGEST_SIZE?

BR,
Edward

Herbert Xu

unread,
Aug 18, 2025, 8:30:48 AM8/18/25
to Edward Adam Davis, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
On Mon, Aug 18, 2025 at 08:17:17PM +0800, Edward Adam Davis wrote:
>
> Their values are equal, so why use sizeof to calculate?
> Similarly, "if (sizeof(intermediary) != crypto_shash_digestsize(desc->tfm)) {",
> why not just use SHA3_256_DIGEST_SIZE?

Please be consistent with the existing code, every other place
in the function uses sizeof(intermediary) so your patch is the
odd one out.

Cheers,

Edward Adam Davis

unread,
Aug 18, 2025, 8:43:56 AM8/18/25
to smue...@chronox.de, her...@gondor.apana.org.au, da...@davemloft.net, ead...@qq.com, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
On Mon, 18 Aug 2025 20:30:29 +0800, Herbert Xu wrote:
> Their values are equal, so why use sizeof to calculate?
> Similarly, "if (sizeof(intermediary) != crypto_shash_digestsize(desc->tfm)) {",
> why not just use SHA3_256_DIGEST_SIZE?
Hi Stephan Mueller, can you explain it?

BR,
Edward

Stephan Mueller

unread,
Aug 18, 2025, 9:22:41 AM8/18/25
to Edward Adam Davis, her...@gondor.apana.org.au, da...@davemloft.net, ead...@qq.com, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
Am Montag, 18. August 2025, 14:43:36 Mitteleuropäische Sommerzeit schrieb
Edward Adam Davis:

Hi Edward,
If the question is why using sizeof(intermediary) instead of
SHA3_256_DIGEST_SIZE, then it is very trivial: I always want to avoid any kind
of double work. If for any reason the buffer size of intermediary changes, the
current code only requires *one* location to fix it.

When changing the branching condition to use SHA3_256_DIGEST_SIZE, we would
have to change *two* locations which is more error-prone than to change one.
This approach is my common coding style to try to minimize the possibilities
where inconsistencies can occur.

Ciao
Stephan


Edward Adam Davis

unread,
Aug 18, 2025, 9:24:35 AM8/18/25
to smue...@chronox.de, da...@davemloft.net, ead...@qq.com, her...@gondor.apana.org.au, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
This is not a leak! The stack memroy is hashed and fed into the
entropy pool. We can't recover the original kernel memory from it.

Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
Signed-off-by: Edward Adam Davis <ead...@qq.com>
---
V1 -> V2: mark it as unpoison
V2 -> V3: replace to sizeof, minimize the possibilities where inconsistencies can occur

crypto/jitterentropy-kcapi.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index 1266eb790708..4020a6e41b0e 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -117,6 +117,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
pr_warn_ratelimited("Unexpected digest size\n");
return -EINVAL;
}
+ kmsan_unpoison_memory(intermediary, sizeof(intermediary));

Stephan Mueller

unread,
Aug 18, 2025, 9:32:48 AM8/18/25
to Edward Adam Davis, da...@davemloft.net, ead...@qq.com, her...@gondor.apana.org.au, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
Am Montag, 18. August 2025, 15:24:17 Mitteleuropäische Sommerzeit schrieb
Edward Adam Davis:

Hi Edward,

> This is not a leak! The stack memroy is hashed and fed into the
> entropy pool. We can't recover the original kernel memory from it.
>
> Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
> Signed-off-by: Edward Adam Davis <ead...@qq.com>

Thank you for the patch. Just for the records:

- the intermediary buffer could be initialized to 0 without any effect on the
Jitter RNG, because all it wants is actually the execution of the Keccak
operation as part of crypto_shhash_finup.

- the intermediary buffer is inserted into the Jitter RNG state to ensure that
the compiler cannot optimize away the loop if the intermediary buffer would
not be used at all

- the intermediary buffer is not credited with any entropy as we only want the
Keccak operation

- by keeping the intermediary uninitialized, the Jitter RNG may get some
variations from the uninitialized buffer so that its internal state may
benefit from it

That said, I am fine with this current patch. But if there is still lingering
concern, I am equally fine to have it initialized to zero.

Thanks a lot
Stephan

> ---
> V1 -> V2: mark it as unpoison
> V2 -> V3: replace to sizeof, minimize the possibilities where
> inconsistencies can occur
>
> crypto/jitterentropy-kcapi.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
> index 1266eb790708..4020a6e41b0e 100644
> --- a/crypto/jitterentropy-kcapi.c
> +++ b/crypto/jitterentropy-kcapi.c
> @@ -117,6 +117,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8
> *addtl, pr_warn_ratelimited("Unexpected digest size\n");
> return -EINVAL;
> }
> + kmsan_unpoison_memory(intermediary, sizeof(intermediary));
>
> /*
> * This loop fills a buffer which is injected into the entropy pool.


Ciao
Stephan


Ard Biesheuvel

unread,
Aug 26, 2025, 9:51:20 AM8/26/25
to Herbert Xu, linux-h...@vger.kernel.org, Kees Cook, Edward Adam Davis, syzbot+e8bcd7...@syzkaller.appspotmail.com, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
(cc Kees)

On Sat, 16 Aug 2025 at 11:17, Herbert Xu <her...@gondor.apana.org.au> wrote:
>
> On Sat, Aug 09, 2025 at 05:59:43PM +0800, Edward Adam Davis wrote:
> > Initialize the intermediary array member to 0 to prevent the kernel from
> > leaking uninitialized data to user space.
> >
> > Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
> > Tested-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
> > Signed-off-by: Edward Adam Davis <ead...@qq.com>
> > ---
> > crypto/jitterentropy-kcapi.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
> > index c24d4ff2b4a8..9e9e069f55af 100644
> > --- a/crypto/jitterentropy-kcapi.c
> > +++ b/crypto/jitterentropy-kcapi.c
> > @@ -107,7 +107,7 @@ int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,
> > {
> > struct shash_desc *hash_state_desc = (struct shash_desc *)hash_state;
> > SHASH_DESC_ON_STACK(desc, hash_state_desc->tfm);
> > - u8 intermediary[SHA3_256_DIGEST_SIZE];
> > + u8 intermediary[SHA3_256_DIGEST_SIZE] = { 0 };
>
> This is not a leak! The stack memroy is hashed and fed into the
> entropy pool.

Is there still a point to doing this now that the compiler
zero-initializes automatic variables? Or does that not apply to u8
arrays? (asking Kees)

Kees Cook

unread,
Aug 26, 2025, 12:58:41 PM8/26/25
to Ard Biesheuvel, Herbert Xu, linux-h...@vger.kernel.org, Edward Adam Davis, syzbot+e8bcd7...@syzkaller.appspotmail.com, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Wait, the jitterentropy _depends_ on "uninitialized" stack contents?
That is not a safe way to get entropy (especially since the stack
contents are likely predictable). But regardless, yes, arrays would be
fully wiped by zero-initialized automatic variables.

To force it to be uninit, use __uninitialized.

--
Kees Cook

Herbert Xu

unread,
Aug 30, 2025, 4:46:04 AM8/30/25
to Edward Adam Davis, smue...@chronox.de, da...@davemloft.net, linux-...@vger.kernel.org, linux-...@vger.kernel.org, syzbot+e8bcd7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
On Mon, Aug 18, 2025 at 09:24:17PM +0800, Edward Adam Davis wrote:
> This is not a leak! The stack memroy is hashed and fed into the
> entropy pool. We can't recover the original kernel memory from it.
>
> Reported-by: syzbot+e8bcd7...@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e8bcd7ee3db6cb5cb875
> Signed-off-by: Edward Adam Davis <ead...@qq.com>
> ---
> V1 -> V2: mark it as unpoison
> V2 -> V3: replace to sizeof, minimize the possibilities where inconsistencies can occur
>
> crypto/jitterentropy-kcapi.c | 1 +
> 1 file changed, 1 insertion(+)

Patch applied. Thanks.
Reply all
Reply to author
Forward
0 new messages