From patchwork Tue Oct 31 11:56:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 117600 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3807724qgn; Tue, 31 Oct 2017 04:56:36 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QnCBtXjrP8uYfIfT7kCW45V/t7elIGf0Tf5dhYnIeBpit6x+KMxjH28VH033+RYHIdiPMw X-Received: by 10.98.64.141 with SMTP id f13mr1789524pfd.213.1509450996614; Tue, 31 Oct 2017 04:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509450996; cv=none; d=google.com; s=arc-20160816; b=h5lrMRIJIUz0HO6AVYAZZur5yov2ihDQ0SzgCbxK1ZQPgCrhdky1EEuL8Yj91vfCSL Ah8sf3jRYgMcBZ3D6Fb3oz52x3WtYIooRhqmI38Im4KAcHtlMPY8V4Og4epVvBtHg7gM g/y9f1MESJ/upJh0vVYYhtLT6HZrf1BXtKCLR+Rxj2HbVSdnk7tbCgHADxjmyDGZum6B rGjROLQHZ7UG3O0cOkzz6a5oohcZuZw9fDeYnr5hlXbk3Qt4b86YVw8A2cGtYI2Yhru5 fEnpaN9tCJ9tRlblVRAcG3IA1kATvWvMr7vq2fu2q6wDO80klh7SSHjwDnG16GwXGdxX hNpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=EyL3SN1xfenMH6xp6Tivrh0bXKnzTIHYbnPBkE3TEJU=; b=t6bbdy6QNkrKYd1vHLmxMFIAktkzjNGaXGod+FWW55NpQc5vge5X+L1quJVBnz9a+7 y8MY4y9HxgeNGMYG/944OWkK/JTWStkMtcBriegs53tz0ZsxhEHT7JIW6IERkhq7FcsX MGCm+JpnTRwDG2JouGyWX/r2j9eOh2q78NoN1AIakvrjO3ns46LS7af3quUOmw6Gib8Z e/01aJffI1N7tGl1H4Ezc3dXhTBGjOHdrOyA/sMibI5m0puVxjO4OcEMQRe2Gcy3DvTO Ug/ZNxeb440UNdfQmf955RTvJFomopIbdnpFBZ81MxQ2c6c1lTa1AmJdtV4WrSaXeR+L YqdA== 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 b91si1387044plb.819.2017.10.31.04.56.36; Tue, 31 Oct 2017 04:56:36 -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 S1752088AbdJaL4f (ORCPT + 27 others); Tue, 31 Oct 2017 07:56:35 -0400 Received: from foss.arm.com ([217.140.101.70]:34750 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750872AbdJaL4a (ORCPT ); Tue, 31 Oct 2017 07:56:30 -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 4E74B1435; Tue, 31 Oct 2017 04:56:30 -0700 (PDT) Received: from sugar.kfn.arm.com (unknown [10.45.48.167]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6182F3F483; Tue, 31 Oct 2017 04:56:27 -0700 (PDT) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] staging: ccree: copy IV to DMAable memory Date: Tue, 31 Oct 2017 11:56:15 +0000 Message-Id: <1509450978-17784-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509450978-17784-1-git-send-email-gilad@benyossef.com> References: <1509450978-17784-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are being passed an IV buffer from unknown origin, which may be stack allocated and thus not safe for DMA. Allocate a DMA safe buffer for the IV and use that instead. Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_cipher.c | 16 ++++++++++++++-- drivers/staging/ccree/ssi_cipher.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 78706f5..0784c86 100644 --- a/drivers/staging/ccree/ssi_cipher.c +++ b/drivers/staging/ccree/ssi_cipher.c @@ -695,6 +695,7 @@ static int ssi_blkcipher_complete(struct device *dev, struct ablkcipher_request *req = (struct ablkcipher_request *)areq; ssi_buffer_mgr_unmap_blkcipher_request(dev, req_ctx, ivsize, src, dst); + kfree(req_ctx->iv); /*Decrease the inflight counter*/ if (ctx_p->flow_mode == BYPASS && ctx_p->drvdata->inflight_counter > 0) @@ -757,6 +758,13 @@ static int ssi_blkcipher_process( rc = 0; goto exit_process; } + + /* The IV we are handed may be allocted from the stack so + * we must copy it to a DMAable buffer before use. + */ + req_ctx->iv = kmalloc(ivsize, GFP_KERNEL); + memcpy(req_ctx->iv, info, ivsize); + /*For CTS in case of data size aligned to 16 use CBC mode*/ if (((nbytes % AES_BLOCK_SIZE) == 0) && (ctx_p->cipher_mode == DRV_CIPHER_CBC_CTS)) { ctx_p->cipher_mode = DRV_CIPHER_CBC; @@ -778,7 +786,9 @@ static int ssi_blkcipher_process( /* STAT_PHASE_1: Map buffers */ - rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, ivsize, nbytes, info, src, dst); + rc = ssi_buffer_mgr_map_blkcipher_request(ctx_p->drvdata, req_ctx, + ivsize, nbytes, req_ctx->iv, + src, dst); if (unlikely(rc != 0)) { dev_err(dev, "map_request() failed\n"); goto exit_process; @@ -830,8 +840,10 @@ static int ssi_blkcipher_process( if (cts_restore_flag != 0) ctx_p->cipher_mode = DRV_CIPHER_CBC_CTS; - if (rc != -EINPROGRESS) + if (rc != -EINPROGRESS) { kfree(req_ctx->backup_info); + kfree(req_ctx->iv); + } return rc; } diff --git a/drivers/staging/ccree/ssi_cipher.h b/drivers/staging/ccree/ssi_cipher.h index f499962..25e6335 100644 --- a/drivers/staging/ccree/ssi_cipher.h +++ b/drivers/staging/ccree/ssi_cipher.h @@ -43,6 +43,7 @@ struct blkcipher_req_ctx { u32 out_nents; u32 out_mlli_nents; u8 *backup_info; /*store iv for generated IV flow*/ + u8 *iv; bool is_giv; struct mlli_params mlli_params; };