Skip to content

Commit 07216e1

Browse files
committed
Don't back off on a DTLS 1.3 quick timeout with nothing to retransmit
Dtls13RtxTimeout cleared dtls13FastTimeout when it sent the pending ACKs and only then checked the flag to decide whether this was the quick timeout. Whenever ACKs could be sent, the quick timeout fell through to the long timeout path and doubled the retransmission timeout. While a peer flight arrives in parts our own flight is already acknowledged and nothing is buffered, so each quick timeout doubled the timeout without retransmitting anything, and repeated losses could drive it to its maximum. Once at the maximum, the quick timeout failed the handshake while the peer was still sending its flight. Return after the ACKs when the timeout was a quick one and nothing is buffered for retransmission. With records buffered the behaviour stays as before, so callers that wait the full timeout before calling wolfSSL_dtls_got_timeout still retransmit. A timeout taken while the flag is clear still backs off with nothing buffered, so a handshake with a lost peer still ends. A caller that waits the full timeout while the flag is set skips the backoff once, and the next timeout backs off.
1 parent bd5eead commit 07216e1

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎src/dtls13.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,7 @@ int Dtls13DoScheduledWork(WOLFSSL* ssl)
34683468
int Dtls13RtxTimeout(WOLFSSL* ssl)
34693469
{
34703470
int ret = 0;
3471+
int quickTimeout = ssl->dtls13FastTimeout;
34713472

34723473
/* We don't want to send acks until we have done version
34733474
* negotiation in the SH or have received a unified header in the
@@ -3493,6 +3494,9 @@ int Dtls13RtxTimeout(WOLFSSL* ssl)
34933494
return 0;
34943495
}
34953496

3497+
if (quickTimeout && ssl->dtls13Rtx.rtxRecords == NULL)
3498+
return 0;
3499+
34963500
/* Increase timeout on long timeout */
34973501
if (DtlsMsgPoolTimeout(ssl) != 0)
34983502
return WOLFSSL_FATAL_ERROR;

‎tests/api/test_dtls.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,85 @@ int test_dtls_drop_client_ack(void)
29992999
return EXPECT_RESULT();
30003000
}
30013001

3002+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
3003+
defined(WOLFSSL_DTLS13) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
3004+
!defined(WOLFSSL_NO_CLIENT_AUTH)
3005+
/* A quick timeout that sends ACKs with nothing to retransmit doesn't back
3006+
* off, also when the timeout is already at its maximum. */
3007+
static int test_dtls13_quick_timeout_no_backoff_ex(int atMax)
3008+
{
3009+
EXPECT_DECLS;
3010+
struct test_memio_ctx test_ctx;
3011+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
3012+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
3013+
int timeout = 0;
3014+
3015+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
3016+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
3017+
wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
3018+
ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile,
3019+
WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
3020+
ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile,
3021+
WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
3022+
ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL),
3023+
WOLFSSL_SUCCESS);
3024+
wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER |
3025+
WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
3026+
wolfSSL_dtls13_set_send_more_acks(ssl_s, 0);
3027+
if (atMax) {
3028+
ExpectIntEQ(wolfSSL_dtls_set_timeout_max(ssl_s,
3029+
wolfSSL_dtls_get_current_timeout(ssl_s)), WOLFSSL_SUCCESS);
3030+
}
3031+
3032+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3033+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3034+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3035+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3036+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3037+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
3038+
/* The server only gets the first record of the client's flight. */
3039+
ExpectIntGE(test_ctx.s_msg_count, 2);
3040+
while (EXPECT_SUCCESS() && test_ctx.s_msg_count > 1)
3041+
ExpectIntEQ(test_memio_drop_message(&test_ctx, 0, 1), 0);
3042+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3043+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
3044+
ExpectIntEQ(test_ctx.c_msg_count, 0);
3045+
ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_s), 1);
3046+
timeout = wolfSSL_dtls_get_current_timeout(ssl_s);
3047+
3048+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS);
3049+
ExpectIntEQ(test_ctx.c_msg_count, 1);
3050+
ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_s), timeout);
3051+
ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_s), 0);
3052+
3053+
if (!atMax) {
3054+
/* The next full timeout still backs off. */
3055+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS);
3056+
ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_s),
3057+
timeout * DTLS_TIMEOUT_MULTIPLIER);
3058+
}
3059+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
3060+
3061+
wolfSSL_free(ssl_c);
3062+
wolfSSL_free(ssl_s);
3063+
wolfSSL_CTX_free(ctx_c);
3064+
wolfSSL_CTX_free(ctx_s);
3065+
return EXPECT_RESULT();
3066+
}
3067+
#endif
3068+
3069+
int test_dtls13_quick_timeout_no_backoff(void)
3070+
{
3071+
EXPECT_DECLS;
3072+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
3073+
defined(WOLFSSL_DTLS13) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
3074+
!defined(WOLFSSL_NO_CLIENT_AUTH)
3075+
ExpectIntEQ(test_dtls13_quick_timeout_no_backoff_ex(0), TEST_SUCCESS);
3076+
ExpectIntEQ(test_dtls13_quick_timeout_no_backoff_ex(1), TEST_SUCCESS);
3077+
#endif
3078+
return EXPECT_RESULT();
3079+
}
3080+
30023081
int test_dtls_bogus_finished_epoch_zero(void)
30033082
{
30043083
EXPECT_DECLS;

‎tests/api/test_dtls.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ int test_records_span_network_boundaries(void);
5656
int test_dtls_record_cross_boundaries(void);
5757
int test_dtls_rtx_across_epoch_change(void);
5858
int test_dtls_drop_client_ack(void);
59+
int test_dtls13_quick_timeout_no_backoff(void);
5960
int test_dtls_bogus_finished_epoch_zero(void);
6061
int test_dtls_replay(void);
6162
int test_dtls_timeout(void);
@@ -262,6 +263,7 @@ int test_dtls_no_cookie_ch_pause(WOLFSSL* ssl, void* ctx);
262263
TEST_DECL_GROUP("dtls", test_dtls_record_cross_boundaries), \
263264
TEST_DECL_GROUP("dtls", test_dtls_rtx_across_epoch_change), \
264265
TEST_DECL_GROUP("dtls", test_dtls_drop_client_ack), \
266+
TEST_DECL_GROUP("dtls", test_dtls13_quick_timeout_no_backoff), \
265267
TEST_DECL_GROUP("dtls", test_dtls_bogus_finished_epoch_zero), \
266268
TEST_DECL_GROUP("dtls", test_dtls_replay), \
267269
TEST_DECL_GROUP("dtls", test_dtls_certreq_order), \

0 commit comments

Comments
 (0)