Skip to contentSkip to conversation

wifi: mt76: Annotate struct mt76_rx_tid with __counted_by

PATCH In review Kees Cook 3 participants 4 messages Sep 15, 2023 – Oct 7, 2023

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 wifi: mt76: Annotate struct mt76_rx_tid 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 mt76_rx_tid.

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

Cc Felix Fietkau <[email protected]>
Cc Lorenzo Bianconi <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Shayne Chen <[email protected]>
Cc Sean Wang <[email protected]>
Cc Kalle Valo <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
---
 drivers/net/wireless/mediatek/mt76/mt76.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt76.h +1 -1
index e8757865a3d0..03ef617b1527 100644
@@ -376,7 +376,7 @@ struct mt76_rx_tid {
 
 	u8 started:1, stopped:1, timer_pending:1;
 
-	struct sk_buff *reorder_buf[];
+	struct sk_buff *reorder_buf[] __counted_by(size);
 };
 
 #define MT_TX_CB_DMA_DONE		BIT(0)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 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 mt76_rx_tid.

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

Quoted 12 lines
Cc Felix Fietkau <[email protected]>
Cc Lorenzo Bianconi <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Shayne Chen <[email protected]>
Cc Sean Wang <[email protected]>
Cc Kalle Valo <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>

Thanks

Signature · 1 line
Gustavo
Quoted 17 lines
---
  drivers/net/wireless/mediatek/mt76/mt76.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt76.h +1 -1
index e8757865a3d0..03ef617b1527 100644
@@ -376,7 +376,7 @@ struct mt76_rx_tid {
 
  	u8 started:1, stopped:1, timer_pending:1;
 
-	struct sk_buff *reorder_buf[];
+	struct sk_buff *reorder_buf[] __counted_by(size);
  };
 
  #define MT_TX_CB_DMA_DONE		BIT(0)
author
#2 lore raw
In reply to Kees Cook
Quoted 7 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 mt76_rx_tid.

Friendly ping. Can this get picked up by the wifi tree, or should it go via something else?

Thanks!

-Kees

Quoted 35 lines

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

Cc Felix Fietkau <[email protected]>
Cc Lorenzo Bianconi <[email protected]>
Cc Ryder Lee <[email protected]>
Cc Shayne Chen <[email protected]>
Cc Sean Wang <[email protected]>
Cc Kalle Valo <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
---
 drivers/net/wireless/mediatek/mt76/mt76.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt76.h +1 -1
index e8757865a3d0..03ef617b1527 100644
@@ -376,7 +376,7 @@ struct mt76_rx_tid {
 
 	u8 started:1, stopped:1, timer_pending:1;
 
-	struct sk_buff *reorder_buf[];
+	struct sk_buff *reorder_buf[] __counted_by(size);
 };
 
 #define MT_TX_CB_DMA_DONE		BIT(0)
Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook
#3 lore raw
Quoted 11 lines · Kees Cook
Quoted 7 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 mt76_rx_tid.

Friendly ping. Can this get picked up by the wifi tree, or should it go via something else?

It's already in mt76 pull request and should be in wireless-next next week:

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

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

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