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

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