From patchwork Wed Jul 19 13:27:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 108292 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp858109obm; Wed, 19 Jul 2017 06:27:45 -0700 (PDT) X-Received: by 10.99.147.19 with SMTP id b19mr79367pge.67.1500470865309; Wed, 19 Jul 2017 06:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500470865; cv=none; d=google.com; s=arc-20160816; b=IrHYKsYFHYIaoK4fA8C5d7tHk9g+DKa1w1+BIKZZqf9goovwjJZzAt+cCg9gmtIUgs kUQnOYAmQFNDTVnt1yRcwSVNZ7kvFp23uhpdZmTy08a+9qyLwUR9DWWBZAlBd11YMrmW 6a8CGnQfy9PwoRn3vJxp4oSEVnF69ZMpr0JDbTqPAjAb9ipTHI24TdK2D6uQVt/Gxqoi WZv5Z/9g+t6D6viCs4P1S+/O4FI5qzyV9mI5sPAH+iEKO6ZAA+o1JHUOto0D2H0+s0gk zrgMiiXvSTfIJ/ROuoLqgiQgH8zbg9xb+R35/ej75YD0/+t4YDnx9VPZjBPojtuneJmE DIcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=exHK8H0qWovIBQlAAiivWv9DfOW9eQREmvNXbS//c3g=; b=gHQdr798xmXcEHb28DSaa06vvHXTPZEj88i4hOTpciiDlDK3xuIUbYKwrhsJUePwlO mR0KDQ0ETTEJfQfY4lPMACwQ8ufVvBsJZGiZnjYCfMdPR4aLla+5u5V0AbvauV9Gyila z154ixbqdkr04pQFghm5bfN804zgFXR2eNpHyD+mQlqTKB6SwkMAUgngk7yKr4XqY/U5 yMa9qn3U4RLwUnVt8mF3iC/JP/jeYvlDFdTNwrqLO8mne0bbfZz1jLKAkBLqje+xkbny W/qirAFZndeDhU0M+UUMOt4ZOWJtBLqTWKNJUSNH5/olOjoD+w1o5g+JEuYC4xBC+rHZ nlPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.b=ZU6RoiKH; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id w8si25564pge.413.2017.07.19.06.27.45; Wed, 19 Jul 2017 06:27:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.b=ZU6RoiKH; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Received: from review.yoctoproject.org (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 78532782CA; Wed, 19 Jul 2017 13:27:41 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by mail.openembedded.org (Postfix) with ESMTP id E2864782B3 for ; Wed, 19 Jul 2017 13:27:35 +0000 (UTC) Received: by mail-wm0-f51.google.com with SMTP id g127so1117079wmd.0 for ; Wed, 19 Jul 2017 06:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=y4HOlIZ6Ufqm/gLFoKZAHHouQErom1+gc8vh/rxNFBg=; b=ZU6RoiKH6+Xnb6BhnSLvQpt49dpXBbaSsff+iEbgG3pJ3VFUD2y0/ecgtpVzHwdzfT yxfRPwluxJBI4oqq7PnxVF7xrsfDZsxavH8AS0iOmYy2DQi3U80PUCKvsDtPISUtEA2B gYr8xIz/4+pe+2DDgwTywIB6nRux2ajAE1kmmIa2GFUV+U96SODdclGh0fAlfyxHnHef owfXCz0RaPzbGF1jAoOJHXS+2uV9NG7MWtZq3HYYqlSFh5i4XfFCR6bwJWaWJFvp+wG0 heucTUeBbFobd4GsBc+FB7Yx+V6j/jhB2EQIQ57Edom8NKiHLwb9pK5NlnjNWam9hQGx CIzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=y4HOlIZ6Ufqm/gLFoKZAHHouQErom1+gc8vh/rxNFBg=; b=emn9GIN3wLE14rS3MIaCwrI5NMsa8pQm06hhl2zRZEDcHhoMDn6FLZiJmXl3W6MbIX tztI0P1mmWqP+GrQaRzDm7c1rUWsD2U0/Lp4tSeWmx9xo86hND6yliE1eBzcw/a6jXbB ydOjafTX4w/wRKOxZfKZ3jP0SriVvI+8W8D5fMYT6l0rHHPtCdcdW1pTxKNz4ss6lM9D vNZIab/+HS/PF1b/DVHE/Vvhs6lYKSir1M8eXpn6Mbn5A+bFsoSHysTrLtj8EgIm16S5 mzjrHD3ZGs9F+9i7Hh2fG9jp3nykAStW85sEMNLsiADQqSQTeE+kBlxGgOHaVA0BQVK7 SRwg== X-Gm-Message-State: AIVw112D9KSabXPBeWNUYHMwCw9FZCegCzQibSJvpJ/otp6EESr7F7Qi Db8fwaO0FRSA6qd0X6g= X-Received: by 10.28.113.21 with SMTP id m21mr4415wmc.80.1500470855782; Wed, 19 Jul 2017 06:27:35 -0700 (PDT) Received: from flashheart.burtonini.com (home.burtonini.com. [81.2.106.35]) by smtp.gmail.com with ESMTPSA id l31sm5911891wrc.12.2017.07.19.06.27.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jul 2017 06:27:34 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Date: Wed, 19 Jul 2017 14:27:31 +0100 Message-Id: <20170719132732.6933-1-ross.burton@intel.com> X-Mailer: git-send-email 2.11.0 Subject: [OE-core] [PATCH][krogoth 1/2] libgcrypt: fix CVE-2017-7526 X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org Fixes CVE-2017-7526, 'flush+reload side-channel attack on RSA secret keys dubbed "Sliding right into disaster"'. Signed-off-by: Ross Burton --- .../libgcrypt/files/CVE-2017-7526.patch | 455 +++++++++++++++++++++ meta/recipes-support/libgcrypt/libgcrypt.inc | 1 + 2 files changed, 456 insertions(+) create mode 100644 meta/recipes-support/libgcrypt/files/CVE-2017-7526.patch -- 2.11.0 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core diff --git a/meta/recipes-support/libgcrypt/files/CVE-2017-7526.patch b/meta/recipes-support/libgcrypt/files/CVE-2017-7526.patch new file mode 100644 index 00000000000..c9541d44f3f --- /dev/null +++ b/meta/recipes-support/libgcrypt/files/CVE-2017-7526.patch @@ -0,0 +1,455 @@ +Flush+reload side-channel attack on RSA secret keys dubbed "Sliding right +into disaster". + +CVE: CVE-2017-7526 +Upstream-Status: Backport +Signed-off-by: Ross Burton + +From 8ae178108eb3c64b40dcb4d1c1943205a86db724 Mon Sep 17 00:00:00 2001 +From: NIIBE Yutaka +Date: Tue, 4 Apr 2017 17:38:05 +0900 +Subject: [PATCH 1/5] mpi: Simplify mpi_powm. + +* mpi/mpi-pow.c (_gcry_mpi_powm): Simplify the loop. + +-- + +This fix is not a solution for the problem reported (yet). The +problem is that the current algorithm of _gcry_mpi_powm depends on +exponent and some information leaks is possible. + +Reported-by: Andreas Zankl +Signed-off-by: NIIBE Yutaka + +(backport from master commit: +719468e53133d3bdf12156c5bfdea2bf15f9f6f1) + +Signed-off-by: Ross Burton +--- + mpi/mpi-pow.c | 105 +++++++++++++++++----------------------------------------- + 1 file changed, 30 insertions(+), 75 deletions(-) + +diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c +index 70bf9e84..c00cfed3 100644 +--- a/mpi/mpi-pow.c ++++ b/mpi/mpi-pow.c +@@ -613,12 +613,8 @@ _gcry_mpi_powm (gcry_mpi_t res, + if (e == 0) + { + j += c; +- i--; +- if ( i < 0 ) +- { +- c = 0; +- break; +- } ++ if ( --i < 0 ) ++ break; + + e = ep[i]; + c = BITS_PER_MPI_LIMB; +@@ -633,38 +629,33 @@ _gcry_mpi_powm (gcry_mpi_t res, + c -= c0; + j += c0; + ++ e0 = (e >> (BITS_PER_MPI_LIMB - W)); + if (c >= W) +- { +- e0 = (e >> (BITS_PER_MPI_LIMB - W)); +- e = (e << W); +- c -= W; +- } ++ c0 = 0; + else + { +- i--; +- if ( i < 0 ) ++ if ( --i < 0 ) + { +- e = (e >> (BITS_PER_MPI_LIMB - c)); +- break; ++ e0 = (e >> (BITS_PER_MPI_LIMB - c)); ++ j += c - W; ++ goto last_step; ++ } ++ else ++ { ++ c0 = c; ++ e = ep[i]; ++ c = BITS_PER_MPI_LIMB; ++ e0 |= (e >> (BITS_PER_MPI_LIMB - (W - c0))); + } +- +- c0 = c; +- e0 = (e >> (BITS_PER_MPI_LIMB - W)) +- | (ep[i] >> (BITS_PER_MPI_LIMB - W + c0)); +- e = (ep[i] << (W - c0)); +- c = BITS_PER_MPI_LIMB - W + c0; + } + ++ e = e << (W - c0); ++ c -= (W - c0); ++ ++ last_step: + count_trailing_zeros (c0, e0); + e0 = (e0 >> c0) >> 1; + +- for (j += W - c0; j; j--) +- { +- mul_mod (xp, &xsize, rp, rsize, rp, rsize, mp, msize, &karactx); +- tp = rp; rp = xp; xp = tp; +- rsize = xsize; +- } +- + /* + * base_u <= precomp[e0] + * base_u_size <= precomp_size[e0] +@@ -681,25 +672,23 @@ _gcry_mpi_powm (gcry_mpi_t res, + u.d = precomp[k]; + + mpi_set_cond (&w, &u, k == e0); +- base_u_size |= (precomp_size[k] & ((mpi_size_t)0 - (k == e0)) ); ++ base_u_size |= ( precomp_size[k] & ((mpi_size_t)0 - (k == e0)) ); + } + +- mul_mod (xp, &xsize, rp, rsize, base_u, base_u_size, +- mp, msize, &karactx); +- tp = rp; rp = xp; xp = tp; +- rsize = xsize; ++ for (j += W - c0; j >= 0; j--) ++ { ++ mul_mod (xp, &xsize, rp, rsize, ++ j == 0 ? base_u : rp, j == 0 ? base_u_size : rsize, ++ mp, msize, &karactx); ++ tp = rp; rp = xp; xp = tp; ++ rsize = xsize; ++ } + + j = c0; ++ if ( i < 0 ) ++ break; + } + +- if (c != 0) +- { +- j += c; +- count_trailing_zeros (c, e); +- e = (e >> c); +- j -= c; +- } +- + while (j--) + { + mul_mod (xp, &xsize, rp, rsize, rp, rsize, mp, msize, &karactx); +@@ -707,40 +696,6 @@ _gcry_mpi_powm (gcry_mpi_t res, + rsize = xsize; + } + +- if (e != 0) +- { +- /* +- * base_u <= precomp[(e>>1)] +- * base_u_size <= precomp_size[(e>>1)] +- */ +- base_u_size = 0; +- for (k = 0; k < (1<< (W - 1)); k++) +- { +- struct gcry_mpi w, u; +- w.alloced = w.nlimbs = precomp_size[k]; +- u.alloced = u.nlimbs = precomp_size[k]; +- w.sign = u.sign = 0; +- w.flags = u.flags = 0; +- w.d = base_u; +- u.d = precomp[k]; +- +- mpi_set_cond (&w, &u, k == (e>>1)); +- base_u_size |= (precomp_size[k] & ((mpi_size_t)0 - (k == (e>>1))) ); +- } +- +- mul_mod (xp, &xsize, rp, rsize, base_u, base_u_size, +- mp, msize, &karactx); +- tp = rp; rp = xp; xp = tp; +- rsize = xsize; +- +- for (; c; c--) +- { +- mul_mod (xp, &xsize, rp, rsize, rp, rsize, mp, msize, &karactx); +- tp = rp; rp = xp; xp = tp; +- rsize = xsize; +- } +- } +- + /* We shifted MOD, the modulo reduction argument, left + MOD_SHIFT_CNT steps. Adjust the result by reducing it with the + original MOD. +-- +2.11.0 + + +From ab6d34849f33d16e1da2b09e3d938bcb0f48f682 Mon Sep 17 00:00:00 2001 +From: NIIBE Yutaka +Date: Sat, 24 Jun 2017 20:46:20 +0900 +Subject: [PATCH 2/5] Same computation for square and multiply. + +* mpi/mpi-pow.c (_gcry_mpi_powm): Compare msize for max_u_size. Move +the assignment to base_u into the loop. Copy content refered by RP to +BASE_U except the last of the loop. + +-- + +Signed-off-by: NIIBE Yutaka +(backport from master commit: +78130828e9a140a9de4dafadbc844dbb64cb709a) + +Signed-off-by: Ross Burton +--- + mpi/mpi-pow.c | 50 +++++++++++++++++++++++++++++--------------------- + 1 file changed, 29 insertions(+), 21 deletions(-) + +diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c +index c00cfed3..0d74f28c 100644 +--- a/mpi/mpi-pow.c ++++ b/mpi/mpi-pow.c +@@ -577,6 +577,8 @@ _gcry_mpi_powm (gcry_mpi_t res, + MPN_COPY (precomp[i], rp, rsize); + } + ++ if (msize > max_u_size) ++ max_u_size = msize; + base_u = mpi_alloc_limb_space (max_u_size, esec); + MPN_ZERO (base_u, max_u_size); + +@@ -623,6 +625,10 @@ _gcry_mpi_powm (gcry_mpi_t res, + { + int c0; + mpi_limb_t e0; ++ struct gcry_mpi w, u; ++ w.sign = u.sign = 0; ++ w.flags = u.flags = 0; ++ w.d = base_u; + + count_leading_zeros (c0, e); + e = (e << c0); +@@ -656,29 +662,31 @@ _gcry_mpi_powm (gcry_mpi_t res, + count_trailing_zeros (c0, e0); + e0 = (e0 >> c0) >> 1; + +- /* +- * base_u <= precomp[e0] +- * base_u_size <= precomp_size[e0] +- */ +- base_u_size = 0; +- for (k = 0; k < (1<< (W - 1)); k++) +- { +- struct gcry_mpi w, u; +- w.alloced = w.nlimbs = precomp_size[k]; +- u.alloced = u.nlimbs = precomp_size[k]; +- w.sign = u.sign = 0; +- w.flags = u.flags = 0; +- w.d = base_u; +- u.d = precomp[k]; +- +- mpi_set_cond (&w, &u, k == e0); +- base_u_size |= ( precomp_size[k] & ((mpi_size_t)0 - (k == e0)) ); +- } +- + for (j += W - c0; j >= 0; j--) + { +- mul_mod (xp, &xsize, rp, rsize, +- j == 0 ? base_u : rp, j == 0 ? base_u_size : rsize, ++ ++ /* ++ * base_u <= precomp[e0] ++ * base_u_size <= precomp_size[e0] ++ */ ++ base_u_size = 0; ++ for (k = 0; k < (1<< (W - 1)); k++) ++ { ++ w.alloced = w.nlimbs = precomp_size[k]; ++ u.alloced = u.nlimbs = precomp_size[k]; ++ u.d = precomp[k]; ++ ++ mpi_set_cond (&w, &u, k == e0); ++ base_u_size |= ( precomp_size[k] & (0UL - (k == e0)) ); ++ } ++ ++ w.alloced = w.nlimbs = rsize; ++ u.alloced = u.nlimbs = rsize; ++ u.d = rp; ++ mpi_set_cond (&w, &u, j != 0); ++ base_u_size ^= ((base_u_size ^ rsize) & (0UL - (j != 0))); ++ ++ mul_mod (xp, &xsize, rp, rsize, base_u, base_u_size, + mp, msize, &karactx); + tp = rp; rp = xp; xp = tp; + rsize = xsize; +-- +2.11.0 + + +From b5370d527612d2c453a366729f07892974b28ba8 Mon Sep 17 00:00:00 2001 +From: NIIBE Yutaka +Date: Thu, 29 Jun 2017 11:48:44 +0900 +Subject: [PATCH 3/5] rsa: Add exponent blinding. + +* cipher/rsa.c (secret): Blind secret D with randomized nonce R for +mpi_powm computation. + +-- + +Co-authored-by: Werner Koch +Signed-off-by: NIIBE Yutaka + +The paper describing attack: https://eprint.iacr.org/2017/627 + +Sliding right into disaster: Left-to-right sliding windows leak +by Daniel J. Bernstein and Joachim Breitner and Daniel Genkin and +Leon Groot Bruinderink and Nadia Heninger and Tanja Lange and +Christine van Vredendaal and Yuval Yarom + + It is well known that constant-time implementations of modular + exponentiation cannot use sliding windows. However, software + libraries such as Libgcrypt, used by GnuPG, continue to use sliding + windows. It is widely believed that, even if the complete pattern of + squarings and multiplications is observed through a side-channel + attack, the number of exponent bits leaked is not sufficient to + carry out a full key-recovery attack against RSA. Specifically, + 4-bit sliding windows leak only 40% of the bits, and 5-bit sliding + windows leak only 33% of the bits. + + In this paper we demonstrate a complete break of RSA-1024 as + implemented in Libgcrypt. Our attack makes essential use of the fact + that Libgcrypt uses the left-to-right method for computing the + sliding-window expansion. We show for the first time that the + direction of the encoding matters: the pattern of squarings and + multiplications in left-to-right sliding windows leaks significantly + more information about exponent bits than for right-to-left. We show + how to incorporate this additional information into the + Heninger-Shacham algorithm for partial key reconstruction, and use + it to obtain very efficient full key recovery for RSA-1024. We also + provide strong evidence that the same attack works for RSA-2048 with + only moderately more computation. + +Exponent blinding is a kind of workaround to add noise. Signal (leak) +is still there for non-constant-time implementation. + +(backported from master commit: +8725c99ffa41778f382ca97233183bcd687bb0ce) + +Signed-off-by: Ross Burton +--- + cipher/rsa.c | 32 +++++++++++++++++++++++++------- + 1 file changed, 25 insertions(+), 7 deletions(-) + +diff --git a/cipher/rsa.c b/cipher/rsa.c +index 0b98b6a8..d8658476 100644 +--- a/cipher/rsa.c ++++ b/cipher/rsa.c +@@ -724,15 +724,33 @@ secret (gcry_mpi_t output, gcry_mpi_t input, RSA_secret_key *skey ) + gcry_mpi_t m1 = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 ); + gcry_mpi_t m2 = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 ); + gcry_mpi_t h = mpi_alloc_secure( mpi_get_nlimbs(skey->n)+1 ); +- +- /* m1 = c ^ (d mod (p-1)) mod p */ ++ gcry_mpi_t D_blind = mpi_alloc_secure ( mpi_get_nlimbs(skey->n) + 1 ); ++ gcry_mpi_t r; ++ unsigned int r_nbits; ++ ++ r_nbits = mpi_get_nbits (skey->p) / 4; ++ if (r_nbits < 96) ++ r_nbits = 96; ++ r = mpi_alloc_secure ((r_nbits + BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB); ++ ++ /* d_blind = (d mod (p-1)) + (p-1) * r */ ++ /* m1 = c ^ d_blind mod p */ ++ _gcry_mpi_randomize (r, r_nbits, GCRY_WEAK_RANDOM); ++ mpi_set_highbit (r, r_nbits - 1); + mpi_sub_ui( h, skey->p, 1 ); +- mpi_fdiv_r( h, skey->d, h ); +- mpi_powm( m1, input, h, skey->p ); +- /* m2 = c ^ (d mod (q-1)) mod q */ ++ mpi_mul ( D_blind, h, r ); ++ mpi_fdiv_r ( h, skey->d, h ); ++ mpi_add ( D_blind, D_blind, h ); ++ mpi_powm( m1, input, D_blind, skey->p ); ++ /* d_blind = (d mod (q-1)) + (q-1) * r */ ++ /* m2 = c ^ d_blind mod q */ ++ _gcry_mpi_randomize (r, r_nbits, GCRY_WEAK_RANDOM); ++ mpi_set_highbit (r, r_nbits - 1); + mpi_sub_ui( h, skey->q, 1 ); +- mpi_fdiv_r( h, skey->d, h ); +- mpi_powm( m2, input, h, skey->q ); ++ mpi_mul ( D_blind, h, r ); ++ mpi_fdiv_r ( h, skey->d, h ); ++ mpi_add ( D_blind, D_blind, h ); ++ mpi_powm( m2, input, D_blind, skey->q ); + /* h = u * ( m2 - m1 ) mod q */ + mpi_sub( h, m2, m1 ); + if ( mpi_has_sign ( h ) ) +-- +2.11.0 + + +From b7c572550b8759f2b0e45ee72df0494700b26da1 Mon Sep 17 00:00:00 2001 +From: NIIBE Yutaka +Date: Thu, 29 Jun 2017 12:36:27 +0900 +Subject: [PATCH 4/5] rsa: Fix exponent blinding. + +* cipher/rsa.c (secret): Free D_BLIND. + +-- + +Fixes-commit: a9f612def801c8145d551d995475e5d51a4c988c +Signed-off-by: NIIBE Yutaka +Signed-off-by: Ross Burton +--- + cipher/rsa.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/cipher/rsa.c b/cipher/rsa.c +index d8658476..9474fe89 100644 +--- a/cipher/rsa.c ++++ b/cipher/rsa.c +@@ -760,6 +760,7 @@ secret (gcry_mpi_t output, gcry_mpi_t input, RSA_secret_key *skey ) + mpi_mul ( h, h, skey->p ); + mpi_add ( output, m1, h ); + ++ mpi_free ( D_blind ); + mpi_free ( h ); + mpi_free ( m1 ); + mpi_free ( m2 ); +-- +2.11.0 + + +From e5a5f14bdd8d6265f85264575a1f3c3307306849 Mon Sep 17 00:00:00 2001 +From: NIIBE Yutaka +Date: Thu, 29 Jun 2017 12:40:19 +0900 +Subject: [PATCH 5/5] rsa: More fix. + +* cipher/rsa.c (secret): Free R. + +-- + +Fixes-commit: a9f612def801c8145d551d995475e5d51a4c988c +Signed-off-by: NIIBE Yutaka +Signed-off-by: Ross Burton +--- + cipher/rsa.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/cipher/rsa.c b/cipher/rsa.c +index 9474fe89..b151b39f 100644 +--- a/cipher/rsa.c ++++ b/cipher/rsa.c +@@ -760,6 +760,7 @@ secret (gcry_mpi_t output, gcry_mpi_t input, RSA_secret_key *skey ) + mpi_mul ( h, h, skey->p ); + mpi_add ( output, m1, h ); + ++ mpi_free ( r ); + mpi_free ( D_blind ); + mpi_free ( h ); + mpi_free ( m1 ); +-- +2.11.0 + diff --git a/meta/recipes-support/libgcrypt/libgcrypt.inc b/meta/recipes-support/libgcrypt/libgcrypt.inc index 5478253e068..404f870db03 100644 --- a/meta/recipes-support/libgcrypt/libgcrypt.inc +++ b/meta/recipes-support/libgcrypt/libgcrypt.inc @@ -18,6 +18,7 @@ SRC_URI = "ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-${PV}.tar.gz \ file://add-pkgconfig-support.patch \ file://libgcrypt-fix-building-error-with-O2-in-sysroot-path.patch \ file://fix-ICE-failure-on-mips-with-option-O-and-g.patch \ + file://CVE-2017-7526.patch \ " BINCONFIG = "${bindir}/libgcrypt-config" From patchwork Wed Jul 19 13:27:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 108291 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp858016obm; Wed, 19 Jul 2017 06:27:40 -0700 (PDT) X-Received: by 10.84.236.77 with SMTP id h13mr70462pln.183.1500470860101; Wed, 19 Jul 2017 06:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500470860; cv=none; d=google.com; s=arc-20160816; b=MTMlr2CGDh+ccN08MtZKf5oYb9bCu7Ci8Mw4QOJYYXFAdaC4J43YkGlqCHq1hQ+D/y RokWZMIboO3Clh8WElNre5fp9Ii0enDE60EzZ9e9hInbSTsY4puqoSzSPHvKgvg447CG WgBXaFWRgiu0pTRlhJUjuE9kkNb5J+zVMTpK7cRI+hR9PzHw0BtGsXHAJs4p0G4GRKKs aukEATQMGfewL7qSilMQJt9laMoC2L2HkxqMrl8qRXfXgTXqUrQYFGHoc9vPNWibE2q6 qhJCBdb3LMSqWyXjJoxcXCpIGINzv5Rj07pZHm9mkV4hWJCTBxkTiEMyzbSZOq3RseQM YUFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=g1rnWG8Iq9MIuYvqFNNVcR4ak44TUiWQpAalVpPmRW8=; b=RunObOhLW+hsNAxpyAAIFhAFQRKbSYDgCd/UVAC7cRf8KBC2BjiKDBtPU8XF5WzLKJ QydGg4jRxCG31fbGtqtwdKNfhTcHlKrWhgk7p8p+locjwxZ+TRx9GgX8YGKGlk1xcWiG SXbVVtA3Ct61b0vZfGIlzvK6iBx4VRuVlRHTr6iE5yOy77b1irkLzvrSIuG6oAR9q5ji TvIgvA1nDDdqh6EKQscog3I0ajIbjg/rSy/mDub61bMox1C4gnNLiWsvBfpWtuC26rN6 mtYYfgProWjgjIiNGp0sTd9VfY/iIOFdb4BUZYhFk5lyp7oZi9T4XnwrPzEFySdQDgsJ apLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.b=vGMASMfh; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id q3si4342877plb.366.2017.07.19.06.27.39; Wed, 19 Jul 2017 06:27:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel-com.20150623.gappssmtp.com header.b=vGMASMfh; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Received: from review.yoctoproject.org (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 5B85E782B5; Wed, 19 Jul 2017 13:27:37 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by mail.openembedded.org (Postfix) with ESMTP id EB062782B5 for ; Wed, 19 Jul 2017 13:27:35 +0000 (UTC) Received: by mail-wr0-f174.google.com with SMTP id v105so28447656wrb.0 for ; Wed, 19 Jul 2017 06:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=kGmFCaLiC4RoMOJvOaQ9+Hm6vznW5Tyv6BxJD8IH3C8=; b=vGMASMfh+Nq5yefYd9WSSI9t5HT+Bfg5FpZ36LLM4Il2cE5nukPuelkcbdLv1USk/B pPa8vQxAAwQkB6/WC9ltrVaV5Bs/ZXAs6K1S+OqEWwvlNXJvt4H5X1oMhAA0c/OcYNNd wtlDMUk0eTRXukAZNMlQ3srG/OFntKCHT2BlyenkTozrVmv6w0+IijU0LMc/HkrPxBaB Hvq2yK8pM4BdC9DEAa8IHxrbJykk2IDJ7bw9mJ+S9ReeX/fAm5CPR45vcFF4CDhb79RT ZvnW/WbF0Nu8gYNs5M13NqtwKFp9SQqnhaAzjN5E64yGqbSvbGL3Ap+o0D8vNETFtKe7 XXfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=kGmFCaLiC4RoMOJvOaQ9+Hm6vznW5Tyv6BxJD8IH3C8=; b=Ji5YgU/d8BAskXI/jAt8xt5URSTlsvKJ5QG60G3m+fnPEi0yV6I09Ohkfk5FGx3b/R ErL81xNTvv5kYNe8/IkgKSP+zgfn0jfqTTGTECjtephN/vOE+6hh4hNVHfP6e2PstuOg x2Toqu97qGq4utHjGHCdFWwKT9uWAS3jC58EDz5l0YGQsBADYWLIj9oPY8rz4x4V23Yn VYYJkW2G8TGJcvstwcAQVK07rkGj1R6/pDnaX6NnR88RtlThTOkRMaa70clOZTfVK0Ml 15Nz9C7R+gARzfGahEznF3v2smtP70gmWOtBPaZKHJ659aPLCKIYvJQSZQ+JTlh3KjYs pu+Q== X-Gm-Message-State: AIVw111BAsY8MDXDPcOGxiTQILJgKgJjNLIfYsPMJaourTNE8cnHIX1C qMg2SVi4vuIKzzYO940= X-Received: by 10.223.149.65 with SMTP id 59mr382341wrs.292.1500470856782; Wed, 19 Jul 2017 06:27:36 -0700 (PDT) Received: from flashheart.burtonini.com (home.burtonini.com. [81.2.106.35]) by smtp.gmail.com with ESMTPSA id l31sm5911891wrc.12.2017.07.19.06.27.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Jul 2017 06:27:36 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Date: Wed, 19 Jul 2017 14:27:32 +0100 Message-Id: <20170719132732.6933-2-ross.burton@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170719132732.6933-1-ross.burton@intel.com> References: <20170719132732.6933-1-ross.burton@intel.com> Subject: [OE-core] [PATCH][krogoth 2/2] libgcrypt: fix CVE-2017-9526 X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org In libgcrypt before 1.7.7, an attacker who learns the EdDSA session key (from side-channel observation during the signing process) can easily recover the long-term secret key. 1.7.7 makes a cipher/ecc-eddsa.c change to store this session key in secure memory, to ensure that constant-time point operations are used in the MPI library. Signed-off-by: Ross Burton --- ...-Store-EdDSA-session-key-in-secure-memory.patch | 39 ++++++++++++++++++++++ meta/recipes-support/libgcrypt/libgcrypt.inc | 1 + 2 files changed, 40 insertions(+) create mode 100644 meta/recipes-support/libgcrypt/files/0001-ecc-Store-EdDSA-session-key-in-secure-memory.patch -- 2.11.0 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core diff --git a/meta/recipes-support/libgcrypt/files/0001-ecc-Store-EdDSA-session-key-in-secure-memory.patch b/meta/recipes-support/libgcrypt/files/0001-ecc-Store-EdDSA-session-key-in-secure-memory.patch new file mode 100644 index 00000000000..f6c4ca76f33 --- /dev/null +++ b/meta/recipes-support/libgcrypt/files/0001-ecc-Store-EdDSA-session-key-in-secure-memory.patch @@ -0,0 +1,39 @@ +CVE: CVE-2017-9526 +Upstream-Status: Backport +Signed-off-by: Ross Burton + +From b3cab278eb9c2ceda79f980bc26460d97f260041 Mon Sep 17 00:00:00 2001 +From: Jo Van Bulck +Date: Thu, 19 Jan 2017 17:00:15 +0100 +Subject: [PATCH] ecc: Store EdDSA session key in secure memory. + +* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_sign): use mpi_snew to allocate +session key. +-- + +An attacker who learns the EdDSA session key from side-channel +observation during the signing process, can easily revover the long- +term secret key. Storing the session key in secure memory ensures that +constant time point operations are used in the MPI library. + +Signed-off-by: Jo Van Bulck +--- + cipher/ecc-eddsa.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c +index f91f8489..813e030d 100644 +--- a/cipher/ecc-eddsa.c ++++ b/cipher/ecc-eddsa.c +@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, ECC_secret_key *skey, + a = mpi_snew (0); + x = mpi_new (0); + y = mpi_new (0); +- r = mpi_new (0); ++ r = mpi_snew (0); + ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0, + skey->E.p, skey->E.a, skey->E.b); + b = (ctx->nbits+7)/8; +-- +2.11.0 + diff --git a/meta/recipes-support/libgcrypt/libgcrypt.inc b/meta/recipes-support/libgcrypt/libgcrypt.inc index 404f870db03..8e7a38f8940 100644 --- a/meta/recipes-support/libgcrypt/libgcrypt.inc +++ b/meta/recipes-support/libgcrypt/libgcrypt.inc @@ -18,6 +18,7 @@ SRC_URI = "ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-${PV}.tar.gz \ file://add-pkgconfig-support.patch \ file://libgcrypt-fix-building-error-with-O2-in-sysroot-path.patch \ file://fix-ICE-failure-on-mips-with-option-O-and-g.patch \ + file://0001-ecc-Store-EdDSA-session-key-in-secure-memory.patch \ file://CVE-2017-7526.patch \ "