Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1789313yba; Sun, 7 Apr 2019 00:01:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVbTLEMViLACXVykZqPp2JBKnePeTj2Pnpeng9dEWfPXrf0GBOa8jMEnIut2TZ8zX0IuGJ X-Received: by 2002:a62:184a:: with SMTP id 71mr4114476pfy.1.1554620502819; Sun, 07 Apr 2019 00:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554620502; cv=none; d=google.com; s=arc-20160816; b=Z/frbimUHwufuGJHKIo4WA4xt3aJDRitu1XUkKl0TJ7fhP9zzkSJTZHid0VxzwkPgu wm6YpMNgg8a3M4WVoH/2NHpg6Nccag1RaYXimWDgNQJGeLv6BGAfyYikznK8EKFUM2P2 Gl68aib/DhmA+7GseEnAwTo8o9U3tJ+ZhZ/Zk9R8+XSuHohfhPrNWm7EdsmacIQJ3cDw ObIrnWC8p0CQ8NML1d0U5yqTVF7Xwk943AGA5tyl+hdo61imjjrhOyoMJWzMfsLUBMJp Qfn8NdyGzJ3uiTsnd2n0giAzo7cv47QM+uLYYfeLMLgh8U3uS9n3XRiYUg/DHcFDIR4Y yDig== 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=udeFYY97AUaVi5uUg5i5+vAr9ddxUiSs9q76UzhjZTY=; b=cRnBW6hv25CdbPpfhWQ7HwdbkEW8Agw2rRFUlpssMyqBaSrhrsUsMuNTRRIUbDl7HZ SB+HwBQTs9BnP53/lPrj612TMn2lM8TgecYF0xMrgevY0mIpuehlTAr3iaROjddeIPWd 0Rm22yenKfY+0MMf1wSCzBfgOHO3h3w/b4xv8LHYQOYXFtKtAtcMHfbq6dgajDrTWcei +mot0rKvOfCbXAjEN5caRS+dPMv94xZxmPZTx++0Dh/jl6S3gUCxzHxmQQG+8f2zUprl NlsmG6IbjP39x0qRE+H6ci/z4DtUNREPpxHqX03tUNPNF0ZkgESSe82nyZsuOUGIeXYQ YE1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1si7426967plo.212.2019.04.07.00.01.27; Sun, 07 Apr 2019 00:01:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726314AbfDGG7g (ORCPT + 99 others); Sun, 7 Apr 2019 02:59:36 -0400 Received: from verein.lst.de ([213.95.11.211]:35788 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbfDGG7g (ORCPT ); Sun, 7 Apr 2019 02:59:36 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id B7D2A67329; Sun, 7 Apr 2019 08:59:23 +0200 (CEST) Date: Sun, 7 Apr 2019 08:59:23 +0200 From: Christoph Hellwig To: Robin Murphy Cc: Christoph Hellwig , Joerg Roedel , Catalin Marinas , Will Deacon , Tom Lendacky , iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 02/21] arm64/iommu: improve mmap bounds checking Message-ID: <20190407065923.GA9086@lst.de> References: <20190327080448.5500-1-hch@lst.de> <20190327080448.5500-3-hch@lst.de> <3629087c-a8cb-d66e-840b-cfee125bdf4c@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3629087c-a8cb-d66e-840b-cfee125bdf4c@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 Fri, Apr 05, 2019 at 06:30:52PM +0100, Robin Murphy wrote: > On 27/03/2019 08:04, Christoph Hellwig wrote: >> The nr_pages checks should be done for all mmap requests, not just those >> using remap_pfn_range. > > Hmm, the logic in iommu_dma_mmap() inherently returns an error for the "off > >= nr_pages" case already. It's also supposed to be robust against the > "vma_pages(vma) > nr_pages - off" condition, although by making the partial > mapping and treating it as a success, rather than doing nothing and > returning an error. What's the exact motivation here? Have one error check at the front of the function that is identical to the mmap checks in the other dma_map_ops instances so that: a) we get the same error behavior for partial requests everywhere b) we can lift these checks into common code in the next round.