Skip to content

Commit 000814c

Browse files
authored
Don't let a mismatch AT_SYSINFO_EHDR image preclude use of AUX values. (#1484)
* Don't let a mismatch AT_SYSINFO_EHDR image preclude use of AUX values. If the ELF image pointed to by the `AT_SYSINFO_EHDR` AUX record doesn't match the architecture rustix is compiled for, don't use it, but do continue to use the rest of the AUX fields. Fixes #1465. * Fix a warning.
1 parent 9c8981f commit 000814c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/backend/linux_raw/param/auxv.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use core::sync::atomic::Ordering::Relaxed;
2222
use core::sync::atomic::{AtomicPtr, AtomicUsize};
2323
use linux_raw_sys::elf::*;
2424
use linux_raw_sys::general::{
25-
AT_BASE, AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ,
26-
AT_SYSINFO_EHDR,
25+
AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR,
2726
};
2827
#[cfg(feature = "runtime")]
2928
use linux_raw_sys::general::{
@@ -401,13 +400,12 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
401400
AT_HWCAP2 => hwcap2 = a_val as usize,
402401
AT_MINSIGSTKSZ => minsigstksz = a_val as usize,
403402
AT_EXECFN => execfn = check_raw_pointer::<c::c_char>(a_val as *mut _)?.as_ptr(),
404-
AT_SYSINFO_EHDR => sysinfo_ehdr = check_elf_base(a_val as *mut _)?.as_ptr(),
405403

406-
AT_BASE => {
407-
// The `AT_BASE` value can be null in a static executable that
408-
// doesn't use a dynamic linker. If so, ignore it.
409-
if !a_val.is_null() {
410-
let _ = check_elf_base(a_val.cast())?;
404+
// Use the `AT_SYSINFO_EHDR` if it matches the platform rustix is
405+
// compiled for.
406+
AT_SYSINFO_EHDR => {
407+
if let Some(value) = check_elf_base(a_val as *mut _) {
408+
sysinfo_ehdr = value.as_ptr();
411409
}
412410
}
413411

@@ -448,8 +446,7 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
448446
secure = 2;
449447
}
450448

451-
// The base and sysinfo_ehdr (if present) matches our platform. Accept the
452-
// aux values.
449+
// Accept the aux values.
453450
PAGE_SIZE.store(pagesz, Relaxed);
454451
CLOCK_TICKS_PER_SECOND.store(clktck, Relaxed);
455452
HWCAP.store(hwcap, Relaxed);

0 commit comments

Comments
 (0)