Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2784605lqp; Mon, 25 Mar 2024 09:07:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNuLE91516EBerM/yoQzwZD2H+MTdX5cVrSY2f//cJVBXTd/6Mahf9qgOU0NAkUxyERgMN1bbsrekWV74Gqq2fFovgCUC6EtGRo7Xwbw== X-Google-Smtp-Source: AGHT+IGB0zltxNmfhcZw4b9gtVfS7+6BAMr3rhQBykN53B94LsxjRd13DposhjepZDVk6acXnF0O X-Received: by 2002:ac2:510b:0:b0:515:a665:94ba with SMTP id q11-20020ac2510b000000b00515a66594bamr4328028lfb.19.1711382875340; Mon, 25 Mar 2024 09:07:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711382875; cv=pass; d=google.com; s=arc-20160816; b=gNF1zyrP04nq10Jnqrzqme9n742yCSC0K56bjhHppusTTk7+o4O1ox0CtxzTqwrxo+ vwvDuJ9B/X35F9Pp2ku1mmbFhHfF5YAa2XhVtpkf4inKC/vQgzWTXszZUZfZ7SO+gBq9 CR7iwL9x6RopvJjVMEoBtaSGisDoMN/e8BwUGaiXnQKKm4csFmrt7Ue0h9A7P9uJYvJo XcAjo02RWRZ/Wraf3+z8/veJw6ekLHi/ebwkXlvAOWKiIsuY/QxOjqkJpXZzeYOYcNr2 RH1QSABKZq1EKycwyA4b7SUnk0iPFPnxplf1Y5BKbM6vhXDkgj46DkBHL7cB4DBaKAdg nFvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jIOwlwxzzcSMslwXLrjLWmaoHhvyTmqwx/xJnqLqn6Y=; fh=qbRXjho4lPIXs5B9PfbtWxXH3ivnywFdr2Py1Rq4+Cw=; b=WKvLai5fmP39ibRvXmfIaaPkSX7lhj0wfmNiaaDP6fyyb3JrkQwhwNNS4gD+0gGDx8 issV7VVcYlkVMeE62G4DbmwzHh2/aTvFs9bm5HaVpF9J23oCSUB/fttm++yn1pSfv9Sv CDg5i3UCxQEVOUXYn9iaFha75Kqs7Pa1hQLDF3fnEC3MSSvoVjkKNFoyWICQv5/3pTsE AFh81B0oJkdgN4MWAwyTIyLdDjwTVRik+S0uO/qoS7yre55HNR0FsA8PYgGlWPtHQD1E xg1gWKp7l0PKgyRaYHM5nKbcsXWlpNz0JR9BDuoIW9SlkmS2c42bEN4yVSO5LKQuJKAj ouwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M2DBbpap; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-117161-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bg25-20020a170906a05900b00a46c1bc8e82si2698897ejb.748.2024.03.25.09.07.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:07:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117161-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=@redhat.com header.s=mimecast20190719 header.b=M2DBbpap; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-117161-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 1A8121F3A864 for ; Mon, 25 Mar 2024 16:02:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0AF112EBEE; Mon, 25 Mar 2024 13:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M2DBbpap" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 6D5DC12EBE7 for ; Mon, 25 Mar 2024 13:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711374095; cv=none; b=ZUTWvYjTnVablrg+CBv3U5iVsPsK0ojNHBU7DyDXdLbJaU3WSW89j3iPw+L/IgWOTQORI3WdLbio40fp5nOerwumlEYrqmWlQmi97Z5HLkAvz/Z1y7/6dnfLiqXjojV0GJxFmCV9Tip12oba97Wl7+4lhryZvXf8v+cqIRlXB1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711374095; c=relaxed/simple; bh=PiNEWr5x90esMmfh7ZHofO9+fLGzeXqEHD3NoBMXM3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GQjgAu7oQJa+kFIztyTzQHXm9NpwR6U0VMpcPBiJcZDFTfLkx3UaRC3z3tmuA1Q+x8pMzEQYE8llIWkyCRtJapuGiyDJ1mBrUNrQfiDgIT4F2msHmXJzEH0ZOETtlN/s/K5usgLrYw5KOCcwOB5SCTbvIWbIjCV5JmJNxUK3ZAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=M2DBbpap; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711374092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jIOwlwxzzcSMslwXLrjLWmaoHhvyTmqwx/xJnqLqn6Y=; b=M2DBbpapGnLzEPs+bXuQwUrOy3YBy/lVizcbrp4SaDqtF2Xo2u3Hv++dgg9U4/x8RV1eeu vDEIM6cyrikrsdYBsF6tsv4IerHL+JDxgHxyvU0nJxDiVchItsPFcqQUCHHK/YH11ucz4Z OJOoToS/g6QWZmHRktd8eoUrZzYD3sY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-beZWhhHSNDqBQcS9cJvtwA-1; Mon, 25 Mar 2024 09:41:29 -0400 X-MC-Unique: beZWhhHSNDqBQcS9cJvtwA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6DE438035AB; Mon, 25 Mar 2024 13:41:28 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAFEF2166B5D; Mon, 25 Mar 2024 13:41:25 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Mike Rapoport , Miklos Szeredi , Lorenzo Stoakes , xingwei lee , yue sun , Miklos Szeredi , stable@vger.kernel.org Subject: [PATCH v1 1/3] mm/secretmem: fix GUP-fast succeeding on secretmem folios Date: Mon, 25 Mar 2024 14:41:12 +0100 Message-ID: <20240325134114.257544-2-david@redhat.com> In-Reply-To: <20240325134114.257544-1-david@redhat.com> References: <20240325134114.257544-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 folio_is_secretmem() states that secretmem folios cannot be LRU folios: so we may only exit early if we find an LRU folio. Yet, we exit early if we find a folio that is not a secretmem folio. Consequently, folio_is_secretmem() fails to detect secretmem folios and, therefore, we can succeed in grabbing a secretmem folio during GUP-fast, crashing the kernel when we later try reading/writing to the folio, because the folio has been unmapped from the directmap. Reported-by: xingwei lee Reported-by: yue sun Closes: https://lore.kernel.org/lkml/CABOYnLyevJeravW=QrH0JUPYEcDN160aZFb7kwndm-J2rmz0HQ@mail.gmail.com/ Debugged-by: Miklos Szeredi Reviewed-by: Mike Rapoport (IBM) Tested-by: Miklos Szeredi Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas") Cc: Signed-off-by: David Hildenbrand --- include/linux/secretmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/secretmem.h b/include/linux/secretmem.h index 35f3a4a8ceb1..6996f1f53f14 100644 --- a/include/linux/secretmem.h +++ b/include/linux/secretmem.h @@ -16,7 +16,7 @@ static inline bool folio_is_secretmem(struct folio *folio) * We know that secretmem pages are not compound and LRU so we can * save a couple of cycles here. */ - if (folio_test_large(folio) || !folio_test_lru(folio)) + if (folio_test_large(folio) || folio_test_lru(folio)) return false; mapping = (struct address_space *) -- 2.43.2