Skip to content

Commit f904c67

Browse files
Byte-LabAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test for non-NULLable PTR_TO_BTF_IDs
In a recent patch, we taught the verifier that trusted PTR_TO_BTF_ID can never be NULL. This prevents the verifier from incorrectly failing to load certain programs where it gets confused and thinks a reference isn't dropped because it incorrectly assumes that a branch exists in which a NULL PTR_TO_BTF_ID pointer is never released. This patch adds a testcase that verifies this cannot happen. Signed-off-by: David Vernet <void@manifault.com> Acked-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/r/20230602150112.1494194-2-void@manifault.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 51302c9 commit f904c67

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tools/testing/selftests/bpf/prog_tests/cpumask.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ void test_cpumask(void)
7070
verify_success(cpumask_success_testcases[i]);
7171
}
7272

73+
RUN_TESTS(cpumask_success);
7374
RUN_TESTS(cpumask_failure);
7475
}

tools/testing/selftests/bpf/progs/cpumask_success.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <bpf/bpf_tracing.h>
66
#include <bpf/bpf_helpers.h>
77

8+
#include "bpf_misc.h"
89
#include "cpumask_common.h"
910

1011
char _license[] SEC("license") = "GPL";
@@ -426,3 +427,26 @@ int BPF_PROG(test_global_mask_rcu, struct task_struct *task, u64 clone_flags)
426427

427428
return 0;
428429
}
430+
431+
SEC("tp_btf/task_newtask")
432+
__success
433+
int BPF_PROG(test_refcount_null_tracking, struct task_struct *task, u64 clone_flags)
434+
{
435+
struct bpf_cpumask *mask1, *mask2;
436+
437+
mask1 = bpf_cpumask_create();
438+
mask2 = bpf_cpumask_create();
439+
440+
if (!mask1 || !mask2)
441+
goto free_masks_return;
442+
443+
bpf_cpumask_test_cpu(0, (const struct cpumask *)mask1);
444+
bpf_cpumask_test_cpu(0, (const struct cpumask *)mask2);
445+
446+
free_masks_return:
447+
if (mask1)
448+
bpf_cpumask_release(mask1);
449+
if (mask2)
450+
bpf_cpumask_release(mask2);
451+
return 0;
452+
}

0 commit comments

Comments
 (0)