From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <kuniyu@amazon.com>
Cc: <andrii@kernel.org>, <ast@kernel.org>, <bpf@vger.kernel.org>,
<daniel@iogearbox.net>, <davem@davemloft.net>,
<dsahern@kernel.org>, <edumazet@google.com>, <haoluo@google.com>,
<joe@cilium.io>, <joe@wand.net.nz>, <john.fastabend@gmail.com>,
<jolsa@kernel.org>, <kafai@fb.com>, <kpsingh@kernel.org>,
<kuba@kernel.org>, <linux-kernel@vger.kernel.org>,
<lmb@isovalent.com>, <martin.lau@linux.dev>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>, <sdf@google.com>,
<song@kernel.org>, <willemdebruijn.kernel@gmail.com>,
<yhs@fb.com>
Subject: Re: [PATCH bpf-next 1/2] bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign
Date: Thu, 25 May 2023 19:49:31 -0700 [thread overview]
Message-ID: <20230526024931.88117-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230526014317.80715-1-kuniyu@amazon.com>
From: Kuniyuki Iwashima <kuniyu@amazon.com>
Date: Thu, 25 May 2023 18:43:17 -0700
> From: Martin KaFai Lau <martin.lau@linux.dev>
> Date: Thu, 25 May 2023 16:42:46 -0700
> > On 5/25/23 1:19 AM, Lorenz Bauer wrote:
> > > diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h
> > > index 56f1286583d3..3ba4dc2703da 100644
> > > --- a/include/net/inet6_hashtables.h
> > > +++ b/include/net/inet6_hashtables.h
> > > @@ -48,6 +48,13 @@ struct sock *__inet6_lookup_established(struct net *net,
> > > const u16 hnum, const int dif,
> > > const int sdif);
> > >
> > > +struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
> > > + struct sk_buff *skb, int doff,
> > > + const struct in6_addr *saddr,
> > > + __be16 sport,
> > > + const struct in6_addr *daddr,
> > > + unsigned short hnum);
> > > +
> > > struct sock *inet6_lookup_listener(struct net *net,
> > > struct inet_hashinfo *hashinfo,
> > > struct sk_buff *skb, int doff,
> > > @@ -85,14 +92,33 @@ static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
> > > int iif, int sdif,
> > > bool *refcounted)
> > > {
> > > - struct sock *sk = skb_steal_sock(skb, refcounted);
> > > -
> > > + bool prefetched;
> > > + struct sock *sk = skb_steal_sock(skb, refcounted, &prefetched);
> > > + struct net *net = dev_net(skb_dst(skb)->dev);
> > > + const struct ipv6hdr *ip6h = ipv6_hdr(skb);
> > > +
> > > + if (prefetched) {
> > > + struct sock *reuse_sk = inet6_lookup_reuseport(net, sk, skb, doff,
> >
> > If sk is TCP_ESTABLISHED, I suspect sk->sk_reuseport is 1 (from sk_clone)?
>
> Exactly, it will cause null-ptr-deref in reuseport_select_sock().
Sorry, this doesn't occur. reuseport_select_sock() has null check.
> We may want to use rcu_access_pointer(sk->sk_reuseport_cb) in
> each lookup_reuseport() instead of adding sk_state check ?
And if someone has a weird program that creates multiple listeners and
disable SO_REUSEPORT for a listener that hits first in lhash2, checking
sk_reuseport_cb might not work ? I hope no one does such though, checking
sk_reuseport and sk_state could be better.
>
>
> >
> > If it is, it should still work other than an extra inet6_ehashfn. Does it worth
> > an extra sk->sk_state check or it is overkill?
> >
> >
> > > + &ip6h->saddr, sport,
> > > + &ip6h->daddr, ntohs(dport));
next prev parent reply other threads:[~2023-05-26 2:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-25 8:19 [PATCH bpf-next 1/2] bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign Lorenz Bauer
2023-05-25 8:19 ` [PATCH bpf-next 2/2] selftests/bpf: Test that SO_REUSEPORT can be used with sk_assign helper Lorenz Bauer
2023-05-26 0:06 ` Martin KaFai Lau
2023-05-25 13:24 ` [PATCH bpf-next 1/2] bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign Eric Dumazet
2023-05-25 19:51 ` Daniel Borkmann
2023-05-25 17:41 ` Kuniyuki Iwashima
2023-05-25 20:01 ` Daniel Borkmann
2023-05-25 23:42 ` Martin KaFai Lau
2023-05-26 1:43 ` Kuniyuki Iwashima
2023-05-26 2:49 ` Kuniyuki Iwashima [this message]
2023-05-26 21:08 ` Martin KaFai Lau
2023-05-26 5:56 ` Joe Stringer
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=20230526024931.88117-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=joe@cilium.io \
--cc=joe@wand.net.nz \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lmb@isovalent.com \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yhs@fb.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