Skip to content

Commit a2d9cb3

Browse files
fishilicoFakeShell
authored andcommitted
apparmor: use SHASH_DESC_ON_STACK
When building the kernel with clang, the compiler fails to build security/apparmor/crypto.c with the following error: security/apparmor/crypto.c:36:8: error: fields must have a constant size: 'variable length array in structure' extension will never be supported char ctx[crypto_shash_descsize(apparmor_tfm)]; ^ Since commit a0a77af ("crypto: LLVMLinux: Add macro to remove use of VLAIS in crypto code"), include/crypto/hash.h defines SHASH_DESC_ON_STACK to work around this issue. Use it in aa_calc_hash() and aa_calc_profile_hash(). Signed-off-by: Nicolas Iooss <[email protected]> Signed-off-by: John Johansen <[email protected]> Signed-off-by: Alfred Neumayer <[email protected]>
1 parent 7f6d820 commit a2d9cb3

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

security/apparmor/crypto.c

+13-19
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ unsigned int aa_hash_size(void)
3131

3232
char *aa_calc_hash(void *data, size_t len)
3333
{
34-
struct {
35-
struct shash_desc shash;
36-
char ctx[crypto_shash_descsize(apparmor_tfm)];
37-
} desc;
34+
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
3835
char *hash = NULL;
3936
int error = -ENOMEM;
4037

@@ -45,16 +42,16 @@ char *aa_calc_hash(void *data, size_t len)
4542
if (!hash)
4643
goto fail;
4744

48-
desc.shash.tfm = apparmor_tfm;
49-
desc.shash.flags = 0;
45+
desc->tfm = apparmor_tfm;
46+
desc->flags = 0;
5047

51-
error = crypto_shash_init(&desc.shash);
48+
error = crypto_shash_init(desc);
5249
if (error)
5350
goto fail;
54-
error = crypto_shash_update(&desc.shash, (u8 *) data, len);
51+
error = crypto_shash_update(desc, (u8 *) data, len);
5552
if (error)
5653
goto fail;
57-
error = crypto_shash_final(&desc.shash, hash);
54+
error = crypto_shash_final(desc, hash);
5855
if (error)
5956
goto fail;
6057

@@ -69,10 +66,7 @@ char *aa_calc_hash(void *data, size_t len)
6966
int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
7067
size_t len)
7168
{
72-
struct {
73-
struct shash_desc shash;
74-
char ctx[crypto_shash_descsize(apparmor_tfm)];
75-
} desc;
69+
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
7670
int error = -ENOMEM;
7771
u32 le32_version = cpu_to_le32(version);
7872

@@ -86,19 +80,19 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
8680
if (!profile->hash)
8781
goto fail;
8882

89-
desc.shash.tfm = apparmor_tfm;
90-
desc.shash.flags = 0;
83+
desc->tfm = apparmor_tfm;
84+
desc->flags = 0;
9185

92-
error = crypto_shash_init(&desc.shash);
86+
error = crypto_shash_init(desc);
9387
if (error)
9488
goto fail;
95-
error = crypto_shash_update(&desc.shash, (u8 *) &le32_version, 4);
89+
error = crypto_shash_update(desc, (u8 *) &le32_version, 4);
9690
if (error)
9791
goto fail;
98-
error = crypto_shash_update(&desc.shash, (u8 *) start, len);
92+
error = crypto_shash_update(desc, (u8 *) start, len);
9993
if (error)
10094
goto fail;
101-
error = crypto_shash_final(&desc.shash, profile->hash);
95+
error = crypto_shash_final(desc, profile->hash);
10296
if (error)
10397
goto fail;
10498

0 commit comments

Comments
 (0)