Article View: linux.kernel.netdev
Article #4217[PATCH bpf-next 36/38] bpf: Follow the head if an skb is written from a slice
From: Alexei Starovoitov
Date: Sat, 17 Oct 2026 01:24
Date: Sat, 17 Oct 2026 01:24
71 lines
10612 bytes
10612 bytes
From: Josef Bacik <josef@toxicpanda.com>
The source of bpf_dynptr_write() may be a slice of the skb which is
written to, that is a pointer into its head. bpf_dynptr_copy() does it by
itself for a copy inside of one skb, if the source is linear and the
destination is not.
__bpf_skb_store_bytes() and __bpf_skb_meta_store_bytes() make the skb
writable first. If that reallocates the head, the source points to the old
one, and freed memory is copied into the packet.
The offsets in the head do not change when it is reallocated here. Make
the skb writable up front and move the source along with the head.
Fixes: 2012c867c800 ("bpf: verifier: Accept dynptr mem as mem in helpers")
Fixes: f38499ff45f5 ("bpf: Unclone skb head on bpf_dynptr_write to skb metadata")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/filter.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index bf01152d0cf9..54e9084b9263 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1752,9 +1752,32 @@ static const struct bpf_func_proto bpf_skb_store_bytes_proto = {
.arg5_type = ARG_ANYTHING,
};
+/*
+ * The source of a write through a dynptr may be a slice of the same skb.
+ * Making the skb writable can move its head: follow the move.
+ */
+static int bpf_try_make_writable_from(struct sk_buff *skb, u32 write_len,
+ const void **from)
+{
+ const void *head = skb->head;
+ bool in_head = *from >= head &&
+ *from < (const void *)skb_end_pointer(skb);
+ int err;
+
+ err = bpf_try_make_writable(skb, write_len);
+ if (!err && in_head)
+ *from = skb->head + (*from - head);
+ return err;
+}
+
int __bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from,
u32 len, u64 flags)
{
+ if (unlikely(offset > INT_MAX))
+ return -EFAULT;
+ if (unlikely(bpf_try_make_writable_from(skb, offset + len, &from)))
+ return -EFAULT;
+
return ____bpf_skb_store_bytes(skb, offset, from, len, flags);
}
@@ -12424,7 +12447,7 @@ int __bpf_skb_meta_store_bytes(struct sk_buff *skb, u32 offset,
{
if (unlikely(flags))
return -EINVAL;
- if (unlikely(bpf_try_make_writable(skb, 0)))
+ if (unlikely(bpf_try_make_writable_from(skb, 0, &from)))
return -EFAULT;
memmove(bpf_skb_meta_pointer(skb, offset), from, len);
--
2.55.0
Technical Details
Message-ID:
<20261017012451.364800-28-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-347622-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-347622-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next 36/38] bpf: Follow the head if an skb is written from a slice
Date: Sat, 17 Oct 2026 01:24:49 +0000
Organization: Usenet Network
Message-ID: <20261017012451.364800-28-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="2936670"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zexcYAOxt2jAg89ZWDXed1Ex7t4= sha256:8D5XlDZWBzPpCBNC2NIOZeJN4Mpk6O3FzlSsHW/UXkA=
sha1:WobYP+YentlGqnKk6z300/ci1wQ= sha256:poWp3p2O3JQo7hbFuZnsNHFWthoDucmHItSVOEjHIFA=
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 BB31711065C; Sat, 17 Oct 2026 04:35:55 +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 X4_NLCY17z6d;
Sat, 17 Oct 2026 04:35:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-347622-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id 0353F11063F; Sat, 17 Oct 2026 04:35:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sin.lore.kernel.org (Postfix) with ESMTP id 113AE24413; Sat, 17 Oct 2026 01:34:45 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 8247E38422E;
Sat, 17 Oct 2026 01:34: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="pxh6He16"
X-Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176])
(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 85E3A38399E
for <netdev@vger.kernel.org>; Sat, 17 Oct 2026 01:34:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792200881; cv=none; b=dXBwdNQQpqWNTdgJbjPMaPwdd/CbSMIN82yk4NxitKb8WeFSd9TRlrkKV6TZ3MCWxpYgTiesS9w97hyavLV9af41UigAup0sj7Yguux7UzJ3zX/TSilIi0CvWa9039/pdQz1GJD99qJRAksqm1X0EdZZGcFa9urkMAj/FWIEZjU=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792200881; c=relaxed/simple;
bh=BBFj6uGrCCWa2wnNUf9OZnXlooSA4nwIym3PBWpXpZw=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=dUs0g1Pjqbq+cRvnh+79XU1Sphtf5g/Qf1mOp1kWbcm/KKv5fl7TFnXR3M7ntoxKD6eVPTB18znhdPCI9gq8VR+IqQ/wLfNZ8drAAw90FcsBBYoj3WECwzyHqK1vurlrsSs1vZS6XgqNtrS7Lx20JjAYcCFab8fZifRrpY9TpV8=
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=pxh6He16; arc=none smtp.client-ip=209.85.215.176
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-f176.google.com with SMTP id 41be03b00d2f7-cc4ca696de6so360765a12.2
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 18:34:38 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792200878; x=1792805678; 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=Cs42Cg7pRUAaqxHt8fGk/dCScz1o4+6AnXssLG5JKeg=;
b=pxh6He16bCZE4H3ANZK1ypve8E5GlzmISc9eKq/mCgMJv7ASHyRt8qLJVKDNOLt2Hh
hPnzXpbxUesQGkXbtM2slgAl0fvfpZFngRVMZS5iePfIhh6DNsy88B2VWNpdbTY/dV98
ueeJ1/HG4L+9MW/gTTa3isImQMTiOszh+MVJsuyru78wUw1ZIZMvT6cwiOfNR7FgNs1K
mkuRA8KU4KRaHoBzDwrARDYlRi4ObWtT5i1yCFlL3wM4r5I/KNeYEO57FUlPmFMHua5r
Na8R+z+4yBqnDRhgSDFR3brOIkmGI9aOGG167Khqo/JspIEdDRFdZ0Su43Z/SfXJbL4W
nhTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792200878; x=1792805678;
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=Cs42Cg7pRUAaqxHt8fGk/dCScz1o4+6AnXssLG5JKeg=;
b=Lp3enY2aoJpZ9z4/bKh5UHc5DCTlt/a284psoCBUn/xBgQMSTeNSgI6SjNrspH5gLh
GzVGsWtdAGhhMWU+uvbBD8un1d3AV8JPpLzssKXQB4oqShPFi8CRqf73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be4XeVCf6iFCH89+qjfyGplaB4elLe9jYjp9X+z7P/ak
X-Received: by 2002:a17:90b:2d86:b0:3ab:2236:6b3d with SMTP id 98e67ed59e1d1-3acef17b4e9mr1437192a91.27.1792200877406;
Fri, 16 Oct 2026 18:34:37 -0700 (PDT)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.245])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ac94748c6csm11484456a91.10.2026.10.16.18.34.36
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 16 Oct 2026 18:34:36 -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>