|
|
9723a8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
9723a8 |
From: Darren Kenny <darren.kenny@oracle.com>
|
|
|
9723a8 |
Date: Wed, 4 Nov 2020 15:10:51 +0000
|
|
|
9723a8 |
Subject: [PATCH] video/fb/fbfill: Fix potential integer overflow
|
|
|
9723a8 |
|
|
|
9723a8 |
The multiplication of 2 unsigned 32-bit integers may overflow before
|
|
|
9723a8 |
promotion to unsigned 64-bit. We should ensure that the multiplication
|
|
|
9723a8 |
is done with overflow detection. Additionally, use grub_sub() for
|
|
|
9723a8 |
subtraction.
|
|
|
9723a8 |
|
|
|
9723a8 |
Fixes: CID 73640, CID 73697, CID 73702, CID 73823
|
|
|
9723a8 |
|
|
|
9723a8 |
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
|
|
|
9723a8 |
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
|
|
|
9723a8 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
9723a8 |
---
|
|
|
9723a8 |
grub-core/video/fb/fbfill.c | 17 +++++++++++++----
|
|
|
9723a8 |
1 file changed, 13 insertions(+), 4 deletions(-)
|
|
|
9723a8 |
|
|
|
9723a8 |
diff --git a/grub-core/video/fb/fbfill.c b/grub-core/video/fb/fbfill.c
|
|
|
b71686 |
index 11816d07a..a37acd1e2 100644
|
|
|
9723a8 |
--- a/grub-core/video/fb/fbfill.c
|
|
|
9723a8 |
+++ b/grub-core/video/fb/fbfill.c
|
|
|
9723a8 |
@@ -31,6 +31,7 @@
|
|
|
9723a8 |
#include <grub/fbfill.h>
|
|
|
9723a8 |
#include <grub/fbutil.h>
|
|
|
9723a8 |
#include <grub/types.h>
|
|
|
9723a8 |
+#include <grub/safemath.h>
|
|
|
9723a8 |
#include <grub/video.h>
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Generic filler that works for every supported mode. */
|
|
|
9723a8 |
@@ -61,7 +62,9 @@ grub_video_fbfill_direct32 (struct grub_video_fbblit_info *dst,
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Calculate the number of bytes to advance from the end of one line
|
|
|
9723a8 |
to the beginning of the next line. */
|
|
|
9723a8 |
- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
|
|
|
9723a8 |
+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) ||
|
|
|
9723a8 |
+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip))
|
|
|
9723a8 |
+ return;
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Get the start address. */
|
|
|
9723a8 |
dstptr = grub_video_fb_get_video_ptr (dst, x, y);
|
|
|
9723a8 |
@@ -98,7 +101,9 @@ grub_video_fbfill_direct24 (struct grub_video_fbblit_info *dst,
|
|
|
9723a8 |
#endif
|
|
|
9723a8 |
/* Calculate the number of bytes to advance from the end of one line
|
|
|
9723a8 |
to the beginning of the next line. */
|
|
|
9723a8 |
- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
|
|
|
9723a8 |
+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) ||
|
|
|
9723a8 |
+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip))
|
|
|
9723a8 |
+ return;
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Get the start address. */
|
|
|
9723a8 |
dstptr = grub_video_fb_get_video_ptr (dst, x, y);
|
|
|
9723a8 |
@@ -131,7 +136,9 @@ grub_video_fbfill_direct16 (struct grub_video_fbblit_info *dst,
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Calculate the number of bytes to advance from the end of one line
|
|
|
9723a8 |
to the beginning of the next line. */
|
|
|
9723a8 |
- rowskip = (dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width);
|
|
|
9723a8 |
+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) ||
|
|
|
9723a8 |
+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip))
|
|
|
9723a8 |
+ return;
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Get the start address. */
|
|
|
9723a8 |
dstptr = grub_video_fb_get_video_ptr (dst, x, y);
|
|
|
9723a8 |
@@ -161,7 +168,9 @@ grub_video_fbfill_direct8 (struct grub_video_fbblit_info *dst,
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Calculate the number of bytes to advance from the end of one line
|
|
|
9723a8 |
to the beginning of the next line. */
|
|
|
9723a8 |
- rowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width;
|
|
|
9723a8 |
+ if (grub_mul (dst->mode_info->bytes_per_pixel, width, &rowskip) ||
|
|
|
9723a8 |
+ grub_sub (dst->mode_info->pitch, rowskip, &rowskip))
|
|
|
9723a8 |
+ return;
|
|
|
9723a8 |
|
|
|
9723a8 |
/* Get the start address. */
|
|
|
9723a8 |
dstptr = grub_video_fb_get_video_ptr (dst, x, y);
|