From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <lmb@isovalent.com>
Cc: <bpf@vger.kernel.org>, <daniel@iogearbox.net>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<kuniyu@amazon.com>, <linux-kernel@vger.kernel.org>,
<martin.lau@kernel.org>, <martin.lau@linux.dev>,
<memxor@gmail.com>, <netdev@vger.kernel.org>, <pabeni@redhat.com>
Subject: Re: [PATCH bpf-next] net: Fix slab-out-of-bounds in inet[6]_steal_sock
Date: Wed, 9 Aug 2023 08:55:38 -0700 [thread overview]
Message-ID: <20230809155538.67000-1-kuniyu@amazon.com> (raw)
In-Reply-To: <CAN+4W8hMpL3+vNOrBBRw01tD6OxQ-Yy8OWpq9nRtiyjm0GgE4g@mail.gmail.com>
From: Lorenz Bauer <lmb@isovalent.com>
Date: Wed, 9 Aug 2023 16:08:31 +0100
> On Wed, Aug 9, 2023 at 3:39 PM Martin KaFai Lau <martin.lau@linux.dev> wrote:
> >
> > On 8/9/23 1:33 AM, Lorenz Bauer wrote:
> > > Kumar reported a KASAN splat in tcp_v6_rcv:
> > >
> > > bash-5.2# ./test_progs -t btf_skc_cls_ingress
> > > ...
> > > [ 51.810085] BUG: KASAN: slab-out-of-bounds in tcp_v6_rcv+0x2d7d/0x3440
> > > [ 51.810458] Read of size 2 at addr ffff8881053f038c by task test_progs/226
> > >
> > > The problem is that inet[6]_steal_sock accesses sk->sk_protocol without
> > > accounting for request sockets. I added the check to ensure that we only
> > > every try to perform a reuseport lookup on a supported socket.
> > >
> > > It turns out that this isn't necessary at all. struct sock_common contains
> > > a skc_reuseport flag which indicates whether a socket is part of a
> >
> > Does it go back to the earlier discussion
> > (https://lore.kernel.org/bpf/7188429a-c380-14c8-57bb-9d05d3ba4e5e@linux.dev/)
> > that the sk->sk_reuseport is 1 from sk_clone for TCP_ESTABLISHED? It works
> > because there is sk->sk_reuseport"_cb" check going deeper into
> > reuseport_select_sock() but there is an extra inet6_ehashfn for all TCP_ESTABLISHED.
>
> Sigh, I'd forgotten about this...
>
> For the TPROXY TCP replacement use case we sk_assign the SYN to the
> listener, which creates the reqsk. We can let follow up packets pass
> without sk_assign since they will match the reqsk and convert to a
> fullsock via the usual route. At least that is what the test does. I'm
> not even sure what it means to redirect a random packet into an
> established TCP socket TBH. It'd probably be dropped?
>
> For UDP, I'm not sure whether we even get into this situation? Doesn't
> seem like UDP sockets are cloned from each other, so we also shouldn't
> end up with a reuseport flag set erroneously.
>
> Things we could do if necessary:
> 1. Reset the flag in inet_csk_clone_lock like we do for SOCK_RCU_FREE
I think we can't do this as sk_reuseport is inherited to twsk and used
in inet_bind_conflict().
> 2. Duplicate the cb check into inet[6]_steal_sock
or 3. Add sk_fullsock() test ?
next prev parent reply other threads:[~2023-08-09 15:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-09 8:33 Lorenz Bauer
2023-08-09 11:58 ` Kumar Kartikeya Dwivedi
2023-08-09 14:39 ` Martin KaFai Lau
2023-08-09 15:08 ` Lorenz Bauer
2023-08-09 15:55 ` Kuniyuki Iwashima [this message]
2023-08-09 16:55 ` Lorenz Bauer
2023-08-09 17:14 ` Kuniyuki Iwashima
2023-08-09 17:12 ` Martin KaFai Lau
2023-08-12 3:35 ` Martin KaFai Lau
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=20230809155538.67000-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lmb@isovalent.com \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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®