Received: by 10.213.65.68 with SMTP id h4csp1426415imn; Wed, 4 Apr 2018 19:44:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jqfh2rMdAiaGCkgzSMhkWrmSle0PYdGMlJ2NsbogJH+gQjN6n3imYm89r9Exiq53t3/hY X-Received: by 2002:a17:902:43a4:: with SMTP id j33-v6mr21556515pld.260.1522896265974; Wed, 04 Apr 2018 19:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522896265; cv=none; d=google.com; s=arc-20160816; b=itNdo2qfpb3NBjrdVAPXbA/FYT9/90Sh+Xb4B8t0jZrx2JDDQgOKZ7kiJHNtPdf3AR 2wkV/niqBUkCT0lzn0RxBjerKjoehI7kasHHBLSQmdKUK5HEUsaZZcz5k5oUnUNhoohe U0OrJixmRXsKzIhf3IcH8xQyzRdXVVpXlEGVs7hqQHov3ybH7WDDlm7glL647Hn8vtsS 9p0XvG/5rtVTTIrgDxFCHKQE0DmJXWMJLPh2Azs9QuXvP25w9Ua20RW55DFQdNZvpo3e 0P6qs+7+mbVJNt+s/l8Eum60i5KJNJqrmAcasqzrZjSc7rmmQxnALndOFWYT2OfCukUT hLtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=ckGXvpfoPTu0nvbAZFYAm4asHzBvkx6Odf+ack5BgMQ=; b=BnWQQpSBp2qvI9GZqvFsbGAYqahQQbkFI26QtEz53QI5KrvjgxG40oNeGsZDGV/5vE /aacdYzUQ7v/BXHJIxr8ttLovwwe0QxjYg1upASeYyQGbg++4vCkj+4cLWH7SY5Vi7Bz kWXihZAflCn42dxhDVe7L4VkcmgLmbMFiIQNfE9SGDGATb62dTgStFmOM24A8UlH5xEo UO53ylHbtKfGBm0GqOd7E/kfEZS7vPmiM3LvUlkhgeE+g8+7/eRth4EHeBrQyQudT9fs By5BpV9Xvwc4uajnCyvOl5IBAOHMX6abzZQIMxmGCCBs/oq7W5R5XOiElGQuYVvqpZxW aWSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XxrheMIZ; dkim=fail header.i=@linux-foundation.org header.s=google header.b=WHnkoYhg; 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 i20si4821277pgn.711.2018.04.04.19.43.37; Wed, 04 Apr 2018 19:44:25 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XxrheMIZ; dkim=fail header.i=@linux-foundation.org header.s=google header.b=WHnkoYhg; 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 S1752789AbeDECkj (ORCPT + 99 others); Wed, 4 Apr 2018 22:40:39 -0400 Received: from mail-it0-f52.google.com ([209.85.214.52]:50247 "EHLO mail-it0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752692AbeDECkh (ORCPT ); Wed, 4 Apr 2018 22:40:37 -0400 Received: by mail-it0-f52.google.com with SMTP id r19-v6so1059889itc.0; Wed, 04 Apr 2018 19:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=ckGXvpfoPTu0nvbAZFYAm4asHzBvkx6Odf+ack5BgMQ=; b=XxrheMIZfYIUpm2H39b+d5V6VSJtrssmCKKleIaKVXIwn59vVV+k17ocFVw+NgD8cv q7idhUfhNypVn6dHTL/VNjVVHKC9ApISVH3ov0itRhu5CyfZCrJVLlfcKtpM87PBy7HU wc+uXa8z6oNPvMhKHiAjy82TvLyk6qijZEgepWioYl/jYSXHpYBZHUpR+Hz7ULMxwB3p aeBxcBp0BrqGBDyGxBZKJRd3XNBlkh9igpxAaIHQNFJvQnTb41nSeOznNFb12EB3XWvW 2iLdwUynUJOpPqrnyYjfv3QAL86zCFTKn/rGKneXU4fAeFJvA+Obo9P1H2HErlBFx6HJ Lc6w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=ckGXvpfoPTu0nvbAZFYAm4asHzBvkx6Odf+ack5BgMQ=; b=WHnkoYhg9FOKqpzP+BKcXW9rSklZ+/NilN2NhqJeht1LBC9w35f6UNcvSseo+xltrY hQuLCVIf2L7WfkSVoVRHF0sPjifJgnzsOVBckNcHfaVEwHIOYymF7N7EyRbItD2Nh763 AnKNg42MVIxNsPeePgcHMSxENpkmcrS8BuLnM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=ckGXvpfoPTu0nvbAZFYAm4asHzBvkx6Odf+ack5BgMQ=; b=XJvLcILLWThw8L8uU0T5y95oFY1rxZ6fTJevZgc2UYzzryCRCaKfGHi3M74stfmtof VtpYZ+XTlXTN3EmkcbRy3uv4vX/hledOxg+if5ds5Z+2dfCl5Ke/D0RdqSEkgr+mw+e0 /1G6wPj8X3R3A6xh7sLqhEE6piH60E/04N+uZShsNZYECTtbQTBrZhtxJSbCYMvk3ygB tGI815U/CbZWd9uRKlkdu9Yov2r5jQBlT5bjRPvqfUyvf3rFrLjIgsUYnB4Cqyqgn72X 1VOqG0jof0MiZSyoDAELFlYDZlnha4n5boFrPV5dMn/qPcMPiP5ZbCTsIuX+mLlCloaV KvTQ== X-Gm-Message-State: ALQs6tAv/eG+ox8w4HWqljHqRvf1foeYB71wU1O5Jgquuic46ScCdQRY 6uikZXHOnD8ECAgcEetIPwn2l/xstDDTS0zzoIU= X-Received: by 2002:a24:87c8:: with SMTP id f191-v6mr11768872ite.16.1522896037003; Wed, 04 Apr 2018 19:40:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.95.15 with HTTP; Wed, 4 Apr 2018 19:40:36 -0700 (PDT) In-Reply-To: <20180405045231-mutt-send-email-mst@kernel.org> References: <1522431382-4232-1-git-send-email-mst@redhat.com> <20180405045231-mutt-send-email-mst@kernel.org> From: Linus Torvalds Date: Wed, 4 Apr 2018 19:40:36 -0700 X-Google-Sender-Auth: hnWAnsyrlTUF3LEz99u205EcLts Message-ID: Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure To: "Michael S. Tsirkin" Cc: Linux Kernel Mailing List , stable , syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com, linux-mm , "Kirill A. Shutemov" , Andrew Morton , Huang Ying , Jonathan Corbet , Peter Zijlstra , Thomas Gleixner , Thorsten Leemhuis 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 On Wed, Apr 4, 2018 at 6:53 PM, Michael S. Tsirkin wrote: > > Any feedback on this? As this fixes a bug in vhost, I'll merge > through the vhost tree unless someone objects. NAK. __get_user_pages_fast() returns the number of pages it gets. It has never returned an error code, and all the other versions of it (architecture-specific) don't either. If you ask for one page, and get zero pages, then that's an -EFAULT. Note that that's an EFAULT regardless of whether that zero page happened due to kernel addresses or just lack of mapping in user space. The documentation is simply wrong if it says anything else. Fix the docs, and fix the users. The correct use has always been to check the number of pages returned. Just looking around, returning an error number looks like it could seriously confuse some things. You have things like the kvm code that does the *right* thing: unsigned long ... npinned ... npinned = get_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages); if (npinned != npages) { ... err: if (npinned > 0) release_pages(pages, npinned); and the above code clearly depends on the actual behavior, not on the documentation. Any changes in this area would need some *extreme* care, exactly because of code like the above that clearly depends on the existing semantics. In fact, the documentation really seems to be just buggy. The actual get_user_pages() function itself is expressly being careful *not* to return an error code, it even has a comment to the effect ("Have to be a bit careful with return values"). So the "If no pages were pinned, returns -errno" comment is just bogus. Linus