Skip to content

Commit 4d3cd46

Browse files
authored
[no-ci] CI: verify the Authenticode signature of vc_redist.x64.exe (13.4.x backport) (#3444)
* CI: verify the Authenticode signature of vc_redist.x64.exe The nightly PyTorch rows in test-wheel-windows.yml downloaded and silently ran vc_redist.x64.exe without checking its signature or the installer's exit code. Require a valid Microsoft Authenticode signature before running it, fail on installer errors (allowing 1638 and 3010), and download into RUNNER_TEMP. This matches the existing vc_redist.arm64.exe check. Refs #3195
1 parent fb8806e commit 4d3cd46

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎.github/workflows/test-wheel-windows.yml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,21 @@ jobs:
413413
- name: Install Visual C++ Redistributable (required by PyTorch on Windows)
414414
if: ${{ inputs.test-mode == 'nightly-pytorch' }}
415415
run: |
416-
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile "vc_redist.x64.exe"
417-
Start-Process -FilePath ".\vc_redist.x64.exe" -ArgumentList "/install", "/quiet", "/norestart" -Wait
418-
Remove-Item "vc_redist.x64.exe"
416+
$redist = Join-Path $env:RUNNER_TEMP "vc_redist.x64.exe"
417+
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile $redist
418+
$signature = Get-AuthenticodeSignature $redist
419+
if ($signature.Status -ne "Valid") { throw "VC++ runtime signature is not valid: $($signature.Status)" }
420+
# Compare the parsed organization (OID 2.5.4.10); a substring match on Subject also accepts
421+
# e.g. "O=Microsoft Corporation Services Ltd" or a CN containing "O=Microsoft Corporation".
422+
$org = @($signature.SignerCertificate.SubjectName.EnumerateRelativeDistinguishedNames() |
423+
Where-Object { $_.GetSingleElementType().Value -eq "2.5.4.10" } |
424+
ForEach-Object { $_.GetSingleElementValue() })
425+
if ($org.Count -ne 1 -or $org[0] -cne "Microsoft Corporation") {
426+
throw "VC++ runtime is not signed by Microsoft Corporation: O=$($org -join '|')"
427+
}
428+
$process = Start-Process $redist -ArgumentList "/install", "/quiet", "/norestart" -Wait -PassThru
429+
if ($process.ExitCode -notin 0, 1638, 3010) { throw "VC++ runtime installer failed: $($process.ExitCode)" }
430+
Remove-Item $redist
419431
420432
- name: Install cuda-python wheels + PyTorch
421433
if: ${{ inputs.test-mode == 'nightly-pytorch' }}

0 commit comments

Comments
 (0)