Skip to content

Commit fbcff15

Browse files
authored
Rollup merge of rust-lang#138002 - 1c3t3a:fix-std-cfi-violation, r=rcvalle
Disable CFI for weakly linked syscalls Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g. std::sys::random::getrandom, we can observe a CFI violation. This is the case for all consumers of the std::sys::pal::weak::syscall macro, as it is defining weak functions which don't show up in LLVM IR metadata. CFI fails for all these functions. Similar to other such cases in rust-lang#115199, this change stops emitting the CFI typecheck for consumers of the macro via the `#[no_sanitize(cfi)]` attribute. r? ``````@rcvalle``````
2 parents 7dfdb32 + b6daa44 commit fbcff15

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

std/src/sys/fs/unix.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,20 @@ impl File {
14541454
Ok(())
14551455
}
14561456

1457+
// FIXME(#115199): Rust currently omits weak function definitions
1458+
// and its metadata from LLVM IR.
1459+
#[cfg_attr(
1460+
any(
1461+
target_os = "android",
1462+
all(
1463+
target_os = "linux",
1464+
target_env = "gnu",
1465+
target_pointer_width = "32",
1466+
not(target_arch = "riscv32")
1467+
)
1468+
),
1469+
no_sanitize(cfi)
1470+
)]
14571471
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
14581472
#[cfg(not(any(
14591473
target_os = "redox",

std/src/sys/pal/unix/fd.rs

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ impl FileDesc {
251251
}
252252

253253
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
254+
// FIXME(#115199): Rust currently omits weak function definitions
255+
// and its metadata from LLVM IR.
256+
#[no_sanitize(cfi)]
254257
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
255258
super::weak::weak!(fn preadv64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
256259

std/src/sys/pal/unix/process/process_unix.rs

+3
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ impl Command {
434434
target_os = "nto",
435435
target_vendor = "apple",
436436
))]
437+
// FIXME(#115199): Rust currently omits weak function definitions
438+
// and its metadata from LLVM IR.
439+
#[cfg_attr(target_os = "linux", no_sanitize(cfi))]
437440
fn posix_spawn(
438441
&mut self,
439442
stdio: &ChildPipes,

std/src/sys/pal/unix/thread.rs

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ impl Thread {
188188
}
189189

190190
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
191+
// FIXME(#115199): Rust currently omits weak function definitions
192+
// and its metadata from LLVM IR.
193+
#[no_sanitize(cfi)]
191194
pub fn set_name(name: &CStr) {
192195
weak! {
193196
fn pthread_setname_np(

std/src/sys/pal/unix/time.rs

+11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ impl Timespec {
9696
}
9797
}
9898

99+
// FIXME(#115199): Rust currently omits weak function definitions
100+
// and its metadata from LLVM IR.
101+
#[cfg_attr(
102+
all(
103+
target_os = "linux",
104+
target_env = "gnu",
105+
target_pointer_width = "32",
106+
not(target_arch = "riscv32")
107+
),
108+
no_sanitize(cfi)
109+
)]
99110
pub fn now(clock: libc::clockid_t) -> Timespec {
100111
use crate::mem::MaybeUninit;
101112
use crate::sys::cvt;

std/src/sys/pal/unix/weak.rs

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
144144
#[cfg(not(any(target_os = "linux", target_os = "android")))]
145145
pub(crate) macro syscall {
146146
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
147+
// FIXME(#115199): Rust currently omits weak function definitions
148+
// and its metadata from LLVM IR.
149+
#[no_sanitize(cfi)]
147150
unsafe fn $name($($arg_name: $t),*) -> $ret {
148151
weak! { fn $name($($t),*) -> $ret }
149152

0 commit comments

Comments
 (0)