|
|
80913e |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
80913e |
From: Darren Kenny <darren.kenny@oracle.com>
|
|
|
80913e |
Date: Wed, 4 Nov 2020 14:43:44 +0000
|
|
|
80913e |
Subject: [PATCH] video/fb/video_fb: Fix multiple integer overflows
|
|
|
80913e |
|
|
|
80913e |
The calculation of the unsigned 64-bit value is being generated by
|
|
|
80913e |
multiplying 2, signed or unsigned, 32-bit integers which may overflow
|
|
|
80913e |
before promotion to unsigned 64-bit. Fix all of them.
|
|
|
80913e |
|
|
|
80913e |
Fixes: CID 73703, CID 73767, CID 73833
|
|
|
80913e |
|
|
|
80913e |
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
|
|
|
80913e |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
80913e |
---
|
|
|
80913e |
grub-core/video/fb/video_fb.c | 52 ++++++++++++++++++++++++++++++-------------
|
|
|
80913e |
1 file changed, 36 insertions(+), 16 deletions(-)
|
|
|
80913e |
|
|
|
80913e |
diff --git a/grub-core/video/fb/video_fb.c b/grub-core/video/fb/video_fb.c
|
|
|
b32e65 |
index 1a602c8b2..1c9a138dc 100644
|
|
|
80913e |
--- a/grub-core/video/fb/video_fb.c
|
|
|
80913e |
+++ b/grub-core/video/fb/video_fb.c
|
|
|
80913e |
@@ -25,6 +25,7 @@
|
|
|
80913e |
#include <grub/fbutil.h>
|
|
|
80913e |
#include <grub/bitmap.h>
|
|
|
80913e |
#include <grub/dl.h>
|
|
|
80913e |
+#include <grub/safemath.h>
|
|
|
80913e |
|
|
|
80913e |
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
80913e |
|
|
|
80913e |
@@ -1417,15 +1418,23 @@ doublebuf_blit_update_screen (void)
|
|
|
80913e |
{
|
|
|
80913e |
if (framebuffer.current_dirty.first_line
|
|
|
80913e |
<= framebuffer.current_dirty.last_line)
|
|
|
80913e |
- grub_memcpy ((char *) framebuffer.pages[0]
|
|
|
80913e |
- + framebuffer.current_dirty.first_line
|
|
|
80913e |
- * framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
- (char *) framebuffer.back_target->data
|
|
|
80913e |
- + framebuffer.current_dirty.first_line
|
|
|
80913e |
- * framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
- framebuffer.back_target->mode_info.pitch
|
|
|
80913e |
- * (framebuffer.current_dirty.last_line
|
|
|
80913e |
- - framebuffer.current_dirty.first_line));
|
|
|
80913e |
+ {
|
|
|
80913e |
+ grub_size_t copy_size;
|
|
|
80913e |
+
|
|
|
80913e |
+ if (grub_sub (framebuffer.current_dirty.last_line,
|
|
|
80913e |
+ framebuffer.current_dirty.first_line, ©_size) ||
|
|
|
80913e |
+ grub_mul (framebuffer.back_target->mode_info.pitch, copy_size, ©_size))
|
|
|
80913e |
+ {
|
|
|
80913e |
+ /* Shouldn't happen, but if it does we've a bug. */
|
|
|
80913e |
+ return GRUB_ERR_BUG;
|
|
|
80913e |
+ }
|
|
|
80913e |
+
|
|
|
80913e |
+ grub_memcpy ((char *) framebuffer.pages[0] + framebuffer.current_dirty.first_line *
|
|
|
80913e |
+ framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
+ (char *) framebuffer.back_target->data + framebuffer.current_dirty.first_line *
|
|
|
80913e |
+ framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
+ copy_size);
|
|
|
80913e |
+ }
|
|
|
80913e |
framebuffer.current_dirty.first_line
|
|
|
80913e |
= framebuffer.back_target->mode_info.height;
|
|
|
80913e |
framebuffer.current_dirty.last_line = 0;
|
|
|
80913e |
@@ -1439,7 +1448,7 @@ grub_video_fb_doublebuf_blit_init (struct grub_video_fbrender_target **back,
|
|
|
80913e |
volatile void *framebuf)
|
|
|
80913e |
{
|
|
|
80913e |
grub_err_t err;
|
|
|
80913e |
- grub_size_t page_size = mode_info.pitch * mode_info.height;
|
|
|
80913e |
+ grub_size_t page_size = (grub_size_t) mode_info.pitch * mode_info.height;
|
|
|
80913e |
|
|
|
80913e |
framebuffer.offscreen_buffer = grub_zalloc (page_size);
|
|
|
80913e |
if (! framebuffer.offscreen_buffer)
|
|
|
80913e |
@@ -1482,12 +1491,23 @@ doublebuf_pageflipping_update_screen (void)
|
|
|
80913e |
last_line = framebuffer.previous_dirty.last_line;
|
|
|
80913e |
|
|
|
80913e |
if (first_line <= last_line)
|
|
|
80913e |
- grub_memcpy ((char *) framebuffer.pages[framebuffer.render_page]
|
|
|
80913e |
- + first_line * framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
- (char *) framebuffer.back_target->data
|
|
|
80913e |
- + first_line * framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
- framebuffer.back_target->mode_info.pitch
|
|
|
80913e |
- * (last_line - first_line));
|
|
|
80913e |
+ {
|
|
|
80913e |
+ grub_size_t copy_size;
|
|
|
80913e |
+
|
|
|
80913e |
+ if (grub_sub (last_line, first_line, ©_size) ||
|
|
|
80913e |
+ grub_mul (framebuffer.back_target->mode_info.pitch, copy_size, ©_size))
|
|
|
80913e |
+ {
|
|
|
80913e |
+ /* Shouldn't happen, but if it does we've a bug. */
|
|
|
80913e |
+ return GRUB_ERR_BUG;
|
|
|
80913e |
+ }
|
|
|
80913e |
+
|
|
|
80913e |
+ grub_memcpy ((char *) framebuffer.pages[framebuffer.render_page] + first_line *
|
|
|
80913e |
+ framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
+ (char *) framebuffer.back_target->data + first_line *
|
|
|
80913e |
+ framebuffer.back_target->mode_info.pitch,
|
|
|
80913e |
+ copy_size);
|
|
|
80913e |
+ }
|
|
|
80913e |
+
|
|
|
80913e |
framebuffer.previous_dirty = framebuffer.current_dirty;
|
|
|
80913e |
framebuffer.current_dirty.first_line
|
|
|
80913e |
= framebuffer.back_target->mode_info.height;
|