linux_dsm_epyc7002/tools/testing/selftests
Jakub Kicinski 28e33f9d78 bpf: disallow arithmetic operations on context pointer
Commit f1174f77b5 ("bpf/verifier: rework value tracking")
removed the crafty selection of which pointer types are
allowed to be modified.  This is OK for most pointer types
since adjust_ptr_min_max_vals() will catch operations on
immutable pointers.  One exception is PTR_TO_CTX which is
now allowed to be offseted freely.

The intent of aforementioned commit was to allow context
access via modified registers.  The offset passed to
->is_valid_access() verifier callback has been adjusted
by the value of the variable offset.

What is missing, however, is taking the variable offset
into account when the context register is used.  Or in terms
of the code adding the offset to the value passed to the
->convert_ctx_access() callback.  This leads to the following
eBPF user code:

     r1 += 68
     r0 = *(u32 *)(r1 + 8)
     exit

being translated to this in kernel space:

   0: (07) r1 += 68
   1: (61) r0 = *(u32 *)(r1 +180)
   2: (95) exit

Offset 8 is corresponding to 180 in the kernel, but offset
76 is valid too.  Verifier will "accept" access to offset
68+8=76 but then "convert" access to offset 8 as 180.
Effective access to offset 248 is beyond the kernel context.
(This is a __sk_buff example on a debug-heavy kernel -
packet mark is 8 -> 180, 76 would be data.)

Dereferencing the modified context pointer is not as easy
as dereferencing other types, because we have to translate
the access to reading a field in kernel structures which is
usually at a different offset and often of a different size.
To allow modifying the pointer we would have to make sure
that given eBPF instruction will always access the same
field or the fields accessed are "compatible" in terms of
offset and size...

Disallow dereferencing modified context pointers and add
to selftests the test case described here.

Fixes: f1174f77b5 ("bpf/verifier: rework value tracking")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Edward Cree <ecree@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-10-18 13:21:13 +01:00
..
bpf bpf: disallow arithmetic operations on context pointer 2017-10-18 13:21:13 +01:00
breakpoints selftests: breakpoints: re-order TEST_GEN_PROGS targets 2017-09-18 10:53:58 -06:00
capabilities
cpu-hotplug selftests/cpu-hotplug: Skip test when there is only one online cpu 2017-08-16 17:48:18 -06:00
cpufreq
drivers/gpu
efivarfs
exec
filesystems
firmware
ftrace selftests/ftrace: multiple_kprobes: Also check for support 2017-09-18 10:55:55 -06:00
futex selftests: futex: Makefile: fix for loops in targets to run silently 2017-09-25 10:09:00 -06:00
gpio
ia64
intel_pstate selftests/intel_pstate: No need to compile test progs in the run script 2017-09-18 10:54:53 -06:00
ipc
kcmp tools/testing/selftests/kcmp/kcmp_test.c: add KCMP_EPOLL_TFD testing 2017-09-08 18:26:47 -07:00
kmod test_kmod: fix description for -s -and -c parameters 2017-08-18 15:32:01 -07:00
lib
locking
media_tests
membarrier
memfd selftests/memfd: correct run_tests.sh permission 2017-09-25 10:09:06 -06:00
memory-hotplug
mount
mqueue selftests: mqueue: Use full path to run tests from Makefile 2017-09-25 10:08:59 -06:00
net selftests/net: msg_zerocopy enable build with older kernel headers 2017-09-19 14:12:29 -06:00
networking/timestamping selftests/net: rxtimestamp: Fix an off by one 2017-10-05 21:28:53 -07:00
nsfs
ntb
powerpc selftests/powerpc: Force ptrace tests to build -fno-pie 2017-08-31 14:26:49 +10:00
prctl
pstore
ptp
ptrace
rcutorture Merge branches 'doc.2017.08.17a', 'fixes.2017.08.17a', 'hotplug.2017.07.25b', 'misc.2017.08.17a', 'spin_unlock_wait_no.2017.08.17a', 'srcu.2017.07.27c' and 'torture.2017.07.24c' into HEAD 2017-08-17 08:10:04 -07:00
seccomp linux-kselftest-4.14-rc3-fixes 2017-09-27 10:51:08 -07:00
sigaltstack tools: fix testing/selftests/sigaltstack for s390x 2017-09-18 10:52:01 -06:00
size
splice
static_keys
sync selftests: sync: kselftest and kselftest-clean fail for make O=dir case 2017-09-21 07:55:40 -06:00
sysctl
tc-testing tc-testing: add test for testing ife type 2017-08-29 15:14:18 -07:00
timers selftests: timers: set-timer-lat: Fix hang when testing unsupported alarms 2017-09-25 10:09:07 -06:00
user
vDSO
vm userfaultfd: selftest: explicit failure if the SIGBUS test failed 2017-09-06 17:27:29 -07:00
watchdog selftests: watchdog: fix to use TEST_GEN_PROGS and remove clean 2017-09-21 07:55:38 -06:00
x86 Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2017-09-11 18:34:47 -07:00
zram
.gitignore
gen_kselftest_tar.sh
kselftest_harness.h selftests: Enhance kselftest_harness.h to print which assert failed 2017-09-05 19:21:33 -06:00
kselftest_install.sh
kselftest.h selftests: kselftest framework: change skip exit code to 0 2017-08-25 10:02:00 -06:00
lib.mk selftests: lib.mk: copy test scripts and test files for make O=dir run 2017-09-21 07:55:40 -06:00
Makefile selftests: Makefile: fix for loops in targets to run silently 2017-09-25 10:08:59 -06:00