Re: [PATCH bpf] bpf: cgroup: allow multi-attach program to replace itself

From: Alexei Starovoitov
Date: Tue Jun 09 2020 - 14:26:31 EST


On Mon, Jun 8, 2020 at 9:22 AM Lorenz Bauer <lmb@xxxxxxxxxxxxxx> wrote:
>
> 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 1020c1f24a94 ("bpf: Simplify __cgroup_bpf_attach") and
> commit d7bf2c10af05 ("bpf: allocate cgroup storage entries on attaching bpf programs")
> as well as commit 324bda9e6c5a ("bpf: multi program support for cgroup+bpf")
>
> Signed-off-by: Lorenz Bauer <lmb@xxxxxxxxxxxxxx>
> Fixes: af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment")

Applied. Thanks