Skip to content

Address GOFIPS short-circuit bug#2244

Merged
michelle-clayton-work merged 1 commit intomicrosoft/mainfrom
dev/mclayton/fix-gofips-2184
Apr 23, 2026
Merged

Address GOFIPS short-circuit bug#2244
michelle-clayton-work merged 1 commit intomicrosoft/mainfrom
dev/mclayton/fix-gofips-2184

Conversation

@michelle-clayton-work
Copy link
Copy Markdown
Contributor

@michelle-clayton-work michelle-clayton-work commented Apr 21, 2026

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:

  • Updated the FIPS mode initialization logic in fips140.go to ensure that only GODEBUG=fips140=on|only|debug enables FIPS, GODEBUG=fips140=off explicitly disables FIPS (and skips platform detection), and only GOFIPS=0|1 and GOLANG_FIPS=0|1 are meaningful—any other value is ignored and does not skip platform detection.
  • Clarified in the documentation (README.md) that GODEBUG=fips140=off, GOFIPS=0, and GOLANG_FIPS=0 now explicitly disable FIPS mode and skip platform-specific detection, while other values are ignored. [1] [2]

Documentation and Release Notes:

  • Added release notes for Go 1.27 describing the new behavior for GODEBUG=fips140=off, GOFIPS=0, and GOLANG_FIPS=0, including the fix for a previous bug where setting GOFIPS or GOLANG_FIPS to any value would skip platform detection. [1] [2]

Codebase Updates:

  • Increased the number of insertions in the backend implementation patch to reflect the new logic and documentation changes. [1] [2]
  • Updated test and dependency files to reflect the new FIPS mode detection logic and environment variable handling. [1] [2]

Copilot AI review requested due to automatic review settings April 21, 2026 01:26
@michelle-clayton-work michelle-clayton-work requested a review from a team as a code owner April 21, 2026 01:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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!

Comment thread eng/doc/fips/README.md
Comment thread eng/doc/fips/README.md Outdated
Comment on lines +2311 to +2324
+ // 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"
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@qmuntal qmuntal left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Copy Markdown
Member

@qmuntal qmuntal left a comment

Choose a reason for hiding this comment

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

LGTM, ditto Copilot comments

Comment thread eng/doc/fips/README.md Outdated
Comment thread eng/doc/fips/README.md Outdated
@michelle-clayton-work michelle-clayton-work force-pushed the dev/mclayton/fix-gofips-2184 branch 3 times, most recently from 3ceeeb2 to 4809d21 Compare April 21, 2026 22:29
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
@michelle-clayton-work michelle-clayton-work merged commit eed1184 into microsoft/main Apr 23, 2026
58 checks passed
@michelle-clayton-work michelle-clayton-work deleted the dev/mclayton/fix-gofips-2184 branch April 23, 2026 16:01
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.

5 participants