mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
	dmitry.torokhov@gmail.com
Cc: floe@butterbrot.org, linux-input@vger.kernel.org,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+eb4706daf505f9c4b547@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v1 2/2] Input: sur40 - keep device state alive until the video node is released
Date: Wed, 30 Sep 2026 10:05:37 +0200	[thread overview]
Message-ID: <48b7f6ef-e5f9-445e-820d-fdfd1458452b@kernel.org> (raw)
In-Reply-To: <20260920113949.12726-3-ngocthang2710.1999@gmail.com>

On 20/09/2026 13:39, Nguyen Ngoc Thang wrote:
> sur40_disconnect() frees the sur40_state, which embeds the video_device,
> the v4l2_device and the vb2_queue, while a video node may still be open.
> Closing that file afterwards touches freed memory:
> 
>   BUG: KASAN: slab-use-after-free in vb2_core_queue_release+0x12d/0x150
>   Read of size 4 at addr ffff888066fa8aa8 by task v4l_id/28733
>    vb2_core_queue_release+0x12d/0x150
>    vb2_fop_release+0x16e/0x200
>    v4l2_release+0x22c/0x350
>    __fput+0x418/0xa50
>   Freed by task 16811:
>    kfree+0x1c5/0x650
>    sur40_disconnect+0xaf/0x140
> 
> Give the v4l2_device a release callback that frees the bulk buffer and
> the state, and drop the disconnect path's own reference with
> v4l2_device_put(). The last closer of the node then does the freeing.
> The probe error paths never open the node and keep freeing directly.
> 
> Reported-by: syzbot+eb4706daf505f9c4b547@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=eb4706daf505f9c4b547
> Fixes: e831cd251fb9 ("[media] add raw video stream support for Samsung SUR40")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>

Reviewed-by: Hans Verkuil <hverkuil+cisco@kernel.org>

Regards,

	Hans

> ---
>  drivers/input/touchscreen/sur40.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
> index 7020bcf9b81a..efd4fe557cef 100644
> --- a/drivers/input/touchscreen/sur40.c
> +++ b/drivers/input/touchscreen/sur40.c
> @@ -648,6 +648,15 @@ static int sur40_input_setup_events(struct input_dev *input_dev)
>  }
>  
>  /* Check candidate USB interface. */
> +/* Runs once the last video node reference is gone. */
> +static void sur40_release(struct v4l2_device *v4l2)
> +{
> +	struct sur40_state *sur40 = container_of(v4l2, struct sur40_state, v4l2);
> +
> +	kfree(sur40->bulk_in_buffer);
> +	kfree(sur40);
> +}
> +
>  static int sur40_probe(struct usb_interface *interface,
>  		       const struct usb_device_id *id)
>  {
> @@ -733,6 +742,7 @@ static int sur40_probe(struct usb_interface *interface,
>  			"Unable to register video master device.");
>  		goto err_free_buffer;
>  	}
> +	sur40->v4l2.release = sur40_release;
>  
>  	/* initialize the lock and subdevice */
>  	sur40->queue = sur40_queue;
> @@ -831,11 +841,10 @@ static void sur40_disconnect(struct usb_interface *interface)
>  	video_unregister_device(&sur40->vdev);
>  	v4l2_device_unregister(&sur40->v4l2);
>  
> -	kfree(sur40->bulk_in_buffer);
> -	kfree(sur40);
> -
>  	usb_set_intfdata(interface, NULL);
>  	dev_dbg(&interface->dev, "%s is now disconnected\n", DRIVER_DESC);
> +
> +	v4l2_device_put(&sur40->v4l2);
>  }
>  
>  /*


      reply	other threads:[~2026-09-30  8:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 11:39 [PATCH v1 0/2] Input: sur40 - fix UAF/hang on closing the video node after unplug Nguyen Ngoc Thang
2026-09-20 11:39 ` [PATCH v1 1/2] Input: sur40 - don't wait for buffers nothing will complete Nguyen Ngoc Thang
2026-09-30  8:04   ` Hans Verkuil
2026-09-20 11:39 ` [PATCH v1 2/2] Input: sur40 - keep device state alive until the video node is released Nguyen Ngoc Thang
2026-09-30  8:05   ` Hans Verkuil [this message]

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=48b7f6ef-e5f9-445e-820d-fdfd1458452b@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=floe@butterbrot.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+eb4706daf505f9c4b547@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

all inboxes | Powered by JetHome®