Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2554459ybv; Mon, 24 Feb 2020 07:19:37 -0800 (PST) X-Google-Smtp-Source: APXvYqwI6wdmii7OBMWCVXA1e5PEjyOkTTQOUicnY8gQCRoOoBkAiabkk7arAX1IODknunnYr5OQ X-Received: by 2002:a9d:6184:: with SMTP id g4mr38203260otk.223.1582557577458; Mon, 24 Feb 2020 07:19:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582557577; cv=none; d=google.com; s=arc-20160816; b=PUmztpyp6YDfa/2vtQadqOQB3drydbfg8JmMk5m6JOgqKmXNNop5kYrwDViN+A3Q9B 6xgKG7Q8P/v8MdTP/XWplh5/i3A/3jLkDDMS3MmQJzzULodM1wgRn0XrD2ueGY2MKyh2 RY+tXEoq8B45uaXJcWMIf8IWQmhOuxbRf25svFxg3NXmV+kF4S9wwBEcWJu9QrF6DU9d QzCFTNqXMudLEwLhj3bRSLhNYfTtXNGRyPCxOEQwCAKg/djIYAPDwomioJYpo1Ni83EX pcjCKwwEto+hf6/TS2+us/JvLzaN0bSzqBmRXRKCagE0j5MFIJprK4hq6fbSCEdenJQX QFdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=p4JyKYMLcjkuhV880m1VVxSJ3o0/QSXYlmmHZLgGbBs=; b=N7srY+AGW7iCQ3N18ZWpDoPn6+JTZctDt7i2hmSjc6dup2Din+/65hFXvSub2fGqGj 8ZNJDAJTe3KNuZJoFA6leTiTRgfsdkp4RfgLNI+yodOCPBTBGYrkvIIcq3FaM7IXFw9P NjpEbNfYS7/IIV7LWuBvfnGNEtHO1BoJNeLO/tgWfNB8TqagbYVleVPR9+bEPUo9uWyi BdNldDYexdJ9qCgx7aIbJJrnqwl4zcPDtjNd/tHRWdHeF/65eS2Qo/Kj7mLlvCoXtNeE T1tmm+SZJIGYpR0mG79uY/JGPe6qdmpBs6paYMxTjVCTHxJo2jD8hhrlsVI1Y7qDB1uI 33pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UQK3K2Gl; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m82si5048693oig.129.2020.02.24.07.19.18; Mon, 24 Feb 2020 07:19:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@linaro.org header.s=google header.b=UQK3K2Gl; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727448AbgBXPTO (ORCPT + 99 others); Mon, 24 Feb 2020 10:19:14 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35321 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727730AbgBXPTN (ORCPT ); Mon, 24 Feb 2020 10:19:13 -0500 Received: by mail-wm1-f68.google.com with SMTP id b17so9825009wmb.0 for ; Mon, 24 Feb 2020 07:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=p4JyKYMLcjkuhV880m1VVxSJ3o0/QSXYlmmHZLgGbBs=; b=UQK3K2Gl/itI8chGjYgrXBownF6wnW9i5V2SNuFZs/dNrGM09ZLSX64aMdnnzAgutA oKrfRbKXeF9+zXYd6vTkLgovyaOd/UvfhCcK2jz4u67rgtx3i7C5MF6xQmeeu8mLXw3T V/RfAUDa17bi8dtDDSuyWYIJs9Vo3e2Jjxg/tRAMlouup31lB5OU/n0CDDCpeg4bTO// RHbtjC8qHrmaa+oZzOgOG39hq5X36XK4oq/suw3ucXjuzlJMRpF88FmRjITsJO82QOZR sU7dYEbon/yAkTxssRVtqgRGXVGB13EW77sbti1/nnUn+Xk3rwiIg2iC2ahSTFPqaABV JHWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p4JyKYMLcjkuhV880m1VVxSJ3o0/QSXYlmmHZLgGbBs=; b=B2IP5+vWVzIIBJALbln8s0lMM+xaSVDT113Yt8IPnyRAR77FWKvQYkU9VHkm83wGqV 7+k6B0crTtdxBuvzTNvs0SR3n9Lk0DaPxp3Isdop+qiUV4jgX0aJTqao7EfZOVNutm8o ZoXXHCn3o0rElQgBBIT9darspdT1lAgM8liS1VnAXMHjSyplVdZyemCtdE9IMzfaWsNU /4aI6hgdYj10E6i0xNFpc+80bk+QeHgGHu2/adjtvosaSQ9A8f9VYBy8bCJZ/66tr9r8 3UGi1ttyRPBHGMS1sN+dIfiqvNWjv8WnVQkqOlyFUmIPHQc/mU4y9hfR7JdEJx+OB2Iz pG/g== X-Gm-Message-State: APjAAAW5BELYWf32NX3uHWHOeq0RpxVZ5lY/IAM2ZqTuVkFvmOBP8gOP GJBgX6uFx3Qyy/7r0AdiCeShMbpDKCRxh6PIDle/itA7dhI= X-Received: by 2002:a1c:282:: with SMTP id 124mr21977917wmc.62.1582557549834; Mon, 24 Feb 2020 07:19:09 -0800 (PST) MIME-Version: 1.0 References: <1582555661-25737-1-git-send-email-clabbe@baylibre.com> In-Reply-To: <1582555661-25737-1-git-send-email-clabbe@baylibre.com> From: Ard Biesheuvel Date: Mon, 24 Feb 2020 16:18:58 +0100 Message-ID: Subject: Re: [PATCH v2] crypto: arm64: CE: implement export/import To: Corentin Labbe Cc: Catalin Marinas , "David S. Miller" , Herbert Xu , Will Deacon , Eric Biggers , linux-arm-kernel , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, 24 Feb 2020 at 15:47, Corentin Labbe wrote: > > When an ahash algorithm fallback to another ahash and that fallback is > shaXXX-CE, doing export/import lead to error like this: > alg: ahash: sha1-sun8i-ce export() overran state buffer on test vector 0, cfg=\"import/export\" > > This is due to the descsize of shaxxx-ce being larger than struct shaxxx_state > off by an u32. > For fixing this, let's implement export/import which rip the finalize > variant instead of using generic export/import. > > Fixes: 6ba6c74dfc6b ("arm64/crypto: SHA-224/SHA-256 using ARMv8 Crypto Extensions") > Fixes: 2c98833a42cd ("arm64/crypto: SHA-1 using ARMv8 Crypto Extensions") > > Signed-off-by: Corentin Labbe Reviewed-by: Ard Biesheuvel > --- > Changes since v1: > - memcpy directly &sctx->sst instead of sctx. As suggested by Eric Biggers > > arch/arm64/crypto/sha1-ce-glue.c | 20 ++++++++++++++++++++ > arch/arm64/crypto/sha2-ce-glue.c | 23 +++++++++++++++++++++++ > 2 files changed, 43 insertions(+) > > diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c > index 63c875d3314b..565ef604ca04 100644 > --- a/arch/arm64/crypto/sha1-ce-glue.c > +++ b/arch/arm64/crypto/sha1-ce-glue.c > @@ -91,12 +91,32 @@ static int sha1_ce_final(struct shash_desc *desc, u8 *out) > return sha1_base_finish(desc, out); > } > > +static int sha1_ce_export(struct shash_desc *desc, void *out) > +{ > + struct sha1_ce_state *sctx = shash_desc_ctx(desc); > + > + memcpy(out, &sctx->sst, sizeof(struct sha1_state)); > + return 0; > +} > + > +static int sha1_ce_import(struct shash_desc *desc, const void *in) > +{ > + struct sha1_ce_state *sctx = shash_desc_ctx(desc); > + > + memcpy(&sctx->sst, in, sizeof(struct sha1_state)); > + sctx->finalize = 0; > + return 0; > +} > + > static struct shash_alg alg = { > .init = sha1_base_init, > .update = sha1_ce_update, > .final = sha1_ce_final, > .finup = sha1_ce_finup, > + .import = sha1_ce_import, > + .export = sha1_ce_export, > .descsize = sizeof(struct sha1_ce_state), > + .statesize = sizeof(struct sha1_state), > .digestsize = SHA1_DIGEST_SIZE, > .base = { > .cra_name = "sha1", > diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c > index a8e67bafba3d..9450d19b9e6e 100644 > --- a/arch/arm64/crypto/sha2-ce-glue.c > +++ b/arch/arm64/crypto/sha2-ce-glue.c > @@ -109,12 +109,32 @@ static int sha256_ce_final(struct shash_desc *desc, u8 *out) > return sha256_base_finish(desc, out); > } > > +static int sha256_ce_export(struct shash_desc *desc, void *out) > +{ > + struct sha256_ce_state *sctx = shash_desc_ctx(desc); > + > + memcpy(out, &sctx->sst, sizeof(struct sha256_state)); > + return 0; > +} > + > +static int sha256_ce_import(struct shash_desc *desc, const void *in) > +{ > + struct sha256_ce_state *sctx = shash_desc_ctx(desc); > + > + memcpy(&sctx->sst, in, sizeof(struct sha256_state)); > + sctx->finalize = 0; > + return 0; > +} > + > static struct shash_alg algs[] = { { > .init = sha224_base_init, > .update = sha256_ce_update, > .final = sha256_ce_final, > .finup = sha256_ce_finup, > + .export = sha256_ce_export, > + .import = sha256_ce_import, > .descsize = sizeof(struct sha256_ce_state), > + .statesize = sizeof(struct sha256_state), > .digestsize = SHA224_DIGEST_SIZE, > .base = { > .cra_name = "sha224", > @@ -128,7 +148,10 @@ static struct shash_alg algs[] = { { > .update = sha256_ce_update, > .final = sha256_ce_final, > .finup = sha256_ce_finup, > + .export = sha256_ce_export, > + .import = sha256_ce_import, > .descsize = sizeof(struct sha256_ce_state), > + .statesize = sizeof(struct sha256_state), > .digestsize = SHA256_DIGEST_SIZE, > .base = { > .cra_name = "sha256", > -- > 2.24.1 >