Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp496821ybk; Wed, 13 May 2020 05:44:07 -0700 (PDT) X-Google-Smtp-Source: APiQypKuKIgaHdXqEltChpfpZXiuDhOSx3gPOYSamhYDnFYRebohovy8oKmSNzIaFzTc16wiMJex X-Received: by 2002:a50:d490:: with SMTP id s16mr16062822edi.242.1589373847593; Wed, 13 May 2020 05:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589373847; cv=none; d=google.com; s=arc-20160816; b=nxXtlAqlf7zGS7We3Z3iwW5lX773x5ZOn3CfFB/sEZv/FrjgctIBk3tBkK7+ydtPuo 6Vi3CtUfXPpu6bnVZ5hO6FbzGkIKX8aZqVEhqESSYzvFYnvXjjyFSukuWiSbIpK7Ek2T gyeBFDGWRAgbwM71B3+R0RqbH8h0wso16VJDndYfHCChoctOnQWK3BFOLdx4l1chB7oA 0+7/Sy2gxyNVcWnJvji6VmoYECOF4/Ms+S/aujazpIYqBYF1G8LQq30T9XdYzIcDmcyg i1tJWYg/nxMwT5w1WPyKij0y1E/+It8GGmWtoTqpMNiAV1eZ71PalaPK6rn11JVhFy3S tYxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Uqnv99CWQ63/0REM3A+ueYglhT4gTdagjTMtuuZotM8=; b=LW/bR9PhzznoTve43F3x7i4+3JB/Rs0JbYxXTPKm4L4AnGK5pgvpnQNCoCMs0JYNX/ H3ZP4gzcF4H/5ZcjDDNnW727uF77f2dbEzW8StsPATA/Cp2GPAfjAJKvlf+O9o21hv+j N3ppLy2799TrYuIGFfsJ23kyAXRPb7QhkgyhL3R52Kexzprp/pOV7RRz9wWRxCDYor4E pNCU9I6Lptdp4o4t0u67DBhowuV1xlUMjZoy03WtDSXESQ5CPtpEM23UZdGgGLVCU4Va 4JZ+WjeynXRgnIkjFq1VPU9bcMZCvlxXfhZcCxs0fZfQVURyH95reXrZgTn1mzL2lOIr pnCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sksyEf4x; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si5648112ejb.278.2020.05.13.05.43.43; Wed, 13 May 2020 05:44:07 -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=@kernel.org header.s=default header.b=sksyEf4x; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732924AbgEMMlN (ORCPT + 99 others); Wed, 13 May 2020 08:41:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:45410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbgEMMlM (ORCPT ); Wed, 13 May 2020 08:41:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5938920659; Wed, 13 May 2020 12:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589373671; bh=w0BMXaAbm3ZXC1lR+6gXnvhYlJsh+XV/CUl+EnU6p4w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sksyEf4xegzo8O+nHBxTJvdgJPilHUrEFS8lx0hzZcPj+F/z2hJpynOt/nOzlczNT zkYzPLKO/JULxjbHoVfFz/slMKxDEN8/IYhkD9GNgx2g9bVoCac33MxmEnRuCk3d4G yWq5+v3kYqhx2T8zmeGFifPqwktUwiSfTG5wj9XM= Date: Wed, 13 May 2020 14:41:09 +0200 From: Greg KH To: Hillf Danton Cc: syzbot , jeremy.linton@arm.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, tglx@linutronix.de, Christoph Hellwig , syzkaller-bugs@googlegroups.com Subject: Re: WARNING in memtype_reserve Message-ID: <20200513124109.GA1082369@kroah.com> References: <000000000000f0d8d205a531f1a3@google.com> <20200509154728.1548-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200509154728.1548-1-hdanton@sina.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 09, 2020 at 11:47:28PM +0800, Hillf Danton wrote: > > Sat, 09 May 2020 00:20:14 -0700 > >syzbot found the following crash on: > > > >HEAD commit: d5eeab8d Merge tag 'scsi-fixes' of git://git.kernel.org/pu.. > >git tree: upstream > >console output: https://syzkaller.appspot.com/x/log.txt?x=15093632100000 > >kernel config: https://syzkaller.appspot.com/x/.config?x=b0212dbee046bc1f > >dashboard link: https://syzkaller.appspot.com/bug?extid=353be47c9ce21b68b7ed > >compiler: gcc (GCC) 9.0.0 20181231 (experimental) > >userspace arch: i386 > >syz repro: https://syzkaller.appspot.com/x/repro.syz?x=168ee02c100000 > >C reproducer: https://syzkaller.appspot.com/x/repro.c?x=119f3788100000 > > > >The bug was bisected to: > > > >commit 2bef9aed6f0e22391c8d4570749b1acc9bc3981e > >Author: Jeremy Linton > >Date: Mon May 4 20:13:48 2020 +0000 > > > > usb: usbfs: correct kernel->user page attribute mismatch > > > >bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=1701f168100000 > >final crash: https://syzkaller.appspot.com/x/report.txt?x=1481f168100000 > >console output: https://syzkaller.appspot.com/x/log.txt?x=1081f168100000 > > > >IMPORTANT: if you fix the bug, please add the following tag to the commit: > >Reported-by: syzbot+353be47c9ce21b68b7ed@syzkaller.appspotmail.com > >Fixes: 2bef9aed6f0e ("usb: usbfs: correct kernel->user page attribute mismatch") > > > >------------[ cut here ]------------ > >memtype_reserve failed: [mem 0xffffffffff000-0x00008fff], req write-back > >WARNING: CPU: 1 PID: 7025 at arch/x86/mm/pat/memtype.c:589 memtype_reserve+0x69f/0x820 arch/x86/mm/pat/memtype.c:589 > >Kernel panic - not syncing: panic_on_warn set ... > >CPU: 1 PID: 7025 Comm: syz-executor254 Not tainted 5.7.0-rc4-syzkaller #0 > >Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 > >Call Trace: > > __dump_stack lib/dump_stack.c:77 [inline] > > dump_stack+0x188/0x20d lib/dump_stack.c:118 > > panic+0x2e3/0x75c kernel/panic.c:221 > > __warn.cold+0x2f/0x35 kernel/panic.c:582 > > report_bug+0x27b/0x2f0 lib/bug.c:195 > > fixup_bug arch/x86/kernel/traps.c:175 [inline] > > fixup_bug arch/x86/kernel/traps.c:170 [inline] > > do_error_trap+0x12b/0x220 arch/x86/kernel/traps.c:267 > > do_invalid_op+0x32/0x40 arch/x86/kernel/traps.c:286 > > invalid_op+0x23/0x30 arch/x86/entry/entry_64.S:1027 > >RIP: 0010:memtype_reserve+0x69f/0x820 arch/x86/mm/pat/memtype.c:589 > >Code: 48 8b 2c ed c0 00 29 88 e8 ae ad 3e 00 48 8d 4b ff 49 89 e8 4c 89 e2 48 c7 c6 20 01 29 88 48 c7 c7 80 f9 28 88 e8 79 e8 0f 00 <0f> 0b 41 bf ea ff ff ff e9 03 fc ff ff 41 bf ea ff ff ff e9 f8 fb > >RSP: 0018:ffffc900015e7790 EFLAGS: 00010282 > >RAX: 0000000000000000 RBX: 0000000000009000 RCX: 0000000000000000 > >RDX: 0000000000000000 RSI: ffffffff815ce181 RDI: fffff520002bcee4 > >RBP: ffffffff8828ff40 R08: ffff888097ce85c0 R09: ffffed1015ce45f1 > >R10: ffff8880ae722f83 R11: ffffed1015ce45f0 R12: 000ffffffffff000 > >R13: 1ffff920002bcef8 R14: dffffc0000000000 R15: 0000000000000000 > > reserve_pfn_range+0x173/0x470 arch/x86/mm/pat/memtype.c:941 > > track_pfn_remap+0x18b/0x280 arch/x86/mm/pat/memtype.c:1033 > > remap_pfn_range+0x202/0xbf0 mm/memory.c:2130 > > dma_direct_mmap+0x197/0x260 kernel/dma/direct.c:453 > > dma_mmap_attrs+0xfe/0x150 kernel/dma/mapping.c:237 > > usbdev_mmap+0x3ae/0x730 drivers/usb/core/devio.c:254 > > call_mmap include/linux/fs.h:1912 [inline] > > mmap_region+0xafb/0x1540 mm/mmap.c:1772 > > do_mmap+0x849/0x1160 mm/mmap.c:1545 > > do_mmap_pgoff include/linux/mm.h:2553 [inline] > > vm_mmap_pgoff+0x197/0x200 mm/util.c:506 > > ksys_mmap_pgoff+0x457/0x5b0 mm/mmap.c:1595 > > do_syscall_32_irqs_on arch/x86/entry/common.c:337 [inline] > > do_fast_syscall_32+0x270/0xe90 arch/x86/entry/common.c:396 > > entry_SYSENTER_compat+0x70/0x7f arch/x86/entry/entry_64_compat.S:139 > > Add check of physical address and boundary. > > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -447,6 +447,7 @@ int dma_direct_mmap(struct device *dev, > unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; > unsigned long pfn = PHYS_PFN(dma_to_phys(dev, dma_addr)); > int ret = -ENXIO; > + unsigned long pa; > > vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); > > @@ -455,6 +456,13 @@ int dma_direct_mmap(struct device *dev, > > if (vma->vm_pgoff >= count || user_count > count - vma->vm_pgoff) > return -ENXIO; > + if (pfn > pfn + vma->vm_pgoff) > + return -ENXIO; > + pa = (pfn + vma->vm_pgoff) << PAGE_SHIFT; > + if (pa < (pfn << PAGE_SHIFT)) > + return -ENXIO; > + if (pa > pa + (user_count << PAGE_SHIFT)) > + return -ENXIO; > return remap_pfn_range(vma, vma->vm_start, pfn + vma->vm_pgoff, > user_count << PAGE_SHIFT, vma->vm_page_prot); Isn't there some sort of "check mmap parms" function somewhere that should do this logic all in one place? Putting it all over the kernel feels wrong to me... thanks, greg k-h