Commit Graph

585 Commits (ae612a0a1061ea65237b62a7d9fa1f2f583dff36)

Author SHA1 Message Date
Dave Tucker db975e9778 aya: Don't store bpf_fd in MapData
This is only used in create and therefore can be passed
as a parameter.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 5ac186299b
sys: refactor btf_obj_get_info_by_fd to share code 1 year ago
Tamir Duberstein c7a19bcefb
sys: add map_ids to bpf_prog_get_info_by_fd
Allows the caller to pass a slice which the kernel will populate with
map ids used by the program.
1 year ago
Tamir Duberstein 5138c731a9
util: avoid vector allocation when parsing ksyms 1 year ago
Addison Crump ed777273b1
nuclear option: no symbol resolution in the crate 1 year ago
Dave Tucker e38e2566e3 aya, aya-obj: Implement ENUM64 fixups
This commit adds:

- A probe to see if the ENUM64 feature is supported
- Fixups for the use of signed enums, or enum64 types
  on systems where enum64 is not supported

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrés Medina 8ebf0ac327
aya: Use OwnedFd in FdLink. 1 year ago
Dave Tucker e9153792f1
Merge pull request #720 from dave-tucker/programsection-noname
aya-obj: Remove name from ProgramSection
1 year ago
Addison Crump d8709de9f2
Extract trait SymbolResolver 1 year ago
Dave Tucker cca9b8f1a7 aya-obj: Remove name from ProgramSection
The name here is never used as we get the program name from the symbol
table instead.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrew Werner 81fb4e5568 uprobe: refactor target resolution
This attempts to do fewer lossy conversions and to avoid some
allocations.
1 year ago
ajwerner de8604d011
Merge pull request #717 from ajwerner/no-libc-in-integration-tests
uprobe,integration-test: do not exercise dylib resolution in integration tests
1 year ago
Dave Tucker 77e9603976
Merge pull request #711 from dave-tucker/sleepable
Tidy up aya-bpf-macros (again)
1 year ago
Andrew Werner dcc6b84a88 programs/uprobe: extract library path resolving
The function is extracted so that a test could be written. This test is
valid on linux-gnu targets, and it doesn't need any special privileges.
This is in anticipation of removing the code that uses this functionality
(seemingly incidentally) from integration tests.
1 year ago
Tamir Duberstein 368ddf10c4
Merge pull request #712 from aya-rs/loaded-links
integration-test: remove bpftool dependency
1 year ago
Tamir Duberstein 30faa5f68f Add links iterator
This is not yet exposed in documentation, but is complete enough for use
in tests, removing the dependency on bpftool.

