mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] bpf: Tracing progs on the stack save subtree can result in OOM
@ 2026-06-09 17:04 Mahnur A
  2026-06-09 22:01 ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Mahnur A @ 2026-06-09 17:04 UTC (permalink / raw)
  To: bpf; +Cc: ast, daniel, andrii, rostedt, linux-kernel

Hi,

I hit the following case on the current mainline kernel (7.1-rc7)

BPF tracing programs that allocate something and have a deferred-free for it:
Attached to any function in the stack save / unwind result in OOM.


KASAN, slub_debug etc. all save a stack on every alloc/free.
An example bpf program updates a map element,
before lookup and retrieval of the timer object.
It then calls bpf_timer_init().
If this happens at every alloc/free event,
a new timer object gets allocated with every map element update,
while the previous one is deferred-free (via kfree_rcu).

All these alloc/free cause cascading probes to fire which in turn trigger more.
The timer objects accumulate without bound.
kfree_rcu()'d timer objects are reclaimed at a slower rate (or RCU stalls).
This results in OOM which eventually kills init.

Please find the reproducer, config files and the full backtrace here:
https://gist.github.com/MahnurA/622d0cd44df686e241a4b043023871a2

A possible patch could be to not allow BPF programs to attach to such
points at all,
but I'm not sure how that would scale.
I’m happy to test debug patches or provide additional information.

Best regards,
Mahnur

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] bpf: Tracing progs on the stack save subtree can result in OOM
  2026-06-09 17:04 [BUG] bpf: Tracing progs on the stack save subtree can result in OOM Mahnur A
@ 2026-06-09 22:01 ` Alexei Starovoitov
  2026-06-10 22:29   ` Mahnur A
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2026-06-09 22:01 UTC (permalink / raw)
  To: Mahnur A, bpf; +Cc: ast, daniel, andrii, rostedt, linux-kernel

On Tue Jun 9, 2026 at 10:04 AM PDT, Mahnur A wrote:
> Hi,
>
> I hit the following case on the current mainline kernel (7.1-rc7)
>
> BPF tracing programs that allocate something and have a deferred-free for it:
> Attached to any function in the stack save / unwind result in OOM.
>
>
> KASAN, slub_debug etc. all save a stack on every alloc/free.
> An example bpf program updates a map element,
> before lookup and retrieval of the timer object.
> It then calls bpf_timer_init().
> If this happens at every alloc/free event,
> a new timer object gets allocated with every map element update,
> while the previous one is deferred-free (via kfree_rcu).

It's a known design constraint.
A bunch of things in the kernel need call_rcu().
bpf is not immune to such requirements.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] bpf: Tracing progs on the stack save subtree can result in OOM
  2026-06-09 22:01 ` Alexei Starovoitov
@ 2026-06-10 22:29   ` Mahnur A
  0 siblings, 0 replies; 3+ messages in thread
From: Mahnur A @ 2026-06-10 22:29 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: bpf, ast, daniel, andrii, rostedt, linux-kernel

> It's a known design constraint.
> A bunch of things in the kernel need call_rcu().
> bpf is not immune to such requirements.

I'm sorry, perhaps I don't understand your answer.
I get that rcu has its usages and is required.
My concern is:
Should bpf tracing programs be allowed to attach
to stack walk/ unwinding functions?
When any memory debugging mechanism is enabled
it will trigger any bpf program attached anywhere here
to run and keep running an exponential amount of times.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-10 22:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09 17:04 [BUG] bpf: Tracing progs on the stack save subtree can result in OOM Mahnur A
2026-06-09 22:01 ` Alexei Starovoitov
2026-06-10 22:29   ` Mahnur A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome