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 8D015186295; Mon, 12 Aug 2024 16:05:42 +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=1723478742; cv=none; b=kPfJ22xGkgNeAdjXpC2mpjHvT3IdDJB56c+EFbFo1Pr4XJX6m8fY3cJggQhaxw5nNaSEnyrGv1KF/vE9W3inNn5WeEQq5ejychWg/hqeHCPVJPJU/obRMqusud8Cziujy+Y0XiEC/zaS2wPmqSZvaM7pjRkLupXB3X8N58dvpoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723478742; c=relaxed/simple; bh=bsi49ZM1BSif4gY68WpDBXwGyYtolcnbwRpu0eGiaAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kNLQlnE/dGlTSI6+4aIB4tCSGo4R9B/JIT5xyOY0OSZYAOdwvh5BwXEULe2SqGO7if8JPciW2T/lSG3yG+rCDiIFfJ/Oca8gyFDeqaskkSXH0OlLNGT1DZvDeInVEc9Jc+UUPHbC8SdD2gZgqMSYi1OWNjyiE1IJtV6w+klZxU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CNwpSfon; 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="CNwpSfon" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB233C32782; Mon, 12 Aug 2024 16:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723478742; bh=bsi49ZM1BSif4gY68WpDBXwGyYtolcnbwRpu0eGiaAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CNwpSfongqq714G7JyFkyGRRcqMG47+U4kSVlL3WEJz7sDwvsg3AZkZSSls2cJTVO IDlT1Smm/VkD0J5mhE0q2HfQOGSuWK7LoqyF/IVW3UtUwCLaSWn9k5GCKptJK4pQby /InNXjKkowAsbFG+mx+Zn0tN+xuLTfs2Io2fsWBE= 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 6.1 005/150] x86/mm: Fix pti_clone_pgtable() alignment assumption Date: Mon, 12 Aug 2024 18:01:26 +0200 Message-ID: <20240812160125.357607135@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812160125.139701076@linuxfoundation.org> References: <20240812160125.139701076@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 6.1-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 78414c6d1b5ed..2c4037174ed22 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -374,14 +374,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; } @@ -401,7 +401,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