mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] romfs: fix romfs_get_unmapped_area() param check
@ 2011-06-14  5:36 Bob Liu
  0 siblings, 0 replies; only message in thread
From: Bob Liu @ 2011-06-14  5:36 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, dhowells, gerg, lethal, gerg, geert, Bob Liu

romfs_get_unmapped_area() check param len without considering PAGE_ALIGN which
will cause do_mmap_pgoff() return -EINVAL error after commit f67d9b1576c
nommu: add page_align to mmap.

This patch fix the param check by changing it to the same way which function
ramfs_nommu_get_unmapped_area() did in ramfs/file-nommu.c.

Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
 fs/romfs/mmap-nommu.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
index f0511e8..eed9942 100644
--- a/fs/romfs/mmap-nommu.c
+++ b/fs/romfs/mmap-nommu.c
@@ -27,14 +27,18 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
 {
 	struct inode *inode = file->f_mapping->host;
 	struct mtd_info *mtd = inode->i_sb->s_mtd;
-	unsigned long isize, offset;
+	unsigned long isize, offset, maxpages, lpages;
 
 	if (!mtd)
 		goto cant_map_directly;
 
+	/* the mapping mustn't extend beyond the EOF */
+	lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	isize = i_size_read(inode);
 	offset = pgoff << PAGE_SHIFT;
-	if (offset > isize || len > isize || offset > isize - len)
+
+	maxpages = (isize + PAGE_SIZE - 1) >> PAGE_SHIFT;
+	if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
 		return (unsigned long) -EINVAL;
 
 	/* we need to call down to the MTD layer to do the actual mapping */
-- 
1.6.3.3



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-14  5:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-14  5:36 [PATCH] romfs: fix romfs_get_unmapped_area() param check Bob Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®