All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Drif Abdelmalek Mohamed Said" <drifabdelmalekmohamedsaid@gmail.com>
Cc: linux-usb@vger.kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH] media: em28xx: fix v4l2 use-after-free after failed init
Date: Sat, 31 Oct 2026 20:55:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-192132@kernel.org> (raw)
In-Reply-To: <20261031204723.1415-1-drifabdelmalekmohamedsaid@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: em28xx: missing mutex_unlock() in em28xx_v4l2_fini() when v4l2 is NULL
--

commit 5132f3a1057e95055bbcd81d79b2a705ab167335
Author: Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com>

media: em28xx: fix v4l2 use-after-free after failed init

This commit fixes a use-after-free when em28xx_v4l2_init() fails after
v4l2_device_register() by clearing dev->v4l2 under dev->lock on the error
path and reading dev->v4l2 under dev->lock in em28xx_v4l2_fini().

> diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
> index 84424284d4869..572e6835b851f 100644
> --- a/drivers/media/usb/em28xx/em28xx-video.c
> +++ b/drivers/media/usb/em28xx/em28xx-video.c
> @@ -2414,7 +2414,7 @@ static int em28xx_v4l2_open(struct file *filp)
>   */
>  static int em28xx_v4l2_fini(struct em28xx *dev)
>  {
> -	struct em28xx_v4l2 *v4l2 = dev->v4l2;
> +	struct em28xx_v4l2 *v4l2;
>  
>  	if (dev->is_audio_only) {
>  		/* Shouldn't initialize IR for this interface */
> @@ -2426,13 +2426,15 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
>  		return 0;
>  	}
>  
> -	if (!v4l2)
> -		return 0;
> -
>  	dev_info(&dev->intf->dev, "Closing video extension\n");
>  
>  	mutex_lock(&dev->lock);
>  
> +	/* matches em28xx_v4l2_init error paths */
> +	v4l2 = dev->v4l2;
> +	if (!v4l2)
> +		return 0;

[Severity: High]
Does this early return in em28xx_v4l2_fini() leak dev->lock when dev->v4l2
is NULL?

When em28xx_v4l2_init() fails (including the unregister_dev error path where
this patch sets dev->v4l2 = NULL), dev->v4l2 is NULL when em28xx_v4l2_fini()
runs later during USB disconnect or module unload. Returning 0 here without
calling mutex_unlock(&dev->lock) leaves dev->lock held.

During USB disconnect in drivers/media/usb/em28xx/em28xx-cards.c,
em28xx_usb_disconnect() calls em28xx_release_resources(dev) immediately
after em28xx_close_extension(dev):

em28xx_usb_disconnect()
  em28xx_close_extension(dev)
    ops->fini(dev) -> em28xx_v4l2_fini(dev)
      mutex_lock(&dev->lock);
      if (!v4l2)
          return 0;
  em28xx_release_resources(dev)
    mutex_lock(&dev->lock);

Wouldn't this immediately self-deadlock on dev->lock?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031204723.1415-1-drifabdelmalekmohamedsaid@gmail.com?part=1

  reply	other threads:[~2026-10-31 20:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 20:47 [PATCH] media: em28xx: fix v4l2 use-after-free after failed init Drif Abdelmalek Mohamed Said
2026-10-31 20:55 ` sashiko-bot [this message]
2026-11-01 21:14 ` [syzbot ci] " syzbot ci

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=sashiko-outbox-192132@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=drifabdelmalekmohamedsaid@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.