Guard the only torch.load with weights_only=True - #35
Open
EvolveAegis wants to merge 1 commit into
Open
Conversation
experiments/crosswords/evaluate.py loads an edge-logits checkpoint with torch.load and no weights_only. pyproject.toml pins torch >=2.1.0, <=2.2.2, where weights_only defaults to False, so the call resolves through pickle's Unpickler and honors REDUCE/GLOBAL opcodes. Pass weights_only=True (and map_location=cpu) so a checkpoint sourced from elsewhere can't trigger arbitrary code at load time. Co-Authored-By: Claude <noreply@anthropic.com>
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 passes
weights_only=Trueto the singletorch.loadin the repo, so reloading an edge-logits checkpoint can't trigger pickle deserialization.The sink
experiments/crosswords/evaluate.py:39(HEADc23a827f561c934ce21dd950408f7606aa4a8821):This is the only
torch.loadin the repo (grep -rn "torch.load"across the tree returns this one hit) and it passes noweights_only.pyproject.toml:65pinstorch = ">=2.1.0, <=2.2.2"; every version in that range defaultsweights_only=False, so the call resolves through pickle'sUnpickler, which honorsREDUCE/GLOBALopcodes. A checkpoint whose payload defines__reduce__runs at load time, beforeload_state_dict/realize()/evaluate.weights_only=Trueonly became torch's default in 2.6, above the pinned ceiling, so on the shipped dependency set (any torch < 2.6) the line is unguarded.Scope
This is a deserialization-hygiene fix (CWE-502), not a claim that the training loop can be subverted. The loop's own REINFORCE output is gradient-bounded floats with no
__reduce__channel, so the repo's own training cannot self-poison this checkpoint. The exposure is adopting a checkpoint from elsewhere — a shared "pre-trained".pkl, a results dir written by someone else, or a model-zoo artifact dropped intoresult/crosswords_Jan15/.weights_only=Trueis free for legitimate numeric state and closes the gadget.Repro
Verified on the pinned torch 2.2.2 (Python 3.9). The script writes a poisoned checkpoint to the loader's computed path and exercises the exact
load_state_dict(torch.load(path))shape fromevaluate.py:39.Observed on torch 2.2.2:
Changes
experiments/crosswords/evaluate.py:39: addweights_only=True, map_location="cpu"to thetorch.loadcall.torch>=2.6(which defaultsweights_only=True), or write shareable checkpoints as safetensors so there's no pickle channel at all.