leanprover / leanprover/lean4

set_next and get_next truncate pointers unsafely on some x86 and ARM configurations

Open
#13,113 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

lean_object has a clever optimization to mutate into a linked list for handling deletions without stack growth:

https://github.com/leanprover/lean4/blob/e60078db3b4e63ca150573dd94f04862be7187e0/src/include/lean/lean.h#L119-L121

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:

https://github.com/leanprover/lean4/blob/e60078db3b4e63ca150573dd94f04862be7187e0/src/runtime/object.cpp#L278-L301

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.