Skip to contentSkip to conversation

rndis_wlan: integer overflows in rndis_wlan_do_link_up_work()

PATCH Superseded Dan Carpenter 4 participants 7 messages Feb 29, 2012 – Mar 1, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 rndis_wlan: integer overflows in rndis_wlan_do_link_up_work()

If "offset" is negative then we can get past this check:
if (offset > CONTROL_BUFFER_SIZE)
Or if we pick a very high "req_ie_len" then we can get around the check:
if (offset + req_ie_len > CONTROL_BUFFER_SIZE)

I made "resp_ie_len" and "req_ie_len" unsigned. I don't know if it was intentional that they were signed in the original.

drivers/net/wireless/rndis_wlan.c +7 -2
index a330c69..6d8a986 100644
@@ -2755,9 +2755,10 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
 	struct ndis_80211_assoc_info *info = NULL;
 	u8 bssid[ETH_ALEN];
-	int resp_ie_len, req_ie_len;
+	unsigned int resp_ie_len, req_ie_len;
+	unsigned int offset;
 	u8 *req_ie, *resp_ie;
-	int ret, offset;
+	int ret;
 	bool roamed = false;
 	bool match_bss;
 
@@ -2785,6 +2786,8 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 		ret = get_association_info(usbdev, info, CONTROL_BUFFER_SIZE);
 		if (!ret) {
 			req_ie_len = le32_to_cpu(info->req_ie_length);
+			if (req_ie_len > CONTROL_BUFFER_SIZE)
+				req_ie_len = CONTROL_BUFFER_SIZE;
 			if (req_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_req_ies);
 
@@ -2799,6 +2802,8 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 			}
 
 			resp_ie_len = le32_to_cpu(info->resp_ie_length);
+			if (resp_ie_len > CONTROL_BUFFER_SIZE)
+				resp_ie_len = CONTROL_BUFFER_SIZE;
 			if (resp_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_resp_ies);
 
#1 lore raw

Am 29.02.2012 07:35, schrieb Dan Carpenter:

Quoted 37 lines

If "offset" is negative then we can get past this check:
if (offset > CONTROL_BUFFER_SIZE)
Or if we pick a very high "req_ie_len" then we can get around the check:
if (offset + req_ie_len > CONTROL_BUFFER_SIZE)

I made "resp_ie_len" and "req_ie_len" unsigned. I don't know if it was intentional that they were signed in the original.

drivers/net/wireless/rndis_wlan.c +5 -2
index a330c69..6d8a986 100644
@@ -2755,9 +2755,10 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
 	struct ndis_80211_assoc_info *info = NULL;
 	u8 bssid[ETH_ALEN];
-	int resp_ie_len, req_ie_len;
+	unsigned int resp_ie_len, req_ie_len;
+	unsigned int offset;
 	u8 *req_ie, *resp_ie;
-	int ret, offset;
+	int ret;
 	bool roamed = false;
 	bool match_bss;
 
@@ -2785,6 +2786,8 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 		ret = get_association_info(usbdev, info, CONTROL_BUFFER_SIZE);
 		if (!ret) {
 			req_ie_len = le32_to_cpu(info->req_ie_length);
+			if (req_ie_len > CONTROL_BUFFER_SIZE)
+				req_ie_len = CONTROL_BUFFER_SIZE;
 			if (req_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_req_ies);
 

drivers/net/wireless/rndis_wlan.c static void rndis_wlan_do_link_up_work(struct usbnet *usbdev) · line 2809

Quoted 8 lines
drivers/net/wireless/rndis_wlan.c +2 -0
@@ -2799,6 +2802,8 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 			}
 
 			resp_ie_len = le32_to_cpu(info->resp_ie_length);
+			if (resp_ie_len > CONTROL_BUFFER_SIZE)
+				resp_ie_len = CONTROL_BUFFER_SIZE;
 			if (resp_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_resp_ies);
 

hi dan,
the check below "if (resp_ie_len > 0)" looks strange for an unsigned.

re,
wh

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 11 lines · walter harms

drivers/net/wireless/rndis_wlan.c static void rndis_wlan_do_link_up_work(struct usbnet *usbdev) · line 2808

Quoted 6 lines
drivers/net/wireless/rndis_wlan.c +2 -0
 			resp_ie_len = le32_to_cpu(info->resp_ie_length);
+			if (resp_ie_len > CONTROL_BUFFER_SIZE)
+				resp_ie_len = CONTROL_BUFFER_SIZE;
 			if (resp_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_resp_ies);

hi dan,
the check below "if (resp_ie_len > 0)" looks strange for an unsigned.

Good point. I'll resend.

regards,
dan carpenter

#3 lore raw

PATCH v2 1/4 rndis_wlan: integer overflows in rndis_wlan_do_link_up_work()

In reply to walter harms

If "offset" is negative then we can get past this check:
if (offset > CONTROL_BUFFER_SIZE)
Or if we pick a very high "req_ie_len" then we can get around the check:
if (offset + req_ie_len > CONTROL_BUFFER_SIZE)

I made "resp_ie_len" and "req_ie_len" unsigned. I don't know if it was intentional that they were signed in the original.

