Commit Graph

334 Commits

Author SHA1 Message Date
Dave Tucker 5d8b279265 aya: Fix BTF verifier output
Currently errors can occur if the verifier output is > buffer as we get
ENOMEM. We should only provide a log_buf if initial load failed, then
retry up to 10 times to get full verifier output.

To DRY this logic it has been moved to a function so its shared with
program loading

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>

one verifier loop to rule them all

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-18 13:22:12 +00:00
Dave Tucker 8f9a32ff10 aya: Fix name truncation
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-16 14:03:25 +00:00
Dave Tucker 437432cdd6 aya: Truncate long program names
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-16 10:48:51 +00:00
Alessandro Decina 6a91fdf5a7 Merge pull request #157 from dave-tucker/doc-aya
aya: document the public api
2022-01-16 13:34:46 +11:00
Dave Tucker abc8d27440 aya: Retrieve program from pinned path
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-14 23:14:51 +00:00
Dave Tucker bca01580e7 aya: document the public api
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-12 17:14:02 +00:00
Dave Tucker 5c6131afba Add BPF_PROG_TYPE_EXT
This requires loading the BTF to kernel when loading all programs as
well as implementing Extension program type

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2022-01-12 11:20:02 +00:00
Michal Rostecki 7e2fcd1d6d Support for fentry and fexit programs
fentry and fexit programs are similar to kprobe and kretprobe, but they
are newer and they have practically zero overhead to call before or
after kernel function. Also, fexit programs are focused on access to
arguments rather than the return value.

Those kind of programs were introduced in the following patchset:

https://lwn.net/Articles/804112/

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
2021-12-14 22:08:25 +11:00
Alessandro Decina 07a6016ebb Merge pull request #120 from eero-thia/thia/dedup
aya: eliminate name duplication in maps and programs.
2021-12-05 16:18:59 +11:00
Thia Wyrod f56dd0a70b aya: eliminate name duplication in maps and programs.
Map and ProgramData objects had unnecessarily cloned strings for their
names, despite them being just as easily available to external users via
bpf.maps() and bpf.programs().
2021-12-04 20:54:18 -08:00
Thia Wyrod daa7ea6d0d aya: remove unnecessary usage of &dyn trait in favor of impl trait.
This should improve performance in most situations by eliminating
unnecessary fat pointer indirection.
2021-11-26 12:34:54 -08:00
Dan Everton 0e84610976 Refactoring after feedback. 2021-11-22 11:51:45 +10:00
Dan Everton 606c3267c4 Support pid filtering in debugfs 2021-11-19 09:28:31 +10:00
Dan Everton 1dc75542b4 Handle probe entry offsets 2021-11-19 09:16:15 +10:00
Dan Everton 4e6aeb2e69 Merge branch 'main' into kprobe-debugfs 2021-11-19 08:29:44 +10:00
Dan Everton 3dff6e8555 Updates based on feedback 2021-11-19 07:37:05 +10:00
Dan Everton 4277205e9d Use current kernel version as default if not specified
When a BPF program doesn't specify the target kernel version, the
most compatible option is to set the program kernel version to match
the currently running kernel.
2021-11-18 16:41:34 +10:00
Dan Everton 42c9737d47 Functional detach of debugfs probes. 2021-11-18 10:10:04 +10:00
Dan Everton a4faabcf93 Fix event_alias comparison when looking in event list 2021-11-18 09:19:58 +10:00
Dan Everton 84fa2197ec Don't duplicate perf_attach code and formatting 2021-11-18 09:08:50 +10:00
Dan Everton d0321bd1ee Attempt auto detach of probe for debugfs 2021-11-18 08:59:41 +10:00
Dan Everton 34aa790a91 Support k/uprobes on older kernels.
Prior to kernel 4.17 probes were attached via debugfs and this patch
attempts to make that work.

Tested on kernel 4.14.
2021-11-17 14:52:55 +10:00
William Findlay 6b6d4af932 aya/programs/lsm: pass Btf by reference instead of loading new Btf in Lsm::load 2021-10-29 00:03:12 -04:00
William Findlay 6539cbb555 aya/aya-bpf: implement btf tracepoint programs 2021-10-29 00:03:12 -04:00
William Findlay 169478c863 Add support for raw tracepoint and LSM programs
This change adds support for the following program types:

* raw tracepoint
* LSM

Supporting LSM programs involved a necessity of supporting more
load_attrs for the BPF_PROG_LOAD operation, concretely:

* expected_attach_type - for LSM programs, it has always to be set to
  BPF_LSM_MAC
