linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
To: akpm@linux-foundation.org
Cc: fengguang.wu@intel.com, kbuild-all@01.org, hannes@cmpxchg.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() (Re: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037))
Date: Tue, 18 Feb 2014 16:01:15 -0500	[thread overview]
Message-ID: <5303ca35.c3030e0a.3e0a.2a2aSMTPIN_ADDED_BROKEN@mx.google.com> (raw)
In-Reply-To: <20140218124400.c173bdbf42c5a32848da2f76@linux-foundation.org>

On Tue, Feb 18, 2014 at 12:44:00PM -0800, Andrew Morton wrote:
> On Fri, 14 Feb 2014 10:09:58 -0500 Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> wrote:
> 
> > Fengguang reported smatch error about potential NULL pointer access.
> > 
> > In updated page table walker, we never run ->hugetlb_entry() callback
> > on the address without vma. This is because __walk_page_range() checks
> > it in advance. So we can assume non-NULL vma in pagemap_hugetlb().
> > 
> > ...
> >
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -1032,9 +1032,9 @@ static int pagemap_hugetlb(pte_t *pte, unsigned long addr, unsigned long end,
> >  	pagemap_entry_t pme;
> >  	unsigned long hmask;
> >  
> > -	WARN_ON_ONCE(!vma);
> > +	BUG_ON(!vma);
> 
> Let's just remove it altogether.
> 
> > -	if (vma && (vma->vm_flags & VM_SOFTDIRTY))
> > +	if (vma->vm_flags & VM_SOFTDIRTY)
> 
> The null deref oops will provide us the same info as the BUG_ON.  It
> will require a *little* more thinking to work out that `vma' was NULL,
> but it will be pretty obvious.

Yes, I agree. pagemap_hugetlb() is callback and never inlined, so we will
have an info like 'NULL pointer access on pagemap_hugetlb()' with call trace,
which is enough to pinpoint the problem.

> 
> This requires knowing offsetof(vm_area_struct, vm_flags).  I use a gdb macro:
> 
> define offsetof
> 	set $off = &(((struct $arg0 *)0)->$arg1)
> 	printf "%d 0x%x\n", $off, $off
> end
> 
> akpm3:/usr/src/25> gdb fs/proc/task_mmu.o
> ...
> (gdb) offsetof vm_area_struct vm_flags
> 80 0x50

Nice note, thank you.

Naoya

--
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-02-18 21:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com>
2014-02-14 13:04 ` [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037) Fengguang Wu
2014-02-14 15:09   ` [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() (Re: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037)) Naoya Horiguchi
     [not found]   ` <52fe31de.89cfe00a.338f.ffff9a19SMTPIN_ADDED_BROKEN@mx.google.com>
2014-02-18 20:44     ` Andrew Morton
2014-02-18 21:01       ` Naoya Horiguchi [this message]

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=5303ca35.c3030e0a.3e0a.2a2aSMTPIN_ADDED_BROKEN@mx.google.com \
    --to=n-horiguchi@ah.jp.nec.com \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=hannes@cmpxchg.org \
    --cc=kbuild-all@01.org \
    --cc=linux-mm@kvack.org \
    /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