Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4256814ybi; Mon, 3 Jun 2019 08:02:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqztMazgjRKvyqT+wLbMU0DeMf8GYdm+gjoC02eyNx3RlTR4an0nz9EAoRqm/fPgxKzngt90 X-Received: by 2002:a63:4826:: with SMTP id v38mr28996671pga.417.1559574151659; Mon, 03 Jun 2019 08:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559574151; cv=none; d=google.com; s=arc-20160816; b=Wzza2ZjUJWoZTrAo54+T0tzPfeS/5M1/g9PR/cksfN1qH6u6V3NztuaHf5NBGq/hiG z5UU4JBrHlV65ixjSYqpodtQgnfeXE3eLJzwuf1IVGDOGHx86VGwdB/56VwU+HGRBBrD BUHxWrndzmRLM4gQe2an8NBT+qA0whDZD5A/JcrErG5h8IvSfacUWgIi9gXJmyum+/3s mZ9g/yUczF6fkh7KOfWVBlZ2tVhp9km4+4WdxJAUR2Nxg+cToK2ZFYcutxZdnFLPPBuR LlwmeDfL1emm6FB+L7dk0cNvBSw67Xu/f3gZyPnWuZrkPtTi+CyGYYIXWMq3IXq+UTEw YEuA== 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=H+ENw6jrAqiv5XC0bufM+Z1ad7r4ORDIUJsEgu2DM9I=; b=fuBRuV6aNARMc0WBNKujy+S3S1+iqxlXyb8WcXDrGvm3wEGyH5CW7YgnS0Y4VhROuG XwaeEi+TjXRfqlXEjNA1VSeWr7d8ATJEZKQwey9DFcy84Ix4IsUpYxvsyCNlLufGJ0a/ 4O+8mqDMKdyLTXhJl/bkozdgjLnYtMhiDb62lNmtpMG3AO5BuO7/F++At1Pj/2luedPi blRV0ibTteI66pGaJ9yxvJ9Cm3ghgjsS0y4i5KF2ci235v4rzPyJXUBee0Ni2cI/1L8C WH/3B2wBdEiKHxfkjDayAzY4jnSFU+eQ+SdhfJAqZPRaS3tNuf5Av2ddMC90e1LMEii3 XKEA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3si17551453pjb.61.2019.06.03.08.02.12; Mon, 03 Jun 2019 08:02:31 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729344AbfFCO7B (ORCPT + 99 others); Mon, 3 Jun 2019 10:59:01 -0400 Received: from mga17.intel.com ([192.55.52.151]:34041 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729123AbfFCO7A (ORCPT ); Mon, 3 Jun 2019 10:59:00 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jun 2019 07:59:00 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by FMSMGA003.fm.intel.com with ESMTP; 03 Jun 2019 07:58:59 -0700 Date: Mon, 3 Jun 2019 08:00:08 -0700 From: Ira Weiny To: Pingfan Liu Cc: linux-mm@kvack.org, Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , John Hubbard , "Aneesh Kumar K.V" , Keith Busch , linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 1/2] mm/gup: fix omission of check on FOLL_LONGTERM in get_user_pages_fast() Message-ID: <20190603150007.GA26623@iweiny-DESK2.sc.intel.com> References: <1559543653-13185-1-git-send-email-kernelfans@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1559543653-13185-1-git-send-email-kernelfans@gmail.com> 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 Mon, Jun 03, 2019 at 02:34:12PM +0800, Pingfan Liu wrote: > As for FOLL_LONGTERM, it is checked in the slow path > __gup_longterm_unlocked(). But it is not checked in the fast path, which > means a possible leak of CMA page to longterm pinned requirement through > this crack. > > Place a check in the fast path. > > Signed-off-by: Pingfan Liu Reviewed-by: Ira Weiny > Cc: Ira Weiny > Cc: Andrew Morton > Cc: Mike Rapoport > Cc: Dan Williams > Cc: Matthew Wilcox > Cc: John Hubbard > Cc: "Aneesh Kumar K.V" > Cc: Keith Busch > Cc: linux-kernel@vger.kernel.org > --- > mm/gup.c | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/mm/gup.c b/mm/gup.c > index f173fcb..6fe2feb 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2196,6 +2196,29 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages, > return ret; > } > > +#if defined(CONFIG_CMA) > +static inline int reject_cma_pages(int nr_pinned, unsigned int gup_flags, > + struct page **pages) > +{ > + if (unlikely(gup_flags & FOLL_LONGTERM)) { > + int i = 0; > + > + for (i = 0; i < nr_pinned; i++) > + if (is_migrate_cma_page(pages[i])) { > + put_user_pages(pages + i, nr_pinned - i); > + return i; > + } > + } > + return nr_pinned; > +} > +#else > +static inline int reject_cma_pages(int nr_pinned, unsigned int gup_flags, > + struct page **pages) > +{ > + return nr_pinned; > +} > +#endif > + > /** > * get_user_pages_fast() - pin user pages in memory > * @start: starting user address > @@ -2236,6 +2259,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, > ret = nr; > } > > + nr = reject_cma_pages(nr, gup_flags, pages); > if (nr < nr_pages) { > /* Try to get the remaining pages with get_user_pages */ > start += nr << PAGE_SHIFT; > -- > 2.7.5 >