Article View: linux.kernel.netdev
Article #25534Re: [PATCH bpf] bpf: Use the checked TCP header length in the syncookie helpers
From: "Alexei Starovoitov"
Date: Wed, 02 Dec 2026 00:14
Date: Wed, 02 Dec 2026 00:14
53 lines
13974 bytes
13974 bytes
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.
Technical Details
Message-ID:
<DN9TALTRFHMA.1SEQ9R930YVX@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375445-linux-kernel-netdev=dewy.ruReferences:
<20261201091755.1130605-1-bjorn@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375445-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com ("Alexei Starovoitov")
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH bpf] bpf: Use the checked TCP header length in the
syncookie helpers
Date: Wed, 02 Dec 2026 00:14:37 +0000
Organization: Usenet Network
Message-ID: <DN9TALTRFHMA.1SEQ9R930YVX@gmail.com>
References: <20261201091755.1130605-1-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1849281"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DdIMMUW7fRCYdAkuS5xMlvkqjDs= sha256:EMYRN8q0Tw/tlX1Y0yDqDdbEdoA9TpN+1TgAkIRfkek=
sha1:hYm3/4J/kr1mFpifkJYtIS7PFoU= sha256:A4V51ka/dITy5G/rSyqkkSf4I5QFOemME0KLnUKsuTs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id E8D931174F4; Wed, 2 Dec 2026 03:14:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id V-B-46gQz82H;
Wed, 2 Dec 2026 03:14:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375445-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 0C1C11171E1; Wed, 2 Dec 2026 03:14:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 39043602F89; Wed, 2 Dec 2026 00:14:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796170480;
b=FgPnSsoFPJBXVk2+S5vf/elkHOWuuEVN4UA0QJqIUGu4K3fEUE88ZBQxKnn3wxf2sH9q
/3IiRgHxTmNsktBqT6sBSs0UhmxYjGE8VS7gW3bfimRsJwmAI4Y5912ya5TjvEmlDMX5o
pfx/P8/M36e+yGjWJXNGAsLwDi80paUieSiGPYzaVZd/iwbL4TeKXtZUqJuyTD/SaE7C5
vVyXozMC/fXL+izIquZMOCWykEwOPUfsJevlaHHb+XQs90eel5noEtT1AuXFREQG4/JZW
NX+AU50xjDA0WtHmlsz9L6NC9lf8HRh/nMktkHAz9k49a2s4zJJG1ZwOLkcGJJrAYsw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796170480;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id:
Cc:Subject:From:To:X-Mailer:References:In-Reply-To;
bh=KC6EWtHW5rfQhhtG4jBZ0fTinMBaaZvz9472z9mO8sk=;
b=uMLC7Kygag13s1pK6HczMDEVpFEpG3VskB7PEzghIDG3YGQNtfO1QqCtBT3okRTzFsRT
HC6/HQytn/o6qvreKCzEDO3Es93hRuCDoyAXll64M1OWnvSoiY8rkhNSCmrhZNS9/Sv2P
CTtktKw6B8ha6TDylR8g5cBxfheRQsFOemaCi2UfUgGD8WX8MvvL7n66dyWxnqQ9bIYpU
QsDph1+7rrp8wyWXv1CnoW+hShGumkpiAt86xZ8vAPRh8HZpNQsBiFqTzM28wuQ2CFpet
NRlK+Y3ZXGsxO+MngOp+mOjjA34tak9SiTRRoZDDqH92XqbSd4Tp3RhCUjX9FEGwlLA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eTNDzG7y;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 585DF606A330;
Wed, 2 Dec 2026 00:14:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eTNDzG7y
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796170479;
b=0P22Ns0m6ZCk/aHSX2c2RUp15FY65Fs3IzbGrqj/qEI8gFMyOD+Y/mF/UbBByCfzoJMq
1E3xKb9cPkiTwyV4jrQepeQ/agv673b7914Vo73TJSeF8jAm+iy8jZNqb8dnScD+NOapZ
XKr2sSkk/ylOStyLP2ZKB8BH4l33125Lue4wVjl5B0/mSuitkOCFf860Y4Z9RG76ogmvI
5gScfJdtB9TCsYt+EzA3WumoTj1XnX94BFrFA5b4MmXlckZT6ajr8VTHleP2u/5jztUPT
rdWShrhtsA0X9E0w1e0vVLzACAwxYNKbBAKOCbuWK0d1acRyZlqgGko2dUXaxJbGk5g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796170479;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id:
Cc:Subject:From:To:X-Mailer:References:In-Reply-To;
bh=KC6EWtHW5rfQhhtG4jBZ0fTinMBaaZvz9472z9mO8sk=;
b=24advSUxi2/4rpShTnOROjBOr5htplVlzuLgG8r8SCnsMWUM3Z8Tf8dAEiVrSdlDRqQL
E+57fCwsjIUrkwLvEy6tq6LKZbNyx6JrU+O7dYql75YZ5utT4hXUFd+0sFPzE7JwD3dfs
omjRnrdcKwb7Bto/D2+VSrwy5bNM16NDzOsQNhQtn+8Shmbrws5ewQgBBZ1HREhQNKZJt
Vw/CPTXkbN+kLAhxzxc7k5SNn9yUPBDbLnjcCus8/bKF7gYHkVZVPz8xDrpsFug+ka9x3
xchLW1JYULTyb8oJMs/JpAldqsfzjDxik4nIsqfPWkY1Hqc23q9rD+iDw+YscvKXvPg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eTNDzG7y;
arc=none smtp.remote-ip=209.85.214.179
X-Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A289606A322
for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 00:14:38 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A289606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f066274caeso62683705ad.2
for <netdev@vger.kernel.org>; Tue, 01 Dec 2026 16:14:38 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796170478; x=1796775278; darn=vger.kernel.org;
h=in-reply-to:references:to:from:subject:cc:message-id:date
:content-type:content-transfer-encoding:mime-version:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=KC6EWtHW5rfQhhtG4jBZ0fTinMBaaZvz9472z9mO8sk=;
b=eTNDzG7yWXRWIKm1oMga8hpZAcrfE6VNJeGPd8ll0NCqk6RPxr+Vne78iphrZUVz2s
hF9Sfg88wTkUOkRstte2zBU+TVzTaoPFiRcu8jk+Fa9ptQPCzmHzlkIvx/dNwsdNQ1cT
FEAIKc935kaSlTeQDXiunGRzFjNe7n8He0tqUbzJ2bp2ceY9139e1OHnymWLslnHoQ1V
mijaoQ52ukdkEtB7fe4t0dZALQSZDPt1JHR/vie3ppMWUIlSj61heWuHY5Ga0jv5qmmL
W6haq35bYB4u+L6iv09LOEzVl1IeAfR5p6DHhGyV/wTLdhBoWmubmfwnhH/YsWtRrTEz
wl+A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796170478; x=1796775278;
h=in-reply-to:references:to:from:subject:cc:message-id:date
:content-type:content-transfer-encoding:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=KC6EWtHW5rfQhhtG4jBZ0fTinMBaaZvz9472z9mO8sk=;
b=vv5RuAooXwC05G2p3dc65q3IdLDcw3Sb1Uo0eanQl2m+fDydtrqo/LBqgY0/1Ab9Hh
HV7XEl7iEa3JxXKw0XWCIIBicWg9bIxJD97GM1gyNVpK8Pzbj2fAWnDtCnwSYTAjD0DJ
flTMrs0IcevTf/zYEGW6pOjeLwid6xPLDEIKuzL7xSGMvhGofctGa2B4XdXU7N5+q1Ei
0icj+M8vRpVJxy/+wFxM4i9izjHoglhmbaYs7IjDPLG1aUKN3oYrCEpx88lz64lMv6dD
jDR7az1qTfEyjKcg3nmluzUL0Idm//YiHF+fSHvyfMJIiq5PlqiTjWLuK9LFu0h9QNBA
wbaw==
X-Forwarded-Encrypted: i=1; AL+hErEkImQ+xn/2r12hfkOX1sAfJvw9FWY7YycZcZuxO7UiMpd9zr69P8TZspmYGwRkulu2/9irrwY=@vger.kernel.org
X-Gm-Message-State: APuU4Z8bGQ0AZWPwUGAt1Je8G5ecCKJkzGrQDNo+Ak8dytUvewulDu+D
fsxjA49FR1UVurqt+I3n9fCf7eQj8Y2fPRU8VCnctmUelNjtIZyMsV87
X-Gm-Gg: AZFdTZd2B0oss9GkE+quPfpK77lmRXHnLxmTFfIpL8AiMpL3Pwsc8cXasePsIJTca1/
VWsRsHTOL2DMZm3xlK4s+Vom7sPa4npp97NqdGA5TTMaKhrtHDC6lv1FDq/Jf8G5Kn85epC4pzu
mi9I0NqgZhokpvCitv3jrMnd2n2/ynrtAKgYttM1mmPrXWp4S6V9SK7Wa+75lzqBrHA7VjlND0k
00rRyCOyNQruB/3zoomNbN1P+bpRovpr8V5udsHSD2uEcjcy088IxcKW0qzh4PhfTfwAG6+TO9k
jC16HJYv38NrsC8OflaHpQoXvhNND8Gk7BwyTOLjWY3GvjIVUy87j6wpAQoKMyDlmYTnRMmx0ty
jX6tngsMK1WoVljCxcKg74HZYdVLanVazTmRQs6Emv0Pha1AE4UECj5XE95kJFJmwc4JfT+gnjH
h6D6GmnETnnN5FlcGscPVlP2rL0tnCFqgzM6mM9hrckdsa8/Yf5KD2iRrMvAXiGmAMiM/CDdllm
F5ztJaZelTLWA9u1+IoxWXZX/VNWkwQpucYlIPo+nnVZSogAT8HTsJ50MMLIcBHt+DOv2rjn174
uqUfRSejPyWUBURLN4qnse/U/Mxwu96QFZ9UZuZWxvtaEoKoYuuDJ1RNvuaVcLQ8exYnlrD0Lxu
Sq3Xny4KnP3DgzcFo09c1CPei8V7nS3nofuTsgsazZH5TeLZxwgajnM0=
X-Received: by 2002:a17:902:e741:b0:2e9:d0fd:639c with SMTP id d9443c01a7336-2f03f1ea747mr422988445ad.55.1796170478099;
Tue, 01 Dec 2026 16:14:38 -0800 (PST)
X-Received: from localhost ([153.61.198.253])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1542d2db2sm33647275ad.36.2026.12.01.16.14.37
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Tue, 01 Dec 2026 16:14:37 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-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>
X-Mailer: aerc 0.20.1-357-ga8fcb8d99360
X-In-Reply-To: <20261201091755.1130605-1-bjorn@kernel.org>