From: Herbert Xu <herbert@gondor.apana.org.au>
To: syzbot <syzbot+4851c19615d35f0e4d68@syzkaller.appspotmail.com>
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: [PATCH] crypto: shash - Fix buffer overrun in import function
Date: Mon, 26 May 2025 16:56:46 +0800 [thread overview]
Message-ID: <aDQszmcfKfEt4Xdd@gondor.apana.org.au> (raw)
In-Reply-To: <683428c8.a70a0220.29d4a0.0801.GAE@google.com>
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
prev parent reply other threads:[~2025-05-26 8:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-26 8:39 [syzbot] [crypto?] KASAN: use-after-free Write in __crypto_shash_import syzbot
2025-05-26 8:56 ` Herbert Xu [this message]
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=aDQszmcfKfEt4Xdd@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=davem@davemloft.net \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+4851c19615d35f0e4d68@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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
all inboxes | Powered by JetHome®