public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gautam Menghani <gautammenghani201@gmail.com>
To: sean@mess.org, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+0c3cb6dc05fbbdc3ad66@syzkaller.appspotmail.com
Subject: Re: [PATCH] drivers/media/rc: Fix a race condition in send_packet()
Date: Mon, 31 Oct 2022 10:20:09 +0530	[thread overview]
Message-ID: <Y19UAV8R4xN7HMAo@biggie> (raw)
In-Reply-To: <20221019050214.107448-1-gautammenghani201@gmail.com>

On Wed, Oct 19, 2022 at 10:32:14AM +0530, Gautam Menghani wrote:
> The function send_packet() has a race condition as follows:
> func send_packet()
> {
>     // do work
>     call usb_submit_urb()
>     mutex_unlock()
>     wait_for_event_interruptible()  <-- lock gone
>     mutex_lock()
> }
> 
> func vfd_write()
> {
>     mutex_lock()
>     call send_packet()  <- prev call is not completed
>     mutex_unlock()
> }
> 
> When the mutex is unlocked and the function send_packet() waits for the
> call to complete, vfd_write() can start another call, which leads to the
> "URB submitted while active" warning in usb_submit_urb(). 
> Fix this by removing the mutex_unlock() call in send_packet() and using
> mutex_lock_interruptible().
> 
> Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
> Link: https://syzkaller.appspot.com/bug?id=e378e6a51fbe6c5cc43e34f131cc9a315ef0337e
> Reported-by: syzbot+0c3cb6dc05fbbdc3ad66@syzkaller.appspotmail.com
> 
> Signed-off-by: Gautam Menghani <gautammenghani201@gmail.com>
> ---
>  drivers/media/rc/imon.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
> index 735b925da998..91d8056666ec 100644
> --- a/drivers/media/rc/imon.c
> +++ b/drivers/media/rc/imon.c
> @@ -646,15 +646,14 @@ static int send_packet(struct imon_context *ictx)
>  		pr_err_ratelimited("error submitting urb(%d)\n", retval);
>  	} else {
>  		/* Wait for transmission to complete (or abort) */
> -		mutex_unlock(&ictx->lock);
>  		retval = wait_for_completion_interruptible(
>  				&ictx->tx.finished);
>  		if (retval) {
>  			usb_kill_urb(ictx->tx_urb);
>  			pr_err_ratelimited("task interrupted\n");
>  		}
> -		mutex_lock(&ictx->lock);
>  
> +		ictx->tx.busy = false;
>  		retval = ictx->tx.status;
>  		if (retval)
>  			pr_err_ratelimited("packet tx failed (%d)\n", retval);
> @@ -955,7 +954,8 @@ static ssize_t vfd_write(struct file *file, const char __user *buf,
>  	if (ictx->disconnected)
>  		return -ENODEV;
>  
> -	mutex_lock(&ictx->lock);
> +	if (mutex_lock_interruptible(&ictx->lock))
> +		return -ERESTARTSYS;
>  
>  	if (!ictx->dev_present_intf0) {
>  		pr_err_ratelimited("no iMON device present\n");
> -- 
> 2.34.1
> 

Hi,

Please review the above fix and let me know if any changes are required.

Thanks,
Gautam

  reply	other threads:[~2022-10-31  4:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  5:02 [PATCH] drivers/media/rc: Fix a race condition in send_packet() Gautam Menghani
2022-10-31  4:50 ` Gautam Menghani [this message]
2022-11-10 16:42   ` Gautam Menghani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y19UAV8R4xN7HMAo@biggie \
    --to=gautammenghani201@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sean@mess.org \
    --cc=syzbot+0c3cb6dc05fbbdc3ad66@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox