🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Herbert Xu Tue, 01 Dec 2026 08:52
[PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
#25092
Author: Herbert Xu
Date: Tue, 01 Dec 2026 08:52
51 lines
11471 bytes
On Thu, Nov 05, 2026 at 07:44:30PM +0100, Uladzislau Rezki wrote:
> On Thu, Nov 05, 2026 at 04:51:39PM +0800, Herbert Xu wrote:
> > On Wed, Nov 04, 2026 at 12:11:24PM +0100, Uladzislau Rezki wrote:
>
> > > net/ipv4/udp.c:
> > >     err = bpf_iter_udp_realloc_batch(iter, batch_sks, GFP_NOWAIT);
> > 
> > This looks buggy in exactly the same way as rhashtable.  It's
> > called under spin_lock_bh, and the same lock can be taken on
> > the softirq path on another CPU.

Since we're not making any progress on resolving this within kvmalloc,
let's fix UDP to not call kvmalloc with GFP_NOWAIT.

---8<---
Even though kvmalloc was modified to support being called with
non-blocking flags such as GFP_NOWAIT and GFP_ATOMIC, it cannot
do so safely when used inside spin locks that may be taken from
soft or hard IRQs.  Doing so can lead to dead-lock because the
kvmalloc code takes naked spin locks without disabling soft or
hard IRQs.

Fix the UDP path to not call kvmalloc when BH spin locks are held.

Fixes: c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index d784faf939c3..613ea92e95b1 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -3886,8 +3886,12 @@ static int bpf_iter_udp_realloc_batch(struct bpf_udp_iter_state *iter,
 {
 	union bpf_udp_iter_batch_item *new_batch;
 
-	new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
-				  flags | __GFP_NOWARN);
+	if (flags != GFP_NOWAIT)
+		new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
+					  flags | __GFP_NOWARN);
+	else
+		new_batch = kmalloc_objs(*new_batch, new_batch_sz,
+					 flags | __GFP_NOWARN);
 	if (!new_batch)
 		return -ENOMEM;
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
#25094
Author: netdev-bot+sinfo
Date: Tue, 01 Dec 2026 08:54
19 lines
9665 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
#25101
Author: Herbert Xu
Date: Tue, 01 Dec 2026 08:58
18 lines
10407 bytes
On Tue, Dec 01, 2026 at 08:54:49AM +0000, netdev-bot+sinfo@kernel.org wrote:
> 
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.

The same issue was triggered on rhashtable.  The UDP bpf path has
exactly the same setup so it is vulnerable to the same issue.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
#25373
Author: Linus Torvalds
Date: Tue, 01 Dec 2026 17:01
10 lines
12749 bytes
On Tue, 1 Dec 2026 at 00:52, Herbert Xu <herbert@gondor.apana.org.au> wrote:
>
> Fix the UDP path to not call kvmalloc when BH spin locks are held.

Bah. I don't love your previous patch, but it's better than this one.

So I applied the one to just not support kvmalloc in irq context.

              Linus
Re: [PATCH net] bpf: udp: Do not call kvmalloc while holding BH spin lock
#25503
Author: Herbert Xu
Date: Tue, 01 Dec 2026 23:18
17 lines
10124 bytes
On Tue, Dec 01, 2026 at 09:01:10AM -0800, Linus Torvalds wrote:
> 
> Bah. I don't love your previous patch, but it's better than this one.
> 
> So I applied the one to just not support kvmalloc in irq context.

Thanks Linus!

So just in case there is any confusion I am withdrawing this patch
to bpf UDP.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads