From: sashiko-bot@kernel.org
To: "Nikolay Aleksandrov" <razor@blackwall.org>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: orphan unsafe prefetched sockets in skb_do_redirect
Date: Mon, 30 Nov 2026 18:45:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-241865@kernel.org> (raw)
In-Reply-To: <20261130182424.2879469-1-razor@blackwall.org>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] netfilter: nf_queue: use-after-free of syncookie reqsk listener
in __nf_queue() [1]
--
commit db64d3de9cb065fcc63cc9c7da578879d98b49a3
Author: Nikolay Aleksandrov <razor@blackwall.org>
bpf: orphan unsafe prefetched sockets in skb_do_redirect
This commit orphans prefetched sockets in skb_do_redirect() unless the
redirect is tc ingress-to-ingress within the socket's netns and the skb
holds a reference to a full socket.
> diff --git a/net/core/filter.c b/net/core/filter.c
> index ea20fd2be65c0..9e7d6c03e5420 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2553,6 +2553,21 @@ static struct net_device *skb_get_peer_dev(struct net_device *dev)
> return NULL;
> }
>
> +static void skb_redirect_prefetched_sk(struct sk_buff *skb,
> + const struct net_device *dev, u32 flags)
> +{
> + struct sock *sk;
> +
> + if (!skb_sk_is_prefetched(skb))
> + return;
> +
> + sk = skb->sk;
> + if (!skb_at_tc_ingress(skb) || flags != BPF_F_INGRESS ||
> + !net_eq(sock_net(sk), dev_net(dev)) || !sk_fullsock(sk) ||
> + !sk_is_refcounted(sk))
> + skb_orphan(skb);
> +}
[Severity: High]
This problem wasn't introduced by this patch, but can __nf_queue() hit a
similar use-after-free on req->rsk_listener [1] when queuing a
packet whose skb->sk was set by bpf_sk_assign_tcp_reqsk()?
bpf_sk_assign_tcp_reqsk() attaches a syncookie request_sock with an
unreferenced req->rsk_listener and sets skb->destructor to sock_pfree.
When __nf_queue() queues the packet to userspace, it only checks
!sk_is_refcounted(sk):
net/netfilter/nf_queue.c:__nf_queue() {
...
if (skb_sk_is_prefetched(skb)) {
struct sock *sk = skb->sk;
if (!sk_is_refcounted(sk)) {
if (!refcount_inc_not_zero(&sk->sk_refcnt))
return -ENOTCONN;
/* drop refcount on skb_orphan */
skb->destructor = sock_edemux;
}
}
...
}
Because sk_fullsock(sk) is false for a request_sock, sk_is_refcounted(sk)
returns true and __nf_queue() leaves the skb unchanged across RCU grace
periods. If the listener closes before nf_reinject() runs,
skb_steal_sock() in tcp_v4_rcv() or tcp_v6_rcv() returns the freed
req->rsk_listener pointer.
[1] https://sashiko.dev/#/bug/linux-e38dcdd4-fc77-4d07-a948-1840d055aa09
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130182424.2879469-1-razor@blackwall.org?part=1
next prev parent reply other threads:[~2026-11-30 18:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:24 [PATCH bpf] bpf: orphan unsafe prefetched sockets in skb_do_redirect Nikolay Aleksandrov
2026-11-30 18:45 ` sashiko-bot [this message]
2026-11-30 18:54 ` Nikolay Aleksandrov
2026-12-01 3:15 ` Alexei Starovoitov
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-241865@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