diff options
author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2022-03-19 09:08:26 +0100 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-04-06 19:32:12 +0200 |
commit | 7cb29b1c99f4244c3f1de04e88eb9aed842a0cba (patch) | |
tree | b26af2d3fe4d3faddbc6b6d917dd4bda2b25064e /tools/testing/selftests/bpf/prog_tests/ksyms_btf.c | |
parent | bpf: Reject writes for PTR_TO_MAP_KEY in check_helper_mem_access (diff) | |
download | linux-7cb29b1c99f4244c3f1de04e88eb9aed842a0cba.tar.xz linux-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/prog_tests/ksyms_btf.c')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/ksyms_btf.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c index f6933b06daf8..1d7a2f1e0731 100644 --- a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c @@ -138,12 +138,16 @@ cleanup: test_ksyms_weak_lskel__destroy(skel); } -static void test_write_check(void) +static void test_write_check(bool test_handler1) { struct test_ksyms_btf_write_check *skel; - skel = test_ksyms_btf_write_check__open_and_load(); - ASSERT_ERR_PTR(skel, "unexpected load of a prog writing to ksym memory\n"); + skel = test_ksyms_btf_write_check__open(); + if (!ASSERT_OK_PTR(skel, "test_ksyms_btf_write_check__open")) + return; + bpf_program__set_autoload(test_handler1 ? skel->progs.handler2 : skel->progs.handler1, false); + ASSERT_ERR(test_ksyms_btf_write_check__load(skel), + "unexpected load of a prog writing to ksym memory\n"); test_ksyms_btf_write_check__destroy(skel); } @@ -179,6 +183,9 @@ void test_ksyms_btf(void) if (test__start_subtest("weak_ksyms_lskel")) test_weak_syms_lskel(); - if (test__start_subtest("write_check")) - test_write_check(); + if (test__start_subtest("write_check1")) + test_write_check(true); + + if (test__start_subtest("write_check2")) + test_write_check(false); } |