Skip to content

Add bounds check on AES-CTS input length to prevent integer overflow#422

Merged
padelsbach merged 1 commit into
wolfSSL:masterfrom
ColtonWilley:wp_fix_aes_cts_int_overflow
Jul 1, 2026
Merged

Add bounds check on AES-CTS input length to prevent integer overflow#422
padelsbach merged 1 commit into
wolfSSL:masterfrom
ColtonWilley:wp_fix_aes_cts_int_overflow

Conversation

@ColtonWilley

@ColtonWilley ColtonWilley commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

The AES-CTS encrypt/decrypt helpers in wp_aes_stream.c compute the block count as a signed int, so an inLen above 0x7FFFFFFF overflows blocks * AES_BLOCK_SIZE. The corrupted (negative) value then explodes inLen via inLen -= blocks * AES_BLOCK_SIZE, leading to an out-of-bounds XMEMCPY into the 32-byte ctsBlock stack buffer.

Adds an upper-bound guard in wp_aes_stream_doit (next to the existing lower-bound check) covering both the encrypt and decrypt paths.

Not reachable through EVP_CipherUpdate (its inl is int, so input is already capped at INT_MAX); the guard is defense in depth for a caller driving OSSL_FUNC_cipher_update directly. No new test — triggering would require a >2 GB input that the EVP API can't pass; existing CTS KAT/KRB/error-case tests pass unchanged.

Fixes Fenrir F-4380 and F-4381

The CTS encrypt/decrypt helpers cast the block count to int, so an inLen
above 0x7FFFFFFF overflows blocks*AES_BLOCK_SIZE and smashes the stack
copy. Not reachable via EVP_CipherUpdate (its inl is int); guard added as
defense in depth for a caller driving OSSL_FUNC_cipher_update directly.
@padelsbach
padelsbach merged commit f26b3a5 into wolfSSL:master Jul 1, 2026
72 checks passed
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