Commit Graph

334 Commits

Author SHA1 Message Date
Tamir Duberstein 595910c410 Set fixed expected attach types
Load cgroup_{device,sysctl}, flow_dissector, lirc_mode2, sk_msg,
sock_ops programs with their fixed expected attach types instead of
omitting them.

These program types already use the same constants when attaching.
2026-04-03 11:22:00 -04:00
Tamir Duberstein 2c927581fe Remove duplicate attach type state
Pass the kernel attach type into the shared loader from each typed
wrapper instead of storing a second mutable copy in `ProgramData`.

This removes the from_pin repair pattern, avoids stale shadow state, and
keeps attach paths driven by wrapper-owned typed attach metadata or
fixed constants.

Also simplify `{sk,cgroup}_skb` section parsing by representing all
variants as `ProgramSection::SkSkb { kind }` and
`ProgramSection::CgroupSkb { attach_type }` respectively, with the
attach type enums shared from aya-obj.
2026-04-03 11:21:32 -04:00
Tamir Duberstein 98960db18a netlink: avoid some allocations 2026-03-16 16:50:42 -04:00
Alessandro Decina cdfa52de6e lsm_cgroup: fix attach on 6.17
For LSM programs the target_btf_id is set at load time not attach time.

Starting from
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1209339844601ec1766f4ff430673fbcfe42bb51
setting it at attach time results in EINVAL, because it happens to be
interpreted as bits of the mprog part of the union.
2026-03-07 03:18:03 +11:00
Tamir Duberstein 2f8759cc62 Dial the lints to 100 2026-01-29 10:02:48 -05:00
Tamir Duberstein e746618143 enable unused_qualifications lint 2026-01-23 11:03:26 -05:00
Sven Cowart 7cbd816a77 doc(aya): document tcx link pinning for atomic program replacement
Add documentation and integration test for SchedClassifier link pinning,
which enables zero-downtime program updates in production environments.

- Add link pinning example to SchedClassifier::attach_with_options()
  showing atomic replacement workflow for TCX mode (kernel >= 6.6).
- Add pin_tcx_link() integration test verifying link persistence
  across program unload and atomic replacement capability.
2026-01-06 20:18:26 -05:00
cyril 775f42d781 aya: avoid trying to parse paths in proc maps
There are various oddities in how the kernel prints path including
"(deleted)" suffix, bracketed properties e.g. "[vdso]", ashmem and memfd
paths, and possibly others. Rather than try to handle these in
`ProcMapEntry::parse` just leave them as they appear and let the caller
deal with them.

Change splitting behavior to any number of consecutive whitespace
characters between columns to account for padding.

This allows uprobe attachment to succeed in the presence of deleted
mapped files and in more cases of android special attributes.

Rewrite tests using `test_case`.

Co-authored-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: cyril <multya77@gmail.com>
2026-01-05 12:23:55 -05:00
Tamir Duberstein eb25e6af2a aya: avoid some allocations
Use `Path::display` in test assertions for better errors.
2026-01-05 12:23:55 -05:00
Tamir Duberstein efecc088b3 aya: trim whitespace just once
Update tests to include the expected trailing newline.
2026-01-05 12:23:55 -05:00
Tamir Duberstein d1f72a580c aya: improve ParseLine as Debug
Print human-readable strings rather than sequences of bytes.
2026-01-05 12:23:54 -05:00
Tamir Duberstein 80d79526a6 aya: move test_resolve_attach_path to tests module 2026-01-05 12:23:53 -05:00
Tamir Duberstein 4984ddc046 aya: use integer::next_multiple_of
See https://github.com/rust-lang/rust-clippy/issues/14144.
2026-01-04 06:57:24 -05:00
swananan eb99da3cbb uprobe: bundle attach location+cookie via UProbeAttachPoint
This follows the #1417 review discussion: by bundling location
+ cookie into a UProbeAttachPoint we get a more idiomatic Into<_>
entry point, keep the one-to-one relationship enforced by the type
system, and make it easier to extend attach with multi-location
support without introducing parallel arrays or a brand new API.
2025-12-23 18:22:42 +01:00
Tamir Duberstein 46221ad11d probe: use RAII to clean up in the error path 2025-11-12 11:55:44 -05:00
Tamir Duberstein 72810f095f aya: ProbeKind is Entry/Return
We already have separate types for KProbe and UProbe.
2025-11-12 11:28:03 -05:00
Tamir Duberstein a4a3c1641f probe: use exhaustive matches 2025-11-12 11:28:03 -05:00
Tamir Duberstein 1944c4aa00 perf_event: refactor perf_event_open_trace_point
Rewrite it in terms of perf_event_open.
2025-11-12 11:28:03 -05:00
Tamir Duberstein 7e07f85edc perf_attach: privatize PerfLink
There's no way to obtain this type externally.
2025-11-12 11:28:03 -05:00
Tamir Duberstein 27c7f1c84f programs: disambiguate fd names 2025-11-12 11:28:02 -05:00
Tamir Duberstein 1791d497d3 programs: remove superfluous type ascription 2025-11-12 11:25:54 -05:00
Friday Ortiz ab38afe95d perf_event: support hardware breakpoints
Implement `PerfEventConfig::Breakpoint`, allowing users to attach
hardware breakpoints. Generate `HW_BREAKPOINT_*` and `struct
bpf_perf_event_data` in support of this feature and update the type of
`PerfEventContext` accordingly.

Add a test exercising R, W, RW, and X breakpoints. Note that R
breakpoints are unsupported on x86, and this is asserted in the test.

