cilium / ebpf

ebpf-go is a pure-Go library to read, modify and load eBPF programs and attach them to various hooks in the Linux kernel.

Home Page:https://ebpf-go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TestHaveProgramType/Extension fails on kernels >6.7

lmb opened this issue · comments

Describe the bug

Running the testsuite against new kernels results in an error:

--- FAIL: TestHaveProgramType (0.07s)
    --- FAIL: TestHaveProgramType/Extension (0.00s)
        feature.go:30: Feature 'Extension' isn't supported even though kernel is newer than v5.6
FAIL
FAIL	github.com/cilium/ebpf/features	0.670s
FAIL

How to reproduce

Using newest vimto:

vimto -kernel :stable-selftests -- go test -short -count 1 ./features

Version information

main

I dumped the error which causes the probe to fail which is:

load program: invalid argument:
	Cannot replace static functions
	processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

Logic related to this error was changed in this patch set: https://lore.kernel.org/all/20231215011334.2307144-1-andrii@kernel.org/

I think I figured it out. This patch adds the following logic:

		/* if main BPF program has associated BTF info, validate that
		 * it's matching expected signature, and otherwise mark BTF
		 * info for main program as unreliable
		 */
		if (env->prog->aux->func_info_aux) {
			ret = btf_prepare_func_args(env, 0);
			if (ret || sub->arg_cnt != 1 || sub->args[0].arg_type != ARG_PTR_TO_CTX)
				env->prog->aux->func_info_aux[0].unreliable = true;
		}

So if a program is a main program (it is directly attached / an entrypoint) then its BTF must have exactly 1 argument, that being a pointer to CTX. But in our current probe the func info doesn't include a parameter. This causes the first XDP program to be marked unreliable, which causes the Cannot replace static functions error when trying to load the extension. Fix PR incoming