Blame SOURCES/0270-efi-uga-use-64-bit-for-fb_base.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Andrei Borzenkov <arvidjaar@gmail.com>
f731ee
Date: Wed, 16 May 2018 13:06:04 -0400
f731ee
Subject: [PATCH] efi/uga: use 64 bit for fb_base
f731ee
f731ee
We get 64 bit from PCI BAR but then truncate by assigning to 32 bit.
f731ee
Make sure to check that pointer does not overflow on 32 bit platform.
f731ee
f731ee
Closes: 50931
f731ee
---
f731ee
 grub-core/video/efi_uga.c | 31 ++++++++++++++++---------------
f731ee
 1 file changed, 16 insertions(+), 15 deletions(-)
f731ee
f731ee
diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c
f731ee
index 464ede874da..1d4091c5631 100644
f731ee
--- a/grub-core/video/efi_uga.c
f731ee
+++ b/grub-core/video/efi_uga.c
f731ee
@@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
f731ee
 
f731ee
 static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
f731ee
 static struct grub_efi_uga_draw_protocol *uga;
f731ee
-static grub_uint32_t uga_fb;
f731ee
+static grub_uint64_t uga_fb;
f731ee
 static grub_uint32_t uga_pitch;
f731ee
 
f731ee
 static struct
f731ee
@@ -52,7 +52,7 @@ static struct
f731ee
 #define FBTEST_COUNT	8
f731ee
 
f731ee
 static int
f731ee
-find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)
f731ee
+find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len)
f731ee
 {
f731ee
   grub_uint32_t *base = (grub_uint32_t *) (grub_addr_t) *fb_base;
f731ee
   int i;
f731ee
@@ -67,7 +67,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)
f731ee
 	    {
f731ee
 	      if ((base[j] & RGB_MASK) == RGB_MAGIC)
f731ee
 		{
f731ee
-		  *fb_base = (grub_uint32_t) (grub_addr_t) base;
f731ee
+		  *fb_base = (grub_uint64_t) (grub_addr_t) base;
f731ee
 		  *line_len = j << 2;
f731ee
 
f731ee
 		  return 1;
f731ee
@@ -84,7 +84,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len)
f731ee
 /* Context for find_framebuf.  */
f731ee
 struct find_framebuf_ctx
f731ee
 {
f731ee
-  grub_uint32_t *fb_base;
f731ee
+  grub_uint64_t *fb_base;
f731ee
   grub_uint32_t *line_len;
f731ee
   int found;
f731ee
 };
f731ee
@@ -120,7 +120,9 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
f731ee
 	      if (i == 5)
f731ee
 		break;
f731ee
 
f731ee
-	      old_bar2 = grub_pci_read (addr + 4);
f731ee
+	      i++;
f731ee
+	      addr += 4;
f731ee
+	      old_bar2 = grub_pci_read (addr);
f731ee
 	    }
f731ee
 	  else
f731ee
 	    old_bar2 = 0;
f731ee
@@ -129,10 +131,15 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
f731ee
 	  base64 <<= 32;
f731ee
 	  base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK);
f731ee
 
f731ee
-	  grub_dprintf ("fb", "%s(%d): 0x%llx\n",
f731ee
+	  grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n",
f731ee
 			((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ?
f731ee
-			"VMEM" : "MMIO"), i,
f731ee
-		       (unsigned long long) base64);
f731ee
+			"VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i,
f731ee
+			base64);
f731ee
+
f731ee
+#if GRUB_CPU_SIZEOF_VOID_P == 4
f731ee
+	  if (old_bar2)
f731ee
+	    continue;
f731ee
+#endif
f731ee
 
f731ee
 	  if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! ctx->found))
f731ee
 	    {
f731ee
@@ -140,12 +147,6 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
f731ee
 	      if (find_line_len (ctx->fb_base, ctx->line_len))
f731ee
 		ctx->found++;
f731ee
 	    }
f731ee
-
f731ee
-	  if (type == GRUB_PCI_ADDR_MEM_TYPE_64)
f731ee
-	    {
f731ee
-	      i++;
f731ee
-	      addr += 4;
f731ee
-	    }
f731ee
 	}
f731ee
     }
f731ee
 
f731ee
@@ -153,7 +154,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
f731ee
 }
f731ee
 
f731ee
 static int
f731ee
-find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len)
f731ee
+find_framebuf (grub_uint64_t *fb_base, grub_uint32_t *line_len)
f731ee
 {
f731ee
   struct find_framebuf_ctx ctx = {
f731ee
     .fb_base = fb_base,