linux-stable/tools
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
..
accounting SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
arch tools arch kvm: Sync kvm headers with the kernel sources 2020-07-17 09:39:16 -03:00
bootconfig tools/bootconfig: Add testcase for show-command and quotes test 2020-06-16 21:21:03 -04:00
bpf tools/bpftool: Make skeleton code C++17-friendly by dropping typeof() 2020-08-12 18:09:45 -07:00
build tools, build: Propagate build failures from tools/build/Makefile.build 2020-08-03 16:15:40 +02:00
cgroup iocost_monitor: start from the oldest usage index 2020-07-30 11:45:29 -06:00
debugging
edid
firewire
firmware
gpio tools: gpio: fix spurious close warning in gpio-event-mon 2020-07-12 10:22:01 +02:00
hv tools: hv: change http to https in hv_kvp_daemon.c 2020-07-06 10:46:23 +00:00
iio
include tools/bpf: Support new uapi for map element bpf iterator 2020-08-06 16:39:14 -07:00
io_uring io_uring: change the poll type to be 32-bits 2020-06-21 20:44:00 -06:00
kvm/kvm_stat tools/kvm_stat: add sample systemd unit file 2020-04-21 09:13:12 -04:00
laptop change email address for Pali Rohár 2020-04-10 15:36:22 -07:00
leds
lib libbpf: Prevent overriding errno when logging errors 2020-08-13 22:30:31 +02:00
memory-model These were the main changes in this cycle: 2020-08-03 14:39:35 -07:00
nfsd
objtool Misc updates: 2020-08-03 14:45:33 -07:00
pci tools: PCI: Add 'e' to clear IRQ 2020-04-02 17:57:10 +01:00
pcmcia
perf Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-08-02 01:02:12 -07:00
power ACPI updates for 5.9-rc1 2020-08-03 20:37:22 -07:00
scripts
spi spi: tools: Make default_tx/rx and input_tx static 2020-06-11 16:27:24 +01:00
testing bpf, selftests: Add tests to sock_ops for loading sk 2020-08-13 22:40:43 +02:00
thermal/tmon - Convert tsens configuration DT binding to yaml (Rajeshwari) 2020-04-07 20:00:16 -07:00
time
usb tools: usb: usbip: Replace HTTP links with HTTPS ones 2020-07-15 16:33:51 +02:00
virtio compiler: Remove uninitialized_var() macro 2020-07-16 12:35:31 -07:00
vm tools/vm/page_owner_sort.c: filter out unneeded line 2020-06-03 20:09:49 -07:00
wmi
Makefile bpf: Compile resolve_btfids tool at kernel compilation start 2020-07-13 10:42:02 -07:00