staging: wlan-ng: properly check endpoint types
PATCH 1/1 staging: wlan-ng: properly check endpoint types
As syzkaller detected, wlan-ng driver submits bulk urb without checking that the endpoint type is actually bulk, add usb_urb_ep_type_check()
--- drivers/staging/wlan-ng/hfa384x_usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/staging/wlan-ng/hfa384x_usb.c +14 -0
@@ -339,6 +339,12 @@ static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) hw->rx_urb_skb = skb; + result =usb_urb_ep_type_check (&hw->rx_urb); +if (result) { +netdev_warn (hw->wlandev->netdev,"invalid rx endpoint" ); + goto cleanup; + } + result = -ENOLINK ;if (!hw->wlandev->hwremoved && !test_bit (WORK_RX_HALT , &hw->usb_flags)) {
@@ -354,6 +360,7 @@ static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) } } +cleanup:/* Don't leak memory if anything should go wrong */ if (result !=0 ) {dev_kfree_skb (skb);
@@ -388,6 +395,12 @@ static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags)struct net_device *netdev = hw->wlandev->netdev;int result; + result =usb_urb_ep_type_check (&hw->tx_urb); +if (result) { +netdev_warn (hw->wlandev->netdev,"invalid tx endpoint" ); + goto done; + } + result = -ENOLINK ;if (netif_running (netdev)) { if (!hw->wlandev->hwremoved &&
@@ -407,6 +420,7 @@ static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags) } } +done:return result; }
Signature · 1 line
2.27.0
Greg KH
maintainerQuoted 15 lines · Rustam Kovhaev
As syzkaller detected, wlan-ng driver submits bulk urb without checking that the endpoint type is actually bulk, add
usb_urb_ep_type_check()Reported-and-tested-by [email protected]Signed-off-by Rustam Kovhaev <[email protected]>--- drivers/staging/wlan-ng/hfa384x_usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/staging/wlan-ng/hfa384x_usb.c +0
-0
drivers/staging/wlan-ng/hfa384x_usb.c static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) · line 346
Quoted 8 lines
drivers/staging/wlan-ng/hfa384x_usb.c +5
-0@@ -339,6 +339,12 @@ static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) hw->rx_urb_skb = skb; + result =usb_urb_ep_type_check (&hw->rx_urb); +if (result) { +netdev_warn (hw->wlandev->netdev,"invalid rx endpoint" ); + goto cleanup; + }
In looking at this again, can you just make these checks in the probe function, and abort binding the driver to the device at that point in time? This feels really late in the init sequence.
The real problem here is in the hfa384x_create() function, where it blindly takes the 1 and 2 endpoints and assumes that those are the "correct type". How about checking the types there, and if they are incorrect, returning an error from that function and have the caller return the error as well.
That should keep anything else in the driver from being initialized and set up, and stop bad devices from being bound to the driver at a much earlier point in time.
Note, just checking for the valid type/direction of those endpoints should be sufficient.
thanks,
greg k-h
Quoted 35 lines · Greg KH
Quoted 15 lines · Rustam Kovhaev
As syzkaller detected, wlan-ng driver submits bulk urb without checking that the endpoint type is actually bulk, add
usb_urb_ep_type_check()Reported-and-tested-by [email protected]Signed-off-by Rustam Kovhaev <[email protected]>--- drivers/staging/wlan-ng/hfa384x_usb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/staging/wlan-ng/hfa384x_usb.c +0
-0drivers/staging/wlan-ng/hfa384x_usb.c static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) · line 346
Quoted 8 lines
drivers/staging/wlan-ng/hfa384x_usb.c +5
-0@@ -339,6 +339,12 @@ static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) hw->rx_urb_skb = skb; + result =usb_urb_ep_type_check (&hw->rx_urb); +if (result) { +netdev_warn (hw->wlandev->netdev,"invalid rx endpoint" ); + goto cleanup; + }In looking at this again, can you just make these checks in the probe function, and abort binding the driver to the device at that point in time? This feels really late in the init sequence.
The real problem here is in the
hfa384x_create()function, where it blindly takes the 1 and 2 endpoints and assumes that those are the "correct type". How about checking the types there, and if they are incorrect, returning an error from that function and have the caller return the error as well.
Quoted 7 lines
That should keep anything else in the driver from being initialized and set up, and stop bad devices from being bound to the driver at a much earlier point in time.
Note, just checking for the valid type/direction of those endpoints should be sufficient.
tyvm for the feedback! makes perfect sense, i'll send a new patch