]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Remove spurious error queue entries on early data
authorMatt Caswell <matt@openssl.org>
Mon, 27 Feb 2023 18:43:20 +0000 (18:43 +0000)
committerPauli <pauli@openssl.org>
Sun, 5 Mar 2023 21:35:17 +0000 (08:35 +1100)
Early data decryption is expected to fail sometimes. If it does we should
not leave spurious error entries on the queue.

Fixes #20377

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20401)

ssl/record/methods/tls_common.c

index ab1905903004071b7d4495881bb4e38c235edb5c..998c1efddacf64b736d57ac7bdf9874542226641 100644 (file)
@@ -802,6 +802,7 @@ int tls_get_more_records(OSSL_RECORD_LAYER *rl)
         }
     }
 
+    ERR_set_mark();
     enc_err = rl->funcs->cipher(rl, rr, num_recs, 0, macbufs, mac_size);
 
     /*-
@@ -813,6 +814,7 @@ int tls_get_more_records(OSSL_RECORD_LAYER *rl)
     if (enc_err == 0) {
         if (rl->alert != SSL_AD_NO_ALERT) {
             /* RLAYERfatal() already got called */
+            ERR_clear_last_mark();
             goto end;
         }
         if (num_recs == 1
@@ -823,6 +825,12 @@ int tls_get_more_records(OSSL_RECORD_LAYER *rl)
              * it like an empty record.
              */
 
+            /*
+             * Remove any errors from the stack. Decryption failures are normal
+             * behaviour.
+             */
+            ERR_pop_to_mark();
+
             thisrr = &rr[0];
 
             if (!rlayer_early_data_count_ok(rl, thisrr->length,
@@ -840,9 +848,12 @@ int tls_get_more_records(OSSL_RECORD_LAYER *rl)
             ret = 1;
             goto end;
         }
+        ERR_clear_last_mark();
         RLAYERfatal(rl, SSL_AD_BAD_RECORD_MAC,
                     SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);
         goto end;
+    } else {
+        ERR_clear_last_mark();
     }
     OSSL_TRACE_BEGIN(TLS) {
         BIO_printf(trc_out, "dec %lu\n", (unsigned long)rr[0].length);