|
@@ -0,0 +1,101 @@
|
|
1
|
+From 60d7aeb6e1450995e721d01f48f60b7db4c44e2b Mon Sep 17 00:00:00 2001
|
|
2
|
+From: Remi Gacogne <rgacogne[at]aquaray[dot]fr>
|
|
3
|
+Date: Tue, 15 Jul 2014 11:36:40 +0200
|
|
4
|
+Subject: [PATCH 3/3] BUG/MEDIUM: ssl: Fix a memory leak in DHE key exchange
|
|
5
|
+
|
|
6
|
+OpenSSL does not free the DH * value returned by the callback specified with SSL_CTX_set_tmp_dh_callback(),
|
|
7
|
+leading to a memory leak for SSL/TLS connections using Diffie Hellman Ephemeral key exchange.
|
|
8
|
+This patch fixes the leak by allocating the DH * structs holding the DH parameters once, at configuration time.
|
|
9
|
+
|
|
10
|
+Note: this fix must be backported to 1.5.
|
|
11
|
+(cherry picked from commit 8de5415b85512da871d58d1e9a0a33bd67f3b570)
|
|
12
|
+---
|
|
13
|
+ src/ssl_sock.c | 43 ++++++++++++++++++++++++++++++++++++-------
|
|
14
|
+ 1 file changed, 36 insertions(+), 7 deletions(-)
|
|
15
|
+
|
|
16
|
+diff --git a/src/ssl_sock.c b/src/ssl_sock.c
|
|
17
|
+index 375225d..cf8adc7 100644
|
|
18
|
+--- a/src/ssl_sock.c
|
|
19
|
++++ b/src/ssl_sock.c
|
|
20
|
+@@ -105,6 +105,13 @@ enum {
|
|
21
|
+ int sslconns = 0;
|
|
22
|
+ int totalsslconns = 0;
|
|
23
|
+
|
|
24
|
++#ifndef OPENSSL_NO_DH
|
|
25
|
++static DH *local_dh_1024 = NULL;
|
|
26
|
++static DH *local_dh_2048 = NULL;
|
|
27
|
++static DH *local_dh_4096 = NULL;
|
|
28
|
++static DH *local_dh_8192 = NULL;
|
|
29
|
++#endif /* OPENSSL_NO_DH */
|
|
30
|
++
|
|
31
|
+ #ifdef SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB
|
|
32
|
+ struct certificate_ocsp {
|
|
33
|
+ struct ebmb_node key;
|
|
34
|
+@@ -1034,16 +1041,16 @@ static DH *ssl_get_tmp_dh(SSL *ssl, int export, int keylen)
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ if (keylen >= 8192) {
|
|
38
|
+- dh = ssl_get_dh_8192();
|
|
39
|
++ dh = local_dh_8192;
|
|
40
|
+ }
|
|
41
|
+ else if (keylen >= 4096) {
|
|
42
|
+- dh = ssl_get_dh_4096();
|
|
43
|
++ dh = local_dh_4096;
|
|
44
|
+ }
|
|
45
|
+ else if (keylen >= 2048) {
|
|
46
|
+- dh = ssl_get_dh_2048();
|
|
47
|
++ dh = local_dh_2048;
|
|
48
|
+ }
|
|
49
|
+ else {
|
|
50
|
+- dh = ssl_get_dh_1024();
|
|
51
|
++ dh = local_dh_1024;
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ return dh;
|
|
55
|
+@@ -1079,11 +1086,11 @@ int ssl_sock_load_dh_params(SSL_CTX *ctx, const char *file)
|
|
56
|
+
|
|
57
|
+ if (global.tune.ssl_default_dh_param <= 1024) {
|
|
58
|
+ /* we are limited to DH parameter of 1024 bits anyway */
|
|
59
|
+- dh = ssl_get_dh_1024();
|
|
60
|
+- if (dh == NULL)
|
|
61
|
++ local_dh_1024 = ssl_get_dh_1024();
|
|
62
|
++ if (local_dh_1024 == NULL)
|
|
63
|
+ goto end;
|
|
64
|
+
|
|
65
|
+- SSL_CTX_set_tmp_dh(ctx, dh);
|
|
66
|
++ SSL_CTX_set_tmp_dh(ctx, local_dh_1024);
|
|
67
|
+ }
|
|
68
|
+ else {
|
|
69
|
+ SSL_CTX_set_tmp_dh_callback(ctx, ssl_get_tmp_dh);
|
|
70
|
+@@ -1594,6 +1601,28 @@ int ssl_sock_prepare_ctx(struct bind_conf *bind_conf, SSL_CTX *ctx, struct proxy
|
|
71
|
+ global.tune.ssl_default_dh_param = 1024;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
++#ifndef OPENSSL_NO_DH
|
|
75
|
++ if (global.tune.ssl_default_dh_param >= 1024) {
|
|
76
|
++ if (local_dh_1024 == NULL) {
|
|
77
|
++ local_dh_1024 = ssl_get_dh_1024();
|
|
78
|
++ }
|
|
79
|
++ if (global.tune.ssl_default_dh_param >= 2048) {
|
|
80
|
++ if (local_dh_2048 == NULL) {
|
|
81
|
++ local_dh_2048 = ssl_get_dh_2048();
|
|
82
|
++ }
|
|
83
|
++ if (global.tune.ssl_default_dh_param >= 4096) {
|
|
84
|
++ if (local_dh_4096 == NULL) {
|
|
85
|
++ local_dh_4096 = ssl_get_dh_4096();
|
|
86
|
++ }
|
|
87
|
++ if (global.tune.ssl_default_dh_param >= 8192 &&
|
|
88
|
++ local_dh_8192 == NULL) {
|
|
89
|
++ local_dh_8192 = ssl_get_dh_8192();
|
|
90
|
++ }
|
|
91
|
++ }
|
|
92
|
++ }
|
|
93
|
++ }
|
|
94
|
++#endif /* OPENSSL_NO_DH */
|
|
95
|
++
|
|
96
|
+ SSL_CTX_set_info_callback(ctx, ssl_sock_infocbk);
|
|
97
|
+ #if OPENSSL_VERSION_NUMBER >= 0x00907000L
|
|
98
|
+ SSL_CTX_set_msg_callback(ctx, ssl_sock_msgcbk);
|
|
99
|
+--
|
|
100
|
+1.8.5.5
|
|
101
|
+
|