selftests/bpf: Fix spurious test failures in core_retro selftest
core_retro selftest uses BPF program that's triggered on sys_enter
system-wide, but has no protection from some unrelated process doing syscall
while selftest is running. This leads to occasional test failures with
unexpected PIDs being returned. Fix that by filtering out all processes that
are not test_progs process.
Fixes: fcda189a51
("selftests/bpf: Add test relying only on CO-RE and no recent kernel features")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200731204957.2047119-1-andriin@fb.com
This commit is contained in:

committed by
Alexei Starovoitov

parent
5a6b1a206d
commit
b5cc46cdff
@@ -8,6 +8,13 @@ struct task_struct {
|
||||
int tgid;
|
||||
} __attribute__((preserve_access_index));
|
||||
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
__uint(max_entries, 1);
|
||||
__type(key, int);
|
||||
__type(value, int);
|
||||
} exp_tgid_map SEC(".maps");
|
||||
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
__uint(max_entries, 1);
|
||||
@@ -21,6 +28,12 @@ int handle_sys_enter(void *ctx)
|
||||
struct task_struct *task = (void *)bpf_get_current_task();
|
||||
int tgid = BPF_CORE_READ(task, tgid);
|
||||
int zero = 0;
|
||||
int real_tgid = bpf_get_current_pid_tgid() >> 32;
|
||||
int *exp_tgid = bpf_map_lookup_elem(&exp_tgid_map, &zero);
|
||||
|
||||
/* only pass through sys_enters from test process */
|
||||
if (!exp_tgid || *exp_tgid != real_tgid)
|
||||
return 0;
|
||||
|
||||
bpf_map_update_elem(&results, &zero, &tgid, 0);
|
||||
|
||||
|
Reference in New Issue
Block a user