Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796205048; b=bNlJOg+c5J2wgH9HWQxRLCKJt14xjSrhpAVdppmMq5ViJvsPwjnDkLbWOBgVZWrX+imi E6JDJ274DnIr6eaz8d7vXr1MC7NFoLMIbRX244wEgyUmmt54QefOPIvZ/n4thK7GQhzu6 ackF41nXH+y6goeuAEhMqFHLBSF0dhUKLr43FaD/8tDbnuV8N6/Zu4VxYALdvTi0gP5T/ 1VVdjAKha9WTUPl0Neu1mqQkPx8PFSdcofDi8SrtOzN9FSri/7EQjJZ3gIOY6K4YpSec4 vFRJayva1IbH4Ozo6/imp/Omg5EsTK5TYpFuYeCoFu+2Zj6Wwoohw8wHLxNtCPQAE9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796205048; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject: To:Cc:References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=HUeeeMlwgOfKkH27sydbO60l4Fz4qvbi/reUcLO/txI=; b=VzByRjRLaHGf42Auv9hBPBMYNf1w4TB1u+sI+bgWuWVAEX/qP57mW7Ullg15DXH1Id1S M+EfGJQgc0F+CrOdqdHd5Rtlg06tiYIURiMkECjn1phy2DsUwHaah/RhsmlZUWqR7/sOv 4XUA+uIUf62a7wit4flKDl5RshDHkPug7oNgWRcMhEHuwlbJ2o6VMhjNLA/tHdeqvcuuF T3ID6TGycXE09uSswXM6WXACMIsbskyGk1pmoTi8n54t9VXLNA+uNmfknTQN/jjEsEgAe Up0mU4fLSSEckXeWBcXYDGzzTSW67lVUAwdFqBkKtFplN/Y3Sj2OaYIkZ70FqgoBTPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dicreVNM; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=kSqgYpNi; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55DB0606A31A for ; Wed, 2 Dec 2026 09:50:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 55DB0606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dicreVNM; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=kSqgYpNi DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796205048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HUeeeMlwgOfKkH27sydbO60l4Fz4qvbi/reUcLO/txI=; b=dicreVNMMXZRaBElRinbAyss8bB6O8Kih28qxdT7UqE/SMj78gyMzt+j+aRtmsJFkpD5hz r+mNQDMxen4V0yFC2glEvt/CkbWEK67TGNUVRG1kSzdDpwxBjqXEG1OAPSN/9Fppz+gY71 etqbw31ViUFjmALrmyYTsVxIjubPL5A= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-kqBHlMVAOhCnAq12daZ_Aw-1; Wed, 2 Dec 2026 09:50:45 +0000 X-MC-Unique: kqBHlMVAOhCnAq12daZ_Aw-1 X-Mimecast-MFC-AGG-ID: kqBHlMVAOhCnAq12daZ_Aw_1796205044 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-48c6a1d4034so7784118f8f.0 for ; Wed, 02 Dec 2026 01:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796205044; x=1796809844; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HUeeeMlwgOfKkH27sydbO60l4Fz4qvbi/reUcLO/txI=; b=kSqgYpNiMUDElpDxZFhPIwmI/ZyMeNRLPHDVPKBTuSZLkoySLbIkOsIepSySbmFMlX x4Jlv4kjTw99/i5ukPHbOe6LVUT8Mw7Q6HM6PkZblwdLL1PnjMh8fYtE2PsvZy5aLw9x 7YOec6U6oOMtv/613OMgKdH/3xpkv/5toyhKVyiiARty8s/ya74UrddEosiZOhH3rX9j hSgR+OqmOBRMlSxDz38Lvn9huiqHxxQb0k3XmBaOmQQrdlQw9rjOHviFVBiRZGDe7aWG UK5L3I5vhhx1Ed2snhdAFsYXeyjulqovGQrgdpc5oEgN+5t9e3DMNH2p1SpH+J6bWQ6N CvXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796205044; x=1796809844; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HUeeeMlwgOfKkH27sydbO60l4Fz4qvbi/reUcLO/txI=; b=HUS8B0Z+4jjRuqPHZFeFfwNSDPpyrRgBMO7ixKvKp2m/q+9ALoC28ZZQYdUofdOPvE bm4NWNHLDe2GNVte7UdHmHH2vHejfucgjXeeH3FerrDkx2PWGoS9Iw2r0jgWJZP5F29o cGzRTpldbz0pGCcfiopweTGdqXLUhxt6dzDq6gM6rCFMl/836tZhtUwHmxdF+7PcWxFE 51p4hjO+M7geRyNpZ7zIxapDEHwoC42jbqmMgctvH7fF3PP7O0kSRLI33ocujAKs+RW4 ov1bUB2efN6mGdzJo8Fcsd1I6ilcndwqufs9It+YpVn3YHRbqX6MemapKwTB/wie1yQC v4Cg== X-Forwarded-Encrypted: i=1; AL+hErFKhazjeBUdGlwZyAaBeKz2VCbr/5Mslt6F0xoprs7c2drUHadA6drURh/BAQtHFR3iWuI=@vger.kernel.org X-Gm-Message-State: APuU4Z8KU9An7BaOySWjiQx5JE7VUZjCqDn1qQrrBNx96F8GmjzEZEtC H4A02fAzqylpzNG81wPvIvHnsEnRLBuc7LE2jLIkRHAQ05nwhaVgk5J8x6N8D0IykYg5DRHbPX/ dnwXhmqVbk2qdbEjdrZNECgJHc2uSRcEKQlMej4s2wG1hFqN+91xPrQ== X-Gm-Gg: AZFdTZeDouJ8ndMi1V4RoRIb553o/nE+ZOcZhJQfoyhSSEcdu1XcE2Is66bkbj/Sgbg HX5iMIZPt3WCaD98jMhPSAwqglRa3jaJwvL1/lthG6cSc7ULkEvluilogPRnA/Q7YFZc03AX0jB 9vzrX/IKlBKptn9veJVcynuzSL+QllhdfOGBH0qCCCkIl6QDTgy1yHgsoYKEfrC6jpHcAW6+Ncl /d0j04EVzpH6G3gp8h+7pCys/+gCiINfxLh3BxFiTCNsG3DFdyQbmpZdJRenYIYZ3s2WIwEgef6 3EK3ITPfR2rSSjXHR2uzJ8LNgXUjcYwrJToppErt8qKOCOCOBGSVrd9P8Z+t/6gOJdb5iSfM9aF XfXYxMzvPnL0LMYdFbhR9m8IUAFxhNIjuzee/KQTsIc2e3qqbe+E0/81SNFpKtN7QDQrDCx8r1T JMBZD1CKAu4366uqCyMEbhEMxFQfmMf5f2cyJUxYP42yE= X-Received: by 2002:a05:600c:4e93:b0:4a2:190f:cf6a with SMTP id 5b1f17b1804b1-4bb8894283emr791163545e9.35.1796205044034; Wed, 02 Dec 2026 01:50:44 -0800 (PST) X-Received: by 2002:a05:600c:4e93:b0:4a2:190f:cf6a with SMTP id 5b1f17b1804b1-4bb8894283emr791163125e9.35.1796205043535; Wed, 02 Dec 2026 01:50:43 -0800 (PST) Received: from [192.168.88.30] (ip231-128-192-82.pool-bba.aruba.it. [82.192.128.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853b2437sm1451407525e9.13.2026.12.02.01.50.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 01:50:43 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 10:50:41 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf] bpf: Use the checked TCP header length in the syncookie helpers To: Alexei Starovoitov , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Eric Dumazet , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , bpf@vger.kernel.org, netdev@vger.kernel.org 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 References: <20261201091755.1130605-1-bjorn@kernel.org> Content-Language: en-US From: Paolo Abeni In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 >> --- >> 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