mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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: Wed, 16 Sep 2026 18:26:02 -0700	[thread overview]
Message-ID: <6aab41aa.b398a7c9.1f86be.0003.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..39166161d 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -647,6 +647,25 @@ static int sur40_input_setup_events(struct input_dev *input_dev)
 	return 0;
 }
 
+/*
+ * Release the sur40 state once the last reference to the video device is
+ * gone. The video_device is embedded in sur40, so sur40 must not be freed
+ * while an open file descriptor can still reach it (e.g. from the v4l2 core
+ * release path). sur40_disconnect() only drops the reference taken by
+ * v4l2_device_register(), which frees sur40 right away if nothing is open
+ * or defers it to this callback until the last user closes the device.
+ */
+static void sur40_release(struct v4l2_device *v4l2_dev)
+{
+	struct sur40_state *sur40 =
+		container_of(v4l2_dev, struct sur40_state, v4l2);
+
+	v4l2_ctrl_handler_free(&sur40->hdl);
+	v4l2_device_unregister(&sur40->v4l2);
+	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)
@@ -726,6 +745,7 @@ static int sur40_probe(struct usb_interface *interface,
 	}
 
 	/* register the video master device */
+	sur40->v4l2.release = sur40_release;
 	snprintf(sur40->v4l2.name, sizeof(sur40->v4l2.name), "%s", DRIVER_LONG);
 	error = v4l2_device_register(sur40->dev, &sur40->v4l2);
 	if (error) {
@@ -827,14 +847,18 @@ static void sur40_disconnect(struct usb_interface *interface)
 
 	input_unregister_device(sur40->input);
 
-	v4l2_ctrl_handler_free(&sur40->hdl);
+	v4l2_device_disconnect(&sur40->v4l2);
 	video_unregister_device(&sur40->vdev);
-	v4l2_device_unregister(&sur40->v4l2);
-
-	kfree(sur40->bulk_in_buffer);
-	kfree(sur40);
 
 	usb_set_intfdata(interface, NULL);
+
+	/*
+	 * Drop the reference taken by v4l2_device_register(). The state is
+	 * only freed from sur40_release() once the last video device user is
+	 * gone, so an open device node cannot use the freed memory.
+	 */
+	v4l2_device_put(&sur40->v4l2);
+
 	dev_dbg(&interface->dev, "%s is now disconnected\n", DRIVER_DESC);
 }
 

      parent reply	other threads:[~2026-09-17  1:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 16:15 [syzbot] [media?] " 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
2026-09-17  1:26 ` syzbot [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=6aab41aa.b398a7c9.1f86be.0003.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 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®