mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] media: imon: fix use-after-free in display_close via dev_dbg
@ 2026-09-28 12:12 Deepanshu Kartikey
  2026-09-28 12:18 ` Deepanshu Kartikey
  0 siblings, 1 reply; 3+ messages in thread
From: Deepanshu Kartikey @ 2026-09-28 12:12 UTC (permalink / raw)
  To: sean, mchehab
  Cc: jarod, linux-media, linux-kernel, Deepanshu Kartikey,
	syzbot+9bfac891bdd42eb708fc

ictx->dev is a raw pointer to the usb_interface's embedded device,
cached in imon_init_intf0() without taking a reference. On
disconnect, usb_disconnect() can drop the last reference on the
interface and free it while a userspace fd for /dev/lcd0 is still
open. When that fd is later closed, display_close() dereferences
the now-freed ictx->dev via dev_dbg(), causing a use-after-free.

Fix by pinning the device with get_device() when ictx->dev is
assigned, and releasing it with put_device() when ictx is freed.

Also drop the dev_dbg() in free_imon_context(), which only printed
a debug message and is no longer needed.

Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
Reported-by: syzbot+9bfac891bdd42eb708fc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9bfac891bdd42eb708fc
Link: http://lore.kernel.org/all/20260918054851.26083-1-kartikey406@gmail.com/T/ [v1]
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
v2:
- Remove the dev_dbg() in free_imon_context(), as suggested by
  Sean Young.
---
 drivers/media/rc/imon.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index 049a73b5f882..562a70186db4 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -501,7 +501,7 @@ static void free_imon_context(struct imon_context *ictx)
 	usb_free_urb(ictx->rx_urb_intf1);
 	kfree_rcu(ictx, rcu);
 
-	dev_dbg(dev, "%s: iMON context freed\n", __func__);
+	put_device(dev);
 }
 
 /*
@@ -2253,7 +2253,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
 
 	mutex_lock(&ictx->lock);
 
-	ictx->dev = dev;
+	ictx->dev = get_device(dev);
 	ictx->usbdev_intf0 = interface_to_usbdev(intf);
 	ictx->rx_urb_intf0 = rx_urb;
 	ictx->tx_urb = tx_urb;
@@ -2314,6 +2314,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
 find_endpoint_failed:
 	mutex_unlock(&ictx->lock);
 	usb_free_urb(tx_urb);
+	put_device(ictx->dev);
 tx_urb_alloc_failed:
 	usb_free_urb(rx_urb);
 rx_urb_alloc_failed:
-- 
2.34.1


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

* Re: [PATCH v2] media: imon: fix use-after-free in display_close via dev_dbg
  2026-09-28 12:12 [PATCH v2] media: imon: fix use-after-free in display_close via dev_dbg Deepanshu Kartikey
@ 2026-09-28 12:18 ` Deepanshu Kartikey
  2026-09-28 12:25   ` Sean Young
  0 siblings, 1 reply; 3+ messages in thread
From: Deepanshu Kartikey @ 2026-09-28 12:18 UTC (permalink / raw)
  To: sean, mchehab
  Cc: jarod, linux-media, linux-kernel, syzbot+9bfac891bdd42eb708fc

On Mon, Sep 28, 2026 at 5:42 PM Deepanshu Kartikey
<kartikey406@gmail.com> wrote:
>
> ictx->dev is a raw pointer to the usb_interface's embedded device,
> cached in imon_init_intf0() without taking a reference. On
> disconnect, usb_disconnect() can drop the last reference on the
> interface and free it while a userspace fd for /dev/lcd0 is still
> open. When that fd is later closed, display_close() dereferences
> the now-freed ictx->dev via dev_dbg(), causing a use-after-free.
>
> Fix by pinning the device with get_device() when ictx->dev is
> assigned, and releasing it with put_device() when ictx is freed.
>
> Also drop the dev_dbg() in free_imon_context(), which only printed
> a debug message and is no longer needed.
>
> Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
> Reported-by: syzbot+9bfac891bdd42eb708fc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=9bfac891bdd42eb708fc
> Link: http://lore.kernel.org/all/20260918054851.26083-1-kartikey406@gmail.com/T/ [v1]
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> ---
> v2:
> - Remove the dev_dbg() in free_imon_context(), as suggested by
>   Sean Young.
> ---
>  drivers/media/rc/imon.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
> index 049a73b5f882..562a70186db4 100644
> --- a/drivers/media/rc/imon.c
> +++ b/drivers/media/rc/imon.c
> @@ -501,7 +501,7 @@ static void free_imon_context(struct imon_context *ictx)
>         usb_free_urb(ictx->rx_urb_intf1);
>         kfree_rcu(ictx, rcu);
>
> -       dev_dbg(dev, "%s: iMON context freed\n", __func__);
> +       put_device(dev);
>  }
>
>  /*
> @@ -2253,7 +2253,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
>
>         mutex_lock(&ictx->lock);
>
> -       ictx->dev = dev;
> +       ictx->dev = get_device(dev);
>         ictx->usbdev_intf0 = interface_to_usbdev(intf);
>         ictx->rx_urb_intf0 = rx_urb;
>         ictx->tx_urb = tx_urb;
> @@ -2314,6 +2314,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
>  find_endpoint_failed:
>         mutex_unlock(&ictx->lock);
>         usb_free_urb(tx_urb);
> +       put_device(ictx->dev);
>  tx_urb_alloc_failed:
>         usb_free_urb(rx_urb);
>  rx_urb_alloc_failed:
> --
> 2.34.1
>

Please disregard this patch.

Thanks

Deepanshu

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

* Re: [PATCH v2] media: imon: fix use-after-free in display_close via dev_dbg
  2026-09-28 12:18 ` Deepanshu Kartikey
