[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aDQszmcfKfEt4Xdd@gondor.apana.org.au>
Date: Mon, 26 May 2025 16:56:46 +0800
From: Herbert Xu <herbert@...dor.apana.org.au>
To: syzbot <syzbot+4851c19615d35f0e4d68@...kaller.appspotmail.com>
Cc: davem@...emloft.net, linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com
Subject: [PATCH] crypto: shash - Fix buffer overrun in import function
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@...kaller.appspotmail.com
Fixes: 7650f826f7b2 ("crypto: shash - Handle partial blocks in API")
Signed-off-by: Herbert Xu <herbert@...dor.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@...dor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Powered by blists - more mailing lists