Skip to content

Conversation

dylandreimerink
Copy link
Member

@dylandreimerink dylandreimerink commented Aug 27, 2025

On systems where the kernel.kptr_restrict and net.core.bpf_jit_harden sysctls are enabled, certain fields in the program info may be restricted. When this is the case xlated and jitted instruction, line info, and function info are unavailable.

When such fields are unavailable, we do get ..len fields set to non-zero values, but the kernel will have not written any data to the pointers provided. Link

At present when this happens we don't recognize this and attempt to parse the empty buffers resulting in a parse func info: offset 0: type ID 0 is a *btf.Void, but expected a Func error.

The only clue we have that this is happening is that the kernel will zero out the insns pointer. This commit adds logic to detect when this happens and then returns a dedicated ErrInfoRestricted error so this case can be handled gracefully.

This is similar to / based on the approach bpftool has taken to handle this.

@dylandreimerink dylandreimerink force-pushed the feature/handle-restricted-prog-info branch from 27470e0 to 83c838b Compare August 27, 2025 16:36
@dylandreimerink dylandreimerink marked this pull request as ready for review August 28, 2025 09:19
@dylandreimerink dylandreimerink requested a review from a team as a code owner August 28, 2025 09:19
florianl
florianl previously approved these changes Aug 28, 2025
On systems where the `kernel.kptr_restrict` and
`net.core.bpf_jit_harden` sysctls are enabled, certain fields in the
program info may be restricted. When this is the case xlated and jitted
instruction, line info, and function info are unavailable.

When such fields are unavailable, we do get ..len fields set to non-zero
values, but the kernel will have not written any data to the pointers
provided.

At present when this happens we don't recognize this and attempt to
parse the empty buffers resulting in a `parse func info: offset 0:
type ID 0 is a *btf.Void, but expected a Func` error.

The only clue we have that this is happening is that the kernel will
zero out the insns pointer. This commit adds logic to detect when
this happens and then returns a dedicated `ErrInfoRestricted` error
so this case can be handled gracefully.

Signed-off-by: Dylan Reimerink <[email protected]>
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.

3 participants