From 52096f34c3d1559963f8b372376fe9dfe5b60c79 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 28 Jun 2025 13:42:46 -0700 Subject: [PATCH 1/2] 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. --- src/backend/linux_raw/param/auxv.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/backend/linux_raw/param/auxv.rs b/src/backend/linux_raw/param/auxv.rs index d748219a9..fccfb2bb7 100644 --- a/src/backend/linux_raw/param/auxv.rs +++ b/src/backend/linux_raw/param/auxv.rs @@ -401,15 +401,12 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator) -> Opti AT_HWCAP2 => hwcap2 = a_val as usize, AT_MINSIGSTKSZ => minsigstksz = a_val as usize, AT_EXECFN => execfn = check_raw_pointer::(a_val as *mut _)?.as_ptr(), - AT_SYSINFO_EHDR => sysinfo_ehdr = check_elf_base(a_val as *mut _)?.as_ptr(), - - AT_BASE => { - // The `AT_BASE` value can be null in a static executable that - // doesn't use a dynamic linker. If so, ignore it. - if !a_val.is_null() { - let _ = check_elf_base(a_val.cast())?; - } - } + + // Use the `AT_SYSINFO_EHDR` if it matches the platform rustix is + // compiled for. + AT_SYSINFO_EHDR => if let Some(value) = check_elf_base(a_val as *mut _) { + sysinfo_ehdr = value.as_ptr(); + }, #[cfg(feature = "runtime")] AT_SECURE => secure = (a_val as usize != 0) as u8 + 1, @@ -448,8 +445,7 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator) -> Opti secure = 2; } - // The base and sysinfo_ehdr (if present) matches our platform. Accept the - // aux values. + // Accept the aux values. PAGE_SIZE.store(pagesz, Relaxed); CLOCK_TICKS_PER_SECOND.store(clktck, Relaxed); HWCAP.store(hwcap, Relaxed); From 61121bdf5bfd4f377811a5a1068f53eb4b72e2ef Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 28 Jun 2025 13:52:51 -0700 Subject: [PATCH 2/2] Fix a warning. --- src/backend/linux_raw/param/auxv.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/backend/linux_raw/param/auxv.rs b/src/backend/linux_raw/param/auxv.rs index fccfb2bb7..ca86822f0 100644 --- a/src/backend/linux_raw/param/auxv.rs +++ b/src/backend/linux_raw/param/auxv.rs @@ -22,8 +22,7 @@ use core::sync::atomic::Ordering::Relaxed; use core::sync::atomic::{AtomicPtr, AtomicUsize}; use linux_raw_sys::elf::*; use linux_raw_sys::general::{ - AT_BASE, AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ, - AT_SYSINFO_EHDR, + AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR, }; #[cfg(feature = "runtime")] use linux_raw_sys::general::{ @@ -404,9 +403,11 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator) -> Opti // Use the `AT_SYSINFO_EHDR` if it matches the platform rustix is // compiled for. - AT_SYSINFO_EHDR => if let Some(value) = check_elf_base(a_val as *mut _) { - sysinfo_ehdr = value.as_ptr(); - }, + AT_SYSINFO_EHDR => { + if let Some(value) = check_elf_base(a_val as *mut _) { + sysinfo_ehdr = value.as_ptr(); + } + } #[cfg(feature = "runtime")] AT_SECURE => secure = (a_val as usize != 0) as u8 + 1,