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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D19BC433F5 for ; Fri, 4 Feb 2022 11:42:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9A886B0072; Fri, 4 Feb 2022 06:42:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4AFB6B0073; Fri, 4 Feb 2022 06:42:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C137D6B0074; Fri, 4 Feb 2022 06:42:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id B3E686B0072 for ; Fri, 4 Feb 2022 06:42:49 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7874496F18 for ; Fri, 4 Feb 2022 11:42:49 +0000 (UTC) X-FDA: 79104910458.08.634B7DD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf12.hostedemail.com (Postfix) with ESMTP id E2B6D40004 for ; Fri, 4 Feb 2022 11:42:48 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D4732210FB; Fri, 4 Feb 2022 11:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1643974967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5vTMEeuc5XcaxXNy7RhPX2Qj+TF9VsgpJldSEApLliY=; b=shIYF4Q81+Q7n2FnlCw4AleLDUBuS+Vp14Nlvawm65Md73a6NHXv6fnJJEfUiG5puSo6p6 mp4KfJQ+S/RtFzk5cRI02O1Yz2kfYJPt/KVdpcd0b9YtKRLsltrTQNQ2oVReTahqXwce5X k5iV43fTTjE9AsKPlUnKbpC+kDzwrKc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1643974967; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5vTMEeuc5XcaxXNy7RhPX2Qj+TF9VsgpJldSEApLliY=; b=tMa6OywQY7J+wtQOvfqQ0fpqhivw/YXG0qt/1HglAAN5YoEjadOBG3gKQr5zFDMLDODeNg aaxEu/ZqSf+W2XCQ== Received: from quack3.suse.cz (unknown [10.163.28.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id B7342A3B84; Fri, 4 Feb 2022 11:42:47 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 5AA3FA05B6; Fri, 4 Feb 2022 12:42:47 +0100 (CET) Date: Fri, 4 Feb 2022 12:42:47 +0100 From: Jan Kara To: John Hubbard Cc: Andrew Morton , Peter Xu , Jason Gunthorpe , David Hildenbrand , Lukas Bulwahn , Claudio Imbrenda , Christoph Hellwig , Matthew Wilcox , Jan Kara , "Kirill A . Shutemov" , Alex Williamson , Andrea Arcangeli , LKML , linux-mm@kvack.org Subject: Re: [PATCH v4 1/5] mm: Fix invalid page pointer returned with FOLL_PIN gups Message-ID: <20220204114247.dupafq4yogate2sz@quack3.lan> References: <20220204020010.68930-1-jhubbard@nvidia.com> <20220204020010.68930-2-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220204020010.68930-2-jhubbard@nvidia.com> X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E2B6D40004 X-Stat-Signature: tqzf3cso3fydrcna1d4tr16rj6k8kcp7 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=shIYF4Q8; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=tMa6OywQ; spf=pass (imf12.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none X-HE-Tag: 1643974968-144717 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 Thu 03-02-22 18:00:06, John Hubbard wrote: > From: Peter Xu > > Alex reported invalid page pointer returned with pin_user_pages_remote() from > vfio after upstream commit 4b6c33b32296 ("vfio/type1: Prepare for batched > pinning with struct vfio_batch"). > > It turns out that it's not the fault of the vfio commit; however after vfio > switches to a full page buffer to store the page pointers it starts to expose > the problem easier. > > The problem is for VM_PFNMAP vmas we should normally fail with an -EFAULT then > vfio will carry on to handle the MMIO regions. However when the bug triggered, > follow_page_mask() returned -EEXIST for such a page, which will jump over the > current page, leaving that entry in **pages untouched. However the caller is > not aware of it, hence the caller will reference the page as usual even if the > pointer data can be anything. > > We had that -EEXIST logic since commit 1027e4436b6a ("mm: make GUP handle pfn > mapping unless FOLL_GET is requested") which seems very reasonable. It could > be that when we reworked GUP with FOLL_PIN we could have overlooked that > special path in commit 3faa52c03f44 ("mm/gup: track FOLL_PIN pages"), even if > that commit rightfully touched up follow_devmap_pud() on checking FOLL_PIN when > it needs to return an -EEXIST. > > Attaching the Fixes to the FOLL_PIN rework commit, as it happened later than > 1027e4436b6a. > > Cc: Andrea Arcangeli > Cc: Andrew Morton > Cc: Jan Kara > Cc: Kirill A. Shutemov > Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages") > Reviewed-by: Claudio Imbrenda > Reported-by: Alex Williamson > Debugged-by: Alex Williamson > Tested-by: Alex Williamson > Signed-off-by: Peter Xu > [jhubbard: added some tags, removed a reference to an out of tree module.] > Signed-off-by: John Hubbard Makes sence. Feel free to add: Reviewed-by: Jan Kara Honza > --- > mm/gup.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/gup.c b/mm/gup.c > index a9d4d724aef7..80229ecf0114 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -465,7 +465,7 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, > pte_t *pte, unsigned int flags) > { > /* No page to get reference */ > - if (flags & FOLL_GET) > + if (flags & (FOLL_GET | FOLL_PIN)) > return -EFAULT; > > if (flags & FOLL_TOUCH) { > -- > 2.35.1 > -- Jan Kara SUSE Labs, CR