Skip to content

Commit

Permalink
Fix vdso crashes on current Ubuntu.
Browse files Browse the repository at this point in the history
- Remove noops from several vdso stubs to make them shorter.

- Allow new stubs to be a little longer than what they replace if
  it fits given 8-byte alignment.
  • Loading branch information
samth committed Nov 23, 2022
1 parent 6f03658 commit a7f6cae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions reverie-ptrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![feature(internal_output_capture)]
#![feature(never_type)]
#![feature(int_roundings)]

mod children;
mod cp;
Expand Down
15 changes: 4 additions & 11 deletions reverie-ptrace/src/vdso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ mod vdso_syms {
0xb8, 0xe4, 0x00, 0x00, 0x00, // mov SYS_clock_gettime, %eax
0x0f, 0x05, // syscall
0xc3, // retq
0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, // nopl 0x0(%rax, %rax, 1)
0x00,
];

pub const getcpu: &[u8] = &[
Expand All @@ -59,16 +57,12 @@ mod vdso_syms {
0xb8, 0x60, 0x00, 0x00, 0x00, // mov SYS_gettimeofday, %eax
0x0f, 0x05, // syscall
0xc3, // retq
0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, // nopl 0x0(%rax, %rax, 1)
0x00,
];

pub const clock_getres: &[u8] = &[
0xb8, 0xe5, 0x00, 0x00, 0x00, // mov SYS_clock_getres, %eax
0x0f, 0x05, // syscall
0xc3, // retq
0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, // nopl 0x0(%rax, %rax, 1)
0x00,
];
}

Expand Down Expand Up @@ -160,11 +154,11 @@ lazy_static! {
for (k, v) in VDSO_SYMBOLS {
if let Some(&(base, size)) = info.get(*k) {
assert!(
v.len() <= size,
v.len().div_ceil(8) <= size.div_ceil(8),
"vdso symbol {}'s real size is {} bytes, but trying to replace it with {} bytes",
k,
size,
v.len()
size.div_ceil(8),
v.len().div_ceil(8)
);
res.insert(*k, (base, size, *v));
}
Expand Down Expand Up @@ -239,10 +233,9 @@ where

for (name, (offset, size, bytes)) in VDSO_PATCH_INFO.iter() {
let start = vdso.address.0 + offset;
assert!(bytes.len() <= *size);
assert!(bytes.len().div_ceil(8) <= (*size).div_ceil(8));
let rptr = AddrMut::from_raw(start as usize).unwrap();
memory.write_exact(rptr, bytes)?;
assert!(*size >= bytes.len());
if *size > bytes.len() {
let fill: Vec<u8> = std::iter::repeat(0x90u8).take(size - bytes.len()).collect();
memory.write_exact(unsafe { rptr.add(bytes.len()) }, &fill)?;
Expand Down

0 comments on commit a7f6cae

Please sign in to comment.