Commit 84499c5d authored by Thomas Zimmermann's avatar Thomas Zimmermann Committed by Linus Torvalds

drm/aperture: Run fbdev removal before internal helpers

Always run fbdev removal first to remove simpledrm via sysfb_disable().
This clears the internal state.

The later call to drm_aperture_detach_drivers() then does nothing.
Otherwise, with drm_aperture_detach_drivers() running first, the call to
sysfb_disable() uses inconsistent state.

Example backtrace show below:

  BUG: KASAN: use-after-free in device_del+0x79/0x5f0
  Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
  CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5.19.0-rc2-1-default+ #1689
  Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
  Call Trace:
    device_del+0x79/0x5f0
    platform_device_del.part.0+0x19/0xe0
    platform_device_unregister+0x1c/0x30
    sysfb_disable+0x2d/0x70
    remove_conflicting_framebuffers+0x1c/0xf0
    remove_conflicting_pci_framebuffers+0x130/0x1a0
    drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
    mgag200_pci_probe+0x2d/0x140 [mgag200]
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Fixes: 873eb3b1 ("fbdev: Disable sysfb device registration when removing conflicting FBs")
Cc: Javier Martinez Canillas <javierm@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Changcheng Deng <deng.changcheng@zte.com.cn>
Reviewed-by: default avatarZack Rusin <zackr@vmware.com>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent de2a3477
...@@ -329,15 +329,7 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, ...@@ -329,15 +329,7 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
const struct drm_driver *req_driver) const struct drm_driver *req_driver)
{ {
resource_size_t base, size; resource_size_t base, size;
int bar, ret = 0; int bar, ret;
for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
continue;
base = pci_resource_start(pdev, bar);
size = pci_resource_len(pdev, bar);
drm_aperture_detach_drivers(base, size);
}
/* /*
* WARNING: Apparently we must kick fbdev drivers before vgacon, * WARNING: Apparently we must kick fbdev drivers before vgacon,
...@@ -345,9 +337,21 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, ...@@ -345,9 +337,21 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
*/ */
#if IS_REACHABLE(CONFIG_FB) #if IS_REACHABLE(CONFIG_FB)
ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name); ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
if (ret)
return ret;
#endif #endif
if (ret == 0)
ret = vga_remove_vgacon(pdev); ret = vga_remove_vgacon(pdev);
if (ret)
return ret; return ret;
for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
continue;
base = pci_resource_start(pdev, bar);
size = pci_resource_len(pdev, bar);
drm_aperture_detach_drivers(base, size);
}
return 0;
} }
EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers); EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment