linux-stable/tools/testing/selftests
John Fastabend 9efa9e4997 bpf, selftests: Add tests to sock_ops for loading sk
Add tests to directly accesse sock_ops sk field. Then use it to
ensure a bad pointer access will fault if something goes wrong.
We do three tests:

The first test ensures when we read sock_ops sk pointer into the
same register that we don't fault as described earlier. Here r9
is chosen as the temp register.  The xlated code is,

  36: (7b) *(u64 *)(r1 +32) = r9
  37: (61) r9 = *(u32 *)(r1 +28)
  38: (15) if r9 == 0x0 goto pc+3
  39: (79) r9 = *(u64 *)(r1 +32)
  40: (79) r1 = *(u64 *)(r1 +0)
  41: (05) goto pc+1
  42: (79) r9 = *(u64 *)(r1 +32)

The second test ensures the temp register selection does not collide
with in-use register r9. Shown here r8 is chosen because r9 is the
sock_ops pointer. The xlated code is as follows,

  46: (7b) *(u64 *)(r9 +32) = r8
  47: (61) r8 = *(u32 *)(r9 +28)
  48: (15) if r8 == 0x0 goto pc+3
  49: (79) r8 = *(u64 *)(r9 +32)
  50: (79) r9 = *(u64 *)(r9 +0)
  51: (05) goto pc+1
  52: (79) r8 = *(u64 *)(r9 +32)

And finally, ensure we didn't break the base case where dst_reg does
not equal the source register,

  56: (61) r2 = *(u32 *)(r1 +28)
  57: (15) if r2 == 0x0 goto pc+1
  58: (79) r2 = *(u64 *)(r1 +0)

