LWN.net Logo

Virtual Machines and Memory Protections

Virtual Machines and Memory Protections

Posted Nov 22, 2006 16:26 UTC (Wed) by cventers (subscriber, #31465)
Parent article: Virtual Machines and Memory Protections

Why not double-mmap a region created with shm_open() and ftruncate()?


(Log in to post comments)

Virtual Machines and Memory Protections

Posted Nov 22, 2006 19:29 UTC (Wed) by bluefoxicy (guest, #25366) [Link]

Because shared memory objects are never allowed to be executable, even on vanilla Linux. I don't think POSIX allows executable shared memory due to the massive security implications.

Virtual Machines and Memory Protections

Posted Nov 22, 2006 21:59 UTC (Wed) by cventers (subscriber, #31465) [Link]

Huh. Well, I was taking a guess, but I figured that the permissions you
supplied to shm_open() and mmap() would determine that.

Virtual Machines and Memory Protections

Posted Nov 23, 2006 19:27 UTC (Thu) by bluefoxicy (guest, #25366) [Link]

Read the man page for shmget.

> mode_flags (least significant 9 bits) specifying the permissions granted to the owner, group, and world. These bits have the same format, and the same meaning, as the mode argument of open(2). Presently, the execute permissions are not used by the system.

I may be wrong about POSIX, but Linux disallows shared memory to be executable. Any attempt to use shared memory violating its permissions (i.e. mmap()ing it writable when the caller has only read-only perms) fails.

Yes, shared memory is complex and confusing as crap. Don't feel bad if you don't get it.

Virtual Machines and Memory Protections

Posted Nov 23, 2006 21:42 UTC (Thu) by cventers (subscriber, #31465) [Link]

> Yes, shared memory is complex and confusing as crap. Don't feel bad if
> you don't get it.

Well, I think SysV shared memory is crap. POSIX shared memory is much
better. shm_open() says nothing about execute permissions in the manual
page. I haven't checked the kernel's implementation, but I thought that
might indicate that it does nothing special there.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds