linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] lsm: Add a __counted_by() annotation to lsm_ctx.ctx
@ 2023-12-22 14:54 Mark Brown
  2023-12-22 23:00 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Brown @ 2023-12-22 14:54 UTC (permalink / raw)
  To: Paul Moore, James Morris, Serge E. Hallyn, Kees Cook,
	Gustavo A. R. Silva
  Cc: linux-security-module, linux-kernel, linux-hardening,
	Aishwarya TCV, Mark Brown

The ctx in struct lsm_ctx is an array of size ctx_len, tell the compiler
about this using __counted_by() where supported to improve the ability to
detect overflow issues.

Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
Changes in v2:
- Add explicit stddef.h inclusion in case __counted_by() definition
  isn't otherwise pulled in.
- Link to v1: https://lore.kernel.org/r/20231221-lsm-fix-counted-by-v1-1-12cc27597cdf@kernel.org
---
 include/uapi/linux/lsm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/lsm.h b/include/uapi/linux/lsm.h
index f0386880a78e..f8aef9ade549 100644
--- a/include/uapi/linux/lsm.h
+++ b/include/uapi/linux/lsm.h
@@ -9,6 +9,7 @@
 #ifndef _UAPI_LINUX_LSM_H
 #define _UAPI_LINUX_LSM_H
 
+#include <linux/stddef.h>
 #include <linux/types.h>
 #include <linux/unistd.h>
 
@@ -36,7 +37,7 @@ struct lsm_ctx {
 	__u64 flags;
 	__u64 len;
 	__u64 ctx_len;
-	__u8 ctx[];
+	__u8 ctx[] __counted_by(ctx_len);
 };
 
 /*

---
base-commit: ec4e9d630a64df500641892f4e259e8149594a99
change-id: 20231221-lsm-fix-counted-by-f9fd827e26aa

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

* Re: [PATCH v2] lsm: Add a __counted_by() annotation to lsm_ctx.ctx
  2023-12-22 14:54 [PATCH v2] lsm: Add a __counted_by() annotation to lsm_ctx.ctx Mark Brown
@ 2023-12-22 23:00 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2023-12-22 23:00 UTC (permalink / raw)
  To: Mark Brown, James Morris, Serge E. Hallyn, Kees Cook,
	Gustavo A. R. Silva
  Cc: linux-security-module, linux-kernel, linux-hardening,
	Aishwarya TCV, Mark Brown

On Dec 22, 2023 Mark Brown <broonie@kernel.org> wrote:
> 
> The ctx in struct lsm_ctx is an array of size ctx_len, tell the compiler
> about this using __counted_by() where supported to improve the ability to
> detect overflow issues.
> 
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
> Changes in v2:
> - Add explicit stddef.h inclusion in case __counted_by() definition
>   isn't otherwise pulled in.
> - Link to v1: https://lore.kernel.org/r/20231221-lsm-fix-counted-by-v1-1-12cc27597cdf@kernel.org
> ---
>  include/uapi/linux/lsm.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied to lsm/dev, thanks!

--
paul-moore.com

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

end of thread, other threads:[~2023-12-22 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-22 14:54 [PATCH v2] lsm: Add a __counted_by() annotation to lsm_ctx.ctx Mark Brown
2023-12-22 23:00 ` Paul Moore

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).