linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args
@ 2022-02-09  2:52 Hongyu Xie
  2022-02-09  9:29 ` Mathias Nyman
  0 siblings, 1 reply; 4+ messages in thread
From: Hongyu Xie @ 2022-02-09  2:52 UTC (permalink / raw)
  To: gregkh, mathias.nyman; +Cc: linux-usb, linux-kernel, Hongyu Xie, stable

From: Hongyu Xie <xiehongyu1@kylinos.cn>

xhci_check_args returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
the return value of xhci_check_args <= 0.
This will cause a problem.
For example, r8152_submit_rx calling usb_submit_urb in
drivers/net/usb/r8152.c.
r8152_submit_rx will never get -ENODEV after submiting an urb
when xHC is halted,
because xhci_urb_enqueue returns -EINVAL in the very beginning.

Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.")
Cc: stable@vger.kernel.org
Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
---

v2: keep return value to -EINVAL for roothub urbs

 drivers/usb/host/xhci.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index dc357cabb265..948546b98af0 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1604,9 +1604,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 	struct urb_priv	*urb_priv;
 	int num_tds;
 
-	if (!urb || xhci_check_args(hcd, urb->dev, urb->ep,
-					true, true, __func__) <= 0)
+	if (!urb)
 		return -EINVAL;
+	ret = xhci_check_args(hcd, urb->dev, urb->ep,
+					true, true, __func__);
+	if (ret <= 0)
+		return ret ? ret : -EINVAL;
 
 	slot_id = urb->dev->slot_id;
 	ep_index = xhci_get_endpoint_index(&urb->ep->desc);
@@ -3323,7 +3326,7 @@ static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
 		return -EINVAL;
 	ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__);
 	if (ret <= 0)
-		return -EINVAL;
+		return ret ? ret : -EINVAL;
 	if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) {
 		xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion"
 				" descriptor for ep 0x%x does not support streams\n",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args
  2022-02-09  2:52 [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args Hongyu Xie
@ 2022-02-09  9:29 ` Mathias Nyman
  2022-02-10  1:04   ` 谢泓宇
  0 siblings, 1 reply; 4+ messages in thread
From: Mathias Nyman @ 2022-02-09  9:29 UTC (permalink / raw)
  To: Hongyu Xie, gregkh, mathias.nyman
  Cc: linux-usb, linux-kernel, Hongyu Xie, stable

On 9.2.2022 4.52, Hongyu Xie wrote:
> From: Hongyu Xie <xiehongyu1@kylinos.cn>
> 
> xhci_check_args returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
> xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
> the return value of xhci_check_args <= 0.
> This will cause a problem.
> For example, r8152_submit_rx calling usb_submit_urb in
> drivers/net/usb/r8152.c.
> r8152_submit_rx will never get -ENODEV after submiting an urb
> when xHC is halted,
> because xhci_urb_enqueue returns -EINVAL in the very beginning.
> 
> Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
> ---

Thanks, added to queue.
Changed the commit message and header a bit:

"xhci: Prevent futile URB re-submissions due to incorrect return value.
    
The -ENODEV return value from xhci_check_args() is incorrectly changed
to -EINVAL in a couple places before propagated further.
    
xhci_check_args() returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
the return value of xhci_check_args <= 0.
This causes problems for example r8152_submit_rx, calling usb_submit_urb
in drivers/net/usb/r8152.c.
r8152_submit_rx will never get -ENODEV after submiting an urb when xHC
is halted because xhci_urb_enqueue returns -EINVAL in the very beginning."

Let me know if you disagree with this.

Thanks
-Mathias

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args
  2022-02-09  9:29 ` Mathias Nyman
@ 2022-02-10  1:04   ` 谢泓宇
  2022-02-10  8:18     ` Mathias Nyman
  0 siblings, 1 reply; 4+ messages in thread
From: 谢泓宇 @ 2022-02-10  1:04 UTC (permalink / raw)
  To: Mathias Nyman, Hongyu Xie, gregkh, mathias.nyman
  Cc: linux-usb, linux-kernel, stable

Hi,

