2023-07-07 05:17:45

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] [ext4?] general protection fault in ext4_finish_bio

syzbot has bisected this issue to:

commit b6d972f6898308fbe7e693bf8d44ebfdb1cd2dc4
Author: David Howells <[email protected]>
Date: Fri Jun 16 11:10:32 2023 +0000

crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE)

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=17e4fa88a80000
start commit: ae230642190a Merge branch 'af_unix-followup-fixes-for-so_p..
git tree: net-next
final oops: https://syzkaller.appspot.com/x/report.txt?x=1414fa88a80000
console output: https://syzkaller.appspot.com/x/log.txt?x=1014fa88a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=c9bf1936936ca698
dashboard link: https://syzkaller.appspot.com/bug?extid=689ec3afb1ef07b766b2
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=136b9d48a80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=10223cb8a80000

Reported-by: [email protected]
Fixes: b6d972f68983 ("crypto: af_alg/hash: Fix recvmsg() after sendmsg(MSG_MORE)")

For information about bisection process see: https://goo.gl/tpsmEJ#bisection


2023-07-07 08:21:40

by David Howells

[permalink] [raw]
Subject: Re: [syzbot] [ext4?] general protection fault in ext4_finish_bio

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

crypto: algif/hash: Fix race between MORE and non-MORE sends

The 'MSG_MORE' state of the previous sendmsg() is fetched without the
socket lock held, so two sendmsg calls can race. This can be seen with a
large sendfile() as that now does a series of sendmsg() calls, and if a
write() comes in on the same socket at an inopportune time, it can flip the
state.

Fix this by moving the fetch of ctx->more inside the socket lock.

Fixes: c662b043cdca ("crypto: af_alg/hash: Support MSG_SPLICE_PAGES")
Reported-by: [email protected]
Link: https://lore.kernel.org/r/[email protected]/
Signed-off-by: David Howells <[email protected]>
cc: Herbert Xu <[email protected]>
cc: Paolo Abeni <[email protected]>
cc: "David S. Miller" <[email protected]>
cc: Eric Dumazet <[email protected]>
cc: Jakub Kicinski <[email protected]>
cc: [email protected]
cc: [email protected]

diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c
index 0ab43e149f0e..82c44d4899b9 100644
--- a/crypto/algif_hash.c
+++ b/crypto/algif_hash.c
@@ -68,13 +68,15 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
struct hash_ctx *ctx = ask->private;
ssize_t copied = 0;
size_t len, max_pages, npages;
- bool continuing = ctx->more, need_init = false;
+ bool continuing, need_init = false;
int err;

max_pages = min_t(size_t, ALG_MAX_PAGES,
DIV_ROUND_UP(sk->sk_sndbuf, PAGE_SIZE));

lock_sock(sk);
+ continuing = ctx->more;
+
if (!continuing) {
/* Discard a previous request that wasn't marked MSG_MORE. */
hash_free_result(sk, ctx);


2023-07-07 09:10:09

by syzbot

[permalink] [raw]
Subject: Re: [syzbot] [ext4?] general protection fault in ext4_finish_bio

Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: [email protected]

Tested on:

commit: 5133c9e5 Merge tag 'drm-next-2023-07-07' of git://anon..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=124f34d8a80000
kernel config: https://syzkaller.appspot.com/x/.config?x=8f6b0c7ae2c9c303
dashboard link: https://syzkaller.appspot.com/bug?extid=689ec3afb1ef07b766b2
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=1624cf4f280000

Note: testing is done by a robot and is best-effort only.