Skip to content

Security audit: re-approve the four torch findings that 2.14.0 opened - #10233

Merged
danielhanchen merged 3 commits into
mainfrom
security-torch-2140-rebaseline
Sep 3, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
security-torch-2140-rebaseline

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Security audit has been red on every main commit since 2ecb19df7, on pip scan-packages :: studio and pip scan-packages :: extras, with the same 1 CRITICAL and 3 HIGH. All four are in torch, and no commit in this repo caused them.

torch is not named in any scanned input. grep -rn "torch" studio/backend/requirements/*.txt finds only torchcodec, torch-c-dlpack-ext, pytorch_tokenizers and torch-stoi; torch itself arrives transitively through --with-deps, which resolves to whatever PyPI serves that morning. hf-stack stays green because its inputs are deliberately torch-free.

torch 2.14.0 was published at 2026-09-02T13:42:48Z. The last green Security audit on main started at 13:22, the first red one at 14:06. I pulled the last-green artifact rather than infer it:

$ gh run download 33635288732 -n scan-packages-log-studio
$ grep -oE "torch-[0-9.]+[^ ]*\.whl" logs-scan-packages-studio.txt | sort -u
torch-2.13.0-cp312-cp312-manylinux_2_28_x86_64.whl

against the red run, which reports torch-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl.

The four findings

Three are new upstream code between v2.13.0 and v2.14.0, one is an existing entry whose span digest rotated.

torch/_precompile.py is a new file (pytorch/pytorch#189620, torch.compiler.precompile). Both halves of the finding are one line, L1570, in _make_inlined_forward, which execs an artifact the user produced and logs a loud warning first:

    # python_code is untrusted EXECUTABLE input -- exec'ing it runs whatever it contains
    log.warning(
        "torch.compiler.precompile.load is about to EXEC python_code, which is untrusted "
        ...
    )
    module_ns: dict[str, object] = {"__name__": "_precompiled_artifact"}
    exec(compile(python_code, "<precompile>", "exec"), module_ns)

The Exec: half of the evidence also lists L967 and L1174, which look like comments the stripper missed. They are not: both sit inside _GENERATED_HEADER / _EAGER_GENERATED_HEADER, string constants assigned to a name, so the # is literal text baked into a generated file's header. _strip_noncode only blanks bare docstrings, correctly. RE_EXEC_EVAL matched documentation prose.

torch/_inductor/standalone_compile.py gained load_from_python (pytorch/pytorch#187858, torch._inductor.compile_to_python). One line, L687, the counterpart to compile_to_python, exec'ing a self-contained Inductor module the caller just generated. Same shape as the already-baselined torch/fx/graph_module.py entry.

torch/_inductor/compile_worker/subproc_pool.py gained a test helper (pytorch/pytorch#189290):

def _ignore_sigterm_and_sleep_for_test() -> None:
    # Test helper: a compile worker that ignores SIGTERM and blocks, forcing pool
    # teardown to escalate to SIGKILL instead of stalling on a graceful shutdown.
    import signal

    signal.signal(signal.SIGTERM, signal.SIG_IGN)
    while True:
        time.sleep(3600)

RE_ANTI_ANALYSIS pairs that long sleep with subprocess.Popen( at L212, which is the pool's own worker launch, 650 lines away and unchanged since 2.13.0. Nothing conditions on a debugger, a VM or a tracer. The two halves never co-occur at runtime.

torch/testing/_internal/common_utils.py is not new code at all. import socket is at line 32 in both releases; this file+check has been reviewed benign twice already (89faaaa8..., ba439cbf...) and this is the third digest for the same thing. RE_REVERSE_SHELL is re.DOTALL, so the match runs from the first socket to the last subprocess and _render digests the whole bridged span. That span went from 6,270 to 6,595 lines, and the changed lines inside it are 381 added and 56 removed, of which zero match any IOC pattern in the scanner. It reopened on a new HardwareClassification enum and thirty-odd unrelated test edits.

The patch

Four additive, unpinned entries, matching how the two existing common_utils.py reverse-shell entries and #10187 are maintained. 223 entries to 227.

I derived them with scan_packages.py torch==2.14.0 --write-baseline and took only the delta, rather than regenerating the other 219, then recomputed every evidence_hash independently through the scanner's own _evidence_hash and confirmed all four agree.

Reproduced end to end against a real 2.14.0 wheel:

before  Summary: 1 CRITICAL, 3 HIGH, 22 MEDIUM   exit 1
after   Summary: 22 MEDIUM                       exit 0
        14 finding(s) suppressed by baseline (8 CRITICAL, 6 HIGH, 0 MEDIUM)

The before output is byte-identical to the CI evidence, including both sha256: digests. A control run on 2.13.0 with --no-baseline shows 8 CRITICAL + 3 HIGH, all already committed, and none on the three new files.

tests/security/test_scan_packages.py is unaffected: 132 passed, with the one unrelated failure that #10206 fixes.

Why this keeps happening

This is the fourth time a routine upstream release has turned main red on this workflow, after huggingface-hub (#9252, #8135), unsloth-zoo (#9674, #10187) and now torch. The mechanism is the same each time and it is worth writing down.

58 of the 223 entries carry a span digest. 23 (package, file, check) triples hold more than one entry, 34 entries beyond the first, and 22 of those 34 exist purely because a span digest rotated: 4 for huggingface_hub/utils/_http.py, 4 for unsloth_zoo/compiler.py, 2 for torch/testing/_internal/common_utils.py, and so on. Every one of those four _http.py entries covers about 650 lines to bind a 30-line retry loop.

The cause is .* greediness under re.DOTALL: a cross-line branch matches from the first atom in the file to the last, and _render's long-span fallback then digests everything it bridged. The entry is not pinned to the reviewed code, it is pinned to most of the file, so any refactor anywhere between the atoms reopens a CRITICAL.

A fix I measured but am deliberately not folding in here: give each cross-line regex a companion line-level atom pattern and, when _render falls back to a digest, digest only the atom-bearing lines. That collapses common_utils.py to one stable digest across both releases and _http.py to one across 1.26.1 / 1.27.0 / 1.28.0, while a spliced reverse shell, a spliced beacon loop and the scenario in test_the_hf_backoff_suppression_is_narrow all still reopen. The honest cost is that an edit inside a span carrying none of that check's atoms no longer reopens that entry, though it still raises its own finding if it trips any other check. And landing it rotates all 58 hashes at once, which needs its own PR with the code re-read entry by entry, not a --write-baseline regeneration bolted onto an urgent unblock.

Smaller companion, worth having either way: the report cannot currently tell "a file+check nobody has ever reviewed" from "a file+check reviewed three times whose digest rotated". torch/_precompile.py and common_utils.py printed identically here, and they deserve different sentences. Classifying on the coarse (package, file, check) key, NEW versus REOPENED, with the superseded evidence printed alongside, would have made this triage minutes instead of an afternoon. Both still exit 1.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T08:49:49.459507Z 0f6f16d Manual request
🔒 Security Review ✅ Completed 2026-09-03T08:53:21.306580Z 0f6f16d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 588cf117bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/scan_packages_baseline.json Outdated
Comment on lines +1810 to +1811
"evidence": "Obfusc: L1570: exec(compile(python_code, \"<precompile>\", \"exec\"), module_ns)\nExec: L967: # exec(open(\"this_file.py\").read(), ns) | L1174: # exec(open(\"this_file.py\").read(), ns) | L1570: exec(compile(python_code, \"<precompile>\", \"exec\"), module_ns)",
"evidence_hash": "ed7c7bfe07302200f8323e8f091a8f6ab06c9607410e31c4f036699fe7dee161"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin context-dependent exec approvals to reviewed files

For both this entry and the analogous standalone_compile.py entry below, the benign judgment depends on surrounding code establishing where python_code comes from and when it is executed, but the evidence hash covers only the unchanged exec(compile(...)) call. Without file_sha256, a future or compromised torch release can change that surrounding provenance while retaining these lines, causing _partition_baseline to suppress the finding and keep the security audit green. Add the reviewed 2.14.0 file digests to both entries.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on both, and pinned in 0f6f16d.

The reviewed 2.14.0 digests, computed the way check_py_file does at scan_packages.py:1211 (sha256(original.encode("utf-8", "replace")) over the wheel member, which round-trips identically for all three):

file file_sha256
torch/_precompile.py a8ab839be1e8b555c181a08a8c431185aaf67e8ac00e517590fc8092d0554e46
torch/_inductor/standalone_compile.py fe16758342f83ce0040a038648a371315bee8f3876f0da75a786562828cbb836
torch/_inductor/compile_worker/subproc_pool.py 695b5c1df7d0ae710451aa8904c5ef101e0c93de26a591f3e995bb9151d4c0e3

Taken out of torch-2.14.0-cp312-cp312-manylinux_2_28_x86_64.whl itself, not from a GitHub tag, so they are the bytes the scanner actually reads.

Verified by running the scan rather than by reasoning about it:

$ python scripts/scan_packages.py torch==2.14.0
  Summary: 22 MEDIUM
  14 finding(s) suppressed by baseline scripts/scan_packages_baseline.json (8 CRITICAL, 6 HIGH, 0 MEDIUM)
=== EXIT 0 ===

and _load_baseline reports one pin per key rather than None, so _partition_baseline now reopens each of the three on any edit to the file, not just to the matched lines.

I left torch/testing/_internal/common_utils.py unpinned deliberately: its evidence already carries a span digest over the whole socket to subprocess region, and adding a file pin on top would only duplicate coverage that is, if anything, already too broad. That entry is the one this baseline has re-approved three times for exactly that reason, which is written up in the PR description.

The cost of these three pins is honest and worth stating: the next torch release edits all three files, so Security audit goes red on them and asks for a re-review. That is the control working, but it is the same treadmill the PR description argues about, and it is now three entries longer.

Comment thread scripts/scan_packages_baseline.json Outdated
Comment on lines +1826 to +1827
"evidence": "Anti: L860: time.sleep(3600)\nSubprocess: L212: self.process = subprocess.Popen( sha256:62f622e5b17b6c6b1656b44c8ba27274f02c68c4f9d35502fb593f1d6a3af55d",
"evidence_hash": "f760ab1ce9c086051291c29ac4e486575db6f2dac2eddba2ac31ef5c434609d8"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pin the control-flow-dependent anti-analysis approval

This approval is benign only because the long sleep is currently confined to a test helper and is unrelated at runtime to the worker-launching Popen, but the evidence hash records only the sleep and subprocess call text, not that control-flow separation. Without file_sha256, a later torch release can invoke or relocate the unchanged helper into the production worker path while retaining the same evidence, and _partition_baseline will suppress the resulting anti-analysis finding. Pin this entry to the reviewed 2.14.0 file digest.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinned in 0f6f16d, to 695b5c1df7d0ae710451aa8904c5ef101e0c93de26a591f3e995bb9151d4c0e3. Your reading of the gap is exact: the sha256:62f622e5... already in that entry's evidence is the span digest over the 13-line Popen block only, so it records the call text and nothing about _ignore_sigterm_and_sleep_for_test being confined to the test path. Relocating the unchanged helper into the production worker would have kept the evidence hash intact. See the reply on the other comment for how the digests were derived and for the end-to-end scan that confirms all four now suppress at exit 0.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 0f6f16d258

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0f6f16d258

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen
danielhanchen merged commit daa18fe into main Sep 3, 2026
36 of 40 checks passed
@danielhanchen
danielhanchen deleted the security-torch-2140-rebaseline branch September 3, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant