android_kernel_oneplus_msm8998/kernel/bpf
Alexei Starovoitov 1c74bd22e8 bpf: Prevent memory disambiguation attack
commit af86ca4e3088fe5eacf2f7e58c01fa68ca067672 upstream.

Detect code patterns where malicious 'speculative store bypass' can be used
and sanitize such patterns.

 39: (bf) r3 = r10
 40: (07) r3 += -216
 41: (79) r8 = *(u64 *)(r7 +0)   // slow read
 42: (7a) *(u64 *)(r10 -72) = 0  // verifier inserts this instruction
 43: (7b) *(u64 *)(r8 +0) = r3   // this store becomes slow due to r8
 44: (79) r1 = *(u64 *)(r6 +0)   // cpu speculatively executes this load
 45: (71) r2 = *(u8 *)(r1 +0)    // speculatively arbitrary 'load byte'
                                 // is now sanitized

Above code after x86 JIT becomes:
 e5: mov    %rbp,%rdx
 e8: add    $0xffffffffffffff28,%rdx
 ef: mov    0x0(%r13),%r14
 f3: movq   $0x0,-0x48(%rbp)
 fb: mov    %rdx,0x0(%r14)
 ff: mov    0x0(%rbx),%rdi
103: movzbq 0x0(%rdi),%rsi

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
[bwh: Backported to 4.4:
 - Add verifier_env parameter to check_stack_write()
 - Look up stack slot_types with state->stack_slot_type[] rather than
   state->stack[].slot_type[]
 - Drop bpf_verifier_env argument to verbose()
 - Adjust filename, context]
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-17 21:55:15 +01:00
..
arraymap.c bpf: generally move prog destruction to RCU deferral 2018-11-10 07:41:37 -08:00
core.c bpf: fix divides by zero 2018-02-03 17:04:24 +01:00
hashtab.c bpf: map_get_next_key to return first key on NULL 2018-05-16 10:06:46 +02:00
helpers.c bpf: avoid copying junk bytes in bpf_get_current_comm() 2016-04-20 15:42:01 +09:00
inode.c bpf, inode: disallow userns mounts 2016-06-24 10:18:17 -07:00
Makefile bpf: add support for persistent maps/progs 2015-11-02 22:48:39 -05:00
syscall.c bpf: generally move prog destruction to RCU deferral 2018-11-10 07:41:37 -08:00
verifier.c bpf: Prevent memory disambiguation attack 2018-12-17 21:55:15 +01:00