From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Kuniyuki Iwashima <kuniyu@google.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Joe Stringer <joe@wand.net.nz>,
Network Development <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf v8 1/2] net: Validate protocol in skb_steal_sock() for BPF-assigned sockets
Date: Tue, 9 Jun 2026 21:54:38 +0800 [thread overview]
Message-ID: <f0468cb2-1b52-4216-9592-ceb204f6ea41@linux.dev> (raw)
In-Reply-To: <CAAVpQUC1Ot9vr09gNoe+vxgLoqU8Wwn2DV+CQZYYpAJUATJiWg@mail.gmail.com>
On 6/9/26 6:34 AM, Kuniyuki Iwashima wrote:
> On Mon, Jun 8, 2026 at 3:16 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>> On Mon Jun 8, 2026 at 2:35 PM PDT, Kuniyuki Iwashima wrote:
>>>> btw is earlier sashiko TOCTOU concern real?
>>> Yes, the selftest in patch 2 should reproduce null-ptr-deref.
>>> (I tested one in a prior version)
>>>
>>>
>>>> iph->protocol = IPPROTO_TCP;
>>>> bpf_sk_assign_tcp_reqsk(udp_skb, tcp_sk);
>>>> iph->protocol = IPPROTO_UDP;
>>>>
>>>> as far as I can tell past bpf_sk_assign_tcp_reqsk()
>>>> the networking stack only looks at skb->protocol,
>>>> so modifying iph->protocol will only mess up
>>>> things on the wire (if this packet goes out).
>>> ip_rcv_finish_core() uses iph->protocol for early demux
>>> and ip_local_deliver_finish() also uses it for demux.
>> ok. Another idea... we can keep the checks on bpf side and
>> teach the verifier to invalidate packet pointers at bpf_sk_assign_tcp_reqsk()
>> and introduce new concept of "readonly skb".
>> So after invalidation the reloaded sbk->data will be read only.
> Yes, this is exactly what I had in mind in the other thread :)
>
> ---8<---
> On top of L4 validation in bpf_sk_assign() and bpf_sk_assign_tcp_reqsk(),
> can't we mark such an skb immutable after the helpers and catch
> subsequent writes to skb->data on the verifier ?
> ---8<---
>
>
>> There is no such thing today. The verifier only understands PTR_TO_PACKET
>> as read/write. So it's not easy, but probably good thing to have
>> for this and other cases where bpf prog shouldn't touch the packet
>> once it called some kfunc/helper.
> This would be useful and we could (re)move some validations from
> the fast path.
Hi Kuniyuki and Alexei,
Thanks both for the discussion, it makes sense to me.
I'll go back to fixing this in the helper itself, like the previous
version did.
Then, as a longer-term and more general solution, I'll try look into
marking the
skb as immutable after these helpers so the verifier can reject any
later writes
to the packet.
next prev parent reply other threads:[~2026-06-09 13:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 12:58 [PATCH bpf v8 0/2] bpf: tcp: Fix null-ptr-deref in arbitrary SYN Cookie Jiayuan Chen
2026-06-08 12:58 ` [PATCH bpf v8 1/2] net: Validate protocol in skb_steal_sock() for BPF-assigned sockets Jiayuan Chen
2026-06-08 13:31 ` sashiko-bot
2026-06-08 13:31 ` bot+bpf-ci
2026-06-08 17:21 ` Kuniyuki Iwashima
2026-06-08 20:02 ` Alexei Starovoitov
2026-06-08 20:55 ` Kuniyuki Iwashima
2026-06-08 21:25 ` Alexei Starovoitov
2026-06-08 21:35 ` Kuniyuki Iwashima
2026-06-08 22:16 ` Alexei Starovoitov
2026-06-08 22:34 ` Kuniyuki Iwashima
2026-06-09 13:54 ` Jiayuan Chen [this message]
2026-06-09 17:14 ` Kuniyuki Iwashima
2026-06-08 12:58 ` [PATCH bpf v8 2/2] selftests/bpf: Add protocol check test for bpf_sk_assign_tcp_reqsk() Jiayuan Chen
2026-06-08 13:07 ` sashiko-bot
2026-06-08 13:31 ` bot+bpf-ci
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=f0468cb2-1b52-4216-9592-ceb204f6ea41@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=joe@wand.net.nz \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yonghong.song@linux.dev \
/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