Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp606819yba; Thu, 18 Apr 2019 06:45:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUnSAj8G6tGZ8nnX9hmwR+v/BMWnPCSeS8GWy4Syy6RlnRKx5y0C5yzYLdEARQtS/rrj+c X-Received: by 2002:aa7:8c56:: with SMTP id e22mr97059054pfd.155.1555595108033; Thu, 18 Apr 2019 06:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555595108; cv=none; d=google.com; s=arc-20160816; b=UpUz2GJbqro7lYVvCqkqjy5iZlKBdDhgPk2UH9kqDkOY6aq1i6Ajd6v+xIPpi3kZdb pLw2rSIl8L9M6u37BOv65zuq3VaEj5zeEexagd7WDzbVem2C538SPizkADyiOtvR0bf9 99Cdi6PplNfAnnD9a79v3lhUS5+nxYQ/nzHkg+MPM+lOSyFUhOuE1gs1DKXIi5eHk/Ut aR/BetqRGwFHUZgdIPhUX4/u9/OOoYMNm92lavP+JIIwuxC9/sxNEMfy8s40T+CACfwg GQE8tnxFYNCTxLfak0kzphjxJUCCU0U59tCMWIWJv0NuGsVdPFoC6R6xA3sMEt3po4SB 4l6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qI+XqKLmP9DMufDWk/E18zAnZBQb47rMXwJNsb3jaAk=; b=Kb5S2xMP0i8fBDVWAJQBr1yTKzfpjw+XBDxtCaQTIxtf8dCP83Nc4znKH/+Bit+rfH EsB7/UniOhCt+vHtwDZQ0yYxxzK0IptZTkqG9CLT/Qj4mlKfhND1kzCnfFfs79vjBhMx sX383bCIRW2mlqxgrW7qUY18VvuHpCtgns927MWR5+4jOpzL8UyTbAPmn/PEgPb3aCgH qVI1n1qgUJUgawdWkkwV7i+GrsVoG6oRZLOXFfJLh8J5sDgcPIFsPT1PbMjSMDRZF7oK n+Yw+k1UJRfPXRcCHmjrT9yWSOgbKIZp8yhFlWOUngw5Tttvh0NUhFpcwC4Dii4C9okF 8qnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si2459050pfa.268.2019.04.18.06.44.53; Thu, 18 Apr 2019 06:45:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389277AbfDRNmJ (ORCPT + 99 others); Thu, 18 Apr 2019 09:42:09 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33742 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389071AbfDRNmH (ORCPT ); Thu, 18 Apr 2019 09:42:07 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AB32380D; Thu, 18 Apr 2019 06:42:06 -0700 (PDT) Received: from e110176-lin.kfn.arm.com (e110176-lin.kfn.arm.com [10.50.4.178]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0EE6D3F5AF; Thu, 18 Apr 2019 06:42:04 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" Cc: Ofir Drang , stable@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 29/35] crypto: ccree: don't map MAC key on stack Date: Thu, 18 Apr 2019 16:39:04 +0300 Message-Id: <20190418133913.9122-30-gilad@benyossef.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418133913.9122-1-gilad@benyossef.com> References: <20190418133913.9122-1-gilad@benyossef.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The MAC hash key might be passed to us on stack. Copy it to a slab buffer before mapping to gurantee proper DMA mapping. Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ --- drivers/crypto/ccree/cc_hash.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccree/cc_hash.c b/drivers/crypto/ccree/cc_hash.c index 36e9fb4141f8..a6abe4e3bb0e 100644 --- a/drivers/crypto/ccree/cc_hash.c +++ b/drivers/crypto/ccree/cc_hash.c @@ -69,6 +69,7 @@ struct cc_hash_alg { struct hash_key_req_ctx { u32 keylen; dma_addr_t key_dma_addr; + u8 *key; }; /* hash per-session context */ @@ -742,13 +743,20 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key, ctx->key_params.keylen = keylen; ctx->key_params.key_dma_addr = 0; ctx->is_hmac = true; + ctx->key_params.key = NULL; if (keylen) { + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, (void *)ctx->key_params.key, keylen, + DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", - key, keylen); + ctx->key_params.key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -899,6 +907,9 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key, dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); } + + kzfree(ctx->key_params.key); + return rc; } @@ -925,11 +936,16 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash, ctx->key_params.keylen = keylen; + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, ctx->key_params.key, keylen, DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -981,6 +997,8 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash, dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); + kzfree(ctx->key_params.key); + return rc; } -- 2.21.0