wifi: mt76: Annotate struct mt76_rx_tid with __counted_by
authorKees Cook <keescook@chromium.org>
Fri, 15 Sep 2023 20:06:12 +0000 (13:06 -0700)
committerFelix Fietkau <nbd@nbd.name>
Sat, 30 Sep 2023 18:19:43 +0000 (20:19 +0200)
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 <nbd@nbd.name>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Ryder Lee <ryder.lee@mediatek.com>
Cc: Shayne Chen <shayne.chen@mediatek.com>
Cc: Sean Wang <sean.wang@mediatek.com>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: linux-wireless@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mediatek@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76.h

index 3730c5e7d7026b64f3288ad3f305fde014117114..ea828ba0b83acf1509e9505714e4046ec89c96b6 100644 (file)
@@ -379,7 +379,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)