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=1796381049; b=kk1P8TH22MzHBLUAsd0BlzPG1QqN/H9gUwQyQBJbD7Q7kQxLT2RT6ODW7Ln0twOroofy EpjIGQA3LziYnsaz2nS20c7D6M79cD4yZ3swaRjAVnuzNZIqOEg/p2yMtb1osLZLBxA/t PM28IJ9g5cT2thZlaxaiUe43kghGhLJQMmZUr9+cqjRrBfAANSrMw3TSXTJPWzLq2qnIb mNWVbC6r7M3sEN1M8JNl8G0lB9XUnjQFV1CxWfQ+shtr5RTiuSmfbOoO6OJVLvL30E3ZU h/pU95QDKZRDFnVkEIHt3a0TGmBT6YdDYAmjRMiB9KA7SnHeshfkDRdhpZ9c/nl6BSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381049; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=j5NXzAnxes40S6TVV6H2H+XzrYXNtX4wpELrjO/i3dM=; b=2gj4Gppq6RnxrrWrMoq68/N6UKwt8lEB2iMZ4Kr30HC7KlNEr+AYGlcDojpzGgTv0YlW K0CZk9Rv3wiCO3vglJKImtQtIorF+V3vg7wFsTgSLwgQlMGTdW2uBDDUNaKLTaEoCbWAx E+Jf/FU+5EsqlIqSy6NWdlMn3amq2bOZom9kLN7mNVuiykhRC47iYc8WhA71J4B+kOt2v dMlX2VTfDudIH7WCRTxIpRbM7Ei9eTETNUEHq2PmdNkkbl7nU83y3eEJPnArIMVr0nldg rcllS3z+12a+d2bUML2qiWUbwB9Wtjl0Aw3FVp1QRV+0lTdUwMDK1Ooqk5fD70EsxpQ== 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=TCYbQTOk; 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 9C632606A322; Fri, 4 Dec 2026 10:44:09 +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=TCYbQTOk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CF351F00897; Fri, 4 Dec 2026 10:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381049; bh=j5NXzAnxes40S6TVV6H2H+XzrYXNtX4wpELrjO/i3dM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TCYbQTOkLkfcYoIXr+P0IImtlHVuY7BQy7qib6FvEyYpCs3fYMrPONMd4+q4LyVD/ hH/zZcq6y3Sj/g5aSaIhgiqAGPD3slsleUG5iyayXBZoCM2aV+O01rCVEQpKVWaqsd evygep1pHKFLbuZnISgcffqWn7Ca29ApFv52izqY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Jose Fernandez (Anthropic)" , Andrew Morton , Jan Kara , "Matthew Wilcox (Oracle)" , David Hildenbrand , Krystian Kaniewski , Pedro Falcato Subject: [PATCH 7.3 537/742] mm/filemap: stop fault-around when the walk steps back Date: Fri, 4 Dec 2026 19:06:41 +0900 Message-ID: <20261204100649.441640362@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jose Fernandez (Anthropic) commit cf5518aa1832d82b391ac2492863ae6a7315827c upstream. filemap_map_pages() can dereference a PTE pointer outside the page table it locked. KASAN has reported this as a use-after-free read [1]. The same path can also write out of bounds. When the stray entry reads as none, the fault-around loop maps a page there with set_pte_range(). Its fault-around loop walks the page cache and moves vmf->pte by the change in index. A lower index moves it back. xas_find() can step back to a lower index when a multi-index entry is split during the walk. [1] fixes xas_find(), but the loop still relies on the walk never stepping back. Stop the fault-around when the walk steps back. ->fault() maps the faulting page if the loop did not. Link: https://lore.kernel.org/20261031-jf-mm-filemap-map-pages-lower-bound-v2-1-21029744e589@linux.dev Link: https://lore.kernel.org/20260904121301.200049-1-krystianmkaniewski@gmail.com [1] Fixes: 6b24ca4a1a8d ("mm: Use multi-index entries in the page cache") Signed-off-by: Jose Fernandez (Anthropic) Signed-off-by: Andrew Morton Reviewed-by: Jan Kara Cc: Matthew Wilcox (Oracle) Cc: David Hildenbrand Cc: Krystian Kaniewski Cc: Pedro Falcato Cc: Signed-off-by: Greg Kroah-Hartman --- mm/filemap.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3950,6 +3950,13 @@ vm_fault_t filemap_map_pages(struct vm_f unsigned long end; vm_fault_t map_ret; + /* A lower index could move vmf->pte out of its page table. */ + if (unlikely(xas.xa_index < last_pgoff)) { + folio_unlock(folio); + folio_put(folio); + break; + } + addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT; vmf->pte += xas.xa_index - last_pgoff; last_pgoff = xas.xa_index;