linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] integrity: Use static_assert() to check struct sizes
@ 2024-08-08 22:04 Gustavo A. R. Silva
  2024-08-16 12:28 ` Roberto Sassu
  2024-10-10  3:00 ` Mimi Zohar
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-08 22:04 UTC (permalink / raw)
  To: Mimi Zohar, Roberto Sassu, Dmitry Kasatkin, Eric Snowberg,
	Paul Moore, James Morris, Serge E. Hallyn
  Cc: linux-integrity, linux-security-module, linux-kernel,
	Gustavo A. R. Silva, linux-hardening

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>
---
 security/integrity/integrity.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
index 660f76cb69d3..c2c2da691123 100644
--- a/security/integrity/integrity.h
+++ b/security/integrity/integrity.h
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] integrity: Use static_assert() to check struct sizes
  2024-08-08 22:04 [PATCH][next] integrity: Use static_assert() to check struct sizes Gustavo A. R. Silva
@ 2024-08-16 12:28 ` Roberto Sassu
  2024-10-10  3:00 ` Mimi Zohar
  1 sibling, 0 replies; 3+ messages in thread
From: Roberto Sassu @ 2024-08-16 12:28 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Mimi Zohar, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn
  Cc: linux-integrity, linux-security-module, linux-kernel,
	linux-hardening

On Thu, 2024-08-08 at 16:04 -0600, Gustavo A. R. Silva wrote:
> 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.

Looks good to me.

Tested-by: Roberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>

Thanks

Roberto

> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  security/integrity/integrity.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
> index 660f76cb69d3..c2c2da691123 100644
> --- a/security/integrity/integrity.h
> +++ b/security/integrity/integrity.h
> @@ -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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] integrity: Use static_assert() to check struct sizes
  2024-08-08 22:04 [PATCH][next] integrity: Use static_assert() to check struct sizes Gustavo A. R. Silva
  2024-08-16 12:28 ` Roberto Sassu
@ 2024-10-10  3:00 ` Mimi Zohar
  1 sibling, 0 replies; 3+ messages in thread
From: Mimi Zohar @ 2024-10-10  3:00 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Roberto Sassu, Dmitry Kasatkin,
	Eric Snowberg, Paul Moore, James Morris, Serge E. Hallyn
  Cc: linux-integrity, linux-security-module, linux-kernel,
	linux-hardening

On Thu, 2024-08-08 at 16:04 -0600, Gustavo A. R. Silva wrote:
> 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>

Sorry for the delay.  It's now queued in next-integrity.

thanks,

Mimi


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-10  3:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 22:04 [PATCH][next] integrity: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-16 12:28 ` Roberto Sassu
2024-10-10  3:00 ` Mimi Zohar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).