--- linux-2.4.20-oM3-orig/mm/mmap.c Wed Mar 31 12:41:23 2004 +++ linux-2.4.20-oM3-mod/mm/mmap.c Wed May 12 17:05:08 2004 @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -558,8 +559,15 @@ int registration_result = 0; #endif /* CONFIG_MOSIX */ - if (file && (!file->f_op || !file->f_op->mmap)) - return -ENODEV; + if (file) { + if (!file->f_op || !file->f_op->mmap) + return -ENODEV; + + if ((len = PAGE_ALIGN(len)) == 0) + if ((prot & PROT_EXEC) && (file->f_vfsmnt) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC)) + return -EPERM; + } + #ifdef CONFIG_MOSIX_FS if(file && file_is_mfs(file)) return(mmap_read_instead(file, addr, len, prot, flags, pgoff)); @@ -571,12 +579,11 @@ if (!len) return addr; - if (len > TASK_SIZE) - return -EINVAL; - - /* This cannot be zero now */ len = PAGE_ALIGN(len); + if (len > TASK_SIZE || len == 0) + return -EINVAL; + /* offset overflow? */ if ((pgoff + (len >> PAGE_SHIFT)) < pgoff) return -EINVAL; @@ -1250,6 +1257,8 @@ break; } no_mmaps: + if (last < first) + return; /* * If the PGD bits are not consecutive in the virtual address, the * old method of shifting the VA >> by PGDIR_SHIFT doesn't work. @@ -1398,6 +1407,9 @@ len = PAGE_ALIGN(len); if (!len) return addr; + + if ((addr + len) > TASK_SIZE || (addr + len) < addr) + return -EINVAL; #ifdef CONFIG_MOSIX if(current->mosix.dflags & DDEPUTY)