Repository navigation
using extern "x86-interrupt" + #[naked] + kernel address sanitizer crashes compiler #129224
Copy link
Copy link
Closed
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSA-sanitizersArea: Sanitizers for correctness and code qualityArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.Category: This is a bug.F-naked_functions`#![feature(naked_functions)]``#![feature(naked_functions)]`I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-bare-metalTarget: Rust without an operating systemTarget: Rust without an operating systemO-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)PG-exploit-mitigationsProject group: Exploit mitigationsProject group: Exploit mitigationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
#![no_std]
#![feature(abi_x86_interrupt)]
#![feature(naked_functions)]
#[naked]
pub extern "x86-interrupt" fn page_fault_handler(_: u64, _: u64) {
unsafe {
core::arch::asm!("ud2", options(noreturn));
}
}And compiled it with --target x86_64-unknown-none -Zsanitizer=kernel-address.
I expected to see this happen: The compiler should generate a function page_fault_handler which only contains the ud2 instruction.
Instead, this happened: The compiler crashes with SIGILL.
Meta
rustc --version --verbose:
rustc 1.82.0-nightly (506052d49 2024-08-16)
binary: rustc
commit-hash: 506052d49d3903ea554e4ce760cc53610cff4ef5
commit-date: 2024-08-16
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
As requested in #127853 (comment).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSA-sanitizersArea: Sanitizers for correctness and code qualityArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.Category: This is a bug.F-naked_functions`#![feature(naked_functions)]``#![feature(naked_functions)]`I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-bare-metalTarget: Rust without an operating systemTarget: Rust without an operating systemO-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)PG-exploit-mitigationsProject group: Exploit mitigationsProject group: Exploit mitigationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
saethlin commentedon Aug 18, 2024
This is an LLVM assertion
tgross35 commentedon Aug 18, 2024
It was noted in #127853 (comment) that this comes from sanitizer annotations being added to naked functions. Seems like we might not want to do that? Cc @rust-lang/project-exploit-mitigations
1 remaining item
workingjubilee commentedon Aug 18, 2024
Reported at llvm/llvm-project#104718
nikic commentedon Sep 2, 2024
To clarify, the fix that landed is just to make this an IR verification failure rather than a backend crash. The underlying issue with the kasan + naked combination still needs to be fixed.
Do not request sanitizers for naked functions
Rollup merge of rust-lang#129891 - nikic:naked-no-san, r=jackh726
Do not request sanitizers for naked functions
Rollup merge of rust-lang#129891 - nikic:naked-no-san, r=jackh726
Do not request sanitizers for naked functions
Auto merge of rust-lang#129891 - nikic:naked-no-san, r=<try>
Rollup merge of rust-lang#129891 - nikic:naked-no-san, r=jackh726
Unrolled build for rust-lang#129891
antoniofrighetto commentedon Sep 10, 2024
@nikic Should we file an issue upstream to handle this in sanitizers as well, or is there one already opened?