mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joas Antonio dos Santos via B4 Relay <devnull+joasantonio108.gmail.com@kernel.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	 syzbot+37578f730d38898f4b74@syzkaller.appspotmail.com,
	 stable@vger.kernel.org,
	Joas Antonio dos Santos <joasantonio108@gmail.com>
Subject: [PATCH] media: dvb-core: fix use-after-free in dvb_remove_device()
Date: Thu, 05 Nov 2026 02:20:14 +0000	[thread overview]
Message-ID: <20261105-dvb-remove-device-uaf-v1-1-a9e091d7c9ae@gmail.com> (raw)

From: Joas Antonio dos Santos <joasantonio108@gmail.com>

dvb_remove_device() calls dvb_device_put() while still holding and
using the dvb_device pointer.  If the put drops the last reference,
dvb_free_device() kfrees the struct, and the subsequent calls to
dvb_media_device_free(), device_destroy(), and list_del() all operate
on freed memory.

The syzbot KASAN report shows the freed kmalloc-256 object being read
at dvb_media_device_free()+0x3a, which dereferences dvbdev->entity
(dvbdev.c:210) after dvb_device_put() in dvb_remove_device() already
freed it via dvb_free_device().

Fix by saving the minor number before releasing the reference and
moving dvb_device_put() to after all accesses to the dvb_device
struct.  This ensures the device remains valid for the entire cleanup
sequence regardless of the reference count.

Found by LLM-assisted code review of syzbot-reported crash patterns.

Reported-by: syzbot+37578f730d38898f4b74@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=37578f730d38898f4b74
Fixes: 0fc044b2b5e2 ("media: dvbdev: adopts refcnt to avoid UAF")
Cc: stable@vger.kernel.org
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
---
 drivers/media/dvb-core/dvbdev.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index d753d3295..b2beacbab 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -593,19 +593,22 @@ EXPORT_SYMBOL(dvb_register_device);
 
 void dvb_remove_device(struct dvb_device *dvbdev)
 {
+	int minor;
+
 	if (!dvbdev)
 		return;
 
+	minor = dvbdev->minor;
+
 	down_write(&minor_rwsem);
-	dvb_minors[dvbdev->minor] = NULL;
-	dvb_device_put(dvbdev);
+	dvb_minors[minor] = NULL;
 	up_write(&minor_rwsem);
 
 	dvb_media_device_free(dvbdev);
-
-	device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor));
-
+	device_destroy(dvb_class, MKDEV(DVB_MAJOR, minor));
 	list_del(&dvbdev->list_head);
+
+	dvb_device_put(dvbdev);
 }
 EXPORT_SYMBOL(dvb_remove_device);
 

---
base-commit: ebcf66fba448879076bfdd1018ac5cda37b912bf
change-id: 20261105-dvb-remove-device-uaf-aea34136c515

Best regards,
-- 
Joas Antonio dos Santos <joasantonio108@gmail.com>



                 reply	other threads:[~2026-11-05  2:20 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=20261105-dvb-remove-device-uaf-v1-1-a9e091d7c9ae@gmail.com \
    --to=devnull+joasantonio108.gmail.com@kernel.org \
    --cc=joasantonio108@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+37578f730d38898f4b74@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®