Extend the VM integration test harness and supporting infrastructure
(e.g. `download_kernel_images.sh`) to download kernel debug packages and
mount `System.map` in initramfs. This is needed (at least) on the aarch
6.1 Debian kernel which was not compiled with `CONFIG_KALLSYMS_ALL=y`
for some reason, and the locations of globals are not available in
kallsyms. To attach breakpoints to these symbols in the test pipeline,
we need to read them from System.map and apply the KASLR offset to get
their real address. The `System.map` file is not provided in the kernel
package by default, so we need to extract it from the corresponding
debug package. The KASLR offset is computed using `gunzip` which appears
in kallsyms on all Debian kernels tested.

Co-authored-by: Tamir Duberstein <tamird@gmail.com>
2025-11-10 16:33:54 -05:00
Tamir Duberstein 112ab47fcd Add clippy coverage for doctests 2025-11-09 18:26:39 -05:00
Tamir Duberstein 18c7f7ccd6 perf_event: push down type safety
This makes it more difficult to mishandle callers of `perf_event_open`.

Change `wakeup_events = 0` to 1; per `man 2 perf_event_open`:

  Prior to Linux 3.0, setting wakeup_events to 0 resulted in
  no overflow notifications; more recent kernels treat 0 the
  same as 1.
2025-11-09 17:50:53 -05:00
Tamir Duberstein 7e405c216e perf_event: simplify PerfEventScope 2025-11-09 13:20:41 -05:00
swananan 4fbce44b6a aya: tolerate proc map trailing newline
Proc maps terminate with a newline so split(b'\n') yields an empty
slice at the end. Filter it out before parsing so the absolute-path
fallback for pid-scoped attach doesn't get short-circuited by a
ProcMap::ParseLine error.
2025-11-05 22:37:43 -05:00
Tamir Duberstein d73c65caae Add some type ascription 2025-10-26 11:42:32 -04:00
Tamir Duberstein 0144c0eb22 integration-test: defer cleanup to ensure unpin 2025-10-17 22:16:28 -04:00
Tamir Duberstein 2e5f5efbf1 aya: make ProgramInfo a proper enum
This allows us to distinguish between LSM and LSM_CGROUP programs and do
the proper capability check in is_program_supported.
2025-10-17 22:16:28 -04:00
Tamir Duberstein 4c974d33a3 xdp: replace kernel version check with fallback 2025-10-17 15:28:21 -04:00
Tyrone Wu 3d7fbaad28 aya: enforce valid perf_event type & config combos
Add guardrails for when setting event type and config for perf_event
programs. The `PerfEventConfig` enum now defines the event `type` and
`config` of interest.

Remove public re-exports, and add idiomatic Rust types for:
- perf_hw_id => HardwareEvent
- perf_sw_ids => SoftwareEvent
- perf_hw_cache_id => HwCacheEvent
- perf_hw_cache_op_id => HwCacheOp
- perf_hw_cache_op_result_id => HwCacheResult

The motivation behind this is mainly for the `type` and `config` fields
of `bpf_link_info.perf_event.event`. The newly added enums are planned
to also be used in the `bpf_link_info` metadata.

Although `Breakpoint`/`PERF_TYPE_BREAKPOINT` variant exists, it is not
fully implemented. It's only usage at the moment is in link info.
2025-10-16 09:51:10 -04:00
Tamir Duberstein f76fdf9da5 Improve error output
- Use consistent casing.
- Emit syscall return value.
2025-10-16 06:20:43 -04:00
Tamir Duberstein 82aec26963 flow_dissector: add missing impl_try_into_fdlink 2025-10-16 06:20:43 -04:00
Altug Bozkurt fc5387c806 lsm: cgroup attachment type support 2025-10-09 06:23:19 -07:00
Tamir Duberstein 75edc3d294 *: downcase log strings 2025-10-05 07:47:16 -04:00
Tamir Duberstein 5f5305c2a8 lint all crates; enable strict pointer lints 2025-09-29 05:19:23 -04:00
Tamir Duberstein a3aa387a2e remove superfluous commas 2025-08-11 16:50:31 -04:00
Tamir Duberstein 0d1193720b doc: generate docs in macro
Remove a bunch of repetition and missing links.
2025-08-11 16:35:21 -04:00
Tamir Duberstein 8ee12d337f doc: fix rustdoc link in macro
`$wrapper` is not visible to rustdoc before expansion. Build the link
after expansion.
2025-08-11 16:11:00 -04:00
Thomas Bertschinger ab182be622 aya: construct_debuglink_path() should be infallible
`construct_debuglink_path()` returns a `Result`, but it doesn't actually
do anything that can fail. This means callers must do a useless
`unwrap()` to get at the return value.

This fixes the signature to reflect that the function is infallible.
2025-07-08 06:42:33 -04:00
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>
2025-05-14 08:38:27 -04:00
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.
2025-05-14 08:03:51 -04:00
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.
2025-05-14 08:03:51 -04:00
Dave Tucker f74a157907 Merge pull request #1262 from dave-tucker/stabilize-links
feat(aya): Make LinkInfo and loaded_links public
2025-05-08 10:43:29 +01:00
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>
2025-05-08 09:13:51 +01:00
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.
2025-05-05 10:03:21 -04:00
Omri Steiner 90d5604877 aya: uprobe attach: use mmap instead of reading whole binaries to memory 2025-05-05 10:03:21 -04:00
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.
2025-05-05 10:03:21 -04:00
Tamir Duberstein 583709f6a0 appease clippy::uninlined-format-args 2025-04-24 06:42:21 -04:00
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>
2025-03-24 13:09:13 +00:00