linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/mm/pti: Check unaligned address for pmd clone in pti_clone_pagetable()
@ 2020-11-30 15:25 Lai Jiangshan
  2020-11-30 15:25 ` [PATCH 2/2] x86/mm/pti: warn and stop when pti_clone_pagetable() is on 1G page Lai Jiangshan
  2020-12-01 17:43 ` [PATCH 1/2] x86/mm/pti: Check unaligned address for pmd clone in pti_clone_pagetable() Dave Hansen
  0 siblings, 2 replies; 9+ messages in thread
From: Lai Jiangshan @ 2020-11-30 15:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Lai Jiangshan, Dave Hansen, Andy Lutomirski, Peter Zijlstra,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin

From: Lai Jiangshan <laijs@linux.alibaba.com>

The commit 825d0b73cd752("x86/mm/pti: Handle unaligned address gracefully
in pti_clone_pagetable()") handles unaligned address well for unmapped
PUD/PMD etc. But unaligned address for pmd_large() or PTI_CLONE_PMD is also
needed to be aware.

For example, when pti_clone_pagetable(start, end, PTI_CLONE_PTE) is
called with @start=@pmd_aligned_addr+100*PAGE_SIZE,
@bug_addr=@pmd_aligned_addr+x*PMD_SIZE and  @end is larger than
@bug_addr+PMD_SIZE+PAGE_SIZE.

So @bug_addr is pmd aligned. If @bug_addr is mapped as large page
and @bug_addr+PMD_SIZE is not large page. It is easy to see that
[@bug_addr+PMD_SIZE, @bug_addr+PMD_SIZE+PAGE_SIZE) is not cloned.
(In the code, @addr=@bug_addr+100*PAGE_SIZE is handled as large page,
and is advanced to @bug_addr+100*PAGE_SIZE+PMD_SIZE which is not
large page mapped and 100 pages is skipped without cloned)

Similar for PTI_CLONE_PMD when @bug_addr+100*PAGE_SIZE+PMD_SIZE
is larger than @end even @bug_addr is not large page.
In the case several pages after @bug_addr+PMD_SIZE is not cloned.

We also use addr = round_up(addr+1, PAGE_SIZE) in another branch for
consistent coding without fixing anything since the addresses are
at least PAGE_ALIGNED.

No real bug is found, this patch is just for the sake of robustness.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
---
 arch/x86/mm/pti.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 1aab92930569..a229320515da 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -374,7 +374,7 @@ 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) {
 
@@ -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.19.1.6.gb485710b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-18 13:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 15:25 [PATCH 1/2] x86/mm/pti: Check unaligned address for pmd clone in pti_clone_pagetable() Lai Jiangshan
2020-11-30 15:25 ` [PATCH 2/2] x86/mm/pti: warn and stop when pti_clone_pagetable() is on 1G page Lai Jiangshan
2020-11-30 16:37   ` Dave Hansen
2020-12-01 17:43 ` [PATCH 1/2] x86/mm/pti: Check unaligned address for pmd clone in pti_clone_pagetable() Dave Hansen
2020-12-02  8:55   ` Lai Jiangshan
2020-12-10 14:35   ` [PATCH V2 1/3] x86/mm/pti: handle " Lai Jiangshan
2020-12-10 14:35     ` [PATCH V2 2/3] x86/mm/pti: issue warning when mapping large pmd beyond specifid range Lai Jiangshan
2020-12-10 14:35     ` [PATCH V2 3/3] x86/mm/pti: warn and stop when pti_clone_pagetable() is on 1G page Lai Jiangshan
2020-12-18 13:00     ` [PATCH V2 1/3] x86/mm/pti: handle unaligned address for pmd clone in pti_clone_pagetable() Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).