linux_dsm_epyc7002/tools/testing/selftests
Daniel Borkmann 6bdf6abc56 bpf: prevent leaking pointer via xadd on unpriviledged
Leaking kernel addresses on unpriviledged is generally disallowed,
for example, verifier rejects the following:

  0: (b7) r0 = 0
  1: (18) r2 = 0xffff897e82304400
  3: (7b) *(u64 *)(r1 +48) = r2
  R2 leaks addr into ctx

Doing pointer arithmetic on them is also forbidden, so that they
don't turn into unknown value and then get leaked out. However,
there's xadd as a special case, where we don't check the src reg
for being a pointer register, e.g. the following will pass:

  0: (b7) r0 = 0
  1: (7b) *(u64 *)(r1 +48) = r0
  2: (18) r2 = 0xffff897e82304400 ; map
  4: (db) lock *(u64 *)(r1 +48) += r2
  5: (95) exit

We could store the pointer into skb->cb, loose the type context,
and then read it out from there again to leak it eventually out
of a map value. Or more easily in a different variant, too:

   0: (bf) r6 = r1
   1: (7a) *(u64 *)(r10 -8) = 0
   2: (bf) r2 = r10
   3: (07) r2 += -8
   4: (18) r1 = 0x0
   6: (85) call bpf_map_lookup_elem#1
   7: (15) if r0 == 0x0 goto pc+3
   R0=map_value(ks=8,vs=8,id=0),min_value=0,max_value=0 R6=ctx R10=fp
   8: (b7) r3 = 0
   9: (7b) *(u64 *)(r0 +0) = r3
  10: (db) lock *(u64 *)(r0 +0) += r6
  11: (b7) r0 = 0
  12: (95) exit

  from 7 to 11: R0=inv,min_value=0,max_value=0 R6=ctx R10=fp
  11: (b7) r0 = 0
  12: (95) exit

Prevent this by checking xadd src reg for pointer types. Also
add a couple of test cases related to this.

Fixes: 1be7f75d16 ("bpf: enable non-root eBPF programs")
Fixes: 17a5267067 ("bpf: verifier (add verifier core)")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-29 15:44:34 -04:00
..
bpf bpf: prevent leaking pointer via xadd on unpriviledged 2017-06-29 15:44:34 -04:00
breakpoints selftests: breakpoints: allow to cross-compile for aarch64/arm64 2017-04-21 11:25:26 -06:00
capabilities
cpu-hotplug
cpufreq selftests: create cpufreq kconfig fragments 2017-04-27 08:42:18 -06:00
drivers/gpu drm/i915: Provide a hook for selftests 2017-02-13 20:45:21 +00:00
efivarfs
exec
filesystems
firmware driver core patches for 4.11-rc1 2017-02-22 11:44:32 -08:00
ftrace selftests/ftrace: Add a testcase for many kprobe events 2017-05-26 22:37:00 -04:00
futex selftests: futex: override clean in lib.mk to fix warnings 2017-04-25 09:47:21 -06:00
gpio selftests: gpio: fix clean target to remove all generated files and dirs 2017-04-25 09:49:50 -06:00
ia64
intel_pstate selftests/intel_pstate: Update makefile to match new style 2017-01-19 10:30:40 -07:00
ipc
kcmp
lib selftests: lib: add config fragment for bitmap, printf and prime numbers tests 2017-04-11 09:37:53 -06:00
locking
media_tests
membarrier
memfd
memory-hotplug
mount
mqueue
net selftests/net: Fix broken test case in psock_fanout 2017-04-25 11:56:17 -04:00
networking/timestamping
nsfs
ntb NTB: ntb_test: fix bug printing ntb_perf results 2017-06-19 14:24:41 -04:00
powerpc selftests/powerpc: Fix TM resched DSCR test with some compilers 2017-05-19 19:46:34 +10:00
prctl
pstore
ptp
ptrace
rcutorture torture: Use correct path for Kconfig fragment for duplicates 2017-04-19 09:29:19 -07:00
seccomp
sigaltstack tools/testing/selftests/sigaltstack/sas.c: improve output of sigaltstack testcase 2017-02-27 18:43:45 -08:00
size
splice selftests: splice: override clean in lib.mk to fix warnings 2017-04-27 08:05:04 -06:00
static_keys
sync selftests: sync: override clean in lib.mk to fix warnings 2017-04-27 08:05:14 -06:00
sysctl
timers linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
user
vDSO
vm linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
watchdog selftests: watchdog: accept multiple params on command line 2017-05-02 10:48:24 -06:00
x86 linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
zram
.gitignore selftests: add gpio generated files to .gitignore 2017-04-25 09:49:38 -06:00
gen_kselftest_tar.sh
kselftest_install.sh
kselftest.h
lib.mk selftests: lib.mk: define CLEAN macro to allow Makefiles to override clean 2017-04-25 09:46:45 -06:00
Makefile selftests/Makefile: Add missed PHONY targets 2017-04-21 11:24:58 -06:00