summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-10-25 10:14:48 +0000
committerjsing <>2021-10-25 10:14:48 +0000
commite3f2ec519b25cefd4a104b2b27e0831a9b500067 (patch)
tree72099adc9016a30359e826e49affebd213eae6cd
parentca06f0eb8077fb22dbd7cd11aa65d4c1e3b1c452 (diff)
downloadopenbsd-e3f2ec519b25cefd4a104b2b27e0831a9b500067.tar.gz
openbsd-e3f2ec519b25cefd4a104b2b27e0831a9b500067.tar.bz2
openbsd-e3f2ec519b25cefd4a104b2b27e0831a9b500067.zip
Add record processing limit to DTLS code.
This is effectively the same record processing limit that was previously added to the legacy TLS stack - without this a single session can be made to spin on a stream of alerts or other similar records. ok beck@ tb@
-rw-r--r--src/lib/libssl/d1_pkt.c16
-rw-r--r--src/lib/libssl/ssl_pkt.c5
2 files changed, 18 insertions, 3 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index 9601a39e3a..f0f393b0fd 100644
--- a/src/lib/libssl/d1_pkt.c
+++ b/src/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_pkt.c,v 1.114 2021/10/25 10:09:28 jsing Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.115 2021/10/25 10:14:48 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -514,6 +514,7 @@ int
514dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 514dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
515{ 515{
516 int al, i, ret; 516 int al, i, ret;
517 int rrcount = 0;
517 unsigned int n; 518 unsigned int n;
518 SSL3_RECORD_INTERNAL *rr; 519 SSL3_RECORD_INTERNAL *rr;
519 520
@@ -539,6 +540,19 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
539 } 540 }
540 541
541 start: 542 start:
543 /*
544 * Do not process more than three consecutive records, otherwise the
545 * peer can cause us to loop indefinitely. Instead, return with an
546 * SSL_ERROR_WANT_READ so the caller can choose when to handle further
547 * processing. In the future, the total number of non-handshake and
548 * non-application data records per connection should probably also be
549 * limited...
550 */
551 if (rrcount++ >= 3) {
552 ssl_force_want_read(s);
553 return -1;
554 }
555
542 s->internal->rwstate = SSL_NOTHING; 556 s->internal->rwstate = SSL_NOTHING;
543 557
544 /* S3I(s)->rrec.type - is the type of record 558 /* S3I(s)->rrec.type - is the type of record
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c
index 8a5f97e5c7..e3101eefba 100644
--- a/src/lib/libssl/ssl_pkt.c
+++ b/src/lib/libssl/ssl_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_pkt.c,v 1.51 2021/10/25 10:09:28 jsing Exp $ */ 1/* $OpenBSD: ssl_pkt.c,v 1.52 2021/10/25 10:14:48 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -715,7 +715,8 @@ ssl3_write_pending(SSL *s, int type, const unsigned char *buf, unsigned int len)
715int 715int
716ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 716ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
717{ 717{
718 int al, i, ret, rrcount = 0; 718 int al, i, ret;
719 int rrcount = 0;
719 unsigned int n; 720 unsigned int n;
720 SSL3_RECORD_INTERNAL *rr; 721 SSL3_RECORD_INTERNAL *rr;
721 722