Skip to content

Commit 82034c2

Browse files
labbottwildea01
authored andcommitted
arm64: Make sure permission updates happen for pmd/pud
Commit 15122ee ("arm64: Enforce BBM for huge IO/VMAP mappings") disallowed block mappings for ioremap since that code does not honor break-before-make. The same APIs are also used for permission updating though and the extra checks prevent the permission updates from happening, even though this should be permitted. This results in read-only permissions not being fully applied. Visibly, this can occasionaly be seen as a failure on the built in rodata test when the test data ends up in a section or as an odd RW gap on the page table dump. Fix this by using pgattr_change_is_safe instead of p*d_present for determining if the change is permitted. Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Peter Robinson <pbrobinson@gmail.com> Reported-by: Peter Robinson <pbrobinson@gmail.com> Fixes: 15122ee ("arm64: Enforce BBM for huge IO/VMAP mappings") Signed-off-by: Laura Abbott <labbott@redhat.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent cc19846 commit 82034c2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

arch/arm64/mm/mmu.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,27 +933,31 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
933933
{
934934
pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT |
935935
pgprot_val(mk_sect_prot(prot)));
936+
pud_t new_pud = pfn_pud(__phys_to_pfn(phys), sect_prot);
936937

937-
/* ioremap_page_range doesn't honour BBM */
938-
if (pud_present(READ_ONCE(*pudp)))
938+
/* Only allow permission changes for now */
939+
if (!pgattr_change_is_safe(READ_ONCE(pud_val(*pudp)),
940+
pud_val(new_pud)))
939941
return 0;
940942

941943
BUG_ON(phys & ~PUD_MASK);
942-
set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot));
944+
set_pud(pudp, new_pud);
943945
return 1;
944946
}
945947

946948
int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
947949
{
948950
pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT |
949951
pgprot_val(mk_sect_prot(prot)));
952+
pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), sect_prot);
950953

951-
/* ioremap_page_range doesn't honour BBM */
952-
if (pmd_present(READ_ONCE(*pmdp)))
954+
/* Only allow permission changes for now */
955+
if (!pgattr_change_is_safe(READ_ONCE(pmd_val(*pmdp)),
956+
pmd_val(new_pmd)))
953957
return 0;
954958

955959
BUG_ON(phys & ~PMD_MASK);
956-
set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot));
960+
set_pmd(pmdp, new_pmd);
957961
return 1;
958962
}
959963

0 commit comments

Comments
 (0)