* [PATCH 5.10.y] bpf: Clear buf on error in __bpf_get_task_stack
@ 2026-11-26 11:45 Dickson Wu via B4 Relay
2026-11-27 17:01 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-26 11:45 UTC (permalink / raw)
To: stable; +Cc: Jiri Olsa, Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
bpf
From: Jiri Olsa <jolsa@kernel.org>
commit f5d242825ca417bb6afe35fde6e8880f97ca43fb upstream.
Both bpf_get_task_stack and bpf_get_task_stack_sleepable helpers that
use __bpf_get_task_stack have buf defined as ARG_PTR_TO_UNINIT_MEM
argument and we should initialize the buf on every return path.
Adding missing buf memset for __bpf_get_task_stack fail paths. This
provides deterministic buffer contents, which is useful when the buffer
is used directly as a map key.
Fixes: 06ab134ce8ec ("bpf: Refcount task stack in bpf_get_task_stack")
Fixes: b992f01e6615 ("bpf: Guard against accessing NULL pt_regs in bpf_get_task_stack()")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20260803210149.296496-10-jolsa@kernel.org
[ adapted to 5.10.y: use bpf_get_task_stack() ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
6.1.y and newer already have this fix. This branch has no
__bpf_get_task_stack(); the same code sits directly in
bpf_get_task_stack(), so the two memsets go there.
Tested on v5.10.275:
- x86_64 allmodconfig W=1 build of kernel/bpf/stackmap.o, base vs
patched, no new warnings
- booted the patched kernel under QEMU/KVM. I didn't run a BPF test
that hits the two error paths.
The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
kernel/bpf/stackmap.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 3ec76cb5f240..c9a9cfbca4ae 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -670,14 +670,17 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
struct pt_regs *regs;
long res = -EINVAL;
- if (!try_get_task_stack(task))
+ if (!try_get_task_stack(task)) {
+ memset(buf, 0, size);
return -EFAULT;
+ }
regs = task_pt_regs(task);
if (regs)
res = __bpf_get_stack(regs, task, NULL, buf, size, flags);
+ else
+ memset(buf, 0, size);
put_task_stack(task);
-
return res;
}
---
base-commit: 99112ea818e35b606397c84fbc05e6fadb6ea162
change-id: 20261126-so1b-bpf-510-9a33e5e85398
Best regards,
--
Dickson Wu <dickson.wu@certik.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 5.10.y] bpf: Clear buf on error in __bpf_get_task_stack
2026-11-26 11:45 [PATCH 5.10.y] bpf: Clear buf on error in __bpf_get_task_stack Dickson Wu via B4 Relay
@ 2026-11-27 17:01 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-27 17:01 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Jiri Olsa, Andrii Nakryiko, Alexei Starovoitov,
Daniel Borkmann, bpf, Dickson Wu via B4 Relay, Dickson Wu
> Adding missing buf memset for __bpf_get_task_stack fail paths.
Queued for 5.15 and 5.10, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 17:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 11:45 [PATCH 5.10.y] bpf: Clear buf on error in __bpf_get_task_stack Dickson Wu via B4 Relay
2026-11-27 17:01 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox