mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 12:13:51 -04:00
selftests/bpf: Test verifier log for global percpu data
Add two tests to verify the verifier log "R%d points to percpu_array map which cannot be used as const string\n". Signed-off-by: Leon Hwang <leon.hwang@linux.dev> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/bpf/20260813152324.97937-10-leon.hwang@linux.dev
This commit is contained in:
committed by
Andrii Nakryiko
parent
3993d5beef
commit
1ed2294b31
@@ -322,6 +322,11 @@ static void test_global_percpu_data_rdonly_direct_write(void)
|
||||
close(map_fd);
|
||||
}
|
||||
|
||||
static void test_global_percpu_data_verifier_log(void)
|
||||
{
|
||||
RUN_TESTS(test_global_percpu_data);
|
||||
}
|
||||
|
||||
void test_global_percpu_data(void)
|
||||
{
|
||||
if (!feat_supported(NULL, FEAT_PERCPU_DATA)) {
|
||||
@@ -337,4 +342,5 @@ void test_global_percpu_data(void)
|
||||
test_global_percpu_data_rdonly_direct_read();
|
||||
if (test__start_subtest("rdonly_direct_write"))
|
||||
test_global_percpu_data_rdonly_direct_write();
|
||||
test_global_percpu_data_verifier_log();
|
||||
}
|
||||
|
||||
@@ -38,4 +38,27 @@ int update_percpu_data(void *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char fmt[] SEC(".percpu.fmt") = "data %d\n";
|
||||
|
||||
SEC("?kprobe")
|
||||
__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
|
||||
int verifier_strncmp(void *ctx)
|
||||
{
|
||||
return bpf_strncmp("test", 5, fmt);
|
||||
}
|
||||
|
||||
SEC("?kprobe")
|
||||
__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
|
||||
int verifier_snprintf(void *ctx)
|
||||
{
|
||||
u64 args[] = { data };
|
||||
char buf[128];
|
||||
int len;
|
||||
|
||||
len = bpf_snprintf(buf, sizeof(buf), fmt, args, sizeof(args));
|
||||
if (len > 0)
|
||||
bpf_printk("snprintf: %s\n", buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
Reference in New Issue
Block a user