From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796170480; b=18YZAGlBbEHlCu3c2t0fzTdMwTKY2Qv0PctP5ugwPIidXphO1SCuHdS38PTNAFDYIiRz zffkSQzgcnwfK48XwJdF0RnTqgRGzhD3o8xje4SUBNpLYHxl7ZZdmXbGdiKmIfMLQQ9A9 mEtHhDUGvDpVFnW4EBXvA+t8Jt3VNSVd8n+Jfv/hU1o7iPKodsedEIIl+HS+ntzDgAiQa x8j477dshQIIGB++HqhpASz1ZUHVAkX46bhkSQmTlgQdj6fXOY6s2biE4zkChXkiOMT8r 4FsiQNJ4rbrKcYkN8CTjX8J2/qZcNKPwPtKfOydQZDBDAI4oaNE8xJFvGoQHazHEjaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796170480; 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=dj0E8FrYegnL2S5zqquSJvbQbO4hOHdjuowFx5NW931NUWIqsQgOoDLr0EnO2CEYQ3EX t0ObW8Gz+SJKWtV8F7rzHLByBWhaSpERItBdlSqIPU79EbNFWqDCc7b41ShEEYfnKOegT Ad52P0yvLVOWhxz31TyriQ+HyRkgSF6wrkxOWgHcjGiT5uxR4Zk1Ge0WZjbpe+m5+Y1AH bpLs7AFLUxaXAUlurGWgmOJtaGkoYsN7FBQu6hcce3utCuYm1j4GNzMNRhXb08BKCkf7P 3hA+30Uwz2z47IcNDv4nyKG30dUzFowVlv9morczzBk+ruvc20/NxuX6Mgp4CXSLcqg== 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.173 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 165DF606A320 for ; Wed, 2 Dec 2026 00:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 165DF606A320 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-f173.google.com with SMTP id d9443c01a7336-2f03920c4a0so75482955ad.3 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=fSNknjhbjuc9uFbprVaFQkSbX7v/Z2hjEuaTxYUDxOQt6G+BlRLEB/QvYSEuh36WYm OwJEP6fccPZjUbc8HkEOL5D5hW1qTUurs4ipnMYO8q2GXrYzqn6Hb9zYTdRNrOiMRYk2 5WQ4kbt5lebOK/Ostjx00Hx3HKstuh55e/lGc+ooy7Ta4rkvnMLAxfwD+/veEs7Lrshr qzP5Y7ZXAx682kdJQmLHucN5nNvcUwt8ayPZkFidHHjcKpyCoWK8FFvChQO0A2StlYdI 42M4bAYcH9Zq5U8k09lcwXhrDg0POnO3o308uOfGMnzFI1wibmGQutTIkIP3VzJ/zgUQ jxfg== X-Forwarded-Encrypted: i=1; AL+hErFd4pDw2+QmCD3vUjckLYUEH6SnT4U6VwIfoz97/Ssq9cARA+D9OXYQnLMauav790THxZQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/9SLGxLhduC0vl2stREPwgSdNzQaHCc1x5dnBBp9VPulIzuQtY OVM3qdiaqiSVtlH9TUbT+hFFOB0RowhwG/Lf2CfxPeURq8sBKK6HlSCM X-Gm-Gg: AZFdTZfvwSg+iZPKcZ9XdUDtuQ8FiRAmhZ2kl3TDnmxce+5kJ1TaT4P3C1GVognQAHH I96biMbL93hUTnldqw/mdGu9O5I5+ntan/4EbZUdI7jU8OHxVFwcwTBeU6EUWzbcGenpZm2yKt6 ZKhkGar9+qJW/uUooLg4uT4yO0jyXnST7NsfECmzgfO2fZGByvH4cF+v3d5/oZZtsP8Qz20AdVD jEcedHdWbvuSITu9BrqMagyb6BtAIw7bdhPysTpMLs7mzH+3hlU3G/MA0h/YDK+kuEgmR3a1tvj msWu4Rk+njL4ANJeCJMFYv0cj+VXp4pYbgrN+OgVWQ5WFScCaNiupeq0nYDGEtgyYrgo7Vl3RjM fo1MMMKB2iAb82CG/7pbMI/Xfy6nuJTUnpAWIqhqHYAUoUwCRhDwolRnCB4MYxcm/71HjUpRDIq CYsQ2E+YZdwQ2ojk/g847rX/6/mgLr8RPoX49ax00f2fY+nfA4WNQTFlBXmtIllXck+w5u5Mx6C T8rII/AfLKLEWlZTJFsgkScNpg0tHjAj349DQEu0A9tUEeIyVQK9tjDhMu/5tF5Xv4b6Y8MU/mk 5nohxz85oTkwVp6RHDLdt3qStmxyIgdFK6TmACpVzE9Nty3O8+afin3PnTKKf53E9KP/QRUecdF INRvLuG8YOBVx+aWjnBDBtPKBLgYtKHM9Ewcl9cLONmgSSC7bw0kQx9Q= 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: bpf@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.