From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <lizhi.xu@windriver.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>,
<syzbot+8811381d455e3e9ec788@syzkaller.appspotmail.com>,
<syzkaller-bugs@googlegroups.com>, <kuniyu@amazon.com>
Subject: Re: [syzbot] [net?] KASAN: slab-use-after-free Read in unix_stream_read_actor (2)
Date: Wed, 4 Sep 2024 23:59:55 -0700 [thread overview]
Message-ID: <20240905065955.17065-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20240905052532.533159-1-lizhi.xu@windriver.com>
From: Lizhi Xu <lizhi.xu@windriver.com>
Date: Thu, 5 Sep 2024 13:25:32 +0800
> The sock queue oob twice, the first manage_oob (in unix_stream_read_generic) peek next skb only,
> and the next skb is the oob skb, so if skb is oob skb we need use manage_oob dealwith it.
I think the correct fix should be like this.
The issue happens only when the head oob is consumed (!unix_skb_len(skb))
and the next skb is peeked. Then, we can fallback to the else branch in
manage_oob().
#syz test
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index a1894019ebd5..9913a447b758 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2654,51 +2654,49 @@ static int unix_stream_recv_urg(struct unix_stream_read_state *state)
static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
int flags, int copied)
{
+ struct sk_buff *consumed_skb = NULL;
+ struct sk_buff *unread_skb = NULL;
struct unix_sock *u = unix_sk(sk);
- if (!unix_skb_len(skb)) {
- struct sk_buff *unlinked_skb = NULL;
-
- spin_lock(&sk->sk_receive_queue.lock);
+ spin_lock(&sk->sk_receive_queue.lock);
+ if (!unix_skb_len(skb)) {
if (copied && (!u->oob_skb || skb == u->oob_skb)) {
skb = NULL;
} else if (flags & MSG_PEEK) {
skb = skb_peek_next(skb, &sk->sk_receive_queue);
} else {
- unlinked_skb = skb;
+ consumed_skb = skb;
skb = skb_peek_next(skb, &sk->sk_receive_queue);
- __skb_unlink(unlinked_skb, &sk->sk_receive_queue);
+ __skb_unlink(consumed_skb, &sk->sk_receive_queue);
}
- spin_unlock(&sk->sk_receive_queue.lock);
-
- consume_skb(unlinked_skb);
- } else {
- struct sk_buff *unlinked_skb = NULL;
+ if (!u->oob_skb || skb != u->oob_skb)
+ goto unlock;
+ }
- spin_lock(&sk->sk_receive_queue.lock);
+ if (skb == u->oob_skb) {
+ if (copied) {
+ skb = NULL;
+ } else if (!(flags & MSG_PEEK)) {
+ WRITE_ONCE(u->oob_skb, NULL);
- if (skb == u->oob_skb) {
- if (copied) {
- skb = NULL;
- } else if (!(flags & MSG_PEEK)) {
- WRITE_ONCE(u->oob_skb, NULL);
-
- if (!sock_flag(sk, SOCK_URGINLINE)) {
- __skb_unlink(skb, &sk->sk_receive_queue);
- unlinked_skb = skb;
- skb = skb_peek(&sk->sk_receive_queue);
- }
- } else if (!sock_flag(sk, SOCK_URGINLINE)) {
- skb = skb_peek_next(skb, &sk->sk_receive_queue);
+ if (!sock_flag(sk, SOCK_URGINLINE)) {
+ __skb_unlink(skb, &sk->sk_receive_queue);
+ unread_skb = skb;
+ skb = skb_peek(&sk->sk_receive_queue);
}
+ } else if (!sock_flag(sk, SOCK_URGINLINE)) {
+ skb = skb_peek_next(skb, &sk->sk_receive_queue);
}
+ }
- spin_unlock(&sk->sk_receive_queue.lock);
+unlock:
+ spin_unlock(&sk->sk_receive_queue.lock);
+
+ consume_skb(consumed_skb);
+ kfree_skb(unread_skb);
- kfree_skb(unlinked_skb);
- }
return skb;
}
#endif
next prev parent reply other threads:[~2024-09-05 7:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-04 15:13 [syzbot] [net?] KASAN: slab-use-after-free Read in unix_stream_read_actor (2) syzbot
2024-09-04 15:32 ` Eric Dumazet
2024-09-04 17:32 ` Shoaib Rao
2024-09-05 7:35 ` Shoaib Rao
2024-09-05 8:04 ` Eric Dumazet
2024-09-05 19:06 ` Shoaib Rao
2024-09-05 19:46 ` Kuniyuki Iwashima
2024-09-05 20:15 ` Shoaib Rao
2024-09-05 20:35 ` Kuniyuki Iwashima
2024-09-05 20:48 ` Shoaib Rao
2024-09-05 21:03 ` Kuniyuki Iwashima
2024-09-06 12:37 ` Eric Dumazet
2024-09-06 16:48 ` Shoaib Rao
2024-09-07 5:06 ` Shoaib Rao
2024-09-07 5:39 ` Kuniyuki Iwashima
2024-09-10 0:29 ` Shoaib Rao
2024-09-10 0:48 ` Kuniyuki Iwashima
2024-09-10 16:55 ` Shoaib Rao
2024-09-10 17:57 ` Kuniyuki Iwashima
2024-09-10 18:16 ` Shoaib Rao
2024-09-10 18:33 ` Kuniyuki Iwashima
2024-09-10 18:49 ` Shoaib Rao
2024-09-10 19:49 ` Kuniyuki Iwashima
2024-09-10 20:57 ` Shoaib Rao
2024-09-10 21:53 ` Kuniyuki Iwashima
2024-09-10 22:30 ` Shoaib Rao
2024-09-10 22:59 ` Kuniyuki Iwashima
2024-09-10 23:42 ` Shoaib Rao
2024-09-11 0:16 ` Kuniyuki Iwashima
2024-09-05 20:37 ` Shoaib Rao
2024-09-05 20:41 ` Shoaib Rao
2024-09-05 20:42 ` Kuniyuki Iwashima
2024-09-05 5:25 ` Lizhi Xu
2024-09-05 5:57 ` syzbot
2024-09-05 6:59 ` Kuniyuki Iwashima [this message]
2024-09-05 7:46 ` syzbot
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=20240905065955.17065-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.xu@windriver.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+8811381d455e3e9ec788@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;
as well as URLs for NNTP newsgroup(s).