Skip to contentSkip to conversation

usbip: Fix vep_free_request() null pointer checks on input args

PATCH In review Shuah Khan 4 participants 9 messages Jan 18, 2019 – Jan 25, 2019

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author maintainer
#0 lore raw

PATCH 1/1 usbip: Fix vep_free_request() null pointer checks on input args

From: Shuah Khan <[email protected]>

Fix vep_free_request() to return when usb_ep and usb_request are null instead of calling WARN_ON.

---
 drivers/usb/usbip/vudc_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_dev.c +1 -1
index 1634d8698e15..bfc8218e3fb6 100644
@@ -297,7 +297,7 @@ static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req)
 {
 	struct vrequest *req;
 
-	if (WARN_ON(!_ep || !_req))
+	if (!_ep || !_req)
 		return;
 
 	req = to_vrequest(_req);
author maintainer
#1 lore raw

PATCH 1/1 usbip: Fix vhci_urb_enqueue() URB null transfer buffer error path

From: Shuah Khan <[email protected]>

Fix vhci_urb_enqueue() to print error and return error instead of failing with WARN_ON.

---
 drivers/usb/usbip/vhci_hcd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/usbip/vhci_hcd.c +4 -2
index 1e592ec94ba4..849ebfde87b5 100644
@@ -702,8 +702,10 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 	}
 	vdev = &vhci_hcd->vdev[portnum-1];
 
-	/* patch to usb_sg_init() is in 2.5.60 */
-	BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
+	if (!urb->transfer_buffer && urb->transfer_buffer_length) {
+		dev_err(dev, "Null URB transfer buffer\n");
+		return -EINVAL;
+	}
 
 	spin_lock_irqsave(&vhci->lock, flags);
 
maintainer
#2 lore raw

Re: [PATCH] usbip: Fix vhci_urb_enqueue() URB null transfer buffer error path

Quoted 15 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vhci_urb_enqueue() to print error and return error instead of failing with WARN_ON.

---
 drivers/usb/usbip/vhci_hcd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/usbip/vhci_hcd.c +0 -0
index 1e592ec94ba4..849ebfde87b5 100644

drivers/usb/usbip/vhci_hcd.c static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag · line 708

Quoted 9 lines
drivers/usb/usbip/vhci_hcd.c +4 -2
@@ -702,8 +702,10 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 	}
 	vdev = &vhci_hcd->vdev[portnum-1];
 
-	/* patch to usb_sg_init() is in 2.5.60 */
-	BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
+	if (!urb->transfer_buffer && urb->transfer_buffer_length) {
+		dev_err(dev, "Null URB transfer buffer\n");
+		return -EINVAL;
+	}

Could that BUG_ON be hit by userspace somehow? Or is this just an internal check for the api usage?

And sending out a 0 buffer length might be a valid thing (or at least a crazy attempt at something), so you might want to make that dev_dbg() in case userspace could trigger this to keep the log spam down.

thanks,

greg k-h

#3 lore raw

Re: [PATCH] usbip: Fix vhci_urb_enqueue() URB null transfer buffer error path

In reply to Shuah Khan

Hello!

Quoted 4 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vhci_urb_enqueue() to print error and return error instead of failing with WARN_ON.

It's BUG_ON().

Quoted 12 lines
---
 drivers/usb/usbip/vhci_hcd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/usbip/vhci_hcd.c +0 -0
index 1e592ec94ba4..849ebfde87b5 100644
@@ -702,8 +702,10 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 	}
 	vdev = &vhci_hcd->vdev[portnum-1];

drivers/usb/usbip/vhci_hcd.c static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag · line 711

Quoted 10 lines
drivers/usb/usbip/vhci_hcd.c +4 -2
 
-	/* patch to usb_sg_init() is in 2.5.60 */
-	BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
+	if (!urb->transfer_buffer && urb->transfer_buffer_length) {
+		dev_err(dev, "Null URB transfer buffer\n");
+		return -EINVAL;
+	}
 
 	spin_lock_irqsave(&vhci->lock, flags);
 

MBR, Sergei

maintainer
#4 lore raw

Re: [PATCH] usbip: Fix vhci_urb_enqueue() URB null transfer buffer error path

Quoted 10 lines · Sergei Shtylyov

Hello!

Quoted 4 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vhci_urb_enqueue() to print error and return error instead of failing with WARN_ON.

    It's BUG_ON().

