Skip to content

Allow loading weak kfuncs without CAP_SYS_ADMIN#1950

Open
dylandreimerink wants to merge 3 commits intomainfrom
feature/fix-1929
Open

Allow loading weak kfuncs without CAP_SYS_ADMIN#1950
dylandreimerink wants to merge 3 commits intomainfrom
feature/fix-1929

Conversation

@dylandreimerink
Copy link
Member

@dylandreimerink dylandreimerink commented Feb 4, 2026

Currently when users attempt to load a program with a weak kfunc on a kernel that does not have that kfunc while lacking CAP_SYS_ADMIN, loading fails with the following error.

fixing up kfuncs: finding kfunc in kernel: find target in modules:
iterate modules: get next BTF ID: operation not permitted`

This happens because when we are unable to find the kfunc in the kernel BTF, we attempt to look for it in kernel modules. Iterating over kernel modules requires CAP_SYS_ADMIN, and we throw the error we get back.

This PR changes findTargetInKernel to wrap the EPERM error we get back when lacking CAP_SYS_ADMIN with btf.ErrNotFound. This allows the kfunc resolution logic to treat it the same way as if the kfunc was not found. For non weak kfuncs, this will still cause loading to fail, but for weak kfuncs, loading will now succeed.Currently

The PR also includes a new test helper which allows us to drop capabilities to a specific set while running a callback so we can write tests that assert certain behavior works with reduced capabilities.

Fixes: #1929

This commits introduces the WithCapabilities helper function which
allows us to write tests that assert behavior works correctly when
certain capabilities are present or absent.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
This commit changes the TestWeakKfunc test so it runs without
CAP_SYS_ADMIN to assert that we should be able to load BPF programs
with weak kfuncs even when we don't have that capability.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Currently when users attempt to load a program with a weak kfunc
on a kernel that does not have that kfunc while lacking CAP_SYS_ADMIN,
loading fails with the following error.

> fixing up kfuncs: finding kfunc in kernel: find target in modules:
> iterate modules: get next BTF ID: operation not permitted`

This happens because when we are unable to find the kfunc in the
kernel BTF, we attempt to look for it in kernel modules. Iterating
over kernel modules requires CAP_SYS_ADMIN, and we throw the error
we get back.

This commit changes `findTargetInKernel` to wrap the EPERM error we get
back when lacking CAP_SYS_ADMIN with btf.ErrNotFound. This allows the
kfunc resolution logic to treat it the same way as if the kfunc was not
found. For non weak kfuncs, this will still cause loading to fail, but
for weak kfuncs, loading will now succeed.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
@dylandreimerink dylandreimerink marked this pull request as ready for review February 6, 2026 13:04
@dylandreimerink dylandreimerink requested a review from a team as a code owner February 6, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

modules BTF loading fails when CAP_SYS_ADMIN is missing

1 participant