Updates #645.
1 year ago
Dave Tucker 71737f5576 aya: Set BPF_F_SLEEPABLE for sleepable programs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 89ef97e848
aya: preallocate the vector
This code badly needs tests :(
1 year ago
Tamir Duberstein 7bb9b7f5a5
programs: plug file descriptor leak
This leaked a file descriptor if bpf_prog_get_info_by_fd failed.
1 year ago
Tamir Duberstein b1404e9a73
sys: push error construction up 1 year ago
Tamir Duberstein a0af7e0b2f
programs: make `loaded_programs` opaque 1 year ago
Tamir Duberstein de8519a380
sys: extract common SyscallError
We currently have 4 copies of this.
1 year ago
Tamir Duberstein 4cb3ea6e8f
sys: `sys_bpf` takes mut ref
Some syscalls mutate the argument, we can't be passing an immutable
reference here.
1 year ago
Tamir Duberstein 7ee6f52a74
sys: avoid repeating BPF_BTF_LOAD dance 1 year ago
Tamir Duberstein 6f3cce75cf
test: s/assert!(.*) ==/assert_eq!\1,/
One case manually adjusted to `assert_matches!`.
1 year ago
Tamir Duberstein 0ec9afdb07
Reduce state cardinality from 4 to 2
Encode into the type system the fact that PerfLink::probe_kind and
PerfLink::event_alias are present or absent together.
1 year ago
Andrés Medina dbfba18dac aya: Return `OwnedFd` for `perf_event_open`.
This fixes a file descriptor leak when creating a link of
BPF_PERF_EVENT attach type.
1 year ago
Tamir Duberstein 868a9b00b3
Merge pull request #704 from aya-rs/better-panic
all: better panic messages
1 year ago
Tamir Duberstein 17f25a6793
all: better panic messages
Always include operands in failing assertions. Use assert_matches over
manual match + panic.
1 year ago
Tuetuopay c74813f8c5 test: add the possibility to run a test inside a network namespace
For tests that do networking operations, this allows to have a
clean-state network namespace and interfaces for each test. Mainly, this
avoids "device or resource busy" errors when reusing the loopback
interface across tests.
1 year ago
Tamir Duberstein 8961be9526
Do not escape newlines on Err(LoadError).unwrap()
Wrap verifier logs in a newtype whose `Debug` impl emits unescaped
newlines. This improves ergonomics in tests where we `Result::unwrap()`
those load errors; when these fail today they emit the errors with
newlines escaped, making them incredibly difficult to read.
1 year ago
Andrés Medina ea96c29ccb aya: Use Arc<OwnedFd> when loading BTF fd
This fixes an existing file descriptor leak when there is BTF data in
the loaded object.

To avoid lifetime issues while having minimal impact to UX the
`OwnedFd` returned from the BPF_BTF_LOAD syscall will be wrapped in an
`Arc` and shared accross the programs and maps of the loaded BPF
file.
1 year ago
Andrés Medina 683a1cf2e4 aya: Make SysResult generic on Ok variant 1 year ago
Andrés Medina c63d9904f7 Replace std::os::unix::io for std::os::fd
This is just taking https://github.com/aya-rs/aya/pull/633 to its
logical conclusion. Because `std::os::fd` was only introduced as a
module in Rust v1.66.0 I have also updated the `Cargo.toml` of the
`aya` package to reflect the true MSRV. Note that this commit is *not*
the cause for this MSRV bump, that was done by a previous commit, this
commit is just making it explicit in the `Cargo.toml`
1 year ago
Tamir Duberstein 76c78e3bf8
sys: bpf_prog_get_fd_by_id returns OwnedFd 1 year ago
Mike Rostecki 96fa08bd82 cargo: Define dependencies on the workspace level
This way we will avoid version mismatches and make differences in
features across our crates clearer.
1 year ago
Dave Tucker 764eb309b0 Clippy fixes for latest nightly
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 35ed85a87f
Handle WSL kernel version strings
Fixes #654.
1 year ago
Tamir Duberstein 961f45da37
Replace matches with assert_matches
The matches crate has been archived now that `matches!` is in std.
However `assert_matches!` is still unstable in std, and the
assert_matches crate provides a more expressive form:

```
assert_matches!(foo, Ok(bar) => {
  assert_eq!(bar, baz);
});
```
1 year ago
Tamir Duberstein 61608e6458
Merge pull request #650 from aya-rs/test-cleanup
Remove async feature; misc test cleanup
1 year ago
Tamir Duberstein 5407d4a9a1
Don't use env::tempdir
This can cause test pollution. Create a new temp directory on each run.
1 year ago
Tamir Duberstein fa91fb4f59
Remove "async" feature
This feature is equivalent to async_tokio || async_std; removing it
avoids warnings emitted during `cargo hack check --feature-powerset`
where async is selected without either of the other features.

Use cargo hack to ensure clippy runs on the powerset of features.
1 year ago
Mary 74b546827c aya: Ignore embedded BTF error if not truely required
This allows fallback to BTF manual relocation when BTF loading fail when not truely required.
1 year ago
Alessandro Decina 242d8c33c4 Fix build 1 year ago
Alessandro Decina eb60d65613
Merge pull request #520 from astoycos/unsupported-map
Add Unsupported Map type
1 year ago
Andrew Stoycos 80b371f6d1
add FdLink documentation and example
Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Andrew Stoycos 58895db9b4
Implement FdLink conversions
Implement TryFrom functions to convert Fdlink to PerfLink/TracePointLink/
KprobeLink, and UprobeLink and vice-versa.

This allows us to pin taken links for perf programs, ultimately
ensuring the link isn't dropped when the loading process exits.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Tamir Duberstein 8c61fc9ea6
integration-test: compile C probes using build.rs
- Add libbpf as a submodule. This prevents having to plumb its location
  around (which can't be passed to Cargo build scripts) and also
  controls the version against which codegen has run.
- Move bpf written in C to the integration-test crate and define
  constants for each probe.
- Remove magic; each C source file must be directly enumerated in the
  build script and in lib.rs.
1 year ago
Tamir Duberstein e621a09181
Clippy over tests and integration-ebpf
Replace all `assert!(matches!(..))` with `assert_matches!(..)`.

Remove the now-unused build-integration-test xtask command whose logic
doesn't match that of the build-and-run command.
1 year ago
Tamir Duberstein a1e0130387
Type-erase KernelVersion::current error 1 year ago
Tamir Duberstein 6bceb1c3da
Invert comparison
Incorrectly inverted in b611038d5b.
1 year ago
Tamir Duberstein 6e570f0f14
Rewrite kernel version logic
This restores and enhances the logic originally added in #579.
1 year ago
Tamir Duberstein cc2bc0acc1
Remove procfs dependency 1 year ago
Tamir Duberstein b5ebcb7cc5
Remove verifier log special case 1 year ago
Tamir Duberstein b45a5bb71b
Get verifier logs when loading programs 1 year ago
Tamir Duberstein 6b94b2080d
Hide details of VerifierLog
This type is really only used by one function.
1 year ago
Tamir Duberstein b611038d5b
Use procfs crate for kernel version parsing
This allows the logic to be shared between aya and the integration tests
without exposing additional public API surface.
1 year ago
Tamir Duberstein 27120b328a
aya: don't allocate static strings 1 year ago
Tamir Duberstein ff86f1385c
Remove dependency on bpftool in integration tests 1 year ago
Dave Tucker 47f764c191 aya: Make Features part of the public API
This commit adds a new probe for bpf_attach_cookie, which would be used
to implement USDT probes. Since USDT probes aren't currently supported,
we this triggers a dead_code warning in clippy.

There are cases where exposing FEATURES - our lazy static - is actually
helpful to users of the library. For example, they may wish to choose to
load a different version of their bytecode based on current features.
Or, in the case of an orchestrator like bpfd, we might want to allow
users to describe which features their program needs and return nice
error message is one or more nodes in their cluster doesn't support the
necessary feature set.

To do this without breaking the API, we make all the internal members of
the `Features` and `BtfFeatures` structs private, and add accessors for
them. We then add a `features()` API to avoid leaking the
lazy_static.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Alessandro Decina 76d35d10ce
Merge pull request #526 from dave-tucker/trie
aya: Remove iter_key from LPM Trie API
1 year ago
Dave Tucker 00c480d2f9 aya: Remove iter_key from LPM Trie API
Based on the discussion in Discord we've decided to drop the
iter_key() API for LPM Trie. According to the kernel self-tests and
experimentation done in Aya, providing a key into bpf_map_get_next_id
will either:

- If key is an EXACT match, proceed iterating through all keys in the
trie from this point
- If key is NOT an EXACT match, proceed iterating through all keys in
the trie starting at the leftmost entry.

An API in Aya could be crafted that gets the LPM match + less specific
matches for a prefix using these semantics BUT it would only apply to
userspace. Therefore we've opted out of fixing this.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
ajwerner 65d10f9ffc aya: replace os::unix::prelude with os::fd 1 year ago
Mary 77cce840f7
Update aya/src/bpf.rs
Co-authored-by: Alessandro Decina <alessandro.d@gmail.com>
1 year ago
Mary 93435fc854 aya: allow global value to be optional
This allow to not error out when a global symbol is missing from the object.
1 year ago
Andrew Stoycos 17930a88c5
Fixups in response to alessandrod review
Move BpfError::UnsupportedMap into MapError and add a map_type field to
the error.

Update the `allow_unsupported_maps` function comment.

Update the logic to check if any unsupported maps are being used. More
specifically only search a program's maps if `allow_unsupported_maps` is
set and then use the iter function `try_for_each` with a match statement
which allows us to return the inner map type if it's unsupported.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Andrew Stoycos b5719c5b3f
Add Unsupported Map type
Just because aya doesn't support working with some map
types doesn't mean we should't allow them to be loaded.

Add a new `Unsupported` map type to facilitate this,

Next add a user configurable option `allow_unsupported_maps()`
which can be called against the `bpfLoader`.  Additionally
add a nice warning log message when a program is being loaded
by Aya and contains an unsupported map type.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Federico Ponzi 987e8489d0 aya-utils: add syscall_prefix and syscall_fnname_add_prefix
These two functions are needed because kernel symbols representing
syscalls have architecture-specific prefixes.

These are the equivalent of bcc's get_syscall_fnname and
get_syscall_prefix.

Solves: #534
1 year ago
Mary 49c6f5d122 aya: Fix uprobe support on 4.16 and lower
Fix uprobe support on Ubuntu 18.04.
1 year ago
Mary 8e9f395eab aya: Add support for old ld.so.cache format
This fix uprobe support on Debian 10. (and possibly others)
This implement support to parse the original libc5 format.
1 year ago
Alexis (Poliorcetics) Bourget 243986c1da fix: Relax unnecessarily strict atomic ordering on probe event_alias 1 year ago
Mary e9be3d9023 aya: Make probe event_alias unique
This fixes issues when trying to attach the same kernel function multiple times on 4.17 and lower (possibly upper too?)
1 year ago
Alessandro Decina 3a9a54fd9b
Merge pull request #602 from marysaka/fix/btf-reloc-all-functions
aya: Apply BTF relocations to all functions
1 year ago
Kenjiro Nakayama afb4aa1c66 Add a few tweak a code to fix libbpf's API change. 1 year ago
William Batista 3d1013d729 Fixed a typo in the per_cpu_hashmap documentation 1 year ago
Hanaasagi 0e4aec475f fix(lint): remove useless `any` `all` in cfg. 1 year ago
Mary 591e21267a aya: Do not create data maps on kernel without global data support
Fix map creation failure when a BPF have a data section on older
kernel. (< 5.2)

If the BPF uses that section, relocation will fail accordingly and
report an error.
1 year ago
Mary 9e1109b3ce aya: Move program's functions to the same map 1 year ago
Tamir Duberstein ae8a95b0ee
build(deps): update bitflags requirement from 1.2.1 to 2.2.1
Updates the requirements on [bitflags](https://github.com/bitflags/bitflags) to permit the latest version.
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/1.2.1...2.2.1)
1 year ago
vadorovsky deb054afa4
Merge pull request #577 from aya-rs/dependabot/cargo/object-0.31
build(deps): update object requirement from 0.30 to 0.31
1 year ago
Alessandro Decina 120b59dd2e
Merge pull request #545 from epompeii/lsm_sleepable
Add `BPF_F_SLEEPABLE` flag support to LSM
1 year ago
dependabot[bot] 4c78f7f1a0
build(deps): update object requirement from 0.30 to 0.31
Updates the requirements on [object](https://github.com/gimli-rs/object) to permit the latest version.
- [Release notes](https://github.com/gimli-rs/object/releases)
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.30.0...0.31.0)

---
updated-dependencies:
- dependency-name: object
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
1 year ago
Alessandro Decina 45efa6384f
Merge pull request #586 from probulate/no-std-inversion
aya: flip feature "no_std" to feature "std"
1 year ago
Tamir Duberstein 33a0a2b604
aya: flip feature "no_std" to feature "std"
This fixes `cargo build --all-features` by sidestepping the feature
unification problem described in The Cargo Book[0].

Add `cargo hack --feature-powerset` to CI to enforce that this doesn't
regress (and that all combinations of features work).

Since error_in_core is nightly-only, use core-error and a fake std
module to allow aya-obj to build without std on stable.

[0] https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
1 year ago
Everett Pompeii 1f2006bfde
Merge branch 'aya-rs:main' into lsm_sleepable 1 year ago
Dave Tucker ed14751c79
Merge pull request #525 from dave-tucker/borrow
aya: MapData should be Borrow, not AsRef
1 year ago
Mary 3aeeb8167b aya: Correctly set the kernel code version for Debian kernel
Fix BPF syscall failure related to the kernel code version.
1 year ago
Mary f1d891836e aya: Correctly set the kernel code version for Ubuntu kernel
Fix BPF syscall failure related to the kernel code version.
1 year ago
Mary 1132b6e01b aya: Add sanitize code for kernels without bpf_probe_read_kernel
Required for kernel before 5.5.

Also move Features to aya-obj.
1 year ago
Mary 7c25fe90a9 aya: Do not use unwrap with btf_fd in bpf_create_map
Fixes a crash when trying to create a map of type BPF_MAP_TYPE_PERCPU_ARRAY when btf_fd is None.

Tested on Ubuntu 18.04 (4.15.0-202-generic)
1 year ago
Alessandro Decina 93ac3e94bc aya: support relocations across multiple text sections + fixes
Fix R_BPF_64_64 text relocations in sections other than .text (for
instance .text.unlikely). Also fix misc bugs triggered by integration
tests.
1 year ago
Alessandro Decina 401ea5e848 aya, aya-obj: refactor map relocations
Clearly split the code between `.maps`, `maps` and data maps (bss, data,
rodata). Sprinkle comments.

Remove MapKind which was effectively only needed since we used to have
one variant - BpfSectionKind::Data - to represent all data maps. Instead
add explicit BpfSectionKind::{Data, Rodata, Bss} variants and match on
those when we initialize maps.
1 year ago
epompeii 85714d5cf3 review 2 years ago
epompeii 17f497ce42 program_section 2 years ago
Alessandro Decina b13070a342
Merge pull request #557 from drewvis/main
Add check for empty tracefs mounts
2 years ago
Alessandro Decina bcb2972a96 aya: make it possible to use set_global() with slices of Pod(s) 2 years ago
drewvis 8f64cf8cd5 Added code check comment 2 years ago
drewvis 3a2c0cd1dd Add check for empty tracefs mounts 2 years ago
Alessandro Decina 8ef00c4c63 Revert "aya: make it possible to use set_global() with slices of Pod(s)"
This reverts commit b614ffd603.
2 years ago
Alessandro Decina b614ffd603 aya: make it possible to use set_global() with slices of Pod(s) 2 years ago