]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fbdev: fix potential buffer overflow in do_register_framebuffer()
authorYongzhen Zhang <zhangyongzhen@kylinos.cn>
Tue, 1 Jul 2025 09:07:04 +0000 (17:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:25:59 +0000 (16:25 +0200)
[ Upstream commit 523b84dc7ccea9c4d79126d6ed1cf9033cf83b05 ]

The current implementation may lead to buffer overflow when:
1.  Unregistration creates NULL gaps in registered_fb[]
2.  All array slots become occupied despite num_registered_fb < FB_MAX
3.  The registration loop exceeds array bounds

Add boundary check to prevent registered_fb[FB_MAX] access.

Signed-off-by: Yongzhen Zhang <zhangyongzhen@kylinos.cn>
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/video/fbdev/core/fbmem.c

index f8c32c58b5b2c58cd6052dab017a67f90c8c898c..5128ffed6a23b528fff880e219c694d505de66dd 100644 (file)
@@ -1549,6 +1549,9 @@ static int do_register_framebuffer(struct fb_info *fb_info)
                if (!registered_fb[i])
                        break;
 
+       if (i >= FB_MAX)
+               return -ENXIO;
+
        if (!fb_info->modelist.prev || !fb_info->modelist.next)
                INIT_LIST_HEAD(&fb_info->modelist);