Skip to content

Commit

Permalink
fix: undefined behavior ebpf
Browse files Browse the repository at this point in the history
  • Loading branch information
fhilgers committed Dec 10, 2024
1 parent 711dd11 commit 59d002c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
11 changes: 6 additions & 5 deletions rust/backend/ebpf/src/jni_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

use core::mem;
use core::{mem, ptr::addr_of_mut};
use aya_ebpf::{maps::RingBuf, macros::{uprobe, map}, programs::{ProbeContext}, EbpfContext, helpers::bpf_ktime_get_ns};
use aya_ebpf::maps::HashMap;
use aya_log_ebpf::error;
Expand Down Expand Up @@ -38,10 +38,11 @@ fn handle_trace(ctx: ProbeContext, method: JNIMethodName) -> u32 {
let entry_mut = entry.as_mut_ptr();

unsafe {
(*entry_mut).pid = pid;
(*entry_mut).tid = tid;
(*entry_mut).begin_time_stamp = time_stamp;
(*entry_mut).method_name = method;
(&raw mut (*entry_mut).pid).write(pid);
(&raw mut (*entry_mut).pid).write(pid);
(&raw mut (*entry_mut).tid).write(tid);
(&raw mut (*entry_mut).begin_time_stamp).write(time_stamp);
(&raw mut (*entry_mut).method_name).write(method);
}

entry.submit(0);
Expand Down
14 changes: 7 additions & 7 deletions rust/backend/ebpf/src/sys_sendmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

use core::ptr::addr_of_mut;

use aya_ebpf::{macros::{tracepoint, map}, maps::{HashMap, RingBuf}, programs::{TracePointContext}, EbpfContext, helpers::gen::bpf_ktime_get_ns};
use aya_log_ebpf::error;
use backend_common::{generate_id, SysSendmsgCall};
Expand Down Expand Up @@ -84,16 +86,14 @@ pub fn sys_exit_sendmsg(ctx: TracePointContext) -> u32 {
let entry_mut = entry.as_mut_ptr();

unsafe {
(*entry_mut).pid = pid;
(*entry_mut).tid = tid;
(*entry_mut).begin_time_stamp = data.begin_time_stamp;
(*entry_mut).fd = data.fd;
(*entry_mut).duration_nano_sec = duration_nano_sec;
(&raw mut (*entry_mut).pid).write(pid);
(&raw mut (*entry_mut).tid).write(tid);
(&raw mut (*entry_mut).begin_time_stamp).write(data.begin_time_stamp);
(&raw mut (*entry_mut).fd).write(data.fd);
(&raw mut (*entry_mut).duration_nano_sec).write(duration_nano_sec);
}


entry.submit(0);


0
}
15 changes: 8 additions & 7 deletions rust/backend/ebpf/src/vfs_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

use core::ptr::addr_of_mut;

use aya_ebpf::{
macros::{kprobe, map, kretprobe},
maps::{HashMap, RingBuf},
Expand Down Expand Up @@ -97,14 +99,13 @@ pub fn vfs_write_ret(ctx: RetProbeContext) -> Result<(), u32> {
};

let entry_mut = entry.as_mut_ptr();

unsafe {
(*entry_mut).pid = pid;
(*entry_mut).tid = tid;
(*entry_mut).begin_time_stamp = data.begin_time_stamp;
(*entry_mut).fp = data.fp;
(*entry_mut).bytes_written = data.bytes_written;

(&raw mut (*entry_mut).pid).write(pid);
(&raw mut (*entry_mut).tid).write(tid);
(&raw mut (*entry_mut).begin_time_stamp).write(data.begin_time_stamp);
(&raw mut (*entry_mut).fp).write(data.fp);
(&raw mut (*entry_mut).bytes_written).write(data.bytes_written);
}

entry.submit(0);
Expand Down

0 comments on commit 59d002c

Please sign in to comment.