Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in  __ffs_ep0_queue_wait
@ 2023-01-24  9:11 Udipto Goswami
  2023-01-24 10:53 ` John Keeping
  0 siblings, 1 reply; 2+ messages in thread
From: Udipto Goswami @ 2023-01-24  9:11 UTC (permalink / raw)
  To: John Keeping, Dan Carpenter, Greg Kroah-Hartman, linux-usb
  Cc: Pratham Pratap, Udipto Goswami

__ffs_ep0_queue_wait executes holding the spinlock of &ffs->ev.waitq.lock
and unlocks it after the assignments to usb_request are done.
However in the code if the request is already NULL we bail out returning
-EINVAL but never unlocked the spinlock.

Fix this by adding spin_unlock_irq &ffs->ev.waitq.lock before returning.

Fixes: 6a19da111057("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
Signed-off-by: Udipto Goswami <quic_ugoswami@quicinc.com>
---
 drivers/usb/gadget/function/f_fs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 523a961b910b..8ad354741380 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -279,8 +279,10 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
 	struct usb_request *req = ffs->ep0req;
 	int ret;
 
-	if (!req)
+	if (!req) {
+		spin_unlock_irq(&ffs->ev.waitq.lock);
 		return -EINVAL;
+	}
 
 	req->zero     = len < le16_to_cpu(ffs->ev.setup.wLength);
 
-- 
2.17.1


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

* Re: [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait
  2023-01-24  9:11 [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait Udipto Goswami
@ 2023-01-24 10:53 ` John Keeping
  0 siblings, 0 replies; 2+ messages in thread
From: John Keeping @ 2023-01-24 10:53 UTC (permalink / raw)
  To: Udipto Goswami
  Cc: Dan Carpenter, Greg Kroah-Hartman, linux-usb, Pratham Pratap

On Tue, Jan 24, 2023 at 02:41:49PM +0530, Udipto Goswami wrote:
> __ffs_ep0_queue_wait executes holding the spinlock of &ffs->ev.waitq.lock
> and unlocks it after the assignments to usb_request are done.
> However in the code if the request is already NULL we bail out returning
> -EINVAL but never unlocked the spinlock.
> 
> Fix this by adding spin_unlock_irq &ffs->ev.waitq.lock before returning.
> 
> Fixes: 6a19da111057("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
> Signed-off-by: Udipto Goswami <quic_ugoswami@quicinc.com>

Reviewed-by: John Keeping <john@metanate.com>

> ---
>  drivers/usb/gadget/function/f_fs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 523a961b910b..8ad354741380 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -279,8 +279,10 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
>  	struct usb_request *req = ffs->ep0req;
>  	int ret;
>  
> -	if (!req)
> +	if (!req) {
> +		spin_unlock_irq(&ffs->ev.waitq.lock);
>  		return -EINVAL;
> +	}
>  
>  	req->zero     = len < le16_to_cpu(ffs->ev.setup.wLength);
>  
> -- 
> 2.17.1
> 

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

end of thread, other threads:[~2023-01-24 10:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-24  9:11 [PATCH] usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait Udipto Goswami
2023-01-24 10:53 ` John Keeping

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox