From patchwork Mon Mar 25 13:41:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13602229 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 2B914C54E64 for ; Mon, 25 Mar 2024 13:41:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7033A6B008A; Mon, 25 Mar 2024 09:41:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B08B6B008C; Mon, 25 Mar 2024 09:41:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 578B06B0092; Mon, 25 Mar 2024 09:41:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 49C106B008A for ; Mon, 25 Mar 2024 09:41:33 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 102A8A0853 for ; Mon, 25 Mar 2024 13:41:33 +0000 (UTC) X-FDA: 81935673666.28.95D085D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 77684C0006 for ; Mon, 25 Mar 2024 13:41:31 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nb2fZU2t; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711374091; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jIOwlwxzzcSMslwXLrjLWmaoHhvyTmqwx/xJnqLqn6Y=; b=sSBr52/2dHplQ441wMbgH0wWtDCE7htR9FHxk7c0mQ3v0BeaZtr/S5/vIrGVq4IrPGCQ6L FH3oSbQ+RtBGHZKcMrHRWALWfnkiGZKHy0Wuwkh8lBQMIIniaSmwpPZFDDPH927A7YI10w tEUPmA6sh/j9bAZT1bQ0mSqRioG2EaE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nb2fZU2t; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711374091; a=rsa-sha256; cv=none; b=kclgqv60fUcyioKUI2UCnWfrx90HDNXbKL9rf04othvztSv+V4JqUyYQsvUj46eV+/48Dz flWJb2dp0lQRdyBnIrK4I6cbQN/dAjoS3h/F/FHkF7IFUx+LK/17/0lc9pB1T58+aS97sp guKCPjrQ9Ckw0M9fvpOrsug70ouvWVw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711374090; 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=Nb2fZU2tQzcANAQcnmghC/hRb0ysMLkOqbyxtfNFYB7zPInme/2g8M9SNKAHBxxg7AdzTu vWgd3Xw4zupMLPyY++yiR/QPnV4znrjQ39VF5NxIUAiM2T+vVX/DEtWAz/uhlYxJXluzJ+ 2F2F/01MAK6FZIrZ0Bs3wbfs0aMflEg= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Rspamd-Queue-Id: 77684C0006 X-Rspam-User: X-Stat-Signature: s484wt1t34y1spa1nypgi6ohb7sbw7gw X-Rspamd-Server: rspam01 X-HE-Tag: 1711374091-494104 X-HE-Meta: U2FsdGVkX1+gfDOhBwcPxR0qmlQMUn4OrCVRwoVqKAazU5ma//HdJ2V37HwChtzK/yQY1GAU1QAmngsp2jqGGYCE39mY8ilh/gUwKwsqcNjqRCcyZtk57p6+e2cK3gqUE8BxfXOKmud62eCsN/7eqFwV0umPLL04NLGm7CHntlyxrxEsqYhnPvSAPtx3jsN07kCCUbEz50m5JFK7BJg+9y2991yvsLJWigTVszJh0qdQblGVHNiSJfB5cRAEsaxtF0c0Bf67VGuNKQrpDXsm+VJhMeu26IKRbJjmGU6BI1hjqgm2XTNxUEUVj42KIrE0pWtqsW1Nyc4uJNJ5W7q6IGJ52jFyjUts7ayBftu8qWlaBQ5+IcsOp6kmTLf5Fi3q/Etu1XvgkeAF5SzlRxDZzA9eAztzQIQvXYN1uyT90Vl0SHxo8QtTkM0J8raZ1eBt12lPOrIjjPjihntg4Xp+Oh831AhRtnYlhYpBNsq1FWkwn0RcHy896UviwQhuPC9ETlcBJhtYwTTdkeTsYFX5gdxq92rmgDYGzEJAdVgf1DZfgPdRyhl2dYVby1vf6JMjMZgmU0+bev6xvCLLdPMORDA07LZsLM5bQ7+XYdu8ftd+3O2yI2Noe+4g+bTkYkbzd1wNtWriZOBntkABtGtyxnzz0OmFfN/FgjVZi6EfHsh1Mu3sV/6BZrARpH6vFn4ThRKC5kOW1E0Dp/jqOi0c2syfbby8D3KPOeGpKXaa8YFwCVmy/NUHZYWwtKyvFUxn+dex/DcCmdkKXXn1BF3kC7AaoKRbixgIuCjYSO5yICyxijcOFZOnPfaLfY/nOjhQCaK7S4TqEYY3ZUlhxdR881EJSid2wqcnQYy0Wi9hiBkl7ja1OL+i5L33v/giV/urbZayog9Pib02BFBnEihULg== 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: List-Subscribe: List-Unsubscribe: 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 *)