Skip to content

Commit 666b90b

Browse files
fbdev: simplefb: 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/20220505220456.366090-1-javierm@redhat.com
1 parent 89bfd40 commit 666b90b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/video/fbdev/simplefb.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ struct simplefb_par {
8484
static void simplefb_clocks_destroy(struct simplefb_par *par);
8585
static void simplefb_regulators_destroy(struct simplefb_par *par);
8686

87+
/*
88+
* fb_ops.fb_destroy is called by the last put_fb_info() call at the end
89+
* of unregister_framebuffer() or fb_release(). Do any cleanup here.
90+
*/
8791
static void simplefb_destroy(struct fb_info *info)
8892
{
8993
struct simplefb_par *par = info->par;
@@ -94,6 +98,8 @@ static void simplefb_destroy(struct fb_info *info)
9498
if (info->screen_base)
9599
iounmap(info->screen_base);
96100

101+
framebuffer_release(info);
102+
97103
if (mem)
98104
release_mem_region(mem->start, resource_size(mem));
99105
}
@@ -545,8 +551,8 @@ static int simplefb_remove(struct platform_device *pdev)
545551
{
546552
struct fb_info *info = platform_get_drvdata(pdev);
547553

554+
/* simplefb_destroy takes care of info cleanup */
548555
unregister_framebuffer(info);
549-
framebuffer_release(info);
550556

551557
return 0;
552558
}

0 commit comments

Comments
 (0)