* grub-core/kern/mm.c (grub_mm_init_region): Skip regions less than

4K before the end.
	Reported by: Leif Lindholm
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-09-18 20:23:47 +02:00
parent 436ad5c3f4
commit 1bc783bd39
2 changed files with 15 additions and 0 deletions

View file

@ -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>

View 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)
{