Skip to contentSkip to conversation

mprotect patch for use by SLIM

RFC PATCH In review Kylene Jo Hall 2 participants 2 messages Jul 14, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/6 mprotect patch for use by SLIM

This small patch makes mprotect available for use by SLIM for write revocation.

---
 include/linux/mm.h |    2 ++
 mm/mprotect.c      |   14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
mm/mprotect.c +12 -2
Index: linux-2.6.17/mm/mprotect.c
===================================================================
@@ -19,6 +19,7 @@
 #include <linux/mempolicy.h>
 #include <linux/personality.h>
 #include <linux/syscalls.h>
+#include <linux/module.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
 #include <asm/uaccess.h>
@@ -179,8 +180,7 @@ fail:
 	return error;
 }
 
-asmlinkage long
-sys_mprotect(unsigned long start, size_t len, unsigned long prot)
+int do_mprotect(unsigned long start, size_t len, unsigned long prot)
 {
 	unsigned long vm_flags, nstart, end, tmp, reqprot;
 	struct vm_area_struct *vma, *prev;
@@ -278,3 +278,13 @@ out:
 	up_write(&current->mm->mmap_sem);
 	return error;
 }
+EXPORT_SYMBOL_GPL(do_mprotect);
+
+asmlinkage long
+sys_mprotect(unsigned long start, size_t len, unsigned long prot)
+{
+	int ret;
+
+	ret = do_mprotect(start, len, prot);
+	return ret;
+}
include/linux/mm.h +2 -0
Index: linux-2.6.17/include/linux/mm.h
===================================================================
@@ -138,6 +138,8 @@ extern unsigned int kobjsize(const void 
 #define VM_EXEC		0x00000004
 #define VM_SHARED	0x00000008
 
+extern int do_mprotect(unsigned long start, size_t len, unsigned long prot);
+
 /* 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
#1 lore raw
Quoted 2 lines · Kylene Jo Hall

This small patch makes mprotect available for use by SLIM for write revocation.

Hmmm. Do you really want mprotect() itself? Or, do you just want to
keep people from writing? (there is a difference :)

If somebody mmap()s something with write permissions, I would expect them to expect to see rw in /proc/<pid>/maps. If you use mprotect() on that mmap() to remove the write permissions, the permissions will be reflected in /proc/<pid>/maps.

-- Dave