fix: kernel to check opaque values for fvars#14498
Merged
Merged
Conversation
This PR fixes a kernel unsoundness: just as for definitions and theorems, an `opaque` declaration's value must not contain fvars. This was discovered by Patrick Hulin with the help of GPT-5.6 Sol. The impact of this bug is that a malicious metaprogram can prove `False`, by first seeding the kernel's type checker cache for a free variable, and then refering to that free variable from the body of an `opaque`. See #14484 for an example. Because the export format used by comparator [cannot even express an fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160), the “[gold standard for validating proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)” is – luckily – not affected. And even it were, users who use comparator with multiple checkers would be safe. This bug can only be exploited by meta programs running in the same process. Such malicious meta programs can do nefarious things; this is known and unavoidable. So while we have a genuine kernel soundness at hand, it does not lead to new attack vectors in practice. Fixes #14484
nomeata
enabled auto-merge
July 22, 2026 14:03
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
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.32.0 releases/v4.32.0
# Navigate to the new working tree
cd .worktrees/backport-releases/v4.32.0
# Create a new branch
git switch --create backport-14498-to-releases/v4.32.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7346219967957ca3dd4302a75a849b67eed1b3cd
# Push it to GitHub
git push --set-upstream origin backport-14498-to-releases/v4.32.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-releases/v4.32.0Then, create a pull request where the |
Garmelon
pushed a commit
that referenced
this pull request
Jul 22, 2026
This PR fixes a kernel unsoundness: just as for definitions and theorems, an `opaque` declaration's value must not contain fvars. This was discovered by Patrick Hulin with the help of GPT-5.6 Sol. The impact of this bug is that a malicious metaprogram can prove `False`, by first seeding the kernel's type checker cache for a free variable, and then refering to that free variable from the body of an `opaque`. See #14484 for an example. Because the export format used by comparator [cannot even express an fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160), the “[gold standard for validating proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)” is – luckily – not affected. And even if it were, users who use comparator with nanoda as a second independent checker would be safe, as [the bug does not exist in nanoda](https://github.com/ammkrn/nanoda_lib/blob/f58f2f6d535e189a40fcb02ede8eb95f97a92d37/src/tc.rs#L169). This bug can only be exploited by meta programs running in the same process. Such malicious meta programs can do nefarious things; this is known and unavoidable. So while we have a genuine kernel unsoundness at hand, it does not lead to new attack vectors in practice. Fixes #14484
Garmelon
pushed a commit
that referenced
this pull request
Jul 22, 2026
This PR fixes a kernel unsoundness: just as for definitions and theorems, an `opaque` declaration's value must not contain fvars. This was discovered by Patrick Hulin with the help of GPT-5.6 Sol. The impact of this bug is that a malicious metaprogram can prove `False`, by first seeding the kernel's type checker cache for a free variable, and then refering to that free variable from the body of an `opaque`. See #14484 for an example. Because the export format used by comparator [cannot even express an fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160), the “[gold standard for validating proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)” is – luckily – not affected. And even if it were, users who use comparator with nanoda as a second independent checker would be safe, as [the bug does not exist in nanoda](https://github.com/ammkrn/nanoda_lib/blob/f58f2f6d535e189a40fcb02ede8eb95f97a92d37/src/tc.rs#L169). This bug can only be exploited by meta programs running in the same process. Such malicious meta programs can do nefarious things; this is known and unavoidable. So while we have a genuine kernel unsoundness at hand, it does not lead to new attack vectors in practice. Fixes #14484
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 a kernel unsoundness: just as for definitions and theorems, an
opaquedeclaration's value must not contain fvars.This was discovered by Patrick Hulin with the help of GPT-5.6 Sol.
The impact of this bug is that a malicious metaprogram can prove
False, by first seeding the kernel's type checker cache for a free variable, and then refering to that free variable from the body of anopaque. See #14484 for an example.Because the export format used by comparator cannot even express an fvar, the “gold standard for validating proofs” is – luckily – not affected. And even if it were, users who use comparator with nanoda as a second independent checker would be safe, as the bug does not exist in nanoda.
This bug can only be exploited by meta programs running in the same process. Such malicious meta programs can do nefarious things; this is known and unavoidable. So while we have a genuine kernel unsoundness at hand, it does not lead to new attack vectors in practice.
Fixes #14484