Patch "media: imon: fix a race condition in send_packet()" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    media: imon: fix a race condition in send_packet()

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     media-imon-fix-a-race-condition-in-send_packet.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 01a88de0109b797db8f5a67a8edf1e880ccf46e2
Author: Gautam Menghani <gautammenghani201@xxxxxxxxx>
Date:   Wed Oct 19 06:02:14 2022 +0100

    media: imon: fix a race condition in send_packet()
    
    [ Upstream commit 813ceef062b53d68f296aa3cb944b21a091fabdb ]
    
    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().
    
    Link: https://syzkaller.appspot.com/bug?id=e378e6a51fbe6c5cc43e34f131cc9a315ef0337e
    
    Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
    Reported-by: syzbot+0c3cb6dc05fbbdc3ad66@xxxxxxxxxxxxxxxxxxxxxxxxx
    Signed-off-by: Gautam Menghani <gautammenghani201@xxxxxxxxx>
    Signed-off-by: Sean Young <sean@xxxxxxxx>
    Signed-off-by: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index bc9ac6002e25..98a38755c694 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);
@@ -958,7 +957,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");



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux