Skip to content

Commit b992f01

Browse files
rnavmpe
authored andcommitted
bpf: Guard against accessing NULL pt_regs in bpf_get_task_stack()
task_pt_regs() can return NULL on powerpc for kernel threads. This is then used in __bpf_get_stack() to check for user mode, resulting in a kernel oops. Guard against this by checking return value of task_pt_regs() before trying to obtain the call chain. Fixes: fa28dcb ("bpf: Introduce helper bpf_get_task_stack()") Cc: [email protected] # v5.9+ Signed-off-by: Naveen N. Rao <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/d5ef83c361cc255494afd15ff1b4fb02a36e1dcf.1641468127.git.naveen.n.rao@linux.vnet.ibm.com
1 parent 29ec39f commit b992f01

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/stackmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,14 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
472472
u32, size, u64, flags)
473473
{
474474
struct pt_regs *regs;
475-
long res;
475+
long res = -EINVAL;
476476

477477
if (!try_get_task_stack(task))
478478
return -EFAULT;
479479

480480
regs = task_pt_regs(task);
481-
res = __bpf_get_stack(regs, task, NULL, buf, size, flags);
481+
if (regs)
482+
res = __bpf_get_stack(regs, task, NULL, buf, size, flags);
482483
put_task_stack(task);
483484

484485
return res;

0 commit comments

Comments
 (0)