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 6DFBB1A0712; Thu, 15 Aug 2024 14:20:17 +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=1723731617; cv=none; b=afZSEE83VH068zBXsXuFKpjk1yU6lHpRSutgr3tX4FbyKXjfIMl0X4cIMPW70Ma3y6vspR/N8zdnGa3uyormlbl1xMFX2cEpE8HlvX50OJKVIRfMzSxpX/4kDsFlupOG60iXFJK2YoC0dHDLV9f7iks+ICMEKFfCvq/mJ3dUBHE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723731617; c=relaxed/simple; bh=uDnKTNjnYEOABhkcfEJYUKZzPEZDn3n5XWJjk8hVEhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxcY2OYaGAcrWGDHJ3uQLXDZsxOAWu2EEECEJ5KgwpMMmmcwhVerwrI96e0cUv87Mjr213C4uhqG6odElIPeOwxCO/o1DpFyZglfgPNHMzks3n/EfY8G/0A6IBghGdWggNdcgia0Vej2D4ZKu1B3915fGCMKYpZ5H3JXJJE+CYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mCpvnRxb; 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="mCpvnRxb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E61FCC32786; Thu, 15 Aug 2024 14:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723731617; bh=uDnKTNjnYEOABhkcfEJYUKZzPEZDn3n5XWJjk8hVEhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCpvnRxbSb6XK2CRsv6hgA7Y8oR5PbwFyP3YBYjZKyJBZ0SA+2IK36n7Jh6U4d2g6 e8k2ZafO+SVU7wl7+cMNrY/HWBX6QWVbUVG5WXMGjWSG9kelkEMabCETqwynaCjRSB k0KDDi1/rBUn6wuAdmNEBfNI4MQVdqrZI9Z5vK8s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guenter Roeck , Thomas Gleixner , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 185/259] x86/mm: Fix pti_clone_pgtable() alignment assumption Date: Thu, 15 Aug 2024 15:25:18 +0200 Message-ID: <20240815131909.924567110@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131902.779125794@linuxfoundation.org> References: <20240815131902.779125794@linuxfoundation.org> User-Agent: quilt/0.67 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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra [ Upstream commit 41e71dbb0e0a0fe214545fe64af031303a08524c ] Guenter reported dodgy crashes on an i386-nosmp build using GCC-11 that had the form of endless traps until entry stack exhaust and then #DF from the stack guard. It turned out that pti_clone_pgtable() had alignment assumptions on the start address, notably it hard assumes start is PMD aligned. This is true on x86_64, but very much not true on i386. These assumptions can cause the end condition to malfunction, leading to a 'short' clone. Guess what happens when the user mapping has a short copy of the entry text? Use the correct increment form for addr to avoid alignment assumptions. Fixes: 16a3fe634f6a ("x86/mm/pti: Clone kernel-image on PTE level for 32 bit") Reported-by: Guenter Roeck Tested-by: Guenter Roeck Suggested-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20240731163105.GG33588@noisy.programming.kicks-ass.net Signed-off-by: Sasha Levin --- arch/x86/mm/pti.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 7f2140414440d..29eaf3cd9bbdb 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -375,14 +375,14 @@ pti_clone_pgtable(unsigned long start, unsigned long end, */ *target_pmd = *pmd; - addr += PMD_SIZE; + addr = round_up(addr + 1, PMD_SIZE); } else if (level == PTI_CLONE_PTE) { /* Walk the page-table down to the pte level */ pte = pte_offset_kernel(pmd, addr); if (pte_none(*pte)) { - addr += PAGE_SIZE; + addr = round_up(addr + 1, PAGE_SIZE); continue; } @@ -402,7 +402,7 @@ pti_clone_pgtable(unsigned long start, unsigned long end, /* Clone the PTE */ *target_pte = *pte; - addr += PAGE_SIZE; + addr = round_up(addr + 1, PAGE_SIZE); } else { BUG(); -- 2.43.0