patch-2.0.9 linux/ipc/shm.c

Next file: linux/mm/filemap.c
Previous file: linux/include/linux/affs_fs_sb.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.8/linux/ipc/shm.c linux/ipc/shm.c
@@ -467,6 +467,7 @@
 	int err;
 	unsigned int id;
 	unsigned long addr;
+	unsigned long len;
 
 	if (shmid < 0) {
 		/* printk("shmat() -> EINVAL because shmid = %d < 0\n",shmid); */
@@ -490,6 +491,12 @@
 		else
 			return -EINVAL;
 	}
+	/*
+	 * Check if addr exceeds TASK_SIZE (from do_mmap)
+	 */
+	len = PAGE_SIZE*shp->shm_npages;
+       if (addr >= TASK_SIZE || len > TASK_SIZE  || addr > TASK_SIZE - len)
+		return -EINVAL;
 	/*
 	 * If shm segment goes below stack, make sure there is some
 	 * space left for the stack to grow (presently 4 pages).

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov