Reject GCM IV lengths below 8 in EVP_CTRL_GCM_IV_GEN - #3424
Open
dougch wants to merge 3 commits into
Open
Conversation
EVP_CTRL_AEAD_SET_IVLEN accepts any positive int, so a caller can set gctx->ivlen to 1..7. EVP_CTRL_GCM_IV_GEN then computes the invocation counter pointer as gctx->iv + gctx->ivlen - 8, which underflows for ivlen < 8. The subsequent 8-byte load and store touch memory before gctx->iv -- into the preceding oiv[16] member of EVP_CIPHER_CTX. No code pointers are affected, but the "generated" IV returned to the caller then contains bytes read from oiv[], and the increment writes back into oiv[]. Subsequent GCM operations on the same ctx can produce predictable or attacker-influenced IV state, which under GCM breaks confidentiality and authenticity. Extend the entry guard to reject ivlen < 8. Match BoringSSL's fix in e2a57cfb (Change-Id Ia9c87e42c43a0dcf6ed9e51621d7484d6a6a6964). Add a regression test that sets a 7-byte IV via SET_IVLEN, primes with SET_IV_FIXED(-1), and verifies EVP_CTRL_GCM_IV_GEN returns 0 rather than proceeding to the underflow.
Contributor
|
🔒 Security Review — View Report Please review before merging. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3424 +/- ##
=======================================
Coverage 78.23% 78.24%
=======================================
Files 698 698
Lines 124580 124590 +10
Branches 17285 17287 +2
=======================================
+ Hits 97471 97488 +17
+ Misses 26184 26177 -7
Partials 925 925 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
justsmth
previously approved these changes
Aug 13, 2026
nebeid
reviewed
Aug 13, 2026
Addresses review feedback: - Remove now-redundant "invocation field will be at least 8 bytes" comment; the new guard comment above covers it, matching upstream. - Add SET_IV_INV overflow test from BoringSSL 1f70b5b6 covering negative and oversized arg values against the existing aws-lc guard.
nebeid
approved these changes
Aug 14, 2026
justsmth
approved these changes
Aug 14, 2026
dougch
had a problem deploying
to
manual-approval
August 17, 2026 17:20 — with
GitHub Actions
Failure
dougch
had a problem deploying
to
manual-approval
August 17, 2026 21:40 — with
GitHub Actions
Failure
dougch
had a problem deploying
to
manual-approval
August 17, 2026 22:19 — with
GitHub Actions
Failure
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
dougch
requested a deployment
to
manual-approval
August 18, 2026 16:49 — with
GitHub Actions
Waiting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
EVP_CTRL_AEAD_SET_IVLENaccepts any positive int, so a caller can setgctx->ivlento 1..7.EVP_CTRL_GCM_IV_GENthen computes the invocation counter pointer asgctx->iv + gctx->ivlen - 8, which underflows forivlen < 8. The subsequent 8-byteCRYPTO_load_u64_be/CRYPTO_store_u64_betouch memory beforegctx->iv— into the precedingoiv[16]member ofEVP_CIPHER_CTX.No code pointers are affected. The impact is IV/nonce state confusion: the "generated" IV returned to the caller contains bytes read from
oiv[], and the increment writes back intooiv[]. Subsequent GCM operations on the same ctx can produce predictable or attacker-influenced IV state, which under GCM breaks confidentiality and authenticity.Reachable from any caller that lets attacker-influenced input drive
EVP_CTRL_AEAD_SET_IVLEN. Not directly reachable through standard TLS 1.2 AES-GCM ciphersuites (12-byte IVs on the send path are hardcoded), but any consumer that plumbs IV-length parameters end-to-end (bindings, custom AEAD frameworks, PKI tools) is exposed.Call-outs
Extends the entry guard on
EVP_CTRL_GCM_IV_GENto rejectivlen < 8. Mirrors BoringSSL's fix ine2a57cfb(Change-IdIa9c87e42c43a0dcf6ed9e51621d7484d6a6a6964), merged 2026-05-20. Also matches the test shape upstream added toSetIVLengthResets, adapted to aws-lc's existingGCMIncrementingIVtest.Not applying the corresponding defense-in-depth check at
EVP_CTRL_AEAD_SET_IVLEN: that would change behavior for callers that use short IVs on the SET_IV_FIXED / decrypt path without invoking IV_GEN. Matching upstream's narrower fix is the right call.Testing
Added
CipherTest.GCMIncrementingIVsub-block that setsSET_IVLEN=7, primes withSET_IV_FIXED(-1), and verifiesEVP_CTRL_GCM_IV_GENreturns 0. Verified locally:CipherTestsuite passes (21 tests).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.