linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@xenotime.net>
From: Randy Dunlap <rdunlap@xenotime.net>
To: linux-mm@kvack.org
Cc: hugh@veritas.com, akpm <akpm@osdl.org>
Subject: [RFC/PATCH mmap2: better determine overflow
Date: Tue, 26 Sep 2006 10:35:04 -0700	[thread overview]
Message-ID: <20060926103504.82bd9409.rdunlap@xenotime.net> (raw)

mm/mmap.c::do_mmap_pgoff() checks for overflow like:

	/* offset overflow? */
	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
               return -EOVERFLOW;

However, using pgoff (page indexes) to determine address range
overflow doesn't overflow.  Change to use byte offsets instead,
so that overflow can actually happen and be noticed.
Also return EOVERFLOW instead of ENOMEM when PAGE_ALIGN(len)
is 0.

Tested on i686 and x86_64.

Test program is at:  http://www.xenotime.net/linux/src/mmap-test.c

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
---
 mm/mmap.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- linux-2618-work.orig/mm/mmap.c
+++ linux-2618-work/mm/mmap.c
@@ -923,13 +923,16 @@ unsigned long do_mmap_pgoff(struct file 
 
 	/* Careful about overflows.. */
 	len = PAGE_ALIGN(len);
-	if (!len || len > TASK_SIZE)
-		return -ENOMEM;
+	if (!len)
+		return -EOVERFLOW;
 
 	/* offset overflow? */
-	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
+	if (((pgoff << PAGE_SHIFT) + len) < (pgoff << PAGE_SHIFT))
                return -EOVERFLOW;
 
+	if (len > TASK_SIZE)
+		return -ENOMEM;
+
 	/* Too many mappings? */
 	if (mm->map_count > sysctl_max_map_count)
 		return -ENOMEM;

---

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2006-09-26 17:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-26 17:35 Randy Dunlap, Randy Dunlap [this message]
2006-09-26 18:10 ` Hugh Dickins
2006-09-26 19:08   ` Randy Dunlap
2006-09-26 20:44     ` Hugh Dickins
2006-09-26 22:18       ` Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060926103504.82bd9409.rdunlap@xenotime.net \
    --to=rdunlap@xenotime.net \
    --cc=akpm@osdl.org \
    --cc=hugh@veritas.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox