Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1243008ybk; Thu, 14 May 2020 04:16:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTyJX4E8ueWRMMbUWL018RDMxid38HyLkeygEThzhYHB0l+o16JPe4Td+sfKcdEwCiqyHZ X-Received: by 2002:aa7:daca:: with SMTP id x10mr3266250eds.59.1589454998233; Thu, 14 May 2020 04:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589454998; cv=none; d=google.com; s=arc-20160816; b=G9ojuz1thKH3LW63A94wT1TlHmx6fW3XUyY5KoOhh0gDzgODf+CbDtoV3jChKkxfas tWn/5EMNKLjGmlfqhKu16598HaNbBn4fjeKCsTrxt/IEJOvHe+fNXAj5Oe2AIN/f93vz lhwEoshx7T39dZFTwgzL/FiEIHLJ0R5I4uzAioOq9GFFT5GRElx71J5VP2Jil/3OVvDn Vy/0EVC/Lh9N1IBXxgIsN2FvrwDH0ZpaKrAUP+Z69qZIcXI5oVt0WB2fn+HR6WE7SUy5 WmHl/Jdy+UVAtkp0wjrUvCGkpcKCVJaMYNuq3PyqpS+vY9IzuoQxzfhuiUr7gwkceqKG qWaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lPGKdejC6vCDiRzZO4nXrjL/XqV6uR1MiXn6Uslh4wk=; b=kFL61odVCZ1MsDNb2O0MeNCskRlwBcKRNlPJhmhkTPes8iwKwyCDH0l8kpqsm1bf+C 20BYdgSd9ngdnuCemPqgtWLx7niw80opEmUFxwLyCtP7fw5PkYNDYnK4ZS5D4pugmwDh +6hj7ybgwX13otx/wXM92Md9/pAbV7iSJhWMUdZyuSjV0NSrA6o4TOjIuj1cfLJ0DbUr 1RQ1nUz7KY+SHZ1zBwjcvPXlowZCDzMv/fwjAhsD5q30i1V66RYRvRdI5X7ru/BSuOSy PkF8Mp6b1PXHJpHMjEhgk2PCphBPDZx2FG+RX2iyqiywGG99k+PXu/2fpq9VLKyTyjZd 2s5A== ARC-Authentication-Results: i=1; mx.google.com; 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 n17si1554101ejd.437.2020.05.14.04.16.14; Thu, 14 May 2020 04:16:38 -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; 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 S1726098AbgENLOq (ORCPT + 99 others); Thu, 14 May 2020 07:14:46 -0400 Received: from verein.lst.de ([213.95.11.211]:51366 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgENLOq (ORCPT ); Thu, 14 May 2020 07:14:46 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 951B268BEB; Thu, 14 May 2020 13:14:42 +0200 (CEST) Date: Thu, 14 May 2020 13:14:42 +0200 From: Christoph Hellwig To: Jeremy Linton Cc: Christoph Hellwig , Greg KH , Hillf Danton , syzbot , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, syzkaller-bugs@googlegroups.com, x86@kernel.org Subject: Re: Validating dma_mmap_coherent() parameters before calling (was Re: WARNING in memtype_reserve) Message-ID: <20200514111442.GA13813@lst.de> References: <000000000000f0d8d205a531f1a3@google.com> <20200509074507.GC1831917@kroah.com> <87wo5l4ecm.fsf@nanos.tec.linutronix.de> <20200513124445.GA1082735@kroah.com> <87zhab249p.fsf@nanos.tec.linutronix.de> <20200514035458.14760-1-hdanton@sina.com> <20200514061417.GA8367@lst.de> <20200514062750.GA1488715@kroah.com> <20200514063158.GA8780@lst.de> <8bdb3488-59d0-67ce-4822-e25dbd0dc42a@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8bdb3488-59d0-67ce-4822-e25dbd0dc42a@arm.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 14, 2020 at 06:10:03AM -0500, Jeremy Linton wrote: >> I only need to look at the commit for 3 seconds to tell you that it is >> completely buggy. While using dma_mmap_coherent is fundamentally the >> right thing and absolutely required for dma_alloc_* allocations, USB >> also uses it's own local gen pool allocator or plain kmalloc for not >> DMA capable controller. This need to use remap_pfn_range. I'm pretty >> sure you hit one of those cases. > > ? The code path in question is usbdev_mmap() and the allocation is done ~13 > lines lines before as a usb_alloc_coherent(). And did you take a look at how usb_alloc_coherent is implemented? That should make it completely obvious that not all allocations come from dma_alloc_*. > That sort of makes sense, except for the above, and the fact that I would > imagine the dma_mmap_coherent should be dealing with that case. I'm not > really clear about the details of the GCE usb device here, but my first > guess at this was the dma_pgprot() in dma_direct_mmap() is incorrectly > picking a pgprot... No, dma_mmap_* / dma_direct_mmap has absolutely no business dealing with memory that did not come from the DMA allocator.