diff --git a/bpf/aya-bpf/src/args.rs b/bpf/aya-bpf/src/args.rs index 179bfa87..a766c76b 100644 --- a/bpf/aya-bpf/src/args.rs +++ b/bpf/aya-bpf/src/args.rs @@ -149,7 +149,9 @@ impl FromPtRegs for *const T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { unsafe { - let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; + let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong) + .try_into() + .unwrap(); bpf_probe_read(addr as *const T) .map(|v| &v as *const _) .ok() @@ -173,7 +175,7 @@ impl FromPtRegs for *const T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { unsafe { - let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; + let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong; bpf_probe_read(addr as *const T) .map(|v| &v as *const _) .ok() @@ -201,6 +203,15 @@ impl FromPtRegs for *const T { } } + fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { + unsafe { + let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; + bpf_probe_read(addr as *const T) + .map(|v| &v as *const _) + .ok() + } + } + fn from_retval(ctx: &pt_regs) -> Option { unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *const _).ok() } } @@ -246,7 +257,9 @@ impl FromPtRegs for *mut T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { unsafe { - let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; + let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong) + .try_into() + .unwrap(); bpf_probe_read(addr as *mut T) .map(|mut v| &mut v as *mut _) .ok() @@ -270,7 +283,7 @@ impl FromPtRegs for *mut T { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { unsafe { - let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; + let addr: c_ulonglong = (ctx.sp + 8 * (n + 1) as u64) as c_ulonglong; bpf_probe_read(addr as *mut T) .map(|mut v| &mut v as *mut _) .ok() @@ -298,6 +311,15 @@ impl FromPtRegs for *mut T { } } + fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { + unsafe { + let addr: c_ulonglong = ctx.sp + 8 * (n + 1) as c_ulonglong; + bpf_probe_read(addr as *mut T) + .map(|mut v| &mut v as *mut _) + .ok() + } + } + fn from_retval(ctx: &pt_regs) -> Option { unsafe { bpf_probe_read(&ctx.ra).map(|v| v as *mut _).ok() } } @@ -346,7 +368,9 @@ macro_rules! impl_from_pt_regs { fn from_stack_argument(ctx: &pt_regs, n: usize) -> Option { unsafe { - let addr: c_ulonglong = ctx.uregs[13] + 8 * (n + 1) as c_ulonglong; + let addr: c_ulonglong = (ctx.uregs[13] + 8 * (n + 1) as c_ulonglong) + .try_into() + .unwrap(); bpf_probe_read(addr as *const $type) .map(|v| v as $type) .ok() diff --git a/test/integration-ebpf/Cargo.toml b/test/integration-ebpf/Cargo.toml index ae938675..bf54af0f 100644 --- a/test/integration-ebpf/Cargo.toml +++ b/test/integration-ebpf/Cargo.toml @@ -28,6 +28,10 @@ path = "src/name_test.rs" name = "pass" path = "src/pass.rs" +[[bin]] +name = "stack_argument" +path = "src/stack_argument.rs" + [[bin]] name = "test" path = "src/test.rs" @@ -50,8 +54,4 @@ path = "src/redirect.rs" [[bin]] name = "xdp_sec" -path = "src/xdp_sec.rs" - -[[bin]] -name = "stack_argument" -path = "src/stack_argument.rs" \ No newline at end of file +path = "src/xdp_sec.rs" \ No newline at end of file diff --git a/test/integration-test/src/tests/stack_argument.rs b/test/integration-test/src/tests/stack_argument.rs index b9610f4e..1a5e6f8d 100644 --- a/test/integration-test/src/tests/stack_argument.rs +++ b/test/integration-test/src/tests/stack_argument.rs @@ -1,15 +1,4 @@ -use aya::{ - include_bytes_aligned, - maps::{AsyncPerfEventArray, HashMap}, - programs::UProbe, - util::online_cpus, - Bpf, -}; -use aya_log::BpfLogger; -use bytes::BytesMut; -use log::warn; - -use crate::STACK_ARGUMENT; +use aya::{maps::HashMap, programs::UProbe, Bpf}; #[no_mangle] #[inline(never)] @@ -33,7 +22,6 @@ pub extern "C" fn trigger_stack_argument( #[tokio::test] async fn stack_argument() { - event_logger::init(); let mut bpf = Bpf::load(crate::STACK_ARGUMENT).unwrap(); let prog: &mut UProbe = bpf