From: Naoya Horiguchi Date: Mon, 7 Apr 2014 22:36:54 +0000 (-0700) Subject: mm/hugetlb.c: add NULL check of return value of huge_pte_offset X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a9af0c5dfdaf0b2e1a8bab7fbf6f29138947d534;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git 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 Cc: Mel Gorman Cc: Sasha Levin Cc: Kirill A. Shutemov Cc: Aneesh Kumar K.V Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7c02b9dadfb0..6cddfadaba03 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2690,7 +2690,8 @@ retry_avoidcopy: BUG_ON(huge_pte_none(pte)); spin_lock(ptl); 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; /* * race occurs while re-acquiring page table @@ -2734,7 +2735,7 @@ retry_avoidcopy: */ spin_lock(ptl); 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); /* Break COW */