* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
@ 2023-06-13 10:24 ` Herbert Xu
2023-06-14 12:04 ` David Howells
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2023-06-13 10:24 UTC (permalink / raw)
To: syzbot
Cc: davem, dhowells, linux-crypto, linux-kernel, netdev, pabeni,
syzkaller-bugs
On Mon, Jun 12, 2023 at 02:43:45AM -0700, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: ded5c1a16ec6 Merge branch 'tools-ynl-gen-code-gen-improvem..
> git tree: net-next
> console+strace: https://syzkaller.appspot.com/x/log.txt?x=104cdef1280000
> kernel config: https://syzkaller.appspot.com/x/.config?x=526f919910d4a671
> dashboard link: https://syzkaller.appspot.com/bug?extid=e79818f5c12416aba9de
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13c6193b280000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16c7a795280000
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/ffd66beb6784/disk-ded5c1a1.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/e7336ae5a7bf/vmlinux-ded5c1a1.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/10ded02dc7e2/bzImage-ded5c1a1.xz
>
> The issue was bisected to:
>
> commit c662b043cdca89bf0f03fc37251000ac69a3a548
> Author: David Howells <dhowells@redhat.com>
> Date: Tue Jun 6 13:08:56 2023 +0000
>
> crypto: af_alg/hash: Support MSG_SPLICE_PAGES
David, the logic for calling hash_alloc_result looks quite different
from that on whether you do the hash finalisation. I'd suggest that
you change them to use the same check, and also set use NULL instead
of ctx->result if you didn't call hash_alloc_result.
Thanks,
--
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] 10+ messages in thread* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
2023-06-13 10:24 ` Herbert Xu
@ 2023-06-14 12:04 ` David Howells
2023-06-14 14:54 ` David Howells
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2023-06-14 12:04 UTC (permalink / raw)
To: Herbert Xu
Cc: dhowells, syzbot, davem, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
Herbert Xu <herbert@gondor.apana.org.au> wrote:
> David, the logic for calling hash_alloc_result looks quite different
> from that on whether you do the hash finalisation. I'd suggest that
> you change them to use the same check, and also set use NULL instead
> of ctx->result if you didn't call hash_alloc_result.
I don't fully understand what the upstream hash_sendmsg() is doing. Take this
bit for example:
if (!ctx->more) {
if ((msg->msg_flags & MSG_MORE))
hash_free_result(sk, ctx);
Why is it freeing the old result only if MSG_MORE is now set, but wasn't set
on the last sendmsg()?
David
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
2023-06-13 10:24 ` Herbert Xu
2023-06-14 12:04 ` David Howells
@ 2023-06-14 14:54 ` David Howells
2023-06-14 22:42 ` syzbot
2023-07-25 12:57 ` syzbot
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: David Howells @ 2023-06-14 14:54 UTC (permalink / raw)
To: syzbot
Cc: dhowells, davem, herbert, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main
crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE)
If an AF_ALG socket bound to a hashing algorithm is sent a zero-length
message with MSG_MORE set and then recvmsg() is called without first
sending another message without MSG_MORE set to end the operation, an oops
will occur because the crypto context and result doesn't now get set up in
advance because hash_sendmsg() now defers that as long as possible in the
hope that it can use crypto_ahash_digest() - and then because the message
is zero-length, it the data wrangling loop is skipped.
Fix this by always making a pass of the loop, even in the case that no data
is provided to the sendmsg().
Fix also extract_iter_to_sg() to handle a zero-length iterator by returning
0 immediately.
Whilst we're at it, remove the code to create a kvmalloc'd scatterlist if
we get more than ALG_MAX_PAGES - this shouldn't happen.
Fixes: c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES")
Reported-by: syzbot+13a08c0bf4d212766c3c@syzkaller.appspotmail.com
Link: https://lore.kernel.org/r/000000000000b928f705fdeb873a@google.com/
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index dfb048cefb60..1176533a55c9 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -83,26 +83,14 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
ctx->more = false;
- while (msg_data_left(msg)) {
+ do {
ctx->sgl.sgt.sgl = ctx->sgl.sgl;
ctx->sgl.sgt.nents = 0;
ctx->sgl.sgt.orig_nents = 0;
err = -EIO;
npages = iov_iter_npages(&msg->msg_iter, max_pages);
- if (npages == 0)
- goto unlock_free;
-
- if (npages > ARRAY_SIZE(ctx->sgl.sgl)) {
- err = -ENOMEM;
- ctx->sgl.sgt.sgl =
- kvmalloc(array_size(npages,
- sizeof(*ctx->sgl.sgt.sgl)),
- GFP_KERNEL);
- if (!ctx->sgl.sgt.sgl)
- goto unlock_free;
- }
- sg_init_table(ctx->sgl.sgl, npages);
+ sg_init_table(ctx->sgl.sgl, max_t(size_t, npages, 1));
ctx->sgl.need_unpin = iov_iter_extract_will_pin(&msg->msg_iter);
@@ -111,7 +99,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
if (err < 0)
goto unlock_free;
len = err;
- sg_mark_end(ctx->sgl.sgt.sgl + ctx->sgl.sgt.nents - 1);
+ if (len > 0)
+ sg_mark_end(ctx->sgl.sgt.sgl + ctx->sgl.sgt.nents - 1);
if (!msg_data_left(msg)) {
err = hash_alloc_result(sk, ctx);
@@ -148,7 +137,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
copied += len;
af_alg_free_sg(&ctx->sgl);
- }
+ } while (msg_data_left(msg));
ctx->more = msg->msg_flags & MSG_MORE;
err = 0;
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index e97d7060329e..77a7b18ee751 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -1340,7 +1340,7 @@ ssize_t extract_iter_to_sg(struct iov_iter *iter, size_t maxsize,
struct sg_table *sgtable, unsigned int sg_max,
iov_iter_extraction_t extraction_flags)
{
- if (maxsize == 0)
+ if (!maxsize || !iter->count)
return 0;
switch (iov_iter_type(iter)) {
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-14 14:54 ` David Howells
@ 2023-06-14 22:42 ` syzbot
0 siblings, 0 replies; 10+ messages in thread
From: syzbot @ 2023-06-14 22:42 UTC (permalink / raw)
To: davem, dhowells, herbert, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-and-tested-by: syzbot+e79818f5c12416aba9de@syzkaller.appspotmail.com
Tested on:
commit: fa0e21fa rtnetlink: extend RTEXT_FILTER_SKIP_STATS to ..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main
console output: https://syzkaller.appspot.com/x/log.txt?x=12ae3673280000
kernel config: https://syzkaller.appspot.com/x/.config?x=526f919910d4a671
dashboard link: https://syzkaller.appspot.com/bug?extid=e79818f5c12416aba9de
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
patch: https://syzkaller.appspot.com/x/patch.diff?x=172d9e8b280000
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
` (2 preceding siblings ...)
2023-06-14 14:54 ` David Howells
@ 2023-07-25 12:57 ` syzbot
2023-07-25 12:58 ` Aleksandr Nogikh
2023-07-25 15:29 ` David Howells
2023-07-26 13:01 ` David Howells
5 siblings, 1 reply; 10+ messages in thread
From: syzbot @ 2023-07-25 12:57 UTC (permalink / raw)
To: alexander.deucher, davem, dhowells, herbert, linux-crypto,
linux-kernel, mario.limonciello, netdev, pabeni, syzkaller-bugs
syzbot suspects this issue was fixed by commit:
commit 30c3d3b70aba2464ee8c91025e91428f92464077
Author: Mario Limonciello <mario.limonciello@amd.com>
Date: Tue May 30 16:57:59 2023 +0000
drm/amd: Disallow s0ix without BIOS support again
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=13ad506ea80000
start commit: ded5c1a16ec6 Merge branch 'tools-ynl-gen-code-gen-improvem..
git tree: net-next
kernel config: https://syzkaller.appspot.com/x/.config?x=526f919910d4a671
dashboard link: https://syzkaller.appspot.com/bug?extid=e79818f5c12416aba9de
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13c6193b280000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16c7a795280000
If the result looks correct, please mark the issue as fixed by replying with:
#syz fix: drm/amd: Disallow s0ix without BIOS support again
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-07-25 12:57 ` syzbot
@ 2023-07-25 12:58 ` Aleksandr Nogikh
0 siblings, 0 replies; 10+ messages in thread
From: Aleksandr Nogikh @ 2023-07-25 12:58 UTC (permalink / raw)
To: syzbot
Cc: alexander.deucher, davem, dhowells, herbert, linux-crypto,
linux-kernel, mario.limonciello, netdev, pabeni, syzkaller-bugs
On Tue, Jul 25, 2023 at 2:57 PM syzbot
<syzbot+e79818f5c12416aba9de@syzkaller.appspotmail.com> wrote:
>
> syzbot suspects this issue was fixed by commit:
>
> commit 30c3d3b70aba2464ee8c91025e91428f92464077
> Author: Mario Limonciello <mario.limonciello@amd.com>
> Date: Tue May 30 16:57:59 2023 +0000
>
> drm/amd: Disallow s0ix without BIOS support again
>
> bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=13ad506ea80000
> start commit: ded5c1a16ec6 Merge branch 'tools-ynl-gen-code-gen-improvem..
> git tree: net-next
> kernel config: https://syzkaller.appspot.com/x/.config?x=526f919910d4a671
> dashboard link: https://syzkaller.appspot.com/bug?extid=e79818f5c12416aba9de
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13c6193b280000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16c7a795280000
>
> If the result looks correct, please mark the issue as fixed by replying with:
No, that's rather unlikely.
>
> #syz fix: drm/amd: Disallow s0ix without BIOS support again
>
> For information about bisection process see: https://goo.gl/tpsmEJ#bisection
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/0000000000009eae2406014f451d%40google.com.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
` (3 preceding siblings ...)
2023-07-25 12:57 ` syzbot
@ 2023-07-25 15:29 ` David Howells
2023-07-25 16:02 ` syzbot
2023-07-26 13:01 ` David Howells
5 siblings, 1 reply; 10+ messages in thread
From: David Howells @ 2023-07-25 15:29 UTC (permalink / raw)
To: syzbot
Cc: dhowells, davem, herbert, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git b6d972f6898308fbe7e693bf8d44ebfdb1cd2dc4
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-07-25 15:29 ` David Howells
@ 2023-07-25 16:02 ` syzbot
0 siblings, 0 replies; 10+ messages in thread
From: syzbot @ 2023-07-25 16:02 UTC (permalink / raw)
To: davem, dhowells, herbert, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-and-tested-by: syzbot+e79818f5c12416aba9de@syzkaller.appspotmail.com
Tested on:
commit: b6d972f6 crypto: af_alg/hash: Fix recvmsg() after send..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=11736cbea80000
kernel config: https://syzkaller.appspot.com/x/.config?x=2cdac84c489b934f
dashboard link: https://syzkaller.appspot.com/bug?extid=e79818f5c12416aba9de
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
Note: no patches were applied.
Note: testing is done by a robot and is best-effort only.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [syzbot] [crypto?] general protection fault in cryptd_hash_export
2023-06-12 9:43 [syzbot] [crypto?] general protection fault in cryptd_hash_export syzbot
` (4 preceding siblings ...)
2023-07-25 15:29 ` David Howells
@ 2023-07-26 13:01 ` David Howells
5 siblings, 0 replies; 10+ messages in thread
From: David Howells @ 2023-07-26 13:01 UTC (permalink / raw)
To: syzbot
Cc: dhowells, davem, herbert, linux-crypto, linux-kernel, netdev,
pabeni, syzkaller-bugs
#syz fix: crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE)
^ permalink raw reply [flat|nested] 10+ messages in thread