From patchwork Thu Oct 27 12:25:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 687580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3t4R1h4pv4z9t1C; Thu, 27 Oct 2016 23:25:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b=uIMX1E4Y; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1bzjka-0006Ky-Rb; Thu, 27 Oct 2016 12:25:40 +0000 Received: from mail-qk0-f181.google.com ([209.85.220.181]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1bzjkU-0006Km-VP for kernel-team@lists.ubuntu.com; Thu, 27 Oct 2016 12:25:35 +0000 Received: by mail-qk0-f181.google.com with SMTP id z190so40940811qkc.2 for ; Thu, 27 Oct 2016 05:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=I+818JesEUupoSPl+isvGMe9Ezz0XAXBQzhk5VUgM9g=; b=uIMX1E4Y6pHRN8UeA8G0+QjaYMa4TCTlHoz+fM425/3WGRHElYTcKaGzIKEkBdZC+a CCnuZkQULUMR8ryswGQfFpxdEaiMf59tpqTaCl1TduUEkSR+nQVKMNF+Quyvt0i1THC4 lZog9Jt0187ooGeU5Mthe1VGxkf+IXSvlIomjxKrMLk/ONVDwNReOnfjajZ+IL86/+L1 Nqv9uqhj/3SBrCWP0oyQSam5NNM2OVcmmvSf9W3avVz44F/agiXam/ubNtadBpiI85XD prRUxOk3+WMR8jmAtXapT16iyo9fwOeCqdriIYPievaXZzoCLHN6qQLQ+7fG18KXvdKX AMSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=I+818JesEUupoSPl+isvGMe9Ezz0XAXBQzhk5VUgM9g=; b=PIGgWsZ7sA+uuGg6aTuHgfUdprozRQy2Nl4eho+pAFsRbP+KMmoov7vZrB9NqQGhM4 B3rTVMyTTsUUjsjdcCGZO5SjO3OyYffhZcGUP/ZcLpqc2rNC0luht/SZznaLlhVOzrKu g80fvAuvJTrQ5rPmATeIv9AViH6oBMSvWXjZckR2VpccuZ3uOIAt3roJi6eGJaK6jYej 3yT9OL/s0u99TL38YSc7D3q1qHcpjxgMzvJPX/ixYpxwjYvjDtXQ8/nZD7/neuPw2pdv mkb16vrmCAJFBNlwDvrJczVBNqC1Y1n5EKipo9pVbcdxxu1ifovahSUn7DJwIFUQMW9M IFUw== X-Gm-Message-State: ABUngvfgiAMdO125mCVB8Jplk31HXrKVvSgMYIK9sSIXEcWRlazF6YmZpSpHXjPz7isiD2AG X-Received: by 10.55.141.65 with SMTP id p62mr5990127qkd.301.1477571133529; Thu, 27 Oct 2016 05:25:33 -0700 (PDT) Received: from localhost.localdomain ([189.79.179.176]) by smtp.gmail.com with ESMTPSA id u44sm3489436qtu.5.2016.10.27.05.25.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Oct 2016 05:25:32 -0700 (PDT) From: Marcelo Cerri To: kernel-team@lists.ubuntu.com Subject: [Xenial][PATCH 1/2] crypto: sha-mb - Fix load failure Date: Thu, 27 Oct 2016 10:25:25 -0200 Message-Id: <1477571126-15915-1-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Wang, Rui Y BugLink: https://bugs.launchpad.net/bugs/1637165 On Monday, February 1, 2016 4:18 PM, Herbert Xu wrote: > > On Wed, Jan 27, 2016 at 05:08:35PM +0800, Rui Wang wrote: >> >> +static int sha1_mb_async_import(struct ahash_request *req, const void >> +*in) { >> + struct ahash_request *mcryptd_req = ahash_request_ctx(req); >> + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); >> + struct sha1_mb_ctx *ctx = crypto_ahash_ctx(tfm); >> + struct mcryptd_ahash *mcryptd_tfm = ctx->mcryptd_tfm; >> + struct crypto_shash *child = mcryptd_ahash_child(mcryptd_tfm); >> + struct mcryptd_hash_request_ctx *rctx; >> + struct shash_desc *desc; >> + int err; >> + >> + memcpy(mcryptd_req, req, sizeof(*req)); >> + ahash_request_set_tfm(mcryptd_req, &mcryptd_tfm->base); >> + rctx = ahash_request_ctx(mcryptd_req); >> + desc = &rctx->desc; >> + desc->tfm = child; >> + desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; >> + >> + err = crypto_shash_init(desc); >> + if (err) >> + return err; > > What is this desc for? Hi Herbert, Yeah I just realized that the call to crypto_shash_init() isn't necessary here. What it does is overwritten by crypto_ahash_import(). But this desc still needs to be initialized here because it's newly allocated by ahash_request_alloc(). We eventually calls the shash version of import() which needs desc as an argument. The real context to be imported is then derived from shash_desc_ctx(desc). desc is a sub-field of struct mcryptd_hash_request_ctx, which is again a sub-field of the bigger blob allocated by ahash_request_alloc(). The entire blob's size is set in sha1_mb_async_init_tfm(). So a better version is as follows: (just removed the call to crypto_shash_init()) >From 4bcb73adbef99aada94c49f352063619aa24d43d Mon Sep 17 00:00:00 2001 From: Rui Wang Date: Mon, 14 Dec 2015 17:22:13 +0800 Subject: [PATCH v2 1/4] crypto x86/sha1_mb: Fix load failure modprobe sha1_mb fails with the following message: modprobe: ERROR: could not insert 'sha1_mb': No such device It is because it needs to set its statesize and implement its import() and export() interface. v2: remove redundant call to crypto_shash_init() Signed-off-by: Rui Wang Signed-off-by: Herbert Xu (cherry picked from commit fd09967b830c9ed60f53f318ee67907803065c9c) Signed-off-by: Marcelo Cerri --- arch/x86/crypto/sha-mb/sha1_mb.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/x86/crypto/sha-mb/sha1_mb.c b/arch/x86/crypto/sha-mb/sha1_mb.c index 8381c09d..081255c 100644 --- a/arch/x86/crypto/sha-mb/sha1_mb.c +++ b/arch/x86/crypto/sha-mb/sha1_mb.c @@ -762,6 +762,38 @@ static int sha1_mb_async_digest(struct ahash_request *req) return crypto_ahash_digest(mcryptd_req); } +static int sha1_mb_async_export(struct ahash_request *req, void *out) +{ + struct ahash_request *mcryptd_req = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct sha1_mb_ctx *ctx = crypto_ahash_ctx(tfm); + struct mcryptd_ahash *mcryptd_tfm = ctx->mcryptd_tfm; + + memcpy(mcryptd_req, req, sizeof(*req)); + ahash_request_set_tfm(mcryptd_req, &mcryptd_tfm->base); + return crypto_ahash_export(mcryptd_req, out); +} + +static int sha1_mb_async_import(struct ahash_request *req, const void *in) +{ + struct ahash_request *mcryptd_req = ahash_request_ctx(req); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); + struct sha1_mb_ctx *ctx = crypto_ahash_ctx(tfm); + struct mcryptd_ahash *mcryptd_tfm = ctx->mcryptd_tfm; + struct crypto_shash *child = mcryptd_ahash_child(mcryptd_tfm); + struct mcryptd_hash_request_ctx *rctx; + struct shash_desc *desc; + + memcpy(mcryptd_req, req, sizeof(*req)); + ahash_request_set_tfm(mcryptd_req, &mcryptd_tfm->base); + rctx = ahash_request_ctx(mcryptd_req); + desc = &rctx->desc; + desc->tfm = child; + desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP; + + return crypto_ahash_import(mcryptd_req, in); +} + static int sha1_mb_async_init_tfm(struct crypto_tfm *tfm) { struct mcryptd_ahash *mcryptd_tfm; @@ -796,8 +828,11 @@ static struct ahash_alg sha1_mb_async_alg = { .final = sha1_mb_async_final, .finup = sha1_mb_async_finup, .digest = sha1_mb_async_digest, + .export = sha1_mb_async_export, + .import = sha1_mb_async_import, .halg = { .digestsize = SHA1_DIGEST_SIZE, + .statesize = sizeof(struct sha1_hash_ctx), .base = { .cra_name = "sha1", .cra_driver_name = "sha1_mb",