Blame SOURCES/0299-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c294fc
From: Alexey Makhalov <amakhalov@vmware.com>
c294fc
Date: Fri, 17 Jul 2020 05:17:26 +0000
9723a8
Subject: [PATCH] relocator: Fix grub_relocator_alloc_chunk_align() top memory
9723a8
 allocation
c294fc
c294fc
Current implementation of grub_relocator_alloc_chunk_align()
c294fc
does not allow allocation of the top byte.
c294fc
c294fc
Assuming input args are:
c294fc
  max_addr = 0xfffff000;
c294fc
  size = 0x1000;
c294fc
c294fc
And this is valid. But following overflow protection will
c294fc
unnecessarily move max_addr one byte down (to 0xffffefff):
c294fc
  if (max_addr > ~size)
c294fc
    max_addr = ~size;
c294fc
c294fc
~size + 1 will fix the situation. In addition, check size
c294fc
for non zero to do not zero max_addr.
c294fc
c294fc
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
c294fc
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
c294fc
Upstream-commit-id: ab80a97eb1f
c294fc
---
c294fc
 grub-core/lib/relocator.c | 4 ++--
c294fc
 1 file changed, 2 insertions(+), 2 deletions(-)
c294fc
c294fc
diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
c294fc
index 5847aac3643..f2c1944c28d 100644
c294fc
--- a/grub-core/lib/relocator.c
c294fc
+++ b/grub-core/lib/relocator.c
c294fc
@@ -1386,8 +1386,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
c294fc
   };
c294fc
   grub_addr_t min_addr2 = 0, max_addr2;
c294fc
 
c294fc
-  if (max_addr > ~size)
c294fc
-    max_addr = ~size;
c294fc
+  if (size && (max_addr > ~size))
c294fc
+    max_addr = ~size + 1;
c294fc
 
c294fc
 #ifdef GRUB_MACHINE_PCBIOS
c294fc
   if (min_addr < 0x1000)