Skip to content

Heap-buffer-overflow in CRYPTO_128_wrap #12014

Closed

Description

@guidovranken

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22836

#include <openssl/evp.h>
--
 
#define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; }
#define CF_CHECK_GTE(expr, res) if ( (expr) < (res) ) { goto end; }
int main(void)
{
const unsigned char key[16] = { 0 };
const unsigned char iv[8] = { 0 };
unsigned char cleartext[16] = { 0 };
unsigned char out[23];
int len = -1;
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
const EVP_CIPHER* cipher = EVP_aes_128_wrap();
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL), 1);
CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
/* "the amount of data written may be anything from zero bytes to (inl + cipher_block_size - 1)" */
CF_CHECK_GTE(sizeof(out), sizeof(cleartext) + EVP_CIPHER_block_size(cipher) - 1);
CF_CHECK_EQ(EVP_EncryptUpdate(ctx, out, &len, cleartext, sizeof(cleartext)), 1);
end:
return 0;
}

Activity

  1. added
    issue: bug report
    on Jun 2, 2020
  2. added
    branch: master
    triaged: bug
    and removed
    issue: bug report
    on Jun 2, 2020
  3. paulidale commented on Jun 2, 2020

    @paulidale
    Contributor

    Digging deeper, this looks like a documentation error.

  4. bernd-edlinger commented on Jun 2, 2020

    @bernd-edlinger
    Member

    I'd say for WRAP ciphers you need inl + 16
    Interesting is that this test case is invalid
    to make it work in 1.1.1 you have to add
    EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
    as follows:

    #include <openssl/evp.h>
    
    #define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; }
    #define CF_CHECK_GTE(expr, res) if ( (expr) < (res) ) { goto end; }
    int main(void)
    {
    const unsigned char key[16] = { 0 };
    const unsigned char iv[8] = { 0 };
    unsigned char cleartext[16] = { 0 };
    unsigned char out[23];
    int len = -1;
    EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
    const EVP_CIPHER* cipher = EVP_aes_128_wrap();
    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
    EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
    CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL), 1);
    CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
    /* "the amount of data written may be anything from zero bytes to (inl + cipher_block_size - 1)" */
    CF_CHECK_GTE(sizeof(out), sizeof(cleartext) + EVP_CIPHER_block_size(cipher) - 1);
    CF_CHECK_EQ(EVP_EncryptUpdate(ctx, out, &len, cleartext, sizeof(cleartext)), 1);
    end:
    return 0;
    }
    
  5. bernd-edlinger commented on Jun 2, 2020

    @bernd-edlinger
    Member

    That check for EVP_CIPHER_CTX_FLAG_WRAP_ALLOW was obviously
    dropped in master. Most likely accidentally?

  6. paulidale commented on Jun 2, 2020

    @paulidale
    Contributor

    There is still a check in master, it must be avoided somehow.

  7. nhorman commented on Jun 13, 2024

    @nhorman
    Contributor

    Marking as inactive, to be closed at the end of 3.4 dev, barring further input

  8. t8m commented on Aug 20, 2025

    @t8m
    Member

    Closing as the issue was labeled as inactive for extended period of time and there was no additional input.
    Please add a comment if you have any further information to support reopening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    branch: mastertriaged: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions