Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1091725ybk; Wed, 13 May 2020 23:34:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWr+S09POYz+wwN54wMLylh2NfEdtdv8F6l2vLZxSfnkAta9oCuJ8lTJkxjDddQNCk3qY3 X-Received: by 2002:a17:906:17c1:: with SMTP id u1mr2384946eje.47.1589438063412; Wed, 13 May 2020 23:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589438063; cv=none; d=google.com; s=arc-20160816; b=m3O6CQqpHZMa42J2mGEEjZ3AHMqYeWOaf4NqVXT14zk5S3H5ipbF9gjPhHeZDJgk93 ByH9ETNBwrubQ+j7+DGvHvA1+9Fi17LsQyeprXNCdPqXDZjzfNyqoceBDMvDH/9iZ8gt bxtyLGEfWQYyHVpPCFeKUq5V5dy1aYkZUzmWInAaRnv14nFl1ykuOrUEQGGhbt8W5LM1 jvQTTHPXnBGgb5gcMWoagBzMqFbndfVrs/AKspUV55cxZr23H6FCBk0LjhN3p99g4dnC IkJUolNqkxT4KDNrscXUPtlZYPmgXhqPJBtNM8oQSJyK/nR0COtEIZxFyRwfeXNDSvUE 3EUA== 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=7beuWqfQ78sZ4JE4BHCpndgfFcv5hqYlle/rcKwSYqM=; b=Xext/Gix0DobwxKdMpe9iH6BK1MxJBMGX970mqnQP1n/OypPQNigA9k0ZYlZaCuv1/ t5Kf5UWMs3GvEY+SedqQcGzcLKMPNL4sx8IN7YIRyorPA5JtXEbZXwwxEhK/oMAtdkYV Arx2oImyVpz7bTF6sUP+W1YEmtdkfQHIg1lS0Icy/1G5p8eMImvxUFgnLm2ocX6LMr+c e7yB1g2aXKSzVUzhNSOJhmyJPc8xMDnLXl7QhLCDx7m2PQe3McrZI2WwpPP9hZLW7GUJ SJ1dvO7fUCgFL//OaDKqp0klAdLEx4tB3QhKNr3fh4zj7V0aAjvHoxKRaM8rqaUsixxd r6QQ== 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 i2si1182428ejg.45.2020.05.13.23.33.59; Wed, 13 May 2020 23:34:23 -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 S1726011AbgENGcC (ORCPT + 99 others); Thu, 14 May 2020 02:32:02 -0400 Received: from verein.lst.de ([213.95.11.211]:50261 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbgENGcB (ORCPT ); Thu, 14 May 2020 02:32:01 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 98AFF68C7B; Thu, 14 May 2020 08:31:58 +0200 (CEST) Date: Thu, 14 May 2020 08:31:58 +0200 From: Christoph Hellwig To: Greg KH Cc: Christoph Hellwig , Hillf Danton , syzbot , Thomas Gleixner , jeremy.linton@arm.com, 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: <20200514063158.GA8780@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200514062750.GA1488715@kroah.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 08:27:50AM +0200, Greg KH wrote: > On Thu, May 14, 2020 at 08:14:17AM +0200, Christoph Hellwig wrote: > > Guys, can you please start formal thread on this? I have no > > idea where this came from and what the rationale is. Btw, if the > > pfn is crap in dma_direct_mmap then the dma_addr_t passed in is > > crap, as it is derived from that. What is the caller, and how is > > this triggered? > > > Ok, to summarize, commit 2bef9aed6f0e ("usb: usbfs: correct kernel->user > page attribute mismatch") changed a call from remap_pfn_range() to > dma_mmap_coherent() for usb data buffers being sent from userspace. 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 logic should be something like: if (hcd->localmem_pool || !hcd_uses_dma(hcd)) remap_pfn_range() else dma_mmap_coherent()