Skip to content

Commit

Permalink
fbdev: Prevent possible use-after-free in fb_release()
Browse files Browse the repository at this point in the history
Most fbdev drivers have issues with the fb_info lifetime, because call to
framebuffer_release() from their driver's .remove callback, rather than
doing from fbops.fb_destroy callback.

Doing that will destroy the fb_info too early, while references to it may
still exist, leading to a use-after-free error.

To prevent this, check the fb_info reference counter when attempting to
kfree the data structure in framebuffer_release(). That will leak it but
at least will prevent the mentioned error.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220505220413.365977-1-javierm@redhat.com
  • Loading branch information
Daniel Vetter authored and Javier Martinez Canillas committed May 6, 2022
1 parent 135332f commit 89bfd40
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/video/fbdev/core/fbsysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void framebuffer_release(struct fb_info *info)
{
if (!info)
return;

if (WARN_ON(refcount_read(&info->count)))
return;

kfree(info->apertures);
kfree(info);
}
Expand Down

0 comments on commit 89bfd40

Please sign in to comment.