summaryrefslogtreecommitdiff
path: root/src/lib/libssl
diff options
context:
space:
mode:
authorjsing <>2026-05-06 15:02:51 +0000
committerjsing <>2026-05-06 15:02:51 +0000
commite162d1d43a0870508c4db32a52b441f1b7d96ebe (patch)
tree0ab1491176809140f9a95fa946d6ef668f74593b /src/lib/libssl
parentda19cc86929787482add39a31b6d4de43375bf68 (diff)
downloadopenbsd-e162d1d43a0870508c4db32a52b441f1b7d96ebe.tar.gz
openbsd-e162d1d43a0870508c4db32a52b441f1b7d96ebe.tar.bz2
openbsd-e162d1d43a0870508c4db32a52b441f1b7d96ebe.zip
Avoid use of uninitialised decode_error variable.
Pull initialisation of decode_error and invalid_key up to tls_key_share_{client,server}_peer_public(), which are the entry points for the key share code. The entry point was previously tls_key_share_peer_public(), however with the introduction of MLKEM this was split into separate client and server functions, without the initialisation being included. Also initialise decode_error and invalid_params on entry to tls_key_share_peer_params(). Code that reaches tls_key_share_client_peer_public_mlkem768x25519() could previously result in code branching based on decode_error, which is uninitialised stack based memory. Thanks to Guido Vranken of Aisle Research for reporting this issue. With and ok tb@
Diffstat (limited to 'src/lib/libssl')
-rw-r--r--src/lib/libssl/tls_key_share.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/lib/libssl/tls_key_share.c b/src/lib/libssl/tls_key_share.c
index 9e04cb7b75..48b353d318 100644
--- a/src/lib/libssl/tls_key_share.c
+++ b/src/lib/libssl/tls_key_share.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_key_share.c,v 1.10 2026/01/01 12:47:52 tb Exp $ */ 1/* $OpenBSD: tls_key_share.c,v 1.11 2026/05/06 15:02:51 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -469,6 +469,9 @@ int
469tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs, 469tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs,
470 int *decode_error, int *invalid_params) 470 int *decode_error, int *invalid_params)
471{ 471{
472 *decode_error = 0;
473 *invalid_params = 0;
474
472 if (ks->nid != NID_dhKeyAgreement) 475 if (ks->nid != NID_dhKeyAgreement)
473 return 0; 476 return 0;
474 477
@@ -518,8 +521,6 @@ tls_key_share_peer_public_x25519(struct tls_key_share *ks, CBS *cbs,
518{ 521{
519 size_t out_len; 522 size_t out_len;
520 523
521 *decode_error = 0;
522
523 if (ks->x25519_peer_public != NULL) 524 if (ks->x25519_peer_public != NULL)
524 return 0; 525 return 0;
525 526
@@ -570,8 +571,6 @@ tls_key_share_server_peer_public_mlkem768x25519(struct tls_key_share *ks,
570 CBS x25519_cbs, mlkem768_cbs; 571 CBS x25519_cbs, mlkem768_cbs;
571 size_t out_len; 572 size_t out_len;
572 573
573 *decode_error = 0;
574
575 /* The server should not have an mlkem private key */ 574 /* The server should not have an mlkem private key */
576 if (ks->mlkem_private != NULL) 575 if (ks->mlkem_private != NULL)
577 return 0; 576 return 0;
@@ -619,11 +618,6 @@ static int
619tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, int *decode_error, 618tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, int *decode_error,
620 int *invalid_key) 619 int *invalid_key)
621{ 620{
622 *decode_error = 0;
623
624 if (invalid_key != NULL)
625 *invalid_key = 0;
626
627 if (ks->nid == NID_dhKeyAgreement) 621 if (ks->nid == NID_dhKeyAgreement)
628 return tls_key_share_peer_public_dhe(ks, cbs, decode_error, 622 return tls_key_share_peer_public_dhe(ks, cbs, decode_error,
629 invalid_key); 623 invalid_key);
@@ -639,6 +633,11 @@ int
639tls_key_share_client_peer_public(struct tls_key_share *ks, CBS *cbs, 633tls_key_share_client_peer_public(struct tls_key_share *ks, CBS *cbs,
640 int *decode_error, int *invalid_key) 634 int *decode_error, int *invalid_key)
641{ 635{
636 *decode_error = 0;
637
638 if (invalid_key != NULL)
639 *invalid_key = 0;
640
642 if (ks->nid == NID_X25519MLKEM768) 641 if (ks->nid == NID_X25519MLKEM768)
643 return tls_key_share_client_peer_public_mlkem768x25519(ks, cbs, 642 return tls_key_share_client_peer_public_mlkem768x25519(ks, cbs,
644 decode_error); 643 decode_error);
@@ -651,6 +650,11 @@ int
651tls_key_share_server_peer_public(struct tls_key_share *ks, CBS *cbs, 650tls_key_share_server_peer_public(struct tls_key_share *ks, CBS *cbs,
652 int *decode_error, int *invalid_key) 651 int *decode_error, int *invalid_key)
653{ 652{
653 *decode_error = 0;
654
655 if (invalid_key != NULL)
656 *invalid_key = 0;
657
654 if (ks->nid == NID_X25519MLKEM768) 658 if (ks->nid == NID_X25519MLKEM768)
655 return tls_key_share_server_peer_public_mlkem768x25519(ks, cbs, 659 return tls_key_share_server_peer_public_mlkem768x25519(ks, cbs,
656 decode_error); 660 decode_error);