Commit Graph

62 Commits (b0a4ab5f20b9838d035913e48fc350b97e8e4a06)

Author SHA1 Message Date
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
Mary 5c86b7ee95
Merge pull request #635 from marysaka/misc/aya-obj-enum-public
misc: aya-obj: Make it possible to externally assemble BtfEnum
1 year ago
Mary d9dfd94f29 misc: aya-obj: Make it possible to externally assemble BtfEnum 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
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
dependabot[bot] f5f8083441
build(deps): update hashbrown requirement from 0.13 to 0.14
Updates the requirements on [hashbrown](https://github.com/rust-lang/hashbrown) to permit the latest version.
- [Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/hashbrown/compare/v0.13.1...v0.14.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
1 year ago
dependabot[bot] fa3dd4bef2
build(deps): update rbpf requirement from 0.1.0 to 0.2.0
Updates the requirements on [rbpf](https://github.com/qmonnet/rbpf) to permit the latest version.
- [Commits](https://github.com/qmonnet/rbpf/compare/v0.1.0...v0.2.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
1 year ago
Mary 85ad0197e0
Merge pull request #563 from marysaka/fix/reloc-less-strict
aya-obj: Make relocations less strict
1 year ago
Mary 35eaa50736 aya-obj: Make relocations less strict
Missing relocations at load time shouldn't cause an error in aya-obj
but instead poison related instructions.

This makes struct flavors work.
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
Mary c4e721f3d3 aya: Apply BTF relocations to all functions
This fix aya wrong logic causing non entrypoint functions to not have
any BTF relocations working.

Also fix missing section_offset computation for instruction offset in
multiple spots.
1 year ago
alessandrod 0bc886f163 [codegen] Update libbpf to f7eb43b90f4c8882edf6354f8585094f8f3aade0Update libbpf to f7eb43b90f4c8882edf6354f8585094f8f3aade0
Files changed:
M	aya-obj/src/generated/btf_internal_bindings.rs
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs
M	bpf/aya-bpf-bindings/src/aarch64/bindings.rs
M	bpf/aya-bpf-bindings/src/armv7/bindings.rs
M	bpf/aya-bpf-bindings/src/riscv64/bindings.rs
M	bpf/aya-bpf-bindings/src/x86_64/bindings.rs
1 year ago
Andrés 5894c4ce82
Fix load errors for empty (but existent) BTF/BTF.ext sections (#608)
* use the hdr_len of BTF.ext sections rather than size of struct

Otherwise this will erroneously fail on older btf_ext_header that have
less fields than the bindgen'd struct

* do not attempt to load a BTF object that has no types

* add tests

* fix: hdr_len i32 -> u32

* guard against a bigger header in the future

* use separate unsafe blocks

* simplify writing to zero'd out header

* merge safe block and address typo
1 year ago
Alessandro Decina 5165bf2f99
Merge pull request #585 from probulate/tag-len-value
aya-log-common: support logging byte slices
1 year ago
Alessandro Decina 9c437aafd9
Merge pull request #605 from marysaka/fix/global-data-reloc-ancient-kernels
aya: Do not create data maps on kernel without global data support
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 18b3d75d09 aya-obj: Fix ProgramSection::from_str for bss and rodata sections 1 year ago
Tamir Duberstein 4e2f8322cc
Build tests with all features
Remove mem::forget::<HashMap>() calls in tests which fail to compile when
HashMap is provided by hashbrown:

  info: running `cargo check --all-targets --no-default-features` on aya-obj (11/23)
      Checking aya-obj v0.1.0 (/home/tamird/src/aya/aya-obj)
  error[E0505]: cannot move out of `map` because it is borrowed
     --> aya-obj/src/relocation.rs:594:21
      |
  578 |         let map = fake_legacy_map(1);
      |             --- binding `map` declared here
  579 |         let maps_by_symbol = HashMap::from([(1, ("test_map", Some(1), &map))]);
      |                                                                       ---- borrow of `map` occurs here
  ...
  594 |         mem::forget(map);
      |                     ^^^ move out of `map` occurs here
  595 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_1` because it is borrowed
     --> aya-obj/src/relocation.rs:655:21
      |
  632 |         let map_1 = fake_legacy_map(1);
      |             ----- binding `map_1` declared here
  ...
  635 |             (1, ("test_map_1", Some(1), &map_1)),
      |                                         ------ borrow of `map_1` occurs here
  ...
  655 |         mem::forget(map_1);
      |                     ^^^^^ move out of `map_1` occurs here
  656 |         mem::forget(map_2);
  657 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_2` because it is borrowed
     --> aya-obj/src/relocation.rs:656:21
      |
  633 |         let map_2 = fake_legacy_map(2);
      |             ----- binding `map_2` declared here
  ...
  636 |             (2, ("test_map_2", Some(2), &map_2)),
      |                                         ------ borrow of `map_2` occurs here
  ...
  656 |         mem::forget(map_2);
      |                     ^^^^^ move out of `map_2` occurs here
  657 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map` because it is borrowed
     --> aya-obj/src/relocation.rs:694:21
      |
  678 |         let map = fake_btf_map(1);
      |             --- binding `map` declared here
  679 |         let maps_by_symbol = HashMap::from([(1, ("test_map", Some(1), &map))]);
      |                                                                       ---- borrow of `map` occurs here
  ...
  694 |         mem::forget(map);
      |                     ^^^ move out of `map` occurs here
  695 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_1` because it is borrowed
     --> aya-obj/src/relocation.rs:755:21
      |
  732 |         let map_1 = fake_btf_map(1);
      |             ----- binding `map_1` declared here
  ...
  735 |             (1, ("test_map_1", Some(1), &map_1)),
      |                                         ------ borrow of `map_1` occurs here
  ...
  755 |         mem::forget(map_1);
      |                     ^^^^^ move out of `map_1` occurs here
  756 |         mem::forget(map_2);
  757 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_2` because it is borrowed
     --> aya-obj/src/relocation.rs:756:21
      |
  733 |         let map_2 = fake_btf_map(2);
      |             ----- binding `map_2` declared here
  ...
  736 |             (2, ("test_map_2", Some(2), &map_2)),
      |                                         ------ borrow of `map_2` occurs here
  ...
  756 |         mem::forget(map_2);
      |                     ^^^^^ move out of `map_2` occurs here
  757 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  For more information about this error, try `rustc --explain E0505`.
  error: could not compile `aya-obj` due to 6 previous errors
  warning: build failed, waiting for other jobs to finish...
  error: process didn't exit successfully: `/home/tamird/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo check --all-targets --manifest-path aya-obj/Cargo.toml --no-default-features` (exit status: 101)
1 year ago
Mary 9e1109b3ce aya: Move program's functions to the same map 1 year ago
Kenjiro Nakayama e67025b66f Drop unnecessary mut 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
Alessandro Decina b2d5059ac2
Merge pull request #583 from 0xrawsec/fix-builtin-linkage
Fix builtin linkage
1 year ago
Quentin JEROME 1464bdc1d4 - comment changed to be more precise
- adapted test to be more readable

Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 72c1572178 added memmove, memcmp to the list of function changed to BTF_FUNC_STATIC
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME a51c9bc532 fixed indent
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 5b4fc9ea93 removed useless line break and comments
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 74bc754862 add debug messages
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
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
Quentin JEROME 4e41da6a86 Fixed BTF linkage of memset and memcpy to static
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Mary 4e33fa011e aya-obj: fix DATASEC to STRUCT conversion
This fix the following issues:
- Previously the DATASEC name wasn't sanitized resulting on "Invalid
  name" returned by old kernels.
- The newly created BTF struct had a size of 0 making old kernels refuse
  it.

This was tested on Debian 10 with kernel 4.19.0-21.
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 b25a089819 aya-obj: change two drain() calls to into_iter() 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
Alessandro Decina 5c4f1d69a6 aya-obj: rework `maps` section parsing
Avoid allocations and add comments explaining how things work.
1 year ago
epompeii 85714d5cf3 review 2 years ago
epompeii 6dfb9d82af macro 2 years ago
epompeii 6a25d4ddec obj 2 years ago
Alessandro Decina dfbe1207c1 aya-obj: fix compilation with nightly 2 years ago
dave-tucker 24f15ea25f [codegen] Update libbpf to a41e6ef3251cba858021b90c33abb9efdb17f575Update libbpf to a41e6ef3251cba858021b90c33abb9efdb17f575
Files changed:
M	aya-obj/src/generated/btf_internal_bindings.rs
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs
M	bpf/aya-bpf-bindings/src/aarch64/bindings.rs
M	bpf/aya-bpf-bindings/src/armv7/bindings.rs
M	bpf/aya-bpf-bindings/src/riscv64/bindings.rs
M	bpf/aya-bpf-bindings/src/x86_64/bindings.rs
2 years ago
Dave Tucker 376c486400 aya-bpf: Add multibuffer support for XDP
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker a18693b42d aya: Add support for multibuffer programs
This adds support for loading XDP programs that are multi-buffer
capable, which is signalled using the xdp.frags section name. When this
is set, we should set the BPF_F_XDP_HAS_FRAGS flag when loading the
program into the kernel.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Alessandro Decina 9a6f8143a1 aya: btf: add support for BTF_KIND_ENUM64 2 years ago
Alessandro Decina 4482db42d8 aya: btf: fix relocations for signed enums (32 bits)
Enums now carry a signed bit in the info flags. Take it into account
when applying enum relocations.
2 years ago
Alessandro Decina d6b976c6f1 aya: btf: switch ComputedRelocationValue::value to u64
This is in preparation of adding Enum64 relocation support
2 years ago