public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] Enforce buffer boundaries on RNDIS USB Gadget
@ 2022-11-17 19:44 Szymon Heidrich
  2022-11-20 15:02 ` Fabio Estevam
  0 siblings, 1 reply; 9+ messages in thread
From: Szymon Heidrich @ 2022-11-17 19:44 UTC (permalink / raw)
  To: u-boot; +Cc: Szymon Heidrich

Prevent access to arbitrary memory locations in gen_ndis_set_resp
via manipulation of buf->InformationBufferOffset. Lack of validation
of BufOffset could be exploited to dump arbitrary memory contents
via NDIS packet filter.

Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
---
 drivers/usb/gadget/rndis.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 13c327ea38..3948f2cc9a 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -855,14 +855,17 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
 	rndis_set_cmplt_type	*resp;
 	rndis_resp_t		*r;
 
+	BufLength = get_unaligned_le32(&buf->InformationBufferLength);
+	BufOffset = get_unaligned_le32(&buf->InformationBufferOffset);
+	if ((BufOffset > RNDIS_MAX_TOTAL_SIZE - 8) ||
+	    (BufLength > RNDIS_MAX_TOTAL_SIZE - 8 - BufOffset))
+		return -EINVAL;
+
 	r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type));
 	if (!r)
 		return -ENOMEM;
 	resp = (rndis_set_cmplt_type *) r->buf;
 
-	BufLength = get_unaligned_le32(&buf->InformationBufferLength);
-	BufOffset = get_unaligned_le32(&buf->InformationBufferOffset);
-
 #ifdef	VERBOSE
 	debug("%s: Length: %d\n", __func__, BufLength);
 	debug("%s: Offset: %d\n", __func__, BufOffset);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-12-09 11:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-17 19:44 [PATCH] Enforce buffer boundaries on RNDIS USB Gadget Szymon Heidrich
2022-11-20 15:02 ` Fabio Estevam
2022-12-03 14:59   ` Szymon Heidrich
2022-12-04 19:12     ` Marek Vasut
2022-12-04 20:36       ` Szymon Heidrich
2022-12-05  0:41         ` Marek Vasut
2022-12-05  9:28           ` [PATCH v2] usb: gadget: rndis: Prevent InformationBufferOffset manipulation Szymon Heidrich
2022-12-09  1:56             ` Marek Vasut
2022-12-09 11:48               ` Szymon Heidrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox