Skip to content

libbpf-rs is unable to load eBPF programs on older kernel versions #1151

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

Closed
olcarver opened this issue Apr 3, 2025 · 3 comments · Fixed by #1162
Closed

libbpf-rs is unable to load eBPF programs on older kernel versions #1151

olcarver opened this issue Apr 3, 2025 · 3 comments · Fixed by #1162

Comments

@olcarver
Copy link

olcarver commented Apr 3, 2025

Kernel version: 5.4.0-1125-aws
Distro: Ubuntu 18.04.6 LTS

After bumping our libbpf-rs version from 0.21.2->0.24.8, we ran into the following error when trying to run our program on a system running kernel 5.4

BPF map `bss` mmap pointer is NULL

The error is being thrown during the new function of the auto generated OpenXXXXMaps code in *.skel.rs. This error does not occur when we run our program but with libbpf-rs version 0.21.2.

How to reproduce:

Attempting to run the sample capable on a new EC2 instance with the same kernel/distro version yields the same error but for rodata.

$ sudo ./capable

thread 'main' panicked at /home/ssm-user/libbpf-rs/examples/capable/src/bpf/capable.skel.rs:165:26:
BPF map `rodata` mmap pointer is NULL
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@anakryiko
Copy link
Member

On old kernel that do not support memory-mapped global variable maps, libbpf will just avoid doing mmap. So libbpf-rs doesn't seem to handle this condition. Not sure what would make the most sense, I'd rather wait for Daniel (libbpf-rs maintainer) to come back to decide on best ways to handle this.

@d-e-s-o d-e-s-o marked this as a duplicate of #1155 Apr 30, 2025
@weitsochen
Copy link

Do we have any updates on this issue?

@d-e-s-o
Copy link
Collaborator

d-e-s-o commented May 5, 2025

I suspect given this behavior we may have to make each <xxx>_data field an Option, as there is no way to correctly predict in advance what will happen at runtime.

d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
Commit 27dfe16 "libbpf-cargo: Don't provide kconfig data access after "open""
worked around the fact that the kconfig data member may not be present
whenever. As it turns out, there is no guarantee that any of the data
members are available as memory mapped data: on older kernels that "do
not support memory-mapped global variable maps, libbpf will just avoid
doing mmap" [0].
Revert this special sauce work around, as that means it's basically
unnecessary now and we have to come up with a generic solution instead.

This reverts commit 27dfe16.

[0]: libbpf#1151 (comment)

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
As discussed in libbpf#1151, libbpf may not provide access to any of the data
sec members if the kernel does not support memory-mapped global variable
maps.
To that end, make them all optional.

Closes: libbpf#1151

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
As discussed in libbpf#1151, libbpf may not provide direct memory map access
to any of the BPF map members if the kernel does not support
memory-mapped global variable maps.
To that end, make them all optional.

Closes: libbpf#1151

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
As discussed in libbpf#1151, libbpf may not provide direct memory map access
to any of the BPF map members if the kernel does not support
memory-mapped global variable maps.
To that end, make them all optional.

Closes: libbpf#1151

Signed-off-by: Daniel Müller <[email protected]>
@d-e-s-o d-e-s-o linked a pull request May 5, 2025 that will close this issue
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
As discussed in libbpf#1151, libbpf may not provide direct memory map access
to any of the BPF map members if the kernel does not support
memory-mapped global variable maps.
To that end, make them all optional.

Closes: libbpf#1151

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/libbpf-rs that referenced this issue May 5, 2025
As discussed in libbpf#1151, libbpf may not provide direct memory map access
to any of the BPF map members if the kernel does not support
memory-mapped global variable maps.
To that end, make them all optional.

Closes: libbpf#1151

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit that referenced this issue May 7, 2025
Commit 27dfe16 "libbpf-cargo: Don't provide kconfig data access after "open""
worked around the fact that the kconfig data member may not be present
whenever. As it turns out, there is no guarantee that any of the data
members are available as memory mapped data: on older kernels that "do
not support memory-mapped global variable maps, libbpf will just avoid
doing mmap" [0].
Revert this special sauce work around, as that means it's basically
unnecessary now and we have to come up with a generic solution instead.

This reverts commit 27dfe16.

[0]: #1151 (comment)

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit that referenced this issue May 7, 2025
As discussed in #1151, libbpf may not provide direct memory map access
to any of the BPF map members if the kernel does not support
memory-mapped global variable maps.
To that end, make them all optional.

Closes: #1151

Signed-off-by: Daniel Müller <[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 a pull request may close this issue.

4 participants