repro issue #808

Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
pull/810/head
Quentin JEROME 2 years ago
parent 62849944f2
commit 024def8da6

@ -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"

@ -0,0 +1,6 @@
# the bug needs debug info so that it triggers
[profile.release]
debug = true
[profile.dev]
debug = true

@ -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 {}
}

@ -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;

@ -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();
}

Loading…
Cancel
Save