From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179 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== 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== 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 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 ; Wed, 2 Dec 2026 00:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A289606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f066274caeso62683705ad.2 for ; Tue, 01 Dec 2026 16:14:38 -0800 (PST) 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) 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Dec 2026 00:14:37 +0000 Message-Id: Cc: "Kuniyuki Iwashima" , "Simon Horman" , "Martin KaFai Lau" , "John Fastabend" , "Stanislav Fomichev" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "Lorenz Bauer" , "Petar Penkov" , "Tariq Toukan" , "Alice Mikityanska" Subject: Re: [PATCH bpf] bpf: Use the checked TCP header length in the syncookie helpers From: "Alexei Starovoitov" To: =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Eric Dumazet" , "Neal Cardwell" , "David S . Miller" , "Jakub Kicinski" , "Paolo Abeni" , "Willem de Bruijn" , "Jesper Dangaard Brouer" , , X-Mailer: aerc 0.20.1-357-ga8fcb8d99360 References: <20261201091755.1130605-1-bjorn@kernel.org> In-Reply-To: <20261201091755.1130605-1-bjorn@kernel.org> On Tue Dec 1, 2026 at 9:17 AM UTC, Bj=C3=B6rn T=C3=B6pel 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=C3=B6rn T=C3=B6pel > --- > 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.