Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B9BD446D0BD; Thu, 20 Aug 2026 16:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787243970; cv=none; b=TAwI4Om8b9I0iX1ZofJziE2wVDuzlsAQKTLXBjfCHPjZw+M03j9uUyZ04bcmytIwWhly1LL9hLnT6ImoKg0TUP++eutlfoir2+gxEzNQ8K3nH+MFBa3rwYn/6gMOKVM8qnoeb6YTiRsGlN8hqc3BU/cPx/utIfYZ6LkjQcXIWfE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787243970; c=relaxed/simple; bh=/77e5BAHJxvHWM8I9N1B6Pkdi8+Tkp0buDjMnwzy6uk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o78E+Sw5poZvEkdig0rEl70nJdPJCW42craAMhv/ZGbVG63eVT8lGYsoDSv7pN5qD3ojrw9guJdMxSOsYR6fpmYNQ3ioT8Ul/8w3VbBR5Cml9tWYO7MWaYQjT98pU/hSx45KHc5ZoFBSlrESlX29e5BuuX9doeifNWfhZznT9uk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=SF/9/vMP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="SF/9/vMP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00F761F000E9; Thu, 20 Aug 2026 16:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787243968; bh=pkbcihj7NiCCj06/iRacMCoPfusUTx/o2jykeYdiCWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SF/9/vMPf/1U1Db25MiV/b7VBMTYPsPuZ4emRmk6RRwUSROvix7fv3he6xXYXia2T 68l/sQlSpJX8XN5Yh9kA9NSlZWpTdUATN738JJzke3+lWd9wKUnKkKcLnyTxivXDFM pw1K9qZOYvJABdJDIYy9b2M/QqyzOh+BXqVs3xWE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Lorenzo Stoakes (ARM)" , "Mike Rapoport (Microsoft)" , "David Hildenbrand (Arm)" , Kiryl Shutsemau , Andy Lutomirski , "Borah, Chaitanya Kumar" , "Borislav Petkov (AMD)" , Catalin Marinas , Dave Hansen , David Carlier , Dev Jain , "H. Peter Anvin" , Ingo Molnar , "Liam R. Howlett" , Michal Hocko , Peter Zijlstra , Ryan Roberts , Shakeel Butt , Suren Baghdasaryan , Toshi Kani , "Uladzislau Rezki (Sony)" , Vlastimil Babka , Will Deacon , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 248/272] mm/ptdump: always stabilise against page table freeing using init_mm Date: Thu, 20 Aug 2026 16:57:12 +0200 Message-ID: <20260820145239.063312950@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145231.229664293@linuxfoundation.org> References: <20260820145231.229664293@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Lorenzo Stoakes (ARM)" [ Upstream commit 27c32e5538344b13c1505a08861e04620c125d47 ] Previous commits have established the invariant that kernel page table freeing is performed while an mmap read lock on init_mm is held, which fixes races between ptdump and kernel page table freeing over init_mm. However, x86 and arm64 can perform a ptdump over an mm other than init_mm via ptdump_walk_pgd() and since kernel memory ranges are shared across non-kernel mm's, this means that the race still exists for these cases. Fix this by acquiring a nested mmap write lock for init_mm in ptdump_walk_pgd(). This is safe as we take this after mmap write locking the mm, and nothing acquires the init_mm lock first before locking an arbitrary mm, so no deadlock is possible. Also update walk_page_range_debug() to assert that init_mm is write locked, add a comment explaining why and remove some redundant code, and eliminate the unnecessary and confusing invocation of walk_kernel_page_table_range(). We can safely remove the non-NULL check for walk.mm, as the mmap lock asserts would NULL pointer deref if it was (and of course no callers do this). The first point at which ptdump can race kernel page table freeing is commit b6bdb7517c3d ("mm/vmalloc: add interfaces to free unmapped page table"), so we target this in the Fixes tag. Link: https://lore.kernel.org/20260723-series-vmap-race-fix-v6-4-8cc77dcc0018@kernel.org Fixes: b6bdb7517c3d ("mm/vmalloc: add interfaces to free unmapped page table") Signed-off-by: Lorenzo Stoakes (ARM) Reviewed-by: Mike Rapoport (Microsoft) Acked-by: David Hildenbrand (Arm) Reviewed-by: Kiryl Shutsemau Cc: Andy Lutomirski Cc: "Borah, Chaitanya Kumar" Cc: "Borislav Petkov (AMD)" Cc: Catalin Marinas Cc: Dave Hansen Cc: David Carlier Cc: Dev Jain Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Liam R. Howlett Cc: Michal Hocko Cc: Peter Zijlstra Cc: Ryan Roberts Cc: Shakeel Butt Cc: Suren Baghdasaryan Cc: Toshi Kani Cc: "Uladzislau Rezki (Sony)" Cc: Vlastimil Babka Cc: Will Deacon Cc: Signed-off-by: Andrew Morton [ Adapted the hunk to `walk_page_range_novma()` since 5.15 lacks the `walk_page_range_debug()` rename and the `walk_kernel_page_table_range()` dispatch, keeping the existing `!walk.mm` guard. ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/pagewalk.c | 8 ++++++++ mm/ptdump.c | 7 +++++++ 2 files changed, 15 insertions(+) --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -505,6 +505,14 @@ int walk_page_range_novma(struct mm_stru return -EINVAL; mmap_assert_write_locked(walk.mm); + /* + * x86, arm64 ptdump allow walks of efi mm's and x86 ptdump allows walks + * of arbitrary mm's. + * + * However, they both must also hold the init_mm lock to account for + * concurrent kernel page table freeing. + */ + mmap_assert_write_locked(&init_mm); return walk_pgd_range(start, end, &walk); } --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -146,11 +146,18 @@ void ptdump_walk_pgd(struct ptdump_state get_online_mems(); mmap_write_lock(mm); + /* To stabilise kernel page tables we must hold the init_mm lock too. */ + if (mm != &init_mm) + mmap_write_lock_nested(&init_mm, SINGLE_DEPTH_NESTING); + while (range->start != range->end) { walk_page_range_novma(mm, range->start, range->end, &ptdump_ops, pgd, st); range++; } + + if (mm != &init_mm) + mmap_write_unlock(&init_mm); mmap_write_unlock(mm); put_online_mems();