]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/mm.c (grub_mm_init_region): Skip regions less than
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 18 Sep 2013 18:23:47 +0000 (20:23 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 18 Sep 2013 18:23:47 +0000 (20:23 +0200)
4K before the end.
Reported by: Leif Lindholm

ChangeLog
grub-core/kern/mm.c

index aabb82f0e134c050a3d361575332fbe4842b4b6f..c8edd1ff2d9772949ea8820ef547906ca9fa40b7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,12 @@
        * docs/grub.texi (Networking commands): Add documentation for
        network related commands.
 
+2013-09-18  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/kern/mm.c (grub_mm_init_region): Skip regions less than
+       4K before the end.
+       Reported by: Leif Lindholm
+
 2013-09-18  Pawel Wojtalczyk <eyak@wp.pl>
 2013-09-18  Vladimir Serbinenko  <phcoder@gmail.com>
 
index 959c3bab10fbd3f52a303d79cdcde16941623bab..59e45c7ae5868a0f952ccdf52aca5a5208d2f51f 100644 (file)
@@ -117,6 +117,15 @@ grub_mm_init_region (void *addr, grub_size_t size)
   grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size);
 #endif
 
+  /* Exclude last 4K to avoid overflows. */
+  /* If addr + 0x1000 overflows then whole region is in excluded zone.  */
+  if ((grub_addr_t) addr > ~((grub_addr_t) 0x1000))
+    return;
+
+  /* If addr + 0x1000 + size overflows then decrease size.  */
+  if (((grub_addr_t) addr + 0x1000) > ~(grub_addr_t) size)
+    size = ((grub_addr_t) -0x1000) - (grub_addr_t) addr;
+
   for (p = &grub_mm_base, q = *p; q; p = &(q->next), q = *p)
     if ((grub_uint8_t *) addr + size + q->pre_size == (grub_uint8_t *) q)
       {