Linux Media Controller development
 help / color / mirror / Atom feed
From: ThangNN99 <ngocthang2710.1999@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	ThangNN99 <ngocthang2710.1999@gmail.com>,
	syzbot+2a3de29133b40e8f69f3@syzkaller.appspotmail.com
Subject: [PATCH] media: as102: init mutexes before registering the dvb adapter
Date: Tue,  1 Sep 2026 20:31:00 +0700	[thread overview]
Message-ID: <20260901133100.15692-1-ngocthang2710.1999@gmail.com> (raw)

as102_dvb_register() calls dvb_register_adapter() and
dvb_register_frontend() before mutex_init()'ing bus_adap.lock and
sem. Both mutexes live inside the kzalloc'd as102_dev, so until
mutex_init() runs they are all-zero, uninitialized memory.

dvb_register_frontend() makes /dev/dvb/adapterX/frontendY openable
right away, and open() reaches as102_stream_ctrl(), which locks
bus_adap.lock. Likewise, dvb_dmxdev_init() exposes as102_dev->sem to
the demux start/stop_feed callbacks well before the two
mutex_init() calls near the end of the function run. A concurrent
open() racing the tail of as102_dvb_register() can thus lock a
mutex that was never initialized: lockdep reports this as "trying
to register non-static key", and on a real contended lock it is
worse than a missing annotation, since an uninitialized mutex has
no valid wait list.

Move both mutex_init() calls to the top of the function, before the
adapter is registered, so the locks are always ready before the
device is reachable from userspace.

Reported-by: syzbot+2a3de29133b40e8f69f3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2a3de29133b40e8f69f3
Signed-off-by: ThangNN99 <ngocthang2710.1999@gmail.com>
---
 drivers/media/usb/as102/as102_drv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/as102/as102_drv.c b/drivers/media/usb/as102/as102_drv.c
index 6b1d3528a0a7..5495672c0646 100644
--- a/drivers/media/usb/as102/as102_drv.c
+++ b/drivers/media/usb/as102/as102_drv.c
@@ -287,6 +287,10 @@ int as102_dvb_register(struct as102_dev_t *as102_dev)
 	struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
 	int ret;
 
+	/* locks must be ready before the device nodes become openable */
+	mutex_init(&as102_dev->bus_adap.lock);
+	mutex_init(&as102_dev->sem);
+
 	ret = dvb_register_adapter(&as102_dev->dvb_adap,
 			   as102_dev->name, THIS_MODULE,
 			   dev, adapter_nr);
@@ -341,12 +345,6 @@ int as102_dvb_register(struct as102_dev_t *as102_dev)
 		goto efereg;
 	}
 
-	/* init bus mutex for token locking */
-	mutex_init(&as102_dev->bus_adap.lock);
-
-	/* init start / stop stream mutex */
-	mutex_init(&as102_dev->sem);
-
 	/*
 	 * try to load as102 firmware. If firmware upload failed, we'll be
 	 * able to upload it later.
-- 
2.43.0


                 reply	other threads:[~2026-09-01 13:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260901133100.15692-1-ngocthang2710.1999@gmail.com \
    --to=ngocthang2710.1999@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=syzbot+2a3de29133b40e8f69f3@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