On Tue, Jul 28, 2020 at 05:18:55PM +1000, Herbert Xu wrote:
> This patch initialises skcipher requests to zero.  This allows
> algorithms to distinguish between the first operation versus
> subsequent ones.
> 
> Signed-off-by: Herbert Xu <herb...@gondor.apana.org.au>
> ---
> 
>  include/crypto/skcipher.h |   18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
> index c46ea1c157b29..6db5f83d6e482 100644
> --- a/include/crypto/skcipher.h
> +++ b/include/crypto/skcipher.h
> @@ -129,13 +129,14 @@ struct skcipher_alg {
>   * This performs a type-check against the "tfm" argument to make sure
>   * all users have the correct skcipher tfm for doing on-stack requests.
>   */
> -#define SYNC_SKCIPHER_REQUEST_ON_STACK(name, tfm) \
> -     char __##name##_desc[sizeof(struct skcipher_request) + \
> -                          MAX_SYNC_SKCIPHER_REQSIZE + \
> -                          (!(sizeof((struct crypto_sync_skcipher *)1 == \
> -                                    (typeof(tfm))1))) \
> -                         ] CRYPTO_MINALIGN_ATTR; \
> -     struct skcipher_request *name = (void *)__##name##_desc
> +#define SYNC_SKCIPHER_REQUEST_ON_STACK(name, sync) \
> +     struct { \
> +             struct skcipher_request req; \
> +             char ext[MAX_SYNC_SKCIPHER_REQSIZE]; \
> +     } __##name##_desc = { \
> +             .req.base.tfm = crypto_skcipher_tfm(&sync->base), \
> +     }; \
> +     struct skcipher_request *name = &__##name##_desc.req
>  
>  /**
>   * DOC: Symmetric Key Cipher API
> @@ -519,8 +520,7 @@ static inline struct skcipher_request 
> *skcipher_request_alloc(
>  {
>       struct skcipher_request *req;
>  
> -     req = kmalloc(sizeof(struct skcipher_request) +
> -                   crypto_skcipher_reqsize(tfm), gfp);
> +     req = kzalloc(sizeof(*req) + crypto_skcipher_reqsize(tfm), gfp);
>  
>       if (likely(req))
>               skcipher_request_set_tfm(req, tfm);

Does this really work?  Some users allocate memory themselves without using
*_request_alloc().

- Eric

Reply via email to