From patchwork Thu Nov 2 08:10:21 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: 117759 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1746251edm; Thu, 2 Nov 2017 01:12:02 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R973VN2b0Pu/6MbA+Gvxdko8cMH40IgduWs5gGlDEpx4kC5jtpgn69cuMZ33yLSf30cU44 X-Received: by 10.84.224.200 with SMTP id k8mr2399669pln.403.1509610321846; Thu, 02 Nov 2017 01:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509610321; cv=none; d=google.com; s=arc-20160816; b=BtPQ9coYvglRnEAo6DAvUBE1R6B3W9bPIj0F0AxBO6V08NHXrdqr2/D3QFGGHrPpLp FLRBj0Thx+HvbRr64wrMXVqDrZ1K1xkHpzzhxMgmsQak6s306jiwprfWLB7zH7AShtXs oz5CxbT2qhnGt2Dtb9MuAR2T8L7tbqhjcnE0AaAkNi73h3EvJMDzelxJW/EK8xhmuyFz GRlgXdyA1+wIsVg58k1D9XArs+dXGsoofYDzL+nYazKtIIHob8kzB698L4p9pvQqvPj7 G5d9SyWbBvSE7lbrHbuOanemUVLkOZVr+pH3V0qUUmgQmDQqqutxafxYC+BgIUIdg13s XDTg== 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=z7iIpuGcet01SlxaATsjvbt4+s9df2izgYYQcmLtqfA=; b=xLd+R2YKOcqvfry2hPkgUsrceRD3kt+zIbgJ8dsq6mSfRtPKTtJ8fTvYnRgNjC7b6a kWnzvuMQ7Q/7xMMfO/HHZjLrVALnw2rB0qOVYFXMdyO74Gijn5ZCghBLDeP34zgqml44 pGFQx5DaD2e6Ae+xmB0w7yVQRXLtkK1dujvs2TX4nibatY1lTmdeuqtFPceUKGRsmyAB tVylXxeo2ZyqZ8MgNo75xuNNUbU+zTWFAJxxpRVCI9A5SYJEY350hRNHxvh1DxYi7tVm Zqk5ZiA0K8OJR+aJIv0csEYanSs9LFUW/n/3UlsRBP9WHRXiBcidxgvHJSlh2dBZjdxG oI7g== 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 s10si3119470pgd.559.2017.11.02.01.12.01; Thu, 02 Nov 2017 01:12:01 -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 S1755362AbdKBIL7 (ORCPT + 26 others); Thu, 2 Nov 2017 04:11:59 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55736 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755436AbdKBIKe (ORCPT ); Thu, 2 Nov 2017 04:10:34 -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 4BD351529; Thu, 2 Nov 2017 01:10:34 -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 ABA543F483; Thu, 2 Nov 2017 01:10:32 -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 v2 1/3] staging: ccree: copy IV to DMAable memory Date: Thu, 2 Nov 2017 08:10:21 +0000 Message-Id: <1509610224-14708-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509610224-14708-1-git-send-email-gilad@benyossef.com> References: <1509610224-14708-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 | 20 ++++++++++++++++++-- drivers/staging/ccree/ssi_cipher.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_cipher.c b/drivers/staging/ccree/ssi_cipher.c index 78706f5..0b69103 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,17 @@ 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); + if (!req_ctx->iv) { + rc = -ENOMEM; + goto exit_process; + } + 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 +790,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 +844,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; };