rtl8187: fix use after free on failure path in rtl8187_init_urbs()
Subsystems (2)
------------------------------
Quoted 38 lines · On Mon, Sep 2, 2013 05:06 BST Alexey Khoroshilov wrote:
Quoted 37 lines · Hin-Tak Leung
------------------------------
On Sat, Aug 31, 2013 22:18 BST Alexey Khoroshilov wrote:In case of
__dev_alloc_skb()failurertl8187_init_urbs()callsusb_free_urb(entry)where 'entry' can points to urb allocated at the previous iteration. That means refcnt will be decremented incorrectly and the urb can be used after memory deallocation.The patch fixes the issue and implements error handling of
init_urbsinrtl8187_start().Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Alexey Khoroshilov <[email protected]>---
drivers/net/wireless/rtl818x/rtl8187/dev.c| 15 ++++++++++-----1 file changed, 10 insertions(+), 5 deletions(-)drivers/net/wireless/rtl818x/rtl8187/dev.c +1
-1@@ -438,17 +438,16 @@ static int rtl8187_init_urbs(struct ieee80211_hw *dev) skb_queue_tail(&priv->rx_queue, skb); usb_anchor_urb(entry, &priv->anchored); ret = usb_submit_urb(entry, GFP_KERNEL); + usb_free_urb(entry); if (ret) { skb_unlink(skb, &priv->rx_queue); usb_unanchor_urb(entry); goto err; } - usb_free_urb(entry); } return ret;
Quoted 11 lines
Quoted 6 lines
err:
-usb_free_urb(entry);
kfree_skb(skb);usb_kill_anchored_urbs(&priv->anchored);
return ret;
This part looks wrong - youfree_urb(entry)thenunanchor_urb(entry).I do not see any problems here.
usb_free_urb()just decrements refcnt of the urb.
Whileusb_anchor_urb()andusb_unanchor_urb()increment and decrement it as well.
So actual memory deallocation will happen inusb_unanchor_urb().
If the routines work as you say, they probably are misnamed, and/or prototyped wrongly? Also, you are making assumptions about how they are implemented, and relying on the implementation details to be fixed for eternity.
I am just saying,
XXX_free(some_entity);
if(condtion)
do_stuff(some_entity);
looks wrong, and if that's intentional, those routines really shouldn't be named as such.
Hin-Tak
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 56 lines · Hin-Tak Leung
------------------------------
Quoted 38 lines · On Mon, Sep 2, 2013 05:06 BST Alexey Khoroshilov wrote:
Quoted 37 lines · Hin-Tak Leung
------------------------------
On Sat, Aug 31, 2013 22:18 BST Alexey Khoroshilov wrote:In case of
__dev_alloc_skb()failurertl8187_init_urbs()callsusb_free_urb(entry)where 'entry' can points to urb allocated at the previous iteration. That means refcnt will be decremented incorrectly and the urb can be used after memory deallocation.The patch fixes the issue and implements error handling of
init_urbsinrtl8187_start().Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by Alexey Khoroshilov <[email protected]>---
drivers/net/wireless/rtl818x/rtl8187/dev.c| 15 ++++++++++-----1 file changed, 10 insertions(+), 5 deletions(-)drivers/net/wireless/rtl818x/rtl8187/dev.c +1
-1@@ -438,17 +438,16 @@ static int rtl8187_init_urbs(struct ieee80211_hw *dev)skb_queue_tail (&priv->rx_queue, skb);usb_anchor_urb (entry, &priv->anchored); ret =usb_submit_urb (entry,GFP_KERNEL ); +usb_free_urb (entry);if (ret) {skb_unlink (skb, &priv->rx_queue);usb_unanchor_urb (entry); goto err; } -usb_free_urb (entry); }return ret;Quoted 11 lines
Quoted 6 lines
err:
- usb_free_urb(entry); kfree_skb(skb); usb_kill_anchored_urbs(&priv->anchored); return ret;This part looks wrong - you
free_urb(entry)thenunanchor_urb(entry).I do not see any problems here.
usb_free_urb()just decrements refcnt of the urb.
Whileusb_anchor_urb()andusb_unanchor_urb()increment and decrement it as well.
So actual memory deallocation will happen inusb_unanchor_urb().If the routines work as you say, they probably are misnamed, and/or prototyped wrongly? Also, you are making assumptions about how they are implemented, and relying on the implementation details to be fixed for eternity.
Quoted 7 lines
I am just saying,
XXX_free(some_entity);
if(condtion)do_stuff(some_entity);looks wrong, and if that's intentional, those routines really shouldn't be named as such.
There is an alias for usb_free_urb() named usb_put_urb(). I will resend the patch with such substitution.
--
Alexey