Skip to content

Locals aligned to greater than page size can cause unsound behavior #70143

Open

Description

@retep998

View all comments

Forked from #70022

Minimal example

#[repr(align(0x10000))]
struct Aligned(u8);

fn main() {
    let x = Aligned(0);
    println!("{:#x}", &x as *const _ as usize);
}

Aligning the stack is done after the stack probe. Because stacks grow downwards and aligning the stack shifts it downwards, it can cause the end of the stack to extend past the guard page and cause invalid access exceptions or worse when those sections of the stack are touched.

Only confirmed that this occurs on pc-windows-msvc (pnkfelix edit: see comment thread, its a more general problem.)

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    O-windows-msvcToolchain: MSVC, Operating system: Windows
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    on Mar 19, 2020
  2. changed the title [-]Alignment greater than page size locals can cause invalid access exceptions.[/-] [+]Locals aligned to greater than page size can cause unsound behavior[/+] on Mar 19, 2020
  3. Amanieu commented on Mar 19, 2020

    @Amanieu
    Member

    This is most likely an LLVM bug.

  4. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Mar 19, 2020
  5. RalfJung commented on Apr 22, 2020

    @RalfJung
    Member

    Could someone who knows the technical details here report this bug upstream with LLVM?

  6. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 9, 2020
  7. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 17, 2020
  8. LeSeulArtichaut commented on Jun 17, 2020

    @LeSeulArtichaut
    Contributor

    @rustbot ping llvm

  9. 27 remaining items

  10. cuviper commented on Dec 10, 2022

    @cuviper
    Member

    Updating my earlier godbolt to current nightly (https://rust.godbolt.org/z/hseenMTKP) still shows the same asm, still just as problematic. However, I also rechecked "probe-stack"="inline-asm" since #102503 turned that on for the upcoming LLVM 16, and it's better, but I found a bug: https://reviews.llvm.org/D139756

    (NB: inline-asm won't apply for Windows and its __chkstk.)

  11. added a commit that references this issue on Aug 2, 2023
  12. cuviper commented on Mar 5, 2024

    @cuviper
    Member

    I think we can now consider this a Windows-only bug, because the rest are now using "probe-stack"="inline-asm", except for arches that lack stack probes entirely. It's not really specific to MSVC either, as windows-gnu generates the same code calling __chkstk.

    @rustbot label -O-linux -O-windows-msvc +O-windows

  13. added
    O-windowsOperating system: Windows
    and removed
    O-linuxOperating system: Linux
    O-windows-msvcToolchain: MSVC, Operating system: Windows
    on Mar 5, 2024
  14. added
    C-external-bugCategory: issue that is caused by bugs in software beyond our control
    on Nov 22, 2024
  15. jieyouxu commented on Nov 22, 2024

    @jieyouxu
    Member

    Visited during T-compiler P-high review: as far as we can tell this still needs someone to try and investigate/fix from the llvm side. Labeled with C-external-bug as well.

  16. added
    E-needs-investigationCall for participation: This issues needs some investigation to determine current status
    on Jun 19, 2026
  17. apiraino commented on Jun 19, 2026

    @apiraino
    Contributor

    Visited during T-compiler P-high review#t-compiler/meetings > [triage] 2026-06-19 P-high review @ 💬

    Looks nothing changed here and the fix is on us rather than LLVM? cc: @rust-lang/wg-llvm

  18. ChrisDenton commented on Jun 19, 2026

    @ChrisDenton
    Member
  19. RalfJung commented on Jun 19, 2026

    @RalfJung
    Member

    This is still an LLVM bug, isn't it? We just gave up on hoping they'll fix it so we plan to reject it on the Rust side?

  20. ChrisDenton commented on Jun 20, 2026

    @ChrisDenton
    Member

    Yeah. Making it an error unless it is ever fixed in llvm was the plan. Notably both clang and msvc's cl have a limit of 8192 alignment for the target (godbolt). In my (brief) testing, 16384 appeared to work in rust though it's possible I'm missing some situation where that would break.

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

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlE-needs-investigationCall for participation: This issues needs some investigation to determine current statusI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-windowsOperating system: WindowsP-highHigh priorityT-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