Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repro issue #808 #810

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/integration-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ path = "src/xdp_sec.rs"
[[bin]]
name = "ring_buf"
path = "src/ring_buf.rs"

[[bin]]
name = "log_str_random"
path = "src/repro/log_str_random.rs"
6 changes: 6 additions & 0 deletions test/integration-ebpf/src/repro/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# the bug needs debug info so that it triggers
[profile.release]
debug = true

[profile.dev]
debug = true
47 changes: 47 additions & 0 deletions test/integration-ebpf/src/repro/log_str_random.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// this file aims at reproducing the bug reported here: https://github.com/aya-rs/aya/issues/808
#![no_std]
#![no_main]

use aya_bpf::{helpers::bpf_get_prandom_u32, macros::kprobe, programs::ProbeContext};
use aya_log_ebpf::error;

#[repr(C)]
enum Error {
Foo,
Bar,
}

impl Error {
const fn into_str(self) -> &'static str {
match self {
Self::Foo => "foo",
Self::Bar => "bar",
}
}
}

#[kprobe]
pub fn log_str_random(ctx: ProbeContext) -> u32 {
match try_log_str_random(ctx) {
Ok(ret) => ret,
Err(ret) => ret,
}
}

fn try_log_str_random(ctx: ProbeContext) -> Result<u32, u32> {
let err = {
if unsafe { bpf_get_prandom_u32() } % 2 == 0 {
Error::Bar
} else {
Error::Foo
}
};
error!(&ctx, "{}", err.into_str());
Ok(0)
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
1 change: 1 addition & 0 deletions test/integration-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub const BPF_PROBE_READ: &[u8] =
pub const REDIRECT: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/redirect"));
pub const XDP_SEC: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/xdp_sec"));
pub const RING_BUF: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/ring_buf"));
pub const LOG_STR_RAND: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/log_str_random"));

#[cfg(test)]
mod tests;
Expand Down
16 changes: 16 additions & 0 deletions test/integration-test/src/tests/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,19 @@ fn pin_lifecycle_uprobe() {
// Make sure the function isn't optimized out.
uprobe_function();
}

#[test]
fn log_str_random() {
// userland code to reproduce bug reported here: https://github.com/aya-rs/aya/issues/808
// To reproduce the bug, eBPF code needs to be built with a custom
// bpf-linker from the feature/fix-di branch. Additionally, eBPF program
// needs to be built with debug information.
let mut bpf = Bpf::load(crate::LOG_STR_RAND).unwrap();
let prog: &mut KProbe = bpf
.program_mut("log_str_random")
.unwrap()
.try_into()
.unwrap();
prog.load().unwrap();
prog.attach("schedule", 0).unwrap();
}