Skip to content

Commit d258d00

Browse files
fbdev: efifb: Cleanup fb_info in .fb_destroy rather than .remove
The driver is calling framebuffer_release() in its .remove callback, but this will cause the struct fb_info to be freed too early. Since it could be that a reference is still hold to it if user-space opened the fbdev. This would lead to a use-after-free error if the framebuffer device was unregistered but later a user-space process tries to close the fbdev fd. To prevent this, move the framebuffer_release() call to fb_ops.fb_destroy instead of doing it in the driver's .remove callback. Strictly speaking, the code flow in the driver is still wrong because all the hardware cleanupd (i.e: iounmap) should be done in .remove while the software cleanup (i.e: releasing the framebuffer) should be done in the .fb_destroy handler. But this at least makes to match the behavior before commit 27599aa ("fbdev: Hot-unplug firmware fb devices on forced removal"). Fixes: 27599aa ("fbdev: Hot-unplug firmware fb devices on forced removal") Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20220505220540.366218-1-javierm@redhat.com
1 parent 666b90b commit d258d00

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/video/fbdev/efifb.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ static void efifb_show_boot_graphics(struct fb_info *info)
243243
static inline void efifb_show_boot_graphics(struct fb_info *info) {}
244244
#endif
245245

246+
/*
247+
* fb_ops.fb_destroy is called by the last put_fb_info() call at the end
248+
* of unregister_framebuffer() or fb_release(). Do any cleanup here.
249+
*/
246250
static void efifb_destroy(struct fb_info *info)
247251
{
248252
if (efifb_pci_dev)
@@ -254,6 +258,9 @@ static void efifb_destroy(struct fb_info *info)
254258
else
255259
memunmap(info->screen_base);
256260
}
261+
262+
framebuffer_release(info);
263+
257264
if (request_mem_succeeded)
258265
release_mem_region(info->apertures->ranges[0].base,
259266
info->apertures->ranges[0].size);
@@ -620,9 +627,9 @@ static int efifb_remove(struct platform_device *pdev)
620627
{
621628
struct fb_info *info = platform_get_drvdata(pdev);
622629

630+
/* efifb_destroy takes care of info cleanup */
623631
unregister_framebuffer(info);
624632
sysfs_remove_groups(&pdev->dev.kobj, efifb_groups);
625-
framebuffer_release(info);
626633

627634
return 0;
628635
}

0 commit comments

Comments
 (0)