video: fbdev: don't remove firmware fb device if it is busy
Subsystems (2)
PATCH 1/1 video: fbdev: don't remove firmware fb device if it is busy
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
--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +3 -1
@@ -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 {
Signature · 1 line
2.25.1
Hi
Am 30.04.22 um 04:57 schrieb Junxiao Chang:
Quoted 4 lines
When firmware framebuffer is in use, don't remove its platform device. Or else its
fb_infobuffer is released by platform remove hook while device is still opened. This introduces use after free issue.
When exactly does this happen? Do you have a reliable way of reproducing it?
Best regards
Thomas
Quoted 47 lines
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/0xaeFixes 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal")Signed-off-by Junxiao Chang <[email protected]>Signed-off-by Lili Li <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +3
-1@@ -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 {
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hi Thomas,
We reproduced this issue with Yocto image + 5.18-rc3 kernel.
If you could try Yocto image and enable psplash, the problem could be reproduced almost every time if psplash is launched before Intel i915 registers 2nd framebuffer.
During Yocto booting up, it launches psplash which opens EFI firmware framebuffer and plays animation. When it exits, fb_release in kernel might access memory which has been released.
Overall process looks like:
1. EFI registers framebuffer in efifb_probe, framebuffer_alloc is called to allocate "struct fb_info" memory;
2. In userspace, psplash is started to play boot animation, it opens framebuffer driver. In fb_open function, it saves fb_info memory to file->private_data;
3. When Intel i915 driver is probed, it registers 2nd framebuffer, and will remove conflicting framebuffer;
4. In do_remove_conflicting_framebuffers, it calls "platform_device_unregister" to remove EFI platform framebuffer device;
5. In EFI framebuffer's efifb_remove function, it calls framebuffer_release to release "struct fb_info" memory which is still use and stored in file->private_data;
6. When psplash user space application exits, it calls fb_release function, and accesses to fb_info memory, but it has been released in step 5. Kernel panic happens.
Our patch is to check whether EFI framebuffer is opened at that time. If it is free(registered_fb[i]->count == 1), go ahead to remove EFI platform device. Or else, just unregister framebuffer to avoid kernel panic.
Thanks,
Junxiao
-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Monday, May 2, 2022 3:24 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busy
Hi
Am 30.04.22 um 04:57 schrieb Junxiao Chang:
Quoted 3 lines
When firmware framebuffer is in use, don't remove its platform device. Or else its
fb_infobuffer is released by platform remove hook while device is still opened. This introduces use after free issue.
When exactly does this happen? Do you have a reliable way of reproducing it?
Best regards
Thomas
Quoted 38 lines
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/0xaeFixes 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forcedremoval")
Signed-off-by Junxiao Chang <[email protected]>Signed-off-by Lili Li <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +0
-0
drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1594
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +3
-1@@ -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 {
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
(cc'ing Javier)
Hi
Am 03.05.22 um 02:38 schrieb Chang, Junxiao:
Quoted 7 lines
Hi Thomas,
We reproduced this issue with Yocto image + 5.18-rc3 kernel.
If you could try Yocto image and enable psplash, the problem could be reproduced almost every time if psplash is launched before Intel i915 registers 2nd framebuffer.During Yocto booting up, it launches psplash which opens EFI firmware framebuffer and plays animation. When it exits,
fb_releasein kernel might access memory which has been released.
Quoted 7 lines
Overall process looks like:
1. EFI registers framebuffer inefifb_probe,framebuffer_allocis called to allocate "structfb_info" memory;
2. In userspace, psplash is started to play boot animation, it opens framebuffer driver. Infb_openfunction, it savesfb_infomemory tofile->private_data;
3. When Intel i915 driver is probed, it registers 2nd framebuffer, and will remove conflicting framebuffer;
4. Indo_remove_conflicting_framebuffers, it calls "platform_device_unregister" to remove EFI platform framebuffer device;
5. In EFI framebuffer'sefifb_removefunction, it callsframebuffer_releaseto release "structfb_info" memory which is still use and stored infile->private_data;
6. When psplash user space application exits, it callsfb_releasefunction, and accesses tofb_infomemory, but it has been released in step 5. Kernel panic happens.
Thanks for the information. We only had a similar report about RPi devices, but we never encountered this problem before.
Quoted 2 lines
Our patch is to check whether EFI framebuffer is opened at that time. If it is
free(registered_fb[i]->count == 1), go ahead to remove EFI platform device. Or else, just unregister framebuffer to avoid kernel panic.
Javier posted a possible fix for the root cause of this problem, but we're still looking for testers. If you have the opportunity, could you
please test the patch at [1] and report back on the results.
Best regards
Thomas
[1] https://lore.kernel.org/dri-devel/[email protected]/T/#u
Quoted 79 lines
Thanks,
Junxiao-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Monday, May 2, 2022 3:24 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busyHi
Am 30.04.22 um 04:57 schrieb Junxiao Chang:
Quoted 3 lines
When firmware framebuffer is in use, don't remove its platform device. Or else its
fb_infobuffer is released by platform remove hook while device is still opened. This introduces use after free issue.When exactly does this happen? Do you have a reliable way of reproducing it?
Best regards
ThomasQuoted 38 lines
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/0xaeFixes 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forcedremoval")
Signed-off-by Junxiao Chang <[email protected]>Signed-off-by Lili Li <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +0
-0drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1594
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +3
-1@@ -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 {--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
We tested Javier's fix, issue couldn't be reproduced anymore.
https://lore.kernel.org/dri-devel/[email protected]/T/#u
But this fix doesn't cover all FB driver's interface:
.get_unmapped_area = get_fb_unmapped_area,
.fsync = fb_deferred_io_fsync,
file_fb_info(file) NULL checking should be added in these two interface functions(get_fb_unmapped_area and fb_deferred_io_fsync) as well?
Regards,
Junxiao
-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Tuesday, May 3, 2022 3:16 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>; Javier Martinez Canillas <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busy
(cc'ing Javier)
Hi
Am 03.05.22 um 02:38 schrieb Chang, Junxiao:
Quoted 7 lines
Hi Thomas,
We reproduced this issue with Yocto image + 5.18-rc3 kernel.
If you could try Yocto image and enable psplash, the problem could be reproduced almost every time if psplash is launched before Intel i915 registers 2nd framebuffer.During Yocto booting up, it launches psplash which opens EFI firmware framebuffer and plays animation. When it exits,
fb_releasein kernel might access memory which has been released.
Quoted 7 lines
Overall process looks like:
1. EFI registers framebuffer inefifb_probe,framebuffer_allocis
called to allocate "structfb_info" memory; 2. In userspace, psplash
is started to play boot animation, it opens framebuffer driver. Infb_openfunction, it savesfb_infomemory tofile->private_data; 3.
When Intel i915 driver is probed, it registers 2nd framebuffer, and
will remove conflicting framebuffer; 4. Indo_remove_conflicting_framebuffers, it calls "platform_device_unregister" to remove EFI platform framebuffer device; 5. In EFI framebuffer'sefifb_removefunction, it callsframebuffer_releaseto release "structfb_info" memory which is still use and stored infile->private_data; 6. When psplash user space application exits, it callsfb_releasefunction, and accesses tofb_infomemory, but it has been released in step 5. Kernel panic happens.
Thanks for the information. We only had a similar report about RPi devices, but we never encountered this problem before.
Quoted 2 lines
Our patch is to check whether EFI framebuffer is opened at that time. If it is
free(registered_fb[i]->count == 1), go ahead to remove EFI platform device. Or else, just unregister framebuffer to avoid kernel panic.
Javier posted a possible fix for the root cause of this problem, but we're still looking for testers. If you have the opportunity, could you
please test the patch at [1] and report back on the results.
Best regards
Thomas
[1]
https://lore.kernel.org/dri-devel/[email protected]/T/#u
Quoted 73 lines
Thanks,
Junxiao-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Monday, May 2, 2022 3:24 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busyHi
Am 30.04.22 um 04:57 schrieb Junxiao Chang:
Quoted 3 lines
When firmware framebuffer is in use, don't remove its platform device. Or else its
fb_infobuffer is released by platform remove hook while device is still opened. This introduces use after free issue.When exactly does this happen? Do you have a reliable way of reproducing it?
Best regards
ThomasQuoted 47 lines
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/0xaeFixes 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forcedremoval")
Signed-off-by Junxiao Chang <[email protected]>Signed-off-by Lili Li <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +3
-1@@ -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));
Quoted 8 lines
drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1594
Quoted 1 line
drivers/video/fbdev/core/fbmem.c +0
-0}else {--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Hi
Am 03.05.22 um 14:29 schrieb Chang, Junxiao:
Quoted 2 lines
We tested Javier's fix, issue couldn't be reproduced anymore.
https://lore.kernel.org/dri-devel/[email protected]/T/#u
Thank you so much.
Best regards
Thomas
Quoted 141 lines
But this fix doesn't cover all FB driver's interface:
.get_unmapped_area =
get_fb_unmapped_area,
.fsync =fb_deferred_io_fsync,
file_fb_info(file)NULL checking should be added in these two interfacefunctions(get_fb_unmapped_area and fb_deferred_io_fsync)as well?Regards,
Junxiao-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Tuesday, May 3, 2022 3:16 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>; Javier Martinez Canillas <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busy(cc'ing Javier)
Hi
Am 03.05.22 um 02:38 schrieb Chang, Junxiao:
Quoted 7 lines
Hi Thomas,
We reproduced this issue with Yocto image + 5.18-rc3 kernel.
If you could try Yocto image and enable psplash, the problem could be reproduced almost every time if psplash is launched before Intel i915 registers 2nd framebuffer.During Yocto booting up, it launches psplash which opens EFI firmware framebuffer and plays animation. When it exits,
fb_releasein kernel might access memory which has been released.Quoted 7 lines
Overall process looks like:
1. EFI registers framebuffer inefifb_probe,framebuffer_allocis
called to allocate "structfb_info" memory; 2. In userspace, psplash
is started to play boot animation, it opens framebuffer driver. Infb_openfunction, it savesfb_infomemory tofile->private_data; 3.
When Intel i915 driver is probed, it registers 2nd framebuffer, and
will remove conflicting framebuffer; 4. Indo_remove_conflicting_framebuffers, it calls "platform_device_unregister" to remove EFI platform framebuffer device; 5. In EFI framebuffer'sefifb_removefunction, it callsframebuffer_releaseto release "structfb_info" memory which is still use and stored infile->private_data; 6. When psplash user space application exits, it callsfb_releasefunction, and accesses tofb_infomemory, but it has been released in step 5. Kernel panic happens.Thanks for the information. We only had a similar report about RPi devices, but we never encountered this problem before.
Quoted 2 lines
Our patch is to check whether EFI framebuffer is opened at that time. If it is
free(registered_fb[i]->count == 1), go ahead to remove EFI platform device. Or else, just unregister framebuffer to avoid kernel panic.Javier posted a possible fix for the root cause of this problem, but we're still looking for testers. If you have the opportunity, could you
please test the patch at [1] and report back on the results.Best regards
Thomas[1]
https://lore.kernel.org/dri-devel/[email protected]/T/#uQuoted 73 lines
Thanks,
Junxiao-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Monday, May 2, 2022 3:24 PM
To: Chang, Junxiao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Li, Lili <[email protected]>
Subject: Re: [PATCH] video: fbdev: don't remove firmware fb device if it is busyHi
Am 30.04.22 um 04:57 schrieb Junxiao Chang:
Quoted 3 lines
When firmware framebuffer is in use, don't remove its platform device. Or else its
fb_infobuffer is released by platform remove hook while device is still opened. This introduces use after free issue.When exactly does this happen? Do you have a reliable way of reproducing it?
Best regards
ThomasQuoted 47 lines
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/0xaeFixes 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forcedremoval")
Signed-off-by Junxiao Chang <[email protected]>Signed-off-by Lili Li <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +3
-1@@ -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));Quoted 8 lines
drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1594
Quoted 1 line
drivers/video/fbdev/core/fbmem.c +0
-0}else {--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Hello Junxiao,
Quoted 3 lines · Junxiao
We tested Javier's fix, issue couldn't be reproduced anymore.
https://lore.kernel.org/dri-devel/[email protected]/T/#u
Thanks for testing!
Quoted 7 lines
But this fix doesn't cover all FB driver's interface:
.get_unmapped_area =
get_fb_unmapped_area,
.fsync =fb_deferred_io_fsync,
file_fb_info(file)NULL checking should be added in these two interfacefunctions(get_fb_unmapped_area and fb_deferred_io_fsync)as well?
Yes, I was about to send a new version adding checks for this but I decided not to. Because by looking at these file ops, I see get_fb_unmapped_area() is only used when:
#if defined(HAVE_ARCH_FB_UNMAPPED_AREA) || \ (defined(CONFIG_FB_PROVIDE_GET_FB_UNMAPPED_AREA) && \ !defined(CONFIG_MMU)) .get_unmapped_area = get_fb_unmapped_area,
#endif
so is not really a common configuration and fb_deferred_io_fsync() is not defined in the same compilation unit, which means that file_fb_info() would have to be exported (and probably renamed to fb_file_fb_info or something), which will make the fix more complex and harder to backport to stable.
The fb_release() handler bug in the other hand is quite easy to trigger, so I'll just keep this fix with the minimum change.
I plan to fix the other two handlers though in a separate patch.
--
Best regards,
Javier Martinez Canillas
Linux Engineering
Red Hat