Blame SOURCES/0379-video-fb-fbfill-Fix-potential-integer-overflow.patch

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