Skip to content

Commit

Permalink
fix: [kunai-ebpf] clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: qjerome <qjerome@rawsec.lu>
  • Loading branch information
qjerome committed Apr 17, 2024
1 parent 3e7126f commit bfd630e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
7 changes: 3 additions & 4 deletions kunai-ebpf/src/probes/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ use super::*;

#[kprobe(function = "security_task_alloc")]
pub fn clone_enter_security_task_alloc(ctx: ProbeContext) -> u32 {
let rc = match unsafe { try_enter_wake_up_new_task(&ctx) } {
match unsafe { try_enter_wake_up_new_task(&ctx) } {
Ok(_) => errors::BPF_PROG_SUCCESS,
Err(s) => {
error!(&ctx, s);
errors::BPF_PROG_FAILURE
}
};
rc
}
}

unsafe fn try_enter_wake_up_new_task(ctx: &ProbeContext) -> ProbeResult<()> {
let new_task = task_struct::from_ptr(kprobe_arg!(ctx, 0)?);
let clone_flags = kprobe_arg!(&ctx, 1)?;
let clone_flags = kprobe_arg!(ctx, 1)?;

alloc::init()?;

Expand Down
10 changes: 5 additions & 5 deletions kunai-ebpf/src/probes/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ pub fn net_dns_enter_vfs_read(ctx: ProbeContext) -> u32 {
// many vfs_read ar happening (not only on sockets) so this function
// aims at filtering as much as we can to save only interesting contexts
unsafe fn try_enter_vfs_read(ctx: &ProbeContext) -> ProbeResult<()> {
let file = co_re::file::from_ptr(kprobe_arg!(&ctx, 0)?);
let ubuf: *const u8 = kprobe_arg!(&ctx, 1)?;
let count: size_t = kprobe_arg!(&ctx, 2)?;
let file = co_re::file::from_ptr(kprobe_arg!(ctx, 0)?);
let ubuf: *const u8 = kprobe_arg!(ctx, 1)?;
let count: size_t = kprobe_arg!(ctx, 2)?;

if !file.is_sock().unwrap_or(false) || ubuf.is_null() || count == 0 {
return Ok(());
Expand Down Expand Up @@ -220,7 +220,7 @@ unsafe fn try_enter_sys_recvfrom(ctx: &ProbeContext) -> ProbeResult<()> {
return Ok(());
}

ProbeFn::dns_sys_recv_from.save_ctx(&ctx)?;
ProbeFn::dns_sys_recv_from.save_ctx(ctx)?;

Ok(())
}
Expand Down Expand Up @@ -317,7 +317,7 @@ unsafe fn try_enter_sys_recvmsg(ctx: &ProbeContext) -> ProbeResult<()> {
}

// we save context
ProbeFn::net_dns_sys_recvmsg.save_ctx(&ctx)?;
ProbeFn::net_dns_sys_recvmsg.save_ctx(ctx)?;

Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions kunai-ebpf/src/probes/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ static mut FILE_TRACKING: LruHashMap<FileKey, RW> = LruHashMap::with_max_entries
#[inline(always)]
unsafe fn track_read(file: &co_re::file) -> ProbeResult<()> {
let key = &file_key(file)?;
match FILE_TRACKING.get_ptr_mut(&key) {
match FILE_TRACKING.get_ptr_mut(key) {
Some(rw) => (*rw).0 = true,
None => {
FILE_TRACKING
.insert(&key, &RW(true, false), 0)
.insert(key, &RW(true, false), 0)
.map_err(|_| MapError::InsertFailure)?;
}
}
Expand All @@ -32,11 +32,11 @@ unsafe fn track_read(file: &co_re::file) -> ProbeResult<()> {
#[inline(always)]
unsafe fn track_write(file: &co_re::file) -> ProbeResult<()> {
let key = &file_key(file)?;
match FILE_TRACKING.get_ptr_mut(&key) {
match FILE_TRACKING.get_ptr_mut(key) {
Some(rw) => (*rw).1 = true,
None => {
FILE_TRACKING
.insert(&key, &RW(false, true), 0)
.insert(key, &RW(false, true), 0)
.map_err(|_| MapError::InsertFailure)?;
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ unsafe fn try_security_path_unlink(ctx: &ProbeContext) -> ProbeResult<()> {
// as vfs_unlink can be reached without security_path_unlink being called
// we report error when insertion is failing
PATHS
.insert(&ProbeFn::security_path_unlink.depth_key(), &p, 0)
.insert(&ProbeFn::security_path_unlink.depth_key(), p, 0)
.map_err(|_| MapError::InsertFailure)?;

Ok(())
Expand Down Expand Up @@ -302,7 +302,7 @@ unsafe fn try_vfs_unlink(ctx: &ProbeContext) -> ProbeResult<()> {

let path_key = ProbeFn::security_path_unlink.depth_key();
if let Some(p) = PATHS.get(&path_key) {
e.data.path.copy_from(&p);
e.data.path.copy_from(p);
// make some room in the cache
ignore_result!(PATHS.remove(&path_key));
} else {
Expand Down
4 changes: 2 additions & 2 deletions kunai-ebpf/src/probes/prctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ unsafe fn try_enter_prctl(ctx: &TracePointContext) -> ProbeResult<()> {
// we ignore result as we can check something went wrong when we try to insert argument
ignore_result!(PRCTL_ARGS.insert(&bpf_task_tracking_id(), &args, 0));

return Ok(());
Ok(())
}

#[tracepoint(name = "sys_exit_prctl", category = "syscalls")]
Expand Down Expand Up @@ -73,5 +73,5 @@ unsafe fn try_exit_prctl(ctx: &TracePointContext) -> ProbeResult<()> {
// cleanup prctl arguments no need to handle failure
ignore_result!(PRCTL_ARGS.remove(&key));

return Ok(());
Ok(())
}

0 comments on commit bfd630e

Please sign in to comment.