From mboxrd@z Thu Jan 1 00:00:00 1970 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 4CDA739FCAD for ; Mon, 20 Apr 2026 13:09:05 +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=1776690545; cv=none; b=o4LaVCuJL9CqCbq8m+CIKfajnnNzAJ5mTQet98o/AIBhPB71+Q4NmGHulS8bs5VJGpNj167PpvW3vwXeqvBPnWe23v8xxfT0jeF2t1Q9vJ+dwBBrINxhbwTaqCORL1+kdWRYSdDrsMQBTO7OvK+xLk6BydjTDs4aFYGxYQ6nkaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776690545; c=relaxed/simple; bh=tEg569IOX5CPlewzddj7ejmX5CKT+8zbrdIiaSe2f6w=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=lyOL7wMVCYZ9JnFrhBeImfZTO4QbW7QJSia0vxZinlbKQVsUKWCYy+3kJWnMQoIAVVS/RMjy3Z/uOq+tW76JIAglVcXQnTLW4n/kWC9mYHKrGmpEbDzOqLSz/gsb6i0UnV2LoR60WpfQrx3Yw2sob1r2CvEI+vHv9sttDHjzj9I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wiS1HjeP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wiS1HjeP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94832C2BCB4; Mon, 20 Apr 2026 13:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776690544; bh=tEg569IOX5CPlewzddj7ejmX5CKT+8zbrdIiaSe2f6w=; h=Subject:To:Cc:From:Date:From; b=wiS1HjePFRqHsh4zvOIxTQhQbgfgsrl+0ztyzuVy/I6DdXeUbPei/2IHwhsMfyHWy WV9+UoruDQe3QBIzsYTnNNsU9HiqQfkNF/mTxdfT3+a9MmXPNKNndohZIEU5R91QJ2 X2hwJgo/+NCpkFB4EyrMEv+Z97YuYUVjzEA4+Eyc= Subject: FAILED: patch "[PATCH] mm: call ->free_folio() directly in folio_unmap_invalidate()" failed to apply to 6.18-stable tree To: willy@infradead.org,akpm@linux-foundation.org,axboe@kernel.dk,big-sleep-vuln-reports+bigsleep-501448199@google.com,jack@suse.cz,stable@vger.kernel.org Cc: From: Date: Mon, 20 Apr 2026 15:09:02 +0200 Message-ID: <2026042002-idealness-evade-7213@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.18-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.18.y git checkout FETCH_HEAD git cherry-pick -x 615d9bb2ccad42f9e21d837431e401db2e471195 # git commit -s git send-email --to '' --in-reply-to '2026042002-idealness-evade-7213@gregkh' --subject-prefix 'PATCH 6.18.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 615d9bb2ccad42f9e21d837431e401db2e471195 Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Mon, 13 Apr 2026 19:43:11 +0100 Subject: [PATCH] mm: call ->free_folio() directly in folio_unmap_invalidate() We can only call filemap_free_folio() if we have a reference to (or hold a lock on) the mapping. Otherwise, we've already removed the folio from the mapping so it no longer pins the mapping and the mapping can be removed, causing a use-after-free when accessing mapping->a_ops. Follow the same pattern as __remove_mapping() and load the free_folio function pointer before dropping the lock on the mapping. That lets us make filemap_free_folio() static as this was the only caller outside filemap.c. Link: https://lore.kernel.org/20260413184314.3419945-1-willy@infradead.org Fixes: fb7d3bc41493 ("mm/filemap: drop streaming/uncached pages when writeback completes") Signed-off-by: Matthew Wilcox (Oracle) Reported-by: Google Big Sleep Cc: Jens Axboe Cc: Jan Kara Cc: Signed-off-by: Andrew Morton diff --git a/mm/filemap.c b/mm/filemap.c index 3c1e785542dd..793bf4816ea3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -228,7 +228,8 @@ void __filemap_remove_folio(struct folio *folio, void *shadow) page_cache_delete(mapping, folio, shadow); } -void filemap_free_folio(struct address_space *mapping, struct folio *folio) +static void filemap_free_folio(const struct address_space *mapping, + struct folio *folio) { void (*free_folio)(struct folio *); diff --git a/mm/internal.h b/mm/internal.h index cb0af847d7d9..546114d3ee44 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -540,7 +540,6 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); unsigned find_get_entries(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices); -void filemap_free_folio(struct address_space *mapping, struct folio *folio); int truncate_inode_folio(struct address_space *mapping, struct folio *folio); bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end); diff --git a/mm/truncate.c b/mm/truncate.c index 12467c1bd711..8617a12cb169 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -622,6 +622,7 @@ static int folio_launder(struct address_space *mapping, struct folio *folio) int folio_unmap_invalidate(struct address_space *mapping, struct folio *folio, gfp_t gfp) { + void (*free_folio)(struct folio *); int ret; VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); @@ -648,9 +649,12 @@ int folio_unmap_invalidate(struct address_space *mapping, struct folio *folio, xa_unlock_irq(&mapping->i_pages); if (mapping_shrinkable(mapping)) inode_lru_list_add(mapping->host); + free_folio = mapping->a_ops->free_folio; spin_unlock(&mapping->host->i_lock); - filemap_free_folio(mapping, folio); + if (free_folio) + free_folio(folio); + folio_put_refs(folio, folio_nr_pages(folio)); return 1; failed: xa_unlock_irq(&mapping->i_pages);