bpf: Guard against accessing NULL pt_regs in bpf_get_task_stack()
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Thu, 6 Jan 2022 11:45:05 +0000 (17:15 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Feb 2022 16:26:59 +0000 (17:26 +0100)
commit0bcd484587b3b3092e448d27dc369e347e1810c3
tree47d9cdfa49a01ca8b5056bdc86f0f038d92377d4
parentcfd2a7f8deaa6c86bcb12dad82a8b8a871d8aff2
bpf: Guard against accessing NULL pt_regs in bpf_get_task_stack()

commit b992f01e66150fc5e90be4a96f5eb8e634c8249e upstream.

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: fa28dcb82a38f8 ("bpf: Introduce helper bpf_get_task_stack()")
Cc: stable@vger.kernel.org # v5.9+
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/d5ef83c361cc255494afd15ff1b4fb02a36e1dcf.1641468127.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/bpf/stackmap.c