generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into uprobes_frontend
Signed-off-by: Felix Hilgers <[email protected]>
- Loading branch information
Showing
18 changed files
with
177 additions
and
69 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
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
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
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,4 +1,6 @@ | ||
// SPDX-FileCopyrightText: 2024 Felix Hilgers <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Benedikt Zinn <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Robin Seidl <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
|
@@ -12,9 +14,10 @@ use tokio::io::unix::AsyncFd; | |
use tokio::{join, select}; | ||
use tonic::Status; | ||
use tracing::error; | ||
use backend_common::{SysSendmsgCall, VfsWriteCall}; | ||
use shared::ziofa::{Event, SysSendmsgEvent, VfsWriteEvent}; | ||
use backend_common::{JNICall, JNIMethodName, SysSendmsgCall, VfsWriteCall}; | ||
use shared::ziofa::{Event, JniReferencesEvent, SysSendmsgEvent, VfsWriteEvent}; | ||
use shared::ziofa::event::{EventData}; | ||
use shared::ziofa::jni_references_event; | ||
|
||
pub trait CollectFromMap { | ||
const MAP_NAME: &'static str; | ||
|
@@ -23,6 +26,8 @@ pub trait CollectFromMap { | |
} | ||
|
||
struct VfsWriteCollect; | ||
struct JNICollect; | ||
struct SysSendmsgCollect; | ||
|
||
impl CollectFromMap for VfsWriteCollect { | ||
const MAP_NAME: &'static str = "VFS_WRITE_EVENTS"; | ||
|
@@ -41,7 +46,31 @@ impl CollectFromMap for VfsWriteCollect { | |
} | ||
} | ||
|
||
struct SysSendmsgCollect; | ||
impl CollectFromMap for JNICollect { | ||
const MAP_NAME: &'static str = "JNI_REF_CALLS"; | ||
|
||
fn convert(item: RingBufItem<'_>) -> Result<Event, Status> { | ||
let data = unsafe { &*(item.as_ptr() as *const JNICall) }; | ||
|
||
// manual cast from the ebpf (c rep.) typ to protobuf (rust rep.) type | ||
let jni_method_name = match data.method_name { | ||
JNIMethodName::AddLocalRef => jni_references_event::JniMethodName::AddLocalRef, | ||
JNIMethodName::DeleteLocalRef => jni_references_event::JniMethodName::DeleteLocalRef, | ||
JNIMethodName::AddGlobalRef => jni_references_event::JniMethodName::AddGlobalRef, | ||
JNIMethodName::DeleteGlobalRef => jni_references_event::JniMethodName::DeleteGlobalRef, | ||
}; | ||
|
||
Ok(Event { | ||
event_data: Some(EventData::JniReferences(JniReferencesEvent { | ||
pid: data.pid, | ||
tid: data.tid, | ||
begin_time_stamp: data.begin_time_stamp, | ||
jni_method_name: i32::from(jni_method_name), | ||
})) | ||
}) | ||
} | ||
} | ||
|
||
|
||
impl CollectFromMap for SysSendmsgCollect { | ||
const MAP_NAME: &'static str = "SYS_SENDMSG_EVENTS"; | ||
|
@@ -63,19 +92,22 @@ impl CollectFromMap for SysSendmsgCollect { | |
pub struct MultiCollector { | ||
vfs_write: Option<Collector<VfsWriteCollect>>, | ||
sys_sendmsg: Option<Collector<SysSendmsgCollect>>, | ||
jni_event: Option<Collector<JNICollect>>, | ||
} | ||
|
||
impl MultiCollector { | ||
pub fn from_ebpf(ebpf: &mut Ebpf) -> Result<Self, MapError> { | ||
let vfs_write = Collector::<VfsWriteCollect>::from_ebpf(ebpf)?; | ||
let sys_sendmsg = Collector::<SysSendmsgCollect>::from_ebpf(ebpf)?; | ||
Ok(Self { vfs_write: Some(vfs_write), sys_sendmsg: Some(sys_sendmsg) }) | ||
let jni_collect = Collector::<JNICollect>::from_ebpf(ebpf)?; | ||
Ok(Self { vfs_write: Some(vfs_write), sys_sendmsg: Some(sys_sendmsg), jni_event: Some(jni_collect) }) | ||
} | ||
|
||
pub async fn collect(&mut self, tx: Sender<Result<Event, Status>>, shutdown: tokio::sync::oneshot::Receiver<()>) -> Result<(), std::io::Error> { | ||
|
||
let (vfs_write_shutdown_tx, vfs_write_shutdown_rx) = tokio::sync::oneshot::channel(); | ||
let (sys_sendmsg_shutdown_tx, sys_sendmsg_shutdown_rx) = tokio::sync::oneshot::channel(); | ||
let (jni_event_shutdown_tx, jni_event_shutdown_rx) = tokio::sync::oneshot::channel(); | ||
|
||
let cancellation_task = async move { | ||
if shutdown.await.is_err() { | ||
|
@@ -87,6 +119,9 @@ impl MultiCollector { | |
if sys_sendmsg_shutdown_tx.send(()).is_err() { | ||
error!("Error while cancelling sys_sendmsg collector"); | ||
} | ||
if jni_event_shutdown_tx.send(()).is_err() { | ||
error!("Error while cancelling sys_sendmsg collector"); | ||
} | ||
}; | ||
|
||
let vfs_write_tx = tx.clone(); | ||
|
@@ -96,22 +131,31 @@ impl MultiCollector { | |
Ok::<(), std::io::Error>(()) | ||
}; | ||
|
||
let sys_sendmsg_tx = tx; | ||
let sys_sendmsg_tx = tx.clone(); | ||
let mut sys_sendmsg = self.sys_sendmsg.take().expect("sys_sendmsg should be initialized"); | ||
let sys_sendmsg_task = async { | ||
sys_sendmsg.collect(sys_sendmsg_tx, sys_sendmsg_shutdown_rx).await?; | ||
Ok::<(), std::io::Error>(()) | ||
}; | ||
|
||
let jni_event_tx = tx; | ||
let mut jni_event = self.jni_event.take().expect("jni_event should be initialized"); | ||
let jni_event_task = async { | ||
jni_event.collect(jni_event_tx, jni_event_shutdown_rx).await?; | ||
Ok::<(), std::io::Error>(()) | ||
}; | ||
|
||
let (_, vfs_write_result, sys_sendmsg_result) = join!(cancellation_task, vfs_write_task, sys_sendmsg_task); | ||
let (_, vfs_write_result, sys_sendmsg_result, jni_event_result) = join!(cancellation_task, vfs_write_task, sys_sendmsg_task, jni_event_task); | ||
|
||
self.vfs_write = Some(vfs_write); | ||
self.sys_sendmsg = Some(sys_sendmsg); | ||
self.jni_event = Some(jni_event); | ||
|
||
// TODO: multiple errors | ||
vfs_write_result?; | ||
sys_sendmsg_result?; | ||
|
||
jni_event_result?; | ||
|
||
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
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
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
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
Oops, something went wrong.