Skip to contentSkip to conversation

mwifiex: add cfg80211 handlers add/del_virtual_intf

DISCUSSION Dan Carpenter 2 participants 4 messages Oct 5, 2011

lore
Share & tools
lore
#0 lore raw

Hi Yogesh,

The Smatch static checker complains that 93a1df48d22429 "mwifiex: add cfg80211 handlers add/del_virtual_intf" introduces a potential NULL dereference.

@@ -985,9 +817,20 @@ int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)

                       atomic_read(&adapter->cmd_pending));
        }

- /* Remove interface */
- for (i = 0; i < adapter->priv_num; i++)
- mwifiex_remove_interface(adapter, i);
+ for (i = 0; i < adapter->priv_num; i++) {
+ priv = adapter->priv[i];
+
+ if (!priv)
+ continue;
+

+               rtnl_lock();
+               mwifiex_del_virtual_intf(priv->wdev->wiphy, priv->netdev);
+               rtnl_unlock();
+       }
+
+       wiphy_unregister(priv->wdev->wiphy);
                         ^^^^^^^^^^

Can priv be NULL here? How do we know that the last element of adapter->priv[]; is non-NULL when we have to check the others?

regards,
dan carpenter

#1 lore raw

Hi Dan,

Thanks for your comment.

Quoted 33 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, October 04, 2011 11:08 PM
To: Yogesh Powar
Cc: Bing Zhao; [email protected]
Subject: re: mwifiex: add cfg80211 handlers add/del_virtual_intf

Hi Yogesh,

The Smatch static checker complains that 93a1df48d22429 "mwifiex: add cfg80211 handlers add/del_virtual_intf" introduces a potential NULL dereference.

(quoted diff) +12 -3
@@ -985,9 +817,20 @@ int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
                       atomic_read(&adapter->cmd_pending));
        }
 
-       /* Remove interface */
-       for (i = 0; i < adapter->priv_num; i++)
-               mwifiex_remove_interface(adapter, i);
+       for (i = 0; i < adapter->priv_num; i++) {
+               priv = adapter->priv[i];
+
+               if (!priv)
+                       continue;
+
+               rtnl_lock();
+               mwifiex_del_virtual_intf(priv->wdev->wiphy, priv->netdev);
+               rtnl_unlock();
+       }
+
+       wiphy_unregister(priv->wdev->wiphy);
                         ^^^^^^^^^^
Quoted 2 lines

Can priv be NULL here? How do we know that the last element of adapter->priv[]; is non-NULL when we have to check the others?

That's a good catch.

Since the first element of priv[] cannot be NULL. How about this fix?

+ priv = adapter->priv[0];
+ BUG_ON(!priv);
+

        wiphy_unregister(priv->wdev->wiphy);

Thanks,
Bing

Quoted 3 lines

regards,
dan carpenter

#2 lore raw

Review

Quoted 7 lines · Bing Zhao

Since the first element of priv[] cannot be NULL. How about this fix?

(quoted diff) +3 -0
+       priv = adapter->priv[0];
+       BUG_ON(!priv);
+
        wiphy_unregister(priv->wdev->wiphy);

I don't know the code at all, so I'll trust you on that. :)

But please don't add the BUG_ON(). Calls to BUG_ON() make the code messier, and they are more painful than needed for the user. If we don't have the BUG_ON() then we get an Oops and the driver will die, but we can still can close our documents and reboot the system.

Debugging NULL dereference bugs is normally super easy. Just compile with CONFIG_DEBUG_INFO=y, run gdb on the .ko file and type:
"list *(function_name+0x63)" at the gdb prompt. Done.

regards,
dan carpenter

#3 lore raw

Hi Dan,

Quoted 18 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday, October 05, 2011 12:52 PM
To: Bing Zhao
Cc: Yogesh Powar; [email protected]
Subject: Re: mwifiex: add cfg80211 handlers add/del_virtual_intf

Review

Quoted 7 lines · Bing Zhao

Since the first element of priv[] cannot be NULL. How about this fix?

(quoted diff) +3 -0
+       priv = adapter->priv[0];
+       BUG_ON(!priv);
+
        wiphy_unregister(priv->wdev->wiphy);

I don't know the code at all, so I'll trust you on that. :)

Quoted 8 lines

But please don't add the BUG_ON(). Calls to BUG_ON() make the code messier, and they are more painful than needed for the user. If we don't have the BUG_ON() then we get an Oops and the driver will die, but we can still can close our documents and reboot the system.

Debugging NULL dereference bugs is normally super easy. Just compile with CONFIG_DEBUG_INFO=y, run gdb on the .ko file and type:
"list *(function_name+0x63)" at the gdb prompt. Done.

Thanks for the information.

Regards,
Bing

Quoted 3 lines

regards,
dan carpenter