Thanks. I will fix it.

-- Shuah

maintainer
#5 lore raw
In reply to Shuah Khan
Quoted 15 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vep_free_request() to return when usb_ep and usb_request are null instead of calling WARN_ON.

---
 drivers/usb/usbip/vudc_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_dev.c +0 -0
index 1634d8698e15..bfc8218e3fb6 100644

drivers/usb/usbip/vudc_dev.c static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req) · line 300

Quoted 5 lines
drivers/usb/usbip/vudc_dev.c +1 -1
@@ -297,7 +297,7 @@ static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req)
 {
 	struct vrequest *req;
 
-	if (WARN_ON(!_ep || !_req))
+	if (!_ep || !_req)

It's impossible for _ep to be NULL in this callback (see usb_ep_free_request() for where this is called from to prove that), so I don't think you need to check that. It's almost impossible for _req to be NULL, so you might as well leave that check in.

thanks,

greg k-h

maintainer
#6 lore raw
Quoted 19 lines · Greg KH
Quoted 18 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vep_free_request() to return when usb_ep and usb_request are null instead of calling WARN_ON.

---
  drivers/usb/usbip/vudc_dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_dev.c +0 -0
index 1634d8698e15..bfc8218e3fb6 100644
@@ -297,7 +297,7 @@ static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req)
  {
  	struct vrequest *req;
 
Quoted 8 lines

drivers/usb/usbip/vudc_dev.c static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req) · line 300

Quoted 2 lines
drivers/usb/usbip/vudc_dev.c +1 -1
-	if (WARN_ON(!_ep || !_req))
+	if (!_ep || !_req)

It's impossible for _ep to be NULL in this callback (see usb_ep_free_request() for where this is called from to prove that), so I don't think you need to check that. It's almost impossible for _req to be NULL, so you might as well leave that check in.

Yes. ep can never be null here in vep_free_request(). I will leave this alone.

thanks,
-- Shuah

maintainer
#7 lore raw
Quoted 28 lines · shuah
Quoted 11 lines · Greg KH
Quoted 10 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vep_free_request() to return when usb_ep and usb_request are null instead of calling WARN_ON.

---
  drivers/usb/usbip/vudc_dev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

drivers/usb/usbip/vudc_dev.c static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req) · line 299

Quoted 9 lines
drivers/usb/usbip/vudc_dev.c +1 -1
index 1634d8698e15..bfc8218e3fb6 100644
@@ -297,7 +297,7 @@ static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req)
  {
  	struct vrequest *req;
-	if (WARN_ON(!_ep || !_req))
+	if (!_ep || !_req)

It's impossible for _ep to be NULL in this callback (see usb_ep_free_request() for where this is called from to prove that), so I don't think you need to check that. It's almost impossible for _req to be NULL, so you might as well leave that check in.

Quoted 2 lines

Yes. ep can never be null here in vep_free_request(). I will leave this alone.

You can drop the !_ep check at the least, no need to check something that is impossible to hit :)

thanks,

greg k-h

maintainer
#8 lore raw
Quoted 29 lines · Greg KH
Quoted 28 lines · shuah
Quoted 26 lines · Greg KH
Quoted 15 lines · Shuah Khan

From: Shuah Khan <[email protected]>

Fix vep_free_request() to return when usb_ep and usb_request are null instead of calling WARN_ON.

---
   drivers/usb/usbip/vudc_dev.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vudc_dev.c +0 -0
index 1634d8698e15..bfc8218e3fb6 100644

drivers/usb/usbip/vudc_dev.c static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req) · line 299

Quoted 4 lines
drivers/usb/usbip/vudc_dev.c +1 -1
@@ -297,7 +297,7 @@ static void vep_free_request(struct usb_ep *_ep, struct usb_request *_req)
   {
   	struct vrequest *req;
-	if (WARN_ON(!_ep || !_req))
+	if (!_ep || !_req)

It's impossible for _ep to be NULL in this callback (see usb_ep_free_request() for where this is called from to prove that), so I don't think you need to check that. It's almost impossible for _req to be NULL, so you might as well leave that check in.

Quoted 6 lines
Quoted 2 lines

Yes. ep can never be null here in vep_free_request(). I will leave this alone.

You can drop the !_ep check at the least, no need to check something that is impossible to hit :)

Thanks. I will do that.

-- Shuah