Notice it takes us an extra four instructions when src reg is the
same as dst reg. One to save the reg, two to restore depending on
the branch taken and a goto to jump over the second restore.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/159718355325.4728.4163036953345999636.stgit@john-Precision-5820-Tower
2020-08-13 22:40:43 +02:00
..
android SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
arm64 kselftest: arm64: Remove redundant clean target 2020-06-24 14:25:59 +01:00
bpf bpf, selftests: Add tests to sock_ops for loading sk 2020-08-13 22:40:43 +02:00
breakpoints selftests: breakpoints: do not use ksft_exit_skip after ksft_set_plan 2020-07-06 15:47:48 -06:00
capabilities .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
cgroup SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
clone3 linux-kselftest-5.9-rc1 2020-08-05 10:28:25 -07:00
core tests: add CLOSE_RANGE_UNSHARE tests 2020-06-17 00:07:38 +02:00
cpu-hotplug
cpufreq
dmabuf-heaps kselftests: dmabuf-heaps: Fix confused return value on expected error testing 2020-05-08 09:40:58 -06:00
drivers selftests: mlxsw: RED: Test offload of trapping on RED qevents 2020-08-03 18:06:46 -07:00
efivarfs .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
exec linux-kselftest-5.8-rc1 2020-06-09 10:03:12 -07:00
filesystems selftests/binderfs: Fix harness API usage 2020-07-06 15:59:16 -06:00
firmware selftest/firmware: Add selftest timeout in settings 2020-07-25 12:05:20 +02:00
fpu selftests/fpu: Add an FPU selftest 2020-06-29 10:02:23 +02:00
ftrace selftests/ftrace: Support ":README" suffix for requires 2020-06-16 10:42:47 -06:00
futex .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
gpio selftests: add build/cross-build dependency check script 2020-04-23 17:23:20 -06:00
ia64 .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
intel_pstate selftests: add build/cross-build dependency check script 2020-04-23 17:23:20 -06:00
ipc selftests/ipc: Fix test failure seen after initial test run 2020-04-14 10:24:28 -06:00
ir .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
kcmp .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
kexec
kmod selftests: kmod: Add module address visibility test 2020-07-17 13:36:51 -06:00
kselftest Driver core changes for 5.9-rc1 2020-08-05 11:52:17 -07:00
kvm KVM: nVMX: check for invalid hdr.vmx.flags 2020-07-27 09:04:50 -04:00
lib lib: make a test module with set/clear bit 2020-06-04 19:06:25 -07:00
livepatch
lkdtm lkdtm: Make arch-specific tests always available 2020-06-29 18:41:39 +02:00
locking
media_tests .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
membarrier .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
memfd selftests: add build/cross-build dependency check script 2020-04-23 17:23:20 -06:00
memory-hotplug
mount .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
mqueue .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
net mptcp: more stable diag self-tests 2020-08-07 17:25:38 -07:00
netfilter selftests: netfilter: add meta iif/oif match test 2020-08-03 12:02:22 +02:00
nsfs tools/testing: Replace zero-length array with flexible-array 2020-05-08 09:42:14 -06:00
ntb NTB: ntb_test: Fix bug when counting remote files 2020-06-05 20:02:09 -04:00
openat2 .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
pid_namespace selftests: Remove unneeded selftest API headers 2020-07-06 15:59:07 -06:00
pidfd linux-kselftest-5.9-rc1 2020-08-05 10:28:25 -07:00
powerpc selftests/powerpc: Use proper error code to check fault address 2020-07-15 23:10:17 +10:00
prctl .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
proc proc: use human-readable values for hidepid 2020-04-22 10:51:22 -05:00
pstore pstore/platform: Use backend name for console registration 2020-05-30 10:34:02 -07:00
ptp testptp: add new options for perout phase and pulse width 2020-07-20 18:04:59 -07:00
ptrace SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
rcutorture Merge branches 'doc.2020.06.29a', 'fixes.2020.06.29a', 'kfree_rcu.2020.06.29a', 'rcu-tasks.2020.06.29a', 'scale.2020.06.29a', 'srcu.2020.06.29a' and 'torture.2020.06.29a' into HEAD 2020-06-29 12:03:15 -07:00
resctrl selftests/resctrl: fix spelling mistake "Errror" -> "Error" 2020-03-13 13:29:22 -06:00
rseq .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
rtc .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
safesetid .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
seccomp arch/csky patches for 5.9-rc1 2020-08-06 10:15:28 -07:00
sigaltstack selftests: sigaltstack: do not use ksft_exit_skip after ksft_set_plan 2020-07-06 15:57:15 -06:00
size .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
sparc64 .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
splice .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
static_keys
sync selftests: sync_test: do not use ksft_exit_skip after ksft_set_plan 2020-07-06 15:57:28 -06:00
sysctl linux-kselftest-5.8-rc1 2020-06-09 10:03:12 -07:00
tc-testing tc-testing: Add tdc to kselftests 2020-07-20 18:29:37 -07:00
timens selftests/timens: handle a case when alarm clocks are not supported 2020-05-22 13:29:55 -06:00
timers .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
tmpfs .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
tpm2 selftests: tpm: upgrade TPM2 tests from Python 2 to Python 3 2020-07-06 14:20:35 -06:00
uevent selftests: Remove unneeded selftest API headers 2020-07-06 15:59:07 -06:00
user
vDSO selftests: vdso: Add a selftest for vDSO getcpu() 2020-05-22 11:05:07 -06:00
vm hmm related patches for 5.9 2020-08-05 13:28:50 -07:00
watchdog .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
wireguard wireguard: device: avoid circular netns references 2020-06-23 14:50:34 -07:00
x86 Support for FSGSBASE. Almost 5 years after the first RFC to support it, 2020-08-04 21:16:22 -07:00
zram
.gitignore SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
Makefile Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-08-05 20:13:21 -07:00
gen_kselftest_tar.sh selftests: introduce gen_tar Makefile target 2020-05-19 16:11:46 -06:00
kselftest.h linux-kselftest-5.9-rc1 2020-08-05 10:28:25 -07:00
kselftest_deps.sh selftests: add build/cross-build dependency check script 2020-04-23 17:23:20 -06:00
kselftest_harness.h selftests/harness: Limit step counter reporting 2020-07-17 13:56:35 -06:00
kselftest_install.sh
kselftest_module.h
lib.mk selftests: fix condition in run_tests 2020-07-07 14:11:31 -06:00