Skip to contentSkip to conversation

keys: Annotate struct asymmetric_key_id with __counted_by

PATCH In review Thorsten Blum 3 participants 3 messages Oct 23, 2025 – Oct 27, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 keys: Annotate struct asymmetric_key_id with __counted_by

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.

---
 include/keys/asymmetric-type.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/keys/asymmetric-type.h +1 -1
index 69a13e1e5b2e..1b91c8f98688 100644
@@ -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 {
Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Thorsten Blum
Quoted 25 lines · Thorsten Blum

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.

---
 include/keys/asymmetric-type.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/keys/asymmetric-type.h +1 -1
index 69a13e1e5b2e..1b91c8f98688 100644
@@ -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 {
Signature · 1 line
2.51.0

BR, Jarkko