KMSAN: kernel-infoleak in rng_recvmsg
syzbot
syzbotHello,
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:
=====================================================
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 [email protected].
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
#syz test
crypto/jitterentropy-kcapi.c +1 -1
@@ -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 has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
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.
PATCH 1/1 crypto: Prevent kernel-infoleak in rng_recvmsg
In reply to syzbotInitialize the intermediary array member to 0 to prevent the kernel from leaking uninitialized data to user space.
--- crypto/jitterentropy-kcapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/jitterentropy-kcapi.c +1 -1
@@ -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;
Signature · 1 line
2.43.0
Herbert Xu
maintainerRe: [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg
Quoted 16 lines · Edward Adam Davis
Initialize the intermediary array member to 0 to prevent the kernel from leaking uninitialized data to user space.
Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- crypto/jitterentropy-kcapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)crypto/jitterentropy-kcapi.c +0
-0
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 110
Quoted 5 lines
crypto/jitterentropy-kcapi.c +1
-1@@ -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.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg
Quoted 17 lines · Herbert Xu
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 110
Quoted 10 lines · Edward Adam Davis
crypto/jitterentropy-kcapi.c +1
-1@@ -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 :)
Quoted 1 line
Please find a way to mark this as a false positive.
I think kmsan_unpoison_memory is the function that you should call.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
PATCH v2 1/1 crypto: Mark intermediary memory as clean
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.
---
V1 -> V2: mark it as unpoison
crypto/jitterentropy-kcapi.c | 1 + 1 file changed, 1 insertion(+)
crypto/jitterentropy-kcapi.c +1 -0
@@ -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.
Signature · 1 line
2.43.0
Herbert Xu
maintainerRe: [PATCH V2] crypto: Mark intermediary memory as clean
Quoted 17 lines · Edward Adam Davis
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 [email protected]Signed-off-by Edward Adam Davis <[email protected]>---
V1 -> V2: mark it as unpoisoncrypto/jitterentropy-kcapi.c | 1 + 1 file changed, 1 insertion(+)crypto/jitterentropy-kcapi.c +0
-0
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 120
Quoted 4 lines
crypto/jitterentropy-kcapi.c +1
-0@@ -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).
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH V2] crypto: Mark intermediary memory as clean
Quoted 11 lines · Herbert Xu
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 120
Quoted 9 lines
crypto/jitterentropy-kcapi.c +1
-0@@ -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_SIZEto 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
maintainerRe: [PATCH V2] crypto: Mark intermediary memory as clean
Quoted 4 lines · Edward Adam Davis
Their values are equal, so why use sizeof to calculate?
Similarly, "if (sizeof(intermediary) !=crypto_shash_digestsize(desc->tfm)) {", why not just useSHA3_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,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH V2] crypto: Mark intermediary memory as clean
Quoted 3 lines · Herbert Xu
Their values are equal, so why use sizeof to calculate?
Similarly, "if (sizeof(intermediary) !=crypto_shash_digestsize(desc->tfm)) {", why not just useSHA3_256_DIGEST_SIZE?
Hi Stephan Mueller, can you explain it?
BR,
Edward
Re: [PATCH V2] crypto: Mark intermediary memory as clean
Am Montag, 18. August 2025, 14:43:36 Mitteleuropäische Sommerzeit schrieb Edward Adam Davis:
Hi Edward,
Quoted 7 lines · Herbert Xu
Quoted 4 lines
Their values are equal, so why use sizeof to calculate? Similarly, "if (sizeof(intermediary) !=
crypto_shash_digestsize(desc->tfm)) {", why not just useSHA3_256_DIGEST_SIZE?Hi Stephan Mueller, can you explain it?
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
PATCH v3 1/1 crypto: Mark intermediary memory as clean
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.
---
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(+)
crypto/jitterentropy-kcapi.c +1 -0
@@ -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.
Signature · 1 line
2.43.0
Re: [PATCH V3] crypto: Mark intermediary memory as clean
Am Montag, 18. August 2025, 15:24:17 Mitteleuropäische Sommerzeit schrieb Edward Adam Davis:
Hi Edward,
Quoted 6 lines
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 [email protected]Signed-off-by Edward Adam Davis <[email protected]>
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
Quoted 13 lines
---
V1 -> V2: mark it as unpoison
V2 -> V3: replace to sizeof, minimize the possibilities where inconsistencies can occurcrypto/jitterentropy-kcapi.c | 1 + 1 file changed, 1 insertion(+)crypto/jitterentropy-kcapi.c +0
-0
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 · line 123
Quoted 7 lines
crypto/jitterentropy-kcapi.c +1
-0@@ -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
Herbert Xu
maintainerRe: [PATCH V3] crypto: Mark intermediary memory as clean
In reply to Edward Adam DavisQuoted 6 lines · Edward Adam Davis
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 [email protected]Signed-off-by Edward Adam Davis <[email protected]>
Quoted 6 lines
---
V1 -> V2: mark it as unpoison
V2 -> V3: replace to sizeof, minimize the possibilities where inconsistencies can occurcrypto/jitterentropy-kcapi.c | 1 + 1 file changed, 1 insertion(+)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg
In reply to Herbert Xu(cc Kees)
Quoted 13 lines · Herbert Xu
Quoted 11 lines · Edward Adam Davis
Initialize the intermediary array member to 0 to prevent the kernel from leaking uninitialized data to user space.
Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- crypto/jitterentropy-kcapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 110
Quoted 10 lines
crypto/jitterentropy-kcapi.c +1
-1@@ -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)
Re: [PATCH] crypto: Prevent kernel-infoleak in rng_recvmsg
Quoted 30 lines · Ard Biesheuvel
(cc Kees)
Quoted 13 lines · Herbert Xu
Quoted 11 lines · Edward Adam Davis
Initialize the intermediary array member to 0 to prevent the kernel from leaking uninitialized data to user space.
Reported-by [email protected]Tested-by [email protected]Signed-off-by Edward Adam Davis <[email protected]>--- crypto/jitterentropy-kcapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
crypto/jitterentropy-kcapi.c int jent_hash_time(void *hash_state, __u64 time, u8 *addtl, · line 110
Quoted 10 lines
crypto/jitterentropy-kcapi.c +1
-1@@ -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.
Quoted 3 lines
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)
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.
Signature · 1 line
Kees Cook