Commit Graph

753 Commits (80fd4a31214358476ab7b20038b8207e5245059a)

Author SHA1 Message Date
Mehnaz Yunus 4b5ba53a36 aya: implement TryFrom<[Program Type]> for FdLink for various program types
Implements TryFrom for FdLink for CgroupSkb, CgroupSock, CgroupSockAddr
and SockOps program types. This allows support for link pinning for
these program types, aligning with the documentation for FdLink.

Fixes: #739

Co-authored-by: Benjamin Barzen <bbarzen@amazon.com>
3 weeks ago
Tyrone Wu 7a0dabc295 aya: short-circuit info field if non-zero
Short-circuits `CACHE` to true if the field is non-zero.

This saves from executing the probing logic since the logic essentially
checks if the field can process (or doesn't error) non-zero value.
3 weeks ago
Tyrone Wu 23bc5b5836 aya,aya-obj: cache feat probed info fields
Cached probed for ProgramInfo fields instead of exposing it through
global FEATURE. Probing occurs on cache miss, which happens when first
accessing the field, *and* if the field is 0.
3 weeks ago
Tyrone Wu bd492860f5 aya: add feature probing for map type
Add API that probes whether kernel supports a map type.
3 weeks ago
Tyrone Wu ab77decd9a aya,aya-obj: add feature probing program type
Adds API that probes whether kernel supports a program type.
3 weeks ago
Dave Tucker f74a157907
Merge pull request #1262 from dave-tucker/stabilize-links
feat(aya): Make LinkInfo and loaded_links public
4 weeks ago
Dave Tucker 7dba5a41ad feat(aya): Make LinkInfo and loaded_links public
We have had loaded_links in the API as `#[doc(hidden)]` for a while.
I've been using it in bpfman and it's been fine. This commit does the
minimal work required to make the API stable.

We expose a `LinkInfo` type - similar to `ProgInfo` - which wraps the
generated type. In this case, `bpf_link_info`.

A few accessor functions have been added for `id`, `link_type` and
`program_id`. There are many more fields that could be (eventually)
made public.

As a convenience, `LinkInfo` can be retrieved from an existing FdLink
by using `FdLink::info()`.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 weeks ago
Omri Steiner 33c9f2b2b2 aya: uprobe: use PathBuf for ResolveSymbolError::DebuglinkAccessError
Makes no sense to use a string, as it's a path.
This breaks the public API.
1 month ago
Omri Steiner 90d5604877 aya: uprobe attach: use mmap instead of reading whole binaries to memory 1 month ago
Omri Steiner 647100faa7 aya: clean up resolve_symbol a bit
Instead of using intermediate values to extend the lifetime of the
object::File, we just separate the branches.
1 month ago
Omri Steiner 3aded0e0a5 aya: move Mmap struct to aya::util 1 month ago
Tamir Duberstein 583709f6a0 appease `clippy::uninlined-format-args` 1 month ago
Dave Tucker 23a5e06c75 chore(aya): Use BPF_ADD from bindings
We should use the generated one, not the one provided by the libc crate.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 months ago
Andres fc69a06972
aya: fix is_probe_read_kernel_supported in aarch64 kernels 5.5 (#1235)
In aarch64, with kernel 5.5, my programs that use `bpf_probe_read_user`
don't work successfully because `aya` is mistakenly re-writting it
`bpf_probe_read` because it falsely detects that the kernel doesn't
support `bpf_probe_read_user`.

I hadn't updated my `aya` version in a while, but while updating it to
fix a separate issue (panics when parsing kernel versions of PVE
kernels) and running my test suite I saw tests failing on aarch64 5.5
kernels. A git bisect led me to this commit:
942ea51906 and further investigation in the
difference of the new and old assembly showed that the only difference
was subtracting 8 vs adding -8. When I put it back as adding 8 (but
without handwritten assembly) then things work as expected. Since it
used to be `BPF_ADD` and the commit that changed it was just about no
longer handwriting assembly without any reason for the switch to
`BPF_SUB` putting it back as `BPF_ADD` seems reasonable. 

When using `BPF_SUB` 8, the handwritten program in this function
returns a permission error which is treated by this function as
`bpf_probe_read_kernel` not being supported when it is but for some
reason `BPF_SUB` is not. My guess is that it might be an early verifier
error but I am not 100% sure as I thought verifier errors are normally
`EINVAL` not `EPERM` but I have a vague memory of seeing `EPERM` in the
past for errors that happened very early in the verifier.

Fixes: #1233
2 months ago
Dave Tucker 1db534defa
Merge pull request #1209 from dave-tucker/from_prog_info
feat: Allow conversions to Program from ProgramInfo
2 months ago
Dave Tucker e8e268ba76 chore(aya): Fix clippy unused cfg_attr
clippy complained that cfg_attr is applied to the macro invocation and
therefore will not be expanded. This was a false-positive, however
when playing with cargo expand I did notice that the cfg and cfg_attr
section weren't propagating as I would expect them to.

Adding a meta matcher to the impl_try_from_map macro allows us to
remove the need for AsyncPerfEventArray to be in a separate invocation
of the macro while also making sure that attributes do get propagated
to the generated functions.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 months ago
Dave Tucker 2b0dcfbd09 feat: Allow conversions to Program from ProgramInfo
Allow for a ProgramInfo to be converted into one of the program types
that we support. This allows for a user of Aya access to reattach,
pin or unload a program that was either, previously loaded, or was
loaded by another process.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 months ago
Dave Tucker 9eecbe9d0e
Merge pull request #1224 from dave-tucker/unused_trait_names
chore(*): set clippy unused_trait_names = warn
3 months ago
Tamir Duberstein 77b1c6194c Add support for Flow Dissector programs
Closes #216.

Co-authored-by: Zenna Allwein <zrallwein@gmail.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
3 months ago
Dave Tucker f6c5cb2ad2 chore(*): set clippy unused_trait_names = warn
We have previously tried to import traits anonymously where possible but
enforcing this manually was hard.

Since Rust 1.83 clippy can now enforce this for us.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Tamir Duberstein 3edc36af9d aya: remove unhelpful comment 3 months ago
Tamir Duberstein 49a828ec56 taplo: reorder-keys
Group non-workspace keys before workspace ones for readability.
3 months ago
Michal Rostecki f48b5a4a84 aya: Ensure that truncated map names are NULL terminated
Limit of map names in eBPF is 16 bytes and they have to be NULL
terminated.

Before this change, long names were truncated to 16 bytes.
`MAP_WITH_LOOOONG_NAAAAAAAAME` would become `MAP_WITH_LOOOONG`, which
doesn't contain the NULL byte.

This change fixes that by truncating the name to 15 bytes, ensuring
that the 16th byte is NULL. `MAP_WITH_LOOOONG_NAAAAAAAAME` is truncated
to `MAP_WITH_LOOOON\0`.
3 months ago
Tamir Duberstein a43e40ae1d introduce workspace lints, warn on unused crates
In practice this will forbid unused dependencies because we run clippy
with `--deny warnings`.

Workspace lints is a nice place to ratchet up lints through the codebase
all at once and consistently.
3 months ago
Tamir Duberstein 22c8f783e7 programs: allow program names to be static strings 3 months ago
arctic-alpaca 73a34e1571 aya: Add `XskMap::unset` 3 months ago
Dave Tucker ea76e0f62d aya: parse complete entries from /proc/$pid/maps
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
3 months ago
Tamir Duberstein de0b7cee8d Destructure 3 months ago
Tamir Duberstein 7084df68aa Add punctuation 3 months ago
Tamir Duberstein 50ae0ee099 Avoid allocations when parsing /proc/{pid}/maps 3 months ago
Tamir Duberstein e16f0482f8 Revert "ci: remove cross toolchain"
Turns out this was actually being used through magic.

Remove mips since it is a tier 3 target that is only supported on
nightly and dtolnay/rust-toolchain doesn't seem to handle installing
targets without std.

Exclude xtask since it depends on `ring` which doesn't build on all
targets.

Fix compilation on armv7 which had rotted.

This reverts commit d92fc95c39.
3 months ago
Tamir Duberstein f0a9f19ddc Bump edition to 2024
Change FromRawTracepointArgs::arg to return T rather than *const T which
seems to have been returning a dangling pointer.

Arguably this is not strictly necessary; edition 2024 seems to be
focused on increased strictness around unsafe code which doesn't unlock
new functionality for our users. That said, this work revealed an
apparent bug (see above) that we wouldn't otherwise catch due to
allow-by-default lints.
3 months ago
Tamir Duberstein ea5f7e3015 Reduce the scope of expected warnings
This fixes a few safety comments to avoid the warnings.
3 months ago
Tamir Duberstein 4101a5a55d Use #[expect(...)] rather than #[allow(...)]
This is stricter, and revealed a few unused allowances.
3 months ago
Tamir Duberstein 27d69c35f0 aya: remove panics on indeterminate kernel version
Cache the current kernel version in a thread-local while I'm here.

Closes https://github.com/aya-rs/aya/issues/1024.
Closes https://github.com/aya-rs/aya/pull/1042.
3 months ago
Tamir Duberstein 9eefb48a0a aya: remove some copies
Replace truncation with proper NULL termination at the site of use.
3 months ago
Tamir Duberstein 89aa638e05 aya: add TODO to remove once_cell 3 months ago
Tamir Duberstein de1e80c1d1 aya: encode perf_event ioctl contract
Enumerate the possible ioctls in an enum and bake in the knowledge that
they all return 0 on success and -1 on error.
3 months ago
Tamir Duberstein eee7975ce4 aya: remove redundant TEST_SYSCALL use
This is already done in `syscall`.
3 months ago
Tamir Duberstein 055e36e8d9 aya: encode perf_event_open(2) contract
Per man 2 perf_event_open:

> RETURN VALUE
>   On success, perf_event_open() returns the new file descriptor.  On
>   error, -1 is returned and errno is set to indicate the error.

Bake this into our syscalls so we stop using `_` so much which can hide
information loss. Remove the type parameter to SysResult.
3 months ago
Tamir Duberstein bdd8ae2d0b *: avoid `_`
This can silently discard information, so we shouldn't do it.
3 months ago
Tamir Duberstein f6df60fa70 aya: encode bpf(2) contract
Per man 2 bpf:

> RETURN VALUE
>   For a successful call, the return value depends on the operation:
>
>   BPF_MAP_CREATE
>     The new file descriptor associated with the eBPF map.
>
>   BPF_PROG_LOAD
>     The new file descriptor associated with the eBPF program.
>
>   All other commands
>     Zero.
>
>   On error, -1 is returned, and errno is set to indicate the error.

Bake this into our syscalls so we stop using `_` so much which can hide
information loss.
3 months ago
Tamir Duberstein 2d782606fe *: avoid Result::is_{ok,err}
These methods discard information. Discarding information is bad.
3 months ago
Tamir Duberstein dab1aa4e29 maps: avoid retagging in tests 3 months ago
Tamir Duberstein f51ab80075 perf_buffer: attempt to preserve provenance
In tests, provide write provenance.
3 months ago
Tamir Duberstein 888701425b perf_buffer: use MMap from ring_buf 3 months ago
Tamir Duberstein ff82c244f7 netlink: avoiding casting pointers to usize 3 months ago
Tamir Duberstein e17feca2d6 maps: remove some stale comments 3 months ago
Tamir Duberstein 935ba20224 Enable test under miri
nr_cpus() is stubbed since 9e1bcd0ab8.
3 months ago
Tamir Duberstein 9a47495227 aya,aya-obj: preserve pointer provenance 3 months ago