From: KAMEZAWA Hiroyuki Date: Thu, 9 Feb 2006 10:03:17 +0000 (-0800) Subject: [PATCH] shmdt cannot detach not-alined shm segment cleanly. X-Git-Tag: v2.6.15.5~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bde2fcb4fcc69afb0a6ebd1d8c27a83e475480ed;p=thirdparty%2Fkernel%2Fstable.git [PATCH] shmdt cannot detach not-alined shm segment cleanly. sys_shmdt() can manage shm segments which are covered by multiple vmas. (This can happen when a user uses mprotect() after shmat().) This works well if shm is aligned to PAGE_SIZE, but if not, the last segment cannot be detached. It is because a comparison in sys_shmdt() (vma->vm_end - addr) < size addr == return address of shmat() size == shmsize, argments to shmget() size should be aligned to PAGE_SIZE before being compared with vma->vm_end, which is aligned. Signed-off-by: KAMEZAWA Hiroyuki Cc: Manfred Spraul Cc: Hugh Dickins Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman Signed-off-by: Chris Wright --- diff --git a/ipc/shm.c b/ipc/shm.c index 587d836d80d9d..c0e7f4df75d9c 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -863,6 +863,7 @@ asmlinkage long sys_shmdt(char __user *shmaddr) * could possibly have landed at. Also cast things to loff_t to * prevent overflows and make comparisions vs. equal-width types. */ + size = PAGE_ALIGN(size); while (vma && (loff_t)(vma->vm_end - addr) <= size) { next = vma->vm_next;