File openssl-1_1-CVE-2023-3817.patch of Package openssl-1_1
xxxxxxxxxx
1
From 91ddeba0f2269b017dc06c46c993a788974b1aa5 Mon Sep 17 00:00:00 2001
2
From: Tomas Mraz <tomas@openssl.org>
3
Date: Fri, 21 Jul 2023 11:39:41 +0200
4
Subject: [PATCH 198/200] DH_check(): Do not try checking q properties if it is
5
obviously invalid
6
7
If |q| >= |p| then the q value is obviously wrong as q
8
is supposed to be a prime divisor of p-1.
9
10
We check if p is overly large so this added test implies that
11
q is not large either when performing subsequent tests using that
12
q value.
13
14
Otherwise if it is too large these additional checks of the q value
15
such as the primality test can then trigger DoS by doing overly long
16
computations.
17
18
Fixes CVE-2023-3817
19
20
Reviewed-by: Paul Dale <pauli@openssl.org>
21
Reviewed-by: Matt Caswell <matt@openssl.org>
22
(Merged from https://github.com/openssl/openssl/pull/21551)
23
24
Index: openssl-1.1.1l/crypto/dh/dh_check.c
25
===================================================================
26
--- openssl-1.1.1l.orig/crypto/dh/dh_check.c
27
+++ openssl-1.1.1l/crypto/dh/dh_check.c
28
29
/* Note: according to documentation - this only checks the params */
30
int DH_check(const DH *dh, int *ret)
31
{
32
- int ok = 0, r;
33
+ int ok = 0, r, q_good = 0;
34
BN_CTX *ctx = NULL;
35
BIGNUM *t1 = NULL, *t2 = NULL;
36
37
38
if (t2 == NULL)
39
goto err;
40
41
- if (dh->q) {
42
+ if (dh->q != NULL) {
43
+ if (BN_ucmp(dh->p, dh->q) > 0)
44
+ q_good = 1;
45
+ else
46
+ *ret |= DH_CHECK_INVALID_Q_VALUE;
47
+ }
48
+
49
+ if (q_good) {
50
if (BN_cmp(dh->g, BN_value_one()) <= 0)
51
*ret |= DH_NOT_SUITABLE_GENERATOR;
52
else if (BN_cmp(dh->g, dh->p) >= 0)
53
From 34d0f5cb93680a5286d1eb59125631ec8fd6dc81 Mon Sep 17 00:00:00 2001
54
From: Tomas Mraz <tomas@openssl.org>
55
Date: Tue, 25 Jul 2023 15:56:53 +0200
56
Subject: [PATCH] dhtest.c: Add test of DH_check() with q = p + 1
57
58
This must fail with DH_CHECK_INVALID_Q_VALUE and
59
with DH_CHECK_Q_NOT_PRIME unset.
60
61
Reviewed-by: Paul Dale <pauli@openssl.org>
62
Reviewed-by: Matt Caswell <matt@openssl.org>
63
(Merged from https://github.com/openssl/openssl/pull/21551)
64
---
65
test/dhtest.c | 12 ++++++++++++
66
1 file changed, 12 insertions(+)
67
68
diff --git a/test/dhtest.c b/test/dhtest.c
69
index 00b3c471015d..d7e10ebda9b5 100644
70
--- a/test/dhtest.c
71
+++ b/test/dhtest.c
72
73
/* check whether the public key was calculated correctly */
74
TEST_uint_eq(BN_get_word(pub_key2), 3331L);
75
76
+ if (!TEST_ptr(BN_copy(q, p)) || !TEST_true(BN_add(q, q, BN_value_one())))
77
+ goto err3;
78
+
79
+ if (!TEST_true(DH_check(dh, &i)))
80
+ goto err3;
81
+ if (!TEST_true(i & DH_CHECK_INVALID_Q_VALUE)
82
+ || !TEST_false(i & DH_CHECK_Q_NOT_PRIME))
83
+ goto err3;
84
+
85
/* Modulus of size: dh check max modulus bits + 1 */
86
if (!TEST_true(BN_set_word(p, 1))
87
|| !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
88
89
if (!TEST_false(DH_check(dh, &i)))
90
goto err3;
91
92
+ /* We'll have a stale error on the queue from the above test so clear it */
93
+ ERR_clear_error();
94
+
95
/*
96
* II) key generation
97
*/
98