mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gordon Jin <gordon.jin@intel.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, michael.fu@intel.com
Subject: [PATCH 2.6] fix mprotect() with len=(size_t)(-1) to return -ENOMEM
Date: Mon, 14 Mar 2005 17:55:48 +0800	[thread overview]
Message-ID: <1110794148.26254.45.camel@yjin3-dev.sh.intel.com> (raw)

This patch fixes a corner case in sys_mprotect(): 

Case: len is so large that will overflow to 0 after page alignment.
E.g. len=(size_t)(-1), i.e. 0xff...ff.
Expected result: POSIX spec says it should return -ENOMEM.
Current result: len is aligned to 0, then treated the same as len=0 and
return success.

--- linux-2.6.11.3/mm/mprotect.c.orig	2005-03-14 13:40:28.000000000
-0800
+++ linux-2.6.11.3/mm/mprotect.c	2005-03-14 13:42:41.000000000 -0800
@@ -232,14 +232,14 @@ sys_mprotect(unsigned long start, size_t
 
 	if (start & ~PAGE_MASK)
 		return -EINVAL;
+	if (!len)
+		return 0;
 	len = PAGE_ALIGN(len);
 	end = start + len;
-	if (end < start)
+	if (end <= start)
 		return -ENOMEM;
 	if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM))
 		return -EINVAL;
-	if (end == start)
-		return 0;
 	/*
 	 * Does the application expect PROT_READ to imply PROT_EXEC:
 	 */



             reply	other threads:[~2005-03-14 10:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-14  9:55 Gordon Jin [this message]
2005-03-14 10:08 ` Arjan van de Ven
2005-03-14 21:58   ` Ingo Oeser
2005-03-15  3:04 ` [PATCH 2.6] fix mmap() return value to conform POSIX Gordon Jin

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=1110794148.26254.45.camel@yjin3-dev.sh.intel.com \
    --to=gordon.jin@intel.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.fu@intel.com \
    /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

all inboxes | Powered by JetHome®