]> git.baikalelectronics.ru Git - kernel.git/commit
tools/bpf: fix selftest get_cgroup_id_user
authorYonghong Song <yhs@fb.com>
Wed, 6 Jun 2018 16:12:44 +0000 (09:12 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 7 Jun 2018 22:10:07 +0000 (00:10 +0200)
commit712d50b5f611d29e871d22bddce0a6d038f436d4
treeb2058f0e3712c5977dbb66a0477d4af9ced71d93
parent79a90d08772961a583d983d173cf1c76c4bcbb7c
tools/bpf: fix selftest get_cgroup_id_user

Commit 61301b3b754b ("tools/bpf: add a selftest for
bpf_get_current_cgroup_id() helper") added a test
for bpf_get_current_cgroup_id() helper. The bpf program
is attached to tracepoint syscalls/sys_enter_nanosleep
and will record the cgroup id if the tracepoint is hit.
The test program creates a cgroup and attachs itself to
this cgroup and expects that the test program process
cgroup id is the same as the cgroup_id retrieved
by the bpf program.

In a light system where no other processes called
nanosleep syscall, the test case can pass.
In a busy system where many different processes can hit
syscalls/sys_enter_nanosleep tracepoint, the cgroup id
recorded by bpf program may not match the test program
process cgroup_id.

This patch fixed an issue by communicating the test program
pid to bpf program. The bpf program only records
cgroup id if the current task pid is the same as
passed-in pid. This ensures that the recorded cgroup_id
is for the cgroup within which the test program resides.

Fixes: 61301b3b754b ("tools/bpf: add a selftest for bpf_get_current_cgroup_id() helper")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/get_cgroup_id_kern.c
tools/testing/selftests/bpf/get_cgroup_id_user.c