linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Bob Liu <lliubbo@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	Sasha Levin <sasha.levin@oracle.com>,
	Bob Liu <bob.liu@oracle.com>, Linux-MM <linux-mm@kvack.org>
Subject: Re: [PATCH] mm: do_shared_fault: fix potential NULL pointer dereference
Date: Mon, 3 Mar 2014 12:47:24 -0800	[thread overview]
Message-ID: <20140303124724.9c287478cd0c550bc222ca1f@linux-foundation.org> (raw)
In-Reply-To: <CAA_GA1dzMA+RS=TtM6ieJ7_DY5ruAbY9a4Ui9O7EYuvc-bSH_A@mail.gmail.com>

On Sat, 1 Mar 2014 11:14:17 +0800 Bob Liu <lliubbo@gmail.com> wrote:

> >
> > --- a/mm/memory.c~mm-introduce-do_shared_fault-and-drop-do_fault-fix-fix
> > +++ a/mm/memory.c
> > @@ -3476,6 +3476,12 @@ set_pte:
> >
> >         if (set_page_dirty(fault_page))
> >                 dirtied = 1;
> > +       /*
> > +        * Take a local copy of the address_space - page.mapping may be zeroed
> > +        * by truncate after unlock_page().   The address_space itself remains
> > +        * pinned by vma->vm_file's reference.  We rely on unlock_page()'s
> > +        * release semantics to prevent the compiler from undoing this copying.
> > +        */
> >         mapping = fault_page->mapping;
> >         unlock_page(fault_page);
> >         if ((dirtied || vma->vm_ops->page_mkwrite) && mapping) {
> >
> > I don't actually know if that's true.  What *does* protect ->mapping
> > from reclaim, drop_caches, etc?
> >
> 
> I also puzzled what can protect ->mapping.

Yes, ->mapping is pinned by the reference from vma->vm_file. 
vma->vm_file (and the vma itself) are protected by mmap_sem (held for
rear or for write).

I'll stick this in there, see what happens..

--- a/mm/memory.c~a
+++ a/mm/memory.c
@@ -3422,6 +3422,8 @@ static int do_shared_fault(struct mm_str
 	struct vm_fault vmf;
 	int ret, tmp;
 
+	WARN_ON_ONCE(!rwsem_is_locked(&mm->mmap_sem));
+
 	ret = __do_fault(vma, address, pgoff, flags, &fault_page);
 	if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY)))
 		return ret;
_

--
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>

      parent reply	other threads:[~2014-03-03 20:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1393507600-24752-1-git-send-email-bob.liu@oracle.com>
     [not found] ` <20140227154808.cbe04fa80cb47e2e091daa31@linux-foundation.org>
     [not found]   ` <20140227235959.GA9424@node.dhcp.inet.fi>
     [not found]     ` <20140228090745.GE27965@twins.programming.kicks-ass.net>
     [not found]       ` <20140228135950.4a49ce89b5bff12c149b1f73@linux-foundation.org>
2014-03-01  3:14         ` Bob Liu
2014-03-01  3:18           ` Sasha Levin
2014-03-03 20:47           ` Andrew Morton [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=20140303124724.9c287478cd0c550bc222ca1f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bob.liu@oracle.com \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    --cc=lliubbo@gmail.com \
    --cc=peterz@infradead.org \
    --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