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

Fix bpf obj get() behavior. #3238

Merged
merged 6 commits into from
Feb 7, 2024

Conversation

gtrevi
Copy link
Collaborator

@gtrevi gtrevi commented Feb 5, 2024

Fixes #3234

Description

Fixes the behavior of bpf_obj_get() to comply with the official specs: https://docs.kernel.org/userspace-api/ebpf/syscall.html

Testing

CI/CD

Documentation

n.a.

Installation

n.a.

libs/api/ebpf_api.cpp Outdated Show resolved Hide resolved
tests/unit/libbpf_test.cpp Outdated Show resolved Hide resolved
@gtrevi gtrevi requested a review from dthaler February 6, 2024 23:07
}

ebpf_assert(reply.header.id == ebpf_operation_id_t::EBPF_OPERATION_GET_PINNED_OBJECT);

ebpf_handle_t handle = reply.handle;
fd_t fd = _create_file_descriptor_for_handle(handle);
if (fd == ebpf_fd_invalid) {
*fd = _create_file_descriptor_for_handle(handle);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe _open_osfhandle sets errno. Hence you could update the _create_file_descriptor_for_handle() prototype to return the EBPF error rather than simply assuming it's EBPF_NO_MEMORY.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For coherence, I preserved the same behavior for all _create_file_descriptor_for_handle calls across the rest of the code, all returning EBPF_NO_MEMORY.

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=msvc-170, but was not able to find if _open_osfhandle() sets errno.

If _open_osfhandle() does set errno, maybe we can file an issue to fix it all the places?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. libuv/libuv#1420 reported that back in 2017, it didn't.

@gtrevi gtrevi requested a review from dthaler February 6, 2024 23:29
@gtrevi gtrevi added this pull request to the merge queue Feb 7, 2024
Merged via the queue into microsoft:main with commit b6bf2bb Feb 7, 2024
76 checks passed
@gtrevi gtrevi deleted the gtrevi/fix-bpf_obj_get()-behavior branch February 7, 2024 03:54
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.

bpf_obj_get() should set correct errno
4 participants