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

60 Коммитов

Автор SHA1 Сообщение Дата
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 0b293ad804
Fix code analysis annotations for In and In_opt parameters by adding const where appropriate or changing to Inout where appropriate. (#1749)
* 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>
2022-12-15 15:58:33 -08:00
Dave Thaler 76f8191a80
Cleanup (#1737)
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>
2022-12-12 17:56:51 +00:00
Gianni Trevisiol 99b7ece81f
Visual Studio 2022 porting (#1521)
* Draft

* wip - full build

* wip

* Docs & scripts update

* revert test

* Updates to overall GettingStarted.md guide.

* Updated CI/CD scripts

* Update ebpf-verifier cache key

* Fix #1513. Next action forwarded to #1563.

* Bump up epbfverifier to 05bca47

* Fix CRT path.

* Disable sanitizing

* fix cmake build

* Removed unsupported x86 and ARM configurations.

* Test address sanitizer off

* wip -full build w/asan

* asan enabled on ci/cd

* update wdk version to 22621

* wip - full build

* add mock asan

* Update CL param

* wip - proj sync

* wip - ltcg

* wip - driver settings

* wip-build props

* wip - asan opts

* wip-plat asan

* wip-asan

* wip

* wip

* wip-debug

* Branch resync

* Mitigate compiler OOM.

* remove asan mock

* doc update

* doc update

* Removed commented code.

* Added comments for pragma-s
2022-12-08 20:06:57 -07:00
Anurag Saxena ed291b80c9
Return module handle on native module load (#1547)
* 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>
2022-11-29 23:36:58 +00:00
Alan Jowett 850f6d27f6
Annotate execution context API's with _Must_inspect_result_ (#1568)
* Annotate execution context API's with _Must_inspect_result_

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

* PR feedback

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

* Fix rebase

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

* Code analysis failure

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

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-11-14 09:40:21 -08:00
Alan Jowett e7302835b1
Annotate platform API's with _Must_inspect_result_ (#1564)
* Annotate platform API's with _Must_inspect_result_

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

* PR feedback

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>

* Fix up rebase

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

* Fix rebase failure

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

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-11-11 06:44:20 +00:00
Dave Thaler bdd4df8c58
Fuzz test netebpfext helper(s) (#1467)
* Use netebpfext_user in fuzz testing

Address the helper function part of #1325

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix winsock inclusion issues

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix nmr implementation

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update WDK path for more projects

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Disable ubpf warnings

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Cleanup

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix unit tests

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Make build install execution context fuzzer corpus

Filed #1505 to improve this

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix libfuzz harness

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix MBL use by core helper fuzzer

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix cmake build

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix user-mode NMR locking issue

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Extra debug statements

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Cleanup

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix bad merge

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-11-08 09:31:04 +00:00
Alan Jowett 65c4418394
Add ebpf_assert_success and always evaluate ebpf_assert values (#1571)
* Add ebpf_assert_success and always evaluate ebpf_assert values

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

* PR feedback

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

* PR feedback

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

* PR feedback

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-11-07 10:40:39 -07:00
Alan Jowett 03a6c075f9
Startup failures under low memory (#1504)
* Startup failures under low memory

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

* More low memory faillures

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

* Additional low-memory failures

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

* PR feedback

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

* Additional fix

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

* PR feedback

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

* PR feedback

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

* PR feedback

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>
2022-10-27 11:00:52 -06:00
Dave Thaler 568e8f0bdf
Add ability to enumerate maps associated with a program (#1395)
* Add map ids test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Enumerate maps associated with a program

Fixes #1339

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Initialize info before calling

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Update bpftool

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Make "netsh show prog l=v" show map ids for program

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Return EFAULT if map_ids is not a valid pointer

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix warning

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* More test fixes

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Add more checks in the socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix socket test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix netsh

Also fix GettingStarted.md and a missing space in the logs
that were found while testing this fix.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Set map_ids on output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-09-30 12:12:12 -07:00
Dave Thaler 26506f9a67
Clean up ebpf_program.c (#1302)
* Clean up ebpf_program.c

Fixes #339

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix analysis warning

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-07-18 18:07:53 -06:00
saxena-anurag 02f4bf016f
Clean up hard coded program type in EC (#1294)
* fix

* update documentation

* add bpf_obj_get_info_by_fd tests for cgroup_sock_addr

* fix

* cr comment
2022-07-15 13:48:45 -07:00
Dave Thaler 7cd7a05e16
Test helper's _net_ebpf_xdp_adjust_head shouldn't permit unbounded memory allocations (#1229)
* Add SAL

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Test helper's _net_ebpf_xdp_adjust_head shouldn't permit unbounded memory allocations

This bug only affected the tests, not the actual runtime.

Also fix some annotations found while debugging this

Fixes #1218

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-06-17 07:33:25 -07:00
Dave Thaler ee166b5717
Increase instruction count limit (#1152)
* Increase bound on instruction count

And align more with other platforms

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix compiler error

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2022-05-31 16:02:05 -07:00
Alan Jowett 9fdd90adb3
Adding negative tests for ebpf_core.c (#1132)
* Adding negative tests for ebpf_core.c
Fixed bugs in ebpf_core.c around handling bad data.
Fixed incorrect helper function numbering for bpf_ktime_get_ns.
Canonacalizes names of protocol structs and handlers.
Simply protocol dispatch table and remove redundancy.
Add the ability to unregister for async notification (for failure path).
Remove redundant checks (internal calls with SAL annotations).

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>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2022-05-26 14:06:02 -07: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
Shankar Seal ecea57b4d8
Change extensions npiid (#841)
* remove dependabot from the fork.

* change extension provider NPI IDs.

* PR feedback.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-03-28 11:26:19 -07:00
Shankar Seal a8e3a30767
Support attaching XDP program per NIC. (#803)
* Support attaching XDP program per NIC.

* PR Feedback.

* fix bug.

* PR Feedback.
2022-03-14 15:16:11 -07:00
saxena-anurag 2384d6c123
rename ebpf_object to ebpf_core_object (#793) 2022-03-07 09:07:10 -08:00
Alan Jowett 9890a6bf66
Add test to trigger division by zero handler (#791)
* Add test to trigger division by zero handler

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

* Fix bugcheck in interpreter on division by zero

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

* PR feedback

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-03-03 14:30:01 -07:00
Alan Jowett bd2aa504e1
Refactor ebpf_provider_load/ebpf_extension_load and move generation of module_id to caller (#773)
* Move generation of module_id into caller of ebpf platform NMR wrapper

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2022-02-28 09:09:33 -07:00
Alan Jowett d98a296d42
Add option EBPF_JIT_ALWAYS_ON to permit building EC with no interpreter (#742)
* Add option EBPF_JIT_ALWAYS_ON to permit building EC with no interpreter

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

* Add documentation on using compile time options

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

* Set EBPF_JIT_ALWAYS_ON for release builds

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

* Tests should expect interpret to fail if EBPF_JIT_ALWAYS_ON is defined

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

* Rename EBPF_JIT_ALWAYS_ON to CONFIG_BPF_JIT_ALWAYS_ON

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

* Tests should expect interpret to fail if EBPF_JIT_ALWAYS_ON is defined

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

* Update docs/GettingStarted.md

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

* Load returns EBPF_PROGRAM_LOAD_FAILED

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

* Split up load into individual test cases

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

* Program load fails with EBPF_PROGRAM_LOAD_FAILED

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

* Skip tests that depend on interpret mode when it's disabled

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

* PR feedback

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-02-04 10:41:52 -07:00
Alan Jowett f3a10a1b0e
Update external/ubpf to latest (#650)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-03 10:24:54 -06:00
Alan Jowett 260a8d77dc
Instrument eBPF for Windows platform layer (#647)
* Instrument eBPF Core with tracing

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-11-03 09:33:40 -06:00
Dave Thaler 80c953280e
Add libbpf bpf_prog_bind_map() API (#611)
* Add libbpf bpf_prog_bind_map() API

Fixes #379

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix SAL annotation

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Fix leak

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Make program lock protect the set of maps associated with the program

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
2021-09-30 11:43:06 -06:00
Dave Thaler 20d7a6565e
Add more libbpf APIs needed by bpftool (#576)
* Add more libbpf APIs needed by bpftool

* Add missing export for existing bpf_map__name API
* Add bpf_object__load
* Add bpf_object__load_xattr
* Add bpf_object__open_file
* Add bpf_object__unload() API
* Add bpf_program__get_type
* Add bpf_program__set_type
* Add bpf_program__unload() API
* Add libbpf_get_error
* Add libbpf_num_possible_cpus
* Rename BPF_MAP_TYPE_UNSPECIFIED to BPF_MAP_TYPE_UNSPEC for libbpf
  compat
* Rename BPF_PROG_TYPE_UNKNOWN to BPF_PROG_TYPE_UNSPEC for libbpf compat
* Add attach_type to bpf_link_info
* Add map_flags to bpf_map_info (but currently always 0)

Fixes #575

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-23 19:32:09 -07:00
Alan Jowett c794dc9141
Move release of maps to program release (#590)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-21 19:03:54 -07:00
Dave Thaler 956244fb72
Improve netsh show programs functionality (#548)
* Improve netsh show programs functionality

* Rename ebpf_get_next_pinned_program_name to ebpf_get_next_pinned_program_path for clarity
* Show link count and pinned path count
* Support "level=verbose" format
* Support filtering by attached and/or pinned

Fixes #188

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-17 16:41:43 -07:00
Dave Thaler aa09128ae0
Add libpf's libbpf_prog_type_by_name() API (#534)
* Add libpf's libbpf_prog_type_by_name() API

And add an ebpf_get_program_type_by_name() that returns the GUIDs
instead of ints.

This also removes the hard-coding of GUIDs or ints from the netsh
helper.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-15 12:08:18 -07:00
Dave Thaler b6a0fb84b9
Add support for libbpf bpf_obj_get_info_by_fd API (#510)
* Add support for libbpf bpf_obj_get_info_by_fd API

This is the last libbpf api needed to enable the bpftool
flow to detach an already loaded program.

The count of maps is changed from size_t to uint32_t for
consistency with libbpf and because it's not actually a size
in the sizeof() sense, it's a count in the countof() sense.

Also fix bug where map_name was never being set in the kernel

Fixes #372

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-10 21:54:07 -07:00
Dave Thaler 2349de2a46
Add object IDs (#487)
* Add object IDs

Add support for the following libbpf APIs:
* bpf_{link,map,prog}_get_fd_by_id
* bpf_{link,map,prog}_get_next_id

Addresses the main part of #396.
A subsequent PR will handle the rest of 396 which includes:
* remove "extra_value" complexity from maps

The changes in api_common.hpp and libbpf_internal.h are from PR 482 and so will go
away in a rebase once that PR is merged.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

* Address PR feedback

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-07 09:54:08 -07:00
Dave Thaler dd3f1b427c
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h.   Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.

Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on.  Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs.  In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs.  However, all of that is part of issue 351 and not this
issue.

Also removed obsolete/unused "repro.c" from tests/samples

Fixes #426

Signed-off-by: Dave Thaler <dthaler@microsoft.com>

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-01 16:30:33 -07:00
Dave Thaler f45e80d385
Add map-in-map support (#408)
* Add map-in-map support

Replace UM ebpf_map_update/delete_element with libbpf-compliant
bpf_map_update/delete_elem

This adds the basic functionality needed for #375

Not in this PR, but in a subsequent PR:
* ensure that all inner maps match the one specified by inner_map_idx,
  much like prog_types have to match in a prog_array.
* ensure that putting a prog_array in an array of maps adheres to the
  prog_array contract that any associated progs have to match the
  type of the calling program.
* read a map id not fd when UM reads the value (will be done together
  with issue #396 since also affects prog_arrays)

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-23 18:46:24 -07:00
Alan Jowett 2035ef7366
Add support for stack unwind on success. (#367)
Signed-off-by: Alan Jowett alanjo@microsoft.com
2021-08-23 17:24:22 -06:00
Shankar Seal 5519c26f5b
Register program type specific helper functions to uBPF in interpreted mode (#402)
* Register program type specific helper functions to uBPF in interpreted mode.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-23 12:24:45 -07:00
Alan Jowett 6ac7be59a4
ebpf_program_t.links should be initialized (#395)
* Fix issue #394

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-20 11:04:32 -07:00
Dave Thaler 7c12adb067
Prevent mismatched program types in PROG_ARRAY maps (#374)
* Prevent mismatched program types in PROG_ARRAY maps

* Each prog array map has a natural progtype, determined when
  asociating it from a program, or when adding the first program
  to it, if not associated with any program.
* Trying to add a program with mismatching type will fail
* Added libbpf bpf_create_map() API
* Fixed error returns from several libbpf APIs to be negative
* For efficiency, ebpf_program_get_properties now returns a
  pointer rather than copying the data inside the execution
  context, and is renamed to ebpf_program_get_parameters()
  to match what its return type always was.
* Fixed a bug in map size calculation that resulted in a huge
  amount of memory being allocated
* Updated return type of bpf_tail_call to the value meant
  to signal stack unwind needed

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-11 12:17:10 -07:00
saxena-anurag 014ee34392
Add eBPF UM APIs (#368)
* parse map names from elf file
* add apis, change test code

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-10 17:04:07 -07:00
Shankar Seal be67121fda
Test Extension Part 2 (#361)
* Test Extension Part 2

* rename test extension to sample extension and update Getting-started doc.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-07 14:19:00 -07:00
Alan Jowett 0fee94598b
Pull latest ubpf (#360)
Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-06 15:35:36 -07:00
Dave Thaler 2617349903
Remove duplicate public APIs where standard libbpf APIs exist (#356)
* Remove duplicate public APIs where standard libbpf APIs exist

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-03 17:25:50 -07:00
saxena-anurag 14248601d3
Add DETACH operation to detach a program from a hook. (#352)
* add UNLINK operation

* Some fixes:

1. Added attach_lock to synchronize multiple detach calls on same link object.
2. ebpf_extension_unload() should be called from ebpf_link_detach_program()
3. Changed return type of ebpf_program_get_properties to void.

* Update libs/execution_context/ebpf_program.c

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-07-30 17:17:16 -07:00
Shankar Seal 18456999b7
move map helper function prototypes to EC (#337)
* move map helper function prototypes to EC
* replace 'generic' by 'general'

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-07-22 15:31:01 -07:00
Dave Thaler 4d0ac1bd4d
Replace "information" with "info" for consistency (#331)
Previously some places had "info" and some had "information".
Both appear in dictionaries, so guidance to avoid abbreviations does not apply.

Fixes #314

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-07-07 11:16:35 -07:00
Alan Jowett 7870921e02
Additional analysis fixes (#315)
* Fix C26110,C28023,C28193,C6001,C6031,C6054
* Fix C6101

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-06-29 15:51:41 -06:00
Shankar Seal a93f4ba714
program information serialization (#302)
* program information serialization.

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-06-28 16:47:34 -07:00
Dave Thaler dc157726da
Add some more SAL annotations and clean up some code analysis warnings (#277)
* Make a couple of `_In_` arguments be const
* Add `_opt_` to a number of arguments that can be NULL
* Add SAL annotation to a few more APIs that were missing it
* Remove annotations like
  `_Pre_readable_byte_size_(hash_table->key_size)` since they just give
  code analysis warnings such as:
  ```
  c:\git\dthaler\ebpf-for-windows\libs\platform\ebpf_platform.h(445):
  warning C28230: The type of '_Param_(1)' has no member 'key_size'.
  c:\git\dthaler\ebpf-for-windows\libs\platform\ebpf_platform.h(445):
  warning C28285: For function 'ebpf_hash_table_delete' '_Param_(2)'
  syntax error in
  'SAL_readableTo(byteCount(__formal(0,hash_table)->key_size))' near
  'key_size))'.
  ```

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-16 13:27:22 -07:00
Alan Jowett 9e8b88a41a
Switch to approved license header format (#268)
* Switch to approved license header format

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-10 12:02:00 -07:00