Skip to contentSkip to conversation

fix error handling in drivers/staging/rtl8192u/ieee80211/ieee80211_module.c

PATCH In review [email protected] 3 participants 4 messages Sep 26, 2018 – Sep 27, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix error handling in drivers/staging/rtl8192u/ieee80211/ieee80211_module.c

John notes that if the kzalloc of ieee->pHTInfo fails, we fail to call ieee80211_networks_free(). In addition, that function has an un-needed check before kfree().

---

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +1 -2
index 90a097f2cd4e..97ff0371b5bb 100644
@@ -78,8 +78,6 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
 
 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
 {
-	if (!ieee->networks)
-		return;
 	kfree(ieee->networks);
 	ieee->networks = NULL;
 }
@@ -180,6 +178,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
 	return dev;
 
  failed:
+	ieee80211_networks_free(ieee);
 	if (dev)
 		free_netdev(dev);
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Wed, Sep 26, 2018 at 10:52 AM, <[email protected]> wrote:

John notes that if the kzalloc of ieee->pHTInfo fails, we fail to call ieee80211_networks_free(). In addition, that function has an un-needed check before kfree().

(And this seems to be the only case of this -- I don't see this code trivially copy/pasted in other 80211 stacks.)

-Kees

Quoted 23 lines

---

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +1 -2
index 90a097f2cd4e..97ff0371b5bb 100644
@@ -78,8 +78,6 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
 
 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
 {
-       if (!ieee->networks)
-               return;
        kfree(ieee->networks);
        ieee->networks = NULL;
 }
@@ -180,6 +178,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
        return dev;
 
  failed:
+       ieee80211_networks_free(ieee);
        if (dev)
                free_netdev(dev);
 
Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
In reply to [email protected]
Quoted 21 lines · valdis.kletnieks at vt.edu

John notes that if the kzalloc of ieee->pHTInfo fails, we fail to call ieee80211_networks_free(). In addition, that function has an un-needed check before kfree().

---

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +0 -2
index 90a097f2cd4e..97ff0371b5bb 100644
@@ -78,8 +78,6 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
 
 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
 {
-	if (!ieee->networks)
-		return;
 	kfree(ieee->networks);
 	ieee->networks = NULL;
 }

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c struct net_device *alloc_ieee80211(int sizeof_priv) · line 183

Quoted 6 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +1 -0
@@ -180,6 +178,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
 	return dev;
 
  failed:
+	ieee80211_networks_free(ieee);
 	if (dev)
 		free_netdev(dev);

When there is a "goto failed;" then it's called "one err style" error handling and we're just asking for bugs... In this case the bug is that we're not allowd to call ieee80211_networks_free() with a NULL "ieee" parameter. The right thing to do is to only call ieee80211_networks_free() if we know that ieee80211_networks_allocate() succeeded.

regards,
dan carpenter

#3 lore raw
Quoted 24 lines · Dan Carpenter
Quoted 23 lines · valdis.kletnieks at vt.edu

John notes that if the kzalloc of ieee->pHTInfo fails, we fail to call ieee80211_networks_free(). In addition, that function has an un-needed check before kfree().

---

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +0 -2
index 90a097f2cd4e..97ff0371b5bb 100644
@@ -78,8 +78,6 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
 
 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
 {
-     if (!ieee->networks)
-             return;
      kfree(ieee->networks);
      ieee->networks = NULL;
 }
@@ -180,6 +178,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
      return dev;
 
Quoted 11 lines

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c struct net_device *alloc_ieee80211(int sizeof_priv) · line 183

Quoted 4 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +1 -0
  failed:
+     ieee80211_networks_free(ieee);
      if (dev)
              free_netdev(dev);

When there is a "goto failed;" then it's called "one err style" error handling and we're just asking for bugs... In this case the bug is that we're not allowd to call ieee80211_networks_free() with a NULL "ieee" parameter. The right thing to do is to only call ieee80211_networks_free() if we know that ieee80211_networks_allocate() succeeded.

Ah yeah, thanks for the extra eyes. Looks like it would need something more like this:

(quoted diff) +0 -0

b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index 90a097f2cd4e..8d6a28af96dc 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +0 -0
@@ -78,7 +78,7 @@ static inline int ieee80211_networks_allocate(struct

ieee80211_device *ieee)

static inline void ieee80211_networks_free(struct ieee80211_device *ieee) {
- if (!ieee->networks)
+ if (!ieee)

                return;
        kfree(ieee->networks);
        ieee->networks = NULL;

@@ -97,7 +97,7 @@ static inline void ieee80211_networks_initialize(struct ieee80211_device *ieee)

struct net_device *alloc_ieee80211(int sizeof_priv) {
- struct ieee80211_device *ieee;

+       struct ieee80211_device *ieee = NULL;
        struct net_device *dev;
        int i, err;

@@ -180,6 +180,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)

        return dev;

failed:

+       ieee80211_networks_free(ieee);
        if (dev)
                free_netdev(dev);

Valdis, can you respin the patch?

-Kees

Signature · 2 lines
Kees Cook
Pixel Security