Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2459390pxk; Mon, 14 Sep 2020 14:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxcVWS7ezuPGUGKD+hlQt/5Umxlwf6Jj/XDYygse1UKE4UNartXzBzhlt76RIn7OiEH6Y1 X-Received: by 2002:a17:906:7116:: with SMTP id x22mr17184679ejj.426.1600117495514; Mon, 14 Sep 2020 14:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600117495; cv=none; d=google.com; s=arc-20160816; b=nizrTGYfid2/sW9fRQrNzVcO1u5Wj2F31MyfFH5azqRWscU1z78wdPXh5BAaKk9FIH aFHu866JLU+13gkWuDTiXNDT53bUeTOfUqfjUYxDruk/7pNvP2ZIBjWK0fjbgZ/F2fxW AmILmFQPdfnOhJCyZoXtMY13gccqX6Qx55RBoiOENO3g9wnChCc/mXQVWkSJIvUFREch PQ46PoLMu65A7KNC2JhRDxm/kDta/AKXTALNVl+9vnQmFFL0Rc7ER49JLRCvdlvW1+31 rAj1gImd8yIlVCmHYNfow9fKCl9E8bg1MNlHhvNb7FEKIlE57zcOLctltqtH71EMYD4+ wGWA== 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:ironport-sdr:ironport-sdr; bh=g+xm5Yz7LP+3AaG6GMpz31znFduMTa5r+QQvO8BGR7E=; b=LpEk9WJwQgm+KOUHGHrD/7Cixhh8qJ+nKd5lof6LR4Xaal+YDbSoICyTJHvkpoN6j1 o6GA6Frkx/hAwJnXn8WdKBX/hnhlXv5/sQ4jI9fjPG+APNBUUH0KFn/dY6R5td9rwMhi K8IKR6HSWsy2wQHsu8DTCTWANt6JbkFn1cDqJfgKj3KDtmm59oEufR0AcK2wj9Ryv5Fc N1iEPAX/7uxU+4JejPIIr1tjVca++nBQvDYZ0BMomYDYBNlPZDi8+A8k2jRhtwPIQGRq iviOx1kj8oGz16+K8JkZfcJBfPXt0T3Zt2OHoULu6PzDVw0kFHdgAGqcaNNAB7iytG4e tfPw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si7854938edq.370.2020.09.14.14.04.33; Mon, 14 Sep 2020 14:04:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726091AbgINVBp (ORCPT + 99 others); Mon, 14 Sep 2020 17:01:45 -0400 Received: from mga12.intel.com ([192.55.52.136]:25663 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725926AbgINVBo (ORCPT ); Mon, 14 Sep 2020 17:01:44 -0400 IronPort-SDR: dkrt5YU187XNYfPwEfJn8QrbJzzPJ8oDQTtGhlWez0ifvz/vgbqsJoY3j5+L/BEpvz2+LuTiFC 1flX/j6fRbrw== X-IronPort-AV: E=McAfee;i="6000,8403,9744"; a="138665623" X-IronPort-AV: E=Sophos;i="5.76,427,1592895600"; d="scan'208";a="138665623" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 14:01:42 -0700 IronPort-SDR: 2rUzirZ1BOdNHVS6tlDkjvSF5d4fx/aukTADPMK1gZLD0zuUV43HzP4jCck6plmzioPoypXg2y eI12kdtC8QTA== X-IronPort-AV: E=Sophos;i="5.76,427,1592895600"; d="scan'208";a="451032932" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 14:01:42 -0700 Date: Mon, 14 Sep 2020 14:01:41 -0700 From: Ira Weiny To: Souptick Joarder Cc: Jason Gunthorpe , Matthew Wilcox , Andrew Morton , Linux-MM , linux-kernel@vger.kernel.org, John Hubbard Subject: Re: [PATCH] mm/gup.c: Handling ERR within unpin_user_pages() Message-ID: <20200914210141.GD878166@iweiny-DESK2.sc.intel.com> References: <1600007555-11650-1-git-send-email-jrdr.linux@gmail.com> <20200913145520.GH6583@casper.infradead.org> <20200914140814.GE1221970@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 02:22:33AM +0530, Souptick Joarder wrote: > On Mon, Sep 14, 2020 at 7:38 PM Jason Gunthorpe wrote: > > > > On Mon, Sep 14, 2020 at 07:20:34AM +0530, Souptick Joarder wrote: > > > On Sun, Sep 13, 2020 at 8:25 PM Matthew Wilcox wrote: > > > > > > > > On Sun, Sep 13, 2020 at 08:02:35PM +0530, Souptick Joarder wrote: > > > > > It is possible that a buggy caller of unpin_user_pages() > > > > > (specially in error handling path) may end up calling it with > > > > > npages < 0 which is unnecessary. > > > > > @@ -328,6 +328,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages) > > > > > { > > > > > unsigned long index; > > > > > > > > > > + if (WARN_ON_ONCE(npages < 0)) > > > > > + return; > > > > > > > > But npages is unsigned long. So it can't be less than zero. > > > > > > Sorry, I missed it. > > > > > > Then, it means if npages is assigned with -ERRNO by caller, unpin_user_pages() > > > may end up calling a big loop, which is unnecessary. > > > > How will a caller allocate memory of the right size and still manage > > to call with the wrong npages? Do you have an example of a broken caller? > > These are two broken callers which might end up calling unpin_user_pages() > with -ERRNO. > drivers/rapidio/devices/rio_mport_cdev.c#L952 The error here is that nr_pages should not be set to pinned if pinned is < 0. Why not fix the logic there? Because it is inherently dangerous to set an unsigned from a signed variable like that. > drivers/misc/mic/scif/scif_rma.c#L1399 Again this is a caller who is not properly checking error conditions. > > They both are in error handling paths, so might not have any serious impact. > But theoretically possible. Actually I think they might have serious problems so they both should be fixed. In the end this patch just can't work because npages can't be < 0 like Matthew said. Ira