Skip to content

Commit f99db52

Browse files
committed
ksud: add debug insmod
1 parent 9ca9693 commit f99db52

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

userspace/ksud/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ enum Debug {
173173
path: PathBuf,
174174
},
175175

176+
/// Load a kernel module from disk
177+
Insmod {
178+
/// kernel module path
179+
module: PathBuf,
180+
},
181+
176182
/// Process mark management
177183
Mark {
178184
#[command(subcommand)]
@@ -637,6 +643,7 @@ pub fn run() -> Result<()> {
637643
let data = assets::get_asset_data(&name)?;
638644
utils::ensure_binary(&path, &data, false)
639645
}
646+
Debug::Insmod { module } => debug::insmod(&module),
640647
Debug::Mark { command } => match command {
641648
MarkCommand::Get { pid } => debug::mark_get(pid),
642649
MarkCommand::Mark { pid } => debug::mark_set(pid),

userspace/ksud/src/debug.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::{Context, Ok, Result, bail, ensure};
22
use std::{
3+
fs,
34
path::{Path, PathBuf},
45
process::Command,
56
};
@@ -49,6 +50,20 @@ pub fn set_manager(pkg: &str) -> Result<()> {
4950
Ok(())
5051
}
5152

53+
pub fn insmod(module: &Path) -> Result<()> {
54+
let module = module
55+
.canonicalize()
56+
.with_context(|| format!("resolve module path failed: {}", module.display()))?;
57+
let module_data =
58+
fs::read(&module).with_context(|| format!("read module failed: {}", module.display()))?;
59+
60+
ksuinit::load_module(&module_data)
61+
.with_context(|| format!("load module failed: {}", module.display()))?;
62+
63+
println!("Loaded kernel module: {}", module.display());
64+
Ok(())
65+
}
66+
5267
/// Get mark status for a process
5368
pub fn mark_get(pid: i32) -> Result<()> {
5469
let result = ksucalls::mark_get(pid)?;

0 commit comments

Comments
 (0)