Skip to content

Commit 08ae3e5

Browse files
GustavoARSilvamimizohar
authored andcommitted
integrity: Use static_assert() to check struct sizes
Commit 38aa3f5 ("integrity: Avoid -Wflex-array-member-not-at-end warnings") introduced tagged `struct evm_ima_xattr_data_hdr` and `struct ima_digest_data_hdr`. We want to ensure that when new members need to be added to the flexible structures, they are always included within these tagged structs. So, we use `static_assert()` to ensure that the memory layout for both the flexible structure and the tagged struct is the same after any changes. Signed-off-by: Gustavo A. R. Silva <[email protected]> Tested-by: Roberto Sassu <[email protected]> Reviewed-by: Roberto Sassu <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent 699ae62 commit 08ae3e5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

security/integrity/integrity.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct evm_ima_xattr_data {
3737
);
3838
u8 data[];
3939
} __packed;
40+
static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr),
41+
"struct member likely outside of __struct_group()");
4042

4143
/* Only used in the EVM HMAC code. */
4244
struct evm_xattr {
@@ -65,6 +67,8 @@ struct ima_digest_data {
6567
);
6668
u8 digest[];
6769
} __packed;
70+
static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr),
71+
"struct member likely outside of __struct_group()");
6872

6973
/*
7074
* Instead of wrapping the ima_digest_data struct inside a local structure

0 commit comments

Comments
 (0)