LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jesper Juhl <jj@chaosbits.net>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org,
	Tejun Heo <tj@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Rohit Seth <rohit.seth@intel.com>
Subject: Re: [PATCH] Huge TLB: Potential NULL deref in arch/x86/mm/hugetlbpage.c:huge_pmd_share()
Date: Thu, 3 Feb 2011 13:01:50 -0800	[thread overview]
Message-ID: <20110203130150.7031c61f.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.LNX.2.00.1102032142580.15101@swampdragon.chaosbits.net>

On Thu, 3 Feb 2011 21:50:04 +0100 (CET)
Jesper Juhl <jj@chaosbits.net> wrote:

> In arch/x86/mm/hugetlbpage.c:huge_pmd_share() we call find_vma(mm, addr) 
> and then subsequently dereference the pointer returned without checking if 
> it was NULL. I can't find anything that guarantees that find_vma() will 
> never return NULL in this case, so I believe there's a genuine bug. 
> However, I'd greatly appreciate it if someone would take the time to 
> double check me.
> This patch implements what I believe to be the correct handling of a NULL 
> return from find_vma(). Please consider for inclusion.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  hugetlbpage.c |   11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
> index 069ce7c..0ebd3d0 100644
> --- a/arch/x86/mm/hugetlbpage.c
> +++ b/arch/x86/mm/hugetlbpage.c
> @@ -61,14 +61,19 @@ static int vma_shareable(struct vm_area_struct *vma, unsigned long addr)
>  static void huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
>  {
>  	struct vm_area_struct *vma = find_vma(mm, addr);
> -	struct address_space *mapping = vma->vm_file->f_mapping;
> -	pgoff_t idx = ((addr - vma->vm_start) >> PAGE_SHIFT) +
> -			vma->vm_pgoff;
> +	struct address_space *mapping;
> +	pgoff_t idx;
>  	struct prio_tree_iter iter;
>  	struct vm_area_struct *svma;
>  	unsigned long saddr;
>  	pte_t *spte = NULL;
>  
> +	if (!vma)
> +		return;
> +
> +	mapping = vma->vm_file->f_mapping;
> +	idx = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
> +
>  	if (!vma_shareable(vma, addr))
>  		return;

mmap_sem is held and the caller (copy_hugetlb_page_range) knows that
the virtual address at `addr' is within a vma.  So it's a "can't happen".

The code's all undocumented and you got fooled.  Cause, effect.

  reply	other threads:[~2011-02-03 21:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-03 20:50 Jesper Juhl
2011-02-03 21:01 ` Andrew Morton [this message]
2011-02-03 21:17   ` Jesper Juhl
2011-02-03 21:36     ` Andrew Morton
2011-02-03 21:43       ` Jesper Juhl

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=20110203130150.7031c61f.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=rohit.seth@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH] Huge TLB: Potential NULL deref in arch/x86/mm/hugetlbpage.c:huge_pmd_share()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).