Skip to content

Commit f96e4da

Browse files
committed
Address review feedback on Windows FIPS hash injection
- aws-lc-rs.yml: rewrite stale Wine-setup comment. The build no longer runs fips_empty_main.exe; Wine is only needed for the downstream FIPS sanity test step that loads the cross-built DLL. - run_windows_tests.bat: restore crypto.dll from backup before checking the negative-test exit code, so a failure here does not leave a corrupted DLL behind for subsequent local invocations. - inject_hash.go (doWindows): require both BORINGSSL_bcm_rodata_{start,end} markers unconditionally. Windows FIPS is always a shared-library build and the runtime hashes rodata in that configuration; silently skipping rodata here would produce a hash that disagrees with the runtime. - fipscommon/pe.go: add trailing newline at EOF.
1 parent 0bb36b2 commit f96e4da

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

.github/workflows/aws-lc-rs.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,11 @@ jobs:
310310
run: |
311311
set -ex
312312
# Wine binfmt allows the kernel to transparently run .exe files through
313-
# Wine. This is needed for the FIPS build, which runs fips_empty_main.exe
314-
# at build time to capture the integrity hash.
313+
# Wine. The FIPS build itself no longer needs Wine (inject_hash.go
314+
# patches the integrity hash directly into crypto.dll using the
315+
# linker map), but we still need Wine to run the FIPS sanity test
316+
# below, which loads the cross-built DLL so the .CRT$XCU initializer
317+
# can trigger the power-on self-test.
315318
#
316319
# Ubuntu 24.04's wine64 (9.0) does not properly execute .CRT$XCU
317320
# initializers in cross-compiled DLLs, which prevents the FIPS

tests/ci/run_windows_tests.bat

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ cd /d %SRC_ROOT%
7676
go run util/fipstools/break-hash.go -map %BUILD_DIR%\crypto\fips_crypto.map %BUILD_DIR%\crypto\crypto.dll %BUILD_DIR%\crypto\crypto_corrupted.dll || goto error
7777
copy /y %BUILD_DIR%\crypto\crypto_corrupted.dll %BUILD_DIR%\crypto\crypto.dll || goto error
7878
%BUILD_DIR%\util\fipstools\test_fips.exe 2>nul
79-
if %ERRORLEVEL% equ 0 (
80-
echo FIPS integrity negative test failed: test_fips should have failed with corrupted crypto.dll
81-
goto error
82-
)
79+
set FIPS_NEGATIVE_RC=%ERRORLEVEL%
80+
@rem Restore the unmodified DLL before we decide whether the test passed or
81+
@rem failed, so that a failure here does not leave a corrupted crypto.dll
82+
@rem behind for any subsequent local invocation.
8383
copy /y %BUILD_DIR%\crypto\crypto.dll.bak %BUILD_DIR%\crypto\crypto.dll || goto error
8484
del /q %BUILD_DIR%\crypto\crypto.dll.bak
8585
del /q %BUILD_DIR%\crypto\crypto_corrupted.dll
86+
if %FIPS_NEGATIVE_RC% equ 0 (
87+
echo FIPS integrity negative test failed: test_fips should have failed with corrupted crypto.dll
88+
goto error
89+
)
8690

8791
@echo LOG: %date%-%time% %1 %2 FIPS validation complete
8892
exit /b 0

util/fipstools/fipscommon/pe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ func (p *PEInfo) ResolveSymbolFileOffset(symbolAddrs map[string]uint64, name str
8989
}
9090
}
9191
return 0, fmt.Errorf("RVA 0x%x for %q not found in any PE section", rva, name)
92-
}
92+
}

util/fipstools/inject_hash/inject_hash.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,20 @@ func doWindows(objectBytes []byte, mapPath string) ([]byte, []byte, error) {
330330
return nil, nil, err
331331
}
332332

333-
var moduleROData []byte
333+
// The Windows FIPS build is always a shared library (see the `windowsOS`
334+
// branch of `do` below, which rejects static inputs). In shared builds the
335+
// runtime integrity check in bcm.c hashes the rodata region in addition
336+
// to the text region, so the map file must contain both rodata markers.
337+
// Silently skipping rodata here would produce a hash that disagrees with
338+
// what the runtime computes and the DLL would fail the power-on self-test.
334339
_, hasRodataStart := symbolAddrs["BORINGSSL_bcm_rodata_start"]
335340
_, hasRodataEnd := symbolAddrs["BORINGSSL_bcm_rodata_end"]
336-
if hasRodataStart != hasRodataEnd {
337-
return nil, nil, errors.New("rodata marker presence inconsistent")
341+
if !hasRodataStart || !hasRodataEnd {
342+
return nil, nil, errors.New("rodata markers missing from map file; Windows FIPS shared build requires both BORINGSSL_bcm_rodata_start and BORINGSSL_bcm_rodata_end")
338343
}
339-
if hasRodataStart {
340-
moduleROData, err = extractRegion("BORINGSSL_bcm_rodata_start", "BORINGSSL_bcm_rodata_end")
341-
if err != nil {
342-
return nil, nil, err
343-
}
344+
moduleROData, err := extractRegion("BORINGSSL_bcm_rodata_start", "BORINGSSL_bcm_rodata_end")
345+
if err != nil {
346+
return nil, nil, err
344347
}
345348

346349
return moduleText, moduleROData, nil

0 commit comments

Comments
 (0)