From: xiaopeitux@foxmail.com
To: mchehab@kernel.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, mchehab@s-opensource.com
Cc: Pei Xiao <xiaopei01@kylinos.cn>,
Shuangpeng Bai <shuangpeng.kernel@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 2/2] media: pci: saa7164: fix slab-use-after-free in saa7164_dvb_register
Date: Tue, 2 Jun 2026 14:58:19 +0800 [thread overview]
Message-ID: <tencent_2FA9C0219BBCE44ED2E6E05DAB221EB82F09@qq.com> (raw)
In-Reply-To: <c0cb04583f255e53d39214257bc6a3be8ec8dfb9.1780383298.git.xiaopei01@kylinos.cn>
From: Pei Xiao <xiaopei01@kylinos.cn>
A use-after-free (UAF) issue similar to the one in au0828 was found in
the saa7164 DVB driver. When dvb_register_frontend() fails before the
frontend's kref is initialized (e.g., due to -ENOMEM in kzalloc of
fe->frontend_priv), the error path still calls dvb_frontend_detach(),
which eventually invokes dvb_frontend_put(), immediately frees the frontend
via dvb_frontend_free().
Later, the outer error path in saa7164_dvb_register() again calls
dvb->frontend->ops.release() on the already freed frontend, leading
to a double free and a KASAN slab-use-after-free report.
The call chain is:
saa7164_dvb_register()
-> dvb_register(port)
-> dvb_register_frontend()
(fails before kref_init, e.g., -ENOMEM)
-> fail_frontend:
-> dvb_frontend_detach()
-> dvb_frontend_put()
-> __dvb_frontend_free()
-> dvb_frontend_invoke_release(fe, fe->ops.release)
-> (frontend-specific release, frees the object)
(back to saa7164_dvb_register)
if (ret < 0) {
if (dvb->frontend->ops.release)
dvb->frontend->ops.release(dvb->frontend); // USE-AFTER-FREE
}
The second release is redundant and unsafe because the frontend has
already been freed by the first release via dvb_frontend_put.
Fix this by removing the redundant manual release call in the outer
error path. The frontend is already destroyed by dvb_frontend_put()
in the inner error path, so we only need to set dvb->frontend to NULL
to avoid any further misuse.
Modified by referring to au0828 UAF.
Fixes: ead666000a5f ("media: dvb_frontend: only use kref after initialized")
Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Closes: https://lore.kernel.org/lkml/AAC17221-93BF-436F-92AC-906A18F882F0@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/media/pci/saa7164/saa7164-dvb.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/media/pci/saa7164/saa7164-dvb.c b/drivers/media/pci/saa7164/saa7164-dvb.c
index 3eb749db1ca7..ba6e83b360ac 100644
--- a/drivers/media/pci/saa7164/saa7164-dvb.c
+++ b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -727,8 +727,10 @@ int saa7164_dvb_register(struct saa7164_port *port)
/* register everything */
ret = dvb_register(port);
if (ret < 0) {
- if (dvb->frontend->ops.release)
- dvb->frontend->ops.release(dvb->frontend);
+ /* dvb->frontend freed in dvb_frontend_put, now we can set
+ * frontend to NULL
+ */
+ dvb->frontend = NULL;
return ret;
}
--
2.25.1
parent reply other threads:[~2026-06-02 6:58 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <c0cb04583f255e53d39214257bc6a3be8ec8dfb9.1780383298.git.xiaopei01@kylinos.cn>]
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=tencent_2FA9C0219BBCE44ED2E6E05DAB221EB82F09@qq.com \
--to=xiaopeitux@foxmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mchehab@s-opensource.com \
--cc=shuangpeng.kernel@gmail.com \
--cc=stable@vger.kernel.org \
--cc=xiaopei01@kylinos.cn \
/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®