Skip to content

Fix integer underflow in AES-GCM key/data unwrap size calculations#296

Open
sameehj wants to merge 1 commit intowolfSSL:mainfrom
sameehj:fix
Open

Fix integer underflow in AES-GCM key/data unwrap size calculations#296
sameehj wants to merge 1 commit intowolfSSL:mainfrom
sameehj:fix

Conversation

@sameehj
Copy link
Contributor

@sameehj sameehj commented Mar 11, 2026

Multiple AES-GCM unwrap functions compute payload sizes by subtracting header sizes from wrappedKeySz/wrappedDataSz without first verifying the wrapped size is large enough. Since these are uint16_t operations, an undersized input wraps to a large value, causing out-of-bounds reads and writes via wc_AesGcmDecrypt and memcpy.

Add bounds checks before each subtraction in:

  • _AesGcmKeyUnwrap
  • _AesGcmDataUnwrap
  • _HandleKeyUnwrapAndExportRequest
  • _HandleKeyUnwrapAndCacheRequest
  • _HandleDataUnwrapRequest

Add regression tests that send undersized wrappedKeySz/wrappedDataSz through all unwrap client APIs and assert WH_ERROR_BADARGS.

Multiple AES-GCM unwrap functions compute payload sizes by subtracting
header sizes from wrappedKeySz/wrappedDataSz without first verifying the
wrapped size is large enough. Since these are uint16_t operations, an
undersized input wraps to a large value, causing out-of-bounds reads and
writes via wc_AesGcmDecrypt and memcpy.

Add bounds checks before each subtraction in:
  - _AesGcmKeyUnwrap
  - _AesGcmDataUnwrap
  - _HandleKeyUnwrapAndExportRequest
  - _HandleKeyUnwrapAndCacheRequest
  - _HandleDataUnwrapRequest

Add regression tests that send undersized wrappedKeySz/wrappedDataSz
through all unwrap client APIs and assert WH_ERROR_BADARGS.

Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
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.

2 participants