summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2022-05-06 00:04:13 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-05-25 09:57:35 +0200
commit4f631f9f9d08a7c6e47d2f19d866435fe70c3db5 (patch)
tree793c6e6cadb3cbec9981bf2a43387a77f196109a
parent92dc6278dec983f7dfc33f28bb929d5ca92087ac (diff)
downloadlinux-4f631f9f9d08a7c6e47d2f19d866435fe70c3db5.tar.gz
linux-4f631f9f9d08a7c6e47d2f19d866435fe70c3db5.tar.bz2
linux-4f631f9f9d08a7c6e47d2f19d866435fe70c3db5.zip
fbdev: Prevent possible use-after-free in fb_release()
[ Upstream commit 89bfd4017e58faaf70411555e7f508495114e90b ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/video/fbdev/core/fbsysfs.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c
index 65dae05fff8e..ce699396d6ba 100644
--- a/drivers/video/fbdev/core/fbsysfs.c
+++ b/drivers/video/fbdev/core/fbsysfs.c
@@ -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);
}