From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221244; b=DE9IzI55+V6+ppuI7g5tZ0pqSuAXG5trajZzUSSOkVuRnnwi73TMXTG17ytfmaeIDkGf Gxo81A0gxlt8tmprxO9q7VKBImLpwFPv6ybn04bDNU5k4t+hqF5GonwyZvaWeM2gMXYbz 5WD5jTXMy9AX019mAJy5U7UzNOW2RMAMPEj7u/hlMKzGWLezaVOTB1DHtH0jIysRaLeJW D7cmnqeefgxZkeMY4ZI6aHuk50KJQDqlRxysASFpBRWiJJMJB31YVAPOxmPfMpiGxpe/W BoxVwmqAY+m6Q4wyemp2N1ZmiNSHW1Tcsg0AlONbDYK+4IyLMXoZ58md48nh1WA0L1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221244; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=OPTqNGTwIfnGJC9JECCLXAYKPAP9D860NpOknDlp/fE=; b=h5WbpEZFSLG7fpPlh1nta1ViX7kseDTZeUy2qa7KaP1PN2cIdUaIu65vGFedBrT7Qb5Q 1AxNsBSpF0BlutD8CqYfDxVRQRJJXRjIvT5OWqMvL4AFBGsBcqOnaP3NVt698mLE/S1Ly NqEQ8HnjHagn7Xc4w//Ds6fEyFokMfPGFX4ZP2LrdFDgJvxsf1UYMPAOfdfW6502I5b5O Z5ay0UChyMDAR3usBaTg1bsU1rIkciBc7Py/WsPTks1DTVi2GN8TpJRCZQrnqaRSUiCgc LIfybRaHX+JMZFtDDCf7pPICRUnlaXtBuGe0tG31ZAuDfCGTl4/cKp0U1OhsD72teNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=00u3ld1l; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8D89606A686 for ; Wed, 2 Dec 2026 14:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=00u3ld1l Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18E3E1F00935; Wed, 2 Dec 2026 14:20:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221244; bh=OPTqNGTwIfnGJC9JECCLXAYKPAP9D860NpOknDlp/fE=; h=Subject:To:Cc:From:Date; b=00u3ld1lSyWw5VvFJ6akfhc0bd68T+SHR1+3ncdE06bcpwtlWi4fHVMM/sCjf4iOs tbTAInC/V/xtWS5Cfjy6pqewX8toOIjXoFRl2i6sSyLHU+XxFNqtgDfYOtwyMphfkV Japa46UKZAhwT89ia1h2YFEv6eefQtKDqpAvpEuE= Subject: FAILED: patch "[PATCH] mm/memfd: handle GUP pins more reliably when write-sealing" failed to apply to 6.12-stable tree To: david@kernel.org,lance.yang@linux.dev,ljs@kernel.org,mason@kernel.org Cc: From: Date: Wed, 02 Dec 2026 14:35:39 +0100 Message-ID: <2026120239-shank-trekker-0b72@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y git checkout FETCH_HEAD git cherry-pick -x d369ba5a46c65c54b94c94713ca1fb4ad6a87ebf # git commit -s git send-email --to '' --in-reply-to '2026120239-shank-trekker-0b72@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From d369ba5a46c65c54b94c94713ca1fb4ad6a87ebf Mon Sep 17 00:00:00 2001 From: "David Hildenbrand (Arm)" Date: Tue, 3 Nov 2026 19:31:44 +0100 Subject: [PATCH] mm/memfd: handle GUP pins more reliably when write-sealing memfd_wait_for_pins() detects GUP references by comparing a folio's actual refcount with its expected refcount. As spelled out by folio_expected_ref_count(), obtaining the expected refcount when there can be concurrent folio (un)mapping is racy. So it is possible that a changing folio mapcount can race with our check for GUP references, and F_SEAL_WRITE might succeed even if there are some, allowing file contents to be modified after sealing. For folios with a reliable pincount, detect FOLL_PIN references using folio_maybe_dma_pinned() before falling back to the refcount comparison. For small folios without that, the 1024 pinning BIAS makes it very hard (although not impossible) to misguide the refcount comparison. This improves FOLL_PIN detection for folios with a pincount. Handling FOLL_GET and small folios requires a more fundamental change. Fortunately, most interfaces that allow for GUP'ing such pages use FOLL_PIN, in particular interfaces using FOLL_LONGTERM. However, we still have some FOLL_GET leftovers ... Fixes: 05f65b5c7090 ("shm: wait for pins to be released when sealing") Cc: stable@vger.kernel.org Cc: Chris Mason Reviewed-by: Lorenzo Stoakes (ARM) Link: https://patch.msgid.link/20261103-fixes_core_2-v1-1-f332954f1df4@kernel.org Reviewed-by: Lance Yang Signed-off-by: David Hildenbrand (Arm) diff --git a/mm/memfd.c b/mm/memfd.c index 0e3ff3eebfa8..05088ab210ba 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -32,6 +32,13 @@ static bool memfd_folio_has_extra_refs(struct folio *folio) { + /* + * Use the precise pincount where available to avoid racy refcount + * comparisons. + */ + if (folio_has_pincount(folio) && folio_maybe_dma_pinned(folio)) + return true; + return folio_ref_count(folio) != folio_expected_ref_count(folio); }