From: sashiko-bot@kernel.org
To: "Deepanshu Kartikey" <kartikey406@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH] Input: sur40 - fix use-after-free in v4l2_release on disconnect
Date: Sat, 12 Sep 2026 04:04:35 +0000 [thread overview]
Message-ID: <20260912040435.863831F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912035306.13130-1-kartikey406@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The `sur40_probe` error path executes a newly added `sur40_video_release` callback synchronously, causing catastrophic Use-After-Frees and double frees of the `sur40` structure.
Pre-existing issues:
- [High] Premature destruction of the V4L2 control handler in `sur40_disconnect` allows active or new ioctls to access freed memory and a destroyed mutex.
--
commit d6c7a72108e0520323af3e9a931c367af91b2e23
Author: Deepanshu Kartikey <kartikey406@gmail.com>
Input: sur40 - fix use-after-free in v4l2_release on disconnect
The commit attempts to fix a use-after-free in v4l2_release on disconnect
by introducing a proper .release callback for the video device. This defers
freeing the sur40 structure until the last reference is dropped.
Tested-by: syzbot+34957180b0ed2581edaf@syzkaller.appspotmail.com
Reported-by: syzbot+34957180b0ed2581edaf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=34957180b0ed2581edaf
> diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
> index 09d8c5f8d09fc..7936f3d78454d 100644
> --- a/drivers/input/touchscreen/sur40.c
> +++ b/drivers/input/touchscreen/sur40.c
[ ... ]
> @@ -820,6 +822,16 @@ static int sur40_probe(struct usb_interface *interface,
> return error;
> }
>
> +static void sur40_video_release(struct video_device *vdev)
> +{
> + struct sur40_state *sur40 = container_of(
> + vdev, struct sur40_state, vdev);
> +
> + v4l2_device_unregister(&sur40->v4l2);
> + kfree(sur40->bulk_in_buffer);
> + kfree(sur40);
> +}
[Severity: High]
If input_register_device() fails in sur40_probe(), the error path calls
video_unregister_device(&sur40->vdev). Since there are no open file
descriptors during probe, won't this synchronously invoke
sur40_video_release() and free the sur40 structure?
The error path in sur40_probe() then continues to execute:
err_unreg_video:
video_unregister_device(&sur40->vdev);
err_free_ctrl:
v4l2_ctrl_handler_free(&sur40->hdl);
err_unreg_v4l2:
v4l2_device_unregister(&sur40->v4l2);
err_free_buffer:
kfree(sur40->bulk_in_buffer);
err_free_input:
input_free_device(input);
err_free_dev:
kfree(sur40);
Does this lead to use-after-free and double-free bugs on the probe error
path?
> +
> /* Unregister device & clean up. */
> static void sur40_disconnect(struct usb_interface *interface)
> {
> @@ -829,10 +841,6 @@ static void sur40_disconnect(struct usb_interface *interface)
>
> v4l2_ctrl_handler_free(&sur40->hdl);
> video_unregister_device(&sur40->vdev);
[Severity: High]
This isn't a bug introduced by this patch, but won't freeing the control
handler here allow a use-after-free if a userspace process holds an open file
descriptor and issues concurrent VIDIOC_S_CTRL ioctls?
If v4l2_ctrl_handler_free() destroys the handler and its mutex while the
video device is still open, concurrent ioctls can access the freed nodes and
destroyed mutex. Should v4l2_ctrl_handler_free() also be deferred until
sur40_video_release()?
> - 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);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260912035306.13130-1-kartikey406@gmail.com?part=1
prev parent reply other threads:[~2026-09-12 4:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 3:53 [PATCH] Input: sur40 - fix use-after-free in v4l2_release on disconnect Deepanshu Kartikey
2026-09-12 4:04 ` sashiko-bot [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=20260912040435.863831F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kartikey406@gmail.com \
--cc=linux-input@vger.kernel.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.