From patchwork Thu Apr 19 16:41:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 10351315 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 385256023A for ; Thu, 19 Apr 2018 16:42:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28C8C1FEBA for ; Thu, 19 Apr 2018 16:42:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D8D31FF60; Thu, 19 Apr 2018 16:42:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 435791FEBA for ; Thu, 19 Apr 2018 16:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753948AbeDSQmG (ORCPT ); Thu, 19 Apr 2018 12:42:06 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:39927 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753681AbeDSQmD (ORCPT ); Thu, 19 Apr 2018 12:42:03 -0400 Received: by mail-wr0-f195.google.com with SMTP id q3-v6so5748634wrj.6 for ; Thu, 19 Apr 2018 09:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=gFoe6tEsUBDvGlBH1LmdWW769LQSX0c8kNBvd/TRG8c=; b=sd0DWSBg3/A5eEHIT63fpD4WMFbTiQm1RQ9sBWdFc53+bixl5gnhWuWmNkrZ3GFbM+ fWG5jSVeSogF5iJIndUuiGSco6M736EGWqDgs20rH99sdoUvDsSD0pi7fi6wNb1rJ4pd 5qTgmSjAjOLMiQ6kpCqjEdRf0SBU4NRLtZNSAbuHGVeSWI40yrrpAnZ50JGnhOaNKqSV pbGOEkY3c+LXvSMJKUMC+lIMDrbJO93NenuyYONDQNScfA8vw4V7jBF1Rg4JQt79a6gj +iybhF/f07vreYvhh/BfvW1X94Gi9I8NVhvPoOD+eVva+5/9MLA8l6thPUnh5H9qDitd bhyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=gFoe6tEsUBDvGlBH1LmdWW769LQSX0c8kNBvd/TRG8c=; b=YTYPznRO1BCp3Y1oz1keBQGB89tpYLAyZBebqNEQttCtrXAa59eaHkxDz5vcQ2LMZ/ OcjzZwITIFG6Vg+X66DfZtQfrvgfsJa1dg1bLn/zatExxXqNpXuVlyVVellxjSUP05K2 sk9Cqa3S0r8/Q26YNVMUf7r2piATu7uoLRy7eS7muLEYi4Ds/yv1eRthCQClq08JkG02 YemnTOdm1XMRPqyAozBxMhZJ0Pu31fVN/S7A6rlUUbYSpLm0PQp5gF2lWqXGsuIgEkBz Rbs9P9LpK1gR4L0px5QNtKl260zoSrgDEP8S8ViOkZBUKZbZRRMtQYgK1lgUwfmDgETa cHlg== X-Gm-Message-State: ALQs6tBEW97DtAs8uxh/Mjl2prrEl626kPKgWVTArBvkwQ/1xelpFhks USZZN7N/Cli+9kFUdyYjNgkFslLo X-Google-Smtp-Source: AIpwx499IMl+FnBYe40xERzdiaPSHddV1Ofeejl3dYDVzh1+z6s9ErAOdoBOn5tMCFlP55avaGOXaw== X-Received: by 2002:adf:bb0d:: with SMTP id r13-v6mr2758134wrg.201.1524156121784; Thu, 19 Apr 2018 09:42:01 -0700 (PDT) Received: from debian64.daheim (p200300D5FBC3D8FC0000000000000830.dip0.t-ipconnect.de. [2003:d5:fbc3:d8fc::830]) by smtp.gmail.com with ESMTPSA id p33-v6sm6238331wrc.14.2018.04.19.09.41.58 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Apr 2018 09:42:00 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.90_1) (envelope-from ) id 1f9CdC-00027Q-7O for linux-crypto@vger.kernel.org; Thu, 19 Apr 2018 18:41:58 +0200 From: Christian Lamparter To: linux-crypto@vger.kernel.org Subject: [PATCH v1 7/7] crypto: crypto4xx - put temporary dst sg into request ctx Date: Thu, 19 Apr 2018 18:41:57 +0200 Message-Id: <398e5c5c9e9a9e0d6e9f439e2e1f5260a01c747f.1524156017.git.chunkeey@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes a crash that happens when testing rfc4543(gcm(aes)) Unable to handle kernel paging request for data at address 0xf59b3420 Faulting instruction address: 0xc0012994 Oops: Kernel access of bad area, sig: 11 [#1] BE PowerPC 44x Platform Modules linked in: tcrypt(+) crypto4xx [...] CPU: 0 PID: 0 Comm: swapper Tainted: G O 4.17.0-rc1+ #23 NIP: c0012994 LR: d3077934 CTR: 06026d49 REGS: cfff7e30 TRAP: 0300 Tainted: G O (4.17.0-rc1+) MSR: 00029000 CR: 44744822 XER: 00000000 DEAR: f59b3420 ESR: 00000000 NIP [c0012994] __dma_sync+0x58/0x10c LR [d3077934] crypto4xx_bh_tasklet_cb+0x188/0x3c8 [crypto4xx] __dma_sync was fed the temporary _dst that crypto4xx_build_pd() had in it's function stack. This clearly never worked. This patch therefore overhauls the code from the original driver and puts the temporary dst sg list into aead's request context. Fixes: a0aae821ba3d3 ("crypto: crypto4xx - prepare for AEAD support") Signed-off-by: Christian Lamparter --- drivers/crypto/amcc/crypto4xx_alg.c | 15 ++++++++------- drivers/crypto/amcc/crypto4xx_core.c | 10 +++++----- drivers/crypto/amcc/crypto4xx_core.h | 7 ++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/crypto/amcc/crypto4xx_alg.c b/drivers/crypto/amcc/crypto4xx_alg.c index c952bcfdd6ae..f5c07498ea4f 100644 --- a/drivers/crypto/amcc/crypto4xx_alg.c +++ b/drivers/crypto/amcc/crypto4xx_alg.c @@ -87,7 +87,7 @@ static inline int crypto4xx_crypt(struct skcipher_request *req, return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, req->cryptlen, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out, - ctx->sa_len, 0); + ctx->sa_len, 0, NULL); } int crypto4xx_encrypt_noiv(struct skcipher_request *req) @@ -223,7 +223,7 @@ int crypto4xx_rfc3686_encrypt(struct skcipher_request *req) return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, req->cryptlen, iv, AES_IV_SIZE, - ctx->sa_out, ctx->sa_len, 0); + ctx->sa_out, ctx->sa_len, 0, NULL); } int crypto4xx_rfc3686_decrypt(struct skcipher_request *req) @@ -238,7 +238,7 @@ int crypto4xx_rfc3686_decrypt(struct skcipher_request *req) return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, req->cryptlen, iv, AES_IV_SIZE, - ctx->sa_out, ctx->sa_len, 0); + ctx->sa_out, ctx->sa_len, 0, NULL); } static int @@ -449,6 +449,7 @@ int crypto4xx_setkey_aes_ccm(struct crypto_aead *cipher, const u8 *key, static int crypto4xx_crypt_aes_ccm(struct aead_request *req, bool decrypt) { struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); + struct crypto4xx_aead_reqctx *rctx = aead_request_ctx(req); struct crypto_aead *aead = crypto_aead_reqtfm(req); __le32 iv[16]; u32 tmp_sa[SA_AES128_CCM_LEN + 4]; @@ -474,7 +475,7 @@ static int crypto4xx_crypt_aes_ccm(struct aead_request *req, bool decrypt) return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, len, iv, sizeof(iv), - sa, ctx->sa_len, req->assoclen); + sa, ctx->sa_len, req->assoclen, rctx->dst); } int crypto4xx_encrypt_aes_ccm(struct aead_request *req) @@ -622,7 +623,7 @@ static inline int crypto4xx_crypt_aes_gcm(struct aead_request *req, return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, len, iv, sizeof(iv), decrypt ? ctx->sa_in : ctx->sa_out, - ctx->sa_len, req->assoclen); + ctx->sa_len, req->assoclen, rctx->dst); } int crypto4xx_encrypt_aes_gcm(struct aead_request *req) @@ -707,7 +708,7 @@ int crypto4xx_hash_update(struct ahash_request *req) return crypto4xx_build_pd(&req->base, ctx, req->src, &dst, req->nbytes, NULL, 0, ctx->sa_in, - ctx->sa_len, 0); + ctx->sa_len, 0, NULL); } int crypto4xx_hash_final(struct ahash_request *req) @@ -726,7 +727,7 @@ int crypto4xx_hash_digest(struct ahash_request *req) return crypto4xx_build_pd(&req->base, ctx, req->src, &dst, req->nbytes, NULL, 0, ctx->sa_in, - ctx->sa_len, 0); + ctx->sa_len, 0, NULL); } /** diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c index 605398c89ccd..9cb234c72549 100644 --- a/drivers/crypto/amcc/crypto4xx_core.c +++ b/drivers/crypto/amcc/crypto4xx_core.c @@ -695,9 +695,9 @@ int crypto4xx_build_pd(struct crypto_async_request *req, const __le32 *iv, const u32 iv_len, const struct dynamic_sa_ctl *req_sa, const unsigned int sa_len, - const unsigned int assoclen) + const unsigned int assoclen, + struct scatterlist *_dst) { - struct scatterlist _dst[2]; struct crypto4xx_device *dev = ctx->dev; struct dynamic_sa_ctl *sa; struct ce_gd *gd; @@ -996,9 +996,9 @@ static int crypto4xx_aead_init(struct crypto_aead *tfm) amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.aead); crypto4xx_ctx_init(amcc_alg, ctx); - crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) + - max(sizeof(struct crypto4xx_ctx), 32 + - crypto_aead_reqsize(ctx->sw_cipher.aead))); + crypto_aead_set_reqsize(tfm, max(sizeof(struct aead_request) + 32 + + crypto_aead_reqsize(ctx->sw_cipher.aead), + sizeof(struct crypto4xx_aead_reqctx))); return 0; } diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h index 279f650c4f1c..e2ca56722f07 100644 --- a/drivers/crypto/amcc/crypto4xx_core.h +++ b/drivers/crypto/amcc/crypto4xx_core.h @@ -133,6 +133,10 @@ struct crypto4xx_ctx { } sw_cipher; }; +struct crypto4xx_aead_reqctx { + struct scatterlist dst[2]; +}; + struct crypto4xx_alg_common { u32 type; union { @@ -159,7 +163,8 @@ int crypto4xx_build_pd(struct crypto_async_request *req, const __le32 *iv, const u32 iv_len, const struct dynamic_sa_ctl *sa, const unsigned int sa_len, - const unsigned int assoclen); + const unsigned int assoclen, + struct scatterlist *dst_tmp); int crypto4xx_setkey_aes_cbc(struct crypto_skcipher *cipher, const u8 *key, unsigned int keylen); int crypto4xx_setkey_aes_cfb(struct crypto_skcipher *cipher,