Skip to contentSkip to conversation

SHASH_DESC_ON_STACK macro

RFC In review Gustavo A. R. Silva 2 participants 4 messages Mar 21, 2018 – Apr 5, 2018 Crypto API

lore
Share & tools
lore
#0 lore raw

Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and while working on that I came across the following macro at include/crypto/hash.h:154:

#define SHASH_DESC_ON_STACK(shash, ctx)                           \
        char __##shash##_desc[sizeof(struct shash_desc) +         \
                crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
        struct shash_desc *shash = (struct shash_desc *)__##shash##_desc

Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

Do you think it is feasible to replace the call to crypto_shash_descsize with a constant value and get rid of 46 VLA warnings?

I have sent some patches to replace the use of this macro with dynamic memory allocation instead, but it seems that this is not a suitable solution for all cases due to performance issues.

[1] https://lkml.org/lkml/2018/3/7/621

I'd really appreciate any feedback.
Thanks
--
Gustavo

#1 lore raw

PATCH RESEND 1/1 SHASH_DESC_ON_STACK macro

Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and while working on that I came across the following macro at include/crypto/hash.h:154:

#define SHASH_DESC_ON_STACK(shash, ctx)                           \
        char __##shash##_desc[sizeof(struct shash_desc) +         \
                crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
        struct shash_desc *shash = (struct shash_desc *)__##shash##_desc

Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

Do you think it is feasible to replace the call to crypto_shash_descsize with a constant value and get rid of 46 VLA warnings?

I have sent some patches to replace the use of this macro with dynamic memory allocation instead, but it seems that this is not a suitable solution for all cases due to performance issues.

[1] https://lkml.org/lkml/2018/3/7/621

I'd really appreciate any feedback.
Thanks
--
Gustavo

maintainer
#2 lore raw
Quoted 13 lines · Gustavo A. R. Silva

Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and while working on that I came across the following macro at include/crypto/hash.h:154:

#define SHASH_DESC_ON_STACK(shash, ctx)                           \
        char __##shash##_desc[sizeof(struct shash_desc) +         \
                crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
        struct shash_desc *shash = (struct shash_desc *)__##shash##_desc
Quoted 3 lines

Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

descsize is capped at PAGE_SIZE / 8.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw

Hi Herbert,

Quoted 14 lines · Herbert Xu
Quoted 13 lines · Gustavo A. R. Silva

Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and while working on that I came across the following macro at include/crypto/hash.h:154:

#define SHASH_DESC_ON_STACK(shash, ctx)                           \
         char __##shash##_desc[sizeof(struct shash_desc) +         \
                 crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
         struct shash_desc *shash = (struct shash_desc *)__##shash##_desc
Quoted 6 lines
Quoted 3 lines

Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

descsize is capped at PAGE_SIZE / 8.

Sorry for the late response. It seems I lost track of this email somehow.

OK. So based on your response I will propose a patch for this.

Thanks!
--
Gustavo