summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2021-06-19 17:21:40 +0000
committerjsing <>2021-06-19 17:21:40 +0000
commit6afe60e39f7d03240c1f094e1f341b84a8de3f4e (patch)
tree4031b006d4844852d99c4ada4526be15b731c8e0 /src
parente5895fba963b225b4275079fc84444579ae34b3d (diff)
downloadopenbsd-6afe60e39f7d03240c1f094e1f341b84a8de3f4e.tar.gz
openbsd-6afe60e39f7d03240c1f094e1f341b84a8de3f4e.tar.bz2
openbsd-6afe60e39f7d03240c1f094e1f341b84a8de3f4e.zip
Correctly handle epoch wrapping in dtls1_get_bitmap().
Due to a type bug that has been present in DTLS since the code was first committed in 2005, dtls1_get_bitmap() fails to handle next epoch correctly when the epoch is currently 0xffff (and wraps to zero). For various reasons unknown, the epoch field in the SSL3_RECORD_INTERNAL (formerly SSL3_RECORD) was added as unsigned long (even though the value is an unsigned 16 bit value on the wire, hence cannot exceed 0xffff), however was added to other code as unsigned short. Due to integer promotion, the r_epoch value is incremented by one to become 0x10000, before being cast to an unsigned long and compared to the value pulled from the DTLS record header (which is zero). Strangely 0x10000 != 0, meaning that we drop the DTLS record, instead of queueing it for the next epoch. Fix this issue by using more appropriate types and pulling up the calculation of the next epoch value for improved readability. ok inoguchi@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/d1_pkt.c5
-rw-r--r--src/lib/libssl/ssl_locl.h4
2 files changed, 5 insertions, 4 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index 11735f0d2c..17be6dd182 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.98 2021/06/15 19:09:03 jsing Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.99 2021/06/19 17:21:39 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.
@@ -1191,6 +1191,7 @@ dtls1_dispatch_alert(SSL *s)
1191static DTLS1_BITMAP * 1191static DTLS1_BITMAP *
1192dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch) 1192dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
1193{ 1193{
1194 uint16_t next_epoch = D1I(s)->r_epoch + 1;
1194 1195
1195 *is_next_epoch = 0; 1196 *is_next_epoch = 0;
1196 1197
@@ -1199,7 +1200,7 @@ dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
1199 return &D1I(s)->bitmap; 1200 return &D1I(s)->bitmap;
1200 1201
1201 /* Only HM and ALERT messages can be from the next epoch */ 1202 /* Only HM and ALERT messages can be from the next epoch */
1202 else if (rr->epoch == (unsigned long)(D1I(s)->r_epoch + 1) && 1203 else if (rr->epoch == next_epoch &&
1203 (rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) { 1204 (rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
1204 *is_next_epoch = 1; 1205 *is_next_epoch = 1;
1205 return &D1I(s)->next_bitmap; 1206 return &D1I(s)->next_bitmap;
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 18509438ae..d171ef0984 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.349 2021/06/19 16:52:47 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.350 2021/06/19 17:21:40 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 *
@@ -886,7 +886,7 @@ typedef struct ssl3_record_internal_st {
886 unsigned int off; /* read/write offset into 'buf' */ 886 unsigned int off; /* read/write offset into 'buf' */
887 unsigned char *data; /* pointer to the record data */ 887 unsigned char *data; /* pointer to the record data */
888 unsigned char *input; /* where the decode bytes are */ 888 unsigned char *input; /* where the decode bytes are */
889 unsigned long epoch; /* epoch number, needed by DTLS1 */ 889 uint16_t epoch; /* epoch number, needed by DTLS1 */
890 unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */ 890 unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
891} SSL3_RECORD_INTERNAL; 891} SSL3_RECORD_INTERNAL;
892 892