mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rndis_wlan: Prevent buffer overflow in rndis_query_oid
@ 2023-01-10 17:30 Szymon Heidrich
  2023-01-10 19:39 ` Alexander H Duyck
  2023-01-13  8:42 ` [PATCH] " cahu
  0 siblings, 2 replies; 9+ messages in thread
From: Szymon Heidrich @ 2023-01-10 17:30 UTC (permalink / raw)
  To: kvalo, jussi.kivilinna, davem
  Cc: edumazet, kuba, pabeni, szymon.heidrich, linux-wireless, netdev,
	linux-kernel

Since resplen and respoffs are signed integers sufficiently
large values of unsigned int len and offset members of RNDIS
response will result in negative values of prior variables.
This may be utilized to bypass implemented security checks
to either extract memory contents by manipulating offset or
overflow the data buffer via memcpy by manipulating both
offset and len.

Additionally assure that sum of resplen and respoffs does not
overflow so buffer boundaries are kept.

Fixes: 80f8c5b434f9 ("rndis_wlan: copy only useful data from rndis_command respond")
Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
---
 drivers/net/wireless/rndis_wlan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 82a7458e0..d7fc05328 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -697,7 +697,7 @@ static int rndis_query_oid(struct usbnet *dev, u32 oid, void *data, int *len)
 		struct rndis_query_c	*get_c;
 	} u;
 	int ret, buflen;
-	int resplen, respoffs, copylen;
+	u32 resplen, respoffs, copylen;
 
 	buflen = *len + sizeof(*u.get);
 	if (buflen < CONTROL_BUFFER_SIZE)
@@ -740,7 +740,7 @@ static int rndis_query_oid(struct usbnet *dev, u32 oid, void *data, int *len)
 			goto exit_unlock;
 		}
 
-		if ((resplen + respoffs) > buflen) {
+		if (resplen > (buflen - respoffs)) {
 			/* Device would have returned more data if buffer would
 			 * have been big enough. Copy just the bits that we got.
 			 */
-- 
2.38.2


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

end of thread, other threads:[~2023-01-16 11:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 17:30 [PATCH] rndis_wlan: Prevent buffer overflow in rndis_query_oid Szymon Heidrich
2023-01-10 19:39 ` Alexander H Duyck
2023-01-11  9:54   ` Szymon Heidrich
2023-01-11 15:47     ` Alexander Duyck
2023-01-11 17:50       ` [PATCH v2] " Szymon Heidrich
2023-01-11 18:28         ` Alexander Duyck
2023-01-11 19:12           ` Szymon Heidrich
2023-01-16 11:28         ` [v2] wifi: " Kalle Valo
2023-01-13  8:42 ` [PATCH] " cahu

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

all inboxes | Powered by JetHome®