From patchwork Wed Sep 28 16:42:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 9354283 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 D636060757 for ; Wed, 28 Sep 2016 16:43:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6ACD29730 for ; Wed, 28 Sep 2016 16:43:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB0F829743; Wed, 28 Sep 2016 16:43:18 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FE2A29730 for ; Wed, 28 Sep 2016 16:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933141AbcI1QnD (ORCPT ); Wed, 28 Sep 2016 12:43:03 -0400 Received: from mail-qk0-f171.google.com ([209.85.220.171]:34585 "EHLO mail-qk0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933883AbcI1Qmy (ORCPT ); Wed, 28 Sep 2016 12:42:54 -0400 Received: by mail-qk0-f171.google.com with SMTP id j129so44810908qkd.1 for ; Wed, 28 Sep 2016 09:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lezzPxbY/CZBz/IHwsWgTWPpqL9o7PKRX6PvEFCkbCA=; b=E9jexKV1UZVzAd9WZSsjfxFb8QBYsEXB3+GGOX4TPSPKceoA3euQTnZLYhzGxc2WN5 n2ZEXrA7feMWOmCsZmzwjwxiygmeKeCaYlBFNrtDpAd+gq/BPc03h/8tBHGwuIVUE7yG qjR4Y8CdHUyO9NgG2PbK5FWwhEf9G9MCHFrsrh6XmABraeMGkAyAZDfBg8YLAKXgY7hz aBRqPCxtOMFow2gxJ4y78IdLeV8n2NRASxHdOhIzN2tvGzVrWECv5D6PSiOjb7I6s+tM I4gzTYOzFSmk2f4YPdwjxOiCr9EuaqcmOBz4iv8UAu8a0aQFAd6CChz7s/aIp1jSK3Zf jQ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lezzPxbY/CZBz/IHwsWgTWPpqL9o7PKRX6PvEFCkbCA=; b=czZFDXyIPFj5wtJR2m3H5Cw4TLBfpITV5f+8CkoY+9xsojcW0iQRHKraaajJZTkjqU szBma25nGINwoV1Xes/htBosazRE0sS5T4Cwr5B7zh7QpumPZ+LygPiwehONUD1Mklnu 11pJMqjHJF/k+BQWjrpxI7nai9DiBFCvwLi1wNHmIKn+TnL1Mn2aS4zurxcCUB/hgskK CoTU4DT1g2YXDv+wRBx0fPopFogYWO6K+21MyeeiWZUaLipxY9rH5RiIdL2PNr4JwuNH KrUmc8C4aw7p/DiiID8lApk017TMi+HPER4WIpqIpeOnLrYdH46qsZMjnTbVYVbzWgPU eXsg== X-Gm-Message-State: AA6/9RmijiGrLcZ6DhJyk6wOahBIlpZ+Pr3d0EKmEkTlckDdrYmUgKEl2n8CrWKia2e+0DHU X-Received: by 10.55.92.71 with SMTP id q68mr31990318qkb.54.1475080972837; Wed, 28 Sep 2016 09:42:52 -0700 (PDT) Received: from localhost.localdomain (189-19-115-213.dsl.telesp.net.br. [189.19.115.213]) by smtp.gmail.com with ESMTPSA id a192sm4256654qkc.26.2016.09.28.09.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Sep 2016 09:42:51 -0700 (PDT) From: Marcelo Cerri To: linux-crypto@vger.kernel.org, Herbert Xu Cc: "David S. Miller" , Paulo Flabiano Smorigo , "Leonidas S. Barbosa" , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , George Wilson , Marcelo Cerri Subject: [PATCH 2/3] crypto: vmx - Fix memory corruption caused by p8_ghash Date: Wed, 28 Sep 2016 13:42:10 -0300 Message-Id: <1475080931-7926-3-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475080931-7926-1-git-send-email-marcelo.cerri@canonical.com> References: <1475080931-7926-1-git-send-email-marcelo.cerri@canonical.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch changes the p8_ghash driver to use ghash-generic as a fixed fallback implementation. This allows the correct value of descsize to be defined directly in its shash_alg structure and avoids problems with incorrect buffer sizes when its state is exported or imported. Reported-by: Jan Stancek Signed-off-by: Marcelo Cerri --- drivers/crypto/vmx/ghash.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/vmx/ghash.c b/drivers/crypto/vmx/ghash.c index 6c999cb0..27a94a1 100644 --- a/drivers/crypto/vmx/ghash.c +++ b/drivers/crypto/vmx/ghash.c @@ -26,16 +26,13 @@ #include #include #include +#include #include #include #include #define IN_INTERRUPT in_interrupt() -#define GHASH_BLOCK_SIZE (16) -#define GHASH_DIGEST_SIZE (16) -#define GHASH_KEY_LEN (16) - void gcm_init_p8(u128 htable[16], const u64 Xi[2]); void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]); void gcm_ghash_p8(u64 Xi[2], const u128 htable[16], @@ -55,16 +52,11 @@ struct p8_ghash_desc_ctx { static int p8_ghash_init_tfm(struct crypto_tfm *tfm) { - const char *alg; + const char *alg = "ghash-generic"; struct crypto_shash *fallback; struct crypto_shash *shash_tfm = __crypto_shash_cast(tfm); struct p8_ghash_ctx *ctx = crypto_tfm_ctx(tfm); - if (!(alg = crypto_tfm_alg_name(tfm))) { - printk(KERN_ERR "Failed to get algorithm name.\n"); - return -ENOENT; - } - fallback = crypto_alloc_shash(alg, 0, CRYPTO_ALG_NEED_FALLBACK); if (IS_ERR(fallback)) { printk(KERN_ERR @@ -78,10 +70,18 @@ static int p8_ghash_init_tfm(struct crypto_tfm *tfm) crypto_shash_set_flags(fallback, crypto_shash_get_flags((struct crypto_shash *) tfm)); - ctx->fallback = fallback; - shash_tfm->descsize = sizeof(struct p8_ghash_desc_ctx) - + crypto_shash_descsize(fallback); + /* Check if the descsize defined in the algorithm is still enough. */ + if (shash_tfm->descsize < sizeof(struct p8_ghash_desc_ctx) + + crypto_shash_descsize(fallback)) { + printk(KERN_ERR + "Desc size of the fallback implementation (%s) does not match the expected value: %lu vs %u\n", + alg, + shash_tfm->descsize - sizeof(struct p8_ghash_desc_ctx), + crypto_shash_descsize(fallback)); + return -EINVAL; + } + ctx->fallback = fallback; return 0; } @@ -113,7 +113,7 @@ static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key, { struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(tfm)); - if (keylen != GHASH_KEY_LEN) + if (keylen != GHASH_BLOCK_SIZE) return -EINVAL; preempt_disable(); @@ -211,7 +211,8 @@ struct shash_alg p8_ghash_alg = { .update = p8_ghash_update, .final = p8_ghash_final, .setkey = p8_ghash_setkey, - .descsize = sizeof(struct p8_ghash_desc_ctx), + .descsize = sizeof(struct p8_ghash_desc_ctx) + + sizeof(struct ghash_desc_ctx), .base = { .cra_name = "ghash", .cra_driver_name = "p8_ghash",