mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [syzbot] [crypto?] KASAN: use-after-free Write in __crypto_shash_import
@ 2025-05-26  8:39 syzbot
  2025-05-26  8:56 ` [PATCH] crypto: shash - Fix buffer overrun in import function Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: syzbot @ 2025-05-26  8:39 UTC (permalink / raw)
  To: davem, herbert, linux-crypto, linux-kernel, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    176e917e010c Add linux-next specific files for 20250523
git tree:       linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=175c1ad4580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=e7902c752bef748
dashboard link: https://syzkaller.appspot.com/bug?extid=4851c19615d35f0e4d68
compiler:       Debian clang version 20.1.6 (++20250514063057+1e4d39e07757-1~exp1~20250514183223.118), Debian LLD 20.1.6
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14f92170580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17bd88e8580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/5f7692c642fa/disk-176e917e.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/057a442d42d0/vmlinux-176e917e.xz
kernel image: https://storage.googleapis.com/syzbot-assets/8f8ebdb4dd96/bzImage-176e917e.xz

The issue was bisected to:

commit 7650f826f7b2d84782f9147c51687ff0364125e9
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Fri Apr 18 02:58:41 2025 +0000

    crypto: shash - Handle partial blocks in API

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=10cba170580000
final oops:     https://syzkaller.appspot.com/x/report.txt?x=12cba170580000
console output: https://syzkaller.appspot.com/x/log.txt?x=14cba170580000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+4851c19615d35f0e4d68@syzkaller.appspotmail.com
Fixes: 7650f826f7b2 ("crypto: shash - Handle partial blocks in API")

==================================================================
BUG: KASAN: use-after-free in __crypto_shash_import+0x26a/0x2a0 crypto/shash.c:263
Write of size 1 at addr ffff88817c920b47 by task syz-executor264/5855

CPU: 0 UID: 0 PID: 5855 Comm: syz-executor264 Not tainted 6.15.0-rc7-next-20250523-syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:408 [inline]
 print_report+0xd2/0x2b0 mm/kasan/report.c:521
 kasan_report+0x118/0x150 mm/kasan/report.c:634
 __crypto_shash_import+0x26a/0x2a0 crypto/shash.c:263
 crypto_shash_import+0x84/0x230 crypto/shash.c:286
 hash_accept+0x1fb/0x280 crypto/algif_hash.c:267
 do_accept+0x48f/0x680 net/socket.c:1924
 __sys_accept4_file net/socket.c:1964 [inline]
 __sys_accept4+0x11c/0x1c0 net/socket.c:1993
 __do_sys_accept net/socket.c:2006 [inline]
 __se_sys_accept net/socket.c:2003 [inline]
 __x64_sys_accept+0x7d/0x90 net/socket.c:2003
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f685ecf6d59
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe73b98688 EFLAGS: 00000246 ORIG_RAX: 000000000000002b
RAX: ffffffffffffffda RBX: 00000000000158a5 RCX: 00007f685ecf6d59
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000004
RBP: 0000000000000000 R08: 00007ffe73b986bc R09: 00007ffe73b986bc
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe73b986bc
R13: 00007ffe73b986f0 R14: 00007ffe73b986d0 R15: 0000000000000002
 </TASK>

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x17c920
flags: 0x57ff00000000000(node=1|zone=2|lastcpupid=0x7ff)
raw: 057ff00000000000 ffffea0005f24808 ffffea0005f24808 0000000000000000
raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner info is not present (never set?)

Memory state around the buggy address:
 ffff88817c920a00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff88817c920a80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff88817c920b00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                           ^
 ffff88817c920b80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff88817c920c00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================


---
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.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] crypto: shash - Fix buffer overrun in import function
  2025-05-26  8:39 [syzbot] [crypto?] KASAN: use-after-free Write in __crypto_shash_import syzbot
@ 2025-05-26  8:56 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2025-05-26  8:56 UTC (permalink / raw)
  To: syzbot; +Cc: davem, linux-crypto, linux-kernel, syzkaller-bugs

On Mon, May 26, 2025 at 01:39:36AM -0700, syzbot wrote:
> 
> syzbot found the following issue on:
> 
> HEAD commit:    176e917e010c Add linux-next specific files for 20250523
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=175c1ad4580000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=e7902c752bef748
> dashboard link: https://syzkaller.appspot.com/bug?extid=4851c19615d35f0e4d68
> compiler:       Debian clang version 20.1.6 (++20250514063057+1e4d39e07757-1~exp1~20250514183223.118), Debian LLD 20.1.6
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=14f92170580000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17bd88e8580000

This patch should fix the bug:

---8<---
Only set the partial block length to zero if the algorithm is
block-only.  Otherwise the descriptor context could be empty,
e.g., for digest_null.

Reported-by: syzbot+4851c19615d35f0e4d68@syzkaller.appspotmail.com
Fixes: 7650f826f7b2 ("crypto: shash - Handle partial blocks in API")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/shash.c b/crypto/shash.c
index 37537d7995c7..4721f5f134f4 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -257,12 +257,13 @@ static int __crypto_shash_import(struct shash_desc *desc, const void *in,
 	if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
 		return -ENOKEY;
 
-	plen = crypto_shash_blocksize(tfm) + 1;
-	descsize = crypto_shash_descsize(tfm);
 	ss = crypto_shash_statesize(tfm);
-	buf[descsize - 1] = 0;
-	if (crypto_shash_block_only(tfm))
+	if (crypto_shash_block_only(tfm)) {
+		plen = crypto_shash_blocksize(tfm) + 1;
 		ss -= plen;
+		descsize = crypto_shash_descsize(tfm);
+		buf[descsize - 1] = 0;
+	}
 	if (!import) {
 		memcpy(buf, in, ss);
 		return 0;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-26  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-26  8:39 [syzbot] [crypto?] KASAN: use-after-free Write in __crypto_shash_import syzbot
2025-05-26  8:56 ` [PATCH] crypto: shash - Fix buffer overrun in import function Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®