From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Famulari Subject: Re: OpenSSL CVE-2016-2177, CVE-2016-2178 Date: Mon, 13 Jun 2016 16:27:59 -0400 Message-ID: <20160613202759.GA11755@jasmine> References: <20160612012201.GA23504@jasmine> <87pormi14c.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Bu8it7iiRSEf40bY" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCYT2-00034U-J1 for guix-devel@gnu.org; Mon, 13 Jun 2016 16:28:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCYSx-0007Tm-EX for guix-devel@gnu.org; Mon, 13 Jun 2016 16:28:15 -0400 Content-Disposition: inline In-Reply-To: <87pormi14c.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?iso-8859-1?Q?Court=E8s?= Cc: guix-devel@gnu.org --Bu8it7iiRSEf40bY Content-Type: multipart/mixed; boundary="JP+T4n/bALQSJXh8" Content-Disposition: inline --JP+T4n/bALQSJXh8 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 12, 2016 at 10:49:23PM +0200, Ludovic Court=E8s wrote: > Leo Famulari skribis: > > CVE-2016-2177 > > http://seclists.org/oss-sec/2016/q2/500 > > > > CVE-2016-2178 > > http://seclists.org/oss-sec/2016/q2/493 > > > > Should we try cherry-picking the upstream commits from the OpenSSL > > development repo? >=20 > Sounds like it. Could you look into it? I've attached my patch. According to OpenSSL's security policy [0], they seem to consider these bugs to be "LOW severity", since they did not keep them private or issue a new release, or even an advisory [1]. There is also some discussion of the severity in this thread: http://seclists.org/oss-sec/2016/q2/493 So, perhaps it's not worth the risk of cherry-picking these commits out of context, at least not without asking the upstream maintainers. Thoughts? [0] https://www.openssl.org/policies/secpolicy.html [1] https://www.openssl.org/news/vulnerabilities.html#y2016 --JP+T4n/bALQSJXh8 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-gnu-openssl-Fix-CVE-2016-2177-and-CVE-2016-2178.patch" Content-Transfer-Encoding: quoted-printable =46rom 93e120f46b60bb3b87e33711ef4a9342b66bca21 Mon Sep 17 00:00:00 2001 =46rom: Leo Famulari Date: Mon, 13 Jun 2016 16:15:34 -0400 Subject: [PATCH] gnu: openssl: Fix CVE-2016-2177 and CVE-2016-2178. * gnu/packages/patches/openssl-CVE-2016-2177.patch, gnu/packages/patches/openssl-CVE-2016-2178.patch: New files. * gnu/local.mk (dist_patch_DATA): Add them. * gnu/packages/tls.scm (openssl/fixed): Use them. --- gnu/local.mk | 2 + gnu/packages/patches/openssl-CVE-2016-2177.patch | 286 +++++++++++++++++++= ++++ gnu/packages/patches/openssl-CVE-2016-2178.patch | 112 +++++++++ gnu/packages/tls.scm | 4 +- 4 files changed, 403 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/openssl-CVE-2016-2177.patch create mode 100644 gnu/packages/patches/openssl-CVE-2016-2178.patch diff --git a/gnu/local.mk b/gnu/local.mk index 73aef0a..9d642ba 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -686,6 +686,8 @@ dist_patch_DATA =3D \ %D%/packages/patches/openssh-CVE-2015-8325.patch \ %D%/packages/patches/openssl-runpath.patch \ %D%/packages/patches/openssl-c-rehash-in.patch \ + %D%/packages/patches/openssl-CVE-2016-2177.patch \ + %D%/packages/patches/openssl-CVE-2016-2178.patch \ %D%/packages/patches/orpheus-cast-errors-and-includes.patch \ %D%/packages/patches/ots-no-include-missing-file.patch \ %D%/packages/patches/patchelf-page-size.patch \ diff --git a/gnu/packages/patches/openssl-CVE-2016-2177.patch b/gnu/package= s/patches/openssl-CVE-2016-2177.patch new file mode 100644 index 0000000..f6465ae --- /dev/null +++ b/gnu/packages/patches/openssl-CVE-2016-2177.patch @@ -0,0 +1,286 @@ +Fix CVE-2016-2177. + + + +Source: + + +From a004e72b95835136d3f1ea90517f706c24c03da7 Mon Sep 17 00:00:00 2001 +From: Matt Caswell +Date: Thu, 5 May 2016 11:10:26 +0100 +Subject: [PATCH] Avoid some undefined pointer arithmetic + +A common idiom in the codebase is: + +if (p + len > limit) +{ + return; /* Too long */ +} + +Where "p" points to some malloc'd data of SIZE bytes and +limit =3D=3D p + SIZE + +"len" here could be from some externally supplied data (e.g. from a TLS +message). + +The rules of C pointer arithmetic are such that "p + len" is only well +defined where len <=3D SIZE. Therefore the above idiom is actually +undefined behaviour. + +For example this could cause problems if some malloc implementation +provides an address for "p" such that "p + len" actually overflows for +values of len that are too big and therefore p + len < limit! + +Issue reported by Guido Vranken. + +CVE-2016-2177 + +Reviewed-by: Rich Salz +--- + ssl/s3_srvr.c | 14 +++++++------- + ssl/ssl_sess.c | 2 +- + ssl/t1_lib.c | 56 ++++++++++++++++++++++++++++++-----------------------= --- + 3 files changed, 38 insertions(+), 34 deletions(-) + +diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c +index ab28702..ab7f690 100644 +--- a/ssl/s3_srvr.c ++++ b/ssl/s3_srvr.c +@@ -980,7 +980,7 @@ int ssl3_get_client_hello(SSL *s) +=20 + session_length =3D *(p + SSL3_RANDOM_SIZE); +=20 +- if (p + SSL3_RANDOM_SIZE + session_length + 1 >=3D d + n) { ++ if (SSL3_RANDOM_SIZE + session_length + 1 >=3D (d + n) - p) { + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); + goto f_err; +@@ -998,7 +998,7 @@ int ssl3_get_client_hello(SSL *s) + /* get the session-id */ + j =3D *(p++); +=20 +- if (p + j > d + n) { ++ if ((d + n) - p < j) { + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); + goto f_err; +@@ -1054,14 +1054,14 @@ int ssl3_get_client_hello(SSL *s) +=20 + if (SSL_IS_DTLS(s)) { + /* cookie stuff */ +- if (p + 1 > d + n) { ++ if ((d + n) - p < 1) { + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); + goto f_err; + } + cookie_len =3D *(p++); +=20 +- if (p + cookie_len > d + n) { ++ if ((d + n ) - p < cookie_len) { + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); + goto f_err; +@@ -1131,7 +1131,7 @@ int ssl3_get_client_hello(SSL *s) + } + } +=20 +- if (p + 2 > d + n) { ++ if ((d + n ) - p < 2) { + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT); + goto f_err; +@@ -1145,7 +1145,7 @@ int ssl3_get_client_hello(SSL *s) + } +=20 + /* i bytes of cipher data + 1 byte for compression length later */ +- if ((p + i + 1) > (d + n)) { ++ if ((d + n) - p < i + 1) { + /* not enough data */ + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); +@@ -1211,7 +1211,7 @@ int ssl3_get_client_hello(SSL *s) +=20 + /* compression */ + i =3D *(p++); +- if ((p + i) > (d + n)) { ++ if ((d + n) - p < i) { + /* not enough data */ + al =3D SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH); +diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c +index b182998..54ee783 100644 +--- a/ssl/ssl_sess.c ++++ b/ssl/ssl_sess.c +@@ -573,7 +573,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *sessio= n_id, int len, + int r; + #endif +=20 +- if (session_id + len > limit) { ++ if (limit - session_id < len) { + fatal =3D 1; + goto err; + } +diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c +index fb64607..cdac011 100644 +--- a/ssl/t1_lib.c ++++ b/ssl/t1_lib.c +@@ -1867,11 +1867,11 @@ static void ssl_check_for_safari(SSL *s, const uns= igned char *data, + 0x02, 0x03, /* SHA-1/ECDSA */ + }; +=20 +- if (data >=3D (limit - 2)) ++ if (limit - data <=3D 2) + return; + data +=3D 2; +=20 +- if (data > (limit - 4)) ++ if (limit - data < 4) + return; + n2s(data, type); + n2s(data, size); +@@ -1879,7 +1879,7 @@ static void ssl_check_for_safari(SSL *s, const unsig= ned char *data, + if (type !=3D TLSEXT_TYPE_server_name) + return; +=20 +- if (data + size > limit) ++ if (limit - data < size) + return; + data +=3D size; +=20 +@@ -1887,7 +1887,7 @@ static void ssl_check_for_safari(SSL *s, const unsig= ned char *data, + const size_t len1 =3D sizeof(kSafariExtensionsBlock); + const size_t len2 =3D sizeof(kSafariTLS12ExtensionsBlock); +=20 +- if (data + len1 + len2 !=3D limit) ++ if (limit - data !=3D (int)(len1 + len2)) + return; + if (memcmp(data, kSafariExtensionsBlock, len1) !=3D 0) + return; +@@ -1896,7 +1896,7 @@ static void ssl_check_for_safari(SSL *s, const unsig= ned char *data, + } else { + const size_t len =3D sizeof(kSafariExtensionsBlock); +=20 +- if (data + len !=3D limit) ++ if (limit - data !=3D (int)(len)) + return; + if (memcmp(data, kSafariExtensionsBlock, len) !=3D 0) + return; +@@ -2053,19 +2053,19 @@ static int ssl_scan_clienthello_tlsext(SSL *s, uns= igned char **p, + if (data =3D=3D limit) + goto ri_check; +=20 +- if (data > (limit - 2)) ++ if (limit - data < 2) + goto err; +=20 + n2s(data, len); +=20 +- if (data + len !=3D limit) ++ if (limit - data !=3D len) + goto err; +=20 +- while (data <=3D (limit - 4)) { ++ while (limit - data >=3D 4) { + n2s(data, type); + n2s(data, size); +=20 +- if (data + size > (limit)) ++ if (limit - data < size) + goto err; + # if 0 + fprintf(stderr, "Received extension type %d size %d\n", type, siz= e); +@@ -2472,18 +2472,18 @@ static int ssl_scan_clienthello_custom_tlsext(SSL = *s, + if (s->hit || s->cert->srv_ext.meths_count =3D=3D 0) + return 1; +=20 +- if (data >=3D limit - 2) ++ if (limit - data <=3D 2) + return 1; + n2s(data, len); +=20 +- if (data > limit - len) ++ if (limit - data < len) + return 1; +=20 +- while (data <=3D limit - 4) { ++ while (limit - data >=3D 4) { + n2s(data, type); + n2s(data, size); +=20 +- if (data + size > limit) ++ if (limit - data < size) + return 1; + if (custom_ext_parse(s, 1 /* server */ , type, data, size, al) <= =3D 0) + return 0; +@@ -2569,20 +2569,20 @@ static int ssl_scan_serverhello_tlsext(SSL *s, uns= igned char **p, + SSL_TLSEXT_HB_DONT_SEND_REQUESTS); + # endif +=20 +- if (data >=3D (d + n - 2)) ++ if ((d + n) - data <=3D 2) + goto ri_check; +=20 + n2s(data, length); +- if (data + length !=3D d + n) { ++ if ((d + n) - data !=3D length) { + *al =3D SSL_AD_DECODE_ERROR; + return 0; + } +=20 +- while (data <=3D (d + n - 4)) { ++ while ((d + n) - data >=3D 4) { + n2s(data, type); + n2s(data, size); +=20 +- if (data + size > (d + n)) ++ if ((d + n) - data < size) + goto ri_check; +=20 + if (s->tlsext_debug_cb) +@@ -3307,29 +3307,33 @@ int tls1_process_ticket(SSL *s, unsigned char *ses= sion_id, int len, + /* Skip past DTLS cookie */ + if (SSL_IS_DTLS(s)) { + i =3D *(p++); +- p +=3D i; +- if (p >=3D limit) ++ ++ if (limit - p <=3D i) + return -1; ++ ++ p +=3D i; + } + /* Skip past cipher list */ + n2s(p, i); +- p +=3D i; +- if (p >=3D limit) ++ if (limit - p <=3D i) + return -1; ++ p +=3D i; ++ + /* Skip past compression algorithm list */ + i =3D *(p++); +- p +=3D i; +- if (p > limit) ++ if (limit - p < i) + return -1; ++ p +=3D i; ++ + /* Now at start of extensions */ +- if ((p + 2) >=3D limit) ++ if (limit - p <=3D 2) + return 0; + n2s(p, i); +- while ((p + 4) <=3D limit) { ++ while (limit - p >=3D 4) { + unsigned short type, size; + n2s(p, type); + n2s(p, size); +- if (p + size > limit) ++ if (limit - p < size) + return 0; + if (type =3D=3D TLSEXT_TYPE_session_ticket) { + int r; +--=20 +2.8.4 + diff --git a/gnu/packages/patches/openssl-CVE-2016-2178.patch b/gnu/package= s/patches/openssl-CVE-2016-2178.patch new file mode 100644 index 0000000..37cf276 --- /dev/null +++ b/gnu/packages/patches/openssl-CVE-2016-2178.patch @@ -0,0 +1,112 @@ +Fix CVE-2016-2178. + + + +Source: + + + +From 621eaf49a289bfac26d4cbcdb7396e796784c534 Mon Sep 17 00:00:00 2001 +From: Cesar Pereida +Date: Mon, 23 May 2016 12:45:25 +0300 +Subject: [PATCH 1/2] Fix DSA, preserve BN_FLG_CONSTTIME + +Operations in the DSA signing algorithm should run in constant time in +order to avoid side channel attacks. A flaw in the OpenSSL DSA +implementation means that a non-constant time codepath is followed for +certain operations. This has been demonstrated through a cache-timing +attack to be sufficient for an attacker to recover the private DSA key. + +CVE-2016-2178 + +Reviewed-by: Richard Levitte +Reviewed-by: Matt Caswell +--- + crypto/dsa/dsa_ossl.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c +index efc4f1b..b29eb4b 100644 +--- a/crypto/dsa/dsa_ossl.c ++++ b/crypto/dsa/dsa_ossl.c +@@ -248,9 +248,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BI= GNUM **kinvp, + if (!BN_rand_range(&k, dsa->q)) + goto err; + while (BN_is_zero(&k)) ; +- if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) =3D=3D 0) { +- BN_set_flags(&k, BN_FLG_CONSTTIME); +- } +=20 + if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { + if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, +@@ -279,9 +276,12 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, B= IGNUM **kinvp, + } +=20 + K =3D &kq; ++ ++ BN_set_flags(K, BN_FLG_CONSTTIME); + } else { + K =3D &k; + } ++ + DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx, + dsa->method_mont_p); + if (!BN_mod(r, r, dsa->q, ctx)) +--=20 +2.8.4 + +From b7d0f2834e139a20560d64c73e2565e93715ce2b Mon Sep 17 00:00:00 2001 +From: Matt Caswell +Date: Tue, 7 Jun 2016 09:12:51 +0100 +Subject: [PATCH 2/2] More fix DSA, preserve BN_FLG_CONSTTIME + +The previous "fix" still left "k" exposed to constant time problems in +the later BN_mod_inverse() call. Ensure both k and kq have the +BN_FLG_CONSTTIME flag set at the earliest opportunity after creation. + +CVE-2016-2178 + +Reviewed-by: Rich Salz +--- + crypto/dsa/dsa_ossl.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c +index b29eb4b..58013a4 100644 +--- a/crypto/dsa/dsa_ossl.c ++++ b/crypto/dsa/dsa_ossl.c +@@ -247,7 +247,12 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, B= IGNUM **kinvp, + do + if (!BN_rand_range(&k, dsa->q)) + goto err; +- while (BN_is_zero(&k)) ; ++ while (BN_is_zero(&k)); ++ ++ if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) =3D=3D 0) { ++ BN_set_flags(&k, BN_FLG_CONSTTIME); ++ } ++ +=20 + if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { + if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, +@@ -261,6 +266,8 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BI= GNUM **kinvp, + if (!BN_copy(&kq, &k)) + goto err; +=20 ++ BN_set_flags(&kq, BN_FLG_CONSTTIME); ++ + /* + * We do not want timing information to leak the length of k, so = we + * compute g^k using an equivalent exponent of fixed length. (This +@@ -276,8 +283,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BI= GNUM **kinvp, + } +=20 + K =3D &kq; +- +- BN_set_flags(K, BN_FLG_CONSTTIME); + } else { + K =3D &k; + } +--=20 +2.8.4 + diff --git a/gnu/packages/tls.scm b/gnu/packages/tls.scm index e543a7e..513edcc 100644 --- a/gnu/packages/tls.scm +++ b/gnu/packages/tls.scm @@ -316,7 +316,9 @@ required structures.") (base32 "06996ds1rk8xhnyb5y273a7xkcxhggp4bq1g02rab55d7bjhfh0x")) (patches (search-patches "openssl-runpath.patch" - "openssl-c-rehash-in.patch"))))))) + "openssl-c-rehash-in.patch" + "openssl-CVE-2016-2177.patch" + "openssl-CVE-2016-2178.patch"))))))) =20 (define-public libressl (package --=20 2.8.4 --JP+T4n/bALQSJXh8-- --Bu8it7iiRSEf40bY Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXXxdPAAoJECZG+jC6yn8I09QP/38k3BdOQYTDL/lNpx/2anzc R9O5Wj5A//A8me88crQhRXIhkd3zKPI+PkMFlRLtufC3LRk7WqP+LhJtBsi+z0Qe fuq0IbZFc98y2WfqB9he8pP8QVAYZ7CMI436pjnL1RsEB+TkLkzPGywB2gIj/UcV D27/eY5sz3neS0LHbpYBXKjqK9G9ANtcNNw+YcQCZIVy3kppxa79CEBz+MyntUMz 5U8UFT6GuQc2C3rmvSxkWHSkeNyPy7ciPpAUc2WPyYSV99gmflwBIhM9iEtscs0v D9k5fEIpPydtF7nQroRtcKhiU588p6aIP+XjeRptfGlLiFxoochv2+OrqVy9FAX2 GE01Xv6k+o2N3lbzJ8JMzLkf1FUe56iX5AH3KhhahHVDvx6d+9NkLOfZxbNtFgOA hj5qipteUK8Wm4487m6e4wLt2E81NutUqnXEomAZv00DVSEEDFNTycCKvzBNlj8/ zJay/iyQYFZsMDdtnTes9eQXGZ9pQTMtzLtWfF879IbrcUnYXwx7SyczHLNF3IPn HDxsiN/cO9mIY1ZrLj3AOSh7XN4rc0Xs5KEEjLLZyvzOz0V6rn8bDbv5YuDg84ZP yuGJoy18eEX4cOAaBOQ7Cl1o7yTks2hfU/PeU+i7i26GB0DpjxcWhDnlR9F2lmZU +EoiraI9M9pUAo/Boo5q =AKQW -----END PGP SIGNATURE----- --Bu8it7iiRSEf40bY--