Skip to content

Commit ec663d9

Browse files
ctmarinaswildea01
authored andcommitted
arm64: Improve detection of user/non-user mappings in set_pte(_at)
Commit cab15ce ("arm64: Introduce execute-only page access permissions") allowed a valid user PTE to have the PTE_USER bit clear. As a consequence, the pte_valid_not_user() macro in set_pte() was replaced with pte_valid_global() under the assumption that only user pages have the nG bit set. EFI mappings, however, also have the nG bit set and set_pte() wrongly ignores issuing the DSB+ISB. This patch reinstates the pte_valid_not_user() macro and adds the PTE_UXN bit check since all kernel mappings have this bit set. For clarity, pte_exec() is renamed to pte_user_exec() as it only checks for the absence of PTE_UXN. Consequently, the user executable check in set_pte_at() drops the pte_ng() test since pte_user_exec() is sufficient. Fixes: cab15ce ("arm64: Introduce execute-only page access permissions") Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 49f6cba commit ec663d9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
7171
#define pte_young(pte) (!!(pte_val(pte) & PTE_AF))
7272
#define pte_special(pte) (!!(pte_val(pte) & PTE_SPECIAL))
7373
#define pte_write(pte) (!!(pte_val(pte) & PTE_WRITE))
74-
#define pte_exec(pte) (!(pte_val(pte) & PTE_UXN))
74+
#define pte_user_exec(pte) (!(pte_val(pte) & PTE_UXN))
7575
#define pte_cont(pte) (!!(pte_val(pte) & PTE_CONT))
76-
#define pte_ng(pte) (!!(pte_val(pte) & PTE_NG))
7776

7877
#ifdef CONFIG_ARM64_HW_AFDBM
7978
#define pte_hw_dirty(pte) (pte_write(pte) && !(pte_val(pte) & PTE_RDONLY))
@@ -84,8 +83,12 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
8483
#define pte_dirty(pte) (pte_sw_dirty(pte) || pte_hw_dirty(pte))
8584

8685
#define pte_valid(pte) (!!(pte_val(pte) & PTE_VALID))
87-
#define pte_valid_global(pte) \
88-
((pte_val(pte) & (PTE_VALID | PTE_NG)) == PTE_VALID)
86+
/*
87+
* Execute-only user mappings do not have the PTE_USER bit set. All valid
88+
* kernel mappings have the PTE_UXN bit set.
89+
*/
90+
#define pte_valid_not_user(pte) \
91+
((pte_val(pte) & (PTE_VALID | PTE_USER | PTE_UXN)) == (PTE_VALID | PTE_UXN))
8992
#define pte_valid_young(pte) \
9093
((pte_val(pte) & (PTE_VALID | PTE_AF)) == (PTE_VALID | PTE_AF))
9194

@@ -178,7 +181,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte)
178181
* Only if the new pte is valid and kernel, otherwise TLB maintenance
179182
* or update_mmu_cache() have the necessary barriers.
180183
*/
181-
if (pte_valid_global(pte)) {
184+
if (pte_valid_not_user(pte)) {
182185
dsb(ishst);
183186
isb();
184187
}
@@ -212,7 +215,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
212215
pte_val(pte) &= ~PTE_RDONLY;
213216
else
214217
pte_val(pte) |= PTE_RDONLY;
215-
if (pte_ng(pte) && pte_exec(pte) && !pte_special(pte))
218+
if (pte_user_exec(pte) && !pte_special(pte))
216219
__sync_icache_dcache(pte, addr);
217220
}
218221

0 commit comments

Comments
 (0)