linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Kravetz <mike.kravetz@oracle.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: syzbot <syzbot+d6ec23007e951dadf3de@syzkaller.appspotmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, Miklos Szeredi <mszeredi@redhat.com>,
	syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: kernel BUG at mm/hugetlb.c:LINE!
Date: Tue, 12 May 2020 11:11:18 -0700	[thread overview]
Message-ID: <d32b8579-04a3-2a9b-cd54-1d581c63332e@oracle.com> (raw)
In-Reply-To: <CAJfpegtVca6H1JPW00OF-7sCwpomMCo=A2qr5K=9uGKEGjEp3w@mail.gmail.com>

On 5/12/20 8:04 AM, Miklos Szeredi wrote:
> On Tue, Apr 7, 2020 at 12:06 AM Mike Kravetz <mike.kravetz@oracle.com> wrote:
>> On 4/5/20 8:06 PM, syzbot wrote:
>>
>> The routine is_file_hugepages() is just comparing the file ops to huegtlbfs:
>>
>>         if (file->f_op == &hugetlbfs_file_operations)
>>                 return true;
>>
>> Since the file is in an overlayfs, file->f_op == ovl_file_operations.
>> Therefore, length will not be rounded up to huge page size and we create a
>> mapping with incorrect size which leads to the BUG.
>>
>> Because of the code in mmap, the hugetlbfs mmap() routine assumes length is
>> rounded to a huge page size.  I can easily add a check to hugetlbfs mmap
>> to validate length and return -EINVAL.  However, I think we really want to
>> do the 'round up' earlier in mmap.  This is because the man page says:
>>
>>    Huge page (Huge TLB) mappings
>>        For mappings that employ huge pages, the requirements for the arguments
>>        of  mmap()  and munmap() differ somewhat from the requirements for map‐
>>        pings that use the native system page size.
>>
>>        For mmap(), offset must be a multiple of the underlying huge page size.
>>        The system automatically aligns length to be a multiple of the underly‐
>>        ing huge page size.
>>
>> Since the location for the mapping is chosen BEFORE getting to the hugetlbfs
>> mmap routine, we can not wait until then to round up the length.  Is there a
>> defined way to go from a struct file * to the underlying filesystem so we
>> can continue to do the 'round up' in early mmap code?
> 
> That's easy enough:
> 
> static inline struct file *real_file(struct file *file)
> {
>     return file->f_op != ovl_file_operations ? file : file->private_data;
> }
> 
> But adding more filesystem specific code to generic code does not
> sound like the cleanest way to solve this...

We can incorporate the above 'real_file' functionality in the filesystem
specific routine is_file_hugepages(), and I think that would address this
specific issue.  I'll code that up.

>> One other thing I noticed with overlayfs is that it does not contain a
>> specific get_unmapped_area file_operations routine.  I would expect it to at
>> least check for and use the get_unmapped_area of the underlying filesystem?
>> Can someone comment if this is by design?
> 
> Not sure.  What exactly is f_op->get_unmapped_area supposed to do?
> 

IIUC, filesystems can define their own routines to get addresses for mmap
operations.  Quite a few filesystems define get_unmapped_area.

The generic mmap code does the following,

	get_area = current->mm->get_unmapped_area;
	if (file) {
		if (file->f_op->get_unmapped_area)
			get_area = file->f_op->get_unmapped_area;
	} else if (flags & MAP_SHARED) {
		/*
		 * mmap_region() will call shmem_zero_setup() to create a file,
		 * so use shmem's get_unmapped_area in case it can be huge.
		 * do_mmap_pgoff() will clear pgoff, so match alignment.
		 */
		pgoff = 0;
		get_area = shmem_get_unmapped_area;
	}

	addr = get_area(file, addr, len, pgoff, flags);

If the filesystem provides a get_unmapped_area, it will use it.  I beleive
overlayfs prevents this from happening for the underlying filesystem.

Perhaps we do need to add something like a call 'real_file' to this generic
code?  I can't think of any other way to get to the underlying filesystem
get_unmapped_area here.
-- 
Mike Kravetz

  reply	other threads:[~2020-05-12 18:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06  3:06 kernel BUG at mm/hugetlb.c:LINE! syzbot
2020-04-06 22:05 ` Mike Kravetz
2020-05-12 15:04   ` Miklos Szeredi
2020-05-12 18:11     ` Mike Kravetz [this message]
2020-05-15 22:15       ` Mike Kravetz
2020-05-18 11:12         ` Miklos Szeredi
2020-05-18 23:22           ` Mike Kravetz
2020-05-18 23:41     ` Colin Walters
2020-05-19  0:35       ` Mike Kravetz
2020-05-20 11:20         ` Miklos Szeredi
2020-05-20 17:27           ` Mike Kravetz
2020-05-22 10:05             ` Miklos Szeredi
2020-05-28  0:01               ` Mike Kravetz
2020-05-28  8:37                 ` [PATCH v2] ovl: provide real_file() and overlayfs get_unmapped_area() kbuild test robot
2020-05-28 21:01                   ` Mike Kravetz
2020-06-04  9:16                     ` Miklos Szeredi
2020-06-11  0:13                       ` Mike Kravetz
2020-06-11  0:37                         ` Al Viro
2020-06-11  1:36                           ` Matthew Wilcox
2020-06-11  2:17                             ` Al Viro
2020-06-11  2:31                               ` Mike Kravetz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d32b8579-04a3-2a9b-cd54-1d581c63332e@oracle.com \
    --to=mike.kravetz@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@redhat.com \
    --cc=syzbot+d6ec23007e951dadf3de@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).