From patchwork Mon May 20 12:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164606 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp219708ili; Mon, 20 May 2019 05:24:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZOdgZz1WlvyWb3WFngIHzD4zWrz5Yx1yO1xwGOJtHOwWBYAxdxpzwPJKOKyh4TGOdILgS X-Received: by 2002:a17:902:683:: with SMTP id 3mr32380986plh.209.1558355040340; Mon, 20 May 2019 05:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355040; cv=none; d=google.com; s=arc-20160816; b=M82Yual+Vf0oDvw4VUU+RoufgTJRaNUmjv+T1oZDlbjIbwiM+NW5K5YyBDCjoZ0OIb ngg7xul9EQ0x6qsNPtTkDMrkSH6qHh1c8epYueiUejA3Qy9jhhW+NbOv5zfDN6aGNFXU pAQXFPzveVj3tSQlx2pdgBpa9h8kxuJ7I0gmo9qIMkebJ1b5bXZjuHNKk9bZKAimekdk W3rjizxySU5oO0Tmusb/3d8E7fEaUvMmBjJ1ZvwpAJuk+Nfb6rjAFYSESy50ii/HMKCP E3L8R+9Ew5X6XpuXGROZ+a8VDJHgl9R8/QGYSNSYSlAY7WwbN5zCrGfNSU3ZdGii82yD MTRg== 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=PZ9R3lnj/WQmdWnaAXWDXtPY/Q6QUjS4oGv1kTDk0GM=; b=uC5bHVMFnvM8WCXXeOwJB1lEAsMaAYptEY7OZEkH+/wJZ7+2nUGl/ul1lRLEi/67R8 1ieQckNVckhHeOpEi2gjD5ueE8ewmqlxFt/JACkPycLGflsJnpRt9zJfJy4oh7fm0Y2l 6m9Uz3InmZ/ZZ6qGE453wrqqfzLjmR9bPsLsq9zBkrv/AWC6pG8LEV1uQHO+IsI1MH+7 BkLJpUY9CLgot0socXcR44CUatx+0mZzxx3aLxO3ikpjmzSGUDUDeI4J7dW/IDAoYHER iLO9G2yMw5e6Cog+/CPv8N9eeOj8KoBSQlJLAfNyrmgHHnx9Pgr7zgUF7o4HG0K8Ka1R Il/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2u/R27Cd"; 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 y13si18772163pff.19.2019.05.20.05.24.00; Mon, 20 May 2019 05:24:00 -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="2u/R27Cd"; 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 S2388731AbfETMX7 (ORCPT + 14 others); Mon, 20 May 2019 08:23:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38712 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731841AbfETMX6 (ORCPT ); Mon, 20 May 2019 08:23:58 -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 2EBDC21019; Mon, 20 May 2019 12:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355037; bh=IJ56Gfg/ZuObPvWDkhIhB0XNueE9tEbv3xnUjf7eU/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2u/R27Cd9Eyjf/6jxGZpD3Q14kdYwoQ+CA1OoR2XPHczxAXcVsDeklaqwk3SWeUmX yHW0mfcdsJFjxXyZ854vi3CP4zEWsZzu43Pb8Q+sVBMILLKkNWLbt1Jz0kGOgyAF7E ebW//iIn0+yc1M+VWPDVTgm0hui3+/2J7NKK57Zo= 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 4.19 046/105] crypto: ccree - dont map MAC key on stack Date: Mon, 20 May 2019 14:13:52 +0200 Message-Id: <20190520115250.198221588@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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 @@ -64,6 +64,7 @@ struct cc_hash_alg { struct hash_key_req_ctx { u32 keylen; dma_addr_t key_dma_addr; + u8 *key; }; /* hash per-session context */ @@ -724,13 +725,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", @@ -881,6 +889,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; } @@ -907,11 +918,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", @@ -963,6 +979,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; }