diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2022-09-06 17:13:00 +0200 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-09-07 11:04:27 -0700 |
commit | fb66223a244f252273995557b23e0fa53092e92c (patch) | |
tree | dcf688c426b2db8ce56f2b755be5f0e7c50b2d38 /tools/testing/selftests/bpf/progs/kfunc_call_test.c | |
parent | 15baa55ff5b00b81bcd9874b89cb8e0b0daaa13d (diff) | |
download | linux-stable-fb66223a244f252273995557b23e0fa53092e92c.tar.gz linux-stable-fb66223a244f252273995557b23e0fa53092e92c.tar.bz2 linux-stable-fb66223a244f252273995557b23e0fa53092e92c.zip |
selftests/bpf: add test for accessing ctx from syscall program type
We need to also export the kfunc set to the syscall program type,
and then add a couple of eBPF programs that are testing those calls.
The first one checks for valid access, and the second one is OK
from a static analysis point of view but fails at run time because
we are trying to access outside of the allocated memory.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Link: https://lore.kernel.org/r/20220906151303.2780789-5-benjamin.tissoires@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/kfunc_call_test.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/kfunc_call_test.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/kfunc_call_test.c b/tools/testing/selftests/bpf/progs/kfunc_call_test.c index 5aecbb9fdc68..9e1914916f1d 100644 --- a/tools/testing/selftests/bpf/progs/kfunc_call_test.c +++ b/tools/testing/selftests/bpf/progs/kfunc_call_test.c @@ -92,4 +92,42 @@ int kfunc_call_test_pass(struct __sk_buff *skb) return 0; } +struct syscall_test_args { + __u8 data[16]; + size_t size; +}; + +SEC("syscall") +int kfunc_syscall_test(struct syscall_test_args *args) +{ + const long size = args->size; + + if (size > sizeof(args->data)) + return -7; /* -E2BIG */ + + bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(args->data)); + bpf_kfunc_call_test_mem_len_pass1(&args->data, sizeof(*args)); + bpf_kfunc_call_test_mem_len_pass1(&args->data, size); + + return 0; +} + +SEC("syscall") +int kfunc_syscall_test_null(struct syscall_test_args *args) +{ + /* Must be called with args as a NULL pointer + * we do not check for it to have the verifier consider that + * the pointer might not be null, and so we can load it. + * + * So the following can not be added: + * + * if (args) + * return -22; + */ + + bpf_kfunc_call_test_mem_len_pass1(args, 0); + + return 0; +} + char _license[] SEC("license") = "GPL"; |