openssl/openssl

Uninitialized output buffer is causing memory sanitizer build to fail

Chiusa

#23.572 aperta il 13 feb 2024

 (3 commenti) (0 reazioni) (0 assegnatari)C (11.262 fork)batch import
help wantedtriaged: bug

Metriche repository

Star
 (30.157 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Found in master branch and our own build of OpenSSL.

Some of our memory sanitizer unit tests are failing due to an uninitialized output buffer that's used for cipher update in OpenSSL.

The stack trace of the failure:

Uninitialized value was stored to memory at
    #0 ...
    #1 0x7f17601d9f5b in ctr_update /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg_ctr.c:284:5
    #2 0x7f17601d61c9 in drbg_ctr_generate /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg_ctr.c:388:14
    #3 0x7f17602976e2 in ossl_prov_drbg_generate /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg.c:683:10
    #4 0x7f17602950e2 in ossl_drbg_get_seed /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg.c:176:10
    #5 0x7f176029e2e7 in get_entropy /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg.c:241:13
    #6 0x7f176029abee in ossl_prov_drbg_instantiate /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg.c:451:18
    #7 0x7f17601ce0f5 in drbg_ctr_instantiate_wrapper /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg_ctr.c:336:12
    #8 0x7f175f2a05e3 in evp_rand_instantiate_locked /openssl-3.0.2/build_shared/../crypto/evp/evp_rand.c:505:12
    #9 0x7f175f29fda3 in EVP_RAND_instantiate /openssl-3.0.2/build_shared/../crypto/evp/evp_rand.c:518:11
    #10 0x7f175f7d8e3a in rand_new_drbg /openssl-3.0.2/build_shared/../crypto/rand/rand_lib.c:599:10
    #11 0x7f175f7d5baa in RAND_get0_public /openssl-3.0.2/build_shared/../crypto/rand/rand_lib.c:689:16
    #12 0x7f175f7d4ec2 in RAND_bytes_ex /openssl-3.0.2/build_shared/../crypto/rand/rand_lib.c:362:12
    #13 0x7f175f7d602b in RAND_bytes openssl-3.0.2/build_shared/../crypto/rand/rand_lib.c:373:12
    #14 ...

  Uninitialized value was created by an allocation of 'out' in the stack frame of function 'ctr_update'
    #0 0x7f17601d9170 in ctr_update /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg_ctr.c:263

SUMMARY: MemorySanitizer: use-of-uninitialized-value /openssl-3.0.2/build_shared/../providers/implementations/rands/drbg_ctr.c:426:17 in drbg_ctr_generate
Exiting

Specifically, the uninitialized output buffer is here "out":

__owur static int ctr_update(PROV_DRBG *drbg,
                             const unsigned char *in1, size_t in1len,
                             const unsigned char *in2, size_t in2len,
                             const unsigned char *nonce, size_t noncelen)
{
    PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data;
    int outlen = AES_BLOCK_SIZE;
    unsigned char V_tmp[48], ===> out[48]; <===
    ...

We were able to solve the problem by simply zero initializing the output buffer.

unsigned char V_tmp[48], out[48] = {0};

We would like to find out what other consequences this uninitialized output buffer may have and is the above patch sufficient to mitigate them?

Guida contributor