Received: by 10.213.65.68 with SMTP id h4csp1391823imn; Wed, 4 Apr 2018 18:55:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+oBSLwWvKC78XRokKMPPaRuBnDUTBtY3eZBQw8eNC2V1/FAZg/7BqbPRW4AdTyGs+zz1GC X-Received: by 10.99.63.205 with SMTP id m196mr13152308pga.82.1522893309666; Wed, 04 Apr 2018 18:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522893309; cv=none; d=google.com; s=arc-20160816; b=pMPlK63INg48VHmdQpGfvU++f+7H+YBVTFkvFuLnx/o7rMz98vUDHkD8uZ2sjMuJdY odwavYyWyd8NyYWzg1YFZQJ6TqCDj/jPsY+bv6z8NlHfDOCIxP/JhPSSiPCHQ4o9tJDP K/3EQkjSKCXGD5fhIjeQTFvFvpIiQTujGRX6guNcOg50mnzojRNTmZx9XhbasagTXnWt S7f5RPVQZs6pKi7MnGwYLG9qoA9iUPRD+LuFLlbb8z/S7/1p0GvtmB6HO31ij7W5xTa/ il5R8Js0Bcqb9c2waCCOFsAONB+TJKOt0hQhYcGpkEvfCVEggSczJ5wMGVno3brdtZ8Z vlVA== 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 :arc-authentication-results; bh=R5lPxYN3uiqmed0+uG//QmouQDGONZ2KqTTZ9U/RiFk=; b=th3riVashfL1jJSdCGw2GjfYTLJsUgd5cBCJeOw18NB7sACR5+LMv4VWk6EEuHsWT9 wvv7/E4Bz/yvqDbQQfHgTIoTAklfHxPqVxNBOOOrIDiMSFy7DFhyhBZ9QZ6K7SJGBlUo arudcasa8RdGdlmKCFaOcllMlrxoRciFNPAxV53oYqKYKXvM5iiv0dQDHJijZU7iIzwo 0IX8/5Y+z8Odk5gMt1MNGkGHSOCMHrji4r+3ZZ+VUrSWAiYcKc7OnGnjqJAYS+0uMgYP W0J/mo4EvchiFixhn4gV86/11XGPhxlFMV6Lf+XFFI28jB8jfXuW4Y/FuKBfomKLZy8y zl5A== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si4602050pgc.670.2018.04.04.18.54.55; Wed, 04 Apr 2018 18:55:09 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752852AbeDEBxP (ORCPT + 99 others); Wed, 4 Apr 2018 21:53:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60808 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752642AbeDEBxO (ORCPT ); Wed, 4 Apr 2018 21:53:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4A3E4040859; Thu, 5 Apr 2018 01:53:13 +0000 (UTC) Received: from redhat.com (ovpn-120-181.rdu2.redhat.com [10.10.120.181]) by smtp.corp.redhat.com (Postfix) with SMTP id 31DF0215CDAF; Thu, 5 Apr 2018 01:53:12 +0000 (UTC) Date: Thu, 5 Apr 2018 04:53:12 +0300 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com, linux-mm@kvack.org, "Kirill A. Shutemov" , Andrew Morton , Huang Ying , Jonathan Corbet , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Thorsten Leemhuis Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure Message-ID: <20180405045231-mutt-send-email-mst@kernel.org> References: <1522431382-4232-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522431382-4232-1-git-send-email-mst@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 05 Apr 2018 01:53:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 05 Apr 2018 01:53:13 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 30, 2018 at 08:37:45PM +0300, Michael S. Tsirkin wrote: > get_user_pages_fast is supposed to be a faster drop-in equivalent of > get_user_pages. As such, callers expect it to return a negative return > code when passed an invalid address, and never expect it to > return 0 when passed a positive number of pages, since > its documentation says: > > * Returns number of pages pinned. This may be fewer than the number > * requested. If nr_pages is 0 or negative, returns 0. If no pages > * were pinned, returns -errno. > > Unfortunately this is not what the implementation does: it returns 0 if > passed a kernel address, confusing callers: for example, the following > is pretty common but does not appear to do the right thing with a kernel > address: > > ret = get_user_pages_fast(addr, 1, writeable, &page); > if (ret < 0) > return ret; > > Change get_user_pages_fast to return -EFAULT when supplied a > kernel address to make it match expectations. > > __get_user_pages_fast does not seem to be used like this, but let's > change __get_user_pages_fast as well for consistency and to match > documentation. > > Lightly tested. > > Cc: Kirill A. Shutemov > Cc: Andrew Morton > Cc: Huang Ying > Cc: Jonathan Corbet > Cc: Linus Torvalds > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Thorsten Leemhuis > Cc: stable@vger.kernel.org > Fixes: 5b65c4677a57 ("mm, x86/mm: Fix performance regression in get_user_pages_fast()") > Reported-by: syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com > Signed-off-by: Michael S. Tsirkin Any feedback on this? As this fixes a bug in vhost, I'll merge through the vhost tree unless someone objects. > --- > mm/gup.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 6afae32..5642521 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -1749,6 +1749,9 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, > unsigned long flags; > int nr = 0; > > + if (nr_pages <= 0) > + return 0; > + > start &= PAGE_MASK; > addr = start; > len = (unsigned long) nr_pages << PAGE_SHIFT; > @@ -1756,7 +1759,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, > > if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, > (void __user *)start, len))) > - return 0; > + return -EFAULT; > > /* > * Disable interrupts. We use the nested form as we can already have > @@ -1806,9 +1809,12 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, > len = (unsigned long) nr_pages << PAGE_SHIFT; > end = start + len; > > + if (nr_pages <= 0) > + return 0; > + > if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, > (void __user *)start, len))) > - return 0; > + return -EFAULT; > > if (gup_fast_permitted(start, nr_pages, write)) { > local_irq_disable(); > -- > MST