wifi: wfx: validate firmware message body lengths before processing
PATCH v3 1/1 wifi: wfx: validate firmware message body lengths before processing
From: Tristan Madani <[email protected]>
The HIF message handlers cast the body pointer to typed structures without verifying that the firmware actually sent enough data. A shorter-than-expected message causes reads beyond the message boundary.
Add a min_body_len field to the hif_handlers dispatch table and reject messages that are too short before calling into any handler. For the multi-transmit confirmation, which has a variable-length tx_conf_payload array, additionally validate the array extent with struct_size(), both in rx_helper() before buffer accounting and in the handler itself. Guard the body->data accesses in the error and exception indication handlers against truncated messages. Add the same minimum length check for the inline-handled HIF_IND_ID_RX and generic confirmation paths.
---
v3:
- Add min_body_len field to hif_handlers dispatch table and validate before calling any handler, addressing all hif_handlers (Jerome)
- Guard flexible-array data[] accesses in error and exception handlers against truncated messages
- Add body length check for inline-handled RX indication and generic confirmation paths
- Keep struct_size() validation for multi-transmit flexible array
v2:
- Added validation in bh.c rx_helper() before buffer accounting
- Used struct_size() for overflow-safe flexible array validation
drivers/net/wireless/silabs/wfx/bh.c | 20 +++++-- drivers/net/wireless/silabs/wfx/hif_rx.c | 70 ++++++++++++++++++------ 2 files changed, 69 insertions(+), 21 deletions(-)
drivers/net/wireless/silabs/wfx/bh.c +16 -4
@@ -6,6 +6,7 @@* Copyright (c) 2010, ST-Ericsson */ #include <linux/gpio/consumer.h> +#include <linux/overflow.h> #include <net/mac80211.h> #include "bh.h"
@@ -99,11 +100,22 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf)if (!(hif->id &HIF_ID_IS_INDICATION )) { (*is_cnf)++; -if (hif->id ==HIF_CNF_ID_MULTI_TRANSMIT ) - release_count = - ((struct wfx_hif_cnf_multi_transmit *)hif->body)->num_tx_confs; -else +if (hif->id ==HIF_CNF_ID_MULTI_TRANSMIT ) { +const struct wfx_hif_cnf_multi_transmit *body = + (const struct wfx_hif_cnf_multi_transmit *)hif->body; +size_t body_len =le16_to_cpu (hif->len) -sizeof (*hif); + +if (body_len <sizeof (*body) || + body_len <struct_size (body, tx_conf_payload, + body->num_tx_confs)) { +dev_err (wdev->dev, +"invalid multi_tx_confirm length\n" ); + goto err; + } + release_count = body->num_tx_confs; + }else { release_count =1 ; + }WARN (wdev->hif.tx_buffers_used < release_count,"corrupted buffer counter" ); wdev->hif.tx_buffers_used -= release_count; }
drivers/net/wireless/silabs/wfx/hif_rx.c +53 -17
137 lines not on this page · raw message
Signature · 1 line
2.47.3