Sync unmappings in vmalloc/ioremap areas
Subsystems (4)
cover Sync unmappings in vmalloc/ioremap areas
Hi,
here is a small patch-set to sync unmappings in the vmalloc/ioremap areas between page-tables in the system.
This is only needed x86-32 with !SHARED_KERNEL_PMD, which is the case on a PAE kernel with PTI enabled.
On affected systems the missing sync causes old mappings to persist in some page-tables, causing data corruption and other undefined behavior.
Please review.
Thanks,
Joerg
Joerg Roedel (3):
x86/mm: Check for pfn instead of page in vmalloc_sync_one() x86/mm: Sync also unmappings in vmalloc_sync_one() mm/vmalloc: Sync unmappings in vunmap_page_range()
arch/x86/mm/fault.c | 9 +++++---- mm/vmalloc.c | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 x86/mm: Check for pfn instead of page in vmalloc_sync_one()
From: Joerg Roedel <[email protected]>
Do not require a struct page for the mapped memory location because it might not exist. This can happen when an ioremapped region is mapped with 2MB pages.
--- arch/x86/mm/fault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/fault.c +1 -1
@@ -200,7 +200,7 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)if (!pmd_present (*pmd))set_pmd (pmd, *pmd_k);else -BUG_ON (pmd_page (*pmd) !=pmd_page (*pmd_k)); +BUG_ON (pmd_pfn (*pmd) !=pmd_pfn (*pmd_k));return pmd_k; }
Signature · 1 line
2.17.1
Re: [PATCH 1/3] x86/mm: Check for pfn instead of page in vmalloc_sync_one()
Quoted 7 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
Do not require a struct page for the mapped memory location because it might not exist. This can happen when an ioremapped region is mapped with 2MB pages.
Signed-off-by Joerg Roedel <[email protected]>
Lacks a Fixes tag, hmm?
Re: [PATCH 1/3] x86/mm: Check for pfn instead of page in vmalloc_sync_one()
Quoted 11 lines · Thomas Gleixner
Quoted 7 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
Do not require a struct page for the mapped memory location because it might not exist. This can happen when an ioremapped region is mapped with 2MB pages.
Signed-off-by Joerg Roedel <[email protected]>Lacks a Fixes tag, hmm?
Yeah, right, the question is, which commit to put in there. The problem results from two changes:
1) Introduction of !SHARED_KERNEL_PMD path in x86-32. In itself this is not a problem, and the path was only enabled for Xen-PV.
2) Huge IORemapings which use the PMD level. Also not a problem by itself, but together with !SHARED_KERNEL_PMD problematic because it requires to sync the PMD entries between all page-tables, and that was not implemented.
Before PTI-x32 was merged this problem did not show up, maybe because the 32-bit Xen-PV users did not trigger it. But with PTI-x32 all PAE users run with !SHARED_KERNEL_PMD and the problem popped up.
For the last patch I put the PTI-x32 enablement commit in the fixes tag, because that was the one that showed up during bisection. But more correct would probably be
5d72b4fba40e ('x86, mm: support huge I/O mapping capability I/F')
Or do I miss something?
Regards,
Joerg
Re: [PATCH 1/3] x86/mm: Check for pfn instead of page in vmalloc_sync_one()
Quoted 29 lines · Joerg Roedel
Quoted 11 lines · Thomas Gleixner
Quoted 7 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
Do not require a struct page for the mapped memory location because it might not exist. This can happen when an ioremapped region is mapped with 2MB pages.
Signed-off-by Joerg Roedel <[email protected]>Lacks a Fixes tag, hmm?
Yeah, right, the question is, which commit to put in there. The problem results from two changes:
1) Introduction of !SHARED_KERNEL_PMD path in x86-32. In itself this is not a problem, and the path was only enabled for Xen-PV.
2) Huge IORemapings which use the PMD level. Also not a problem by itself, but together with !SHARED_KERNEL_PMD problematic because it requires to sync the PMD entries between all page-tables, and that was not implemented.
Before PTI-x32 was merged this problem did not show up, maybe because the 32-bit Xen-PV users did not trigger it. But with PTI-x32 all PAE users run with !SHARED_KERNEL_PMD and the problem popped up.
Quoted 5 lines
For the last patch I put the PTI-x32 enablement commit in the fixes tag, because that was the one that showed up during bisection. But more correct would probably be
5d72b4fba40e('x86, mm: support huge I/O mapping capability I/F')
Looks about right.
Thanks,
tglx
PATCH 2/3 x86/mm: Sync also unmappings in vmalloc_sync_one()
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
With huge-page ioremap areas the unmappings also need to be synced between all page-tables. Otherwise it can cause data corruption when a region is unmapped and later re-used.
Make the vmalloc_sync_one() function ready to sync unmappings.
--- arch/x86/mm/fault.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/mm/fault.c +4 -3
@@ -194,11 +194,12 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) pmd =pmd_offset (pud, address); pmd_k =pmd_offset (pud_k, address); -if (!pmd_present (*pmd_k)) -return NULL ; -if (!pmd_present (*pmd)) +if (pmd_present (*pmd) ^pmd_present (*pmd_k))set_pmd (pmd, *pmd_k); + +if (!pmd_present (*pmd_k)) +return NULL ;else BUG_ON (pmd_pfn (*pmd) !=pmd_pfn (*pmd_k));
Signature · 1 line
2.17.1
Re: [PATCH 2/3] x86/mm: Sync also unmappings in vmalloc_sync_one()
Quoted 10 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
With huge-page ioremap areas the unmappings also need to be synced between all page-tables. Otherwise it can cause data corruption when a region is unmapped and later re-used.
Make the
vmalloc_sync_one()function ready to sync unmappings.Signed-off-by Joerg Roedel <[email protected]>
Lacks a Fixes tag methinks.
Quoted 9 lines
--- arch/x86/mm/fault.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)arch/x86/mm/fault.c +0
-0
arch/x86/mm/fault.c static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) · line 199
Quoted 9 lines
arch/x86/mm/fault.c +1
-3@@ -194,11 +194,12 @@ static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) pmd =pmd_offset (pud, address); pmd_k =pmd_offset (pud_k, address); -if (!pmd_present (*pmd_k)) -return NULL ; -if (!pmd_present (*pmd)) +if (pmd_present (*pmd) ^pmd_present (*pmd_k))set_pmd (pmd, *pmd_k);
It took me a while to understand what this is doing. Can we please have a comment here?
arch/x86/mm/fault.c static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address) · line 202
Quoted 3 lines
arch/x86/mm/fault.c +3
-0+ +if (!pmd_present (*pmd_k)) +return NULL ;
Thanks,
tglx
PATCH 3/3 mm/vmalloc: Sync unmappings in vunmap_page_range()
In reply to Joerg RoedelFrom: Joerg Roedel <[email protected]>
On x86-32 with PTI enabled, parts of the kernel page-tables are not shared between processes. This can cause mappings in the vmalloc/ioremap area to persist in some page-tables after the regions is unmapped and released.
When the region is re-used the processes with the old mappings do not fault in the new mappings but still access the old ones.
This causes undefined behavior, in reality often data corruption, kernel oopses and panics and even spontaneous reboots.
Fix this problem by activly syncing unmaps in the vmalloc/ioremap area to all page-tables in the system.
References: https://bugzilla.suse.com/show_bug.cgi?id=1118689
--- mm/vmalloc.c | 2 ++ 1 file changed, 2 insertions(+)
mm/vmalloc.c +2 -0
@@ -132,6 +132,8 @@ static void vunmap_page_range(unsigned long addr, unsigned long end)continue ;vunmap_p4d_range (pgd, addr, next); }while (pgd++, addr = next, addr != end); + +vmalloc_sync_all (); } static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
Signature · 1 line
2.17.1