linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* PATHC: SHM mappings beyond the end of a segment.
@ 2000-01-30  4:28 Eric W. Biederman
  0 siblings, 0 replies; only message in thread
From: Eric W. Biederman @ 2000-01-30  4:28 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-mm, linux-kernel

Currently it is possible to extend the vma for a shm segment
with mremap.  The shm code has no checks for access beyond the
end of the shm segment.  Resulting in writes to shp->shm_dir in 2.3
and shp->shm_pages in 2.2 past the allocated end of the array.

By playing with this processes can create weird memory overwrites,
and effectively mlocked private pages.

As using mremap to extend a shm mapping is basically silly,
and linux specific.  I don't think it affects anything in practice.

The attached patch caused SIGBUS to be delivered when
we write past the end of our shm area.

Eric

===File linux-2.3.41.eb1.diff==============
diff -uNrX linux-ignore-files linux-2.3.41/ipc/shm.c linux-2.3.41.eb1/ipc/shm.c
--- linux-2.3.41/ipc/shm.c	Mon Jan 24 13:04:37 2000
+++ linux-2.3.41.eb1/ipc/shm.c	Sat Jan 29 18:57:58 2000
@@ -840,6 +840,15 @@
 	idx = (address - shmd->vm_start) >> PAGE_SHIFT;
 	idx += shmd->vm_pgoff;
 
+	/*
+	 * A shared mapping past the last page of the file is an error
+	 * and results in a SIGBUS, so logically a shared mapping past 
+	 * the end of a shared memory segment should result in SIGBUS
+	 * as well.
+	 */
+	if (idx >= shp->shm_npages) { 
+		return NULL;
+	}
 	down(&shp->sem);
 	if(shp != shm_lock(shp->id))
 		BUG();
============================================================
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-01-30  4:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-30  4:28 PATHC: SHM mappings beyond the end of a segment Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox