diff options
author | Matt Caswell <matt@openssl.org> | 2022-12-06 14:18:53 +0000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-12-22 11:01:06 +0100 |
commit | e51dd6ee1bac6b54debea3f48c6f58b761229b73 (patch) | |
tree | c4c1e9d93351b86a0db994be02769d6cb7dcab34 /crypto/evp/bio_enc.c | |
parent | 42061268ee8f9ae0555d522870740fc91b744f4f (diff) | |
download | openssl-new-e51dd6ee1bac6b54debea3f48c6f58b761229b73.tar.gz |
Fix BIO_f_cipher() flushing
If an error occurs during a flush on a BIO_f_cipher() then in some cases
we could get into an infinite loop. We add a check to make sure we are
making progress during flush and exit if not.
This issue was reported by Octavio Galland who also demonstrated an
infinite loop in CMS encryption as a result of this bug.
The security team has assessed this issue as not a CVE. This occurs on
*encryption* only which is typically processing trusted data. We are not
aware of a way to trigger this with untrusted data.
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19918)
Diffstat (limited to 'crypto/evp/bio_enc.c')
-rw-r--r-- | crypto/evp/bio_enc.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c index 2333c20ef6..a284b6d9eb 100644 --- a/crypto/evp/bio_enc.c +++ b/crypto/evp/bio_enc.c @@ -297,6 +297,7 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) int i; EVP_CIPHER_CTX **c_ctx; BIO *next; + int pend; ctx = BIO_get_data(b); next = BIO_next(b); @@ -332,8 +333,14 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr) /* do a final write */ again: while (ctx->buf_len != ctx->buf_off) { + pend = ctx->buf_len - ctx->buf_off; i = enc_write(b, NULL, 0); - if (i < 0) + /* + * i should never be > 0 here because we didn't ask to write any + * new data. We stop if we get an error or we failed to make any + * progress writing pending data. + */ + if (i < 0 || (ctx->buf_len - ctx->buf_off) == pend) return i; } |