Skip to content

Commit

Permalink
no failure on init_module failing to read args
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin JEROME <[email protected]>
  • Loading branch information
qjerome committed Oct 10, 2023
1 parent d41d60a commit 76d5ff6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
26 changes: 23 additions & 3 deletions kunai-ebpf/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,36 @@ pub enum ProbeError {
CgroupError(cgroup::Error),
}

#[macro_export]
/// log a ProbeError using Aya log
macro_rules! log_err {
($ctx:expr, $err:expr) => {
//aya_log_ebpf::error!($ctx, "{}: {}", $err.name(), $err.description());
aya_log_ebpf::error!($ctx, "{}", $err.name());
log_err!($ctx, "", $err)
};
($ctx:expr, $msg:expr, $err:expr) => {
if $msg.is_empty() {
aya_log_ebpf::error!($ctx, "{}", $err.name())
} else {
aya_log_ebpf::error!($ctx, "{}: {}", $msg, $err.name())
}
};
}

pub(crate) use log_err;

/// if Result is an Err(BpfError), log it with Aya log
macro_rules! log_result_err {
($ctx:expr, $res:expr) => {
log_result_err!($ctx, "", $res)
};
($ctx:expr, $msg:expr, $res:expr) => {
if let Err(e) = $res {
log_err!($ctx, $msg, e)
}
};
}

pub(crate) use log_result_err;

impl From<syscalls::Error> for ProbeError {
fn from(value: syscalls::Error) -> Self {
Self::SyscallError(value)
Expand Down
16 changes: 12 additions & 4 deletions kunai-ebpf/src/probes/init_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ unsafe fn try_sys_enter_init_module(ctx: &TracePointContext) -> ProbeResult<()>
// setting event data
event.data.umod = args.umod;
event.data.len = args.len;
event
.data
.uargs
.read_user_str_bytes(args.uargs as *const u8)?;

// Aya currently reports an error on empty string being read
// so until Aya is upgraded some errors might pop up while there
// is none.
log_result_err!(
ctx,
"failed to read uargs",
event
.data
.uargs
.read_user_str_bytes(args.uargs as *const u8)
);

INIT_MODULE_TRACKING
.insert(&key, event, 0)
Expand Down

0 comments on commit 76d5ff6

Please sign in to comment.