Skip to content

Commit dea0e04

Browse files
committed
cgroups: ebpf: use link.Anchor to check for BPF_F_REPLACE support
In v0.13.0, cilium/ebpf stopped supporting setting BPF_F_REPLACE as an explicit flag and instead requires us to use link.Anchor to specify where the program should be attached. Commit 216175a ("Upgrade Cilium's eBPF library version to 0.16") did update this correctly for the actual attaching logic, but when checking for kernel support we still passed BPF_F_REPLACE. This would result in a generic error being returned, which our feature-support checking logic would treat as being an error the indicates that BPF_F_REPLACE *is* supported, resulting in a regression on pre-5.6 kernels. It turns out that our debug logging saying that this unexpected error was happening was being output as a result of this change, but nobody noticed... Fixes: 216175a ("Upgrade Cilium's eBPF library version to 0.16") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 9453d59 commit dea0e04

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libcontainer/cgroups/devices/ebpf_linux.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ func haveBpfProgReplace() bool {
123123
// BPF_CGROUP_DEVICE programs. If passing BPF_F_REPLACE gives us EINVAL
124124
// we know that the feature isn't present.
125125
err = link.RawAttachProgram(link.RawAttachProgramOptions{
126-
// We rely on this fd being checked after attachFlags.
126+
// We rely on this fd being checked after attachFlags in the kernel.
127127
Target: int(devnull.Fd()),
128-
// Attempt to "replace" bad fds with this program.
128+
// Attempt to "replace" our BPF program with itself. This will
129+
// always fail, but we should get -EINVAL if BPF_F_REPLACE is not
130+
// supported.
131+
Anchor: link.ReplaceProgram(prog),
129132
Program: prog,
130133
Attach: ebpf.AttachCGroupDevice,
131-
Flags: unix.BPF_F_ALLOW_MULTI | unix.BPF_F_REPLACE,
134+
Flags: unix.BPF_F_ALLOW_MULTI,
132135
})
133136
if errors.Is(err, unix.EINVAL) {
134137
// not supported

0 commit comments

Comments
 (0)