mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-11 15:11:48 -04:00
BACKPORT: bpf: Add tests for PTR_TO_BTF_ID vs. null comparison
Add two tests for PTR_TO_BTF_ID vs. null ptr comparison,
one for PTR_TO_BTF_ID in the ctx structure and the
other for PTR_TO_BTF_ID after one level pointer chasing.
In both cases, the test ensures condition is not
removed.
For example, for this test
struct bpf_fentry_test_t {
struct bpf_fentry_test_t *a;
};
int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
{
if (arg == 0)
test7_result = 1;
return 0;
}
Before the previous verifier change, we have xlated codes:
int test7(long long unsigned int * ctx):
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
0: (79) r1 = *(u64 *)(r1 +0)
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
1: (b4) w0 = 0
2: (95) exit
After the previous verifier change, we have:
int test7(long long unsigned int * ctx):
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
0: (79) r1 = *(u64 *)(r1 +0)
; if (arg == 0)
1: (55) if r1 != 0x0 goto pc+4
; test7_result = 1;
2: (18) r1 = map[id:6][0]+48
4: (b7) r2 = 1
5: (7b) *(u64 *)(r1 +0) = r2
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
6: (b4) w0 = 0
7: (95) exit
Change-Id: I4bfad59a173ce4e838c6f6f494e85c0a1e8d0431
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200630171241.2523875-1-yhs@fb.com
This commit is contained in:
parent
55612a8c1b
commit
d6893cb109
1 changed files with 18 additions and 1 deletions
|
|
@ -147,6 +147,20 @@ int noinline bpf_fentry_test6(u64 a, void *b, short c, int d, void *e, u64 f)
|
|||
return a + (long)b + c + d + (long)e + f;
|
||||
}
|
||||
|
||||
struct bpf_fentry_test_t {
|
||||
struct bpf_fentry_test_t *a;
|
||||
};
|
||||
|
||||
int noinline bpf_fentry_test7(struct bpf_fentry_test_t *arg)
|
||||
{
|
||||
return (long)arg;
|
||||
}
|
||||
|
||||
int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
|
||||
{
|
||||
return (long)arg->a;
|
||||
}
|
||||
|
||||
int noinline bpf_modify_return_test(int a, int *b)
|
||||
{
|
||||
*b += 1;
|
||||
|
|
@ -186,6 +200,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
|
|||
const union bpf_attr *kattr,
|
||||
union bpf_attr __user *uattr)
|
||||
{
|
||||
struct bpf_fentry_test_t arg = {};
|
||||
u16 side_effect = 0, ret = 0;
|
||||
int b = 2, err = -EFAULT;
|
||||
u32 retval = 0;
|
||||
|
|
@ -198,7 +213,9 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
|
|||
bpf_fentry_test3(4, 5, 6) != 15 ||
|
||||
bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
|
||||
bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
|
||||
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111)
|
||||
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
|
||||
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
|
||||
bpf_fentry_test8(&arg) != 0)
|
||||
goto out;
|
||||
break;
|
||||
case BPF_MODIFY_RETURN:
|
||||
|
|
|
|||
Loading…
Reference in a new issue