mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] Add a note about partially hardcoded VM_* flags
Date: Tue, 20 Sep 2005 20:46:03 +0200	[thread overview]
Message-ID: <20050920184602.14557.43517.stgit@zion.home.lan> (raw)
In-Reply-To: <20050920184513.14557.8152.stgit@zion.home.lan>

From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

Hugh made me note this line for permission checking in mprotect():

		if ((newflags & ~(newflags >> 4)) & 0xf) {

after figuring out what's that about, I decided it's nasty enough. Btw Hugh
itself didn't like the 0xf.

We can safely change it to VM_READ|VM_WRITE|VM_EXEC because we never change
VM_SHARED, so no need to check that.

CC: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 include/linux/mm.h |    1 +
 mm/mprotect.c      |    3 ++-
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -136,6 +136,7 @@ extern unsigned int kobjsize(const void 
 #define VM_EXEC		0x00000004
 #define VM_SHARED	0x00000008
 
+/* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */
 #define VM_MAYREAD	0x00000010	/* limits for mprotect() etc */
 #define VM_MAYWRITE	0x00000020
 #define VM_MAYEXEC	0x00000040
diff --git a/mm/mprotect.c b/mm/mprotect.c
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -248,7 +248,8 @@ sys_mprotect(unsigned long start, size_t
 
 		newflags = vm_flags | (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
 
-		if ((newflags & ~(newflags >> 4)) & 0xf) {
+		/* newflags >> 4 shift VM_MAY% in place of VM_% */
+		if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
 			error = -EACCES;
 			goto out;
 		}


  parent reply	other threads:[~2005-09-20 18:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-20 18:45 [PATCH 1/7] Add dm-snapshot tutorial in Documentation Paolo 'Blaisorblade' Giarrusso
2005-09-20 18:45 ` [PATCH 2/7] i386: little pgtable.h consolidation vs 2/3level Paolo 'Blaisorblade' Giarrusso
2005-09-20 18:45 ` [PATCH 3/7] fix locking comment in unmap_region() Paolo 'Blaisorblade' Giarrusso
2005-09-20 18:45 ` [PATCH 4/7] README update from the stone age Paolo 'Blaisorblade' Giarrusso
2005-09-20 23:53   ` Randy.Dunlap
2005-09-20 18:45 ` [PATCH 5/7] Clearify comment in swapfile.c Paolo 'Blaisorblade' Giarrusso
2005-09-20 18:45 ` [PATCH 6/7] update stale comment for removal of page->list Paolo 'Blaisorblade' Giarrusso
2005-09-20 18:46 ` Paolo 'Blaisorblade' Giarrusso [this message]
2005-09-20 22:13 ` [PATCH 1/7] Add dm-snapshot tutorial in Documentation Nix
2005-09-21 15:04   ` Blaisorblade
2005-09-21 16:11     ` Nix

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=20050920184602.14557.43517.stgit@zion.home.lan \
    --to=blaisorblade@yahoo.it \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®