Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: Add len and addr validation for MAP_FIXED mappings.
@ 2007-10-28  6:10 David Daney
  2007-10-29 17:51 ` Ralf Baechle
  0 siblings, 1 reply; 2+ messages in thread
From: David Daney @ 2007-10-28  6:10 UTC (permalink / raw)
  To: linux-mips

From: David Daney  <ddaney@avtrex.com>

mmap with MAP_FIXED was not validating the addr and len parameters.
This leads to the failure of GCC's gcc.c-torture/execute/loop-2[fg].c
testcases when using the o32 ABI on a 64 bit kernel.

These testcases try to mmap 65536 bytes at 0x7fff8000 and then access
all the memory.  In 2.6.18 and 2.6.23.1 (and likely other versions as
well) the kernel maps the requested memory, but since half of it is
above 0x80000000 a SIGBUS is generated when it is accessed.

This patch moves the len validation above the MAP_FIXED processing so
that it is always validated.  It also adds validation to the addr
parameter for MAP_FIXED mappings.

The patch is against 2.6.23.1 from kernel.org and was tested in a 64
bit big-endian kernel.

Signed-off-by: David Daney  <ddaney@avtrex.com>
---
--- ../linux-2.6.23.1-clean/arch/mips/kernel/syscall.c	2007-10-12 09:43:44.000000000 -0700
+++ arch/mips/kernel/syscall.c	2007-10-25 23:10:23.000000000 -0700
@@ -73,7 +73,14 @@ unsigned long arch_get_unmapped_area(str
 
 	task_size = STACK_TOP;
 
+	if (len > task_size)
+		return -ENOMEM;
+
 	if (flags & MAP_FIXED) {
+		/* Even MAP_FIXED mappings must reside within task_size.  */
+		if (task_size - len < addr)
+			return -EINVAL;
+
 		/*
 		 * We do not accept a shared mapping if it would violate
 		 * cache aliasing constraints.
@@ -83,8 +90,6 @@ unsigned long arch_get_unmapped_area(str
 		return addr;
 	}
 
-	if (len > task_size)
-		return -ENOMEM;
 	do_color_align = 0;
 	if (filp || (flags & MAP_SHARED))
 		do_color_align = 1;

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

* Re: [PATCH] MIPS: Add len and addr validation for MAP_FIXED mappings.
  2007-10-28  6:10 [PATCH] MIPS: Add len and addr validation for MAP_FIXED mappings David Daney
@ 2007-10-29 17:51 ` Ralf Baechle
  0 siblings, 0 replies; 2+ messages in thread
From: Ralf Baechle @ 2007-10-29 17:51 UTC (permalink / raw)
  To: David Daney; +Cc: linux-mips

On Sat, Oct 27, 2007 at 11:10:20PM -0700, David Daney wrote:

> mmap with MAP_FIXED was not validating the addr and len parameters.
> This leads to the failure of GCC's gcc.c-torture/execute/loop-2[fg].c
> testcases when using the o32 ABI on a 64 bit kernel.
> 
> These testcases try to mmap 65536 bytes at 0x7fff8000 and then access
> all the memory.  In 2.6.18 and 2.6.23.1 (and likely other versions as
> well) the kernel maps the requested memory, but since half of it is
> above 0x80000000 a SIGBUS is generated when it is accessed.
> 
> This patch moves the len validation above the MAP_FIXED processing so
> that it is always validated.  It also adds validation to the addr
> parameter for MAP_FIXED mappings.

Thanks, applied.

  Ralf

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

end of thread, other threads:[~2007-10-29 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-28  6:10 [PATCH] MIPS: Add len and addr validation for MAP_FIXED mappings David Daney
2007-10-29 17:51 ` Ralf Baechle

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