Skip to content

Commit 20ddfe1

Browse files
orishusslmb
authored andcommitted
program: don't return error when kmod BTF is disabled
In kernels where the flag CONFIG_DEBUG_INFO_BTF_MODULES is not set, including kernels 5.10 and below (because the flag was introduced in 5.11), loading a program that attaches to kernel module functions and relied on CORE failed because the module's BTF is not available. This fix allows the program to run, obviously only as long as it only relies on the kernel's BTF and not on the specific module's BTF. Fixes: #1436 Signed-off-by: Ori Shussman <[email protected]>
1 parent 7719d2f commit 20ddfe1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

btf/kernel.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func LoadKernelSpec() (*Spec, error) {
6363
//
6464
// Defaults to /sys/kernel/btf/<module>.
6565
// Returns an error wrapping ErrNotSupported if BTF is not enabled.
66+
// Returns an error wrapping fs.ErrNotExist if BTF for the specific module doesn't exist.
6667
func LoadKernelModuleSpec(module string) (*Spec, error) {
6768
kernelBTF.RLock()
6869
spec := kernelBTF.modules[module]

linker.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"io/fs"
910
"math"
1011
"slices"
1112

@@ -148,10 +149,13 @@ func applyRelocations(insns asm.Instructions, targets []*btf.Spec, kmodName stri
148149

149150
if kmodName != "" {
150151
kmodTarget, err := btf.LoadKernelModuleSpec(kmodName)
151-
if err != nil {
152+
// Ignore ErrNotExists to cater to kernels which have CONFIG_DEBUG_INFO_BTF_MODULES disabled.
153+
if err != nil && !errors.Is(err, fs.ErrNotExist) {
152154
return fmt.Errorf("load kernel module spec: %w", err)
153155
}
154-
targets = append(targets, kmodTarget)
156+
if err == nil {
157+
targets = append(targets, kmodTarget)
158+
}
155159
}
156160
}
157161

0 commit comments

Comments
 (0)