public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v3 1/2] bpf: Reject sleepable kprobe_multi programs at attach time
@ 2026-04-01 19:11 Varun R Mallya
  2026-04-01 19:11 ` [PATCH bpf v3 2/2] selftests/bpf: Add test to ensure kprobe_multi is not sleepable Varun R Mallya
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Varun R Mallya @ 2026-04-01 19:11 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, memxor, yonghong.song, jolsa, rostedt, mhiramat,
	linux-kernel, linux-trace-kernel, varunrmallya

kprobe.multi programs run in atomic/RCU context and cannot sleep.
However, bpf_kprobe_multi_link_attach() did not validate whether the
program being attached had the sleepable flag set, allowing sleepable
helpers such as bpf_copy_from_user() to be invoked from a non-sleepable
context.

This causes a "sleeping function called from invalid context" splat:

  BUG: sleeping function called from invalid context at ./include/linux/uaccess.h:169
  in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1787, name: sudo
  preempt_count: 1, expected: 0
  RCU nest depth: 2, expected: 0

Fix this by rejecting sleepable programs early in
bpf_kprobe_multi_link_attach(), before any further processing.

Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
---
 kernel/trace/bpf_trace.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 0b040a417442..af7079aa0f36 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2752,6 +2752,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	if (!is_kprobe_multi(prog))
 		return -EINVAL;
 
+	/* kprobe_multi is not allowed to be sleepable. */
+	if (prog->sleepable)
+		return -EINVAL;
+
 	/* Writing to context is not allowed for kprobes. */
 	if (prog->aux->kprobe_write_ctx)
 		return -EINVAL;
-- 
2.53.0


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

end of thread, other threads:[~2026-04-06 20:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 19:11 [PATCH bpf v3 1/2] bpf: Reject sleepable kprobe_multi programs at attach time Varun R Mallya
2026-04-01 19:11 ` [PATCH bpf v3 2/2] selftests/bpf: Add test to ensure kprobe_multi is not sleepable Varun R Mallya
2026-04-01 22:50   ` Kumar Kartikeya Dwivedi
2026-04-02  9:46     ` Jiri Olsa
2026-04-06 20:11       ` Kumar Kartikeya Dwivedi
2026-04-02  4:13   ` Leon Hwang
2026-04-01 22:45 ` [PATCH bpf v3 1/2] bpf: Reject sleepable kprobe_multi programs at attach time Kumar Kartikeya Dwivedi
2026-04-02  4:13 ` Leon Hwang
2026-04-02  9:47 ` Jiri Olsa
2026-04-02 16:50 ` patchwork-bot+netdevbpf

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