From: Nikolay Aleksandrov <razor@blackwall.org>
To: Pablo Neira Ayuso <pablo@netfilter.org>,
Weiming Shi <bestswngs@gmail.com>
Cc: Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, Xiang Mei <xmei5@asu.edu>,
co+685321905e91e206@bugs.sh
Subject: Re: [PATCH net] netfilter: nf_queue: do not queue BPF syncookie request sockets
Date: Mon, 30 Nov 2026 22:17:44 +0200 [thread overview]
Message-ID: <b6a545aa-0327-459b-9400-1d6fae012ff1@blackwall.org> (raw)
In-Reply-To: <aw1ieNBG88kMLaob@chamomile>
On 30/11/2026 13:48, Pablo Neira Ayuso wrote:
> On Sun, Nov 29, 2026 at 08:12:29AM -0800, Weiming Shi wrote:
>> bpf_sk_assign_tcp_reqsk() allocates a request socket with
>> inet_reqsk_alloc(ops, sk, false), stores the listener in
>> req->rsk_listener without taking a reference, and attaches it to the
>> skb with skb->destructor = sock_pfree. Because neither the request
>> socket (rsk_refcnt == 0) nor req->rsk_listener is refcounted, the
>> listener pointer is only valid within the ingress RCU read-side
>> critical section.
>>
>> __nf_queue() lets the skb outlive that critical section while waiting
>> for a userspace verdict. Its prefetched-socket check only handles
>> !sk_is_refcounted(sk), which is false for TCP_NEW_SYN_RECV because
>> sk_fullsock() is false for request sockets, and
>> nf_queue_entry_get_refs() only pins state->sk (NULL at prerouting).
>> If the listener is closed and its RCU grace period elapses while the
>> packet is queued, reinjection returns the freed req->rsk_listener from
>> skb_steal_sock() into inet_steal_sock() and tcp_v[46]_rcv():
>>
>> BUG: KASAN: slab-use-after-free in tcp_v4_rcv (include/net/sock.h:2295
>> include/net/inet_hashtables.h:458 include/net/inet_hashtables.h:496
>> net/ipv4/tcp_ipv4.c:2121)
>> Read of size 1 at addr ffff888025542812 by task exploit/194
>> Call Trace:
>> tcp_v4_rcv (net/ipv4/tcp_ipv4.c:2121)
>> ip_protocol_deliver_rcu (net/ipv4/ip_input.c:207)
>> ip_local_deliver_finish (net/ipv4/ip_input.c:241)
>> ip_local_deliver (net/ipv4/ip_input.c:262)
>> ip_rcv_finish (net/ipv4/ip_input.c:492)
>> nfqnl_reinject (net/netfilter/nfnetlink_queue.c:544)
>> nfqnl_recv_verdict (net/netfilter/nfnetlink_queue.c:1905)
>> ...
>> __x64_sys_sendto (net/socket.c:2286)
>>
>> Reject prefetched unrefcounted TCP_NEW_SYN_RECV request sockets in
>> __nf_queue() with -ENOTCONN before the !sk_is_refcounted() check so
>> nf_queue() drops the skb. Calling skb_orphan() instead would discard
>> the validated request socket and cause tcp_v[46]_rcv() to fail
>> cookie_tcp_check() and send a spurious RST on reinjection. Matching
>> on !refcount_read(&sk->sk_refcnt) instead of inet_reqsk(sk)->syncookie
>> also avoids a data race against reqsk_timer_handler() updating
>> num_timeout in the same bitfield byte on hashed request sockets.
>
> Cc: Nikolay.
>
> I have seen working on this. I am not sure if this will require more
> checks in more spots (and more follow up incremental patches), which
> would be better to avoid.
>
Indeed, this has been a part of larger set of fixes that were deferred
recently since a different proposal has been discussed in the past[2]:
https://lore.kernel.org/bpf/20261123084138.723275-1-razor@blackwall.org/
https://lore.kernel.org/bpf/3c96d878-0326-43c2-9869-e941cae675f4@linux.dev/
[2] and before that has been discussed:
https://lore.kernel.org/netdev/20260403015851.148209-1-jiayuan.chen@linux.dev/
https://lore.kernel.org/netdev/20260608125846.157004-1-jiayuan.chen@linux.dev/
Cheers,
Nik
next prev parent reply other threads:[~2026-11-30 20:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 16:12 Weiming Shi
2026-11-30 11:48 ` Pablo Neira Ayuso
2026-11-30 20:17 ` Nikolay Aleksandrov [this message]
2026-11-30 16:14 ` netdev-bot+sashiko
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=b6a545aa-0327-459b-9400-1d6fae012ff1@blackwall.org \
--to=razor@blackwall.org \
--cc=bestswngs@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=co+685321905e91e206@bugs.sh \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
--cc=xmei5@asu.edu \
/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
all inboxes | Powered by JetHome®