[PATCH] mm: fix potential pte_unmap_unlock pte error
From: Shijie Luo
Date: Thu Oct 15 2020 - 08:16:05 EST
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@xxxxxxxxxx>
Signed-off-by: linmiaohe <linmiaohe@xxxxxxxxxx>
---
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