On 2022/2/9 17:29, Mathias Nyman wrote:
> On 9.2.2022 4.52, Hongyu Xie wrote:
>> From: Hongyu Xie <xiehongyu1@kylinos.cn>
>>
>> xhci_check_args returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
>> xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
>> the return value of xhci_check_args <= 0.
>> This will cause a problem.
>> For example, r8152_submit_rx calling usb_submit_urb in
>> drivers/net/usb/r8152.c.
>> r8152_submit_rx will never get -ENODEV after submiting an urb
>> when xHC is halted,
>> because xhci_urb_enqueue returns -EINVAL in the very beginning.
>>
>> Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
>> ---
> Thanks, added to queue.
> Changed the commit message and header a bit:
>
> "xhci: Prevent futile URB re-submissions due to incorrect return value.
>      
> The -ENODEV return value from xhci_check_args() is incorrectly changed
> to -EINVAL in a couple places before propagated further.
>      
> xhci_check_args() returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
> xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
> the return value of xhci_check_args <= 0.
> This causes problems for example r8152_submit_rx, calling usb_submit_urb
> in drivers/net/usb/r8152.c.
> r8152_submit_rx will never get -ENODEV after submiting an urb when xHC
> is halted because xhci_urb_enqueue returns -EINVAL in the very beginning."
>
> Let me know if you disagree with this.
>
> Thanks
> -Mathias

Sounds good to me.

Do I have to send another patch with commit message and header changed?

Thanks

Hongyu Xie


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args
  2022-02-10  1:04   ` 谢泓宇
@ 2022-02-10  8:18     ` Mathias Nyman
  0 siblings, 0 replies; 4+ messages in thread
From: Mathias Nyman @ 2022-02-10  8:18 UTC (permalink / raw)
  To: 谢泓宇, Hongyu Xie, gregkh, mathias.nyman
  Cc: linux-usb, linux-kernel, stable

On 10.2.2022 3.04, 谢泓宇 wrote:
> Hi,
> 
> On 2022/2/9 17:29, Mathias Nyman wrote:
>> On 9.2.2022 4.52, Hongyu Xie wrote:
>>> From: Hongyu Xie <xiehongyu1@kylinos.cn>
>>>
>>> xhci_check_args returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
>>> xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
>>> the return value of xhci_check_args <= 0.
>>> This will cause a problem.
>>> For example, r8152_submit_rx calling usb_submit_urb in
>>> drivers/net/usb/r8152.c.
>>> r8152_submit_rx will never get -ENODEV after submiting an urb
>>> when xHC is halted,
>>> because xhci_urb_enqueue returns -EINVAL in the very beginning.
>>>
>>> Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.")
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Hongyu Xie <xiehongyu1@kylinos.cn>
>>> ---
>> Thanks, added to queue.
>> Changed the commit message and header a bit:
>>
>> "xhci: Prevent futile URB re-submissions due to incorrect return value.
>>      The -ENODEV return value from xhci_check_args() is incorrectly changed
>> to -EINVAL in a couple places before propagated further.
>>      xhci_check_args() returns 4 types of value, -ENODEV, -EINVAL, 1 and 0.
>> xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if
>> the return value of xhci_check_args <= 0.
>> This causes problems for example r8152_submit_rx, calling usb_submit_urb
>> in drivers/net/usb/r8152.c.
>> r8152_submit_rx will never get -ENODEV after submiting an urb when xHC
>> is halted because xhci_urb_enqueue returns -EINVAL in the very beginning."
>>
>> Let me know if you disagree with this.
>>
>> Thanks
>> -Mathias
> 
> Sounds good to me.
> 
> Do I have to send another patch with commit message and header changed?
> 
> Thanks
> 
> Hongyu Xie
> 

No need, I'll submit it.

-Mathias

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-10  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09  2:52 [PATCH -next v2] xhci: fix two places when dealing with return value of function xhci_check_args Hongyu Xie
2022-02-09  9:29 ` Mathias Nyman
2022-02-10  1:04   ` 谢泓宇
2022-02-10  8:18     ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).