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=1796382508; b=1OnvQNFGYv654fgLuvz0nH8095p+V7Zm4TthvwnfpT9eGmOZCqqXprqOc7ttqGl4v+9S mn2tX957Xmn2hCY2FHud1REJtHq5gE6LMYRf4FFKxerxaatck5VzLWhy64rMBVzobH7fp XsXafrRkSAm5imz9ZTcWViGhAhAUZmgL12gjqPVhHjZufJ/dP4Iqd1O6NBj1MKhTuohG6 c/UpFsKScdMjiX/LOAxjo+L9auoeNut+Tmd+EykX8xM84z7S3GPoXTQ1MkSE6fKTi9ANI hrmWzllt9dKQEziMFqiC25LE2O5gZA9v4ArFilpuRs/IxOtqpdQyMxnU6ceXiOY226w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382508; 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=Q51Jl45x+45KJcu42mVSnq1yb7CwseUP9CVlAd7WGgM=; b=pcJEKiLnGfaLAdgH51qnDluJWsexKfwqVV3M4CZjSRMR3fY0C9th74KN6qMXd0viOncu rfuNO4Lc5oLJ2ql5ELVzTqPi2GFVKv9LoBfsxq0ogRVOjEfO9e7ZVoH4Rc+C/g6Y0nLBZ a69i9gyMBq9nyez5MuWDJZvEg3C+W63HBLk3+KBptkwA0dx0ITVFmBa2BwLd2iYcJWnnm BpC6SOb8eV1e+CrUCvhO7HCPBF1/aOdjtGJBGSFzJg9kaAPq7Nmpv0Bht8ZBEE0dUiG1Z vRQw1wbFCXHhY3IS7hdbbI5DBbrM+t5/mDu8rDaSya4ehwRawPs4TyEPcsq8zLILQyw== 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=u3S9ZsiH; 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 C0865606A338; Fri, 4 Dec 2026 11:08:28 +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=u3S9ZsiH Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBCCB1F0092C; Fri, 4 Dec 2026 11:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382508; bh=Q51Jl45x+45KJcu42mVSnq1yb7CwseUP9CVlAd7WGgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u3S9ZsiHXAfojVaXSw+gYF1sCRm+awUjk2KS8agP1D4fFNYSnbFpbHol0xbI/96Ji vS2LwQVBlUnPn77Jr90/nypyLwdF2Qp8FoKrUR97AG2RszH9iiVxSvU63lbFUmPG5+ m5QEyZ38f9ltklh1eb1Uk4x5yaniwxuHbk/NtQvI= 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.18 484/703] mm/filemap: stop fault-around when the walk steps back Date: Fri, 4 Dec 2026 19:06:23 +0900 Message-ID: <20261204100640.677161555@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 @@ -3868,6 +3868,13 @@ vm_fault_t filemap_map_pages(struct vm_f do { unsigned long end; + /* 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;