]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: cgroup: Allow multi-attach program to replace itself
authorLorenz Bauer <lmb@cloudflare.com>
Mon, 8 Jun 2020 16:22:01 +0000 (17:22 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 9 Jun 2020 18:21:43 +0000 (11:21 -0700)
commit94487437841cf30df29a7313eef78f00cbbf6518
treec319d492bd9e0bf5c9c3c7a321af5036fa50fcaf
parenta91b862f57d0a678582beb4d329f38d219a6d840
bpf: cgroup: Allow multi-attach program to replace itself

When using BPF_PROG_ATTACH to attach a program to a cgroup in
BPF_F_ALLOW_MULTI mode, it is not possible to replace a program
with itself. This is because the check for duplicate programs
doesn't take the replacement program into account.

Replacing a program with itself might seem weird, but it has
some uses: first, it allows resetting the associated cgroup storage.
Second, it makes the API consistent with the non-ALLOW_MULTI usage,
where it is possible to replace a program with itself. Third, it
aligns BPF_PROG_ATTACH with bpf_link, where replacing itself is
also supported.

Sice this code has been refactored a few times this change will
only apply to v5.7 and later. Adjustments could be made to
commit 1f04601c6e1a ("bpf: Simplify __cgroup_bpf_attach") and
commit 143586412d9a ("bpf: allocate cgroup storage entries on attaching bpf programs")
as well as commit 8e506b1a28cb ("bpf: multi program support for cgroup+bpf")

Fixes: 78b5ce1cbefa ("bpf: Implement bpf_link-based cgroup BPF program attachment")
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200608162202.94002-1-lmb@cloudflare.com
kernel/bpf/cgroup.c
tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c