Граф коммитов

35 Коммитов

Автор SHA1 Сообщение Дата
D. Michael Agun a41953dc62
remove --no-verify option from bpf2c and tests using it (#3673)
* 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>
2024-09-14 00:45:03 +00:00
Anurag Saxena ffb3638259
Implement `implicit_context` for helper functions. (#3656)
* backup

* backup

* fix build issues

* fix build

* fix analysis failures, fix tests

* seperate out sample for implicit context

* backup

* add ctx as last argument

* fix hash

* block implicit context for jit and interpret

* stabilize tests

* tail call fast path

* add check to reject change in context_header support

* enable implicit context for jit and interpret

* fix

* fix build

* fix analysis build

* update version, update expected files

* fix test failures

* fix test failures

* fix tests

* cleanup

* cleanup

* more cleanup

* enable performance tests

* enable performance tests

* remove tail_call changes

* remove tail_call changes

* remove tail_call changes

* remove tail_call changes

* fix analysis error

* update documentation

* code cleanup

* fix bad merge

* fix test case

* cr comments

* update expected files

* cr comments
2024-07-19 17:12:08 +00:00
D. Michael Agun 2efce152dc
Set empty program name to hash of instructions (#3493)
* 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>
2024-07-02 14:47:03 +00:00
Dave Thaler 840269a9ec
Add support for multiple programs per section (#3557)
* 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>
2024-05-29 15:30:20 +00:00
Alan Jowett aed27b488b
Add option to control the level of verbosity emitted by verifier. (#3570)
* 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>
2024-05-23 14:02:34 +00:00
Dave Thaler d096b21ac5
Update copyright to be eBPF for Windows contributors (#3508)
* 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>
2024-05-04 19:55:56 +00:00
Shankar Seal 73647f801b
Reallocate packet (#3344)
* reallocate_packet.

* PR Feedback.
2024-04-04 00:49:27 +00:00
Shankar Seal fc973542c9
extension_header (#3326)
* 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
2024-03-30 17:27:09 +00:00
Shankar Seal 66087c57c8
Revert "Helper reallocate packet (#3110)" (#3263)
This reverts commit 13eed744fe.
2024-02-15 02:06:29 +00:00
Shankar Seal 13eed744fe
Helper reallocate packet (#3110)
* add reallocate_packet flag to helper prototype struct.

* PR Feedback.

* fix.

* export reallocate_packet flag.
2023-12-11 17:54:34 +00:00
Alan Jowett 66588bdc27
Remove check that prevents fuzzing below minimum size (#2849)
* Remove check that prevents fuzzing below minimum size

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* WIP

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Cleanup handling of request lengths in _ebpf_core_protocol_program_test_run

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Update libs/execution_context/ebpf_core.c

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Fix break

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Enable warning 4062

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Remove overactive assert

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 <dthaler@microsoft.com>
2023-09-20 19:31:54 +00:00
Anurag Saxena 88b6f67e79
Fix program info hash algorithm (#2829)
* backup

* backup2

* fix

* fix

* fix

* fix

* fix

* code cleanup

* revert expected files

* remove regression test

* code cleanup

* remove dead code

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* fix build

---------

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-09-11 22:23:02 +00:00
Alan Jowett 1955692077
Add option to write bpf2c output directly to file (#2570)
* Add option to write bpf2c output directly to file

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>
2023-06-22 03:23:07 +00:00
Anthony Nandaa 1210a5553e
fix: minor typo in bpf2c.exe help text (#2485)
fixes #1905
2023-05-19 15:56:24 +00:00
Sharmi e6f96cc3e1
Remove eBPF for Windows hard-coded dependency on SHA256 (#2252)
* Initial commit

* Initial commit

* Initial commit-2

* Implement correct utf8 to unicode handling

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Removed changes in ebpf_api files to addres PR comment

* Added test case

* Update libs/platform/ebpf_platform.h

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Update libs/platform/ebpf_platform.h

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Update tools/bpf2c/bpf_code_generator.cpp

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* Addressed PR comments

---------

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2023-04-20 17:51:40 +00:00
Dave Thaler 3d626ff9c1
Clean up order of includes (#2015)
* 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>
2023-02-07 18:32:19 +00:00
Alan Jowett eced450508
Regenerate and checkin corpus files (#1872)
* Regenerate and checkin corpus files

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>
2023-01-24 18:29:10 +00:00
Anurag Saxena 8cb62b3fd7
Support for multiple implementations of global helper functions (#1761)
* fix

* add native test

* cleanup

* CR comments

* update expected files

* fix

* cr comments
2022-12-31 10:56:28 -07:00
Alan Jowett 3840b31fc0
Check program_info hash during attach to provider (#1760)
* Check program_info hash during attach to provider

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-12-19 19:22:41 +00:00
Alan Jowett f93f0d58ee
Include hash of program information in metadata (#1376)
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 <dthaler@microsoft.com>
2022-09-20 15:58:38 -07:00
saxena-anurag 4ad167dbbd
add --type option to bpf2c tool (#1283)
* add --type option to bpf2c tool

* fix test

* fix failing test, CR comments

* add negative test

* negative test
2022-07-13 14:24:32 -07:00
saxena-anurag 1160f7914e
Registry changes for program and section data. (#1192)
* fix

* backup

* fix backup

* msbuild compiling

* fix release build

* fixes

* cmake build fix

* fix cmake build

* fix analyse build

* fix

Signed-off-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>

* fix expected output

* add pre step for tests

* add pre step for tests

* add -s option, revert this later

* Revert "add -s option, revert this later"

This reverts commit 1f42d100e4.

* code cleanup

Signed-off-by: Anurag Saxena <anusa@microsoft.com>

* rename driver_registry_helper.h

* delete bpf_structs.h

* fix

* hardcode HKLM

* code cleanup

* fix

* backup

* fix backup

* msbuild compiling

* fix release build

* fixes

* cmake build fix

* fix cmake build

* fix analyse build

* fix

Signed-off-by: Anurag Saxena <43585259+saxena-anurag@users.noreply.github.com>

* add pre step for tests

* add pre step for tests

* add -s option, revert this later

* Revert "add -s option, revert this later"

This reverts commit 1f42d100e4.

* code cleanup

Signed-off-by: Anurag Saxena <anusa@microsoft.com>

* rename driver_registry_helper.h

* delete bpf_structs.h

* fix

* hardcode HKLM

* code cleanup

* fix build break

* fix build break, enable warning

* fix bad merge

* cleanup

* fix

* fix tests

* add tests, make ebpf_store_helper platform agnostic

* fixes, cleanup, common code for store APIs

* fix cmake build, driver tests

* cleanup

* code cleanup

* cr comments

* code cleanup

* cleanup

* bugfix

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* fix build break

* move UM read store APIs to a different file

* cr comments

* cr comments

* cr comments

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-06-30 16:53:03 -07:00
Alan Jowett 1782724071
Build ELF parse at compile time using EverParse (#1219)
* Build ELF parse at compile time using EverParse

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix build

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2022-06-22 16:24:02 -06:00
Alan Jowett 2560f4bbd8
Mark unsafe strings via unsafe_string class (#1214)
* Mark unsafe strings via unsafe_string class

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Cleanup string handling

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Update expected output in tests

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Build break

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-06-15 13:52:55 -07:00
saxena-anurag 96226a7db9
Change default program type to EBPF_PROGRAM_TYPE_UNSPECIFIED (#1173)
* fixes

* update cmakelists

* fix bpf2c tests

* fix cilium tests

* add tests

* update bpf2c issue number

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* fix

* fix

* fix

* cr comments

* fix build break

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2022-06-15 09:59:39 -06:00
Alan Jowett e6c68671b2
Fix driver verifier failure from zero size allocation (#1116)
* Fix driver verifier failure from zero size allocation

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix assert when duplicating empty UTF8 string

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Add test coverage - empty ELF file

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Add test coverage - empty ELF file

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix driver verifier failure from zero size allocation

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2022-05-19 13:53:41 -06:00
Alan Jowett d835854796
Add tests for bpf2c CLI interface (#1062)
* Add tests for bpf2c CLI interface

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix parsing

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
2022-05-05 16:24:58 -06:00
Alan Jowett b262f97825
Add SHA256 hash of ELF file when generating native binary (#1047)
* Add SHA256 hash of ELF file when generating native binary

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix CXX17 deprecation warnings

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix build

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Add CXXFLAGS

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Move CXX17 suppresion to top-level

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix builds

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Update expected bpf2c output

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Downgrade to LLVM 11 for bpf2c tests

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Revert clang11 in test

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Build sample ELF's with LLVM11

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Additional test cases

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-05-03 07:40:42 -07:00
Alan Jowett 17379737cf
Add all program types to get_program_type_info in offline mode (#972)
* Encode all program info types

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Expand hard coded program types and helper functions

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix tail_call_map verification failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix tail_call_map verification failure

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-04-18 17:41:01 -06:00
Alan Jowett 05c92adeba
Call ebpf_verifier prior to code gen (#961)
* Call ebpf_verifier prior to code gen

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Resovle failures after merge

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Revert rollback of catch2

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-18 12:52:55 -06:00
Alan Jowett 5359c08cf1
Switch bpf2c to use the BTF parser in ebpf-verifier (#941)
* Switch to ebpf-verifier's BTF parser

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Unify BTF parsers

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Unify BTF parsers

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Add tests for bpf2c code gen

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Revert changes to ebpf-for-windows.sln

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Canonicalize paths in output

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Generate ELF with llvm 13.0.0 and PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix copyright header

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Fix release build of bpf2c_tests

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

* Update expected output

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-04-13 11:17:48 -06:00
saxena-anurag 3470d6d7b7
EC and API changes to load generated BPF driver (#811)
* initial_commit

* fix build

* fix build

* fix build break due to merge

* debug build

* api changes, other changes

* bpf2c change to enmit program type, other fixes

* hydrate UM ebpf_object, other fixes

* remove logic to disable programs

* fixes

* fix sal

* build break

* build break

* fix sal errors

* fixes

* fix bpf2c_tests failure

* unload driver when program ref count becomes 0, other minor fixes

* fixes

* tail_call fixes, add test cases, other fixes

* build break

* build break

* code cleanup

* fix bad merge

* code cleanup

* code cleanup

* cleanup

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* address cr comments

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* add tracing in ebpfcore, other fixes

* tracing

* add section for each map in sample

* do not delete the native service

* fix bad merge

* remove code to delete service, other fixes

* cr comments

* bpf2c should read and populate all the maps in ELF file

* add test case for creating map-in-map from native driver

* Apply suggestions from code review

Co-authored-by: Dave Thaler <dthaler@microsoft.com>

* cr comments

* add tracing for api code changes

* rename epbf_native_t to ebpf_native_module_t

* fix bad merge

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-01 12:52:04 -07:00
saxena-anurag 69fd71f6f3
bpf2c should read and populate all the maps in ELF file (#865) 2022-04-01 10:37:55 -07:00
Alan Jowett aa87ee0ce2
Emit either bare code, sys, or dll (#769)
* Emit either bare code, sys, or dll

Resolve #767
2022-02-24 11:18:28 -07:00
Alan Jowett 430e575f1a
Add tool to generate C code from eBPF byte code in ELF file (#757)
Add bpf2, a tool to generate C programs from eBPF instructions in an ELF file.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-02-15 17:44:23 -07:00