Skip to content

Commit

Permalink
Fix BIO_f_cipher() flushing
Browse files Browse the repository at this point in the history
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 #19919)
  • Loading branch information
mattcaswell authored and t8m committed Dec 22, 2022
1 parent 92d86b3 commit 54b5aeb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crypto/evp/bio_enc.c
Expand Up @@ -299,6 +299,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);
Expand Down Expand Up @@ -334,8 +335,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;
}

Expand Down

0 comments on commit 54b5aeb

Please sign in to comment.