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

Remove JIT and interpreter code from NativeOnly builds #2475

Merged
merged 8 commits into from
Jun 7, 2023

Conversation

dthaler
Copy link
Collaborator

@dthaler dthaler commented May 16, 2023

Description

Remove JIT and interpreter code from NativeOnly builds

Fixes #2030 (security cleanup)
Fixes #2488 (bug)

Also fixes version number typo in GettingStarted.md

Testing

Updated CI/CD

Note that issue #2281 only updated kernel tests to use sys files, it did not update the user-mode tests in tests/unit/libbpf_test.cpp and tests/end_to_end/end_to_end.cpp, so in this PR the relevant ones are commented out. Issue #1121 covers updating the relevant ones to use dlls, and also covers updating port_quota.exe.

Documentation

Updated docs

@dthaler dthaler marked this pull request as draft May 16, 2023 21:29
@dthaler dthaler added cleanup Affects API usability or code maintainability but not correctness or applicability security Related to security hardening labels May 16, 2023
@dthaler dthaler force-pushed the native-only branch 7 times, most recently from 88396ec to f7a53a1 Compare May 19, 2023 17:25
@dthaler dthaler added bug Something isn't working and removed security Related to security hardening labels May 19, 2023
@dthaler dthaler force-pushed the native-only branch 2 times, most recently from 5fc1ceb to c5d50c5 Compare May 19, 2023 18:16
@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #2475 (f981580) into main (d6bcf19) will decrease coverage by 0.03%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #2475      +/-   ##
==========================================
- Coverage   83.99%   83.96%   -0.03%     
==========================================
  Files         157      157              
  Lines       29116    29119       +3     
==========================================
- Hits        24456    24450       -6     
- Misses       4660     4669       +9     
Impacted Files Coverage Δ
libs/execution_context/ebpf_native.c 91.60% <ø> (ø)
...ution_context/unit/execution_context_unit_test.cpp 98.88% <ø> (ø)
libs/thunk/mock/mock.cpp 100.00% <ø> (ø)
tests/bpf2c_tests/raw_bpf.cpp 96.14% <ø> (ø)
tests/end_to_end/end_to_end.cpp 97.71% <ø> (ø)
tests/sample/ext/app/sample_ext_app.cpp 98.61% <ø> (ø)
tests/unit/libbpf_test.cpp 99.94% <ø> (ø)
libs/api/libbpf_program.cpp 83.24% <33.33%> (-0.47%) ⬇️
libs/api/ebpf_api.cpp 87.49% <100.00%> (-0.05%) ⬇️
libs/execution_context/ebpf_core.c 91.83% <100.00%> (ø)
... and 1 more

... and 5 files with indirect coverage changes

@dthaler dthaler force-pushed the native-only branch 8 times, most recently from 23ed3a1 to 2ae2e07 Compare May 21, 2023 04:41
@dthaler dthaler force-pushed the native-only branch 2 times, most recently from b9a693c to 57aa29d Compare May 21, 2023 18:03
@dthaler dthaler marked this pull request as ready for review May 31, 2023 02:46
@dthaler dthaler changed the title WIP: Remove JIT and interpreter code from NativeOnly builds Remove JIT and interpreter code from NativeOnly builds May 31, 2023
@dthaler dthaler added the security Related to security hardening label May 31, 2023
Alan-Jowett
Alan-Jowett previously approved these changes May 31, 2023
@@ -25,6 +25,7 @@ bpf_load_program_xattr(const struct bpf_load_program_attr* load_attr, char* log_
return libbpf_err(-EINVAL);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why do we want to block this at API layer also if it is already blocked in ebpfcore? Anyone can modify and recompile this dll to override this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will having the checks in user mode block us to test the ebpfcore code where it fails the jit and interpret IOCTL calls for native_only case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nit: why do we want to block this at API layer also if it is already blocked in ebpfcore? Anyone can modify and recompile this dll to override this.

footprint reduction, and also changes the error return from "invalid value" to the more specific "not supported" meaning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will having the checks in user mode block us to test the ebpfcore code where it fails the jit and interpret IOCTL calls for native_only case?

The UM unit tests test that code path.

@@ -1139,6 +1158,7 @@ DECLARE_CGROUP_SOCK_ADDR_LOAD_TEST(
DECLARE_CGROUP_SOCK_ADDR_LOAD_TEST(
SAMPLE_PATH "cgroup_sock_addr", "authorize_recv_accept6", EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT);

#if !defined(CONFIG_BPF_JIT_DISABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: instead of removing these tests from native build, we could possibly use native_module_helper_t helper to get an appropriate file name (.sys or .o) based on whether JIT is enabled or disabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that's what #1121 already covers.

@@ -2528,6 +2538,7 @@ _Requires_lock_not_held_(_ebpf_state_mutex) static ebpf_result_t
EBPF_RETURN_RESULT(result);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) && !defined(CONFIG_BPF_INTERPRETER_DISABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

If JIT is enabled but INTERPRET is disabled (which is the case of Regular/Release build), do we still want to disable this API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no. I think you're saying the && should be || and I think you're right

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I meant to say that only -- that it should be || instead of &&

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -9,11 +9,17 @@

typedef enum _ebpf_operation_id
{
#if !defined(CONFIG_BPF_JIT_DISABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: removing the operation ids from the middle will cause the value of the other ids to change. So the same operation ID will have different value in native-only vs. regular build. Not sure if this can cause any issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since the IDs are not used in apps (they should be calling libbpf) it's ok to have breaking changes in my view

dthaler added 8 commits June 6, 2023 10:27
Fixes microsoft#2030
Fixes microsoft#2488

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
@dthaler dthaler added this pull request to the merge queue Jun 6, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 7, 2023
@dthaler dthaler added this pull request to the merge queue Jun 7, 2023
Merged via the queue into microsoft:main with commit 87b6520 Jun 7, 2023
@dthaler dthaler deleted the native-only branch June 7, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cleanup Affects API usability or code maintainability but not correctness or applicability security Related to security hardening
Projects
None yet
3 participants