public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* don't let mmap allocate down to zero
@ 2005-01-26 16:18 Rik van Riel
  2005-01-26 16:38 ` linux-os
  2005-01-26 17:25 ` William Lee Irwin III
  0 siblings, 2 replies; 40+ messages in thread
From: Rik van Riel @ 2005-01-26 16:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, James Antill, Bryn Reeves

With some programs the 2.6 kernel can end up allocating memory
at address zero, for a non-MAP_FIXED mmap call!  This causes
problems with some programs and is generally rude to do. This
simple patch fixes the problem in my tests.

Make sure that we don't allocate memory all the way down to zero,
so the NULL pointer never gets covered up with anonymous memory
and we don't end up violating the C standard.

Signed-off-by: Rik van Riel <riel@redhat.com>

--- linux-2.6.9/mm/mmap.c.nullmmap	2005-01-25 18:00:26.000000000 -0500
+++ linux-2.6.9/mm/mmap.c	2005-01-26 08:48:03.438701673 -0500
@@ -1114,6 +1114,8 @@ void arch_unmap_area(struct vm_area_stru
  		area->vm_mm->free_area_cache = area->vm_start;
  }

+#define SHLIB_BASE             0x00111000
+
  /*
   * This mmap-allocator allocates new areas top-down from below the
   * stack's low limit (the base):
@@ -1162,6 +1164,13 @@ try_again:
  			return addr;

  		/*
+		 * Make sure we don't allocate all the way down to
+		 * zero, which would break NULL pointer detection.
+		 */
+		if (addr < SHLIB_BASE)
+			goto fail;
+
+		/*
  		 * new region fits between prev_vma->vm_end and
  		 * vma->vm_start, use it:
  		 */
@@ -1258,8 +1267,6 @@ get_unmapped_area_prot(struct file *file
  EXPORT_SYMBOL(get_unmapped_area_prot);


-#define SHLIB_BASE             0x00111000
-
  unsigned long arch_get_unmapped_exec_area(struct file *filp, unsigned long 
addr0,
  		unsigned long len0, unsigned long pgoff, unsigned long flags)
  {

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2005-01-28 15:56 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-26 16:18 don't let mmap allocate down to zero Rik van Riel
2005-01-26 16:38 ` linux-os
2005-01-26 17:05   ` Sytse Wielinga
2005-01-26 17:34   ` Chris Friesen
2005-01-26 17:57     ` Bryn Reeves
2005-01-26 18:37       ` linux-os
2005-01-26 18:54         ` Rik van Riel
2005-01-26 19:09           ` linux-os
2005-01-26 19:13         ` Chris Friesen
2005-01-26 19:08       ` Chris Friesen
2005-01-26 18:10   ` Olivier Galibert
2005-01-26 18:20     ` linux-os
2005-01-26 18:31       ` Olivier Galibert
2005-01-26 18:39         ` linux-os
2005-01-26 19:41   ` Arjan van de Ven
2005-01-26 20:26   ` Andy Isaacson
2005-01-26 20:42     ` Rik van Riel
2005-01-26 22:12   ` Kyle Moffett
2005-01-26 23:31   ` Brian Gerst
2005-01-26 17:25 ` William Lee Irwin III
2005-01-27  5:09   ` William Lee Irwin III
2005-01-27  5:18     ` Dave Jones
2005-01-27  5:28       ` William Lee Irwin III
2005-01-27  9:29     ` Mikael Pettersson
2005-01-27 12:52       ` William Lee Irwin III
2005-01-27 14:25         ` Russell King
2005-01-27 15:12           ` William Lee Irwin III
2005-01-27 19:22             ` Rik van Riel
2005-01-27 20:44               ` William Lee Irwin III
2005-01-27 20:58                 ` Rik van Riel
2005-01-27 21:13                   ` William Lee Irwin III
2005-01-27 21:28                     ` Rik van Riel
2005-01-28  5:30                       ` William Lee Irwin III
2005-01-28 13:01                         ` Rik van Riel
2005-01-28 14:14                           ` Hugh Dickins
2005-01-28 14:26                             ` William Lee Irwin III
2005-01-28 15:41                             ` Rik van Riel
2005-01-28 15:53                               ` Hugh Dickins
2005-01-27 21:58                     ` linux-os
2005-01-27 14:26         ` Mikael Pettersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox