openssl/crypto/evp
Matt Caswell 335d0a4646 Fix undefined behaviour in e_aes_cbc_hmac_sha256.c and e_aes_cbc_hmac_sha1.c
In TLS mode of operation the padding value "pad" is obtained along with the
maximum possible padding value "maxpad". If pad > maxpad then the data is
invalid. However we must continue anyway because this is constant time code.

We calculate the payload length like this:

    inp_len = len - (SHA_DIGEST_LENGTH + pad + 1);

However if pad is invalid then inp_len ends up -ve (actually large +ve
because it is a size_t).

Later we do this:

    /* verify HMAC */
    out += inp_len;
    len -= inp_len;

This ends up with "out" pointing before the buffer which is undefined
behaviour. Next we calculate "p" like this:

    unsigned char *p =
        out + len - 1 - maxpad - SHA256_DIGEST_LENGTH;

Because of the "out + len" term the -ve inp_len value is cancelled out
so "p" points to valid memory (although technically the pointer arithmetic
is undefined behaviour again).

We only ever then dereference "p" and never "out" directly so there is
never an invalid read based on the bad pointer - so there is no security
issue.

This commit fixes the undefined behaviour by ensuring we use maxpad in
place of pad, if the supplied pad is invalid.

With thanks to Brian Carpenter for reporting this issue.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3832)
2017-07-19 11:49:08 +01:00
..
bio_b64.c Remove some commented out code in libcrypto 2017-02-28 16:02:11 +00:00
bio_enc.c Remove some commented out code in libcrypto 2017-02-28 16:02:11 +00:00
bio_md.c Remove some commented out code in libcrypto 2017-02-28 16:02:11 +00:00
bio_ok.c
build.info Implementation of the ARIA cipher as described in RFC 5794. 2017-02-21 11:51:45 +01:00
c_allc.c Implementation of the ARIA cipher as described in RFC 5794. 2017-02-21 11:51:45 +01:00
c_alld.c
cmeth_lib.c
digest.c
e_aes.c Fix gcc-7 warnings. 2017-05-11 19:39:38 +02:00
e_aes_cbc_hmac_sha1.c Fix undefined behaviour in e_aes_cbc_hmac_sha256.c and e_aes_cbc_hmac_sha1.c 2017-07-19 11:49:08 +01:00
e_aes_cbc_hmac_sha256.c Fix undefined behaviour in e_aes_cbc_hmac_sha256.c and e_aes_cbc_hmac_sha1.c 2017-07-19 11:49:08 +01:00
e_aria.c Fix copyright date for the ARIA evp file. 2017-07-03 12:55:16 +10:00
e_bf.c
e_camellia.c
e_cast.c
e_chacha20_poly1305.c Properly zero cipher_data for ChaCha20-Poly1305 on cleanup 2017-02-15 20:00:34 -05:00
e_des.c
e_des3.c Fix the overlapping check for fragmented "Update" operations 2017-01-25 15:02:44 +00:00
e_idea.c
e_null.c
e_old.c
e_rc2.c
e_rc4.c Cleanup EVP_CIPH/EP_CTRL duplicate defines 2017-01-24 18:47:10 +01:00
e_rc4_hmac_md5.c crypto/evp: harden RC4_MD5 cipher. 2017-01-26 10:54:01 +00:00
e_rc5.c
e_seed.c
e_xcbc_d.c
encode.c
evp_cnf.c Clean up references to FIPS 2017-02-28 15:26:25 +01:00
evp_enc.c Restore EVP_CIPH_FLAG_LENGTH_BITS working properly 2017-02-10 13:36:56 +00:00
evp_err.c make error tables const and separate header file 2017-06-07 15:12:03 -04:00
evp_key.c Fix small UI issues 2017-07-05 11:15:37 +02:00
evp_lib.c
evp_locl.h Fix the overlapping check for fragmented "Update" operations 2017-01-25 15:02:44 +00:00
evp_pbe.c Trivial bounds checking. 2017-07-07 15:45:55 +10:00
evp_pkey.c
m_md2.c
m_md4.c
m_md5.c
m_md5_sha1.c
m_mdc2.c
m_null.c
m_ripemd.c
m_sha1.c
m_sigver.c Fix memleak in EVP_DigestSignFinal/VerifyFinal. 2017-06-12 12:49:50 -04:00
m_wp.c
names.c
p5_crpt.c
p5_crpt2.c PBKDF2 computation speedup (15-40%) 2017-04-04 10:44:17 -04:00
p_dec.c
p_enc.c
p_lib.c Add support for parameterized SipHash 2017-02-01 14:14:36 -05:00
p_open.c
p_seal.c Remove some commented out code in libcrypto 2017-02-28 16:02:11 +00:00
p_sign.c
p_verify.c
pmeth_fn.c
pmeth_gn.c
pmeth_lib.c ED25519 public key method. 2017-05-30 20:38:20 +01:00
scrypt.c