Skip to content

using extern "x86-interrupt" + #[naked] + kernel address sanitizer crashes compiler #129224

Closed

Description

@Freax13

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).

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 18, 2024
  2. added
    A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzS
    A-sanitizersArea: Sanitizers for correctness and code quality
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    O-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)
    A-ABIArea: Concerning the application binary interface (ABI)
    O-bare-metalTarget: Rust without an operating system
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 18, 2024
  3. saethlin commented on Aug 18, 2024

    @saethlin
    Member

    This is an LLVM assertion

    UNREACHABLE executed at /checkout/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1959!
    
  4. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 18, 2024
  5. tgross35 commented on Aug 18, 2024

    @tgross35
    Member

    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

  6. 1 remaining item

  7. workingjubilee commented on Aug 18, 2024

    @workingjubilee
    Member
  8. added
    llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
    on Aug 20, 2024
  9. removed
    llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
    on Sep 2, 2024
  10. nikic commented on Sep 2, 2024

    @nikic
    Contributor

    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.

  11. self-assigned this
    on Sep 2, 2024
  12. added a commit that references this issue on Sep 2, 2024
  13. added a commit that references this issue on Sep 5, 2024
  14. added a commit that references this issue on Sep 6, 2024
  15. added a commit that references this issue on Sep 7, 2024
  16. added a commit that references this issue on Sep 7, 2024
  17. antoniofrighetto commented on Sep 10, 2024

    @antoniofrighetto

    @nikic Should we file an issue upstream to handle this in sanitizers as well, or is there one already opened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-ABIArea: Concerning the application binary interface (ABI)A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSA-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.F-naked_functions`#![feature(naked_functions)]`I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-bare-metalTarget: Rust without an operating systemO-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)PG-exploit-mitigationsProject group: Exploit mitigationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions