Re: [PATCH v3][next] integrity: Avoid -Wflex-array-member-not-at-end warnings

From: Gustavo A. R. Silva
Date: Thu Mar 21 2024 - 11:56:52 EST




On 3/21/24 07:58, Mimi Zohar wrote:
On Wed, 2024-03-20 at 22:11 -0600, Gustavo A. R. Silva wrote:
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
ready to enable it globally.

There is currently an object (`hdr)` in `struct ima_max_digest_data`
that contains a flexible structure (`struct ima_digest_data`):

struct ima_max_digest_data {
struct ima_digest_data hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;

So, in order to avoid ending up with a flexible-array member in the
middle of a struct, we use the `__struct_group()` helper to separate
the flexible array from the rest of the members in the flexible
structure:

struct ima_digest_data {
__struct_group(ima_digest_data_hdr, hdr, __packed,

... the rest of the members

);
u8 digest[];
} __packed;

With the change described above, we can now declare an object of the
type of the tagged `struct ima_digest_data_hdr`, without embedding the
flexible array in the middle of another struct:

struct ima_max_digest_data {
struct ima_digest_data_hdr hdr;
u8 digest[HASH_MAX_DIGESTSIZE];
} __packed;


And similarly for 'struct evm_digest'.

Yes. :)



We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure.

So, with these changes, fix the following warnings:

security/integrity/evm/evm.h:45:32: warning: structure containing a flexible
array member is not at the end of another structure [-Wflex-array-member-not-
at-end]
security/integrity/evm/evm.h:45:32: warning: structure containing a flexible
array member is not at the end of another structure [-Wflex-array-member-not-
at-end]
security/integrity/evm/evm.h:45:32: warning: structure containing a flexible
array member is not at the end of another structure [-Wflex-array-member-not-
at-end]

I assume these messages are gone.

Yes. :)

Thanks
--
Gustavo