Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH] fbmem: prevent potential use-after-free issues with console_lock()
@ 2022-12-30  6:35 Hang Zhang
  2023-01-02 15:28 ` Helge Deller
  0 siblings, 1 reply; 13+ messages in thread
From: Hang Zhang @ 2022-12-30  6:35 UTC (permalink / raw)
  Cc: Daniel Vetter, Helge Deller, Javier Martinez Canillas,
	Thomas Zimmermann, Sam Ravnborg, Alex Deucher, linux-fbdev,
	dri-devel, linux-kernel, Hang Zhang

In do_fb_ioctl(), user specified "fb_info" can be freed in the callee
fbcon_get_con2fb_map_ioctl() -> set_con2fb_map() ->
con2fb_release_oldinfo(), this free operation is protected by
console_lock() in fbcon_set_con2fb_map_ioctl(), it also results in
the change of certain states such as "minfo->dead" in matroxfb_remove(),
so that it can be checked to avoid use-after-free before the use sites
(e.g., the check at the beginning of matroxfb_ioctl()). However,
the problem is that the use site is not protected by the same locks
as for the free operation, e.g., "default" case in do_fb_ioctl()
can lead to "matroxfb_ioctl()" but it's not protected by console_lock(),
which can invalidate the aforementioned state set and check in a
concurrent setting.

Prevent the potential use-after-free issues by protecting the "default"
case in do_fb_ioctl() with console_lock(), similarly as for many other
cases like "case FBIOBLANK" and "case FBIOPAN_DISPLAY".

Signed-off-by: Hang Zhang <zh.nvgt@gmail.com>
---
 drivers/video/fbdev/core/fbmem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 1e70d8c67653..8b1a1527d18a 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1182,6 +1182,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 		console_unlock();
 		break;
 	default:
+		console_lock();
 		lock_fb_info(info);
 		fb = info->fbops;
 		if (fb->fb_ioctl)
@@ -1189,6 +1190,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
 		else
 			ret = -ENOTTY;
 		unlock_fb_info(info);
+		console_unlock();
 	}
 	return ret;
 }
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-01-06 23:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-30  6:35 [PATCH] fbmem: prevent potential use-after-free issues with console_lock() Hang Zhang
2023-01-02 15:28 ` Helge Deller
2023-01-05 10:21   ` Daniel Vetter
2023-01-05 10:25     ` Daniel Vetter
2023-01-05 18:38       ` Hang Zhang
2023-01-06 18:59         ` Daniel Vetter
2023-01-06 19:58           ` Hang Zhang
2023-01-06 20:05             ` Daniel Vetter
2023-01-06 20:25               ` Hang Zhang
2023-01-06 21:19                 ` Daniel Vetter
2023-01-06 22:12                   ` Hang Zhang
2023-01-06 22:46                     ` Daniel Vetter
2023-01-06 23:19                       ` Hang Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox