Skip to content

Commit 2b4b248

Browse files
aet00torvalds
authored andcommitted
romfs: fix romfs_get_unmapped_area() argument check
romfs_get_unmapped_area() checks argument `len' without considering PAGE_ALIGN which will cause do_mmap_pgoff() return -EINVAL error after commit f67d9b1 ("nommu: add page_align to mmap"). Fix the check by changing it in same way ramfs_nommu_get_unmapped_area() was changed in ramfs/file-nommu.c. Signed-off-by: Bob Liu <[email protected]> Cc: David Howells <[email protected]> Cc: Paul Mundt <[email protected]> Acked-by: Greg Ungerer <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8c95aa6 commit 2b4b248

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/romfs/mmap-nommu.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
2727
{
2828
struct inode *inode = file->f_mapping->host;
2929
struct mtd_info *mtd = inode->i_sb->s_mtd;
30-
unsigned long isize, offset;
30+
unsigned long isize, offset, maxpages, lpages;
3131

3232
if (!mtd)
3333
goto cant_map_directly;
3434

35+
/* the mapping mustn't extend beyond the EOF */
36+
lpages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
3537
isize = i_size_read(inode);
3638
offset = pgoff << PAGE_SHIFT;
37-
if (offset > isize || len > isize || offset > isize - len)
39+
40+
maxpages = (isize + PAGE_SIZE - 1) >> PAGE_SHIFT;
41+
if ((pgoff >= maxpages) || (maxpages - pgoff < lpages))
3842
return (unsigned long) -EINVAL;
3943

4044
/* we need to call down to the MTD layer to do the actual mapping */

0 commit comments

Comments
 (0)