[PATCH] NOMMU: Check fd read permission in validate_mmap_request()

From: David Howells
Date: Fri Aug 14 2009 - 07:30:01 EST


From: Graff Yang <graff.yang@xxxxxxxxx>

According to the POSIX (1003.1-2008), the file descriptor shall have been
opened with read permission, regardless of the protection options specified to
mmap(). The ltp test cases mmap06/07 need this.

Signed-off-by: Graff Yang <graff.yang@xxxxxxxxx>
Acked-by: Paul Mundt <lethal@xxxxxxxxxxxx>
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

mm/nommu.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)


diff --git a/mm/nommu.c b/mm/nommu.c
index 1b2b59b..fd1e2b5 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -919,6 +919,10 @@ static int validate_mmap_request(struct file *file,
if (!file->f_op->read)
capabilities &= ~BDI_CAP_MAP_COPY;

+ /* The file shall have been opened with read permission. */
+ if (!(file->f_mode & FMODE_READ))
+ return -EACCES;
+
if (flags & MAP_SHARED) {
/* do checks for writing, appending and locking */
if ((prot & PROT_WRITE) &&

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/