Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: dummy_st_ops should reject 0 for non-nullable params

Check if BPF_PROG_TEST_RUN for bpf_dummy_struct_ops programs
rejects execution if NULL is passed for non-nullable parameter.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20240424012821.595216-6-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Eduard Zingerman and committed by
Alexei Starovoitov
6a2d30d3 980ca8ce

+27
+27
tools/testing/selftests/bpf/prog_tests/dummy_st_ops.c
··· 147 147 dummy_st_ops_success__destroy(skel); 148 148 } 149 149 150 + /* dummy_st_ops.test_sleepable() parameter is not marked as nullable, 151 + * thus bpf_prog_test_run_opts() below should be rejected as it tries 152 + * to pass NULL for this parameter. 153 + */ 154 + static void test_dummy_sleepable_reject_null(void) 155 + { 156 + __u64 args[1] = {0}; 157 + LIBBPF_OPTS(bpf_test_run_opts, attr, 158 + .ctx_in = args, 159 + .ctx_size_in = sizeof(args), 160 + ); 161 + struct dummy_st_ops_success *skel; 162 + int fd, err; 163 + 164 + skel = dummy_st_ops_success__open_and_load(); 165 + if (!ASSERT_OK_PTR(skel, "dummy_st_ops_load")) 166 + return; 167 + 168 + fd = bpf_program__fd(skel->progs.test_sleepable); 169 + err = bpf_prog_test_run_opts(fd, &attr); 170 + ASSERT_EQ(err, -EINVAL, "test_run"); 171 + 172 + dummy_st_ops_success__destroy(skel); 173 + } 174 + 150 175 void test_dummy_st_ops(void) 151 176 { 152 177 if (test__start_subtest("dummy_st_ops_attach")) ··· 184 159 test_dummy_multiple_args(); 185 160 if (test__start_subtest("dummy_sleepable")) 186 161 test_dummy_sleepable(); 162 + if (test__start_subtest("dummy_sleepable_reject_null")) 163 + test_dummy_sleepable_reject_null(); 187 164 188 165 RUN_TESTS(dummy_st_ops_fail); 189 166 }