Repository navigation
fix: mark the children of objects whose single-threaded count overflowed - #15288
Merged
Merged
Conversation
This PR makes sharing an object with other threads mark everything it points to as thread-shared even when the object's reference count has overflowed. Previously such objects were shared without their children, so other threads could update the children's reference counts non-atomically and free them while still in use. Overflowing single-threaded counts land at or below the new `LEAN_RC_STUCK_ST`: the inline increment wraps below it, and `lean_inc_ref_huge_n` freezes counts there instead of at `LEAN_RC_STICKY`. `lean_mark_mt` treats counts at or below it as unshared, visits their children, and freezes the object's count at `LEAN_RC_STICKY`. A frozen thread-shared count only reaches `LEAN_RC_STUCK_ST` with more than 4094 maximal increments in flight at once, two fewer than the sticky range already allows before a frozen count wraps. `lean_mark_mt` also freezes single-threaded counts too large for the live thread-shared range at `LEAN_RC_STICKY` rather than negating them. Negating a count near `INT_MAX` would land at or below `LEAN_RC_STUCK_ST`, where a later `lean_mark_mt` would take the shared object for an unshared one and walk it while other threads use it. The model gains `isUnshared` and `markMtRc` for `is_unshared` and the count `lean_mark_mt` leaves on each object it visits. `incRefN_spec` and `incRefHugeMt_spec` now state that an overflowing single-threaded count lands in the band `isStuckSt` reserves and that a thread-shared count never reaches it, and `markMtRc_shared`, `decRef_stays_shared` and `frozen_shared_count_stays_shared` show that a shared count never reads as unshared again. `rc_sticky` checks sharing after each overflow route and with a count near `INT_MAX`, as well as a frozen shared count drifted by the most increments in flight the bound admits. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Kha
enabled auto-merge
September 23, 2026 14:35
Contributor
|
The backport to To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-releases/v4.35.0 releases/v4.35.0
# Navigate to the new working tree
cd .worktrees/backport-releases/v4.35.0
# Create a new branch
git switch --create backport-15288-to-releases/v4.35.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 2b21d8b2653388d34c0a4d1509b0982dbf499d14
# Push it to GitHub
git push --set-upstream origin backport-15288-to-releases/v4.35.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-releases/v4.35.0Then, create a pull request where the |
Contributor
|
The backport to To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-releases/v4.34.0 releases/v4.34.0
# Navigate to the new working tree
cd .worktrees/backport-releases/v4.34.0
# Create a new branch
git switch --create backport-15288-to-releases/v4.34.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 2b21d8b2653388d34c0a4d1509b0982dbf499d14
# Push it to GitHub
git push --set-upstream origin backport-15288-to-releases/v4.34.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-releases/v4.34.0Then, create a pull request where the |
This was referenced Sep 24, 2026
Kha
added a commit
that referenced
this pull request
Sep 24, 2026
…ingle-threaded count overflowed (#15306) Backport 2b21d8b from #15288. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Kha
added a commit
that referenced
this pull request
Sep 24, 2026
…wed (#15288) This PR fixes potential undefined behavior when an object with a huge number of incoming references is shared between threads. Specifically, it makes sharing an object with other threads mark everything it points to as thread-shared even when the object's reference count has overflowed. Previously such objects were shared without their children, so other threads could update the children's reference counts non-atomically and free them while still in use. Overflowing single-threaded counts land at or below the new `LEAN_RC_STUCK_ST`: the inline increment wraps below it, and `lean_inc_ref_huge_n` freezes counts there instead of at `LEAN_RC_STICKY`. `lean_mark_mt` treats counts at or below it as unshared, visits their children, and freezes the object's count at `LEAN_RC_STICKY`. A frozen thread-shared count only reaches `LEAN_RC_STUCK_ST` with more than 4094 maximal increments in flight at once, two fewer than the sticky range already allows before a frozen count wraps. `lean_mark_mt` also freezes single-threaded counts too large for the live thread-shared range at `LEAN_RC_STICKY` rather than negating them. Negating a count near `INT_MAX` would land at or below `LEAN_RC_STUCK_ST`, where a later `lean_mark_mt` would take the shared object for an unshared one and walk it while other threads use it. The model gains `isUnshared` and `markMtRc` for `is_unshared` and the count `lean_mark_mt` leaves on each object it visits. `incRefN_spec` and `incRefHugeMt_spec` now state that an overflowing single-threaded count lands in the band `isStuckSt` reserves and that a thread-shared count never reaches it, and `markMtRc_shared`, `decRef_stays_shared` and `frozen_shared_count_stays_shared` show that a shared count never reads as unshared again. `rc_sticky` checks sharing after each overflow route and with a count near `INT_MAX`, as well as a frozen shared count drifted by the most increments in flight the bound admits. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 2b21d8b)
hyperpolymath
added a commit
to hyperpolymath/marches
that referenced
this pull request
Oct 14, 2026
Follow-up to the CodeRabbit review on #36 (thread on `lean-toolchain`, flagged Major / security): pin v4.34.1, the patched release of the 4.34 line. ## Verified against the primary source, not the bot's summary `git log v4.34.0..v4.34.1` in leanprover/lean4 shows: - three runtime reference-count fixes: - leanprover/lean4#15241: preserve sticky counts in deletion cascades - leanprover/lean4#15288: mark the children of objects whose single-threaded count overflowed - leanprover/lean4#15307: panic instead of wrapping counts in `sharecommon_quick_fn` - a `BitVec.ofNatClamp` backport - `chore: prepare release` (`5045d00`, 2026-09-24) marches checks only its own proofs, not untrusted input, so the practical risk was low. Still, this is a same-line patch bump, it costs nothing, and it keeps the estate's 4.34 soundness floor on the patched build. ## Change - `lean-toolchain`: `v4.34.0` → `v4.34.1` - `README.adoc`: the two version mentions - `STATE.adoc`: a dated entry. The v4.34.0 results are now marked historical. No source change. ## Gates (v4.34.1) ``` $ rm -rf .lake && lake build Build completed successfully (15 jobs). $ grep -rnw sorry Marches/ Marches.lean ; echo $? 1 $ lake env lean Marches/BadGadget.lean [(false, false), (true, true), (false, false), (true, true)] ``` ## Note on the stack #38 (rung-3 docs) is independent of this PR. Both add a `STATE.adoc` entry at the top, so whichever merges second will need a trivial merge, which I'll handle. CI here shows the same two pre-existing reds as `main` (`CI` `startup_failure` from `actions.lock` drift, and `estate-audit` from the cicd-suite pipefail bug). Both are diagnosed in #37. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VTeVWDEJgdYKsUNr4uhnXX --- _Generated by [Claude Code](https://claude.ai/code/session_01VTeVWDEJgdYKsUNr4uhnXX)_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes potential undefined behavior when an object with a huge number of incoming references is shared between threads. The official kernel does not use multithreading in its default configuration (as used by comparator and
lake check/compare), but other Lean-based checkers such as con-leche might be affected.Specifically, it makes sharing an object with other threads mark everything it points to as thread-shared even when the object's reference count has overflowed. Previously such objects were shared without their children, so other threads could update the children's reference counts non-atomically and free them while still in use.
Overflowing single-threaded counts land at or below the new
LEAN_RC_STUCK_ST: the inline increment wraps below it, andlean_inc_ref_huge_nfreezes counts there instead of atLEAN_RC_STICKY.lean_mark_mttreats counts at or below it as unshared, visits their children, and freezes the object's count atLEAN_RC_STICKY. A frozen thread-shared count only reachesLEAN_RC_STUCK_STwith more than 4094 maximal increments in flight at once, two fewer than the sticky range already allows before a frozen count wraps.lean_mark_mtalso freezes single-threaded counts too large for the live thread-shared range atLEAN_RC_STICKYrather than negating them. Negating a count nearINT_MAXwould land at or belowLEAN_RC_STUCK_ST, where a laterlean_mark_mtwould take the shared object for an unshared one and walk it while other threads use it.The model gains
isUnsharedandmarkMtRcforis_unsharedand the countlean_mark_mtleaves on each object it visits.incRefN_specandincRefHugeMt_specnow state that an overflowing single-threaded count lands in the bandisStuckStreserves and that a thread-shared count never reaches it, andmarkMtRc_shared,decRef_stays_sharedandfrozen_shared_count_stays_sharedshow that a shared count never reads as unshared again.rc_stickychecks sharing after each overflow route and with a count nearINT_MAX, as well as a frozen shared count drifted by the most increments in flight the bound admits.