Skip to content

Commit a4d714b

Browse files
szymonhaloktiwa
authored andcommitted
wifi: rndis_wlan: Prevent buffer overflow in rndis_query_oid
[ Upstream commit b870e73 ] 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: 80f8c5b ("rndis_wlan: copy only useful data from rndis_command respond") Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com> Reviewed-by: Alexander Duyck <alexanderduyck@fb.com> Signed-off-by: Kalle Valo <kvalo@kernel.org> Link: https://lore.kernel.org/r/20230111175031.7049-1-szymon.heidrich@gmail.com Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 8a97563bf04358f035a0b98142ae48f1ef095b61) Orabug: 35037715 CVE: CVE-2023-23559 Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
1 parent 58f0e31 commit a4d714b

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

drivers/net/wireless/rndis_wlan.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ static int rndis_query_oid(struct usbnet *dev, u32 oid, void *data, int *len)
712712
struct rndis_query *get;
713713
struct rndis_query_c *get_c;
714714
} u;
715-
int ret, buflen;
716-
int resplen, respoffs, copylen;
715+
int ret;
716+
size_t buflen, resplen, respoffs, copylen;
717717

718718
buflen = *len + sizeof(*u.get);
719719
if (buflen < CONTROL_BUFFER_SIZE)
@@ -748,22 +748,15 @@ static int rndis_query_oid(struct usbnet *dev, u32 oid, void *data, int *len)
748748

749749
if (respoffs > buflen) {
750750
/* Device returned data offset outside buffer, error. */
751-
netdev_dbg(dev->net, "%s(%s): received invalid "
752-
"data offset: %d > %d\n", __func__,
753-
oid_to_string(oid), respoffs, buflen);
751+
netdev_dbg(dev->net,
752+
"%s(%s): received invalid data offset: %zu > %zu\n",
753+
__func__, oid_to_string(oid), respoffs, buflen);
754754

755755
ret = -EINVAL;
756756
goto exit_unlock;
757757
}
758758

759-
if ((resplen + respoffs) > buflen) {
760-
/* Device would have returned more data if buffer would
761-
* have been big enough. Copy just the bits that we got.
762-
*/
763-
copylen = buflen - respoffs;
764-
} else {
765-
copylen = resplen;
766-
}
759+
copylen = min(resplen, buflen - respoffs);
767760

768761
if (copylen > *len)
769762
copylen = *len;

0 commit comments

Comments
 (0)