From: Jan Kiszka <jan.kiszka@domain.hid>
To: Philippe Gerum <rpm@xenomai.org>
Cc: adeos-main <adeos-main@gna.org>
Subject: [Adeos-main] [PATCH] ipipe: Prevent unwritable pages after mprotect
Date: Thu, 07 Jul 2011 21:14:00 +0200 [thread overview]
Message-ID: <4E160578.5020405@domain.hid> (raw)
From: Jan Kiszka <jan.kiszka@domain.hid>
Page protection changes issued via mprotect, e.g. to enable executable
stacks, cause spurious minor faults as they remove the write permission
from the modified range again. Avoid this by faking shared pages so that
vm_get_page_prot returns the desired page permissions.
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
mm/mprotect.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/mm/mprotect.c b/mm/mprotect.c
index 5a688a2..3f234b3 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -147,6 +147,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
{
struct mm_struct *mm = vma->vm_mm;
unsigned long oldflags = vma->vm_flags;
+ unsigned long protflags;
long nrpages = (end - start) >> PAGE_SHIFT;
unsigned long charged = 0;
pgoff_t pgoff;
@@ -205,8 +206,17 @@ success:
* held in write mode.
*/
vma->vm_flags = newflags;
+ protflags = newflags;
+#ifdef CONFIG_IPIPE
+ /*
+ * Enforce non-COW vm_page_prot by faking VM_SHARED on locked regions.
+ */
+ if (test_bit(MMF_VM_PINNED, &mm->flags) &&
+ ((vma->vm_flags | mm->def_flags) & VM_LOCKED))
+ protflags |= VM_SHARED;
+#endif
vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
- vm_get_page_prot(newflags));
+ vm_get_page_prot(protflags));
if (vma_wants_writenotify(vma)) {
vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
--
1.7.1
next reply other threads:[~2011-07-07 19:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-07 19:14 Jan Kiszka [this message]
2011-07-08 11:55 ` [Adeos-main] [PATCH] ipipe: Prevent unwritable pages after mprotect Gilles Chanteperdrix
2011-07-08 12:15 ` Jan Kiszka
2011-07-12 6:48 ` Gilles Chanteperdrix
2011-07-12 7:15 ` Jan Kiszka
2011-07-27 18:41 ` Gilles Chanteperdrix
2011-07-28 16:26 ` Jan Kiszka
2011-07-28 16:28 ` Jan Kiszka
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=4E160578.5020405@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=adeos-main@gna.org \
--cc=rpm@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.