Skip to content

Commit

Permalink
Make sure that VDSO patch code is properly aligned
Browse files Browse the repository at this point in the history
The code that is injected into the tracee processes' VDSO needs to be 8
byte aligned in order to satisfy conditions imposed by the ptrace
interface on 64 bit architectures. There have been reproducible reports
of that not always being the case:
facebookexperimental/hermit#41. Use an
explicitly aligned data structure to enforce this.

Signed-off-by: Bjoern Doebel <[email protected]>
  • Loading branch information
Bjoern Doebel committed Sep 8, 2023
1 parent e3c9782 commit 02096a3
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions reverie-ptrace/src/vdso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,48 @@ use tracing::debug;
mod vdso_syms {
#![allow(non_upper_case_globals)]

pub const time: &[u8; 8] = &[
#[repr(align(64))]
struct CodeAligned([u8;8]);

const time_code: CodeAligned = CodeAligned([
0xb8, 0xc9, 0x00, 0x00, 0x00, // mov %SYS_time, %eax
0x0f, 0x05, // syscall
0xc3, // retq
];
]);

pub const time: &[u8; 8] = &time_code.0;

pub const clock_gettime: &[u8; 8] = &[
const clock_gettime_code: CodeAligned = CodeAligned([
0xb8, 0xe4, 0x00, 0x00, 0x00, // mov SYS_clock_gettime, %eax
0x0f, 0x05, // syscall
0xc3, // retq
];
]);

pub const clock_gettime: &[u8; 8] = &clock_gettime_code.0;

pub const getcpu: &[u8; 8] = &[
const getcpu_code: CodeAligned = CodeAligned([
0xb8, 0x35, 0x01, 0x00, 0x00, // mov SYS_getcpu, %eax
0x0f, 0x05, // syscall
0xc3, // retq
];
]);

pub const gettimeofday: &[u8; 8] = &[
pub const getcpu: &[u8; 8] = &getcpu_code.0;

const gettimeofday_code: CodeAligned = CodeAligned([
0xb8, 0x60, 0x00, 0x00, 0x00, // mov SYS_gettimeofday, %eax
0x0f, 0x05, // syscall
0xc3, // retq
];
]);

pub const gettimeofday: &[u8; 8] = &gettimeofday_code.0;

pub const clock_getres: &[u8; 8] = &[
const clock_getres_code: CodeAligned = CodeAligned([
0xb8, 0xe5, 0x00, 0x00, 0x00, // mov SYS_clock_getres, %eax
0x0f, 0x05, // syscall
0xc3, // retq
];
]);

pub const clock_getres: &[u8; 8] = &clock_getres_code.0;
}

#[cfg(target_arch = "aarch64")]
Expand Down

0 comments on commit 02096a3

Please sign in to comment.