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=1796389374; b=NgvOp8Hz6J+hHH8pyD48cf87FEMmcD6RidRCcA9HVRxhYXw2RktlzSLdGyia0MwYVJZr Q+RtNjieYTIe1OuEc+k68wdAMsWTjF0xSXx5P819tGmIKZEdvROtvkzye7M4dvpohaJdG EQzjpgTxBHqkXLhFjDABvIKixBCLizPX4bM2KQUAR8QJsIZ+++7HnTowKLS8bI/BReGap L7kA3Kpk7/rpgItZVJHGlcA0KkP/CH6zVKi5zIk6p2aZWOZpu0F3Do1VvthE674CVwLQH gWPe2JTmD7MxRp9QyJoP72GGV9bTkM1zYx1GcG762RWj9ZOxJ/C4/oqak4HQLWpM+MQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389374; 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=486mOsYyJ2YGgLYHFFJsnMlCRo55IjF1k8lSe3SgquA=; b=E4YzW2tUU9O38zF8QflkS+LdIPdZa0C0DclI0wnJxm2Q6yz4/oZB+yZZ3efmBEhVBBOo tFLb2RDapprbhBVnYqqDn4oMrBWLCsWHuUcS0kAC2yIzMZxgzSeFc4rRiuiQAkZQ9obL7 u8/rPUXcxPz3PsATwWJ6oAw7KdnFLM6PyYCGqh6jyY1x96y8BO6jPXjw+PLQ/9Cdx4tjO KHF/tKg85bb1B/FwUdxBgxzwwiko/8BumVo4W93OboE797uJe7BQFxlAjU7fJyXyUWpjK Df86bnJaeMcdfzrM4bvjJMyxxnu2K92XPM0dvrn0vVh+Oop+lZVublbgAPSEW/Ku+Cw== 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=tcMMETcL; 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 598BA606A32F; Fri, 4 Dec 2026 13:02:54 +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=tcMMETcL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C0F61F000CE; Fri, 4 Dec 2026 13:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389373; bh=486mOsYyJ2YGgLYHFFJsnMlCRo55IjF1k8lSe3SgquA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tcMMETcLJrwOcOmALzsr06bG4G+gMP8J9906nvqCVoatv9wfb6uZEZeKSUTIayQl4 ceqsLnRPffWu5jbW0jcoNWIdfFkF/0BOROgo6EkPjFAB8Vl2UzMBvMwphOOTc+jU0h IqJIWmPBhgIqmqSeXD9Oe6VIv6BRrvOtRaWMeNfc= 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 6.1 0967/1059] mm/filemap: stop fault-around when the walk steps back Date: Fri, 4 Dec 2026 19:08:18 +0900 Message-ID: <20261204100709.067028075@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 @@ -3508,6 +3508,13 @@ again: if (mmap_miss > 0) mmap_miss--; + /* 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;