From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA71DC43467 for ; Thu, 8 Oct 2020 07:17:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BBCE820725 for ; Thu, 8 Oct 2020 07:17:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBCE820725 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A3ECE6B005C; Thu, 8 Oct 2020 03:17:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EF636B005D; Thu, 8 Oct 2020 03:17:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DE216B0062; Thu, 8 Oct 2020 03:17:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0215.hostedemail.com [216.40.44.215]) by kanga.kvack.org (Postfix) with ESMTP id 603756B005C for ; Thu, 8 Oct 2020 03:17:27 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E0E43181AE869 for ; Thu, 8 Oct 2020 07:17:26 +0000 (UTC) X-FDA: 77347902492.25.tray74_1b04cb7271d6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id B77041804E3A0 for ; Thu, 8 Oct 2020 07:17:26 +0000 (UTC) X-HE-Tag: tray74_1b04cb7271d6 X-Filterd-Recvd-Size: 4098 Received: from huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 8 Oct 2020 07:17:26 +0000 (UTC) Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.53]) by Forcepoint Email with ESMTP id 348A5DFF96053E27784C; Thu, 8 Oct 2020 15:17:19 +0800 (CST) Received: from dggeme753-chm.china.huawei.com (10.3.19.99) by dggeme752-chm.china.huawei.com (10.3.19.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Thu, 8 Oct 2020 15:17:18 +0800 Received: from dggeme753-chm.china.huawei.com ([10.7.64.70]) by dggeme753-chm.china.huawei.com ([10.7.64.70]) with mapi id 15.01.1913.007; Thu, 8 Oct 2020 15:17:18 +0800 From: linmiaohe To: Andrew Morton CC: "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] mm: mmap: Fix general protection fault in unlink_file_vma() Thread-Topic: [PATCH] mm: mmap: Fix general protection fault in unlink_file_vma() Thread-Index: AdadPUUH1xGewDMwTA2vF7DsJG74mw== Date: Thu, 8 Oct 2020 07:17:18 +0000 Message-ID: <8d3d451883a44f608173fe651b7e6718@huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.177.16] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Andrew Morton wrote: > On Wed, 16 Sep 2020 05:07:33 -0400 Miaohe Lin wrot= e: > >> The syzbot reported the below general protection fault: >>=20 >> general protection fault, probably for non-canonical address >> 0xe00eeaee0000003b: 0000 [#1] PREEMPT SMP KASAN >> KASAN: maybe wild-memory-access in range=20 >> [0x00777770000001d8-0x00777770000001df] >> CPU: 1 PID: 10488 Comm: syz-executor721 Not tainted=20 >> 5.9.0-rc3-syzkaller #0 >> Trace: >> free_pgtables+0x1b3/0x2f0 mm/memory.c:415 >> exit_mmap+0x2c0/0x530 mm/mmap.c:3184 >> __mmput+0x122/0x470 kernel/fork.c:1076 >>=20 >> It's because the ->mmap() callback can change vma->vm_file and fput=20 >> the original file. But the commit d70cec898324 ("mm: mmap: merge vma=20 >> after >> call_mmap() if possible") failed to catch this case and always fput()=20 >> the original file, hence add an extra fput(). >>=20 >> ... >> >> --- a/mm/mmap.c >> +++ b/mm/mmap.c >> @@ -1815,7 +1815,11 @@ unsigned long mmap_region(struct file *file, unsi= gned long addr, >> merge =3D vma_merge(mm, prev, vma->vm_start, vma->vm_end, vma->vm_fl= ags, >> NULL, vma->vm_file, vma->vm_pgoff, NULL, NULL_VM_UFFD_CTX); >> if (merge) { >> - fput(file); >> + /* ->mmap() can change vma->vm_file and fput the original file. So >> + * fput the vma->vm_file here or we would add an extra fput for fil= e >> + * and cause general protection fault ultimately. >> + */ >> + fput(vma->vm_file); >> vm_area_free(vma); >> vma =3D merge; >> /* Update vm_flags and possible addr to pick up the change. We=20 >> don't > >What about the case where this code block does its `goto unmap_writable'? > > /* Once vma denies write, undo our temporary denial count */ > if (file) { >unmap_writable: > if (vm_flags & VM_SHARED) > mapping_unmap_writable(file->f_mapping); > if (vm_flags & VM_DENYWRITE) > allow_write_access(file); > } > file =3D vma->vm_file; > >is this using the correct file? I think it is, but please do check. > Many thanks for your reply. Yes, I think so too. We do deny_write_access and mapping_map_writable on @f= ile, so we should undo all of this on @file. Since @file is unchanged over the second vma_merge() time, we'are using the= correct @file to undo our temporary denial count. But how should I check this explicitly ? I can't find out a way to do this.= Could you please figure it out for me? Thanks again.