[PATCH] collapse_pte_mapped_thp() folio conversion fix

From: Vishal Moola (Oracle)
Date: Wed Oct 18 2023 - 17:24:47 EST


filemap_lock_folio() can return an ERR_PTR on failure.
find_lock_page()/pagecache_get_page() handles this internally, while
filemap_lock_folio() does not. Ensure this is checked for in the caller
after converting find_lock_page() to filemap_lock_folio().

Reported-and-tested-by: syzbot+1e2648076cadf48ad9a1@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@xxxxxxxxx>
---
mm/khugepaged.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 94c1dd09a8a6..b944ed231792 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1510,7 +1510,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,

folio = filemap_lock_folio(vma->vm_file->f_mapping,
linear_page_index(vma, haddr));
- if (!folio)
+ if (!folio || IS_ERR(folio))
return SCAN_PAGE_NULL;

if (folio_order(folio) != HPAGE_PMD_ORDER) {
--
2.40.1


--k9WjaocPDLBP3aBR--