From 1b41d4467c422ba17b374818429489fa7fcc18b7 Mon Sep 17 00:00:00 2001 From: player-two <> Date: Wed, 7 Sep 2022 16:52:59 -0500 Subject: [PATCH] Fix haveProgTestRun on kernel version 5.15.65 A recent patch[0] to the kernel prevents bpf_prog_test_run_skb() from running the bpf program with with an empty skb. This makes the existing feature check fail, so to fix it an additional byte of input data is needed. [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fd1894224407c484f652ad456e1ce423e89bb3eb --- prog.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/prog.go b/prog.go index bec7d2347..3d2b8b293 100644 --- a/prog.go +++ b/prog.go @@ -624,8 +624,12 @@ var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() e } defer prog.Close() - // Programs require at least 14 bytes input - in := make([]byte, 14) + // Programs require at least 15 bytes input + // Looking in net/bpf/test_run.c, bpf_test_init() requires that the input is + // at least ETH_HLEN (14) bytes. A recent patch[0] also ensures that the skb + // is not empty after the layer 2 header is removed. + // [0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fd1894224407c484f652ad456e1ce423e89bb3eb + in := make([]byte, 15) attr := sys.ProgRunAttr{ ProgFd: uint32(prog.FD()), DataSizeIn: uint32(len(in)),