]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
sparc: Fix mremap address range validation.
authorDavid S. Miller <davem@davemloft.net>
Mon, 12 May 2008 23:33:33 +0000 (16:33 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 15 May 2008 14:50:05 +0000 (07:50 -0700)
Just like mmap, we need to validate address ranges regardless
of MAP_FIXED.

sparc{,64}_mmap_check()'s flag argument is unused, remove.

Based upon a report and preliminary patch by
Jan Lieskovsky <jlieskov@redhat.com>

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
arch/sparc/kernel/sys_sparc.c
arch/sparc64/kernel/sys_sparc.c
arch/sparc64/kernel/sys_sparc32.c
include/asm-sparc/mman.h
include/asm-sparc64/mman.h

index 9f8c8e101e9d62cbf5707d09f1214e6e669a2b9f..3423d07eb8a172dc0227a44c5d24d380c939fea5 100644 (file)
@@ -220,7 +220,7 @@ out:
        return err;
 }
 
-int sparc_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
+int sparc_mmap_check(unsigned long addr, unsigned long len)
 {
        if (ARCH_SUN4C_SUN4 &&
            (len > 0x20000000 ||
@@ -296,52 +296,14 @@ asmlinkage unsigned long sparc_mremap(unsigned long addr,
        unsigned long old_len, unsigned long new_len,
        unsigned long flags, unsigned long new_addr)
 {
-       struct vm_area_struct *vma;
        unsigned long ret = -EINVAL;
-       if (ARCH_SUN4C_SUN4) {
-               if (old_len > 0x20000000 || new_len > 0x20000000)
-                       goto out;
-               if (addr < 0xe0000000 && addr + old_len > 0x20000000)
-                       goto out;
-       }
-       if (old_len > TASK_SIZE - PAGE_SIZE ||
-           new_len > TASK_SIZE - PAGE_SIZE)
+
+       if (unlikely(sparc_mmap_check(addr, old_len)))
+               goto out;
+       if (unlikely(sparc_mmap_check(new_addr, new_len)))
                goto out;
        down_write(&current->mm->mmap_sem);
-       if (flags & MREMAP_FIXED) {
-               if (ARCH_SUN4C_SUN4 &&
-                   new_addr < 0xe0000000 &&
-                   new_addr + new_len > 0x20000000)
-                       goto out_sem;
-               if (new_addr + new_len > TASK_SIZE - PAGE_SIZE)
-                       goto out_sem;
-       } else if ((ARCH_SUN4C_SUN4 && addr < 0xe0000000 &&
-                   addr + new_len > 0x20000000) ||
-                  addr + new_len > TASK_SIZE - PAGE_SIZE) {
-               unsigned long map_flags = 0;
-               struct file *file = NULL;
-
-               ret = -ENOMEM;
-               if (!(flags & MREMAP_MAYMOVE))
-                       goto out_sem;
-
-               vma = find_vma(current->mm, addr);
-               if (vma) {
-                       if (vma->vm_flags & VM_SHARED)
-                               map_flags |= MAP_SHARED;
-                       file = vma->vm_file;
-               }
-
-               new_addr = get_unmapped_area(file, addr, new_len,
-                                    vma ? vma->vm_pgoff : 0,
-                                    map_flags);
-               ret = new_addr;
-               if (new_addr & ~PAGE_MASK)
-                       goto out_sem;
-               flags |= MREMAP_FIXED;
-       }
        ret = do_mremap(addr, old_len, new_len, flags, new_addr);
-out_sem:
        up_write(&current->mm->mmap_sem);
 out:
        return ret;       
index 6f771060420e7c428ce2d8fcf5b8f13c2180d1c4..4b495fe51e95c0fba0c16dc2dd970f114cfebeb1 100644 (file)
@@ -542,8 +542,7 @@ asmlinkage long sparc64_personality(unsigned long personality)
        return ret;
 }
 
-int sparc64_mmap_check(unsigned long addr, unsigned long len,
-               unsigned long flags)
+int sparc64_mmap_check(unsigned long addr, unsigned long len)
 {
        if (test_thread_flag(TIF_32BIT)) {
                if (len >= STACK_TOP32)
@@ -609,46 +608,19 @@ asmlinkage unsigned long sys64_mremap(unsigned long addr,
        unsigned long old_len, unsigned long new_len,
        unsigned long flags, unsigned long new_addr)
 {
-       struct vm_area_struct *vma;
        unsigned long ret = -EINVAL;
 
        if (test_thread_flag(TIF_32BIT))
                goto out;
        if (unlikely(new_len >= VA_EXCLUDE_START))
                goto out;
-       if (unlikely(invalid_64bit_range(addr, old_len)))
+       if (unlikely(sparc64_mmap_check(addr, old_len)))
+               goto out;
+       if (unlikely(sparc64_mmap_check(new_addr, new_len)))
                goto out;
 
        down_write(&current->mm->mmap_sem);
-       if (flags & MREMAP_FIXED) {
-               if (invalid_64bit_range(new_addr, new_len))
-                       goto out_sem;
-       } else if (invalid_64bit_range(addr, new_len)) {
-               unsigned long map_flags = 0;
-               struct file *file = NULL;
-
-               ret = -ENOMEM;
-               if (!(flags & MREMAP_MAYMOVE))
-                       goto out_sem;
-
-               vma = find_vma(current->mm, addr);
-               if (vma) {
-                       if (vma->vm_flags & VM_SHARED)
-                               map_flags |= MAP_SHARED;
-                       file = vma->vm_file;
-               }
-
-               /* MREMAP_FIXED checked above. */
-               new_addr = get_unmapped_area(file, addr, new_len,
-                                   vma ? vma->vm_pgoff : 0,
-                                   map_flags);
-               ret = new_addr;
-               if (new_addr & ~PAGE_MASK)
-                       goto out_sem;
-               flags |= MREMAP_FIXED;
-       }
        ret = do_mremap(addr, old_len, new_len, flags, new_addr);
-out_sem:
        up_write(&current->mm->mmap_sem);
 out:
        return ret;       
index 2455fa498876f344b0c00db0800bbd1718acead0..54df31ae4b223a78e7df214c863624d6b851ddb1 100644 (file)
@@ -906,44 +906,15 @@ asmlinkage unsigned long sys32_mremap(unsigned long addr,
        unsigned long old_len, unsigned long new_len,
        unsigned long flags, u32 __new_addr)
 {
-       struct vm_area_struct *vma;
        unsigned long ret = -EINVAL;
        unsigned long new_addr = __new_addr;
 
-       if (old_len > STACK_TOP32 || new_len > STACK_TOP32)
+       if (unlikely(sparc64_mmap_check(addr, old_len)))
                goto out;
-       if (addr > STACK_TOP32 - old_len)
+       if (unlikely(sparc64_mmap_check(new_addr, new_len)))
                goto out;
        down_write(&current->mm->mmap_sem);
-       if (flags & MREMAP_FIXED) {
-               if (new_addr > STACK_TOP32 - new_len)
-                       goto out_sem;
-       } else if (addr > STACK_TOP32 - new_len) {
-               unsigned long map_flags = 0;
-               struct file *file = NULL;
-
-               ret = -ENOMEM;
-               if (!(flags & MREMAP_MAYMOVE))
-                       goto out_sem;
-
-               vma = find_vma(current->mm, addr);
-               if (vma) {
-                       if (vma->vm_flags & VM_SHARED)
-                               map_flags |= MAP_SHARED;
-                       file = vma->vm_file;
-               }
-
-               /* MREMAP_FIXED checked above. */
-               new_addr = get_unmapped_area(file, addr, new_len,
-                                   vma ? vma->vm_pgoff : 0,
-                                   map_flags);
-               ret = new_addr;
-               if (new_addr & ~PAGE_MASK)
-                       goto out_sem;
-               flags |= MREMAP_FIXED;
-       }
        ret = do_mremap(addr, old_len, new_len, flags, new_addr);
-out_sem:
        up_write(&current->mm->mmap_sem);
 out:
        return ret;       
index b7dc40bc68f401cabbc89c556cb424070c652852..632cd8a057f04a7c1e8df2aa80d1b7d902e1208e 100644 (file)
@@ -37,9 +37,8 @@
 
 #ifdef __KERNEL__
 #ifndef __ASSEMBLY__
-#define arch_mmap_check        sparc_mmap_check
-int sparc_mmap_check(unsigned long addr, unsigned long len,
-               unsigned long flags);
+#define arch_mmap_check(addr,len,flags)        sparc_mmap_check(addr,len)
+int sparc_mmap_check(unsigned long addr, unsigned long len);
 #endif
 #endif
 
index 8cc1860be63077f312eaef0832f31fb47de06b74..e0fcfca0255c08e616daa674c553ad76bb97007e 100644 (file)
@@ -37,9 +37,8 @@
 
 #ifdef __KERNEL__
 #ifndef __ASSEMBLY__
-#define arch_mmap_check        sparc64_mmap_check
-int sparc64_mmap_check(unsigned long addr, unsigned long len,
-               unsigned long flags);
+#define arch_mmap_check(addr,len,flags)        sparc64_mmap_check(addr,len)
+int sparc64_mmap_check(unsigned long addr, unsigned long len);
 #endif
 #endif