Skip to content

Commit

Permalink
guard vdso overwrites with a static mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVentura committed Mar 28, 2024
1 parent b8834a2 commit 009cc1d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vdso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use core::slice;
use std::error::Error;
use std::fs;
use cacheflush_sys;
use std::sync::Mutex;

static vdso_mutex: Mutex<i32> = Mutex::new(0);

#[derive(Debug, PartialEq)]
pub(crate) struct DynSym {
Expand Down Expand Up @@ -107,6 +110,8 @@ impl vDSO {
/// It is the caller's responsibility to provide the correct amount of data.
pub(crate) fn overwrite(&self, symbol_address: usize, opcodes: &[u8]) {
let dst_addr = self.avv.vdso_base + symbol_address;

let _guard = vdso_mutex.lock().unwrap();
self.change_mode(true);
unsafe {
std::ptr::copy_nonoverlapping(opcodes.as_ptr(), dst_addr as *mut u8, opcodes.len())
Expand Down

0 comments on commit 009cc1d

Please sign in to comment.