---
v2: Fixed a style issue for Walter Harms. Changed > 0 to != 0.

drivers/net/wireless/rndis_wlan.c +9 -4
index a330c69..dde45ef 100644
@@ -2755,9 +2755,10 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
 	struct ndis_80211_assoc_info *info = NULL;
 	u8 bssid[ETH_ALEN];
-	int resp_ie_len, req_ie_len;
+	unsigned int resp_ie_len, req_ie_len;
+	unsigned int offset;
 	u8 *req_ie, *resp_ie;
-	int ret, offset;
+	int ret;
 	bool roamed = false;
 	bool match_bss;
 
@@ -2785,7 +2786,9 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 		ret = get_association_info(usbdev, info, CONTROL_BUFFER_SIZE);
 		if (!ret) {
 			req_ie_len = le32_to_cpu(info->req_ie_length);
-			if (req_ie_len > 0) {
+			if (req_ie_len > CONTROL_BUFFER_SIZE)
+				req_ie_len = CONTROL_BUFFER_SIZE;
+			if (req_ie_len != 0) {
 				offset = le32_to_cpu(info->offset_req_ies);
 
 				if (offset > CONTROL_BUFFER_SIZE)
@@ -2799,7 +2802,9 @@ static void rndis_wlan_do_link_up_work(struct usbnet *usbdev)
 			}
 
 			resp_ie_len = le32_to_cpu(info->resp_ie_length);
-			if (resp_ie_len > 0) {
+			if (resp_ie_len > CONTROL_BUFFER_SIZE)
+				resp_ie_len = CONTROL_BUFFER_SIZE;
+			if (resp_ie_len != 0) {
 				offset = le32_to_cpu(info->offset_resp_ies);
 
 				if (offset > CONTROL_BUFFER_SIZE)
Acked-by on v1 1/4
#6 lore raw
In reply to Dan Carpenter

Quoting Dan Carpenter <[email protected]>:

Quoted 40 lines

If "offset" is negative then we can get past this check:
if (offset > CONTROL_BUFFER_SIZE)
Or if we pick a very high "req_ie_len" then we can get around the check:
if (offset + req_ie_len > CONTROL_BUFFER_SIZE)

I made "resp_ie_len" and "req_ie_len" unsigned. I don't know if it was intentional that they were signed in the original.

drivers/net/wireless/rndis_wlan.c +5 -2
index a330c69..6d8a986 100644
@@ -2755,9 +2755,10 @@ static void rndis_wlan_do_link_up_work(struct  
 usbnet *usbdev)
 	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
 	struct ndis_80211_assoc_info *info = NULL;
 	u8 bssid[ETH_ALEN];
-	int resp_ie_len, req_ie_len;
+	unsigned int resp_ie_len, req_ie_len;
+	unsigned int offset;
 	u8 *req_ie, *resp_ie;
-	int ret, offset;
+	int ret;
 	bool roamed = false;
 	bool match_bss;
@@ -2785,6 +2786,8 @@ static void rndis_wlan_do_link_up_work(struct  
 usbnet *usbdev)
 		ret = get_association_info(usbdev, info, CONTROL_BUFFER_SIZE);
 		if (!ret) {
 			req_ie_len = le32_to_cpu(info->req_ie_length);
+			if (req_ie_len > CONTROL_BUFFER_SIZE)
+				req_ie_len = CONTROL_BUFFER_SIZE;
 			if (req_ie_len > 0) {
 				offset = le32_to_cpu(info->offset_req_ies);

drivers/net/wireless/rndis_wlan.c static void rndis_wlan_do_link_up_work(struct · line 2808

Quoted 7 lines
drivers/net/wireless/rndis_wlan.c +2 -0
@@ -2799,6 +2802,8 @@ static void rndis_wlan_do_link_up_work(struct  
 usbnet *usbdev)
 			}
 
 			resp_ie_len = le32_to_cpu(info->resp_ie_length);
+			if (resp_ie_len > CONTROL_BUFFER_SIZE)
+				resp_ie_len = CONTROL_BUFFER_SIZE;
 			if (resp_ie_len > 0) {

(resp_ie_len > 0), (resp_ie_len != 0), (resp_ie_len) .. all fine by me,

Quoted 4 lines
drivers/net/wireless/rndis_wlan.c +0 -0
 				offset = le32_to_cpu(info->offset_resp_ies);
#5 lore raw
In reply to bojan prtvar
Quoted 8 lines · bojan prtvar

Hi,

Quoted 4 lines · Dan Carpenter
Quoted 7 lines
Quoted 4 lines

---
v2: Fixed a style issue for Walter Harms.  Changed > 0 to != 0.

Why not just  if (req_ie_len) and if (resp_ie_len) ?

It could go either way. I wrote it that way first, then I decided that zero was a special enough case to draw attention to it. In this case it felt like zero was its own thing.

For allocation failures I would do:

	foo = kmalloc();
	if (!foo)
		return -ENOMEM;

Allocation failures are not interesting and the NULL doesn't have a special meaning and doesn't need explanation.

Hard to explain.

regards,
dan carpenter