mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chengfeng Ye <nicoyip.dev@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Mark Brown <broonie@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Florian Westphal <fw@strlen.de>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chengfeng Ye <nicoyip.dev@gmail.com>
Subject: [PATCH net] net: neighbour: Serialize proxy queue admission
Date: Sun, 27 Sep 2026 01:37:37 +0800	[thread overview]
Message-ID: <20260926173737.2491492-1-nicoyip.dev@gmail.com> (raw)

pneigh_enqueue() checks p->qlen before taking proxy_queue.lock, although
both enqueueing and the timer and purge paths update it under that lock.
The unlocked read races with those updates and allows concurrent proxy
ARP or NDP requests to bypass the queue's admission limit.

For example, CPU0 and CPU1 can both observe p->qlen == PROXY_QLEN before
either takes the lock. CPU0 then locks and enqueues, raising the count to
PROXY_QLEN + 1. CPU1 subsequently locks and enqueues using its stale
admission decision, raising the count to PROXY_QLEN + 2. The extra queued
packets consume memory until the timer or purge path removes them.

With a temporary 20 ms delay before locking and a queue-length assertion,
the kernel reported qlen=6 with PROXY_QLEN=4:

  WARNING: net/core/neighbour.c:1757 at pneigh_enqueue+0x4ee/0x650
  Call Trace:
   <IRQ>
   arp_process+0x1846/0x2060
   __netif_receive_skb_core.constprop.0+0x1524/0x2bd0
   __netif_receive_skb_one_core+0xa9/0x1b0
   process_backlog+0x1e5/0x5e0
   __napi_poll+0x9c/0x540
   net_rx_action+0x988/0xfb0
   handle_softirqs+0x18d/0x5b0
   do_softirq+0x3b/0x60
   </IRQ>

Move the existing lock acquisition before the admission check so that the
check and increment are serialized with all queue-length updates. Unlock
before freeing a rejected packet. Keep the existing > comparison so that
serial admission behavior is unchanged.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
 net/core/neighbour.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 7448320f7ad5..e35ce26b4f8a 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1721,7 +1721,9 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
 {
 	unsigned long sched_next = neigh_proxy_delay(p);
 
+	spin_lock(&tbl->proxy_queue.lock);
 	if (p->qlen > NEIGH_VAR(p, PROXY_QLEN)) {
+		spin_unlock(&tbl->proxy_queue.lock);
 		kfree_skb(skb);
 		return;
 	}
@@ -1729,7 +1731,6 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
 	NEIGH_CB(skb)->sched_next = sched_next;
 	NEIGH_CB(skb)->flags |= LOCALLY_ENQUEUED;
 
-	spin_lock(&tbl->proxy_queue.lock);
 	if (timer_delete(&tbl->proxy_timer)) {
 		if (time_before(tbl->proxy_timer.expires, sched_next))
 			sched_next = tbl->proxy_timer.expires;
-- 
2.43.0


             reply	other threads:[~2026-09-26 17:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26 17:37 Chengfeng Ye [this message]
2026-09-26 19:45 ` Kuniyuki Iwashima

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=20260926173737.2491492-1-nicoyip.dev@gmail.com \
    --to=nicoyip.dev@gmail.com \
    --cc=broonie@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 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®