Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cipher: fix buffer overflow in Cipher#update #717

Merged
merged 1 commit into from Apr 30, 2024

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented Feb 5, 2024

OpenSSL::Cipher#update currently allocates the output buffer with size (input data length)+(the block size of the cipher). This is insufficient for the id-aes{128,192,256}-wrap-pad (AES keywrap with padding) ciphers. They have a block size of 8 bytes, but the output may be 15 bytes larger than the input.

Use (input data length)+EVP_MAX_BLOCK_LENGTH (== 32) as the output buffer size, instead. OpenSSL doesn't provide a way to tell the maximum required buffer size for arbitrary ciphers, but this is large enough for all algorithms implemented in current versions of OpenSSL.

Fixes: https://bugs.ruby-lang.org/issues/20236

@rhenium rhenium force-pushed the ky/cipher-update-fix-buffer-size branch 3 times, most recently from 463bc72 to 7eb577d Compare February 5, 2024 13:30
OpenSSL::Cipher#update currently allocates the output buffer with size
(input data length)+(the block size of the cipher). This is insufficient
for the id-aes{128,192,256}-wrap-pad (AES keywrap with padding) ciphers.
They have a block size of 8 bytes, but the output may be up to 15 bytes
larger than the input.

Use (input data length)+EVP_MAX_BLOCK_LENGTH (== 32) as the output
buffer size, instead. OpenSSL doesn't provide a generic way to tell the
maximum required buffer size for ciphers, but this is large enough for
all algorithms implemented in current versions of OpenSSL.

Fixes: https://bugs.ruby-lang.org/issues/20236
@rhenium rhenium force-pushed the ky/cipher-update-fix-buffer-size branch from 7eb577d to 3035559 Compare April 30, 2024 16:36
@rhenium rhenium merged commit 59ff543 into ruby:maint-3.0 Apr 30, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant