Skip to content

Commit 8dd640d

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: mm: Check for pud_/pmd_set_huge() failures on kernel mappings
Sashiko reports: | If pmd_set_huge() rejects an unsafe page table transition (such as | mapping a different physical address over an existing block mapping), | it returns 0 and leaves the page table entry unmodified. | | Because *pmdp remains unmodified, READ_ONCE(pmd_val(*pmdp)) will equal | pmd_val(old_pmd). The transition from old_pmd to old_pmd is evaluated | as safe by pgattr_change_is_safe(), so the BUG_ON never triggers. | | This allows invalid and unsafe mapping updates to be silently dropped | instead of panicking, leaving stale memory mappings active while the | caller assumes the update was successful. The same applies to pud_set_huge() in alloc_init_pud(). Given how it is generally preferred to limp on rather than blow up the system if an unexpected condition such as this one occurs, and the fact that there are no known cases where this disparity results in real problems, let's WARN on these failures rather than BUG, allowing the system to survive to the point where it can actually report them. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 2e52766 commit 8dd640d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/arm64/mm/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static int init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end,
257257
/* try section mapping first */
258258
if (((addr | next | phys) & ~PMD_MASK) == 0 &&
259259
(flags & NO_BLOCK_MAPPINGS) == 0) {
260-
pmd_set_huge(pmdp, phys, prot);
260+
WARN_ON(!pmd_set_huge(pmdp, phys, prot));
261261

262262
/*
263263
* After the PMD entry has been populated once, we
@@ -380,7 +380,7 @@ static int alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long end,
380380
if (pud_sect_supported() &&
381381
((addr | next | phys) & ~PUD_MASK) == 0 &&
382382
(flags & NO_BLOCK_MAPPINGS) == 0) {
383-
pud_set_huge(pudp, phys, prot);
383+
WARN_ON(!pud_set_huge(pudp, phys, prot));
384384

385385
/*
386386
* After the PUD entry has been populated once, we

0 commit comments

Comments
 (0)