]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
bpf: Test_verifier, add alu32 bounds tracking tests
authorJohn Fastabend <john.fastabend@gmail.com>
Thu, 5 Aug 2021 15:53:41 +0000 (18:53 +0300)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Mon, 20 Sep 2021 16:49:56 +0000 (18:49 +0200)
commitd6a425e65ed99aa74e989978a02444936e4b29fd
tree3e0669854bcdb343dd7c0510ef5a1c3651bd9a4b
parent3248aad624df0f75741efb6c1f3822b8d1aa95dc
bpf: Test_verifier, add alu32 bounds tracking tests

BugLink: https://bugs.launchpad.net/bugs/1941796
commit 41f70fe0649dddf02046315dc566e06da5a2dc91 upstream

Its possible to have divergent ALU32 and ALU64 bounds when using JMP32
instructins and ALU64 arithmatic operations. Sometimes the clang will
even generate this code. Because the case is a bit tricky lets add
a specific test for it.

Here is  pseudocode asm version to illustrate the idea,

 1 r0 = 0xffffffff00000001;
 2 if w0 > 1 goto %l[fail];
 3 r0 += 1
 5 if w0 > 2 goto %l[fail]
 6 exit

The intent here is the verifier will fail the load if the 32bit bounds
are not tracked correctly through ALU64 op. Similarly we can check the
64bit bounds are correctly zero extended after ALU32 ops.

 1 r0 = 0xffffffff00000001;
 2 w0 += 1
 2 if r0 > 3 goto %l[fail];
 6 exit

The above will fail if we do not correctly zero extend 64bit bounds
after 32bit op.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/158560430155.10843.514209255758200922.stgit@john-Precision-5820-Tower
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
tools/testing/selftests/bpf/verifier/bounds.c