Subject: Re: lib/9349: mmap() requires PROT_READ even if only writing
To: None <mac@NetBSD.Advantrix.Com>
From: Chris G. Demetriou <cgd@netbsd.org>
List: netbsd-bugs
Date: 02/04/2000 11:26:06
Mike <mac@NetBSD.Advantrix.Com> writes:
> The temporary fix is to "or" PROT_READ into the target, like this:
>
> target = mmap(0, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, output, 0)
>
> But this obviously doesn't fix the improper behavior of mmap().
So, an interesting thing to consider, for whoever's going to fix this:
from SUSv2:
If an implementation cannot support the combination of access types
specified by prot, the call to mmap() fails. An implementation may
permit accesses other than those specified by prot; however, the
implementation will not permit a write to succeed where PROT_WRITE has
not been set or permit any access where PROT_NONE alone has been
set. The implementation will support at least the following values of
prot: PROT_NONE, PROT_READ, PROT_WRITE, and the inclusive OR of
PROT_READ and PROT_WRITE. The file descriptor fildes will have been
opened with read permission, regardless of the protection options
specified. If PROT_WRITE is specified, the application must have
opened the file descriptor fildes with write permission unless
MAP_PRIVATE is specified in the flags parameter as described below.
In other words, if the i386 cannot support writing pages if it can't
read them, the VM system should be silently converting the PROT_WRITE
request to PROT_READ | PROT_WRITE.
Interesting to also note the bit about the file descriptor needing to
have been opened with (at least) read permission regardless of the
protection options desired. This means that the WRITE -> READ|WRITE
change can be considered "safe."
cgd
--
Chris Demetriou - cgd@netbsd.org - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.