BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nikolay Aleksandrov" <razor@blackwall.org>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/8] bpf: Orphan prefetched sk on skb_do_redirect()
Date: Thu, 19 Nov 2026 14:52:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-223322@kernel.org> (raw)
In-Reply-To: <20261119142231.2612515-2-razor@blackwall.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf: unorphaned prefetched sk on peer-ingress redirect in
  skb_do_redirect()
--

commit 49a586a8c784f9d116bbf62d9fbeea56cd7faa45
Author: Daniel Borkmann <daniel@iogearbox.net>

bpf: Orphan prefetched sk on skb_do_redirect()

This commit orphans prefetched sockets in skb_do_redirect() before
redirects other than peer-ingress redirects, preventing RCU-borrowed
listener sockets from outliving their RCU read-side critical section.

> diff --git a/net/core/filter.c b/net/core/filter.c
> index 946b07a17fcec..1ad57a3715343 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2558,6 +2558,15 @@ int skb_do_redirect(struct sk_buff *skb)
>  	ri->flags = 0;
>  	if (unlikely(!dev))
>  		goto out_drop;
> +
> +	/*
> +	 * Prefetched sockets may borrow a listener under RCU. Orphan them
> +	 * before redirects that can outlive this section. Peer ingress
> +	 * stays in the same RCU section.
> +	 */
> +	if (skb_sk_is_prefetched(skb) &&
> +	    (!(flags & BPF_F_PEER) || (flags & BPF_F_EGRESS)))
> +		skb_orphan(skb);
>  	if (flags & BPF_F_PEER) {
>  		dev = skb_get_peer_dev(dev);
>  		if (unlikely(!dev ||

[Severity: High]
Should skb_orphan(skb) run unconditionally whenever
skb_sk_is_prefetched(skb) is true, including for peer-ingress redirects
(flags == BPF_F_PEER)?

The BPF_F_PEER path below requires the target peer device to be in a
different network namespace (!net_eq(net, dev_net(dev))), whereas
bpf_sk_assign() and bpf_sk_assign_tcp_reqsk() require sock_net(sk) to
match the pre-redirect device's namespace.  Skipping skb_orphan(skb) on
peer ingress leaves the source namespace's prefetched socket attached to
skb when skb_do_redirect() returns -EAGAIN to re-enter
__netif_receive_skb_core() on the peer device:

- During another_round on the peer device, a TC ingress act_mirred
  redirect (which sets dont_clone = true at TC ingress) or an rx_handler
  such as a bridge port or macvlan/ipvlan can queue skb to an egress
  qdisc, backlog, or workqueue without orphaning skb->sk.  An
  unreferenced RCU-borrowed listener then outlives the RCU section,
  leading to a use-after-free in sock_pfree() or skb_steal_sock().

- If the packet proceeds up the peer namespace's IP stack, ip_rcv_core()
  and ip6_rcv_core() preserve prefetched skb->sk.  Packets routed for
  forwarding in the peer namespace are then dropped by ip_forward() and
  ip6_forward() at if (unlikely(skb->sk)) goto drop, while local
  delivery via inet_steal_sock() steals skb->sk without checking
  net_eq(sock_net(sk), net), delivering the packet to the socket in the
  source namespace and caching a peer-namespace dst_entry in
  sk->sk_rx_dst.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119142231.2612515-1-razor@blackwall.org?part=1

  reply	other threads:[~2026-11-19 14:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 14:22 [PATCH bpf-next 0/8] bpf: add bpf_sk_assign support on egress Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 1/8] bpf: Orphan prefetched sk on skb_do_redirect() Nikolay Aleksandrov
2026-11-19 14:52   ` sashiko-bot [this message]
2026-11-19 15:01     ` Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 2/8] net: track references owned by prefetched socket assignments Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 3/8] bpf: allow bpf_sk_assign on tc egress with refcounted sockets Nikolay Aleksandrov
2026-11-19 15:19   ` bot+bpf-ci
2026-11-19 15:36     ` Nikolay Aleksandrov
2026-11-19 15:28   ` sashiko-bot
2026-11-19 14:22 ` [PATCH bpf-next 4/8] bpf: support SOCK_RCU_FREE sockets in bpf_sk_assign on egress Nikolay Aleksandrov
2026-11-19 15:24   ` sashiko-bot
2026-11-19 14:22 ` [PATCH bpf-next 5/8] selftests/bpf: Delete assign_reuse namespace when opening it fails Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 6/8] selftests/bpf: Cover egress socket assignment with reuseport Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 7/8] selftests/bpf: Exercise netkit socket assignment to a host proxy Nikolay Aleksandrov
2026-11-19 14:22 ` [PATCH bpf-next 8/8] selftests/bpf: Check assigned socket lifetime across queues and drops Nikolay Aleksandrov

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=sashiko-outbox-223322@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=razor@blackwall.org \
    --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