Skip to contentSkip to conversation

mm: Fix potential pte_unmap_unlock pte error

PATCH Applied Miaohe Lin 3 participants 6 messages Jan 9, 2021 – Jan 25, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm: Fix potential pte_unmap_unlock pte error

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Fixes 42e4089c789 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings")
---
 mm/memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memory.c +3 -3
index feff48e1465a..351b78ebd5a4 100644
@@ -2165,11 +2165,11 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd,
 			unsigned long addr, unsigned long end,
 			unsigned long pfn, pgprot_t prot)
 {
-	pte_t *pte;
+	pte_t *pte, *mapped_pte;
 	spinlock_t *ptl;
 	int err = 0;
 
-	pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
+	mapped_pte = pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
 	if (!pte)
 		return -ENOMEM;
 	arch_enter_lazy_mmu_mode();
@@ -2183,7 +2183,7 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd,
 		pfn++;
 	} while (pte++, addr += PAGE_SIZE, addr != end);
 	arch_leave_lazy_mmu_mode();
-	pte_unmap_unlock(pte - 1, ptl);
+	pte_unmap_unlock(mapped_pte, ptl);
 	return err;
 }
 
Signature · 1 line
2.19.1
#1 lore raw
Quoted 4 lines · Miaohe Lin

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Thanks.

While the fix is correct, I'm not sure if it actually is a real bug. Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug.

That said of course the change is the right thing for main line, but probably doesn't need to be backported.

-Andi

author
#2 lore raw

Hi:

Quoted 6 lines · Andi Kleen
Quoted 4 lines · Miaohe Lin

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Quoted 7 lines

Thanks.

While the fix is correct, I'm not sure if it actually is a real bug. Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug.

It's just a theoretical issue via code inspection.

Quoted 3 lines

That said of course the change is the right thing for main line, but probably doesn't need to be backported.

So it should not be backported. Should I resend a patch or Andrew would kindly do this?

Quoted 3 lines

-Andi
.

Many thanks for review and reply.

author
#3 lore raw

Hi Andrew:

Quoted 10 lines · Miaohe Lin

Hi:

Quoted 8 lines · Andi Kleen
Quoted 4 lines · Miaohe Lin

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Thanks.

Quoted 7 lines
Quoted 5 lines

While the fix is correct, I'm not sure if it actually is a real bug. Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug.

It's just a theoretical issue via code inspection.

Should I send a new one without Cc statle or just drop this patch? Thanks.

Quoted 13 lines
Quoted 4 lines

That said of course the change is the right thing for main line, but probably doesn't need to be backported.

So it should not be backported. Should I resend a patch or Andrew would kindly do this?

Quoted 3 lines

-Andi
.

Many thanks for review and reply.

maintainer
#4 lore raw
Quoted 18 lines · On Fri, 22 Jan 2021 16:27:23 +0800 Miaohe Lin <[email protected]> wrote:

Hi Andrew:

Quoted 16 lines · Miaohe Lin

Hi:

Quoted 13 lines · Andi Kleen
Quoted 4 lines · Miaohe Lin

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Thanks.

While the fix is correct, I'm not sure if it actually is a real bug. Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug.

Quoted 3 lines
Quoted 1 line

It's just a theoretical issue via code inspection.

Should I send a new one without Cc statle or just drop this patch? Thanks.

Your patch makes the code much less scary looking. I added Andi's observation to the changelog, removed the cc:stable and queued it up, thanks.

author
#5 lore raw

Hi:

Quoted 22 lines · Andrew Morton
Quoted 20 lines · On Fri, 22 Jan 2021 16:27:23 +0800 Miaohe Lin <[email protected]> wrote:

Hi Andrew:

Quoted 17 lines · Miaohe Lin

Hi:

Quoted 6 lines · Andi Kleen
Quoted 4 lines · Miaohe Lin

Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock.

Quoted 7 lines

Thanks.

While the fix is correct, I'm not sure if it actually is a real bug. Is there any architecture that would do something else than unlocking the underlying page? If it's just the underlying page then it should be always the same page, so no bug.

It's just a theoretical issue via code inspection.

Quoted 8 lines
Quoted 1 line

Should I send a new one without Cc statle or just drop this patch? Thanks.

Your patch makes the code much less scary looking. I added Andi's observation to the changelog, removed the cc:stable and queued it up, thanks.

.

Sounds reasonable. Many thanks for doing this!