Skip to content

Commit b3c9a92

Browse files
fbdev: vesafb: 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/20220505220631.366371-1-javierm@redhat.com
1 parent d258d00 commit b3c9a92

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/video/fbdev/vesafb.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
179179
return err;
180180
}
181181

182+
/*
183+
* fb_ops.fb_destroy is called by the last put_fb_info() call at the end
184+
* of unregister_framebuffer() or fb_release(). Do any cleanup here.
185+
*/
182186
static void vesafb_destroy(struct fb_info *info)
183187
{
184188
struct vesafb_par *par = info->par;
@@ -188,6 +192,8 @@ static void vesafb_destroy(struct fb_info *info)
188192
if (info->screen_base)
189193
iounmap(info->screen_base);
190194
release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
195+
196+
framebuffer_release(info);
191197
}
192198

193199
static struct fb_ops vesafb_ops = {
@@ -484,10 +490,10 @@ static int vesafb_remove(struct platform_device *pdev)
484490
{
485491
struct fb_info *info = platform_get_drvdata(pdev);
486492

493+
/* vesafb_destroy takes care of info cleanup */
487494
unregister_framebuffer(info);
488495
if (((struct vesafb_par *)(info->par))->region)
489496
release_region(0x3c0, 32);
490-
framebuffer_release(info);
491497

492498
return 0;
493499
}

0 commit comments

Comments
 (0)