Address GOFIPS short-circuit bug#2244
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a FIPS-mode detection short-circuit in the Microsoft Go build by tightening how environment variables are interpreted, ensuring platform-specific FIPS detection is only bypassed by explicit “disable” settings, and updates the FIPS documentation accordingly.
Changes:
- Update FIPS initialization logic so only explicit values (
GODEBUG=fips140=on|only|debug|off,GOFIPS=0|1,GOLANG_FIPS=0|1) affect behavior; unexpected values no longer bypass platform detection. - Update FIPS documentation and release notes to describe the revised env-var semantics and the prior bug.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| patches/0003-Implement-crypto-internal-backend.patch | Updates the patched Go source (notably fips140.go) to validate env var values and avoid accidental platform-detection bypass. |
| eng/doc/fips/README.md | Documents the new explicit-disable behavior and the “ignore unexpected values” rule; adds release notes for the change. |
Patches are happy!
| + // Only "0" and "1" are meaningful values for GOFIPS and GOLANG_FIPS. | ||
| + // Any other value (including the empty string) is treated as if the | ||
| + // variable were unset, to avoid silently bypassing the platform FIPS | ||
| + // detection due to a typo or accidental setting. | ||
| + // "0" explicitly disables FIPS mode, including the platform-specific | ||
| + // FIPS detection. | ||
| + if v, ok := syscall.Getenv("GOFIPS"); ok && (v == "0" || v == "1") { | ||
| + message = "environment variable GOFIPS=" + v | ||
| + value = v | ||
| + } else if v, ok := syscall.Getenv("GOLANG_FIPS"); ok && (v == "0" || v == "1") { | ||
| + message = "environment variable GOLANG_FIPS=" + v | ||
| + value = v | ||
| + } else if systemFIPSMode() { | ||
| + message = "system FIPS mode" |
There was a problem hiding this comment.
This change introduces nuanced precedence/validation rules (e.g., ignore GOFIPS/GOLANG_FIPS unless exactly 0/1, and ensure invalid values don’t bypass systemFIPSMode() detection). There doesn’t appear to be any unit test coverage for these cases; adding focused tests around env var combinations/precedence would help prevent regressions.
3ceeeb2 to
4809d21
Compare
Fix GOFIPS handling to match the documented behavior: only GOFIPS=1 enables FIPS mode, and any other value (including 0 and the empty string) is treated as if GOFIPS were unset. The same applies to GOLANG_FIPS. Add GODEBUG=fips140=off as the supported way to explicitly disable FIPS mode and skip the platform-specific FIPS detection (e.g. the Linux kernel FIPS flag at /proc/sys/crypto/fips_enabled). Previously, due to a bug, setting GOFIPS or GOLANG_FIPS to any value silently bypassed the platform FIPS detection while only =1 actually enabled FIPS mode. That contradicted the docs and made it easy to accidentally disable FIPS detection through a typo or empty assignment. Programs that previously relied on GOFIPS=0 to skip platform FIPS detection should switch to GODEBUG=fips140=off. Fixes #2184
4809d21 to
8f8ffd3
Compare
This pull request updates the FIPS mode detection logic and documentation in the Microsoft Go build to clarify and improve how environment variables control FIPS mode. The changes ensure that only explicit values (
on,off,0,1) affect FIPS mode, preventing accidental bypass of platform-specific detection, and update the documentation to match the new behavior.FIPS Mode Detection and Environment Variable Handling:
fips140.goto ensure that onlyGODEBUG=fips140=on|only|debugenables FIPS,GODEBUG=fips140=offexplicitly disables FIPS (and skips platform detection), and onlyGOFIPS=0|1andGOLANG_FIPS=0|1are meaningful—any other value is ignored and does not skip platform detection.README.md) thatGODEBUG=fips140=off,GOFIPS=0, andGOLANG_FIPS=0now explicitly disable FIPS mode and skip platform-specific detection, while other values are ignored. [1] [2]Documentation and Release Notes:
GODEBUG=fips140=off,GOFIPS=0, andGOLANG_FIPS=0, including the fix for a previous bug where settingGOFIPSorGOLANG_FIPSto any value would skip platform detection. [1] [2]Codebase Updates: