Re: Testing PROT_NONE and other protections, and a surprise

Jamie Lokier
2004-07-01T04:12:56Z

Kyle Moffett wrote:
> Just for kicks, I ran this on Mac OS X too :-D Interesting results!
> Requested PROT | --- R-- -W- RW- --X R-X -WX RWX
> ========================================================================
> MAP_SHARED | --- r-x --- rwx --- r-x --- rwx
> MAP_PRIVATE | --- r-x --- rwx --- r-x --- rwx

Yikes. I wonder if those results are correct.

To be honest, if those results are correct it looks like a MacOS X
bug, or at least POSIX non-conformance. It should always grant a
superset of the requested protections.

That invalidates the portability rule "ask for the permissions you
need to use". If you only need to write or execute a file, and you
only ask for those, MacOS X won't let you. So the rule needs to be
"and always include PROT_READ in the list". Assuming it's not a bug
in the test program.

By the way, my program is potentially slightly flaky on architectures
where the CPU can't do byte writes (such as old Alphas). Depending on
the OS, the program might say write access isn't granted for a
write-only request, when it is. The program should've done a word
write instead.

I doubt that is the cause of those results on a PPC running MacOS X though :)

Can you confirm in a simple way that mapping a file, or some anonymous
memory, without PROT_READ, really isn't writable under MacOS X? Can
you confirm it with a word write, if that would be relevant?

Cheers,
-- Jamie