Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp260914yba; Mon, 20 May 2019 08:16:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqydkQdK0h8CL1TMcHIM7H7DuZ2Zu6qfftuSR49/0sxB0TRtlmzlK7CM/5D7K6k8I44ilI1a X-Received: by 2002:a17:902:e30b:: with SMTP id cg11mr75716466plb.3.1558365401350; Mon, 20 May 2019 08:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558365401; cv=none; d=google.com; s=arc-20160816; b=qwcYKkLLcCy5u6oWUYfK9BqYXGqLHbFQ4w1x3Svc3cUPxbwhXVhgOybK+2G0shm3zh cfqvwZm20DOqPWr4UGugAUJIG1l9pCE4SQgXT3w1/+4AAVbb8imByxtm2HW0i5MMljIf zvpqN53vmG1Si4mGlC2QfyVdqUArfeydYBa7ttDGxd/64ghCUWybZDQM87bAmBU6OxEf UnxyzngbZ6xlBY0FixpTJ5bmrWWND4xaNvfjlgOuuWRUbUZ1tMz8O+ZXGI/T/YxQv0F/ rSnawT30EQqZwc/I9mb76IhbY2CSTS7JEYSX7Ai+Z/hLY6mj7bS+5fLwgrpyyYZzyslk fWQA== 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=nto8aaPH7H1R30DIoRnPqOLSSHdiaKX3FVGo1SrWNG+VNiMUlKha4GA9qN0ht1dHI/ URWhg/uiwrE+fIaSGirz7V4mlKteePafFUuovdzKfgExlRTnMLEh5iKuDVgm+ZF4iy4X 3blcQFS6meb9TjHABTmTwRSARIAdfidF2hGrKaEPXzoQ8oKv67zsY3j1TWBTlJGfrwVA OSPnD8d/VixvC2IYvocg0P9SuLjHPd9bDdRNVB1MWxsh+HxqhqawmsPTuJB5xWgPUOwR ORKHVgtFTkT1angQ4agSTSO8vhIl/N1TKMzRnOfZDSIMPIosbLHTw01gHdqbIAPFCKvx hfZg== 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 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 r10si19333784pfh.147.2019.05.20.08.16.24; Mon, 20 May 2019 08:16:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b="2u/R27Cd"; 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 S2388745AbfETMYC (ORCPT + 99 others); Mon, 20 May 2019 08:24:02 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; }