lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

openssl: fix CVE-2016-2177

+546 -2
+256
pkgs/development/libraries/openssl/1.0.1-CVE-2016-2177.diff
··· 1 + From 6f35f6deb5ca7daebe289f86477e061ce3ee5f46 Mon Sep 17 00:00:00 2001 2 + From: Matt Caswell <matt@openssl.org> 3 + Date: Thu, 5 May 2016 11:10:26 +0100 4 + Subject: [PATCH] Avoid some undefined pointer arithmetic 5 + 6 + A common idiom in the codebase is: 7 + 8 + if (p + len > limit) 9 + { 10 + return; /* Too long */ 11 + } 12 + 13 + Where "p" points to some malloc'd data of SIZE bytes and 14 + limit == p + SIZE 15 + 16 + "len" here could be from some externally supplied data (e.g. from a TLS 17 + message). 18 + 19 + The rules of C pointer arithmetic are such that "p + len" is only well 20 + defined where len <= SIZE. Therefore the above idiom is actually 21 + undefined behaviour. 22 + 23 + For example this could cause problems if some malloc implementation 24 + provides an address for "p" such that "p + len" actually overflows for 25 + values of len that are too big and therefore p + len < limit! 26 + 27 + Issue reported by Guido Vranken. 28 + 29 + CVE-2016-2177 30 + 31 + Reviewed-by: Rich Salz <rsalz@openssl.org> 32 + --- 33 + ssl/s3_srvr.c | 14 +++++++------- 34 + ssl/ssl_sess.c | 2 +- 35 + ssl/t1_lib.c | 48 ++++++++++++++++++++++++++---------------------- 36 + 3 files changed, 34 insertions(+), 30 deletions(-) 37 + 38 + diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c 39 + index 04cf93a..6c74caa 100644 40 + --- a/ssl/s3_srvr.c 41 + +++ b/ssl/s3_srvr.c 42 + @@ -1040,7 +1040,7 @@ int ssl3_get_client_hello(SSL *s) 43 + 44 + session_length = *(p + SSL3_RANDOM_SIZE); 45 + 46 + - if (p + SSL3_RANDOM_SIZE + session_length + 1 >= d + n) { 47 + + if (SSL3_RANDOM_SIZE + session_length + 1 >= (d + n) - p) { 48 + al = SSL_AD_DECODE_ERROR; 49 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 50 + goto f_err; 51 + @@ -1058,7 +1058,7 @@ int ssl3_get_client_hello(SSL *s) 52 + /* get the session-id */ 53 + j = *(p++); 54 + 55 + - if (p + j > d + n) { 56 + + if ((d + n) - p < j) { 57 + al = SSL_AD_DECODE_ERROR; 58 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 59 + goto f_err; 60 + @@ -1114,14 +1114,14 @@ int ssl3_get_client_hello(SSL *s) 61 + 62 + if (s->version == DTLS1_VERSION || s->version == DTLS1_BAD_VER) { 63 + /* cookie stuff */ 64 + - if (p + 1 > d + n) { 65 + + if ((d + n) - p < 1) { 66 + al = SSL_AD_DECODE_ERROR; 67 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 68 + goto f_err; 69 + } 70 + cookie_len = *(p++); 71 + 72 + - if (p + cookie_len > d + n) { 73 + + if ((d + n ) - p < cookie_len) { 74 + al = SSL_AD_DECODE_ERROR; 75 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 76 + goto f_err; 77 + @@ -1166,7 +1166,7 @@ int ssl3_get_client_hello(SSL *s) 78 + p += cookie_len; 79 + } 80 + 81 + - if (p + 2 > d + n) { 82 + + if ((d + n ) - p < 2) { 83 + al = SSL_AD_DECODE_ERROR; 84 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 85 + goto f_err; 86 + @@ -1180,7 +1180,7 @@ int ssl3_get_client_hello(SSL *s) 87 + } 88 + 89 + /* i bytes of cipher data + 1 byte for compression length later */ 90 + - if ((p + i + 1) > (d + n)) { 91 + + if ((d + n) - p < i + 1) { 92 + /* not enough data */ 93 + al = SSL_AD_DECODE_ERROR; 94 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); 95 + @@ -1246,7 +1246,7 @@ int ssl3_get_client_hello(SSL *s) 96 + 97 + /* compression */ 98 + i = *(p++); 99 + - if ((p + i) > (d + n)) { 100 + + if ((d + n) - p < i) { 101 + /* not enough data */ 102 + al = SSL_AD_DECODE_ERROR; 103 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); 104 + diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c 105 + index 48fc451..a97d060 100644 106 + --- a/ssl/ssl_sess.c 107 + +++ b/ssl/ssl_sess.c 108 + @@ -602,7 +602,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, 109 + int r; 110 + #endif 111 + 112 + - if (session_id + len > limit) { 113 + + if (limit - session_id < len) { 114 + fatal = 1; 115 + goto err; 116 + } 117 + diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c 118 + index 0bdb77d..8ed1793 100644 119 + --- a/ssl/t1_lib.c 120 + +++ b/ssl/t1_lib.c 121 + @@ -942,11 +942,11 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 122 + 0x02, 0x03, /* SHA-1/ECDSA */ 123 + }; 124 + 125 + - if (data >= (limit - 2)) 126 + + if (limit - data <= 2) 127 + return; 128 + data += 2; 129 + 130 + - if (data > (limit - 4)) 131 + + if (limit - data < 4) 132 + return; 133 + n2s(data, type); 134 + n2s(data, size); 135 + @@ -954,7 +954,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 136 + if (type != TLSEXT_TYPE_server_name) 137 + return; 138 + 139 + - if (data + size > limit) 140 + + if (limit - data < size) 141 + return; 142 + data += size; 143 + 144 + @@ -962,7 +962,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 145 + const size_t len1 = sizeof(kSafariExtensionsBlock); 146 + const size_t len2 = sizeof(kSafariTLS12ExtensionsBlock); 147 + 148 + - if (data + len1 + len2 != limit) 149 + + if (limit - data != (int)(len1 + len2)) 150 + return; 151 + if (memcmp(data, kSafariExtensionsBlock, len1) != 0) 152 + return; 153 + @@ -971,7 +971,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 154 + } else { 155 + const size_t len = sizeof(kSafariExtensionsBlock); 156 + 157 + - if (data + len != limit) 158 + + if (limit - data != (int)(len)) 159 + return; 160 + if (memcmp(data, kSafariExtensionsBlock, len) != 0) 161 + return; 162 + @@ -1019,19 +1019,19 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, 163 + if (data == limit) 164 + goto ri_check; 165 + 166 + - if (data > (limit - 2)) 167 + + if (limit - data < 2) 168 + goto err; 169 + 170 + n2s(data, len); 171 + 172 + - if (data + len != limit) 173 + + if (limit - data != len) 174 + goto err; 175 + 176 + - while (data <= (limit - 4)) { 177 + + while (limit - data >= 4) { 178 + n2s(data, type); 179 + n2s(data, size); 180 + 181 + - if (data + size > (limit)) 182 + + if (limit - data < size) 183 + goto err; 184 + # if 0 185 + fprintf(stderr, "Received extension type %d size %d\n", type, size); 186 + @@ -1460,20 +1460,20 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, 187 + SSL_TLSEXT_HB_DONT_SEND_REQUESTS); 188 + # endif 189 + 190 + - if (data >= (d + n - 2)) 191 + + if ((d + n) - data <= 2) 192 + goto ri_check; 193 + 194 + n2s(data, length); 195 + - if (data + length != d + n) { 196 + + if ((d + n) - data != length) { 197 + *al = SSL_AD_DECODE_ERROR; 198 + return 0; 199 + } 200 + 201 + - while (data <= (d + n - 4)) { 202 + + while ((d + n) - data >= 4) { 203 + n2s(data, type); 204 + n2s(data, size); 205 + 206 + - if (data + size > (d + n)) 207 + + if ((d + n) - data < size) 208 + goto ri_check; 209 + 210 + if (s->tlsext_debug_cb) 211 + @@ -2179,29 +2179,33 @@ int tls1_process_ticket(SSL *s, unsigned char *session_id, int len, 212 + /* Skip past DTLS cookie */ 213 + if (s->version == DTLS1_VERSION || s->version == DTLS1_BAD_VER) { 214 + i = *(p++); 215 + - p += i; 216 + - if (p >= limit) 217 + + 218 + + if (limit - p <= i) 219 + return -1; 220 + + 221 + + p += i; 222 + } 223 + /* Skip past cipher list */ 224 + n2s(p, i); 225 + - p += i; 226 + - if (p >= limit) 227 + + if (limit - p <= i) 228 + return -1; 229 + + p += i; 230 + + 231 + /* Skip past compression algorithm list */ 232 + i = *(p++); 233 + - p += i; 234 + - if (p > limit) 235 + + if (limit - p < i) 236 + return -1; 237 + + p += i; 238 + + 239 + /* Now at start of extensions */ 240 + - if ((p + 2) >= limit) 241 + + if (limit - p <= 2) 242 + return 0; 243 + n2s(p, i); 244 + - while ((p + 4) <= limit) { 245 + + while (limit - p >= 4) { 246 + unsigned short type, size; 247 + n2s(p, type); 248 + n2s(p, size); 249 + - if (p + size > limit) 250 + + if (limit - p < size) 251 + return 0; 252 + if (type == TLSEXT_TYPE_session_ticket) { 253 + int r; 254 + -- 255 + 1.9.1 256 +
+279
pkgs/development/libraries/openssl/1.0.2-CVE-2016-2177.diff
··· 1 + From a004e72b95835136d3f1ea90517f706c24c03da7 Mon Sep 17 00:00:00 2001 2 + From: Matt Caswell <matt@openssl.org> 3 + Date: Thu, 5 May 2016 11:10:26 +0100 4 + Subject: [PATCH] Avoid some undefined pointer arithmetic 5 + 6 + A common idiom in the codebase is: 7 + 8 + if (p + len > limit) 9 + { 10 + return; /* Too long */ 11 + } 12 + 13 + Where "p" points to some malloc'd data of SIZE bytes and 14 + limit == p + SIZE 15 + 16 + "len" here could be from some externally supplied data (e.g. from a TLS 17 + message). 18 + 19 + The rules of C pointer arithmetic are such that "p + len" is only well 20 + defined where len <= SIZE. Therefore the above idiom is actually 21 + undefined behaviour. 22 + 23 + For example this could cause problems if some malloc implementation 24 + provides an address for "p" such that "p + len" actually overflows for 25 + values of len that are too big and therefore p + len < limit! 26 + 27 + Issue reported by Guido Vranken. 28 + 29 + CVE-2016-2177 30 + 31 + Reviewed-by: Rich Salz <rsalz@openssl.org> 32 + --- 33 + ssl/s3_srvr.c | 14 +++++++------- 34 + ssl/ssl_sess.c | 2 +- 35 + ssl/t1_lib.c | 56 ++++++++++++++++++++++++++++++-------------------------- 36 + 3 files changed, 38 insertions(+), 34 deletions(-) 37 + 38 + diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c 39 + index ab28702..ab7f690 100644 40 + --- a/ssl/s3_srvr.c 41 + +++ b/ssl/s3_srvr.c 42 + @@ -980,7 +980,7 @@ int ssl3_get_client_hello(SSL *s) 43 + 44 + session_length = *(p + SSL3_RANDOM_SIZE); 45 + 46 + - if (p + SSL3_RANDOM_SIZE + session_length + 1 >= d + n) { 47 + + if (SSL3_RANDOM_SIZE + session_length + 1 >= (d + n) - p) { 48 + al = SSL_AD_DECODE_ERROR; 49 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 50 + goto f_err; 51 + @@ -998,7 +998,7 @@ int ssl3_get_client_hello(SSL *s) 52 + /* get the session-id */ 53 + j = *(p++); 54 + 55 + - if (p + j > d + n) { 56 + + if ((d + n) - p < j) { 57 + al = SSL_AD_DECODE_ERROR; 58 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 59 + goto f_err; 60 + @@ -1054,14 +1054,14 @@ int ssl3_get_client_hello(SSL *s) 61 + 62 + if (SSL_IS_DTLS(s)) { 63 + /* cookie stuff */ 64 + - if (p + 1 > d + n) { 65 + + if ((d + n) - p < 1) { 66 + al = SSL_AD_DECODE_ERROR; 67 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 68 + goto f_err; 69 + } 70 + cookie_len = *(p++); 71 + 72 + - if (p + cookie_len > d + n) { 73 + + if ((d + n ) - p < cookie_len) { 74 + al = SSL_AD_DECODE_ERROR; 75 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 76 + goto f_err; 77 + @@ -1131,7 +1131,7 @@ int ssl3_get_client_hello(SSL *s) 78 + } 79 + } 80 + 81 + - if (p + 2 > d + n) { 82 + + if ((d + n ) - p < 2) { 83 + al = SSL_AD_DECODE_ERROR; 84 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); 85 + goto f_err; 86 + @@ -1145,7 +1145,7 @@ int ssl3_get_client_hello(SSL *s) 87 + } 88 + 89 + /* i bytes of cipher data + 1 byte for compression length later */ 90 + - if ((p + i + 1) > (d + n)) { 91 + + if ((d + n) - p < i + 1) { 92 + /* not enough data */ 93 + al = SSL_AD_DECODE_ERROR; 94 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); 95 + @@ -1211,7 +1211,7 @@ int ssl3_get_client_hello(SSL *s) 96 + 97 + /* compression */ 98 + i = *(p++); 99 + - if ((p + i) > (d + n)) { 100 + + if ((d + n) - p < i) { 101 + /* not enough data */ 102 + al = SSL_AD_DECODE_ERROR; 103 + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); 104 + diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c 105 + index b182998..54ee783 100644 106 + --- a/ssl/ssl_sess.c 107 + +++ b/ssl/ssl_sess.c 108 + @@ -573,7 +573,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, 109 + int r; 110 + #endif 111 + 112 + - if (session_id + len > limit) { 113 + + if (limit - session_id < len) { 114 + fatal = 1; 115 + goto err; 116 + } 117 + diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c 118 + index fb64607..cdac011 100644 119 + --- a/ssl/t1_lib.c 120 + +++ b/ssl/t1_lib.c 121 + @@ -1867,11 +1867,11 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 122 + 0x02, 0x03, /* SHA-1/ECDSA */ 123 + }; 124 + 125 + - if (data >= (limit - 2)) 126 + + if (limit - data <= 2) 127 + return; 128 + data += 2; 129 + 130 + - if (data > (limit - 4)) 131 + + if (limit - data < 4) 132 + return; 133 + n2s(data, type); 134 + n2s(data, size); 135 + @@ -1879,7 +1879,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 136 + if (type != TLSEXT_TYPE_server_name) 137 + return; 138 + 139 + - if (data + size > limit) 140 + + if (limit - data < size) 141 + return; 142 + data += size; 143 + 144 + @@ -1887,7 +1887,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 145 + const size_t len1 = sizeof(kSafariExtensionsBlock); 146 + const size_t len2 = sizeof(kSafariTLS12ExtensionsBlock); 147 + 148 + - if (data + len1 + len2 != limit) 149 + + if (limit - data != (int)(len1 + len2)) 150 + return; 151 + if (memcmp(data, kSafariExtensionsBlock, len1) != 0) 152 + return; 153 + @@ -1896,7 +1896,7 @@ static void ssl_check_for_safari(SSL *s, const unsigned char *data, 154 + } else { 155 + const size_t len = sizeof(kSafariExtensionsBlock); 156 + 157 + - if (data + len != limit) 158 + + if (limit - data != (int)(len)) 159 + return; 160 + if (memcmp(data, kSafariExtensionsBlock, len) != 0) 161 + return; 162 + @@ -2053,19 +2053,19 @@ static int ssl_scan_clienthello_tlsext(SSL *s, unsigned char **p, 163 + if (data == limit) 164 + goto ri_check; 165 + 166 + - if (data > (limit - 2)) 167 + + if (limit - data < 2) 168 + goto err; 169 + 170 + n2s(data, len); 171 + 172 + - if (data + len != limit) 173 + + if (limit - data != len) 174 + goto err; 175 + 176 + - while (data <= (limit - 4)) { 177 + + while (limit - data >= 4) { 178 + n2s(data, type); 179 + n2s(data, size); 180 + 181 + - if (data + size > (limit)) 182 + + if (limit - data < size) 183 + goto err; 184 + # if 0 185 + fprintf(stderr, "Received extension type %d size %d\n", type, size); 186 + @@ -2472,18 +2472,18 @@ static int ssl_scan_clienthello_custom_tlsext(SSL *s, 187 + if (s->hit || s->cert->srv_ext.meths_count == 0) 188 + return 1; 189 + 190 + - if (data >= limit - 2) 191 + + if (limit - data <= 2) 192 + return 1; 193 + n2s(data, len); 194 + 195 + - if (data > limit - len) 196 + + if (limit - data < len) 197 + return 1; 198 + 199 + - while (data <= limit - 4) { 200 + + while (limit - data >= 4) { 201 + n2s(data, type); 202 + n2s(data, size); 203 + 204 + - if (data + size > limit) 205 + + if (limit - data < size) 206 + return 1; 207 + if (custom_ext_parse(s, 1 /* server */ , type, data, size, al) <= 0) 208 + return 0; 209 + @@ -2569,20 +2569,20 @@ static int ssl_scan_serverhello_tlsext(SSL *s, unsigned char **p, 210 + SSL_TLSEXT_HB_DONT_SEND_REQUESTS); 211 + # endif 212 + 213 + - if (data >= (d + n - 2)) 214 + + if ((d + n) - data <= 2) 215 + goto ri_check; 216 + 217 + n2s(data, length); 218 + - if (data + length != d + n) { 219 + + if ((d + n) - data != length) { 220 + *al = SSL_AD_DECODE_ERROR; 221 + return 0; 222 + } 223 + 224 + - while (data <= (d + n - 4)) { 225 + + while ((d + n) - data >= 4) { 226 + n2s(data, type); 227 + n2s(data, size); 228 + 229 + - if (data + size > (d + n)) 230 + + if ((d + n) - data < size) 231 + goto ri_check; 232 + 233 + if (s->tlsext_debug_cb) 234 + @@ -3307,29 +3307,33 @@ int tls1_process_ticket(SSL *s, unsigned char *session_id, int len, 235 + /* Skip past DTLS cookie */ 236 + if (SSL_IS_DTLS(s)) { 237 + i = *(p++); 238 + - p += i; 239 + - if (p >= limit) 240 + + 241 + + if (limit - p <= i) 242 + return -1; 243 + + 244 + + p += i; 245 + } 246 + /* Skip past cipher list */ 247 + n2s(p, i); 248 + - p += i; 249 + - if (p >= limit) 250 + + if (limit - p <= i) 251 + return -1; 252 + + p += i; 253 + + 254 + /* Skip past compression algorithm list */ 255 + i = *(p++); 256 + - p += i; 257 + - if (p > limit) 258 + + if (limit - p < i) 259 + return -1; 260 + + p += i; 261 + + 262 + /* Now at start of extensions */ 263 + - if ((p + 2) >= limit) 264 + + if (limit - p <= 2) 265 + return 0; 266 + n2s(p, i); 267 + - while ((p + 4) <= limit) { 268 + + while (limit - p >= 4) { 269 + unsigned short type, size; 270 + n2s(p, type); 271 + n2s(p, size); 272 + - if (p + size > limit) 273 + + if (limit - p < size) 274 + return 0; 275 + if (type == TLSEXT_TYPE_session_ticket) { 276 + int r; 277 + -- 278 + 1.9.1 279 +
+11 -2
pkgs/development/libraries/openssl/default.nix
··· 8 8 opensslCrossSystem = stdenv.cross.openssl.system or 9 9 (throw "openssl needs its platform name cross building"); 10 10 11 - common = { version, sha256 }: stdenv.mkDerivation rec { 11 + common = args@{ version, sha256, patches ? [] }: stdenv.mkDerivation rec { 12 12 name = "openssl-${version}"; 13 13 14 14 src = fetchurl { ··· 17 17 }; 18 18 19 19 patches = 20 - [ ./use-etc-ssl-certs.patch ] 20 + args.patches 21 + ++ [ ./use-etc-ssl-certs.patch ] 21 22 ++ optional stdenv.isCygwin ./1.0.1-cygwin64.patch 22 23 ++ optional 23 24 (versionOlder version "1.0.2" && (stdenv.isDarwin || (stdenv ? cross && stdenv.cross.libc == "libSystem"))) ··· 107 108 openssl_1_0_1 = common { 108 109 version = "1.0.1t"; 109 110 sha256 = "4a6ee491a2fdb22e519c76fdc2a628bb3cec12762cd456861d207996c8a07088"; 111 + patches = [ 112 + # https://git.openssl.org/?p=openssl.git;a=commit;h=6f35f6deb5ca7daebe289f86477e061ce3ee5f46 113 + ./1.0.1-CVE-2016-2177.diff 114 + ]; 110 115 }; 111 116 112 117 openssl_1_0_2 = common { 113 118 version = "1.0.2h"; 114 119 sha256 = "1d4007e53aad94a5b2002fe045ee7bb0b3d98f1a47f8b2bc851dcd1c74332919"; 120 + patches = [ 121 + # https://git.openssl.org/?p=openssl.git;a=commit;h=a004e72b95835136d3f1ea90517f706c24c03da7 122 + ./1.0.2-CVE-2016-2177.diff 123 + ]; 115 124 }; 116 125 117 126 }