All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shihuang Liu" <shlomojune6@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/2] bpf: revalidate assigned sockets after protocol change
Date: Fri, 11 Sep 2026 17:46:59 +0000	[thread overview]
Message-ID: <20260911174659.824371F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911172313.64009-2-shlomojune6@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] bpf_skb_change_proto can synchronously free a socket via skb_orphan(), leading to a Use-After-Free if the BPF program holds a PTR_TO_SOCK_COMMON pointer to it.
--

commit ecfe32dc3cf3e047fa0e8a7841baab762512d237
Author: Shihuang Liu <shlomojune6@gmail.com>

bpf: revalidate assigned sockets after protocol change

This commit adds a check in bpf_skb_change_proto() to revalidate any
prefetched socket after a protocol change. If the socket's address family
is no longer compatible, it releases the assignment by calling skb_orphan().

Link: https://lore.kernel.org/netdev/20260823101809.26802-1-shlomojune6@gmail.com/

[ ... ]

> diff --git a/net/core/filter.c b/net/core/filter.c
> index b5452113f974a..9907e9d44c11f 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3547,6 +3547,11 @@ BPF_CALL_3(bpf_skb_change_proto, struct sk_buff *, skb, __be16, proto,
>  	if (ret)
>  		return ret;
>  
> +	/* Protocol translation can invalidate an earlier socket assignment. */
> +	if (skb_sk_is_prefetched(skb) &&
> +	    !bpf_sk_assign_family_ok(skb, skb->sk))
> +		skb_orphan(skb);

[Severity: Critical]
Does this code introduce a use-after-free if the BPF program currently holds
a pointer to the socket?

If a BPF program, such as a TC hook, loads skb->sk and verifies it, the
verifier grants a valid PTR_TO_SOCK_COMMON register. When the program
subsequently calls bpf_skb_change_proto(), this newly added code calls
skb_orphan().

The skb_orphan() function synchronously drops the SKB's reference to the
socket via sock_pfree() and sock_gen_put(). If this was the last reference
to an established TCP socket (which do not use SOCK_RCU_FREE), the socket
is freed immediately.

While the verifier's clear_all_pkt_pointers() clears packet data pointers
after protocol changes, it does not invalidate PTR_TO_SOCK_COMMON registers.
Can the BPF program then access the freed socket structure via its dangling
pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911172313.64009-1-shlomojune6@gmail.com?part=2

  reply	other threads:[~2026-09-11 17:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 17:23 [PATCH bpf v2 1/2] bpf: reject incompatible socket assignments Shihuang Liu
2026-09-11 17:23 ` [PATCH bpf v2 2/2] bpf: revalidate assigned sockets after protocol change Shihuang Liu
2026-09-11 17:46   ` sashiko-bot [this message]
2026-09-11 17:42 ` [PATCH bpf v2 1/2] bpf: reject incompatible socket assignments sashiko-bot

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=20260911174659.824371F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shlomojune6@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.