mm: disallow raw PFN mappings of huge/shared zeropage
Subsystems (3)
Lance Yang
reviewerPATCH v2 1/1 mm: disallow raw PFN mappings of huge/shared zeropage
From: Lance Yang <[email protected]>
Handling the huge/shared zeropage correctly in vmf_insert_pfn_pmd() and vmf_insert_pfn_prot() is more involved. We would need to check whether the VMA allows it and keep the mapping read-only, similar to the checks in vm_mixed_ok().
No in-tree user needs that support, so reject these mappings with VM_FAULT_SIGBUS rather than complicate the code for now.
---
v1 -> v2:
- Reject the shared zeropage in vmf_insert_pfn_prot() (per Kiryl) - thanks!
- Explain the VMA validation and read-only requirements (per David) - thanks!
- Pick up Kiryl's Reviewed-by tag.
- https://lore.kernel.org/all/[email protected]/
mm/huge_memory.c | 3 +++ mm/memory.c | 3 +++ 2 files changed, 6 insertions(+)
mm/huge_memory.c +3 -0
@@ -1728,6 +1728,9 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn, (VM_PFNMAP|VM_MIXEDMAP));BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +if (unlikely (is_huge_zero_pfn (pfn))) +return VM_FAULT_SIGBUS ; +pfnmap_setup_cachemode_pfn (pfn, &pgprot);return insert_pmd (vma, addr, vmf->pmd, fop, pgprot, write);
mm/memory.c +3 -0
@@ -2860,6 +2860,9 @@ vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma));BUG_ON ((vma->vm_flags &VM_MIXEDMAP ) &&pfn_valid (pfn)); +if (unlikely (is_zero_pfn (pfn))) +return VM_FAULT_SIGBUS ; +if (addr < vma->vm_start || addr >= vma->vm_end)return VM_FAULT_SIGBUS ;
Signature · 1 line
2.49.0
Quoted 10 lines · Lance Yang
From: Lance Yang <[email protected]>
Handling the huge/shared zeropage correctly in
vmf_insert_pfn_pmd()andvmf_insert_pfn_prot()is more involved. We would need to check whether the VMA allows it and keep the mapping read-only, similar to the checks invm_mixed_ok().No in-tree user needs that support, so reject these mappings with
VM_FAULT_SIGBUSrather than complicate the code for now.
Quoted 6 lines
Suggested-by Kiryl Shutsemau (Meta) <[email protected]>Suggested-by David Hildenbrand (Arm) <[email protected]>Reviewed-by Kiryl Shutsemau (Meta) <[email protected]>Signed-off-by Lance Yang <[email protected]>---
Signature · 3 lines
Cheers, David
Quoted 7 lines · Lance Yang
From: Lance Yang <[email protected]>
Handling the huge/shared zeropage correctly in
vmf_insert_pfn_pmd()andvmf_insert_pfn_prot()is more involved. We would need to check whether the VMA allows it and keep the mapping read-only, similar to the checks invm_mixed_ok().
Quoted 8 lines
No in-tree user needs that support, so reject these mappings with
VM_FAULT_SIGBUSrather than complicate the code for now.Suggested-by Kiryl Shutsemau (Meta) <[email protected]>Suggested-by David Hildenbrand (Arm) <[email protected]>Reviewed-by Kiryl Shutsemau (Meta) <[email protected]>Signed-off-by Lance Yang <[email protected]>
Seems sensible to me!
Quoted 40 lines
---
v1 -> v2:
- Reject the shared zeropage invmf_insert_pfn_prot()(per Kiryl) - thanks!
- Explain the VMA validation and read-only requirements (per David) - thanks!
- Pick up Kiryl's Reviewed-by tag.
- https://lore.kernel.org/all/[email protected]/mm/huge_memory.c | 3 +++ mm/memory.c | 3 +++ 2 files changed, 6 insertions(+)mm/huge_memory.c +3
-0@@ -1728,6 +1728,9 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, unsigned long pfn, (VM_PFNMAP|VM_MIXEDMAP));BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma)); +if (unlikely (is_huge_zero_pfn (pfn))) +return VM_FAULT_SIGBUS ; +pfnmap_setup_cachemode_pfn (pfn, &pgprot);return insert_pmd (vma, addr, vmf->pmd, fop, pgprot, write);mm/memory.c +3
-1@@ -2860,6 +2860,9 @@ vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr,BUG_ON ((vma->vm_flags &VM_PFNMAP ) &&vma_is_cow_mapping (vma));BUG_ON ((vma->vm_flags &VM_MIXEDMAP ) &&pfn_valid (pfn)); +if (unlikely (is_zero_pfn (pfn))) +return VM_FAULT_SIGBUS ; +if (addr < vma->vm_start || addr >= vma->vm_end)return VM_FAULT_SIGBUS ; --
Quoted 1 line
2.49.0
--
Cheers, Lorenzo
Quoted 22 lines · Lance Yang
From: Lance Yang <[email protected]>
Handling the huge/shared zeropage correctly in
vmf_insert_pfn_pmd()andvmf_insert_pfn_prot()is more involved. We would need to check whether the VMA allows it and keep the mapping read-only, similar to the checks invm_mixed_ok().No in-tree user needs that support, so reject these mappings with
VM_FAULT_SIGBUSrather than complicate the code for now.Suggested-by Kiryl Shutsemau (Meta) <[email protected]>Suggested-by David Hildenbrand (Arm) <[email protected]>Reviewed-by Kiryl Shutsemau (Meta) <[email protected]>Signed-off-by Lance Yang <[email protected]>---
v1 -> v2:
- Reject the shared zeropage invmf_insert_pfn_prot()(per Kiryl) - thanks!
- Explain the VMA validation and read-only requirements (per David) - thanks!
- Pick up Kiryl's Reviewed-by tag.
- https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
mm/huge_memory.c | 3 +++ mm/memory.c | 3 +++ 2 files changed, 6 insertions(+)
Makes sense to me.
Best Regards,
Yan, Zi