Gate train_state.pt load behind an ownership check#62
Open
Conversation
torch.load(weights_only=False) on train_state.pt runs any __reduce__ in the file, so anyone who can plant a train_state.pt under a checkpoint dir that the training process reads gets code execution in the process that holds WANDB_API_KEY, HF_TOKEN, and SLURM creds. On shared HPC filesystems and for imported "pretrained" checkpoints that write side is attacker-reachable. Factor the load into a _load_train_state helper that refuses files not owned by the current UID and warns on group- or world-writable files. Same-UID attacks are out of scope (the attacker already wins), but this closes the group-writable shared checkpoint dir foot-gun and makes the trust boundary visible in the code. Not a full defense — Tier 2 (weights_only=True with safe_globals, scheduler split) tracked separately.
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.
Summary
torch.load(train_state.pt, weights_only=False)out into_load_train_state(path). The helper refuses to load whenpath.stat().st_uid != os.getuid()and warns on group- or world-writable files.train_state.ptunder the checkpoint path currently gets code execution in the training process on resume.weights_only=True; that is Tier 2 (scheduler/extra split +safe_globalsallowlist), tracked separately.Closes #61
Test plan
uv run pytest tests/unit/test_checkpoint_security.py -v(5 tests covering helper + fullCheckpointManager.load()path).TestAutoResume) still succeeds on a same-UID checkpoint.