Received: by 10.192.165.156 with SMTP id m28csp266326imm; Tue, 17 Apr 2018 09:48:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xKxLl7sVd9wGx7L3pQdFFSBB46kna7IOe63qdFOBOqLlg9AW/P1R/gxQaSfdGcp6wqP42 X-Received: by 10.98.224.76 with SMTP id f73mr2661209pfh.88.1523983685586; Tue, 17 Apr 2018 09:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523983685; cv=none; d=google.com; s=arc-20160816; b=OXegAkB6pZyG72d9w5mit7h6TADsti2Dpit20stg5cTQvAzxT1A46x5//JXdMc3Q5V WA4T+gpCO3sr7I8YYBSeUtUlyrHTcJDsQlYrdJC7J2tin8ym5C+sBDRuJGTeBtpOGp4C hxLQs+tHEvLHXeyf71Smbm29Veg8oJ0j8feRVGEbFiKJ42231fGcuewenKkKKr9aM/UD QNbYvWIR1vuB3hsfXEvWQIZk0An85rYPav31xL0u0KVgepeoZM7iCj1zKW58LqnUyP2H Vww3PQTQ2YKZA7g34ZIk4Cz6ouiRLIg8QgDmUFP1my6xhj2x7gCW8RRNAy2UdoVznj59 KF+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QU95Cag0VF+yPrwu+s5y87iJtp5K4MC8b484xtYOHRM=; b=kMWsWv4XhBwCTB4fN7sgttxzJXfN5lOnvsrGLW5caJlTyl0j+sU4Egjs6xOr24rVER YWy2crSOHYw5Mb5+DxgUBlSzsTyoUClPK3RoCuoxznJoz1jmZB9zGMwT+EJsbLkCnXdE PbMx06+QfqiLyv1KWu994oGSATOcDWuvSFDR9g93e3tHemLH1+P7HlaNUb1FcJ1Xl2V4 5dcWRPxIsYpK8jgU174+1+rlXKNaOHPL8IxNPy7tjAhwEPK+SIZ7NBKU7AwM2Pc1cdk2 WJ75e7M1lYtB+i3X/wbvBzBzQJOeln6BAwjhYiXzFY46HGMdYFwPFCN+3eNth6eTwTTi KdcQ== 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 w31-v6si14828959pla.193.2018.04.17.09.47.51; Tue, 17 Apr 2018 09:48:05 -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 S1754788AbeDQQFg (ORCPT + 99 others); Tue, 17 Apr 2018 12:05:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34580 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754739AbeDQQFd (ORCPT ); Tue, 17 Apr 2018 12:05:33 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5AF03C98; Tue, 17 Apr 2018 16:05:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" , syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com, Andrew Morton , "Kirill A. Shutemov" , Huang Ying , Jonathan Corbet , Peter Zijlstra , Thomas Gleixner , Thorsten Leemhuis , Linus Torvalds Subject: [PATCH 4.15 47/53] get_user_pages_fast(): return -EFAULT on access_ok failure Date: Tue, 17 Apr 2018 17:59:12 +0200 Message-Id: <20180417155725.369805968@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155723.091120060@linuxfoundation.org> References: <20180417155723.091120060@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin commit c61611f70958d86f659bca25c02ae69413747a8d upstream. 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. When get_user_pages_fast fall back on get_user_pages this is exactly what happens. Unfortunately the implementation is inconsistent: 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. All callers have been audited for consistency with the documented semantics. Link: http://lkml.kernel.org/r/1522962072-182137-4-git-send-email-mst@redhat.com Fixes: 5b65c4677a57 ("mm, x86/mm: Fix performance regression in get_user_pages_fast()") Signed-off-by: Michael S. Tsirkin Reported-by: syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com Reviewed-by: Andrew Morton Cc: Kirill A. Shutemov Cc: Huang Ying Cc: Jonathan Corbet Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Thorsten Leemhuis Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/gup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/mm/gup.c +++ b/mm/gup.c @@ -1816,9 +1816,12 @@ int get_user_pages_fast(unsigned long st 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();