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 69461B676; Mon, 23 Jun 2025 22:17:57 +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=1750717077; cv=none; b=qzMitNWNfXrHi1nCl5qcEwRx3EPsAA+dv7SYC7iQvrC9qLjRbhGuwPooakozVj6IgYCBa1rroA53QPouLPIfyBNJyVir96z10V2d0IdKyb8e3h/xfj+kyqi1v8yyf9Or5PAETYT0uVPOE9VKm9FZk8HUsSkt61YUp1GHFBQGHKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750717077; c=relaxed/simple; bh=zFyIqlV6xG9Fj1Y6dR4gfJMRfJ7mOLJDoG14fj8BaU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJE/8lyfIKDSTAHY4czQnxP46sLZqEa5ijKpxjNdBe1g8GIHTvuImtI4pg6rTdp4R+WblNFcZNZGzpP/SMxLFoPPeCaxpQ0LF8VFpzrGQlYentFGWrPvgAuuwsgqxIf5nzPJy/4hhXUVcGGE9w5FxpM8V7Ez5lqQOwkW2HyIp1U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X8NFq2BW; 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="X8NFq2BW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02A92C4CEEA; Mon, 23 Jun 2025 22:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750717077; bh=zFyIqlV6xG9Fj1Y6dR4gfJMRfJ7mOLJDoG14fj8BaU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X8NFq2BWnzX+c9N/gLqwPFYT6iMWRHpnzcit5xMGu/g6eUDf/RmyNt21rQe7p3KAb 70ErybBnYDeSqLwcoaFiTDlMmnwUbXNiJf/GR5JpRx6Vrbt4/2iob9cwdoE8txqwNg p4Cbq6nbZx9bc/cl4IwQ+dKapYfZmvwiV0mJehqc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jann Horn , Lorenzo Stoakes , Liam Howlett , Muchun Song , Oscar Salvador , Vlastimil Babka , Andrew Morton Subject: [PATCH 5.15 364/411] mm/hugetlb: fix huge_pmd_unshare() vs GUP-fast race Date: Mon, 23 Jun 2025 15:08:28 +0200 Message-ID: <20250623130642.803694020@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130632.993849527@linuxfoundation.org> References: <20250623130632.993849527@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org 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: Jann Horn commit 1013af4f585fccc4d3e5c5824d174de2257f7d6d upstream. huge_pmd_unshare() drops a reference on a page table that may have previously been shared across processes, potentially turning it into a normal page table used in another process in which unrelated VMAs can afterwards be installed. If this happens in the middle of a concurrent gup_fast(), gup_fast() could end up walking the page tables of another process. While I don't see any way in which that immediately leads to kernel memory corruption, it is really weird and unexpected. Fix it with an explicit broadcast IPI through tlb_remove_table_sync_one(), just like we do in khugepaged when removing page tables for a THP collapse. Link: https://lkml.kernel.org/r/20250528-hugetlb-fixes-splitrace-v2-2-1329349bad1a@google.com Link: https://lkml.kernel.org/r/20250527-hugetlb-fixes-splitrace-v1-2-f4136f5ec58a@google.com Fixes: 39dde65c9940 ("[PATCH] shared page table for hugetlb page") Signed-off-by: Jann Horn Reviewed-by: Lorenzo Stoakes Cc: Liam Howlett Cc: Muchun Song Cc: Oscar Salvador Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton Signed-off-by: Jann Horn Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6092,6 +6092,13 @@ int huge_pmd_unshare(struct mm_struct *m return 0; pud_clear(pud); + /* + * Once our caller drops the rmap lock, some other process might be + * using this page table as a normal, non-hugetlb page table. + * Wait for pending gup_fast() in other threads to finish before letting + * that happen. + */ + tlb_remove_table_sync_one(); atomic_dec(&virt_to_page(ptep)->pt_share_count); mm_dec_nr_pmds(mm); /*