Commit Graph

834 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 48f9e00c2e util: make Align not pub
This has no effect, so drop it. Tidy up a bit while I'm here and explain
the use of const refernces.
2026-04-02 17:35:36 -04:00
Kirill Lykov a7144b9a6e Align by 8b in include_bytes_aligned.
The max alignment required by ELF files is 8 bytes. There is no need to
use 32b alignment.
2026-04-01 17:41:36 +00:00
Tamir Duberstein 98960db18a netlink: avoid some allocations 2026-03-16 16:50:42 -04:00
Tamir Duberstein ed516b3ec0 netlink: advance through write buffers
Refactor netlink attribute writers to consume and return the remaining
buffer instead of passing offsets through helper calls.
2026-03-16 16:50:42 -04:00
Tamir Duberstein 52c33ebdf8 netlink: use constants more consistently
Use returned lengths where possible rather than hard coding constants.
2026-03-16 16:50:42 -04:00
Tamir Duberstein 68be4b7297 netlink: use checked accessors 2026-03-16 16:50:42 -04:00
Tamir Duberstein f49ef401a7 netlink: avoid repeating NLA_ALIGNTO everywhere 2026-03-16 16:50:39 -04:00
Tamir Duberstein b9cb76b302 Rename EbpfGlobal to Global
Rename the eBPF global wrapper type to `Global` and update its
downstream uses and API snapshot so the public surface matches the new
name.

Co-authored-by: Codex <noreply@openai.com>
2026-03-06 11:20:10 -05: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
cong-or c42157f0b5 netlink: fix attachment failure with long program names
The netlink attribute buffer in TcRequest was only 64 bytes, which is
not enough when TC program names get close to the kernel's 256-byte
limit. This led to a misleading no space left error when attaching
programs with longer names.

Bump the buffer size so it can precisely fit all the netlink attributes
and the max-length name.
2026-02-20 14:34:38 -08:00
vad ae8c76d037 maps: Fix BloomFilter::contains method
Require the caller to pass a reference, not the owned value. That makes
sure that the pointer is valid from the beginning.
2026-02-16 18:19:28 +00:00
Jamie Hill-Daniel 294e0c1941 ebpf: Add helper for safe loading of globals 2026-02-13 11:13:57 -08: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
Tamir Duberstein be872b1cff Use usize::next_multiple_of 2026-01-21 15:20:26 -05:00
Tamir Duberstein f35f7a3610 aya, aya-ebpf: reduce duplication 2026-01-21 09:05:51 -05:00
Lukas Hoehl d022b8dce4 set value_size to 0 if loading ringbuffer (#1443)
Override ring buffer value_size to 0 to allow slightly malformed 
programs to load. This is the same approach taken by Cillium.

Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
2026-01-16 19:07:39 -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 d238b2ea6f Release crates
- aya v0.13.2
- aya-build v0.1.3
- aya-ebpf v0.1.2
- aya-ebpf-bindings v0.1.2
- aya-ebpf-cty v0.2.3
- aya-ebpf-macros v0.1.2
- aya-log v0.2.2
- aya-log-common v0.1.16
- aya-log-ebpf v0.1.2
- aya-log-ebpf-macros v0.1.1
- aya-log-parser v0.1.14
- aya-obj v0.2.2

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2025-11-17 14:51:14 -05: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 d4b2dde78a perf_event: inline perf_event_open_bpf
This function has one caller and provides no abstraction.
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
JPaja d8f5497884 feat: add Ebpf::maps_disjoint_mut
Implemented using `HashMap::get_disjoint_mut` introduced in Rust 1.86.0.
2025-11-10 14:12:04 -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
Alessandro Decina 3a3c451009 aya: restore must_exist argument to set_global
In
https://github.com/aya-rs/aya/commit/03e84871773e09badf08bdef8e83b4f1256850a4
we deprecated set_global but accidentally broke its API by deleting the
must_exist argument.
2025-10-29 13:01:34 +01:00
Tamir Duberstein d73c65caae Add some type ascription 2025-10-26 11:42:32 -04:00
Tamir Duberstein 17c7c7951c lints: enable clippy::as_underscore 2025-10-26 11:36:51 -04:00
Andrew Werner 03e8487177 aya: rename set_ methods on EbpfLoader
This loader is more of a builder, so these `set_` methods didn't
quite fit. See [this discussion][1] for the motivation.

[1]: https://reviewable.io/reviews/aya-rs/aya/1318#gh-2384180366
2025-10-22 00:05:20 -04:00
Andrew Werner 17171647f7 aya/maps/ring_buf: fix producer position initialization
The RingBuf caches the last value it read of the producer so it doesn't
need to constantly contend on the actual producer cache line if lots of
messages have yet to be consumed. It was bogus to initialize this cache
at 0. This patch initializes it properly and adds testing.

Fixes: #1309
2025-10-21 08:30:20 -04:00
Andrew Werner 5802dc7a23 aya: allow specifying a pin path for a named map
This commit extends the EbpfLoader with set_map_pin_path that allows the
caller to associate a named map with a pin path.

One note is that this path is an absolute path, not relative to
`map_pin_path`, and it forces the map to be loaded from that path.
2025-10-21 08:30:20 -04:00
Andrew Werner 1c924bb421 aya: rename map_pin_path to default_map_pin_path
This is the path in which pinned maps are created or resolved. It
isn't actually the path for any specific map itself. This rename
makes way for a method `set_map_pin_path` that actually specifies
the pin path for a specific map.
2025-10-21 08:30:20 -04:00
Tamir Duberstein 0144c0eb22 integration-test: defer cleanup to ensure unpin 2025-10-17 22:16:28 -04:00