0020-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 06aa91f79f902752cb7e5d22ac0ea8e13bffd056 Mon Sep 17 00:00:00 2001
  2. From: Alexey Makhalov <amakhalov@vmware.com>
  3. Date: Fri, 17 Jul 2020 05:17:26 +0000
  4. Subject: [PATCH] relocator: Fix grub_relocator_alloc_chunk_align() top
  5. memory allocation
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. Current implementation of grub_relocator_alloc_chunk_align()
  10. does not allow allocation of the top byte.
  11. Assuming input args are:
  12. max_addr = 0xfffff000;
  13. size = 0x1000;
  14. And this is valid. But following overflow protection will
  15. unnecessarily move max_addr one byte down (to 0xffffefff):
  16. if (max_addr > ~size)
  17. max_addr = ~size;
  18. ~size + 1 will fix the situation. In addition, check size
  19. for non zero to do not zero max_addr.
  20. Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
  21. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  22. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  23. ---
  24. grub-core/lib/relocator.c | 4 ++--
  25. 1 file changed, 2 insertions(+), 2 deletions(-)
  26. diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
  27. index 5847aac36..f2c1944c2 100644
  28. --- a/grub-core/lib/relocator.c
  29. +++ b/grub-core/lib/relocator.c
  30. @@ -1386,8 +1386,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
  31. };
  32. grub_addr_t min_addr2 = 0, max_addr2;
  33. - if (max_addr > ~size)
  34. - max_addr = ~size;
  35. + if (size && (max_addr > ~size))
  36. + max_addr = ~size + 1;
  37. #ifdef GRUB_MACHINE_PCBIOS
  38. if (min_addr < 0x1000)
  39. --
  40. 2.26.2