-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RUSTFLAGS="-Z cf-protection=full" gives prologue in naked functions for x86_64-unknown-none #98768
Comments
CC @npmccallum |
Not immediately clear which one is the bug. Naked functions are supposed to be prologue-free in the sense of having no instructions that e.g. modify parameter passing, but To clarify: Do you want the ability to make a naked function that, with CET enabled, cannot be indirectly branched to without IBT kicking in, then? |
either way, it would be nice to have a |
In my case I was resembling the reset vector page with a naked function, so any addition voids the expectation. I can live with the |
This is not the definition of constrained naked functions that has been adopted via the RFC. That definition is stronger and insists that no instructions are emitted before the inline assembly in naked functions. The reason for this is obvious: any other behavior creates an unknown set of interactions between the generated instructions multiplied across all possible compiler features. The author that chooses a naked function gets no help from the compiler and has to implement all such features manually. This is the only way to control the interactions. (Note that the author CAN detect, using compile-time features whether to emit a CET-enabled block of asm or not.) |
Fair enough. 🤔 Then the question is, why would this happen with the ...Actually, checking Godbolt, there seems to be no difference? So that answers that. It might also be useful to query upstream with LLVM as well if this is intended behavior on their part to begin with, as it's not clear to me that LLVM's |
I have a patch which fixes this for x86, but with rust_begin_unwind:
hint #34
b .LBB0_1
.LBB0_1:
b .LBB0_1
_hlt:
hint #34
hlt #0x1
brk #0x1
_start:
hint #34
str x30, [sp, #-16]!
bl _hlt
brk #0x1
|
Sorry, might have been a glitch in my configuration. Can't reproduce it again either. |
…es-enforcement-technology, r=Amanieu Remove branch target prologues from `#[naked] fn` This patch hacks around rust-lang#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
Fixed in #98998. An alternative proposal for how to fix this and other issues with naked fn, that was brought up in that PR, is Rust lowering naked functions into global asm blocks which then can get compiled separately-ish. |
I tried this code:
I expected to see this happen:
no
endbr64
prologue in_hlt
naked function.Instead, this happened: an unwanted
endbr64
prologue in a naked functionMeta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: