mm81x_mac_check_fw_disabled_chans() iterates over n_channels entries of the firmware response without validating the response length against the array size. A firmware response with n_channels larger than ARRAY_SIZE(mors_s1ghz_channels) reads past the end of the response buffer. Validate it right after the command returns, before the first loop. Assisted-by: LLM Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Signed-off-by: Aamir Ahmed --- v3: - single patch against wireless-next; v2 was stacked on v1 and did not apply (Lachlan) - wireless-next named in the subject so NIPA runs (Lachlan) - drop the flag-clearing paragraph; describe the check as validating the response length against the array size (Lachlan) - Assisted-by: LLM, placed before Fixes: (Lachlan) v2: https://lore.kernel.org/linux-wireless/AS8P251MB00017F5BF791EA475A60A6CCC8B22@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM/ - move the check above the first loop, right after mm81x_cmd_get_disabled_channels() (Lachlan) v1: https://lore.kernel.org/linux-wireless/AS8P251MB0001BD39926B78E73D53A439C8B22@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM/ The uint -> u32 change to mm81x_cmd_get_disabled_channels() will follow as a separate patch once this lands. Compile-tested only (W=1 on the base-commit below); I have no mm81x hardware. drivers/net/wireless/morsemicro/mm81x/mac.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 08ca116a6..c3035a993 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -279,6 +279,11 @@ static void mm81x_mac_check_fw_disabled_chans(struct ieee80211_hw *hw) if (ret) goto out; + if (le32_to_cpu(resp->n_channels) > ARRAY_SIZE(mors_s1ghz_channels)) { + ret = -EINVAL; + goto out; + } + for (i = 0; i < ARRAY_SIZE(mors_s1ghz_channels); i++) { struct ieee80211_channel *ch = &mors_s1ghz_channels[i]; base-commit: 13e51269b6656768dc595ed6025e4974f2026543 -- 2.43.0