linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: fix potential pte_unmap_unlock pte error
@ 2020-10-15 12:15 Shijie Luo
  2020-10-15 12:58 ` osalvador
  2020-10-16 12:31 ` Michal Hocko
  0 siblings, 2 replies; 16+ messages in thread
From: Shijie Luo @ 2020-10-15 12:15 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe, linfeilong, luoshijie1

When flags don't have MPOL_MF_MOVE or MPOL_MF_MOVE_ALL bits, code breaks
 and passing origin pte - 1 to pte_unmap_unlock seems like not a good idea.

Signed-off-by: Shijie Luo <luoshijie1@huawei.com>
Signed-off-by: linmiaohe <linmiaohe@huawei.com>
---
 mm/mempolicy.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 3fde772ef5ef..01f088630d1d 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -571,7 +571,11 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
 		} else
 			break;
 	}
-	pte_unmap_unlock(pte - 1, ptl);
+
+	if (addr >= end)
+		pte = pte - 1;
+
+	pte_unmap_unlock(pte, ptl);
 	cond_resched();
 
 	if (has_unmovable)
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH] mm: Fix potential pte_unmap_unlock pte error
@ 2021-01-09  8:01 Miaohe Lin
  2021-01-10 17:14 ` Andi Kleen
  0 siblings, 1 reply; 16+ messages in thread
From: Miaohe Lin @ 2021-01-09  8:01 UTC (permalink / raw)
  To: akpm; +Cc: tglx, dave.hansen, ak, jpoimboe, linux-mm, linux-kernel, linmiaohe

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")
Signed-off-by: Hongxiang Lou <louhongxiang@huawei.com>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: stable@kernel.org
---
 mm/memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index feff48e1465a..351b78ebd5a4 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -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;
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-01-25  2:15 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 12:15 [PATCH] mm: fix potential pte_unmap_unlock pte error Shijie Luo
2020-10-15 12:58 ` osalvador
2020-10-15 13:19   ` Shijie Luo
2020-10-16 12:31 ` Michal Hocko
2020-10-16 12:37   ` osalvador
2020-10-16 13:11     ` Michal Hocko
2020-10-16 13:15       ` Michal Hocko
2020-10-16 13:42         ` Michal Hocko
2020-10-16 14:05           ` osalvador
2020-10-17  1:55             ` Shijie Luo
2021-01-09  8:01 [PATCH] mm: Fix " Miaohe Lin
2021-01-10 17:14 ` Andi Kleen
2021-01-14  2:51   ` Miaohe Lin
2021-01-22  8:27     ` Miaohe Lin
2021-01-24  2:01       ` Andrew Morton
2021-01-25  2:04         ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).