From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D452C433E2 for ; Mon, 14 Sep 2020 21:01:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AFF3321D41 for ; Mon, 14 Sep 2020 21:01:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFF3321D41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0CED08E0007; Mon, 14 Sep 2020 17:01:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0574B8E0001; Mon, 14 Sep 2020 17:01:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E38E98E0007; Mon, 14 Sep 2020 17:01:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id CB6398E0001 for ; Mon, 14 Sep 2020 17:01:46 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 80027181AEF1E for ; Mon, 14 Sep 2020 21:01:46 +0000 (UTC) X-FDA: 77262888612.23.lift93_261829c2710b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 636FD3760C for ; Mon, 14 Sep 2020 21:01:46 +0000 (UTC) X-HE-Tag: lift93_261829c2710b X-Filterd-Recvd-Size: 4015 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 21:01:44 +0000 (UTC) IronPort-SDR: 9rYV6TEt0e/zivfYAYTzX6Y7bi9rcIx1TQ8V8rib5EG7VDhsySJFagBpwc7hmS/1bIRM2l33+2 GIY0Z0AWiZZQ== X-IronPort-AV: E=McAfee;i="6000,8403,9744"; a="177225022" X-IronPort-AV: E=Sophos;i="5.76,427,1592895600"; d="scan'208";a="177225022" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.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) X-Rspamd-Queue-Id: 636FD3760C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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