]> git.ipfire.org Git - thirdparty/systemd.git/commit
bpf: make sure the kernel do not submit an invalid program if no pattern matched
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 10 Nov 2019 22:08:21 +0000 (23:08 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Nov 2019 14:14:09 +0000 (15:14 +0100)
commit45669ae264c2d16db006c49ea264c38bd2080a22
tree1026c7b80292f47c1ace99afb587920014e1e223
parent00486578281bccbe36a6a447b3597d6bf8967933
bpf: make sure the kernel do not submit an invalid program if no pattern matched

It turns out that the kernel verifier would reject a program we would build
if there was a whitelist, but no entries in the whitelist matched.
The program would approximately like this:
   0: (61) r2 = *(u32 *)(r1 +0)
   1: (54) w2 &= 65535
   2: (61) r3 = *(u32 *)(r1 +0)
   3: (74) w3 >>= 16
   4: (61) r4 = *(u32 *)(r1 +4)
   5: (61) r5 = *(u32 *)(r1 +8)
  48: (b7) r0 = 0
  49: (05) goto pc+1
  50: (b7) r0 = 1
  51: (95) exit
and insn 50 is unreachable, which is illegal. We would then either keep a
previous version of the program or allow everything. Make sure we build a
valid program that simply rejects everything.
src/core/bpf-devices.c
src/core/cgroup.c
src/test/test-bpf-devices.c