Skip to content

Commit f27af42

Browse files
hikerockiesgregkh
authored andcommitted
sparc64: Use arch_validate_flags() to validate ADI flag
[ Upstream commit 147d862 ] When userspace calls mprotect() to enable ADI on an address range, do_mprotect_pkey() calls arch_validate_prot() to validate new protection flags. arch_validate_prot() for sparc looks at the first VMA associated with address range to verify if ADI can indeed be enabled on this address range. This has two issues - (1) Address range might cover multiple VMAs while arch_validate_prot() looks at only the first VMA, (2) arch_validate_prot() peeks at VMA without holding mmap lock which can result in race condition. arch_validate_flags() from commit c462ac2 ("mm: Introduce arch_validate_flags()") allows for VMA flags to be validated for all VMAs that cover the address range given by user while holding mmap lock. This patch updates sparc code to move the VMA check from arch_validate_prot() to arch_validate_flags() to fix above two issues. Suggested-by: Jann Horn <jannh@google.com> Suggested-by: Christoph Hellwig <hch@infradead.org> Suggested-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Khalid Aziz <khalid.aziz@oracle.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 99ed6ae commit f27af42

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

‎arch/sparc/include/asm/mman.h‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,39 @@ static inline int sparc_validate_prot(unsigned long prot, unsigned long addr)
5757
{
5858
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_ADI))
5959
return 0;
60-
if (prot & PROT_ADI) {
61-
if (!adi_capable())
62-
return 0;
60+
return 1;
61+
}
6362

64-
if (addr) {
65-
struct vm_area_struct *vma;
63+
#define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
64+
/* arch_validate_flags() - Ensure combination of flags is valid for a
65+
* VMA.
66+
*/
67+
static inline bool arch_validate_flags(unsigned long vm_flags)
68+
{
69+
/* If ADI is being enabled on this VMA, check for ADI
70+
* capability on the platform and ensure VMA is suitable
71+
* for ADI
72+
*/
73+
if (vm_flags & VM_SPARC_ADI) {
74+
if (!adi_capable())
75+
return false;
6676

67-
vma = find_vma(current->mm, addr);
68-
if (vma) {
69-
/* ADI can not be enabled on PFN
70-
* mapped pages
71-
*/
72-
if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
73-
return 0;
77+
/* ADI can not be enabled on PFN mapped pages */
78+
if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
79+
return false;
7480

75-
/* Mergeable pages can become unmergeable
76-
* if ADI is enabled on them even if they
77-
* have identical data on them. This can be
78-
* because ADI enabled pages with identical
79-
* data may still not have identical ADI
80-
* tags on them. Disallow ADI on mergeable
81-
* pages.
82-
*/
83-
if (vma->vm_flags & VM_MERGEABLE)
84-
return 0;
85-
}
86-
}
81+
/* Mergeable pages can become unmergeable
82+
* if ADI is enabled on them even if they
83+
* have identical data on them. This can be
84+
* because ADI enabled pages with identical
85+
* data may still not have identical ADI
86+
* tags on them. Disallow ADI on mergeable
87+
* pages.
88+
*/
89+
if (vm_flags & VM_MERGEABLE)
90+
return false;
8791
}
88-
return 1;
92+
return true;
8993
}
9094
#endif /* CONFIG_SPARC64 */
9195

0 commit comments

Comments
 (0)