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

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