From 1bc783bd39afb8dfe7fd967993e25ace6d27e30e Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 18 Sep 2013 20:23:47 +0200 Subject: [PATCH] * grub-core/kern/mm.c (grub_mm_init_region): Skip regions less than 4K before the end. Reported by: Leif Lindholm --- ChangeLog | 6 ++++++ grub-core/kern/mm.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index aabb82f0e..c8edd1ff2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ * docs/grub.texi (Networking commands): Add documentation for network related commands. +2013-09-18 Vladimir Serbinenko + + * 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 2013-09-18 Vladimir Serbinenko diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c index 959c3bab1..59e45c7ae 100644 --- a/grub-core/kern/mm.c +++ b/grub-core/kern/mm.c @@ -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) {