Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1588571

Re: [PATCH 1/2] crypto: cbc - Propagate NEED_FALLBACK bit

From Herbert Xu <herbert@gondor.apana.org.au>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] crypto: cbc - Propagate NEED_FALLBACK bit
Date 2017-02-27 11:00 +0100
Message-ID <tfqg3-3L5-21@gated-at.bofh.it> (permalink)
References <tfhZ7-6sW-3@gated-at.bofh.it> <tfis9-6FQ-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, Feb 26, 2017 at 10:03:18PM -0300, Marcelo Henrique Cerri wrote:
> When requesting a fallback algorithm, we should propagate the
> NEED_FALLBACK bit when search for the underlying algorithm.
> 
> This will prevents drivers from allocating unnecessary fallbacks that
> are never called. For instance, currently the vmx-crypto driver will use
> the following chain of calls when calling the fallback implementation:
> 
> p8_aes_cbc -> cbc(p8_aes) -> aes-generic
> 
> However p8_aes will always delegate its calls to aes-generic. With this
> patch, p8_aes_cbc will be able to use cbc(aes-generic) directly as its
> fallback. The same applies to aes_s390.
> 
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
> ---
>  crypto/cbc.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/crypto/cbc.c b/crypto/cbc.c
> index bc160a3..7147842 100644
> --- a/crypto/cbc.c
> +++ b/crypto/cbc.c
> @@ -108,24 +108,32 @@ static void crypto_cbc_free(struct skcipher_instance *inst)
>  static int crypto_cbc_create(struct crypto_template *tmpl, struct rtattr **tb)
>  {
>  	struct skcipher_instance *inst;
> +	struct crypto_attr_type *algt;
>  	struct crypto_spawn *spawn;
>  	struct crypto_alg *alg;
> +	u32 mask;
>  	int err;
>  
>  	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER);
>  	if (err)
>  		return err;
>  
> +	algt = crypto_get_attr_type(tb);
> +	if (IS_ERR(algt))
> +		return PTR_ERR(algt);
> +
> +	mask = CRYPTO_ALG_TYPE_MASK |
> +		crypto_requires_off(algt->type, algt->mask,
> +				    CRYPTO_ALG_NEED_FALLBACK);
> +
> +	alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, mask);
> +	if (IS_ERR(alg))
> +		return PTR_ERR(alg);
> +
>  	inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
>  	if (!inst)
>  		return -ENOMEM;

You're leaking alg if the kzalloc of inst fails.  Easiest fix
would be to do crypto_get_attr_alg after the kzalloc as is the
status quo.

Thanks,
-- 
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

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] Propagate fallback bit for cbc and ctr Marcelo Henrique Cerri <marcelo.cerri@canonical.com> - 2017-02-27 02:10 +0100
  [PATCH 2/2] crypto: ctr - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri <marcelo.cerri@canonical.com> - 2017-02-27 02:10 +0100
  [PATCH 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Marcelo Henrique Cerri <marcelo.cerri@canonical.com> - 2017-02-27 02:40 +0100
    Re: [PATCH 1/2] crypto: cbc - Propagate NEED_FALLBACK bit Herbert Xu <herbert@gondor.apana.org.au> - 2017-02-27 11:00 +0100

csiph-web