From: Jakub Sitnicki <jakub@cloudflare.com>
To: bpf@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Arthur Fabre <arthur@arthurfabre.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
netdev@vger.kernel.org, kernel-team@cloudflare.com
Subject: [PATCH bpf-next v3 02/16] net: Preserve metadata on pskb_expand_head
Date: Sun, 26 Oct 2025 15:18:22 +0100 [thread overview]
Message-ID: <20251026-skb-meta-rx-path-v3-2-37cceebb95d3@cloudflare.com> (raw)
In-Reply-To: <20251026-skb-meta-rx-path-v3-0-37cceebb95d3@cloudflare.com>
pskb_expand_head() copies headroom, including skb metadata, into the newly
allocated head, but then clears the metadata. As a result, metadata is lost
when BPF helpers trigger an skb head reallocation.
Let the skb metadata remain in the newly created copy of head.
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
net/core/skbuff.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 6be01454f262..b4fa9aa2df22 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2218,6 +2218,10 @@ EXPORT_SYMBOL(__pskb_copy_fclone);
*
* All the pointers pointing into skb header may change and must be
* reloaded after call to this function.
+ *
+ * Note: If you skb_push() the start of the buffer after reallocating the
+ * header, call skb_postpush_data_move() first to move the metadata out of
+ * the way before writing to &sk_buff->data.
*/
int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
@@ -2289,8 +2293,6 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
skb->nohdr = 0;
atomic_set(&skb_shinfo(skb)->dataref, 1);
- skb_metadata_clear(skb);
-
/* It is not generally safe to change skb->truesize.
* For the moment, we really care of rx path, or
* when skb is orphaned (not attached to a socket).
--
2.43.0
next prev parent reply other threads:[~2025-10-26 14:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-26 14:18 [PATCH bpf-next v3 00/16] Make TC BPF helpers preserve skb metadata Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 01/16] net: Helper to move packet data and metadata after skb_push/pull Jakub Sitnicki
2025-10-26 14:18 ` Jakub Sitnicki [this message]
2025-10-26 14:18 ` [PATCH bpf-next v3 03/16] bpf: Unclone skb head on bpf_dynptr_write to skb metadata Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 04/16] vlan: Make vlan_remove_tag return nothing Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 05/16] bpf: Make bpf_skb_vlan_pop helper metadata-safe Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 06/16] bpf: Make bpf_skb_vlan_push " Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 07/16] bpf: Make bpf_skb_adjust_room metadata-safe Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 08/16] bpf: Make bpf_skb_change_proto helper metadata-safe Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 09/16] bpf: Make bpf_skb_change_head " Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 10/16] selftests/bpf: Verify skb metadata in BPF instead of userspace Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 11/16] selftests/bpf: Dump skb metadata on verification failure Jakub Sitnicki
2025-10-27 12:29 ` Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 12/16] selftests/bpf: Expect unclone to preserve skb metadata Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 13/16] selftests/bpf: Cover skb metadata access after vlan push/pop helper Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 14/16] selftests/bpf: Cover skb metadata access after bpf_skb_adjust_room Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 15/16] selftests/bpf: Cover skb metadata access after change_head/tail helper Jakub Sitnicki
2025-10-26 14:18 ` [PATCH bpf-next v3 16/16] selftests/bpf: Cover skb metadata access after bpf_skb_change_proto Jakub Sitnicki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251026-skb-meta-rx-path-v3-2-37cceebb95d3@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=andrii@kernel.org \
--cc=arthur@arthurfabre.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).