]> www.infradead.org Git - users/hch/configfs.git/commitdiff
integrity: Use static_assert() to check struct sizes
authorGustavo A. R. Silva <gustavoars@kernel.org>
Thu, 8 Aug 2024 22:04:59 +0000 (16:04 -0600)
committerMimi Zohar <zohar@linux.ibm.com>
Thu, 10 Oct 2024 02:49:40 +0000 (22:49 -0400)
Commit 38aa3f5ac6d2 ("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 <gustavoars@kernel.org>
Tested-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
security/integrity/integrity.h

index 660f76cb69d370515209ac917dc6db3639769e1c..c2c2da6911233bac1a7a41a52ae2c249b45bbcef 100644 (file)
@@ -37,6 +37,8 @@ struct evm_ima_xattr_data {
        );
        u8 data[];
 } __packed;
+static_assert(offsetof(struct evm_ima_xattr_data, data) == sizeof(struct evm_ima_xattr_data_hdr),
+             "struct member likely outside of __struct_group()");
 
 /* Only used in the EVM HMAC code. */
 struct evm_xattr {
@@ -65,6 +67,8 @@ struct ima_digest_data {
        );
        u8 digest[];
 } __packed;
+static_assert(offsetof(struct ima_digest_data, digest) == sizeof(struct ima_digest_data_hdr),
+             "struct member likely outside of __struct_group()");
 
 /*
  * Instead of wrapping the ima_digest_data struct inside a local structure