set_next and get_next truncate pointers unsafely on some x86 and ARM configurations
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
lean_object has a clever optimization to mutate into a linked list for handling deletions without stack growth:
which effectively assumes that a 64-bit pointer can be truncated to 48-bits, and that zero-extending will round-trip, This is implemented here:
Unfortunately, like many clever optimizations, eventually compilers and hardware adjust such that its assumptions no longer hold.
In particular, the following configurations lead to segfaults due to the top bits of the address space being zeroed out:
- Arm's memory tagging hardware extension (MTE), which uses the top bits to implement address sanitization.
- Arm's large virtual addressing, which extends the virtual address space from 48 bits to 52 bits (i.e. with
CONFIG_ARM64_FORCE_52BIT=y) - Intel's 5-level paging, which extends the virtual address space from 48 bits to 57 bits
Context
Detected in some address-sanitization runs of AlphaProof infrastructure.
Steps to Reproduce
- Build with some of the suggested flags above
Expected behavior: Lean's tests pass
Actual behavior: Segfault due to invalid addresses, or the lean_assert(get_next(o) == n); firing.
Versions
4.27.0
Additional Information
[Additional information, configuration or data that might be necessary to reproduce the issue]
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the lean_object definition in src/include/lean/lean.h at lines 119-121, then inspect set_next and get_next in src/runtime/object.cpp at lines 278-301. Run the Lean tests with the affected ARM and x86 address-space configurations where possible. Done means the pointer round-trip remains valid and the tests pass without invalid-address faults or the reported assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100