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: 676309 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3skkCn4QsLz9sf9 for ; Thu, 29 Sep 2016 02:48:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b=E9jexKV1; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3skkCn3NNzzDrZp for ; Thu, 29 Sep 2016 02:48:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b=E9jexKV1; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-qk0-x22d.google.com (mail-qk0-x22d.google.com [IPv6:2607:f8b0:400d:c09::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3skk5q0mm3zDrZr for ; Thu, 29 Sep 2016 02:42:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b=E9jexKV1; dkim-atps=neutral Received: by mail-qk0-x22d.google.com with SMTP id g67so52710990qkd.0 for ; Wed, 28 Sep 2016 09:42:55 -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=kPvhH9KafWBuzMyJjMagtW3JHLT3IwvNu9vfWuMixE18RczWVih/9nMYGDt8MjbAAN Sdd9G7tvYvtgIoA9Do2oyZ1g/spwvUdUv0/qNO3HuoaaZn/ApjVVHZvjW45YhrxGbSZf eE/Zf2WPR0wB+pLCHFwb8qjSfdz/uebDWGq2RmZqyieGtXgJ0G5OxrFBv2peuM218crP o4auOP3i1oDXWczL7IRaNr5YtiGSfGIiFKkrFLZJ8AphW0VBA9xH5Xwo9GdiT4Rc7Zz9 z2wkainDe/lBTwou2+u3eIy+3No+0MHynNtNEgK5dRiTGwsuA82G9hFOLlwEnoueZAC6 uM9w== X-Gm-Message-State: AA6/9RkBgrBHf6vZwB2okyAngmedO0lvRcratxRCu5JbUg+116InBASX59FTAZl898yXUYRA 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 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> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Leonidas S. Barbosa" , linux-kernel@vger.kernel.org, Paul Mackerras , Paulo Flabiano Smorigo , Marcelo Cerri , George Wilson , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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",