Commit 6ea1dc96 authored by Linus Torvalds's avatar Linus Torvalds Committed by Greg Kroah-Hartman

mmap: relax file size limit for regular files

commit 423913ad upstream.

Commit be83bbf8 ("mmap: introduce sane default mmap limits") was
introduced to catch problems in various ad-hoc character device drivers
doing mmap and getting the size limits wrong.  In the process, it used
"known good" limits for the normal cases of mapping regular files and
block device drivers.

It turns out that the "s_maxbytes" limit was less "known good" than I
thought.  In particular, /proc doesn't set it, but exposes one regular
file to mmap: /proc/vmcore.  As a result, that file got limited to the
default MAX_INT s_maxbytes value.

This went unnoticed for a while, because apparently the only thing that
needs it is the s390 kernel zfcpdump, but there might be other tools
that use this too.

Vasily suggested just changing s_maxbytes for all of /proc, which isn't
wrong, but makes me nervous at this stage.  So instead, just make the
new mmap limit always be MAX_LFS_FILESIZE for regular files, which won't
affect anything else.  It wasn't the regular file case I was worried
about.

I'd really prefer for maxsize to have been per-inode, but that is not
how things are today.

Fixes: be83bbf8 ("mmap: introduce sane default mmap limits")
Reported-by: default avatarVasily Gorbik <gor@linux.ibm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bd2f9ce5
...@@ -1278,7 +1278,7 @@ static inline int mlock_future_check(struct mm_struct *mm, ...@@ -1278,7 +1278,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
static inline u64 file_mmap_size_max(struct file *file, struct inode *inode) static inline u64 file_mmap_size_max(struct file *file, struct inode *inode)
{ {
if (S_ISREG(inode->i_mode)) if (S_ISREG(inode->i_mode))
return inode->i_sb->s_maxbytes; return MAX_LFS_FILESIZE;
if (S_ISBLK(inode->i_mode)) if (S_ISBLK(inode->i_mode))
return MAX_LFS_FILESIZE; return MAX_LFS_FILESIZE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment