wifi: mm81x: reject short USB memory reads
PATCH 1/1 wifi: mm81x: reject short USB memory reads
mm81x_usb_mem_read() submits a bulk IN URB for size bytes and checks only the URB status. A short transfer completes with status 0, so the function still copies size bytes from the endpoint buffer and returns size. The bytes past urb->actual_length are stale or uninitialized. The YAPS receive path and the register reads then use them as chip data.
Fail the read with -EIO when the device sends fewer bytes than asked.
Found while checking a report from a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under MemorySanitizer. Not tested on hardware.
Assisted-by LLM
Fixes b1906cea00b0 ("wifi: mm81x: add mm81x Wi-Fi HaLow driver")
Signed-off-by Maoyi Xie <[email protected]>
--- drivers/net/wireless/morsemicro/mm81x/usb.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/wireless/morsemicro/mm81x/usb.c +8 -0
@@ -380,6 +380,14 @@ static int mm81x_usb_mem_read(struct mm81x_usb *musb, u32 address, u8 *data, goto error; } +if (musb->endpoints[MM81X_EP_MEM_RD ].urb->actual_length != size) { +dev_err (mors->dev,"short mem read %u of %zd" , + musb->endpoints[MM81X_EP_MEM_RD ].urb->actual_length, + size); + ret = -EIO ; + goto error; + } +memcpy (data, musb->endpoints[MM81X_EP_MEM_RD ].buffer, size); ret = size;
Signature · 1 line
2.34.1