From patchwork Mon May 20 12:14:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164622 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp231340ili; Mon, 20 May 2019 05:34:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqysTCNlAnK/6PlJ2jzfaiityO2vgp+SYNWIrk+u57Yn6Ma6v1pZeWCiyt7DdkY5D+m1EtsC X-Received: by 2002:a65:4144:: with SMTP id x4mr16741690pgp.282.1558355685532; Mon, 20 May 2019 05:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355685; cv=none; d=google.com; s=arc-20160816; b=Z96HjKzusqRea6HW96D1sJasty6+sfLxt9Mu9HOIp/IjM2tX30GIiWn0yzrJkAUWyC nOwkdgEzb0z3OIlPy0CCn8cqD56LUQKcKeE3q1gowMmOFc/Ts/7a/VMO6Mw3RT6pt806 e3rKqm6vAZDzBDaonaomFKcrNQp6TJz+stZtXwOEA+d7qUfa1UWZdKO0sfWNCO6ABfeQ 09SSnHmO3YHa2wabo84WeRYB//RNNAadkJ14kpsYsK1kMfgcJE9hjTopbz07Dl10Xo7x Z0qF0BTbyuB1ZMWH1XLqO8JGI/UCrmQh3mfaKeUG8kJlnqxGPQx6XzHyYklMbSRR7Apc JPpA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4hi58WDdbOUM/9kH+6aekOTXYHooTdZi2b7xGvjqVXg=; b=bmUZDkvxEUuDQTwQbxswzuMEvfmZ5x0b0ZbiAGDeJK/KpW1U0Su0atCncVeMiVCeyq 6R+AmaxpnqjxP7gIMy29fEJjPH+/YrIUm4ozJ+E42KQ0PHu5c8EIPzNnKQE7TnMdseh7 wkymY0nTq6TGyd7DxWLMMIN/+2oDwBsGiK4+5t4nltRwpidpfc4IoCMAwgurx0Y0yieR u5Rap0kzdtnSLyM0p5sa3u5ar//j6Rqa0DpLDeWyrWdFPjfKS9XYn+6BNFWjUzilSHHV pqI5RdoQ+vsJtaJFcN1Il2wyuUXuT2tGeCbwTidI7HkvfnQdIX4j8Uz8gfx3frLToPTe LUkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ov9DsBTz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.34.43; Mon, 20 May 2019 05:34:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ov9DsBTz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390776AbfETMdn (ORCPT + 14 others); Mon, 20 May 2019 08:33:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:50838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390770AbfETMdm (ORCPT ); Mon, 20 May 2019 08:33:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 861D920815; Mon, 20 May 2019 12:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355621; bh=jS18uhjhZFB0J7GPa296xwoUoszjtacB5vvBJtErWs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ov9DsBTzrZelEL3Gco+S8/JellBtP/rJq3ElSGZsA2pX4r0LFWb1NgMxazQst9kig bF5vFmxl40+Via/jLFw6Qw1KfnOr0Exc3N83LAkPjxupwprbF22B9JVLge9qjGJYwR gYFdTHx7ORBvINgyt4LsOtIt60nyQWyqs2Cd8wx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 5.1 062/128] crypto: ccree - dont map MAC key on stack Date: Mon, 20 May 2019 14:14:09 +0200 Message-Id: <20190520115253.971748129@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef commit 874e163759f27e0a9988c5d1f4605e3f25564fd2 upstream. 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+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_hash.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) --- 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 */ @@ -730,13 +731,20 @@ static int cc_hash_setkey(struct crypto_ 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", @@ -887,6 +895,9 @@ out: 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; } @@ -913,11 +924,16 @@ static int cc_xcbc_setkey(struct crypto_ 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", @@ -969,6 +985,8 @@ static int cc_xcbc_setkey(struct crypto_ 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; }