Skip to contentSkip to conversation

staging: rtl8188eu: Avoid null pointer arithmetic

PATCH In review Aymen Qader 2 participants 3 messages Sep 27, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8188eu: Avoid null pointer arithmetic

Avoid null pointer arithmetic in rtw_mlme_ext.c by skipping other field checks if the information element pointer is null.

---
 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +3 -1
index 834053a0ae9d..8a3a71456cd0 100644
@@ -2971,8 +2971,10 @@ static unsigned int OnAssocReq(struct adapter *padapter,
 	/*  checking SSID */
 	p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
 		pkt_len - WLAN_HDR_A3_LEN - ie_offset);
-	if (!p)
+	if (!p) {
 		status = _STATS_FAILURE_;
+		goto OnAssocReqFail;
+	}
 
 	if (ie_len == 0) { /*  broadcast ssid, however it is not allowed in assocreq */
 		status = _STATS_FAILURE_;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Aymen Qader

Avoid null pointer arithmetic in rtw_mlme_ext.c by skipping other field checks if the information element pointer is null.

---
  drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +0 -0
index 834053a0ae9d..8a3a71456cd0 100644
@@ -2971,8 +2971,10 @@ static unsigned int OnAssocReq(struct adapter *padapter,
  	/*  checking SSID */

drivers/staging/rtl8188eu/core/rtw_mlme_ext.c static unsigned int OnAssocReq(struct adapter *padapter, · line 2980

Quoted 10 lines
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +3 -1
  	p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
  		pkt_len - WLAN_HDR_A3_LEN - ie_offset);
-	if (!p)
+	if (!p) {
  		status = _STATS_FAILURE_;
+		goto OnAssocReqFail;
+	}
 
  	if (ie_len == 0) { /*  broadcast ssid, however it is not allowed in assocreq */
  		status = _STATS_FAILURE_;

I do not think this patch avoids any pointer arithmetic. If p is NULL, then ie_len will be zero and the branch with the memcmp() call, where the pointer arithmetic is done, will be skipped.

That said, it is better to bail out with the first failure condition. I do not require the following, but the code would be even simpler if you test p and ie_len==0 in a single if statement and eliminate some code as in

drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +2 -3
index 1115050077e4..71722cec84a0 100644
@@ -2982,11 +2982,10 @@ static unsigned int OnAssocReq(struct adapter *padapter,
        /*  checking SSID */
        p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
                pkt_len - WLAN_HDR_A3_LEN - ie_offset);
-       if (!p)
-               status = _STATS_FAILURE_;
 
-       if (ie_len == 0) { /*  broadcast ssid, however it is not allowed in assocreq */
+       if (!p || ie_len == 0) { /*  broadcast ssid, however it is not allowed in assocreq */
                status = _STATS_FAILURE_;
+               goto OnAssocReqFail;
        } else {
                /*  check if ssid match */
                if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))

Thanks,

Larry

#2 lore raw
Quoted 20 lines · Larry Finger
Quoted 19 lines · Aymen Qader

Avoid null pointer arithmetic in rtw_mlme_ext.c by skipping other field checks if the information element pointer is null.

---
  drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +1 -1
index 834053a0ae9d..8a3a71456cd0 100644
@@ -2971,8 +2971,10 @@ static unsigned int OnAssocReq(struct adapter *padapter,
  	/*  checking SSID */
  	p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
  		pkt_len - WLAN_HDR_A3_LEN - ie_offset);
-	if (!p)
+	if (!p) {
  		status = _STATS_FAILURE_;
Quoted 8 lines

drivers/staging/rtl8188eu/core/rtw_mlme_ext.c static unsigned int OnAssocReq(struct adapter *padapter, · line 2979

Quoted 4 lines
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +2 -0
+		goto OnAssocReqFail;
+	}
  	if (ie_len == 0) { /*  broadcast ssid, however it is not allowed in assocreq */
  		status = _STATS_FAILURE_;

I do not think this patch avoids any pointer arithmetic. If p is NULL, then ie_len will be zero and the branch with the memcmp() call, where the pointer arithmetic is done, will be skipped.

I'm sincerely sorry, you're completely right--that was a bad oversight from me, I should have checked more thoroughly.

Quoted 21 lines

That said, it is better to bail out with the first failure condition. I do not require the following, but the code would be even simpler if you test p and ie_len==0 in a single if statement and eliminate some code as in

drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +0 -3
index 1115050077e4..71722cec84a0 100644
@@ -2982,11 +2982,10 @@ static unsigned int OnAssocReq(struct adapter *padapter,
        /*  checking SSID */
        p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
                pkt_len - WLAN_HDR_A3_LEN - ie_offset);
-       if (!p)
-               status = _STATS_FAILURE_;
 
-       if (ie_len == 0) { /*  broadcast ssid, however it is not allowed in

assocreq */
+ if (!p || ie_len == 0) { /* broadcast ssid, however it is not
allowed in assocreq */

Quoted 6 lines
                status = _STATS_FAILURE_;
+               goto OnAssocReqFail;
        } else {
                /*  check if ssid match */
                if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))

Yep, I understand that would be a lot better. If it's alright, I'll send this in with a v2 (w/ a more appropriate commit message).

Quoted 7 lines

Thanks,

Larry

Kind regards,
Aymen