Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2916243ybk; Tue, 12 May 2020 11:13:28 -0700 (PDT) X-Google-Smtp-Source: APiQypJH+2/82NLma5pqJYhw1esQLqcwPsy29KaAtgdtPSum+wkyq0xCWO5szHpZbGomeg9hNM/R X-Received: by 2002:a17:906:17c1:: with SMTP id u1mr19213128eje.47.1589307208221; Tue, 12 May 2020 11:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589307208; cv=none; d=google.com; s=arc-20160816; b=RFc08lxOpLeqGirTET//VaLcHOz8GmI/L0wFLcfe1yVcLbD0OjZGpc+c98+tq1YTec tMRKYWUMOKkHKmE5ZFi2X/Vrsm/xwD5e58d3MfuQyxBd37QqZxX17G+XZtm3fI27+XU/ hpHZk2tDBJIgsW9thMOLX3PsCgutYj1toTpDETdvwuMLD5O7UTr6ehDxZi2sNM05CLoz HeSqJyX0pcKY2ebbRO+L4SGX15fyLizv0JTCtmsMAtiDMJAN3t/sf1ieNBfbXSNpwPYW dCXhkU3lEYNIOg3XwWDzNQfgxe2kccJIyZtgsjqC2nGn8Ab7u424Y2UWYF9wWxm9Mmme jXMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=avirZw5AsQS+rl6YFQqDTc3dF1MisQxLLLlK/WfBzs8=; b=GV5izRPSQ4d7b+SAgsc5SPCGP8stSao2pYQyXc6PdvWhWtJFk+VCCo3APMcmBCfY8/ PRgeZ2qE5p142Sc0VB8jU0ohUUbiimQXmn68CGDtF91gSPIkbN8sEcmZAtx6XFInAWW4 3UAa3eLmV7o59JDdIEYStdXQxb/uqJ26oHoMAxjvLMnGmPIthYEIxJzxLx1raxTEG2ej Qm4pqun+h/i3TKD6wvbL+lUxbxc70DwSxRlEyDUUbg5zS5KcWzX2tMg3lQR2+fuF59VM 4rAqugIdeXPeIq2V3jxlHcw+7rhvoLxBUQz2u8ca7zmX2JQB2hkOhrnZQyZfAYccd9Z2 WpcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ys6Ud04n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si8101228ejh.334.2020.05.12.11.13.05; Tue, 12 May 2020 11:13:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ys6Ud04n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730850AbgELSLc (ORCPT + 99 others); Tue, 12 May 2020 14:11:32 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:36062 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbgELSLb (ORCPT ); Tue, 12 May 2020 14:11:31 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04CI773Z068683; Tue, 12 May 2020 18:11:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=avirZw5AsQS+rl6YFQqDTc3dF1MisQxLLLlK/WfBzs8=; b=ys6Ud04nHWkqaGGRiSsPF6TnNyDfh3eiWBCvJjKcsHlYql+/6yUpvJ5hL70JFwR7FXKU l6gjSvLunj9rLQTS51wzBz02kUM4cTfq9SEvhsELLhD3JQUpoimgCXgdgyWSH0JLoftv P43llu20VegcgATj0H/ArwAbT8aCDKZuVb23qY0RpgcKXcE3DgWaQKPR7L1UZOtovFdz FDt6FEH06K19iEwrZ/q1PjH22UY3QniWuVRJB+lvyD8ZYSZkHwYTBaeuBCHGk1m9O/e0 KMYlZ42oEeqw+Y4sxbcQxSdWby2cN9/tjAt8+g+bvnOGXORJ8dUdPcoZS2E2DQ5NZeT8 pQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 30x3gsmkyy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 12 May 2020 18:11:22 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04CI80Gh009083; Tue, 12 May 2020 18:11:22 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 30ydsr0053-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 May 2020 18:11:21 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 04CIBJ1k025843; Tue, 12 May 2020 18:11:20 GMT Received: from [192.168.2.157] (/73.164.160.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 May 2020 11:11:19 -0700 Subject: Re: kernel BUG at mm/hugetlb.c:LINE! To: Miklos Szeredi Cc: syzbot , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Miklos Szeredi , syzkaller-bugs , Al Viro References: <000000000000b4684e05a2968ca6@google.com> From: Mike Kravetz Message-ID: Date: Tue, 12 May 2020 11:11:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005120136 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9619 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 clxscore=1011 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005120136 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/12/20 8:04 AM, Miklos Szeredi wrote: > On Tue, Apr 7, 2020 at 12:06 AM Mike Kravetz 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