Repository navigation
fix: preserve sticky counts in deletion cascades - #15241
Merged
Kha merged 6 commits intoSep 23, 2026
Merged
Conversation
This PR keeps persistent and sticky counts unchanged when references are released through deletion cascades. Use the unsigned ordering of reference-count states to retain the existing single comparison, and cover both sides of the drop threshold with a production-linked regression.
Replace the standalone native fixture with an exhaustive bit-vector theorem in the existing reference-count model. Under the nonpositive-count precondition established by the preceding cascade branches, the unsigned guard is exactly the persistent-or-drop-stopped range.
vincentqb
marked this pull request as ready for review
September 20, 2026 19:31
leanprover#14910 renamed `tests/elab/rc_sticky_thresholds.lean` to `tests/elab/rc_model.lean`, but the `sync with` comments in `lean.h` and `object.cpp` kept the old name. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Name the two unsigned comparisons against the sticky thresholds, `lean_is_unstuck_mt` for the increment paths and `lean_is_never_freed` for the drop paths, and use them in `lean_inc_ref_n`, `lean_inc_ref_huge_n`, `lean_dec_ref_cold` and the deletion cascade. `lean_dec_ref_cold` compared signed before, which only excluded persistent counts because `lean_dec_ref` never hands it one; the shared helper covers them as well. The cascade branch loses its `LEAN_UNLIKELY` hint, since persistent children are common there. The model quotes the helpers where the C uses them, `decRefCold` transcribes the unsigned comparison like the increment paths already did, and `isUnstuckMt_unsigned` and `isNeverFreed_unsigned` state what each single comparison classifies. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…nd deletion cascades `tests/misc_dir/rc_sticky` compiles a C program against the runtime and checks that neither `lean_dec` nor the deletion cascade adjusts a persistent or sticky count, and that no increment adjusts a persistent or frozen one. The cascade case fails without the unsigned guard in `dec`. Every object is freed through the ordinary deletion path at the end, so the test also passes under the `sanitize` preset's leak checker. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Member
|
Thank you! |
Kha
enabled auto-merge
September 23, 2026 10:09
The `leanc` of a release toolchain bundles clang with only its freestanding headers, so `stdio.h` does not exist there. Declare `printf` instead, which the C library `leanc` links still provides. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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-15241-to-releases/v4.34.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 85460834fdf2deef8016319c888f6279a12fb832
# Push it to GitHub
git push --set-upstream origin backport-15241-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 |
Kha
added a commit
that referenced
this pull request
Sep 24, 2026
…ascades (#15301) Backport 8546083 from #15241. Co-authored-by: Vincent QB, PhD <[email protected]> Co-authored-by: Sebastian Ullrich <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Kha
added a commit
that referenced
this pull request
Sep 24, 2026
This PR prevents deletion cascades from releasing objects whose reference count has been frozen after over- or underflow. The public decrement path already stops at `LEAN_RC_STICKY_DROP`, but the internal cascade helper `dec` only stopped for persistent objects. Replace that zero test with an unsigned comparison against the drop threshold, which handles persistent and sticky counts together while live thread-shared counts continue to the atomic path. `cascade_dec_guard_eq_never_freed` in `tests/elab/rc_model.lean` checks the new guard exhaustively over every count that can reach this branch. The sticky-count semantics were introduced in #14838, and the reference-count model extended here was completed in #14910. --------- Co-authored-by: Sebastian Ullrich <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]> (cherry picked from commit 8546083)
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]>
vincentqb
added a commit
to vincentqb/lean4
that referenced
this pull request
Oct 14, 2026
This PR proves that reference-counting deletion releases each field of a freed object exactly as `lean_dec_ref` releases a reference, on every count (`decCascade_eq_decRef`). Hence deletion leaves persistent and sticky counts alone (`decCascade_never_freed`), the property leanprover#15241 restored. Both proofs use only `propext`, `Classical.choice` and `Quot.sound`.
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 prevents deletion cascades from releasing objects whose reference count has been frozen after over- or underflow. Like #14838, on machines with at least 18GB of free RAM, it could potentially be used to trigger use-after-free in the official kernel, which could be extended into a proof of False. Other kernels such as nanoda or con-ron not based on the Lean runtime were not affected.
The public decrement path already stops at
LEAN_RC_STICKY_DROP, but the internal cascade helperdeconly stopped for persistent objects. Replace that zero test with an unsigned comparison against the drop threshold, which handles persistent and sticky counts together while live thread-shared counts continue to the atomic path.cascade_dec_guard_eq_never_freedintests/elab/rc_model.leanchecks the new guard exhaustively over every count that can reach this branch. The sticky-count semantics were introduced in #14838, and the reference-count model extended here was completed in #14910.