Re: mprotect pgprot handling weirdness

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: KOSAKI Motohiro
Date: Monday, April 5, 2010 - 10:52 pm

> Hi folks !

This check was introduced the following commit. yes now we don't
consider arch specific PROT_xx flags. but I don't think it is odd.

Yeah, I can imagine at least embedded people certenary need arch
specific PROT_xx flags and they hope to change it. but I don't 
think mprotect() fit for your usage. I mean mprotect() is widely 
used glibc internally. then, If mprotec can change which flags, 
glibc might turn off such flags implictly.

So, Why can't we proper new syscall? It has no regression risk.



==========================================================
commit d5e066ae3c39b4036b5f5021c352af0b73c85568
Author: torvalds <torvalds>
Date:   Fri Sep 5 19:05:07 2003 +0000

    Fix mprotect() to do proper PROT_xxx -> VM_xxx translation.

    This also fixes the bug with MAP_SEM being potentially
    interpreted as VM_SHARED.

    BKrev: 3f58de63gvzz-PsxwnRPnXTpz7EOeg

diff --git a/mm/mprotect.c b/mm/mprotect.c
index 2c01579..699962e 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -224,7 +224,7 @@ fail:
 asmlinkage long
 sys_mprotect(unsigned long start, size_t len, unsigned long prot)
 {
-       unsigned long nstart, end, tmp;
+       unsigned long vm_flags, nstart, end, tmp;
        struct vm_area_struct * vma, * next, * prev;
        int error = -EINVAL;

@@ -239,6 +239,8 @@ sys_mprotect(unsigned long start, size_t len, unsigned long prot)
        if (end == start)
                return 0;

+       vm_flags = calc_vm_prot_bits(prot);
+
        down_write(&current->mm->mmap_sem);

        vma = find_vma_prev(current->mm, start, &prev);
@@ -257,7 +259,8 @@ sys_mprotect(unsigned long start, size_t len, unsigned long prot)
                        goto out;
                }

-               newflags = prot | (vma->vm_flags & ~(PROT_READ | PROT_WRITE | PROT_EXEC));
+               newflags = vm_flags | (vma->vm_flags & ~(VM_READ | VM_WRITE | VM_EXEC));
+
                if ((newflags & ~(newflags >> 4)) & 0xf) {
                        error = -EACCES;
                        goto out;



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
mprotect pgprot handling weirdness, Benjamin Herrenschmidt, (Mon Apr 5, 10:09 pm)
Re: mprotect pgprot handling weirdness, Benjamin Herrenschmidt, (Mon Apr 5, 10:32 pm)
Re: mprotect pgprot handling weirdness, Benjamin Herrenschmidt, (Mon Apr 5, 10:43 pm)
Re: mprotect pgprot handling weirdness, KOSAKI Motohiro, (Mon Apr 5, 10:52 pm)
Arch specific mmap attributes (Was: mprotect pgprot handli ..., Benjamin Herrenschmidt, (Mon Apr 5, 11:07 pm)
Re: Arch specific mmap attributes (Was: mprotect pgprot ha ..., Benjamin Herrenschmidt, (Tue Apr 6, 12:30 am)
Re: Arch specific mmap attributes (Was: mprotect pgprot ha ..., Benjamin Herrenschmidt, (Tue Apr 6, 3:15 pm)
Re: Arch specific mmap attributes, David Miller, (Wed Apr 7, 12:03 am)
Re: Arch specific mmap attributes, KOSAKI Motohiro, (Wed Apr 7, 12:14 am)
Re: Arch specific mmap attributes, David Miller, (Wed Apr 7, 12:18 am)
Re: Arch specific mmap attributes (Was: mprotect pgprot ha ..., Benjamin Herrenschmidt, (Wed Apr 7, 1:56 am)
Re: Arch specific mmap attributes, Benjamin Herrenschmidt, (Wed Apr 7, 1:58 am)
Re: Arch specific mmap attributes, Benjamin Herrenschmidt, (Wed Apr 7, 2:00 am)