linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Cerri <marcelo.cerri@canonical.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Harald Freudenberger <freude@linux.vnet.ibm.com>,
	linux-crypto@vger.kernel.org, schwidefsky@de.ibm.com
Subject: Re: crypto: hang in crypto_larval_lookup
Date: Sat, 25 Feb 2017 16:20:22 -0300	[thread overview]
Message-ID: <20170225192022.GA18004@gallifrey> (raw)
In-Reply-To: <20170225151707.GA28667@gondor.apana.org.au>

[-- Attachment #1: Type: text/plain, Size: 3093 bytes --]

On Sat, Feb 25, 2017 at 11:17:07PM +0800, Herbert Xu wrote:
> On Fri, Feb 24, 2017 at 08:44:00PM -0300, Marcelo Cerri wrote:
> >
> > This is probably caused by the way that the xts template is handling the
> > underline algorithm selection.
> 
> Good catch.  I think the bigger issue here is that when requesting
> for an XTS that doesn't need a fallback we shouldn't be using an
> underlying ECB that needs one.  So this patch should fix the hang.

Yeah, I agree. This should work as long as the module aliases are
correct, which is enough.

Other templates will not trigger the same error since they don't have to
try more than one underlying algorithm. But I think this is still
desirable for the remaining templates to avoid a long chain of unused
fallbacks as in the example I gave in my previous email.

Probably a helper function to return the correct mask might be useful
for readability and to avoid duplicate code.

> 
> Thanks,
> 
> ---8<---
> Subject: crypto: xts - Propagate NEED_FALLBACK bit
> 
> When we're used as a fallback algorithm, we should propagate
> the NEED_FALLBACK bit when searching for the underlying ECB mode.
> 
> This just happens to fix a hang too because otherwise the search
> may end up loading the same module that triggered this XTS creation.
> 
> Fixes: f1c131b45410 ("crypto: xts - Convert to skcipher")
> Reported-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/crypto/xts.c b/crypto/xts.c
> index 410a2e2..2066161 100644
> --- a/crypto/xts.c
> +++ b/crypto/xts.c
> @@ -463,6 +463,7 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
>  	struct xts_instance_ctx *ctx;
>  	struct skcipher_alg *alg;
>  	const char *cipher_name;
> +	u32 mask;
>  	int err;
>  
>  	algt = crypto_get_attr_type(tb);
> @@ -483,18 +484,19 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
>  	ctx = skcipher_instance_ctx(inst);
>  
>  	crypto_set_skcipher_spawn(&ctx->spawn, skcipher_crypto_instance(inst));
> -	err = crypto_grab_skcipher(&ctx->spawn, cipher_name, 0,
> -				   crypto_requires_sync(algt->type,
> -							algt->mask));
> +
> +	mask = crypto_requires_sync(algt->type, algt->mask) |
> +	       ((algt->type ^ CRYPTO_ALG_NEED_FALLBACK) & algt->mask &
> +	        CRYPTO_ALG_NEED_FALLBACK);
> +
> +	err = crypto_grab_skcipher(&ctx->spawn, cipher_name, 0, mask);
>  	if (err == -ENOENT) {
>  		err = -ENAMETOOLONG;
>  		if (snprintf(ctx->name, CRYPTO_MAX_ALG_NAME, "ecb(%s)",
>  			     cipher_name) >= CRYPTO_MAX_ALG_NAME)
>  			goto err_free_inst;
>  
> -		err = crypto_grab_skcipher(&ctx->spawn, ctx->name, 0,
> -					   crypto_requires_sync(algt->type,
> -								algt->mask));
> +		err = crypto_grab_skcipher(&ctx->spawn, ctx->name, 0, mask);
>  	}
>  
>  	if (err)
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

-- 
Regards,
Marcelo


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2017-02-25 19:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 17:50 crypto: hang in crypto_larval_lookup Harald Freudenberger
2017-02-23 11:19 ` Herbert Xu
2017-02-23 11:39   ` Herbert Xu
2017-02-23 16:02     ` Harald Freudenberger
2017-02-24  8:42       ` Harald Freudenberger
2017-02-24 10:32         ` Harald Freudenberger
2017-02-24 11:21           ` Harald Freudenberger
2017-02-24 23:44     ` Marcelo Cerri
2017-02-25 15:17       ` Herbert Xu
2017-02-25 19:20         ` Marcelo Cerri [this message]
2017-02-26  4:22           ` Herbert Xu
2017-02-26  4:24             ` [v2 PATCH] crypto: xts - Propagate NEED_FALLBACK bit Herbert Xu
2017-02-26 19:14             ` crypto: hang in crypto_larval_lookup Harald Freudenberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170225192022.GA18004@gallifrey \
    --to=marcelo.cerri@canonical.com \
    --cc=freude@linux.vnet.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=schwidefsky@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).