diff options
author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2022-03-19 13:38:26 +0530 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-04-06 10:32:12 -0700 |
commit | 7cb29b1c99f4244c3f1de04e88eb9aed842a0cba (patch) | |
tree | b26af2d3fe4d3faddbc6b6d917dd4bda2b25064e /tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c | |
parent | 7b3552d3f9f6897851fc453b5131a967167e43c2 (diff) | |
download | linux-stable-7cb29b1c99f4244c3f1de04e88eb9aed842a0cba.tar.gz linux-stable-7cb29b1c99f4244c3f1de04e88eb9aed842a0cba.tar.bz2 linux-stable-7cb29b1c99f4244c3f1de04e88eb9aed842a0cba.zip |
selftests/bpf: Test passing rdonly mem to global func
Add two test cases, one pass read only map value pointer to global
func, which should be rejected. The same code checks it for kfunc, so
that is covered as well. Second one tries to use the missing check for
PTR_TO_MEM's MEM_RDONLY flag and tries to write to a read only memory
pointer. Without prior patches, both of these tests fail.
Reviewed-by: Hao Luo <haoluo@google.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20220319080827.73251-5-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c b/tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c index 2180c41cd890..a72a5bf3812a 100644 --- a/tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c +++ b/tools/testing/selftests/bpf/progs/test_ksyms_btf_write_check.c @@ -8,7 +8,7 @@ extern const int bpf_prog_active __ksym; /* int type global var. */ SEC("raw_tp/sys_enter") -int handler(const void *ctx) +int handler1(const void *ctx) { int *active; __u32 cpu; @@ -26,4 +26,20 @@ int handler(const void *ctx) return 0; } +__noinline int write_active(int *p) +{ + return p ? (*p = 42) : 0; +} + +SEC("raw_tp/sys_enter") +int handler2(const void *ctx) +{ + int *active; + __u32 cpu; + + active = bpf_this_cpu_ptr(&bpf_prog_active); + write_active(active); + return 0; +} + char _license[] SEC("license") = "GPL"; |