BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jakub Sitnicki" <jakub@cloudflare.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next 02/15] bpf: Add bpf_skb_fclone_orig() kfunc
Date: Tue, 29 Sep 2026 11:40:47 +0000	[thread overview]
Message-ID: <20260929114048.2DA461F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928-bpf-meta-gated-tracepoints-v1-2-844dbf3e1edf@cloudflare.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] bpf: UAF/Leak via trusted logically freed skb in bpf_skb_fclone_orig()
- [Low] bpf: kernel-doc parameter mismatch for bpf_skb_fclone_orig
--

commit cbb8066a0a59ac3028e52e52059cc238816dbe14
Author: Jakub Sitnicki <jakub@cloudflare.com>

bpf: Add bpf_skb_fclone_orig() kfunc

This patch introduces a new kfunc bpf_skb_fclone_orig() to allow BPF
programs to retrieve the fast-clone original of a TCP write-queue skb.
This enables associating metadata with the original skb that will show
up during retransmissions.

> diff --git a/net/core/filter.c b/net/core/filter.c
> index 33c1ee3b966b0..fdfc1016030a2 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -12469,6 +12469,30 @@ __bpf_kfunc bool bpf_skb_is_traced(struct sk_buff *skb)
>  	return skb->traced;
>  }
>  
> +/**
> + * bpf_skb_fclone_orig() - Return the fast-clone original of an skb
> + * @skb_: socket buffer allocated from the fclone cache

[Severity: Low]
This isn't a bug, but there is a kernel-doc parameter mismatch here.
The documentation refers to @skb_, but the function signature below uses
skb. Could this trigger a warning during W=1 builds?

> + *
> + * TCP write-queue skbs are allocated from the fclone cache, the packet
> + * transmitted on the wire is a fast clone. A prog can only associate
> + * metadata with an skb by keying on its address. On retransmission TCP
> + * reuses the write-queue original, a different address with no packet
> + * hook, so the retransmit carries no metadata. A prog can use this kfunc
> + * to retrieve the address of the write-queue original and populate the
> + * metadata stash for it, so the metadata shows up on skb retransmits.
> + *
> + * Return:
> + * * orig skb address  - skb is a fast clone
> + * * %NULL             - skb is not a fast clone
> + */
> +__bpf_kfunc struct sk_buff *bpf_skb_fclone_orig(struct sk_buff *skb)
> +{
> +	if (skb->fclone == SKB_FCLONE_CLONE)
> +		return &container_of(skb, struct sk_buff_fclones, skb2)->skb1;
> +
> +	return NULL;
> +}
> +
>  #endif /* CONFIG_SKB_GATED_TRACEPOINTS */

[ ... ]

> @@ -12856,6 +12880,7 @@ BTF_KFUNCS_END(bpf_kfunc_check_set_skb_meta)
>  BTF_KFUNCS_START(bpf_kfunc_check_set_skb_tracepoints)
>  BTF_ID_FLAGS(func, bpf_trace_skb)
>  BTF_ID_FLAGS(func, bpf_skb_is_traced)
> +BTF_ID_FLAGS(func, bpf_skb_fclone_orig, KF_RET_NULL)

[Severity: High]
Can this allow a BPF program to modify a logically dead skb, leading to a
memory leak or use-after-free?

If TCP receives an ACK and logically frees the original skb (skb1), its
users count drops to 0. If a qdisc or driver later drops the fast clone
(skb2) and triggers a tracepoint, calling bpf_skb_fclone_orig() returns a
pointer to the dead skb1.

Since the kfunc is registered here without KF_ACQUIRE or KF_RCU, does the
verifier treat the returned pointer as implicitly PTR_TRUSTED?

If a BPF program passes this returned skb to bpf_dynptr_from_skb() and
calls bpf_dynptr_write(), pskb_expand_head() could allocate a new head
buffer for the dead skb1, permanently leaking it.

>  BTF_KFUNCS_END(bpf_kfunc_check_set_skb_tracepoints)
>  #endif

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260928-bpf-meta-gated-tracepoints-v1-0-844dbf3e1edf@cloudflare.com?part=2

  reply	other threads:[~2026-09-29 11:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 11:40 [PATCH net-next 00/15] Gated tracepoints for skb lifecycle (free+clone) Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 01/15] bpf: Add gated tracepoints for skb life-cycle Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 02/15] bpf: Add bpf_skb_fclone_orig() kfunc Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot [this message]
2026-09-28 11:40 ` [PATCH net-next 03/15] bpf: Accept trusted pointers to kern ctx type for kfunc ctx args Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 04/15] bpf: Allow access to bpf_sock_ops_kern->skb Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 05/15] selftests/bpf: Basic tests for metadata passing with gated skb tracepoints Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 06/15] selftests/bpf: Test passing metadata across veth and GRE Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 07/15] selftests/bpf: Test metadata passing to cgroup_skb and sk_filter hooks Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 08/15] selftests/bpf: Test passing metadata to sock_ops and LSM hooks Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 09/15] selftests/bpf: Test passing metadata to kfree_skb tracepoint Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 10/15] selftests/bpf: Test passing metadata to TCP egress Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 11/15] selftests/bpf: Test passing metadata to netfilter hook Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 12/15] selftests/bpf: Test passing metadata to/from LWT hooks Jakub Sitnicki
2026-09-29 11:40   ` sashiko-bot
2026-09-28 11:40 ` [PATCH net-next 13/15] selftests/bpf: Test passing metadata to seg6local End.BPF hook Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 14/15] selftests/bpf: Test passing metadata to sk_skb stream verdict hook Jakub Sitnicki
2026-09-28 11:40 ` [PATCH net-next 15/15] selftests/bpf: Use non-trivial test payload in xdp_context tests Jakub Sitnicki
2026-10-02  1:45 ` [PATCH net-next 00/15] Gated tracepoints for skb lifecycle (free+clone) Jakub Kicinski
2026-10-02 12:47   ` 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=20260929114048.2DA461F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=sashiko-reviews@lists.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