[PATCH] keys: Annotate struct asymmetric_key_id with __counted_by

Thorsten Blum posted 1 patch 3 months, 2 weeks ago
include/keys/asymmetric-type.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] keys: Annotate struct asymmetric_key_id with __counted_by
Posted by Thorsten Blum 3 months, 2 weeks ago
Add the __counted_by() compiler attribute to the flexible array member
'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 include/keys/asymmetric-type.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/keys/asymmetric-type.h b/include/keys/asymmetric-type.h
index 69a13e1e5b2e..1b91c8f98688 100644
--- a/include/keys/asymmetric-type.h
+++ b/include/keys/asymmetric-type.h
@@ -49,7 +49,7 @@ enum asymmetric_payload_bits {
  */
 struct asymmetric_key_id {
 	unsigned short	len;
-	unsigned char	data[];
+	unsigned char	data[] __counted_by(len);
 };
 
 struct asymmetric_key_ids {
-- 
2.51.0
Re: [PATCH] keys: Annotate struct asymmetric_key_id with __counted_by
Posted by Jarkko Sakkinen 3 months, 1 week ago
On Thu, Oct 23, 2025 at 07:48:11PM +0200, Thorsten Blum wrote:
> Add the __counted_by() compiler attribute to the flexible array member
> 'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  include/keys/asymmetric-type.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/keys/asymmetric-type.h b/include/keys/asymmetric-type.h
> index 69a13e1e5b2e..1b91c8f98688 100644
> --- a/include/keys/asymmetric-type.h
> +++ b/include/keys/asymmetric-type.h
> @@ -49,7 +49,7 @@ enum asymmetric_payload_bits {
>   */
>  struct asymmetric_key_id {
>  	unsigned short	len;
> -	unsigned char	data[];
> +	unsigned char	data[] __counted_by(len);
>  };
>  
>  struct asymmetric_key_ids {
> -- 
> 2.51.0
> 

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
Re: [PATCH] keys: Annotate struct asymmetric_key_id with __counted_by
Posted by Lukas Wunner 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 07:48:11PM +0200, Thorsten Blum wrote:
> Add the __counted_by() compiler attribute to the flexible array member
> 'data' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Reviewed-by: Lukas Wunner <lukas@wunner.de>