Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3387679lqp; Tue, 26 Mar 2024 07:57:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3f7zNxq/CUsHpKPOzVrux1jZwcpTOreutZOSo9o960Va+nV294DKCQCOcwmyz00nq9LpGUvcemAHLmlcBke9mkVtjtHUkjZFpBjWCtw== X-Google-Smtp-Source: AGHT+IF4GSjn0Uck5BO5qex/lrb9SyRPSnnTLQQJJ3b2Dxgl7jc3Mf3K0+FCN/b2LcGgxwyMcxwB X-Received: by 2002:a17:906:2786:b0:a49:dfe1:d5e with SMTP id j6-20020a170906278600b00a49dfe10d5emr995282ejc.57.1711465053730; Tue, 26 Mar 2024 07:57:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711465053; cv=pass; d=google.com; s=arc-20160816; b=Kv3QHPeMynjuRQWFiLGteK/Nroz6SsdNqIviDQkk+DOjOL/k4njbwteJBBDrcV51EP lOYUDtK52eyL1QpGUEIB25KjvDwUogiY5ejRflIk56o9fuJ6uayG9rGXFYaJdAs+QCMu qKFOg02n2SR/Sn8JoYE7ovqlVY/mCnFfrypLsG5mtNn1U8pBWu046+cQP1r5gW85vLjo eD6MWJC7qLROQ9gbmNby0tL3TzvTnjETpniGLkVvaPkZseVr/9S7SlK2lAokFFwC8bFu MluLCM20XUWBXIXLYF3PUG2A60GY/9o88xtOOGiyhePV5GOmNTtDdfxlA1V1sWyCAbDc aMng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4uIJUGLkQRKUQyCGjAWUoWWKWykk3vu+aCljlwkTmV4=; fh=0UnQsk/OcTQhDIfvQF6WIS2vS+/sFvedADLzUuGIGwk=; b=N3Jx+wl+uokSohedy4PJazEOL9HDocrCuok8t1Qv2XZ8F5YEBrxr7Qh6zhbmAgilTm 0tlU0pOnz/I7YIEFyIf/7U0aoyTtZZY8lcRaStVOiB0lWhj9/ZilEKLFvttFgsMLar6R XcnV2NRYxoKfgsM95hxA0JU9NeWtw/bZifVVVTKEJtLHTma6jeySff81+Xf1Myr1oIDW dn6a7dMMoHNTpGZNWrpz8jNcfsBM9i1ar3Nr8huMlcodn9n3t2cfbW7WF7I4V05hzbnF WbVzgC366S7yeaLEsgaekzfWjhdJ8tYh0pc7JsHK8fvOtEyduFT9D18UMLSLs3TVfryi vIuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="mkGbXX4/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bo17-20020a170906d05100b00a46be5169ecsi3711831ejb.511.2024.03.26.07.57.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 07:57:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="mkGbXX4/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119240-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119240-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 77B081F632C7 for ; Tue, 26 Mar 2024 14:57:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A585913C693; Tue, 26 Mar 2024 14:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mkGbXX4/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF3FF2233A; Tue, 26 Mar 2024 14:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711465046; cv=none; b=rRR3ZRl/GnNqrM+AD47h+bvtbtnAub/EqRauLuvs4a5xc+NxRm0IXq5+qCwlc+qOwn97+c6k0cTL9zWX7sGInDV90KoDIsdKGM6EwB0IlofIlCv8jziafzBKcKl7dCDh0vReXCJlpLSh5ulSMiaYLOH3aLJ9XuPViGBTkL4WGm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711465046; c=relaxed/simple; bh=sq1B4yPNkZWKh6th8vPtdVzhFb7i5RMJZN/k6yxDj2Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=clnFYXA433xNvuE01p7342+uJhxnVVVfcdzYKxACYBexhHNocC6zI+c2J3LkJNkcDPHVURx0G6pUOs0tvW+JHpSENCG+4tekQT4Mi7pCjms4ZTKhXbRW/vfpsyL1EHJn7vv3S3de1sOTuzMRMdeHNj6PZtbgsJYBM4bUwvv8zbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mkGbXX4/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03F0CC433C7; Tue, 26 Mar 2024 14:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711465046; bh=sq1B4yPNkZWKh6th8vPtdVzhFb7i5RMJZN/k6yxDj2Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mkGbXX4/6d2pvS4gRiFkrP1zX6w2uIWEkJXcnLCgDB+QMZLLOth07HQf1k23UuxSK rKKgmefLXwFeqhX5uZVKYcTOq9908DNjPHTDDh93PD9urSfCDgf41GDQRzyA1xHBXI 6UzBC0H/zpeY0hXouZmJ63J1DkqU0eyIQB9Da2H7A8ghyBuDVUywavIK3htwwJk1ac ORIg24R2gqHTwfrzXF4Gz6p3nfgDY+Rw/bxyQ+gXPkrDVJzHjEJ+bAiG8DgMqiM9vc e6QONn1q9Vvh+L72URJnrKYQHzKnnz9gHOGO1QvF0FpCgGsQgjp/iUPaC3UePFgL+q xlh0j2gmDG9Gw== Date: Tue, 26 Mar 2024 16:56:44 +0200 From: Mike Rapoport To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Miklos Szeredi , Lorenzo Stoakes , xingwei lee , yue sun , Miklos Szeredi , stable@vger.kernel.org Subject: Re: [PATCH v2 1/3] mm/secretmem: fix GUP-fast succeeding on secretmem folios Message-ID: References: <20240326143210.291116-1-david@redhat.com> <20240326143210.291116-2-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240326143210.291116-2-david@redhat.com> On Tue, Mar 26, 2024 at 03:32:08PM +0100, David Hildenbrand wrote: > folio_is_secretmem() currently relies on secretmem folios being LRU folios, > to save some cycles. > > However, folios might reside in a folio batch without the LRU flag set, or > temporarily have their LRU flag cleared. Consequently, the LRU flag is > unreliable for this purpose. > > In particular, this is the case when secretmem_fault() allocates a > fresh page and calls filemap_add_folio()->folio_add_lru(). The folio might > be added to the per-cpu folio batch and won't get the LRU flag set until > the batch was drained using e.g., lru_add_drain(). > > Consequently, folio_is_secretmem() might not detect secretmem folios > and GUP-fast can succeed in grabbing a secretmem folio, crashing the > kernel when we would later try reading/writing to the folio, because > the folio has been unmapped from the directmap. > > Fix it by removing that unreliable check. > > Reported-by: xingwei lee > Reported-by: yue sun > Closes: https://lore.kernel.org/lkml/CABOYnLyevJeravW=QrH0JUPYEcDN160aZFb7kwndm-J2rmz0HQ@mail.gmail.com/ > Debugged-by: Miklos Szeredi > Tested-by: Miklos Szeredi > Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas") > Cc: > Signed-off-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) > --- > include/linux/secretmem.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/secretmem.h b/include/linux/secretmem.h > index 35f3a4a8ceb1..acf7e1a3f3de 100644 > --- a/include/linux/secretmem.h > +++ b/include/linux/secretmem.h > @@ -13,10 +13,10 @@ static inline bool folio_is_secretmem(struct folio *folio) > /* > * Using folio_mapping() is quite slow because of the actual call > * instruction. > - * We know that secretmem pages are not compound and LRU so we can > + * We know that secretmem pages are not compound, so we can > * save a couple of cycles here. > */ > - if (folio_test_large(folio) || !folio_test_lru(folio)) > + if (folio_test_large(folio)) > return false; > > mapping = (struct address_space *) > -- > 2.43.2 > -- Sincerely yours, Mike.