@ 2026-09-28 12:25   ` Sean Young
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Young @ 2026-09-28 12:25 UTC (permalink / raw)
  To: Deepanshu Kartikey
  Cc: mchehab, jarod, linux-media, linux-kernel, syzbot+9bfac891bdd42eb708fc

On Mon, Sep 28, 2026 at 05:48:26PM +0530, Deepanshu Kartikey wrote:
> On Mon, Sep 28, 2026 at 5:42 PM Deepanshu Kartikey
> <kartikey406@gmail.com> wrote:
> >
> > ictx->dev is a raw pointer to the usb_interface's embedded device,
> > cached in imon_init_intf0() without taking a reference. On
> > disconnect, usb_disconnect() can drop the last reference on the
> > interface and free it while a userspace fd for /dev/lcd0 is still
> > open. When that fd is later closed, display_close() dereferences
> > the now-freed ictx->dev via dev_dbg(), causing a use-after-free.
> >
> > Fix by pinning the device with get_device() when ictx->dev is
> > assigned, and releasing it with put_device() when ictx is freed.
> >
> > Also drop the dev_dbg() in free_imon_context(), which only printed
> > a debug message and is no longer needed.
> >
> > Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
> > Reported-by: syzbot+9bfac891bdd42eb708fc@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=9bfac891bdd42eb708fc
> > Link: http://lore.kernel.org/all/20260918054851.26083-1-kartikey406@gmail.com/T/ [v1]
> > Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> > ---
> > v2:
> > - Remove the dev_dbg() in free_imon_context(), as suggested by
> >   Sean Young.
> > ---
> >  drivers/media/rc/imon.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
> > index 049a73b5f882..562a70186db4 100644
> > --- a/drivers/media/rc/imon.c
> > +++ b/drivers/media/rc/imon.c
> > @@ -501,7 +501,7 @@ static void free_imon_context(struct imon_context *ictx)
> >         usb_free_urb(ictx->rx_urb_intf1);
> >         kfree_rcu(ictx, rcu);
> >
> > -       dev_dbg(dev, "%s: iMON context freed\n", __func__);
> > +       put_device(dev);

Why do you need put_device()?

> >  }
> >
> >  /*
> > @@ -2253,7 +2253,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
> >
> >         mutex_lock(&ictx->lock);
> >
> > -       ictx->dev = dev;
> > +       ictx->dev = get_device(dev);

Why do you need this?


Sean

> >         ictx->usbdev_intf0 = interface_to_usbdev(intf);
> >         ictx->rx_urb_intf0 = rx_urb;
> >         ictx->tx_urb = tx_urb;
> > @@ -2314,6 +2314,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf,
> >  find_endpoint_failed:
> >         mutex_unlock(&ictx->lock);
> >         usb_free_urb(tx_urb);
> > +       put_device(ictx->dev);
> >  tx_urb_alloc_failed:
> >         usb_free_urb(rx_urb);
> >  rx_urb_alloc_failed:
> > --
> > 2.34.1
> >
> 
> Please disregard this patch.
> 
> Thanks
> 
> Deepanshu

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

end of thread, other threads:[~2026-09-28 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28 12:12 [PATCH v2] media: imon: fix use-after-free in display_close via dev_dbg Deepanshu Kartikey
2026-09-28 12:18 ` Deepanshu Kartikey
2026-09-28 12:25   ` Sean Young

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

all inboxes | Powered by JetHome®