From: Christoph Hellwig Date: Tue, 9 Jun 2020 04:34:33 +0000 (-0700) Subject: bpf: handle the compat string in bpf_trace_copy_string better X-Git-Tag: baikal/aarch64/sdk6.1~9130^2~10 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=a1b702bf9afd07d099210fc62a6773073daee4a8;p=kernel.git bpf: handle the compat string in bpf_trace_copy_string better User the proper helper for kernel or userspace addresses based on TASK_SIZE instead of the dangerous strncpy_from_unsafe function. Signed-off-by: Christoph Hellwig Signed-off-by: Andrew Morton Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Masami Hiramatsu Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20200521152301.2587579-13-hch@lst.de Signed-off-by: Linus Torvalds --- diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 60e82c7b81226..a2efbdad434b5 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -334,8 +334,11 @@ static void bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype, switch (fmt_ptype) { case 's': #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - strncpy_from_unsafe(buf, unsafe_ptr, bufsz); - break; + if ((unsigned long)unsafe_ptr < TASK_SIZE) { + strncpy_from_user_nofault(buf, user_ptr, bufsz); + break; + } + fallthrough; #endif case 'k': strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz);