From: Paolo Abeni <pabeni@redhat.com>
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
"Björn Töpel" <bjorn@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Eric Dumazet" <edumazet@kernel.org>,
"Neal Cardwell" <ncardwell@google.com>,
"David S . Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Willem de Bruijn" <willemb@google.com>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
Simon Horman <horms@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Lorenz Bauer <lmb@cloudflare.com>,
Petar Penkov <ppenkov@google.com>,
Tariq Toukan <tariqt@nvidia.com>,
Alice Mikityanska <alice.kernel@fastmail.im>
Subject: Re: [PATCH bpf] bpf: Use the checked TCP header length in the syncookie helpers
Date: Wed, 2 Dec 2026 10:50:41 +0100 [thread overview]
Message-ID: <a678597e-5c1b-4a78-a5b6-df2f0fbb8271@redhat.com> (raw)
In-Reply-To: <DN9TALTRFHMA.1SEQ9R930YVX@gmail.com>
On 12/2/26 01:14, Alexei Starovoitov wrote:
> On Tue Dec 1, 2026 at 9:17 AM UTC, Björn Töpel wrote:
>> Each call to bpf_tcp_gen_syncookie(), bpf_tcp_raw_gen_syncookie_ipv4()
>> or bpf_tcp_raw_gen_syncookie_ipv6() reads th->doff twice. The helper
>> first checks that th->doff matches th_len, the header length that the
>> verifier allowed. tcp_parse_mss_option(), called directly or through
>> tcp_get_syncookie_mss(), then reads th->doff again to find the end of
>> the options.
>>
>> The header can change between the two reads when userspace can write
>> the memory it lives in. That is the case for packets in the UMEM of an
>> AF_XDP zero-copy socket, and for values of a BPF_F_MMAPABLE array map.
>> If th->doff grows from 5 to 15 in between, the option walk reads 40
>> bytes past the header that the verifier allowed, and faults when the
>> header ends a mapping.
>>
>> Pass the checked length to tcp_parse_mss_option(), so that each call
>> reads th->doff once.
>>
>> A header that changes during the call can still give another MSS or
>> cookie, as any rewritten packet would, but the walk stays within
>> th_len. The helpers that check cookies read no length from the header
>> and stay as they are. The functions that take the new argument have no
>> other callers.
>>
>> Overhead; This costs nothing measurable. A BPF_PROG_TEST_RUN loop that
>> calls bpf_tcp_raw_gen_syncookie_ipv4() on a 40-byte header takes 136
>> ns per run with and without this patch.
>>
>> Found by an AI code review agent, and reproduced in QEMU without
>> kernel changes. An XDP program on an igb zero-copy queue calls the raw
>> IPv4 helper on a header in the last 20 bytes of the UMEM, while a
>> userspace thread flips th->doff between 5 and 15. The kernel oopses in
>> tcp_parse_mss_option() on the guard page after the UMEM within
>> seconds. A BPF_PROG_TEST_RUN program with the header at the end of an
>> mmap()ed array map value oopses the same way. With this patch, neither
>> oopses, and the test_progs tests xdp_synproxy, btf_skc_cls_ingress,
>> tcp_custom_syncookie and cls_redirect pass.
>>
>> Fixes: 70d66244317e ("bpf: add bpf_tcp_gen_syncookie helper")
>> Fixes: 33bf9885040c ("bpf: Add helpers to issue and check SYN cookies in XDP")
>> Signed-off-by: Björn Töpel <bjorn@kernel.org>
>> ---
>> include/net/tcp.h | 8 ++++----
>> net/core/filter.c | 8 ++++----
>> net/ipv4/tcp_input.c | 8 ++++----
>> net/ipv4/tcp_ipv4.c | 4 ++--
>> net/ipv6/tcp_ipv6.c | 4 ++--
>> 5 files changed, 16 insertions(+), 16 deletions(-)
>
> This is more net tree material. If so Ack.
> Or we can wait for netdev folks to ack it.
AFAICS the original code landed via the bpf tree, I think this one
could go the same way.
The change LGTM.
Acked-by: Paolo Abeni <pabeni@redhat.com>
next prev parent reply other threads:[~2026-12-02 9:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 9:17 [PATCH bpf] bpf: Use the checked TCP header length in the syncookie helpers Björn Töpel
2026-12-01 14:06 ` Alice Mikityanska
2026-12-02 0:14 ` Alexei Starovoitov
2026-12-02 9:50 ` Paolo Abeni [this message]
2026-12-03 4:10 ` patchwork-bot+netdevbpf
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=a678597e-5c1b-4a78-a5b6-df2f0fbb8271@redhat.com \
--to=pabeni@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=alice.kernel@fastmail.im \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=lmb@cloudflare.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=ppenkov@google.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tariqt@nvidia.com \
--cc=willemb@google.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