Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3831286pxb; Fri, 4 Feb 2022 18:25:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoy2LizAcIFZFEw9Fwsm35Odyh31r+2Wjfl6DJwmFwf5dsZIE8NxIZg7KG/Jwugu2BMLQc X-Received: by 2002:a63:844a:: with SMTP id k71mr1475922pgd.610.1644027955415; Fri, 04 Feb 2022 18:25:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644027955; cv=none; d=google.com; s=arc-20160816; b=Q6idvYuNZKU8WDxeYEvBMyrI5n7WOOsWQoUkQkdhzVLabF5PrsDy0fgVpmn4+uQT7z IfQy6VE6ytERbW0T19f/gXfgJhXqRARDED5paZxyocojiUnYbZzC7WHchFBMPvI8RuBK AWz2WUHIC/CxkOyaZ6HNiPd3RTz+5GB8DL8E/a5KSQJ4P6dGJkYIZnQCYVeAOSPGbFCu /67G46sA34USK675AXENQg0YqNBSBVh2wigZYKUUWdWFsJUCRiTA9CCQbqeqwrXW3j8L 7qfolZQjyXvGA/mLnYRc2TNYo1MNnY6CTFUs+ln/JZXlkXOjukp/5qhHs5KgB9HVF4yJ e5VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=5vTMEeuc5XcaxXNy7RhPX2Qj+TF9VsgpJldSEApLliY=; b=Uk26xaNVXyoWHNuZVsLO2CbKOFrnw3pzJQPfgMS0ytRutV+YcME52WU/zeLomhKc9l eSsDkGNkQDu1AJWR7hp+I/5RByXaIzJj3OvXUphDYLpIlTmrGz6wtEFvBLSvCf2WkMAI YPZdV2H3bXcLkdxgNPZFedqAR+Gy82PkkXosR8zJ1IdpC7FZYs1pWKXhWhomHsrnBwWO 07lgZO84mwqXlNzqimoB9ub/nMsEuWDy8K/ZY9LpVsrQXbOe5wFyuzLgEjUkQ3Y0lCfB M5o/GJHewNuhTUgO2xG+z4ScxObQU+e1vBWx+L0qSwkb44aPho+5yoKLTPf6neO44gTG li0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=shIYF4Q8; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v25si3126515pfn.125.2022.02.04.18.25.42; Fri, 04 Feb 2022 18:25:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=shIYF4Q8; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358470AbiBDLmu (ORCPT + 99 others); Fri, 4 Feb 2022 06:42:50 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:52252 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbiBDLms (ORCPT ); Fri, 4 Feb 2022 06:42:48 -0500 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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