netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by
@ 2023-10-03 23:18 Kees Cook
  2023-10-03 23:38 ` Gustavo A. R. Silva
  2023-10-06  5:47 ` Steffen Klassert
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-03 23:18 UTC (permalink / raw)
  To: Steffen Klassert
  Cc: Kees Cook, Herbert Xu, David S. Miller, netdev,
	Gustavo A. R. Silva, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-kernel, linux-hardening, llvm

Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by for struct xfrm_sec_ctx.

Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/uapi/linux/xfrm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h
index 23543c33fee8..6a77328be114 100644
--- a/include/uapi/linux/xfrm.h
+++ b/include/uapi/linux/xfrm.h
@@ -4,6 +4,7 @@
 
 #include <linux/in6.h>
 #include <linux/types.h>
+#include <linux/stddef.h>
 
 /* All of the structures in this file may not change size as they are
  * passed into the kernel from userspace via netlink sockets.
@@ -33,7 +34,7 @@ struct xfrm_sec_ctx {
 	__u8	ctx_alg;
 	__u16	ctx_len;
 	__u32	ctx_sid;
-	char	ctx_str[];
+	char	ctx_str[] __counted_by(ctx_len);
 };
 
 /* Security Context Domains of Interpretation */
-- 
2.34.1


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

* Re: [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by
  2023-10-03 23:18 [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by Kees Cook
@ 2023-10-03 23:38 ` Gustavo A. R. Silva
  2023-10-06  5:47 ` Steffen Klassert
  1 sibling, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-03 23:38 UTC (permalink / raw)
  To: Kees Cook, Steffen Klassert
  Cc: Herbert Xu, David S. Miller, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm



On 10/4/23 01:18, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct xfrm_sec_ctx.
> 
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: netdev@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   include/uapi/linux/xfrm.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h
> index 23543c33fee8..6a77328be114 100644
> --- a/include/uapi/linux/xfrm.h
> +++ b/include/uapi/linux/xfrm.h
> @@ -4,6 +4,7 @@
>   
>   #include <linux/in6.h>
>   #include <linux/types.h>
> +#include <linux/stddef.h>
>   
>   /* All of the structures in this file may not change size as they are
>    * passed into the kernel from userspace via netlink sockets.
> @@ -33,7 +34,7 @@ struct xfrm_sec_ctx {
>   	__u8	ctx_alg;
>   	__u16	ctx_len;
>   	__u32	ctx_sid;
> -	char	ctx_str[];
> +	char	ctx_str[] __counted_by(ctx_len);
>   };
>   
>   /* Security Context Domains of Interpretation */

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

* Re: [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by
  2023-10-03 23:18 [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by Kees Cook
  2023-10-03 23:38 ` Gustavo A. R. Silva
@ 2023-10-06  5:47 ` Steffen Klassert
  1 sibling, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2023-10-06  5:47 UTC (permalink / raw)
  To: Kees Cook
  Cc: Herbert Xu, David S. Miller, netdev, Gustavo A. R. Silva,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel,
	linux-hardening, llvm

On Tue, Oct 03, 2023 at 04:18:28PM -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
> 
> As found with Coccinelle[1], add __counted_by for struct xfrm_sec_ctx.
> 
> Cc: Steffen Klassert <steffen.klassert@secunet.com>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: netdev@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>

Applied to ipsec-next, thanks!

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

end of thread, other threads:[~2023-10-06  5:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 23:18 [PATCH] xfrm: Annotate struct xfrm_sec_ctx with __counted_by Kees Cook
2023-10-03 23:38 ` Gustavo A. R. Silva
2023-10-06  5:47 ` Steffen Klassert

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