From: Junxiao Chang <junxiao.chang@intel.com>
To: linux-fbdev@vger.kernel.org
Cc: lethal@linux-sh.org, patchwork-bot@kernel.org, deller@gmx.de,
lili.li@intel.com, junxiao.chang@intel.com
Subject: [PATCH] video: fbdev: don't remove firmware fb device if it is busy
Date: Sat, 30 Apr 2022 10:57:49 +0800 [thread overview]
Message-ID: <20220430025749.2320824-1-junxiao.chang@intel.com> (raw)
When firmware framebuffer is in use, don't remove its platform
device. Or else its fb_info buffer is released by platform remove
hook while device is still opened. This introduces use after free
issue.
A kernel panic example:
CPU: 2 PID: 3425 Comm: psplash Tainted: G U W 5.18.0-rc3
Hardware name: Intel Client Platform/ADP-S DDR5 UDIMM CRB
RIP: 0010:native_queued_spin_lock_slowpath+0x1c7/0x210
RSP: 0018:ffffb3a0c0c2fdb0 EFLAGS: 00010206
RAX: 002dc074ff5c0988 RBX: ffff92e987a5d818 RCX: ffff92e989ba9f40
RDX: 0000000000002067 RSI: ffffffff864344f1 RDI: ffffffff8644183c
RBP: ffff92f10f4abd40 R08: 0000000000000001 R09: ffff92e986dc2188
...
Call Trace:
<TASK>
_raw_spin_lock+0x2c/0x30
__mutex_lock.constprop.0+0x175/0x4f0
? _raw_spin_unlock+0x15/0x30
? list_lru_add+0x124/0x160
fb_release+0x1b/0x60
__fput+0x89/0x240
task_work_run+0x59/0x90
do_exit+0x343/0xaf0
do_group_exit+0x2d/0x90
__x64_sys_exit_group+0x14/0x20
do_syscall_64+0x40/0x90
entry_SYSCALL_64_after_hwframe+0x44/0xae
Fixes: 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal")
Signed-off-by: Junxiao Chang <junxiao.chang@intel.com>
Signed-off-by: Lili Li <lili.li@intel.com>
---
drivers/video/fbdev/core/fbmem.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index a6bb0e438216..ff9b9830b398 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1586,7 +1586,9 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
* framebuffer as before without warning.
*/
do_unregister_framebuffer(registered_fb[i]);
- } else if (dev_is_platform(device)) {
+ } else if (dev_is_platform(device) &&
+ refcount_read(®istered_fb[i]->count) == 1) {
+ /* Remove platform device if it is not in use. */
registered_fb[i]->forced_out = true;
platform_device_unregister(to_platform_device(device));
} else {
--
2.25.1
next reply other threads:[~2022-04-30 2:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-30 2:57 Junxiao Chang [this message]
2022-05-02 7:24 ` [PATCH] video: fbdev: don't remove firmware fb device if it is busy Thomas Zimmermann
2022-05-03 0:38 ` Chang, Junxiao
2022-05-03 7:16 ` Thomas Zimmermann
2022-05-03 12:29 ` Chang, Junxiao
2022-05-03 13:05 ` Thomas Zimmermann
2022-05-03 15:15 ` Javier Martinez Canillas
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=20220430025749.2320824-1-junxiao.chang@intel.com \
--to=junxiao.chang@intel.com \
--cc=deller@gmx.de \
--cc=lethal@linux-sh.org \
--cc=lili.li@intel.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=patchwork-bot@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;
as well as URLs for NNTP newsgroup(s).