Skip to content

OpenSSL 1.1.1 AES key wrap ciphers use-after-free #12073

Closed

Description

@guidovranken

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

This OSS-Fuzz bug triggered only in LibreSSL, not OpenSSL, because OpenSSL master branch is not affected, but the 1.1.1 branch is.

This is a different bug than #12014

Compile the following poc against the OpenSSL_1_1_1 branch.

#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[1024];
int len = -1;
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX* ctx2 = NULL;
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);

/* Duplicate the ctx */
ctx2 = EVP_CIPHER_CTX_new();
CF_CHECK_EQ(EVP_CIPHER_CTX_copy(ctx2, ctx), 1);
EVP_CIPHER_CTX_free(ctx);
ctx = ctx2;


/* "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 6, 2020
  2. guidovranken commented on Jun 6, 2020

    @guidovranken
    ContributorAuthor

    This is the LibreSSL fix for this bug: openbsd/src@f72711c

  3. bernd-edlinger commented on Jun 7, 2020

    @bernd-edlinger
    Member

    A similar iv pointer is in the ocb cipher:

    #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[16] = { 0 };
    unsigned char cleartext[16] = { 0 };
    unsigned char out[1024];
    int len = -1;
    EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
    EVP_CIPHER_CTX* ctx2 = NULL;
    const EVP_CIPHER* cipher = EVP_aes_128_ocb ();
    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
    
    CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL), 1);
    
    /* Duplicate the ctx */
    ctx2 = EVP_CIPHER_CTX_new();
    CF_CHECK_EQ(EVP_CIPHER_CTX_copy(ctx2, ctx), 1);
    EVP_CIPHER_CTX_free(ctx);
    ctx = ctx2;
    
    CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv), 1);
    CF_CHECK_EQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL), 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;
    }
  4. added
    triaged: bug
    and removed
    issue: bug report
    on Sep 24, 2020
  5. added
    branch: 1.1.1
    branch: master
    on Oct 4, 2020
  6. 48 remaining items

  7. added a commit that references this issue on Dec 23, 2022
    405407a
  8. added a commit that references this issue on Jan 27, 2023
    06f652d
  9. added 2 commits that reference this issue on Apr 24, 2023
    9b90213
    75ca333
  10. added 2 commits that reference this issue on May 13, 2023
    e078204
    910e365
  11. added a commit that references this issue on May 30, 2023
    491ece7
  12. added a commit that references this issue on Jul 19, 2023
    018117c
  13. added a commit that references this issue on Aug 1, 2023
    fbf0736
  14. added a commit that references this issue on Aug 19, 2023
    2f0f904
  15. added a commit that references this issue on Sep 12, 2023
    b739f08
  16. nhorman commented on Jun 13, 2024

    @nhorman
    Contributor

    Pr is closed, assuming this is done

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

  17. 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: 1.1.1branch: mastertriaged: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions