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

43 Коммитов

Автор SHA1 Сообщение Дата
Dave Thaler f15fd232c7
Preserve ebpf_result values up through user mode APIs (#642)
* Rename win32 error code APIs for internal consistency

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

* Update error mappings

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

* Replace unstable NTSTATUS code with a documented one

STATUS_FILE_NOT_SUPPORTED does not appear in MS-ERREF and support varies
by OS version so cannot be relied on.  Replaced with
STATUS_INVALID_IMAGE_FORMAT.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-10-25 14:35:25 -07:00
Alan Jowett be119ea8b6
Add code in mock layer and driver to handle async requests (#632)
* Add logic to track asynchronous operations

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-14 14:22:35 -06:00
saxena-anurag 1bbbc41233
add auto-pinning option for maps. (#612)
* add auto-pinning option

* Apply suggestions from code review

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

* Configure custom pin_root_path using bpf_object_open_opts

* use new api for map-in-map, remove pinning restriction for inner map, remove workaround for inner map id

* code cleanup

* cr comments

* Apply suggestions from code review

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

* fix bad merge

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-10-01 09:01:39 -06:00
Dave Thaler cd77fe694b
Add libbpf bpf_create_map_in_map() API (#613)
* Add libbpf bpf_create_map_in_map() API

* bpf_create_map() now fails for outer maps.  You must use
  bpf_create_map_in_map() instead.
* Fix bug where EBPF_INVALID_FD was incorrectly converted to
  EBPF_INVALID_ARGUMENT by ioctl handling code (part of issue #595)
  One symptom of this bug was that errno was being set to EINVAL
  in a number of cases which should have been EBADF.
* Fix bug where a HASH_OF_MAPS (unlike ARRAY_OF_MAPS) wasn't enforcing
  that an inner map value had to match the inner map template.
  Refactored the code in ebpf_maps.c so the checking is in done in one
  place called by both maps, to ensure consistency.
* Fix bug in HASH_OF_MAPS where if an update failed, it would leave
  the old entry but incorrectly drop the reference it held.  It now
  preserves the reference since the entry is unchanged.
* Added test case for ARRAY_OF_MAPS created via libbpf.  Previously
  only HASH_OF_MAPS creation was tested for that path.

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

* Fix bug caught by kernel test

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-29 14:13:24 -07:00
Dave Thaler 1a17769087
Add program type and attach type to netsh output (#603)
* Add program type to netsh "show programs" output
* Add attach type to netsh "show links" output

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-28 09:45:22 -07:00
Dave Thaler 65390d8baa
Simple error code conversion fixes (#596)
Addresses part of issue #595
A more comprehensive fix is left for a separate PR.
This PR fixes some bad error messages from bpftool.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-24 10:58:57 -07: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
Shankar Seal 9d01eb45c1
Fix EbpfProgramType for sample extension. (#569)
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-20 13:00:21 -07:00
Alan Jowett 967990f700
Disable /ZI and incremental linking (#546)
* Disable /ZI and incremental linking

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-16 16:49:02 -06:00
Dave Thaler 872999db06
Add netsh capability to unpin programs (#539)
* Add netsh capability to unpin programs

* The netsh "set program id=<id> pinned=" (with no value) will now unpin a
  program from all paths
* The netsh "delete program <id>" will now unpin a program from all
  paths before and releasing any reference held by netsh itself
* Make the "attached=<string>" argument to netsh set programs work
  with a section name like string
* Add libbpf api bpf_obj_get()
* Add ebpf_get_next_pinned_program_name() API to enumerate pinned
  programs

Fixes #190 #373

This is required for #188 which will update the "show programs"
and also add an option to "add program" to pin all programs rather
than just the first one in a file, like bpftool has such an option.

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

* Update mock netsh behavior since PR 540 changed the underlying requirements

PreprocessCommand now correctly matches tags so you can specify a later
optional tag without having to specify earlier optional tags

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-15 18:40:44 -07:00
Dave Thaler 12bb2e7195
Update netsh commands to use more standard libbpf apis (#527)
* Update netsh commands to use more standard libbpf apis

* Add support for libbpf bpf_obj_pin() API
* Add support for libbpf bpf_object__next() API
* Rename BPF_{PROG,ATTACH}_TYPE_UNKNOWN to ...UNSPEC for libbpf compat
* Remove now-unused handle APIs ebpf_api_load_program and
  ebpf_api_pin_object, which is part of issue #383
  * netsh set/delete program now uses the ID to identify the program,
    like bpftool does, so that it can work even if the program wasn't
    loaded from an ELF file

Fixes #191

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-14 10:59:57 -07:00
Alan Jowett f5ba5c5d7c
Use CRT library to map handles to fds (#513)
* Use CRT library to map handles to fds

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-14 09:25:56 -06:00
Alan Jowett e553150b1b
Switch from MultiThreadedDebug to MultiThreadedDebugDll (#528)
* Switch from MultiThreadedDebug to MultiThreadedDebugDll
* Pull in latest ebpf-verifier

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-09-14 08:46:01 -06: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 5f5e2c0d1f
Add bpf_link_detach and bpf_link__fd APIs (#482)
* Add bpf_link_detach and bpf_link__fd APIs

Fixes #372

Addresses leftover TODO comments referencing issue 81.

Fixes bug where errno was not being set to correct errno values

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-09-03 14:51:50 -07:00
Shankar Seal ec68058a36
Test utility helper functions. (#480)
* Test utility helper functions.

* fix build break.

* PR feedback.

* PR feedback.
2021-09-02 17:23:16 -07:00
Shankar Seal 16856deb0a
Pass program handle in GET_PROGRAM_INFO message. (#463)
* fix

* PR feedback.

* Apply suggestions from code review

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

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-08-30 20:15:09 -07:00
Dave Thaler 0a1555956e
Add map-in-map type checking (#451)
* Add map-in-map type checking

This PR enforces that all inner maps must be of the same type
as the inner map template used for verification.  Other fields
might need to match too, and if so those will be updated in
a subsequent PR once it is confirmed which fields must match.

A few pieces of this PR related to map_id are prerequisites
for issue #396 which will add IDs for programs, maps, and links.

Finally, there are multiple definitions of bpf_map, since the
version used to write eBPF programs is different from what is
stored in memory (which uses map IDs) so to avoid confusion in
code and allow the compiler to do type checking to catch some
bugs, this splits ebpf_map_definition_t into two, one for
in_memory and one for in_file (meaning in an eBPF program).
This will also allow the future PR for issue 396 to be more
understandable, but also aids clarity in some parts of this PR.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-30 19:14:08 -07:00
Alan Jowett 4be43a7ea1
Include required Clang version (#431)
* Update Getting Started to recommend current release version of Clang/LLVM

Clang-format behaves differently depending on the version of Clang installed.
Update getting started guide to recommend Clang / LLVM 10.0.0.
Update the development guide to indicate that Clang 10 or higher is required for consistent formatting.
Reformat all code using Clang 10.0.0

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-25 09:01:16 -06:00
Dave Thaler ea3765fc7c
Add tests for libbpf bpf_map_*_elem APIs (#429)
* Add tests for libbpf bpf_map_*_elem APIs

* Return correct error between EBPF_OBJECT_ALREADY_EXISTS (A program or
map is already pinned with the *same* path) vs
EBPF_ALREADY_PINNED (The program or map already pinned to a *different*
path).

* Update vs lookup elem were inconsistent in whether returning
  EBPF_KEY_NOT_FOUND vs EBPF_INVALID_ARGUMENT when passing an array
  index >= max_entries.  Made them be consistent in using
  EBPF_INVALID_ARGUMENT.

Fixes #376

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-08-24 11:33:00 -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
Dave Thaler c99a43e5e9
Revert "Remove dead code (#381)" (#401)
This reverts commit 7d779cf117.
2021-08-20 12:07:57 -07:00
Shankar Seal 7d779cf117
Remove dead code (#381)
* Remove dead code

* Address PR feedback

Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-08-13 14:56:36 -06:00
Alan Jowett 8cc5a7f5be
Add support for per-cpu hash and array maps - Part 1 (#378)
Add support for per-cpu hash and array maps

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-08-11 16:39:54 -06: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
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
Shankar Seal 266578ee63
test extension - Part 1 (#336)
* test extension
2021-07-14 14:40:34 -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
Dave Thaler 569da02a8f
Add main API reference page (#329)
Which will fill in content visible at https://microsoft.github.io/ebpf-for-windows/

Fixes #259

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
2021-07-07 10:39:59 -07: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
Alan Jowett a0801d410c
Suppress C26451 (#312)
* Suppress C26451 and related errors

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-28 16:13:29 -07:00
saxena-anurag c31547cff5
Add ebpf public APIs - #1 (#290)
* add ebpf_program_load(), few other APIs
2021-06-22 20:42:18 -07:00
Dave Thaler 2200ab915f
Merge eBPF types with the types in ebpf-verifier (#282)
Remove duplicate types:
* ebpf_helper_return_type_t
* ebpf_helper_argument_type_t
* ebpf_context_descriptor_t

https://github.com/vbpf/ebpf-verifier/pull/238 already made the
necessary changes in the PREVAIL project, which got rid of the
issue with VOID and so the 'undef VOID' workarounds are removed
in the present PR.

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-16 11:53:21 -07:00
Dave Thaler a46b00c2e3
Add VM setup scripts and docs (#281)
* Create an install script rather than having to manually do lots
  of steps
* Make Debug build use vcruntime as static libs to avoid adding
  another prerequisite on a machine before installing eBPF.  This
  isn't required for Release builds as vcruntime release DLLs
  are part of Windows, unlike vcruntime debug DLLs

Fixes #248

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-15 08:44:43 -07:00
Alan Jowett 877cb22ec0
First pass of adding SAL annotations (#253)
* First pass of adding SAL annotations

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

* Finish annotating platform

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

* Cleanup annotation to get lock tracking work correctly

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

* PR feedback and fix static analysis issues

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>

* Fix build break from merge

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-06-10 10:45:23 -06:00
Dave Thaler 6be20d7aad
Simplify names of some ebpf_result codes (#256)
* Simplify names of some ebpf_result codes

* Remove _ERROR_ for consistency
* Combine EBPF_INVALID_HANDLE and EBPF_INVALID_OBJECT
* Rename EBPF_ERROR_NOT_FOUND to EBPF_KEY_NOT_FOUND for consistency with the associated description.
* Change code that returned EBPF_ERROR_NOT_FOUND for a case other than a
key, to use a different appropriate result, so the description stays correct.

Fixes #212

Signed-off-by: Dave Thaler <dthaler@ntdev.microsoft.com>
2021-06-09 19:32:57 -07:00
Shankar Seal 27f8d49888
API to create map and enumerate all pinned maps. (#246)
* API to create map and enumerate all pinned maps.

* Apply suggestions from code review

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

* Address code review comments

* Address code review comments #2

* Address code review comments #3

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-09 09:44:24 -06:00
saxena-anurag cf2ef87325
Move program load to ebpfsvc (#245)
* remove duplicate windows_helpers.cpp, refactor

* remove commented code

* move program load to service

* cleanup commented code

* remove commented code

* cr comments

* make device handle init optional

* cr comments

* change return type of some functions

* fix

* cr comments

* cr comments, cover more error conditions in windows_error_to_ebpf_result

* cr comments

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-06-07 15:22:04 -06:00
saxena-anurag 3a8e5dd7cd
remove duplicate windows_helpers.cpp, refactor (#236)
* remove duplicate windows_helpers.cpp, refactor

* remove commented code

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-05-28 15:29:41 -07:00
Alan Jowett 4c64214af7
Change resolve_maps_in_byte_code to send handles for resolution only when needed. (#230)
* Add LLVM for code generation proposal

* Revert "Add LLVM for code generation proposal"

This reverts commit cd896afd94.

* Eliminate duplicate map resolutions

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2021-05-27 13:56:06 -07:00
saxena-anurag 4b2384479d
refactor api.lib to api.lib, common.lib, service.lib (#219)
* refactor api.lib to api.lib, common.lib, service.lib

Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2021-05-25 14:11:13 -07:00