* attach_btf_obj_fd - it's often used to reference the file descriptor of
  program's BTF info, altough in case of LSM programs, it only has to
  contain the value 0, which means the vmlinux object file (usually
  /sys/kernel/btf/vmlinux)
* attach_btf_id - ID of the BTF object, which in case of LSM programs is
  the ID of the function (the LSM hook)

The example of LSM program using that functionality can be found here:

https://github.com/vadorovsky/aya-example-lsm

Fixes: #9
Signed-off-by: William Findlay <william@williamfindlay.com>
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
2021-10-28 11:47:24 +02:00
Dave Tucker 9426f36f79 Implement Pinning For Programs and Maps
This commit adds 2 new methods to aya::sys
- bpf_pin_object
- bpf_get_object

Which allow the pinning and retrieval of programs/maps to bpffs.

It adds a `Program.pin` API, such that a loaded program can be pinned.
For map pinning, the user must ensure the `pinning u32` in the
`bpf_map_def` is set to 1, maps will be pinned using a new builder API.

BpfLoader::new().map_pin_path("/sys/fs/bpf/myapp").load_file("myapp.o")

This will pin all maps whose definition requests pinning to path + name.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2021-09-28 23:31:29 +10:00
Dave Tucker a10a7b3bf2 bump obj to 0.26
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2021-09-21 18:42:07 +10:00
Alessandro Decina 98361a4c93 aya: minor PerfEvent API tweaks 2021-09-20 10:32:58 +00:00
Markus Stange c39dff6025 Add support for PerfEvent programs. 2021-09-20 05:35:51 +00:00
Dave Tucker e9bad0b61d Make Clippy Happy
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2021-09-15 07:26:47 +10:00
Alessandro Decina 66a12ffcf7 aya: programs: tweak LircMode2::query doc. 2021-07-31 01:05:08 +00:00
Sean Young 81e07e9661 Implement query for lirc programs (#32)
Signed-off-by: Sean Young <sean@mess.org>
2021-07-28 08:53:32 +10:00
Alessandro Decina fa2cbe2f82 aya: fix clippy warnings 2021-07-23 07:28:09 +00:00
Alessandro Decina c2a90c2c01 aya: tc: add qdisc_detach_program
qdisc_detach_program can be used to detach all the programs that have
the given name. It's useful when you want to detach programs that were
attached by some other process (eg. iproute2), or when you want to
detach programs that were previously left attached because the program
that attached them was killed.
2021-07-23 07:08:42 +00:00
Alessandro Decina d996a88de4 aya: fix formatting 2021-07-04 01:39:19 +00:00
Alessandro Decina 0878c4505a aya: fix clippy warnings 2021-07-04 01:39:19 +00:00
Alessandro Decina 9c8e78b7d4 aya: tc: make qdisc_add_clsact return io::Error 2021-06-28 10:41:26 +00:00
Alessandro Decina 08c71dfeb1 aya: kprobe: remove pid argument
Kprobes can only be attached globally. Per-pid logic needs to be
implemented on the BPF side with bpf_get_current_pid_tgid.
2021-06-27 00:00:40 +00:00
Arnabjyoti Kalita 35f15f70e0 aya: add minimum kernel version for each map and program type (#18) 2021-06-26 21:17:39 +10:00
Alessandro Decina bb15e82c1d aya: add missing load() in kprobe example
Fixes #17
2021-06-26 01:06:12 +00:00
Alessandro Decina 7f2ceaf12e aya: netlink: port TC code to using new nlattr utils 2021-06-20 00:13:43 +00:00
Sean Young 1196ba1dcc Fix doctest and run them during CI
Signed-off-by: Sean Young <sean@mess.org>
2021-06-17 12:14:53 +01:00
Sean Young b49ba69d09 Add support for lirc programs
Signed-off-by: Sean Young <sean@mess.org>
2021-06-16 11:47:03 +01:00
Alessandro Decina be0b7bbd83 Doc fixes 2021-06-15 03:18:20 +00:00
Alessandro Decina 768640dd46 aya: add doc aliases for maps and programs 2021-06-13 20:48:25 +00:00
Alessandro Decina 293e66af65 More docs 2021-06-13 20:48:17 +00:00
Alessandro Decina ad58e171ff aya: refactor tc code a bit and add docs 2021-06-13 11:00:32 +00:00
Alessandro Decina 11e21e83be More docs 2021-06-13 11:00:32 +00:00
Alessandro Decina 6c7df27bd0 More doc fixes 2021-06-11 03:09:18 +00:00
Alessandro Decina 2cda5dbbe7 aya: implement ProgramFd for CgroupSkb 2021-06-10 08:41:53 +00:00