From patchwork Sat Jun 10 02:59:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9779611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F18160393 for ; Sat, 10 Jun 2017 02:59:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EE78285A6 for ; Sat, 10 Jun 2017 02:59:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1216A2866F; Sat, 10 Jun 2017 02:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 26BC6285A6 for ; Sat, 10 Jun 2017 02:59:43 +0000 (UTC) Received: (qmail 24401 invoked by uid 550); 10 Jun 2017 02:59:38 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 24283 invoked from network); 10 Jun 2017 02:59:37 -0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=4Yx8 2vUJpZPZSANXDX7BVNOilAg=; b=0ORwIOSGD8JUOKQcdaWKrz45ZxyznZH2cJOj o+4b/LtAU8G5g2TJW4LxftkDGzWP3rPLNWJrhb9an2v6MrF2oVwG/HjMixOXt/Jd 2NVcRPc9rmKJ1Vx7plrXBHLpB4ayEq91/BB5rheZYiyFcgODAMrYo1VXD8MaCP/4 5YokY2YSO/2cPsRcrLScW8DzXcMv861ldMYl2lS9/sO6fUrg76VkUI/ILRktRlf/ +CbE1eTkkrV8fYUEmzOA85R+vEu8roB6vE/k4CaflQn+wUuaKKXuGJVfpFeqcDg8 WRcAlQ+Ifi6Wl1lakzX3fu8EG/X3zELP49bXeqRX7VvcC52DSQ== From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Cc: "Jason A. Donenfeld" , David Safford , Mimi Zohar , David Howells , keyrings@vger.kernel.org, stable@vger.kernel.org Date: Sat, 10 Jun 2017 04:59:10 +0200 Message-Id: <20170610025912.6499-5-Jason@zx2c4.com> In-Reply-To: <20170610025912.6499-1-Jason@zx2c4.com> References: <20170610025912.6499-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH 4/6] security/keys: use constant time memory comparison for macs X-Virus-Scanned: ClamAV using ClamSMTP Otherwise, we enable a MAC forgery via timing attack. Signed-off-by: Jason A. Donenfeld Cc: David Safford Cc: Mimi Zohar Cc: David Howells Cc: keyrings@vger.kernel.org Cc: stable@vger.kernel.org Reviewed-by: James Morris --- security/keys/trusted.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/security/keys/trusted.c b/security/keys/trusted.c index 2ae31c5a87de..df7d30b0a6f7 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -11,6 +11,7 @@ * See Documentation/security/keys-trusted-encrypted.txt */ +#include #include #include #include @@ -243,7 +244,7 @@ static int TSS_checkhmac1(unsigned char *buffer, if (ret < 0) goto out; - if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE)) + if (crypto_memneq(testhmac, authdata, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: kfree(sdesc); @@ -335,7 +336,7 @@ static int TSS_checkhmac2(unsigned char *buffer, TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0); if (ret < 0) goto out; - if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) { + if (crypto_memneq(testhmac1, authdata1, SHA1_DIGEST_SIZE)) { ret = -EINVAL; goto out; } @@ -344,7 +345,7 @@ static int TSS_checkhmac2(unsigned char *buffer, TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0); if (ret < 0) goto out; - if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE)) + if (crypto_memneq(testhmac2, authdata2, SHA1_DIGEST_SIZE)) ret = -EINVAL; out: kfree(sdesc);