Article View: linux.kernel.netdev
Article #4192[PATCH bpf-next 11/38] bpf: Validate the SRH which End.DT6 uncovers in End.BPF
From: Alexei Starovoitov
Date: Sat, 17 Oct 2026 01:24
Date: Sat, 17 Oct 2026 01:24
64 lines
10804 bytes
10804 bytes
From: Josef Bacik <josef@toxicpanda.com>
input_action_end_bpf() validates the SRH of a packet and pulls it into the
head before the program runs. If the program decapsulates the packet with
bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6), bpf_update_srh_state()
looks for a routing header in the inner packet and takes it for the new
SRH as it is.
Nobody has looked at that header, and whoever has sent the packet has
written it. ipv6_find_hdr() finds it in a fragment of the skb as well, but
hdrlen is then read at that offset from skb->data, past the end of the
head. The header need not be an SRH, and its hdrlen need not fit into the
packet, but it is marked as valid, and bpf_lwt_seg6_adjust_srh() and
bpf_lwt_seg6_store_bytes() check their offsets against it.
A program which then adds a TLV at the end of the SRH, where hdrlen has it,
makes bpf_lwt_seg6_adjust_srh() move and write memory behind the head of
the skb, as far as the sender likes within the 2 KB that hdrlen can say:
BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x185/0x240
Read of size 2088 at addr ffff888107d6f09e by task srh/102
BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x1b5/0x240
Write of size 8 at addr ffff888107d6f8be by task srh/102
Use seg6_get_srh(), which pulls and validates the header. Without a valid
SRH the state says that there is none, and the packet goes its way as
before. The pull can move the head, so compute the data pointers behind
it.
Fixes: 486cdf21583e ("bpf: add End.DT6 action to bpf_lwt_seg6_action helper")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/filter.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index a18702f89feb..6ac386dea4e8 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -7022,15 +7022,15 @@ static void bpf_update_srh_state(struct sk_buff *skb)
{
struct seg6_bpf_srh_state *srh_state =
this_cpu_ptr(&seg6_bpf_srh_states);
- int srhoff = 0;
- if (ipv6_find_hdr(skb, &srhoff, IPPROTO_ROUTING, NULL, NULL) < 0) {
- srh_state->srh = NULL;
- } else {
- srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff);
+ /* Behind a decapsulation this is a header that nobody has looked at */
+ srh_state->srh = seg6_get_srh(skb, 0);
+ if (srh_state->srh) {
srh_state->hdrlen = srh_state->srh->hdrlen << 3;
srh_state->valid = true;
}
+ /* it may have been pulled into the head */
+ bpf_compute_data_pointers(skb);
}
BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,
--
2.55.0
Technical Details
Message-ID:
<20261017012451.364800-3-alexei.starovoitov@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347597-linux-kernel-netdev=dewy.ruReferences:
<20261017012058.355787-1-alexei.starovoitov@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-347597-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next 11/38] bpf: Validate the SRH which End.DT6 uncovers in End.BPF
Date: Sat, 17 Oct 2026 01:24:24 +0000
Organization: Usenet Network
Message-ID: <20261017012451.364800-3-alexei.starovoitov@gmail.com>
References: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2934453"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:bEbEqA2gvC2nRzdXThwfNx5ES7g= sha256:dqzvwiwJciuO+CWdUsDajQYTkDzdY1u5E7fOx3tFXJM=
sha1:MCqfaVOrJGICIcHEzE5jrgKttNc= sha256:CtxMthVfydfwejcRN0+TjD68tLUz5C2ZQ8qXMb2WIAY=
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 21DEF110643; Sat, 17 Oct 2026 04:28:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, 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.25,
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 7Z-o92rrzRst;
Sat, 17 Oct 2026 04:27:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-347597-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 8C65B11063F; Sat, 17 Oct 2026 04:27:48 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 3B7F73C3B0; Sat, 17 Oct 2026 01:25:41 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B04531E83B;
Sat, 17 Oct 2026 01:25:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KBUE8Uer"
X-Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3EFF377AB3
for <netdev@vger.kernel.org>; Sat, 17 Oct 2026 01:25:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792200341; cv=none; b=liKioVikwbeKn/SZEMUbFrIqD3ir8GDP3PS8MXJooid2bJHuDBO6AyFuxACQGEqrngOOogSwoCLheVUCKdi2bZq178DtY+JqMv9i4RhkGYZwpvUg5dPWy9yhVLJeaM82LT1RD425ILp+DeFUgEKKXov4dNFRa/LJ5q52NW5x7Sc=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792200341; c=relaxed/simple;
bh=UlbqOc6/7t4Q3Rv1OI56jrgQ8C6d+UlCYrOZt47zjcI=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=d05R0mxHymECagUGd1BFe99h4z2+8DBvMclxgJ4VF34blzY0O4jqpWJ7gYubXbRp+LqjyA7X5/d427k1pAokD9fZFwkDLEwt5tSoAYU6WcGzKLYvhZNwmkUr2O12dY9JbPOS6528PEfSedbMCIiI2I38+5tjKogTHzqnyyPOqBM=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KBUE8Uer; arc=none smtp.client-ip=209.85.215.182
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-pg1-f182.google.com with SMTP id 41be03b00d2f7-cc4be0e5351so245868a12.0
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 18:25:39 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792200339; x=1792805139; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=KnvXl0R2ZaP6oESQKq/Jn4JVsvE5tAcrzA9epQ1+wnY=;
b=KBUE8UerP0YWZP0jc7flDtPcHLtXuumyeKUwzgd61oS7Zh0eeVHujWVXb66SGQGfFK
VN6DhbWBzUsUQyJNkm5xO3Hp4FyVcts1XBFLm3PXT27bBWdTM1Rn78RlTFAVaIdCaCm9
wwGDxvSvvul8y2Nj2PO2P/CGd98hOhLBaPCoxSvqTWr5JOwvrnlonEoaELZsQsilHi8X
biZfNv11GjVBIEYGZJQF+iIhl4LuyXoeNxuzX4dWZ/HRdkBaJUKudvM4OxO15He2r9HK
BghvLxBxwRD8IMc9GUa6MO9g3ENwYT5ShT6YROW7K9MpHGgyb/Fazu0MQ01XV6fyMUka
BPMQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792200339; x=1792805139;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=KnvXl0R2ZaP6oESQKq/Jn4JV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4n5PFd6Q
BKGBcUHGspBt5sf0jidN96ZTVIivCTEY8nL2yLFQgkyEBbrt5/yzVu6StrfSfl+4N7vYWvhOk0H
aB7wArHeY5Zs48DKCK+qopV/S4yItPxYYsOacD4I+elmCj98NAAP6tyHChejZ+crYg+a0t3mzO+
bnpa57agijeE4+nhUDTSHyrulvboDh2n5ujVYuW1DpQ=
X-Received: by 2002:a17:90b:5111:b0:3a8:7096:9b48 with SMTP id 98e67ed59e1d1-3acee293889mr1411278a91.1.1792200338938;
Fri, 16 Oct 2026 18:25:38 -0700 (PDT)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.242])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3acc4872861sm6792933a91.7.2026.10.16.18.25.37
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 16 Oct 2026 18:25:38 -0700 (PDT)
X-Cc: daniel@iogearbox.net,
andrii@kernel.org,
eddyz87@gmail.com,
memxor@gmail.com,
netdev@vger.kernel.org,
josef@toxicpanda.com,
mason@kernel.org
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261017012058.355787-1-alexei.starovoitov@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>