Skip to content

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Aug 26, 2025

The underlying implementation of LLVMCreateConstantRangeAttribute assumes that each of LowerWords and UpperWords points to enough u64 values to define an integer of the specified bit-length, and will encounter UB if that is not the case.

Our safe wrapper function always passes pointers to [u64; 2] arrays, regardless of the bit-length specified. That's fine in practice, because scalar primitives never exceed 128 bits, but it is technically a soundness hole in a safe function.

We can close the soundness hole by explicitly asserting size_bits <= 128. This is effectively just a stricter version of the existing check that the value must be small enough to fit in c_uint.


This is a narrower version of the fix in #145846.

The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes
that each of `LowerWords` and `UpperWords` points to enough u64 values to
define an integer of the specified bit-length, and will encounter UB if that is
not the case.

Our safe wrapper function always passes pointers to `[u64; 2]` arrays,
regardless of the bit-length specified. That's fine in practice, because scalar
primitives never exceed 128 bits, but it is technically a soundness hole in a
safe function.

We can close the soundness hole by explicitly asserting `size_bits <= 128`.
This is effectively just a stricter version of the existing check that the
value must be small enough to fit in `c_uint`.
@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 26, 2025
@Zalathar
Copy link
Contributor Author

cc @nikic

@nikic
Copy link
Contributor

nikic commented Aug 26, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 26, 2025

📌 Commit fcff8f7 has been approved by nikic

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2025
@lcnr lcnr assigned nikic and unassigned lcnr Aug 26, 2025
bors added a commit that referenced this pull request Aug 26, 2025
Rollup of 11 pull requests

Successful merges:

 - #144373 (remove deprecated Error::description in impls)
 - #144551 (Add aarch64_be-unknown-linux-musl target)
 - #145076 (Add new Tier-3 target: riscv64a23-unknown-linux-gnu)
 - #145481 (Add parentheses for closure when suggesting calling closure)
 - #145596 (Losslessly optimize PNG files)
 - #145615 (Fix doc of `std::os::windows::io::BorrowedSocket::borrow_raw`)
 - #145841 (Always build miri for the host in `x run miri`)
 - #145861 (bootstrap: vendor `clippy_test_deps` too)
 - #145863 (formatting_options: Make all methods `const`)
 - #145867 (cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits)
 - #145875 (Make bootstrap command caching opt-in)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6047243 into rust-lang:master Aug 26, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 26, 2025
rust-timer added a commit that referenced this pull request Aug 26, 2025
Rollup merge of #145867 - Zalathar:range-attr, r=nikic

cg_llvm: Assert that LLVM range-attribute values don't exceed 128 bits

The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes that each of `LowerWords` and `UpperWords` points to enough u64 values to define an integer of the specified bit-length, and will encounter UB if that is not the case.

Our safe wrapper function always passes pointers to `[u64; 2]` arrays, regardless of the bit-length specified. That's fine in practice, because scalar primitives never exceed 128 bits, but it is technically a soundness hole in a safe function.

We can close the soundness hole by explicitly asserting `size_bits <= 128`. This is effectively just a stricter version of the existing check that the value must be small enough to fit in `c_uint`.

---

This is a narrower version of the fix in #145846.
@Zalathar Zalathar deleted the range-attr branch August 26, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants