-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The previously used ASM probe didn't work reliably on new kernels, which were rejecting the program, because of lack of valid function pointer being used as a callback. Introduce a small C probe which has a minimal, but valid `bpf_loop` call. Fixes #300
- Loading branch information
1 parent
2516bca
commit 2e175fe
Showing
4 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
bpf_builder::build("test_lsm", "src/test_lsm.bpf.c") | ||
bpf_builder::build("test_bpf_loop", "src/test_bpf_loop.bpf.c")?; | ||
bpf_builder::build("test_lsm", "src/test_lsm.bpf.c")?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use aya::{include_bytes_aligned, programs::TracePoint, Bpf, BpfError}; | ||
use log::warn; | ||
|
||
fn load_probe() -> Result<(), BpfError> { | ||
let mut bpf = Bpf::load(include_bytes_aligned!(concat!( | ||
env!("OUT_DIR"), | ||
"/test_bpf_loop.none.bpf.o" | ||
)))?; | ||
let program: &mut TracePoint = bpf.program_mut("probe_bpf_loop").unwrap().try_into()?; | ||
program.load()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn bpf_loop_supported() -> bool { | ||
match load_probe() { | ||
Ok(_) => true, | ||
Err(e) => { | ||
let err_msg = "`bpf_loop` helper is not supported by the kernel"; | ||
|
||
if let Ok(true) = std::env::var("RUST_BACKTRACE").map(|s| s == "1") { | ||
warn!("{err_msg}: {e}"); | ||
} else { | ||
warn!("{err_msg}"); | ||
} | ||
|
||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "vmlinux.h" | ||
#include <bpf/bpf_helpers.h> | ||
|
||
static int callback(void *ctx, u32 index) { | ||
return 0; | ||
} | ||
|
||
SEC("tracepoint") | ||
int probe_bpf_loop(void *ctx) { | ||
bpf_loop(5, callback, NULL, 0); | ||
return 0; | ||
} |