d923021c2c
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 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
50 lines
1.5 KiB
C
50 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2019 Facebook */
|
|
#include <test_progs.h>
|
|
#include "fentry_test.skel.h"
|
|
#include "fexit_test.skel.h"
|
|
|
|
void test_fentry_fexit(void)
|
|
{
|
|
struct fentry_test *fentry_skel = NULL;
|
|
struct fexit_test *fexit_skel = NULL;
|
|
__u64 *fentry_res, *fexit_res;
|
|
__u32 duration = 0, retval;
|
|
int err, prog_fd, i;
|
|
|
|
fentry_skel = fentry_test__open_and_load();
|
|
if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n"))
|
|
goto close_prog;
|
|
fexit_skel = fexit_test__open_and_load();
|
|
if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n"))
|
|
goto close_prog;
|
|
|
|
err = fentry_test__attach(fentry_skel);
|
|
if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err))
|
|
goto close_prog;
|
|
err = fexit_test__attach(fexit_skel);
|
|
if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
|
|
goto close_prog;
|
|
|
|
prog_fd = bpf_program__fd(fexit_skel->progs.test1);
|
|
err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
|
|
NULL, NULL, &retval, &duration);
|
|
CHECK(err || retval, "ipv6",
|
|
"err %d errno %d retval %d duration %d\n",
|
|
err, errno, retval, duration);
|
|
|
|
fentry_res = (__u64 *)fentry_skel->bss;
|
|
fexit_res = (__u64 *)fexit_skel->bss;
|
|
printf("%lld\n", fentry_skel->bss->test1_result);
|
|
for (i = 0; i < 8; i++) {
|
|
CHECK(fentry_res[i] != 1, "result",
|
|
"fentry_test%d failed err %lld\n", i + 1, fentry_res[i]);
|
|
CHECK(fexit_res[i] != 1, "result",
|
|
"fexit_test%d failed err %lld\n", i + 1, fexit_res[i]);
|
|
}
|
|
|
|
close_prog:
|
|
fentry_test__destroy(fentry_skel);
|
|
fexit_test__destroy(fexit_skel);
|
|
}
|