瀏覽代碼

mm/hugetlb.c: add NULL check of return value of huge_pte_offset

huge_pte_offset() could return NULL, so we need NULL check to avoid
potential NULL pointer dereferences.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Naoya Horiguchi 11 年之前
父節點
當前提交
a9af0c5dfd
共有 1 個文件被更改,包括 3 次插入2 次删除
  1. 3 2
      mm/hugetlb.c

+ 3 - 2
mm/hugetlb.c

@@ -2690,7 +2690,8 @@ retry_avoidcopy:
 				BUG_ON(huge_pte_none(pte));
 				BUG_ON(huge_pte_none(pte));
 				spin_lock(ptl);
 				spin_lock(ptl);
 				ptep = huge_pte_offset(mm, address & huge_page_mask(h));
 				ptep = huge_pte_offset(mm, address & huge_page_mask(h));
-				if (likely(pte_same(huge_ptep_get(ptep), pte)))
+				if (likely(ptep &&
+					   pte_same(huge_ptep_get(ptep), pte)))
 					goto retry_avoidcopy;
 					goto retry_avoidcopy;
 				/*
 				/*
 				 * race occurs while re-acquiring page table
 				 * race occurs while re-acquiring page table
@@ -2734,7 +2735,7 @@ retry_avoidcopy:
 	 */
 	 */
 	spin_lock(ptl);
 	spin_lock(ptl);
 	ptep = huge_pte_offset(mm, address & huge_page_mask(h));
 	ptep = huge_pte_offset(mm, address & huge_page_mask(h));
-	if (likely(pte_same(huge_ptep_get(ptep), pte))) {
+	if (likely(ptep && pte_same(huge_ptep_get(ptep), pte))) {
 		ClearPagePrivate(new_page);
 		ClearPagePrivate(new_page);
 
 
 		/* Break COW */
 		/* Break COW */