summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2021-03-15 15:59:04 +0000
committertb <>2021-03-15 15:59:04 +0000
commitfc06cdeb11963e348e9787bb95689f9be064a506 (patch)
treeb29d9e1fea7b39c9759db74aee2ef863823a7455
parent70029edfad38276befdaee62f4fe7e084070c0cd (diff)
downloadopenbsd-libressl-v3.2.5.tar.gz
openbsd-libressl-v3.2.5.tar.bz2
openbsd-libressl-v3.2.5.zip
Don't leave stale sequence numbers behind in ssl3_clear()libressl-v3.2.5
A TLS client doing session reuse in a certain way could run into a use-after-free. Set the sequence numbers inside ssl3_clear() to make sure this points at valid memory and do the initialization of the record layer a bit earlier so that this works as desired. Additionally, explicitly clear the sequence numbers in ssl3_free() which would have turned the use-after-free into a NULL dereference. Issue reported by Ilya Chipitsine. Fix from jsing This is errata/6.8/017_libssl.patch.sig
-rw-r--r--src/lib/libssl/s3_lib.c11
-rw-r--r--src/lib/libssl/ssl_lib.c7
2 files changed, 13 insertions, 5 deletions
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
index 91bfb5f3b6..97dd2005c2 100644
--- a/src/lib/libssl/s3_lib.c
+++ b/src/lib/libssl/s3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_lib.c,v 1.198 2020/09/17 15:42:14 jsing Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.198.4.1 2021/03/15 15:59:04 tb 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 *
@@ -1577,6 +1577,10 @@ ssl3_free(SSL *s)
1577 1577
1578 free(S3I(s)->alpn_selected); 1578 free(S3I(s)->alpn_selected);
1579 1579
1580 /* Clear reference to sequence numbers. */
1581 tls12_record_layer_clear_read_state(s->internal->rl);
1582 tls12_record_layer_clear_write_state(s->internal->rl);
1583
1580 freezero(S3I(s), sizeof(*S3I(s))); 1584 freezero(S3I(s), sizeof(*S3I(s)));
1581 freezero(s->s3, sizeof(*s->s3)); 1585 freezero(s->s3, sizeof(*s->s3));
1582 1586
@@ -1649,6 +1653,11 @@ ssl3_clear(SSL *s)
1649 s->internal->packet_length = 0; 1653 s->internal->packet_length = 0;
1650 s->version = TLS1_VERSION; 1654 s->version = TLS1_VERSION;
1651 1655
1656 tls12_record_layer_set_read_seq_num(s->internal->rl,
1657 S3I(s)->read_sequence);
1658 tls12_record_layer_set_write_seq_num(s->internal->rl,
1659 S3I(s)->write_sequence);
1660
1652 S3I(s)->hs.state = SSL_ST_BEFORE|((s->server) ? SSL_ST_ACCEPT : SSL_ST_CONNECT); 1661 S3I(s)->hs.state = SSL_ST_BEFORE|((s->server) ? SSL_ST_ACCEPT : SSL_ST_CONNECT);
1653} 1662}
1654 1663
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index 1cf64d1301..d7d3d0c051 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.234.4.1 2021/02/03 07:06:13 tb Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.234.4.2 2021/03/15 15:59:04 tb 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 *
@@ -253,6 +253,8 @@ SSL_new(SSL_CTX *ctx)
253 goto err; 253 goto err;
254 if ((s->internal = calloc(1, sizeof(*s->internal))) == NULL) 254 if ((s->internal = calloc(1, sizeof(*s->internal))) == NULL)
255 goto err; 255 goto err;
256 if ((s->internal->rl = tls12_record_layer_new()) == NULL)
257 goto err;
256 258
257 s->internal->min_version = ctx->internal->min_version; 259 s->internal->min_version = ctx->internal->min_version;
258 s->internal->max_version = ctx->internal->max_version; 260 s->internal->max_version = ctx->internal->max_version;
@@ -341,9 +343,6 @@ SSL_new(SSL_CTX *ctx)
341 if (!s->method->internal->ssl_new(s)) 343 if (!s->method->internal->ssl_new(s))
342 goto err; 344 goto err;
343 345
344 if ((s->internal->rl = tls12_record_layer_new()) == NULL)
345 goto err;
346
347 s->references = 1; 346 s->references = 1;
348 s->server = (ctx->method->internal->ssl_accept == ssl_undefined_function) ? 0 : 1; 347 s->server = (ctx->method->internal->ssl_accept == ssl_undefined_function) ? 0 : 1;
349 348