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

selftests/bpf: add missing __weak kfunc log fixup test

Add test validating that libbpf correctly poisons and reports __weak
unresolved kfuncs in post-processed verifier log.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230418002148.3255690-5-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
30bbfe32 05b6f766

+41
+31
tools/testing/selftests/bpf/prog_tests/log_fixup.c
··· 135 135 test_log_fixup__destroy(skel); 136 136 } 137 137 138 + static void missing_kfunc(void) 139 + { 140 + char log_buf[8 * 1024]; 141 + struct test_log_fixup* skel; 142 + int err; 143 + 144 + skel = test_log_fixup__open(); 145 + if (!ASSERT_OK_PTR(skel, "skel_open")) 146 + return; 147 + 148 + bpf_program__set_autoload(skel->progs.use_missing_kfunc, true); 149 + bpf_program__set_log_buf(skel->progs.use_missing_kfunc, log_buf, sizeof(log_buf)); 150 + 151 + err = test_log_fixup__load(skel); 152 + if (!ASSERT_ERR(err, "load_fail")) 153 + goto cleanup; 154 + 155 + ASSERT_HAS_SUBSTR(log_buf, 156 + "0: <invalid kfunc call>\n" 157 + "kfunc 'bpf_nonexistent_kfunc' is referenced but wasn't resolved\n", 158 + "log_buf"); 159 + 160 + if (env.verbosity > VERBOSE_NONE) 161 + printf("LOG: \n=================\n%s=================\n", log_buf); 162 + 163 + cleanup: 164 + test_log_fixup__destroy(skel); 165 + } 166 + 138 167 void test_log_fixup(void) 139 168 { 140 169 if (test__start_subtest("bad_core_relo_trunc_none")) ··· 176 147 bad_core_relo_subprog(); 177 148 if (test__start_subtest("missing_map")) 178 149 missing_map(); 150 + if (test__start_subtest("missing_kfunc")) 151 + missing_kfunc(); 179 152 }
+10
tools/testing/selftests/bpf/progs/test_log_fixup.c
··· 61 61 return value != NULL; 62 62 } 63 63 64 + extern int bpf_nonexistent_kfunc(void) __ksym __weak; 65 + 66 + SEC("?raw_tp/sys_enter") 67 + int use_missing_kfunc(const void *ctx) 68 + { 69 + bpf_nonexistent_kfunc(); 70 + 71 + return 0; 72 + } 73 + 64 74 char _license[] SEC("license") = "GPL";