Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic when handling libbpf_tristate value #1595

Open
xixiliguo opened this issue Oct 22, 2024 · 0 comments
Open

panic when handling libbpf_tristate value #1595

xixiliguo opened this issue Oct 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@xixiliguo
Copy link

Describe the bug

When load bpf object file which include libbpf_tristate logic, application will panic.

internal.NativeEndian.PutUint64(data, uint64(tri))

enum libbpf_tristate should be 32bit in c, so we should change to internal.NativeEndian.PutUint32(data, uint32(tri))

panic: runtime error: index out of range [7] with length 4

goroutine 1 [running]:
encoding/binary.littleEndian.PutUint64({}, {0xc000012938?, 0x562a80?, 0xc000169a29?}, 0x700000000000013?)
        /usr/local/go/src/encoding/binary/binary.go:115 +0x29
github.com/cilium/ebpf/internal/kconfig.putValueTri({0xc000012938?, 0xc000166000?, 0x0?}, {0x5c6728?, 0xc000166000?}, {0x6a3ee8?, 0xc000136240?})
        /root/project/ebpf/internal/kconfig/kconfig.go:160 +0xf5
github.com/cilium/ebpf/internal/kconfig.PutValue({0xc000012938, 0x4, 0x4}, {0x5c6728?, 0xc000166000?}, {0x6a3ee8, 0x1})
        /root/project/ebpf/internal/kconfig/kconfig.go:105 +0x85
github.com/cilium/ebpf.resolveKconfig(0xc00012d980)
        /root/project/ebpf/collection.go:649 +0xa25
github.com/cilium/ebpf.resolveKconfigReferences({0xc0001002d0, 0x3, 0x3})
        /root/project/ebpf/linker.go:427 +0x125
github.com/cilium/ebpf.newProgramWithOptions(0xc0001636d0, {0x10b2c0?, 0xc0?, 0x0?, 0x0?})
        /root/project/ebpf/prog.go:334 +0x9c5
github.com/cilium/ebpf.(*collectionLoader).loadProgram(0xc00007a160, {0x54a8bb, 0xf})
        /root/project/ebpf/collection.go:504 +0x3fc
github.com/cilium/ebpf.(*CollectionSpec).LoadAndAssign.func1({0x5c7ee0, 0x579a80}, {0x54a8bb, 0xf})
        /root/project/ebpf/collection.go:268 +0x1fa
github.com/cilium/ebpf.assignValues({0x557e20, 0xc000014460}, 0xc000163c68)
        /root/project/ebpf/collection.go:884 +0x3f3
github.com/cilium/ebpf.(*CollectionSpec).LoadAndAssign(0xc00010b440, {0x557e20, 0xc000014460}, 0x40bf01?)
        /root/project/ebpf/collection.go:280 +0x196
main.loadBpfObjects({0x557e20, 0xc000014460}, 0x0)
        /root/project/ebpf/examples/test/bpf_bpfel.go:41 +0x4a
main.main()
        /root/project/ebpf/examples/test/main.go:21 +0x45
exit status 2

How to reproduce

ebpf code

#include "bpf_endian.h"
#include "common.h"

char __license[] SEC("license") = "Dual MIT/GPL";


extern  enum libbpf_tristate CONFIG_VIRTIO_NET __kconfig;


SEC("kprobe")
int kprob_prog_func(struct xdp_md *ctx) {
	return CONFIG_VIRTIO_NET;
}

Version information

v0.16.0

@xixiliguo xixiliguo added the bug Something isn't working label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant