Blame SOURCES/Fixed-missing-input-buffer-length-check-in-urbdrc.patch

dacebc
From ddf9b3f852c31311f8d726012131f657c9857276 Mon Sep 17 00:00:00 2001
dacebc
From: akallabeth <akallabeth@posteo.net>
dacebc
Date: Thu, 13 Oct 2022 08:47:51 +0200
dacebc
Subject: [PATCH] Fixed missing input buffer length check in urbdrc
dacebc
dacebc
(cherry picked from commit 497df00f741dd4fc89292aaef2db7368aee45d0d)
dacebc
---
dacebc
 channels/urbdrc/client/data_transfer.c | 20 ++++++++++++++++++++
dacebc
 1 file changed, 20 insertions(+)
dacebc
dacebc
diff --git a/channels/urbdrc/client/data_transfer.c b/channels/urbdrc/client/data_transfer.c
dacebc
index bb2784055..80e84af48 100644
dacebc
--- a/channels/urbdrc/client/data_transfer.c
dacebc
+++ b/channels/urbdrc/client/data_transfer.c
dacebc
@@ -241,6 +241,10 @@ static UINT urbdrc_process_io_control(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* c
dacebc
 
dacebc
 	Stream_Read_UINT32(s, OutputBufferSize);
dacebc
 	Stream_Read_UINT32(s, RequestId);
dacebc
+
dacebc
+	if (OutputBufferSize > UINT32_MAX - 4)
dacebc
+		return ERROR_INVALID_DATA;
dacebc
+
dacebc
 	InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
dacebc
 	out = urb_create_iocompletion(InterfaceId, MessageId, RequestId, OutputBufferSize + 4);
dacebc
 
dacebc
@@ -724,6 +728,15 @@ static UINT urb_bulk_or_interrupt_transfer(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBA
dacebc
 	Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */
dacebc
 	Stream_Read_UINT32(s, OutputBufferSize);
dacebc
 	EndpointAddress = (PipeHandle & 0x000000ff);
dacebc
+
dacebc
+	if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
dacebc
+	{
dacebc
+		if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize))
dacebc
+		{
dacebc
+			return ERROR_INVALID_DATA;
dacebc
+		}
dacebc
+	}
dacebc
+
dacebc
 	/**  process TS_URB_BULK_OR_INTERRUPT_TRANSFER */
dacebc
 	return pdev->bulk_or_interrupt_transfer(
dacebc
 	    pdev, callback, MessageId, RequestId, EndpointAddress, TransferFlags, noAck,
dacebc
@@ -808,6 +821,13 @@ static UINT urb_isoch_transfer(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback
dacebc
 	packetDescriptorData = Stream_Pointer(s);
dacebc
 	Stream_Seek(s, NumberOfPackets * 12);
dacebc
 	Stream_Read_UINT32(s, OutputBufferSize);
dacebc
+
dacebc
+	if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
dacebc
+	{
dacebc
+		if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize))
dacebc
+			return ERROR_INVALID_DATA;
dacebc
+	}
dacebc
+
dacebc
 	return pdev->isoch_transfer(
dacebc
 	    pdev, callback, MessageId, RequestId, EndpointAddress, TransferFlags, StartFrame,
dacebc
 	    ErrorCount, noAck, packetDescriptorData, NumberOfPackets, OutputBufferSize,
dacebc
-- 
dacebc
2.37.1
dacebc