linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: linux-kernel@vger.kernel.org, mgorman@suse.de,
	andi@firstfloor.org, sasha.levin@oracle.com,
	kirill.shutemov@linux.intel.com, aneesh.kumar@linux.vnet.ibm.com,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm/hugetlb.c: add NULL check of return value of huge_pte_offset
Date: Fri, 4 Apr 2014 15:03:45 -0700	[thread overview]
Message-ID: <20140404150345.92400430db3111fe21df7c7f@linux-foundation.org> (raw)
In-Reply-To: <533efd68.435fe00a.6936.ffffa5e7SMTPIN_ADDED_BROKEN@mx.google.com>

On Fri, 04 Apr 2014 14:43:33 -0400 Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> wrote:

> huge_pte_offset() could return NULL, so we need NULL check to avoid
> potential NULL pointer dereferences.
> 
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2662,7 +2662,8 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
>  				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
> @@ -2706,7 +2707,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
>  	 */
>  	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 */

Has anyone been hitting oopses here or was this from code inspection?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

       reply	other threads:[~2014-04-04 22:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <533efd68.435fe00a.6936.ffffa5e7SMTPIN_ADDED_BROKEN@mx.google.com>
2014-04-04 22:03 ` Andrew Morton [this message]
2014-04-05  0:04   ` Naoya Horiguchi
2014-04-04 18:43 Naoya Horiguchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140404150345.92400430db3111fe21df7c7f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=sasha.levin@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox