mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: bestswngs@gmail.com
Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, 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 16:14:12 +0000	[thread overview]
Message-ID: <179605525205.3146.8322072085993490126@kernel.org> (raw)
In-Reply-To: <20261129161228.4185092-2-bestswngs@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In net/netfilter/nf_queue.c, __nf_queue() now returns
  -ENOTCONN for every prefetched TCP_NEW_SYN_RECV socket with refcnt 0,…
- [Medium] The commit message says only that nf_queue() 'drops the skb',
  and argues this beats skb_orphan() because skb_orphan() would cause a…

--

netfilter: nf_queue: do not queue BPF syncookie request sockets

This patch makes __nf_queue() reject skbs that carry a prefetched,
unrefcounted TCP_NEW_SYN_RECV request socket, the kind created by
bpf_sk_assign_tcp_reqsk(). It returns -ENOTCONN so that nf_queue() drops
the skb. The goal is to stop the skb from outliving the ingress RCU
section while req->rsk_listener is not pinned.

> diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
> index bd603e3a99a59..54d902169065e 100644
> --- a/net/netfilter/nf_queue.c
> +++ b/net/netfilter/nf_queue.c
> @@ -198,6 +198,10 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
>  	if (skb_sk_is_prefetched(skb)) {
>  		struct sock *sk = skb->sk;
>  
> +		if (READ_ONCE(sk->sk_state) == TCP_NEW_SYN_RECV &&
> +		    !refcount_read(&sk->sk_refcnt))
> +			return -ENOTCONN;
> +

[Severity: Medium]
Does this early return also drop packets that nfnetlink_queue would have
passed through in the same RCU section?

The check runs before qh->outfn(), so nfnetlink_queue never sees these
skbs. Two configurations look affected.

The first is --queue-bypass with no daemon bound to the queue.
nfqnl_enqueue_packet() used to return -ESRCH here:

net/netfilter/nfnetlink_queue.c:nfqnl_enqueue_packet() {
    ...
	queue = instance_lookup(q, queuenum);
	if (!queue)
		return -ESRCH;
    ...
}

nf_queue() treats only that case as a bypass:

net/netfilter/nf_queue.c:nf_queue() {
    ...
	if (ret < 0) {
		if (ret == -ESRCH &&
		    (verdict & NF_VERDICT_FLAG_QUEUE_BYPASS))
			return 1;
		kfree_skb(skb);
	}
    ...
}

The second is NFQA_CFG_F_FAIL_OPEN when the queue is full or the unicast
fails. In that case __nfqnl_enqueue_packet() reinjects synchronously:

	if (failopen)
		nfqnl_reinject(entry, NF_ACCEPT);

In both cases the skb stayed inside the current RCU read-side section, so
the stale req->rsk_listener could not be hit.

With this patch __nf_queue() returns -ENOTCONN, which nf_queue() does not
treat as a bypass, so it calls kfree_skb(). Will BPF SYN cookie ACKs then
be silently dropped in exactly the setups that are configured to fail
open?

[Severity: Medium]
Does the commit message describe how wide the effect of this check is?
It says:

  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.

bpf_sk_assign_tcp_reqsk() allocates a new unrefcounted request socket on
every call:

net/core/filter.c:bpf_sk_assign_tcp_reqsk() {
    ...
	req = inet_reqsk_alloc(ops, sk, false);
    ...
	req->rsk_listener = sk;
	req->syncookie = 1;
    ...
	skb->sk = req_to_sk(req);
	skb->destructor = sock_pfree;
    ...
}

As a result, every cookie ACK the BPF program validates (including
retransmissions) matches the new check. If an NFQUEUE verdict applies on
the ingress path, the packet is dropped, so the client sees an
established connection that the server never accepts.

Before this patch the combination failed only when the listener closed
while a packet was queued. After it, bpf_sk_assign_tcp_reqsk() and
NFQUEUE look like they cannot work together at all.

Could the commit message state this? The other approach, pinning
req->rsk_listener on struct nf_queue_entry the way the existing
refcount_inc_not_zero()/sock_edemux handling pins prefetched sockets,
appears only below the cut line. Would that approach be preferable here,
since it keeps this combination working?

>  		if (!sk_is_refcounted(sk)) {
>  			if (!refcount_inc_not_zero(&sk->sk_refcnt))
>  				return -ENOTCONN;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129161228.4185092-2-bestswngs%40gmail.com

      parent reply	other threads:[~2026-11-30 16:14 UTC|newest]

Thread overview: 3+ 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 16:14 ` netdev-bot+sashiko [this message]

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=179605525205.3146.8322072085993490126@kernel.org \
    --to=netdev-bot+sashiko@kernel.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®