The current implementation of bpf_obj_get doesn't follow libbpf semantics,
because it always returns -1 on error, instead of returning the negative
error number.
This is especially noticeable when trying to open a non-existant object,
which should return -ENOENT.
See caa17bdcbf/src/bpf.c (L625-L626)
* remove --no-verify option from bpf2c and tests using it
Closes#3571
* remove builds for unsafe programs in sample.vcxproj
* remove unsafe test cases from netsh_test.cpp
* remove new noverify references
* Revert deletion of netsh tests.
* Add back compilation of unsafe programs (but not bpf2c call)
* remove invalid program tests which used noverify
* remove end_to_end tests using noverify
---------
Co-authored-by: Michael Agun <danielagun@microsoft.com>
* Move C++ hashing lib from tests/libs/util/ to libs/shared/
This puts hash.cpp/hash.h in a more central location for use by other project files.
* Set empty program name to hash of instructions
ebpf_program_load_bytes now hashes the instructions and uses that for the name
instead of generating a random number.
Closes#3443
* fix signed/unsigned warning (and ensure windows helper id >= 0)
* add bcrypt.dll dependency for ebpfapi.dll
* WIP new test case for ebpf_program_load_bytes with nullptr program name
* WIP ebpf_program_load_bytes testing
* truncate SHA256 hash to 63 bytes to stay under BPF_OBJ_NAME_LEN
* remove bcrypt from release dependencies and suppress analyze warning
* PR feedback - fix comment and bpf2c include paths
---------
Co-authored-by: Michael Agun <danielagun@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
* Speedup ebpf_handle_table_terminate by avoiding acquire/release of lock
Signed-off-by: Alan Jowett (from Dev Box) <alanjo@microsoft.com>
* Add workaround for native module handle cleanup delay
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
---------
Signed-off-by: Alan Jowett (from Dev Box) <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
* Implement libbpf autoload APIs
Fixes#3555
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Suppress spurious compiler warning
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Fix test failure
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Update tests
Files with no program sections succeed loading
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Address PR comment from Anurag
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* PR feedback
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Fix test
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Prevent changing prog type of a native program
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* PR feedback
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Remove unused program_type from native load ioctl
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Update default autoload value
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* PR feedback
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Fix test
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Add check to unit_test to match api_test
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Fix api_test
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
---------
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Allow multiple programs per section
Temporarily use a fork of ebpf-verifier until
https://github.com/vbpf/ebpf-verifier/pull/642 is merged.
Per https://stackoverflow.com/questions/13147170/attribute-always-inline-failing
the __attribute__((always_inline)) doesn't do anything unless you also
have the "inline" keyword.
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Update verifier to latest
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Address comment from Alan
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Address API compat comment from Anurag
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
---------
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* change ebpf_extension_header_t to ebpf_version_header_t
* revert to ebpf_version_header_t
* revert to ebpf_version_header_t
* update header
* update doc
* update doc
* use total_size to get the actual struct size
* Apply suggestions from code review
Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
---------
Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
* Add option to control the level of verbosity emitted by verifier.
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
* Re-order enums to make normal < informational < verbose
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
* Apply suggestions from code review
Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
* PR feedback
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
* Workaround for verifier failure #643
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
* Revert change in ebpf-service verification path
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
---------
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler1968@gmail.com>
* Update copyright to be eBPF for Windows contributors
Fixes#3507
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* Undo gratuitous formatting changes in expected files
---------
Signed-off-by: Dave Thaler <dthaler1968@gmail.com>
* extension_header
* fix logic error.
* Re-purposing the size field to act as the "minor version". Additional validation checks are added.
* PR Feedback.
* fix break due to bad merge with PR #3372
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* replace XDP guids with XDP_TEST guids
* updated missde instance
* update bpf2c
* leave xdp_hook as is
* remove extra files
* update with new XDP_TEST guid, update other tests to use sample_ext
* update some tests, update test_helper
* update fuzzer
* temporarily remove bpftool tests
* update execution context test
* build failures
* update sample ext with context_allocate and destroy
* update vm script to use xdp_test
* switch api tests to use sample program
* rename to xdp_Test
* update sample ext
* update incorrect SAL, update netsh tests
* update sample, update tests to use sample where applicable
* update tests
* fix up tests
* fix libbpf tets
* revert unnecessary changes
* remove extra prints
* add back in bpftool tests
* update to use xdp instead of xdp_test for bpftool test
* update atomic_instructions_others.o
* extra debug logs
* updated expected, update bpftool tests
* correct bpftool tests
* more debug logs
* add reg debug
* clear program info
* Attempt fix of buffer overrun
* remove debug logs, minor cleanup, set XDP guids back to their original names
* update docs with xdp_test
* fix guid usage
* CR: remove program, update comments, fix commented out tests, update bpf_program__attach_xdp
* revert changes in libbpf, as they need to use the actual XDP guids
* update comment
* update some XDP tests to use sample ext, comment out some expected failing tests
* update bpftool tests
* fix up bpf prog test run expected output, move to #if instead of comments
* fix up return code issue
* fix bpftool testes
* add some failed xdp tests, set some params to null for sample tests
* update comment
* tmp commit - move to xdp mock
* update unit tests to use mock XDP where possible
* made some samples back to XDP type
* netebpfext unit tests should use xdp_test
* CR
* Update to use latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update to latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use NonPagedPoolNx instead of NonPagedPool for netebpfext state
NonPagedPool is executable, which we don't want
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* build ebpfcore under usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Work around analysis warnings
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix installer project
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Temporarily use ubpf branch with memory fix
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* WIP
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* WIP
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Create project for files shared between ebpfapi and the ebpf runtime
Move existing files from libs/platform either to:
* libs/shared, if meant to be common between user-mode and ebpf runtime
* libs/runtime, if meant to be used by the ebpf runtime only (whether in
user or kernel mode)
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Move ebpf_tracelog.c to shared
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Create shared_user and shared_kernel projects
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* WIP
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* WIP
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Remove usersim from ebpfsvc
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update to cxplat branch of usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use cxplat_utf8_string
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Cleanup
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix build errors
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix ebpf_allocate_with_tag
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fixes
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Bug fixes
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix use of ebpf_reallocate to not pass a null pointer
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix printf tests
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix memory leaks
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Temporary change to help debug double-free in test
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update to latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix analysis warnings
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update to latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim to latest
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Change native module to use latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update nuget package
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Only call cxplat_cleanup if cxplat_initialize succeeds
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
* Revert setup_build.vcxproj change
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim to latest
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
* Update to use latest usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* build ebpfcore under usersim
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim to latest
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix compilation
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Work around analysis warnings
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix installer project
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix memory issues in libbpf implementation
Found my latest usersim code
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim to latest
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix mismatched calloc/free function in ubpf_user.c
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix mismatched alloc/free in verifier_fuzzer
The verifier_fuzzer used ebpf_allocate() but then called free()
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Temporarily use ubpf branch with memory fix
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix memory issues in ebpfsvc
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* PR feedback from Anurag
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use usersim as DLL
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Convert usersim to a DLL
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Make cmake build clear program info state like VS build does
PR #1192 updated the vcxproj file but not the corresponding CMakeLists.txt file
for export_program_info
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Pick up latest usersim fix
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix deadlock in epoch_test_stale_items test
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Don't throw exceptions in unit tests
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix single instance hook initialization in test cases
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix deadlock in performance test
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Add usersim.dll to installer files
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim library for DPC API support
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Flush queued DPCs before terminating usersim platform
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix fault injection test
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix test bugs found by fault injection
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use usersim Ke*Timer apis
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix bad uses of REQUIRE in netebpfext_unit constructors/destructors
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix mismatched initiate/terminate calls
Move Test-FaultInjection.ps1 to the usersim repo
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use REQUIRE instead of throwing exceptions from unit tests
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Don't use REQUIRE in constructors
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix memory leak bug in netebpf_ext_helper destructor
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix reference count leak in net_ebpf_extension_sock_ops_flow_established_classify
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* More usersim library cleanup
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix analyze warning
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use TraceLogging for printk
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix analysis warnings
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix deadlock in core_helper_fuzzer
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update usersim library
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix call to RpcStringFreeA
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Use usersim repo
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Remove DISPATCH test code from _preprocess_load_native_module
Per Anurag: the code was added earlier to execute the 2 paths in
native module, and it is not needed anmore IIRC, as the "DISPATCH"
code has been removed now from the native module
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Bug fixes
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Unify some APIs
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix warnings and clean up code
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* updated
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Remove JIT and interpreter code from NativeOnly builds
Fixes#2030Fixes#2488
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Try conditional project references
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Various test fixes
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Native-only fixes to deploy-ebpf.ps1
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Native-only support for setup-ebpf.ps1
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Native-only support for api_test.exe
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Add connect_redirect_tests to deploy-ebpf.ps1
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* PR feedback from Anurag
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* wrapper for tests using smart pointer
* address PR comments
* address PR comments
* update connect edirect test
* update connect redirect test
* resolve conflict
* resolve conflict
* test with connect redirect
* test with connect redirect
* change connect redirect test
* address PR comment
* rebase the changes from main
* rebase the changes from main
* Update tests/connect_redirect/connect_redirect_tests.cpp
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
* address PR comment
* modify the bpf object pointer
---------
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
* Raise STATUS_ASSERTION_FAILURE on test timeout
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Manually generated dump on test timeout
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
---------
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Add option to invoke eBPF programs in batch mode
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Fix use of uninitialized memory
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback and additional testing
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Fix code analysis failure
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Cleanup and additional test
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
---------
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
* Clean up order of includes
Fixes#1963
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update clang-format
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Clean up headers
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update sort
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* FIx various build errors
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix ordering if including a .c file
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix cmake build
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* More header cleanup
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update expected bpf2c output
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* More header fixes
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Update expected bpf2c output for custom bpf.c
The generate script does not handle this file.
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix tests
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
* Fix more expected bpf2c output
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
---------
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
* ebpf_program_t computes hash of program info on first attach
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Provider reload test
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>
* Remove REQUIRE macro from some non-top level test code
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Fix code analysis warning
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
* Fix code analysis annotations for _In_ and _In_opt_ parameters,
add const where appropriate or change to _Inout_ where appropriate.
The following regex expressions were used to find the problems:
Find _In_ or _In_opt_ that are not const and are not followed by _Post_invalid_ or _Frees_ptr_ or _Post_ptr_invalid_:
```_In_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```
```_In_opt_[ ]+(?!.*(const|_Post_invalid_|_Frees_ptr_|_Post_ptr_invalid_))```
Some of the _In_ and _In_opt_ parameters are not const due to required compatibility with the Windows API.
Pointers to functions are const by definition, so the const qualifier is not required.
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* Fix code analysis failure
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* PR feedback
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
* kernel and platform changes
* fix
* user mode changes, other fixes
* fix test failure
* change function name
* add tests
* fix failing test
* cr comments
* CR comments
* fix cmake build
* fix
* Apply suggestions from code review
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
* fix assert
* cr comments
* fix analysis failure
* fix test to avoid double close of fd
* test case fixes
* test fix
* fix unit test, analysis failure
* fix tests
* fix memory leak, possible race condition
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>