Skip to content

Commit c7b6f29

Browse files
anadavIngo Molnar
authored andcommitted
bpf: Fail bpf_probe_write_user() while mm is switched
When using a temporary mm, bpf_probe_write_user() should not be able to write to user memory, since user memory addresses may be used to map kernel memory. Detect these cases and fail bpf_probe_write_user() in such cases. Suggested-by: Jann Horn <jannh@google.com> Reported-by: Jann Horn <jannh@google.com> Signed-off-by: Nadav Amit <namit@vmware.com> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: <akpm@linux-foundation.org> Cc: <ard.biesheuvel@linaro.org> Cc: <deneen.t.dock@intel.com> Cc: <kernel-hardening@lists.openwall.com> Cc: <kristen@linux.intel.com> Cc: <linux_dti@icloud.com> Cc: <will.deacon@arm.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20190426001143.4983-24-namit@vmware.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5932c9f commit c7b6f29

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/trace/bpf_trace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/syscalls.h>
1515
#include <linux/error-injection.h>
1616

17+
#include <asm/tlb.h>
18+
1719
#include "trace_probe.h"
1820
#include "trace.h"
1921

@@ -163,13 +165,19 @@ BPF_CALL_3(bpf_probe_write_user, void *, unsafe_ptr, const void *, src,
163165
* access_ok() should prevent writing to non-user memory, but in
164166
* some situations (nommu, temporary switch, etc) access_ok() does
165167
* not provide enough validation, hence the check on KERNEL_DS.
168+
*
169+
* nmi_uaccess_okay() ensures the probe is not run in an interim
170+
* state, when the task or mm are switched. This is specifically
171+
* required to prevent the use of temporary mm.
166172
*/
167173

168174
if (unlikely(in_interrupt() ||
169175
current->flags & (PF_KTHREAD | PF_EXITING)))
170176
return -EPERM;
171177
if (unlikely(uaccess_kernel()))
172178
return -EPERM;
179+
if (unlikely(!nmi_uaccess_okay()))
180+
return -EPERM;
173181
if (!access_ok(unsafe_ptr, size))
174182
return -EPERM;
175183

0 commit comments

Comments
 (0)