From patchwork Mon May 20 12:14:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164614 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp225687ili; Mon, 20 May 2019 05:30:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcWIFXUCjiNzMy7j3MA/18zgI0JbFOfXH9XPlfICY5N4AOm6SxW4Uo5IEx8raVkoXdFQ3Q X-Received: by 2002:a63:fd52:: with SMTP id m18mr75515704pgj.267.1558355400662; Mon, 20 May 2019 05:30:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355400; cv=none; d=google.com; s=arc-20160816; b=n7BfrJ7HERWn9ukAYG0ItNPf3AVVv+1w3c+1IV/n24aH+k449NQYjiksa4AgUjTkqG Uu+b/g0UeuEWUW/itaqvIM40jaxpJm+UmASFpHpjyaEAGozi/dy0xMdEwBwk9nG150GX Zme5Vxlp7AxBRf0ukw7lQydZXsH4kr8EDJBC6nnH5NZ6780By+gaIGB3TyvqmjTA5eoZ mSJbsKUuRRGoGhqFbiZx2NlPoAi0tTeFsPdW2sxrLjlli+bq5yKrBO7L98u6olZic4YN b4S5I6ysoHCtFxjSplUZdK+dW1la6fDAFlCwvoSr6fkK+12ObSGdmcwQqqMl5ivO+aYk dXcg== 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=ARw5OkX8RrRkC62uBGX0tw06kUtIzZt2Zd6J4Z/scf4=; b=qEUiWT+XbaOKkVw7bh+lqYbqF84VNsZ5EGs9OPY69stazq4T5hKxHON6F/XH0UqFjW QdFi5nI+gES0wFUEdkBxKoxdNy1nvWIXNcJ+I812feTCt/A72rbU2vQ5dEgs2m7QYiy5 QvQqpxy6l0DQat94hR/mr28Xq0UfxhtV25IGNf4P1veprZZ08h49vnCfolGqL98pn2Pw TD3AiwK4/62BHnBkh7pWVjgX6RFjMOM4ohIQyT3HpdVku5/N800kaRctOJkcemBgPeRn KqGhHBEOgoO0f/UlX1iaN0RGfRr+DctiKN8qUL/w5rDOGcuGzk7z72RUrRO3UKldKYFi aekg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DZz3Ba05; 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 186si18145232pfc.247.2019.05.20.05.30.00; Mon, 20 May 2019 05:30: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=DZz3Ba05; 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 S2389975AbfETM37 (ORCPT + 14 others); Mon, 20 May 2019 08:29:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:46120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390007AbfETM35 (ORCPT ); Mon, 20 May 2019 08:29:57 -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 2CDAE20645; Mon, 20 May 2019 12:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355396; bh=2TRMfZDviT4+xoulx6yedoRHajY+kmB/koE91teu8Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DZz3Ba05G4fCi7W/CN8xH764Ed663rTGo9pxsATVcKGu/rJ06dtmxQIOPdmcH1f4f N2nxACrhOTvCXNbtqokg23Vii1ZrzhbN7/GlyDmEpxCMslXa/Ld/QRID9ItO9nvzrA 0XXp9DsGunVDLfCR4mVXu47qWdZk2Y8cLN2sV3Cg= 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.0 062/123] crypto: ccree - dont map AEAD key and IV on stack Date: Mon, 20 May 2019 14:14:02 +0200 Message-Id: <20190520115248.925921091@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@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 e8662a6a5f8f7f2cadc0edb934aef622d96ac3ee upstream. The AEAD authenc key and IVs 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_aead.c | 11 ++++++++++- drivers/crypto/ccree/cc_buffer_mgr.c | 15 ++++++++++++--- drivers/crypto/ccree/cc_driver.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -424,7 +424,7 @@ static int validate_keys_sizes(struct cc /* This function prepers the user key so it can pass to the hmac processing * (copy to intenral buffer or hash in case of key longer than block */ -static int cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, +static int cc_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *authkey, unsigned int keylen) { dma_addr_t key_dma_addr = 0; @@ -437,6 +437,7 @@ static int cc_get_plain_hmac_key(struct unsigned int hashmode; unsigned int idx = 0; int rc = 0; + u8 *key = NULL; struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ]; dma_addr_t padded_authkey_dma_addr = ctx->auth_state.hmac.padded_authkey_dma_addr; @@ -455,11 +456,17 @@ static int cc_get_plain_hmac_key(struct } if (keylen != 0) { + + key = kmemdup(authkey, keylen, GFP_KERNEL); + if (!key) + return -ENOMEM; + key_dma_addr = dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); if (dma_mapping_error(dev, key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", key, keylen); + kzfree(key); return -ENOMEM; } if (keylen > blocksize) { @@ -542,6 +549,8 @@ static int cc_get_plain_hmac_key(struct if (key_dma_addr) dma_unmap_single(dev, key_dma_addr, keylen, DMA_TO_DEVICE); + kzfree(key); + return rc; } --- a/drivers/crypto/ccree/cc_buffer_mgr.c +++ b/drivers/crypto/ccree/cc_buffer_mgr.c @@ -560,6 +560,7 @@ void cc_unmap_aead_request(struct device if (areq_ctx->gen_ctx.iv_dma_addr) { dma_unmap_single(dev, areq_ctx->gen_ctx.iv_dma_addr, hw_iv_size, DMA_BIDIRECTIONAL); + kzfree(areq_ctx->gen_ctx.iv); } /* Release pool */ @@ -664,19 +665,27 @@ static int cc_aead_chain_iv(struct cc_dr struct aead_req_ctx *areq_ctx = aead_request_ctx(req); unsigned int hw_iv_size = areq_ctx->hw_iv_size; struct device *dev = drvdata_to_dev(drvdata); + gfp_t flags = cc_gfp_flags(&req->base); int rc = 0; if (!req->iv) { areq_ctx->gen_ctx.iv_dma_addr = 0; + areq_ctx->gen_ctx.iv = NULL; goto chain_iv_exit; } - areq_ctx->gen_ctx.iv_dma_addr = dma_map_single(dev, req->iv, - hw_iv_size, - DMA_BIDIRECTIONAL); + areq_ctx->gen_ctx.iv = kmemdup(req->iv, hw_iv_size, flags); + if (!areq_ctx->gen_ctx.iv) + return -ENOMEM; + + areq_ctx->gen_ctx.iv_dma_addr = + dma_map_single(dev, areq_ctx->gen_ctx.iv, hw_iv_size, + DMA_BIDIRECTIONAL); if (dma_mapping_error(dev, areq_ctx->gen_ctx.iv_dma_addr)) { dev_err(dev, "Mapping iv %u B at va=%pK for DMA failed\n", hw_iv_size, req->iv); + kzfree(areq_ctx->gen_ctx.iv); + areq_ctx->gen_ctx.iv = NULL; rc = -ENOMEM; goto chain_iv_exit; } --- a/drivers/crypto/ccree/cc_driver.h +++ b/drivers/crypto/ccree/cc_driver.h @@ -170,6 +170,7 @@ struct cc_alg_template { struct async_gen_req_ctx { dma_addr_t iv_dma_addr; + u8 *iv; enum drv_crypto_direction op_type; };