mm81x_cmd_resp_process() copies a synchronous command response from the received skb into the caller-provided buffer: length = min_t(int, length, le16_to_cpu(src_resp->hdr.len) + sizeof(struct host_cmd_header)); memcpy(dest_resp, src_resp, length); src_resp->hdr.len is the inner host_cmd_header length of the firmware response. The skb, however, was sized by the *outer* mm81x_skb_hdr.len (mm81x_yaps_read_pkt(), yaps.c:186-199: skb_len = sizeof(*hdr) + hdr->offset + le16_to_cpu(hdr->len); skb_trim(skb, skb_len)), and nothing ties the inner header length to the outer one. A buggy or malicious firmware can therefore declare an inner hdr.len far larger than the payload actually present, and the memcpy reads past the end of the skb's data into adjacent heap memory, leaking it into the command response buffer. Clamp the copy to skb->len so we never read past the data actually received. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Cc: stable@vger.kernel.org Signed-off-by: guohongyu --- drivers/net/wireless/morsemicro/mm81x/command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/morsemicro/mm81x/command.c b/drivers/net/wireless/morsemicro/mm81x/command.c index afb7ee9bb236..591e5ba10753 100644 --- a/drivers/net/wireless/morsemicro/mm81x/command.c +++ b/drivers/net/wireless/morsemicro/mm81x/command.c @@ -209,6 +209,7 @@ int mm81x_cmd_resp_process(struct mm81x *mors, struct sk_buff *skb) length = min_t(int, length, le16_to_cpu(src_resp->hdr.len) + sizeof(struct host_cmd_header)); + length = min_t(int, length, skb->len); memcpy(dest_resp, src_resp, length); } else { ret = le32_to_cpu(src_resp->status); -- 2.43.0 mm81x_mac_check_fw_disabled_chans() allocates a response buffer sized for ARRAY_SIZE(mors_s1ghz_channels) (26) channel entries plus the fixed header, but then iterates the entries with the firmware-provided count alone: for (i = 0; i < le32_to_cpu(resp->n_channels); i++) { struct host_cmd_disabled_channel_entry *entry = &resp->channels[i]; n_channels is a __le32 filled by the firmware response and is not validated against the buffer size in any way. A firmware that reports more than 26 channels makes the loop read past the end of the kzalloc()ed buffer into adjacent heap memory and interpret it as channel entries. Bound the loop to the number of entries the buffer was actually allocated for. Fixes: b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver") Cc: stable@vger.kernel.org Signed-off-by: guohongyu --- drivers/net/wireless/morsemicro/mm81x/mac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/morsemicro/mm81x/mac.c b/drivers/net/wireless/morsemicro/mm81x/mac.c index 0fa80b1488aa..953958bf1241 100644 --- a/drivers/net/wireless/morsemicro/mm81x/mac.c +++ b/drivers/net/wireless/morsemicro/mm81x/mac.c @@ -288,7 +288,8 @@ static void mm81x_mac_check_fw_disabled_chans(struct ieee80211_hw *hw) ch->flags &= ~IEEE80211_CHAN_S1G_NO_PRIMARY; } - for (i = 0; i < le32_to_cpu(resp->n_channels); i++) { + for (i = 0; i < le32_to_cpu(resp->n_channels) && + i < ARRAY_SIZE(mors_s1ghz_channels); i++) { struct ieee80211_channel *ch; struct host_cmd_disabled_channel_entry *entry = &resp->channels[i]; -- 2.43.0