Skip to content

Commit

Permalink
romfs: fix nommu map length to keep inside filesystem
Browse files Browse the repository at this point in the history
Checks introduced in commit 4991e72 ("romfs: do not use
mtd->get_unmapped_area directly") re-introduce problems fixed in the earlier
commit 2b4b248 ("romfs: fix romfs_get_unmapped_area() argument check").

If a flat binary app is located at the end of a romfs, its page aligned
length may be outside of the romfs filesystem. The flat binary loader, via
nommu do_mmap_pgoff(), page aligns the length it is mmaping. So simple
offset+size checks will fail - returning EINVAL.

We can truncate the length to keep it inside the romfs filesystem, and that
also keeps the call to mtd_get_unmapped_area() happy.

Are there any side effects to truncating the size here though?

Signed-off-by: Greg Ungerer <[email protected]>
  • Loading branch information
gregungerer committed Apr 28, 2013
1 parent 5143661 commit e4ba4fc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/romfs/mmap-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ static unsigned long romfs_get_unmapped_area(struct file *file,
return (unsigned long) -EINVAL;

offset += ROMFS_I(inode)->i_dataoffset;
if (offset > mtd->size - len)
if (offset >= mtd->size)
return (unsigned long) -EINVAL;
/* the mapping mustn't extend beyond the EOF */
if ((offset + len) > mtd->size)
len = mtd->size - offset;

ret = mtd_get_unmapped_area(mtd, len, offset, flags);
if (ret == -EOPNOTSUPP)
Expand Down

0 comments on commit e4ba4fc

Please sign in to comment.