aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/ia64/kernel/sys_ia64.c28
-rw-r--r--arch/sparc/kernel/sys_sparc.c27
-rw-r--r--arch/sparc64/kernel/sys_sparc.c36
3 files changed, 51 insertions, 40 deletions
diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
index 40722d88607a..9ef62a3fbfad 100644
--- a/arch/ia64/kernel/sys_ia64.c
+++ b/arch/ia64/kernel/sys_ia64.c
@@ -163,10 +163,25 @@ sys_pipe (void)
163 return retval; 163 return retval;
164} 164}
165 165
166int ia64_mmap_check(unsigned long addr, unsigned long len,
167 unsigned long flags)
168{
169 unsigned long roff;
170
171 /*
172 * Don't permit mappings into unmapped space, the virtual page table
173 * of a region, or across a region boundary. Note: RGN_MAP_LIMIT is
174 * equal to 2^n-PAGE_SIZE (for some integer n <= 61) and len > 0.
175 */
176 roff = REGION_OFFSET(addr);
177 if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len)))
178 return -EINVAL;
179 return 0;
180}
181
166static inline unsigned long 182static inline unsigned long
167do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, unsigned long pgoff) 183do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, unsigned long pgoff)
168{ 184{
169 unsigned long roff;
170 struct file *file = NULL; 185 struct file *file = NULL;
171 186
172 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 187 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
@@ -188,17 +203,6 @@ do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, un
188 goto out; 203 goto out;
189 } 204 }
190 205
191 /*
192 * Don't permit mappings into unmapped space, the virtual page table of a region,
193 * or across a region boundary. Note: RGN_MAP_LIMIT is equal to 2^n-PAGE_SIZE
194 * (for some integer n <= 61) and len > 0.
195 */
196 roff = REGION_OFFSET(addr);
197 if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len))) {
198 addr = -EINVAL;
199 goto out;
200 }
201
202 down_write(&current->mm->mmap_sem); 206 down_write(&current->mm->mmap_sem);
203 addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); 207 addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
204 up_write(&current->mm->mmap_sem); 208 up_write(&current->mm->mmap_sem);
diff --git a/arch/sparc/kernel/sys_sparc.c b/arch/sparc/kernel/sys_sparc.c
index a41c8a5c2007..94ff58c9d4a9 100644
--- a/arch/sparc/kernel/sys_sparc.c
+++ b/arch/sparc/kernel/sys_sparc.c
@@ -219,6 +219,21 @@ out:
219 return err; 219 return err;
220} 220}
221 221
222int sparc_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
223{
224 if (ARCH_SUN4C_SUN4 &&
225 (len > 0x20000000 ||
226 ((flags & MAP_FIXED) &&
227 addr < 0xe0000000 && addr + len > 0x20000000)))
228 return -EINVAL;
229
230 /* See asm-sparc/uaccess.h */
231 if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
232 return -EINVAL;
233
234 return 0;
235}
236
222/* Linux version of mmap */ 237/* Linux version of mmap */
223static unsigned long do_mmap2(unsigned long addr, unsigned long len, 238static unsigned long do_mmap2(unsigned long addr, unsigned long len,
224 unsigned long prot, unsigned long flags, unsigned long fd, 239 unsigned long prot, unsigned long flags, unsigned long fd,
@@ -233,25 +248,13 @@ static unsigned long do_mmap2(unsigned long addr, unsigned long len,
233 goto out; 248 goto out;
234 } 249 }
235 250
236 retval = -EINVAL;
237 len = PAGE_ALIGN(len); 251 len = PAGE_ALIGN(len);
238 if (ARCH_SUN4C_SUN4 &&
239 (len > 0x20000000 ||
240 ((flags & MAP_FIXED) &&
241 addr < 0xe0000000 && addr + len > 0x20000000)))
242 goto out_putf;
243
244 /* See asm-sparc/uaccess.h */
245 if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE)
246 goto out_putf;
247
248 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 252 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
249 253
250 down_write(&current->mm->mmap_sem); 254 down_write(&current->mm->mmap_sem);
251 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); 255 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
252 up_write(&current->mm->mmap_sem); 256 up_write(&current->mm->mmap_sem);
253 257
254out_putf:
255 if (file) 258 if (file)
256 fput(file); 259 fput(file);
257out: 260out:
diff --git a/arch/sparc64/kernel/sys_sparc.c b/arch/sparc64/kernel/sys_sparc.c
index 054d0abdb7ee..bf5f14ee73de 100644
--- a/arch/sparc64/kernel/sys_sparc.c
+++ b/arch/sparc64/kernel/sys_sparc.c
@@ -548,6 +548,26 @@ asmlinkage long sparc64_personality(unsigned long personality)
548 return ret; 548 return ret;
549} 549}
550 550
551int sparc64_mmap_check(unsigned long addr, unsigned long len,
552 unsigned long flags)
553{
554 if (test_thread_flag(TIF_32BIT)) {
555 if (len >= STACK_TOP32)
556 return -EINVAL;
557
558 if ((flags & MAP_FIXED) && addr > STACK_TOP32 - len)
559 return -EINVAL;
560 } else {
561 if (len >= VA_EXCLUDE_START)
562 return -EINVAL;
563
564 if ((flags & MAP_FIXED) && invalid_64bit_range(addr, len))
565 return -EINVAL;
566 }
567
568 return 0;
569}
570
551/* Linux version of mmap */ 571/* Linux version of mmap */
552asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, 572asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
553 unsigned long prot, unsigned long flags, unsigned long fd, 573 unsigned long prot, unsigned long flags, unsigned long fd,
@@ -563,27 +583,11 @@ asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
563 } 583 }
564 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 584 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
565 len = PAGE_ALIGN(len); 585 len = PAGE_ALIGN(len);
566 retval = -EINVAL;
567
568 if (test_thread_flag(TIF_32BIT)) {
569 if (len >= STACK_TOP32)
570 goto out_putf;
571
572 if ((flags & MAP_FIXED) && addr > STACK_TOP32 - len)
573 goto out_putf;
574 } else {
575 if (len >= VA_EXCLUDE_START)
576 goto out_putf;
577
578 if ((flags & MAP_FIXED) && invalid_64bit_range(addr, len))
579 goto out_putf;
580 }
581 586
582 down_write(&current->mm->mmap_sem); 587 down_write(&current->mm->mmap_sem);
583 retval = do_mmap(file, addr, len, prot, flags, off); 588 retval = do_mmap(file, addr, len, prot, flags, off);
584 up_write(&current->mm->mmap_sem); 589 up_write(&current->mm->mmap_sem);
585 590
586out_putf:
587 if (file) 591 if (file)
588 fput(file); 592 fput(file);
589out: 593out: