Skip to contentSkip to conversation

wireless/nl80211.c: fix uninitialized variable

PATCH In review Alaa Emad 2 participants 2 messages Mar 30, 2021

Subsystems (3)
lore
Share & tools
lore

Alaa Emad

author
#0 lore raw

PATCH v2 1/1 wireless/nl80211.c: fix uninitialized variable

This change fix KMSAN uninit-value in net/wireless/nl80211.c:225 , That because of fixedlen variable uninitialized,So I initialized it by zero.

---
Changes in v2:
- Make the commit message more clearer.

---
 net/wireless/nl80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/wireless/nl80211.c +1 -1
index 775d0c4d86c3..b87ab67ad33d 100644
@@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
 	const struct element *elem;
 	const struct ieee80211_mgmt *mgmt = (void *)data;
 	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
-	unsigned int fixedlen, hdrlen;
+	unsigned int fixedlen = 0, hdrlen;
 
 	if (s1g_bcn) {
 		fixedlen = offsetof(struct ieee80211_ext,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 18 lines · Alaa Emad

This change fix KMSAN uninit-value in net/wireless/nl80211.c:225 , That because of fixedlen variable uninitialized,So I initialized it by zero.

---
Changes in v2:
- Make the commit message more clearer.

---
 net/wireless/nl80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/wireless/nl80211.c +0 -0
index 775d0c4d86c3..b87ab67ad33d 100644

net/wireless/nl80211.c static int validate_beacon_head(const struct nlattr *attr, · line 216

Quoted 8 lines
net/wireless/nl80211.c +1 -1
@@ -210,7 +210,7 @@ static int validate_beacon_head(const struct nlattr *attr,
 	const struct element *elem;
 	const struct ieee80211_mgmt *mgmt = (void *)data;
 	bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
-	unsigned int fixedlen, hdrlen;
+	unsigned int fixedlen = 0, hdrlen;
 
 	if (s1g_bcn) {
 		fixedlen = offsetof(struct ieee80211_ext,

What was the report exactly ?

Current code does :

unsigned int fixedlen;

if (s1g_bcn) {
    fixedlen = something1;
    ...
else {
    fixedlen = something2;
    ...
}

So your patch does nothing.

Initial value of @fixedlen is not relevant.

Reading this code (without access to KMSAN report) I suspect the issue is more like the following :

net/wireless/nl80211.c +4 -1
index 775d0c4d86c3..d815261917ff 100644
@@ -209,9 +209,12 @@ static int validate_beacon_head(const struct nlattr *attr,
        unsigned int len = nla_len(attr);
        const struct element *elem;
        const struct ieee80211_mgmt *mgmt = (void *)data;
-       bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
        unsigned int fixedlen, hdrlen;
+       bool s1g_bcn;
 
+       if (len < offsetofend(typeof(*mgmt), frame_control))
+               goto err;
+       s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control);
        if (s1g_bcn) {
                fixedlen = offsetof(struct ieee80211_ext,
                                    u.s1g_beacon.variable);