Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1089578ybk; Wed, 13 May 2020 23:29:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQ2oFSgFxnVqayrHs6h5iDRUHVyesnieJtcqBRcfYu8wzZD87QJ59afsfMyAP/TXFfGpdC X-Received: by 2002:a17:906:9518:: with SMTP id u24mr2452580ejx.137.1589437797950; Wed, 13 May 2020 23:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589437797; cv=none; d=google.com; s=arc-20160816; b=j8EcrqdaaX1oYEj+OjU5y3xLqHoQjpU/Y+XB/3HdzbNIOSuo5E2MULlR+vx+Hx2EWJ giR46WvQPXFGBOqU+tx/gOhdVi9L5Mt/mskOOXhHnAz8pKWqet3uGP7ph7byJLGBTnnD BCMhhrecidorQMrZqPJW6Rv+hG3eUDIccYB9LUzvLKuo/PQ4lwTlB6J8kvVXsHlH2XyT 8WQrCrtrH6J6DXISYK44DR8pcYQTvKc84JW0lCy6o3kkvyzpn648ia9lXxsInoxyE3Gv MmSWwQKdD9AuD4X+zphOVcdV970kfq3MJVBZJMfk+HQh9tCN8ddAHOmdZsB60luSGpv+ rcWg== 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=+KRecvXxYJAyZlymngosmC0hSW8C0Nog/sJhSkAYxt4=; b=Uz4EGF7Z0s7PM9YK/iUFdxNO+6mM0cr9LQ/s8sFedbnMTnOz7rqdPqAoAkZU3Nwbg8 MBjs7W/huuARkkEFmhJ+vXbigduNsDCir2VkTg1hTOPUDHzoSliTKuqPVqYIpVInvzsz N+zNmx0MpyINlR+r4rQ9SQWpflfihuewKXPWWlGkHfuj5gczSawgzdrdjfkw5VAdJ9PR kMxGr4tnh36yfwJbZtETZguAt7EeHaQcWyB2lRFHVULA3qlWur4CmXjumgmrvqIlsXG4 R/xEWo1ZGcH6b0Sc6ycH17/pNlx9+mKHkyi6F6lrSr1+LNqs3iut26eoB+thhNx3YYnw XWbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VGwF8ASJ; 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 k26si1293484ejv.260.2020.05.13.23.29.35; Wed, 13 May 2020 23:29:57 -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=VGwF8ASJ; 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 S1726056AbgENG1x (ORCPT + 99 others); Thu, 14 May 2020 02:27:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:51222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgENG1x (ORCPT ); Thu, 14 May 2020 02:27:53 -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 2AEED206B6; Thu, 14 May 2020 06:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589437672; bh=ZZL/VqoacdeBCG/xZqKQotkNP7fuRxsK35yGhyyUx20=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VGwF8ASJoWP8ykgSGEL/7yAp6tuDZFLCWd4GHadPK/Jy0EBZUBanEEfCeTEKkWSl/ gTpl4Q/qikRRcaE8ItuVW2nz+/MdymI14MUHKX8IVb5daWtH8bphPFAUaSuXKS/9ww ky/9xD1YMqx6jyqbMhrZX2Kyl0nxHS2VmJkHP6fo= Date: Thu, 14 May 2020 08:27:50 +0200 From: Greg KH To: Christoph Hellwig Cc: 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: Validating dma_mmap_coherent() parameters before calling (was Re: WARNING in memtype_reserve) Message-ID: <20200514062750.GA1488715@kroah.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200514061417.GA8367@lst.de> 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: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. Details on why this was changed is in the commit changelog, but this has triggered a WARN_ON() in memtype_reserve when I think some odd data buffers were sent to it by syzbot fuzzing. The warning caught the wrong data, but triggered syzbot. So, the question is, should all callers of dma_mmap_coherent() validate the parms better before it is called, or should the call chain here properly sanitize things on their own. Note, usbfs is not the only direct-from-userspace caller of dma_mmap_coherent(), it's also used in other userspace apis (frame buffer drivers, fastrpc, some SoC drivers) but it looks like nothing has fuzzed those apis before to trigger this. Does that help explain things better? thanks, greg k-h