Skip to contentSkip to conversation

wifi: ipw2x00: Annotate struct libipw_txb with __counted_by

PATCH In review Kees Cook 3 participants 3 messages Sep 15, 2023 – Sep 21, 2023 Intel pro/wireless 2100, 2200BG, 2915ABG network connection support

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 wifi: ipw2x00: Annotate struct libipw_txb with __counted_by

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 checking 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 libipw_txb.

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc Stanislav Yakovlev <[email protected]>
Cc Kalle Valo <[email protected]>
---
 drivers/net/wireless/intel/ipw2x00/libipw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/ipw2x00/libipw.h +1 -1
index bec7bc273748..9065ca5b0208 100644
@@ -488,7 +488,7 @@ struct libipw_txb {
 	u8 reserved;
 	u16 frag_size;
 	u16 payload_size;
-	struct sk_buff *fragments[];
+	struct sk_buff *fragments[] __counted_by(nr_frags);
 };
 
 /* SWEEP TABLE ENTRIES NUMBER */
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Kees Cook

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 checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Quoted 8 lines

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

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Cc Stanislav Yakovlev <[email protected]>
Cc Kalle Valo <[email protected]>

Thanks

Signature · 1 line
Gustavo
Quoted 17 lines
---
  drivers/net/wireless/intel/ipw2x00/libipw.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/ipw2x00/libipw.h +1 -1
index bec7bc273748..9065ca5b0208 100644
@@ -488,7 +488,7 @@ struct libipw_txb {
  	u8 reserved;
  	u16 frag_size;
  	u16 payload_size;
-	struct sk_buff *fragments[];
+	struct sk_buff *fragments[] __counted_by(nr_frags);
  };
 
  /* SWEEP TABLE ENTRIES NUMBER */
#2 lore raw
In reply to Kees Cook
Quoted 8 lines · Kees Cook

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 checking 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 libipw_txb.

Quoted 7 lines

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci

Patch applied to wireless-next.git, thanks.

357be7ebba38 wifi: ipw2x00: Annotate struct libipw_txb with __counted_by

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches