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

libbpf-rs: handle maps that were autocreate(false) #637

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

eyakubovich
Copy link
Contributor

If map auto creation was disabled, the Object would fail to load since the map's underlying fd will be -1.

This checks the if the map autocreate flag was disabled and skips creating a Map for it.

@danielocfb
Copy link
Collaborator

Hi @eyakubovich, thanks for the pull request! Would you be able to create a test case that illustrates the issue, please?

If map auto creation was disabled, the Object would fail
to load since the map's underlying fd will be -1.

This checks the if the map autocreate flag was disabled
and skips creating a Map for it.

Signed-off-by: Eugene Yakubovich <eyakubovich@gmail.com>
@eyakubovich
Copy link
Contributor Author

@danielocfb certainly. Added test_sudo_map_autocreate_disable. With the test but without the patch:

failures:

---- test_sudo_map_autocreate_disable stdout ----
libbpf: loading /home/eyakubovich/libbpf-rs/libbpf-rs/tests/bin/map_auto_pin.bpf.o
libbpf: elf: section(3) license, size 4, link 0, flags 3, type=1
libbpf: license of /home/eyakubovich/libbpf-rs/libbpf-rs/tests/bin/map_auto_pin.bpf.o is GPL
libbpf: elf: section(4) .maps, size 40, link 0, flags 3, type=1
libbpf: elf: section(9) .BTF, size 431, link 0, flags 0, type=1
libbpf: elf: section(13) .symtab, size 456, link 1, flags 0, type=2
libbpf: looking for externs among 19 symbols...
libbpf: collected 0 externs total
libbpf: map 'auto_pin_map': at sec_idx 4, offset 0.
libbpf: map 'auto_pin_map': found type = 1.
libbpf: map 'auto_pin_map': found key_size = 4.
libbpf: map 'auto_pin_map': found value_size = 4.
libbpf: map 'auto_pin_map': found max_entries = 1.
libbpf: map 'auto_pin_map': found pinning = 1.
libbpf: map 'auto_pin_map': skipped auto-creating...
thread 'test_sudo_map_autocreate_disable' panicked at libbpf-rs/tests/test.rs:1654:10:
failed to load object: Error: Operation not permitted (os error 1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

N.B. "Operation not permitted" happens because the fd is initialized to -1 and EPERM on Linux is 1. The code misinterprets the initialized FD for an error.

Copy link
Collaborator

@danielocfb danielocfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the fix!

@danielocfb danielocfb merged commit a28a805 into libbpf:master Jan 2, 2024
10 checks passed
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 this pull request may close these issues.

2 participants