|
|
@ -6,7 +6,6 @@ use aya::{
|
|
|
|
programs::{ProgramError, UProbe},
|
|
|
|
programs::{ProgramError, UProbe},
|
|
|
|
Bpf,
|
|
|
|
Bpf,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use integration_test_macros::integration_test;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const RESULT_BUF_LEN: usize = 1024;
|
|
|
|
const RESULT_BUF_LEN: usize = 1024;
|
|
|
|
|
|
|
|
|
|
|
@ -20,13 +19,13 @@ struct TestResult {
|
|
|
|
|
|
|
|
|
|
|
|
unsafe impl aya::Pod for TestResult {}
|
|
|
|
unsafe impl aya::Pod for TestResult {}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_user_str_bytes() {
|
|
|
|
fn bpf_probe_read_user_str_bytes() {
|
|
|
|
let bpf = set_user_buffer(b"foo\0", RESULT_BUF_LEN);
|
|
|
|
let bpf = set_user_buffer(b"foo\0", RESULT_BUF_LEN);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"foo");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"foo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_user_str_bytes_truncate() {
|
|
|
|
fn bpf_probe_read_user_str_bytes_truncate() {
|
|
|
|
let s = vec![b'a'; RESULT_BUF_LEN];
|
|
|
|
let s = vec![b'a'; RESULT_BUF_LEN];
|
|
|
|
let bpf = set_user_buffer(&s, RESULT_BUF_LEN);
|
|
|
|
let bpf = set_user_buffer(&s, RESULT_BUF_LEN);
|
|
|
@ -34,25 +33,25 @@ fn bpf_probe_read_user_str_bytes_truncate() {
|
|
|
|
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
|
|
|
|
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_user_str_bytes_empty_string() {
|
|
|
|
fn bpf_probe_read_user_str_bytes_empty_string() {
|
|
|
|
let bpf = set_user_buffer(b"\0", RESULT_BUF_LEN);
|
|
|
|
let bpf = set_user_buffer(b"\0", RESULT_BUF_LEN);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_user_str_bytes_empty_dest() {
|
|
|
|
fn bpf_probe_read_user_str_bytes_empty_dest() {
|
|
|
|
let bpf = set_user_buffer(b"foo\0", 0);
|
|
|
|
let bpf = set_user_buffer(b"foo\0", 0);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_kernel_str_bytes() {
|
|
|
|
fn bpf_probe_read_kernel_str_bytes() {
|
|
|
|
let bpf = set_kernel_buffer(b"foo\0", RESULT_BUF_LEN);
|
|
|
|
let bpf = set_kernel_buffer(b"foo\0", RESULT_BUF_LEN);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"foo");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"foo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_truncate() {
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_truncate() {
|
|
|
|
let s = vec![b'a'; RESULT_BUF_LEN];
|
|
|
|
let s = vec![b'a'; RESULT_BUF_LEN];
|
|
|
|
let bpf = set_kernel_buffer(&s, RESULT_BUF_LEN);
|
|
|
|
let bpf = set_kernel_buffer(&s, RESULT_BUF_LEN);
|
|
|
@ -60,13 +59,13 @@ fn bpf_probe_read_kernel_str_bytes_truncate() {
|
|
|
|
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
|
|
|
|
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_empty_string() {
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_empty_string() {
|
|
|
|
let bpf = set_kernel_buffer(b"\0", RESULT_BUF_LEN);
|
|
|
|
let bpf = set_kernel_buffer(b"\0", RESULT_BUF_LEN);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[integration_test]
|
|
|
|
#[test]
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_empty_dest() {
|
|
|
|
fn bpf_probe_read_kernel_str_bytes_empty_dest() {
|
|
|
|
let bpf = set_kernel_buffer(b"foo\0", 0);
|
|
|
|
let bpf = set_kernel_buffer(b"foo\0", 0);
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
|
assert_eq!(result_bytes(&bpf), b"");
|
|
|
@ -76,7 +75,7 @@ fn set_user_buffer(bytes: &[u8], dest_len: usize) -> Bpf {
|
|
|
|
let bpf = load_and_attach_uprobe(
|
|
|
|
let bpf = load_and_attach_uprobe(
|
|
|
|
"test_bpf_probe_read_user_str_bytes",
|
|
|
|
"test_bpf_probe_read_user_str_bytes",
|
|
|
|
"trigger_bpf_probe_read_user",
|
|
|
|
"trigger_bpf_probe_read_user",
|
|
|
|
include_bytes_aligned!("../../../../target/bpfel-unknown-none/release/bpf_probe_read"),
|
|
|
|
include_bytes_aligned!("../../../target/bpfel-unknown-none/release/bpf_probe_read"),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
trigger_bpf_probe_read_user(bytes.as_ptr(), dest_len);
|
|
|
|
trigger_bpf_probe_read_user(bytes.as_ptr(), dest_len);
|
|
|
|
bpf
|
|
|
|
bpf
|
|
|
@ -86,7 +85,7 @@ fn set_kernel_buffer(bytes: &[u8], dest_len: usize) -> Bpf {
|
|
|
|
let mut bpf = load_and_attach_uprobe(
|
|
|
|
let mut bpf = load_and_attach_uprobe(
|
|
|
|
"test_bpf_probe_read_kernel_str_bytes",
|
|
|
|
"test_bpf_probe_read_kernel_str_bytes",
|
|
|
|
"trigger_bpf_probe_read_kernel",
|
|
|
|
"trigger_bpf_probe_read_kernel",
|
|
|
|
include_bytes_aligned!("../../../../target/bpfel-unknown-none/release/bpf_probe_read"),
|
|
|
|
include_bytes_aligned!("../../../target/bpfel-unknown-none/release/bpf_probe_read"),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
set_kernel_buffer_element(&mut bpf, bytes);
|
|
|
|
set_kernel_buffer_element(&mut bpf, bytes);
|
|
|
|
trigger_bpf_probe_read_kernel(dest_len);
|
|
|
|
trigger_bpf_probe_read_kernel(dest_len);
|