Skip to contentSkip to conversation

media: siano: Drop responses shorter than the message header

PATCH New Maoyi Xie 1 participant 1 message Nov 27

Subsystems (3)
lore
Share & tools
lore

Maoyi Xie

author
#0 lore raw

PATCH 1/1 media: siano: Drop responses shorter than the message header

smsusb and smssdio set cb->size from the msg_length field that the device sends. Nothing checks that msg_length covers the 8-byte message header. For MSG_SMS_DVBT_BDA_DATA, smsdvb_onresponse() passes cb->size - sizeof(struct sms_msg_hdr) to dvb_dmx_swfilter(). A msg_length below 8 wraps this count to nearly SIZE_MAX. The demux then reads past the end of the buffer pool. On 32-bit big-endian hosts, a short message of another type also makes smsendian_handle_rx_message() byte-swap words past the buffer.

Drop such responses in both receive paths, before
smsendian_handle_rx_message().

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Fixes 2e5c1ec8865a ("V4L/DVB (8258): add support for SMS1010 and SMS1150 based digital television devices")
Fixes 319afbf97f20 ("V4L/DVB (11240): siano: add high level SDIO interface driver for SMS based cards")

---
I used an LLM to help write the harness and this patch.

 drivers/media/mmc/siano/smssdio.c | 6 ++++++
 drivers/media/usb/siano/smsusb.c  | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/media/mmc/siano/smssdio.c +6 -0
index 41dcab816216..eafb20a7c357 100644
@@ -226,6 +226,12 @@ static void smssdio_interrupt(struct sdio_func *func)
 		}
 	}
 
+	if (hdr->msg_length < sizeof(struct sms_msg_hdr)) {
+		pr_err("invalid response msglen %d\n", hdr->msg_length);
+		smscore_putbuffer(smsdev->coredev, cb);
+		return;
+	}
+
 	cb->size = hdr->msg_length;
 	cb->offset = 0;
 
drivers/media/usb/siano/smsusb.c +2 -1
index 0fdc2e0950b7..8c351422a6ec 100644
@@ -98,7 +98,8 @@ static void smsusb_onresponse(struct urb *urb)
 		struct sms_msg_hdr *phdr = (struct sms_msg_hdr *)surb->cb->p;
 
 		smsendian_handle_message_header(phdr);
-		if (urb->actual_length >= phdr->msg_length) {
+		if (phdr->msg_length >= sizeof(struct sms_msg_hdr) &&
+		    urb->actual_length >= phdr->msg_length) {
 			surb->cb->size = phdr->msg_length;
 
 			if (dev->response_alignment &&
Signature · 1 line
2.34.1