From: syzbot <syzbot+34957180b0ed2581edaf@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org
Subject: Forwarded: [PATCH] KASAN: slab-use-after-free Read in v4l2_release (3)
Date: Mon, 14 Sep 2026 18:38:51 -0700 [thread overview]
Message-ID: <6aa8a1ab.f670cee1.72fc4.0022.GAE@google.com> (raw)
In-Reply-To: <6aa4291e.f81106d8.2ab401.001e.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] KASAN: slab-use-after-free Read in v4l2_release (3)
Author: jchuang26@m.fudan.edu.cn
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Reported-by: syzbot+34957180b0ed2581edaf@syzkaller.appspotmail.com
diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index 09d8c5f8d..4da6ad1c3 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -647,6 +647,24 @@ static int sur40_input_setup_events(struct input_dev *input_dev)
return 0;
}
+/*
+ * Final cleanup of the driver state. This runs through v4l2_device_put()
+ * once the last reference to the v4l2_device is gone, i.e. after
+ * video_unregister_device() and after every open file descriptor of the
+ * video node has been closed. Freeing sur40 earlier (for instance
+ * directly in sur40_disconnect()) would let v4l2_release() access the
+ * already freed video_device.
+ */
+static void sur40_v4l2_release(struct v4l2_device *v4l2_dev)
+{
+ struct sur40_state *sur40 = container_of(v4l2_dev, struct sur40_state, v4l2);
+
+ v4l2_device_unregister(&sur40->v4l2);
+ v4l2_ctrl_handler_free(&sur40->hdl);
+ kfree(sur40->bulk_in_buffer);
+ kfree(sur40);
+}
+
/* Check candidate USB interface. */
static int sur40_probe(struct usb_interface *interface,
const struct usb_device_id *id)
@@ -727,6 +745,7 @@ static int sur40_probe(struct usb_interface *interface,
/* register the video master device */
snprintf(sur40->v4l2.name, sizeof(sur40->v4l2.name), "%s", DRIVER_LONG);
+ sur40->v4l2.release = sur40_v4l2_release;
error = v4l2_device_register(sur40->dev, &sur40->v4l2);
if (error) {
dev_err(&interface->dev,
@@ -778,7 +797,6 @@ static int sur40_probe(struct usb_interface *interface,
if (sur40->hdl.error) {
dev_err(&interface->dev,
"Unable to register video controls.");
- v4l2_ctrl_handler_free(&sur40->hdl);
error = sur40->hdl.error;
goto err_unreg_v4l2;
}
@@ -787,7 +805,7 @@ static int sur40_probe(struct usb_interface *interface,
if (error) {
dev_err(&interface->dev,
"Unable to register video subdevice.");
- goto err_free_ctrl;
+ goto err_unreg_v4l2;
}
/* register the polled input device */
@@ -806,10 +824,17 @@ static int sur40_probe(struct usb_interface *interface,
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);
+ /*
+ * Drop the reference taken above by v4l2_device_register(). The
+ * last reference releases sur40 via sur40_v4l2_release(), which
+ * also frees the control handler and the bulk buffer.
+ */
+ input_free_device(input);
+ v4l2_device_put(&sur40->v4l2);
+
+ return error;
+
err_free_buffer:
kfree(sur40->bulk_in_buffer);
err_free_input:
@@ -827,15 +852,19 @@ static void sur40_disconnect(struct usb_interface *interface)
input_unregister_device(sur40->input);
- v4l2_ctrl_handler_free(&sur40->hdl);
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);
+
+ /*
+ * Release the reference taken by v4l2_device_register(). If the
+ * video node is still open, sur40_v4l2_release() is deferred until
+ * the last file descriptor is closed, so sur40 stays valid for
+ * v4l2_release().
+ */
+ v4l2_device_put(&sur40->v4l2);
}
/*
next prev parent reply other threads:[~2026-09-15 1:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 16:15 [syzbot] [media?] KASAN: slab-use-after-free Read in v4l2_release (3) syzbot
2026-09-12 1:03 ` Forwarded: [PATCH] Input: sur40 - fix use-after-free in v4l2_release on disconnect syzbot
2026-09-14 11:46 ` Forwarded: [PATCH] KASAN: slab-use-after-free Read in v4l2_release (3) syzbot
2026-09-15 1:38 ` syzbot [this message]
2026-09-17 1:26 ` syzbot
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=6aa8a1ab.f670cee1.72fc4.0022.GAE@google.com \
--to=syzbot+34957180b0ed2581edaf@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
/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.