make PROT_WRITE imply PROT_READ

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hi,

Currently, if i mmap() a file PROT_WRITE only and then first read from it 
and then write to it, i get a SEGV. However, if i write to it first and 
then read from it, i get no SEGV. This seems rather inconsistent.

The current implementation seems to be to make PROT_WRITE imply PROT_READ, 
however it does not quite work correctly. The patch below resolves this 
issue, by explicitly setting the PROT_READ flag when PROT_WRITE is 
requested.

This might appear at first as a possible permissions subversion, as i 
could get PROT_READ on a file that i only have write permission 
to...however, the mmap implementation requires that the file be opened 
with at least read access already. Thus, i don't believe there is any 
issue with regards to permissions.

Another consequenece of this patch is that it forces PROT_READ even for 
architectures that might be able to support it, (I know that x86, x86_64 
and ia64 do not) but i think this is best for portability.

This was originally reported by Doug Chapman.

thanks,

-Jason


Signed-off-by: Jason Baron <[email protected]>

--- linux-2.6/mm/mmap.c.bak	2006-06-21 17:07:52.000000000 -0400
+++ linux-2.6/mm/mmap.c	2006-06-21 17:22:54.000000000 -0400
@@ -910,6 +910,13 @@
 		if (!(file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC)))
 			prot |= PROT_EXEC;
 
+	 /* SuSv3: "if the application requests only PROT_WRITE, the 
+	 *          implementation may also allow read access."
+ 	 */
+
+	if (prot & PROT_WRITE)
+		prot |= PROT_READ;
+
 	if (!len)
 		return -EINVAL;
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux