From: Ingo Molnar <mingo@kernel.org>
To: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>, Hugh Dickins <hughd@google.com>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Anton Arapov <anton@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] uprobes: write_opcode()->__replace_page() can race with try_to_unmap()
Date: Fri, 15 Jun 2012 14:11:51 +0200 [thread overview]
Message-ID: <20120615121151.GB28541@gmail.com> (raw)
In-Reply-To: <20120615061217.GC12051@linux.vnet.ibm.com>
* Srikar Dronamraju <srikar@linux.vnet.ibm.com> wrote:
> > ---
> > Subject: [PATCH] uprobes: write_opcode()->__replace_page() can race with try_to_unmap()
> >
> > write_opcode() gets old_page via get_user_pages() and then calls
> > __replace_page() which assumes that this old_page is still mapped
> > after pte_offset_map_lock().
> >
> > This is not true if this old_page was already try_to_unmap()'ed,
> > and in this case everything __replace_page() does with old_page
> > is wrong. Just for example, put_page() is not balanced.
> >
> > I think it is possible to teach __replace_page() to handle this
> > unlikely case correctly, but this patch simply changes it to use
> > page_check_address() and return -EAGAIN if it fails. The caller
> > should notice this error code and retry.
> >
> > Note: write_opcode() asks for the cleanups, I'll try to do this
> > in a separate patch.
> >
> > Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> > ---
> > kernel/events/uprobes.c | 41 +++++++++++++----------------------------
> > 1 files changed, 13 insertions(+), 28 deletions(-)
> >
> > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> > index 9c53bc2..54c8780 100644
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -135,33 +135,17 @@ static loff_t vma_address(struct vm_area_struct *vma, loff_t offset)
> > static int __replace_page(struct vm_area_struct *vma, struct page *page, struct page *kpage)
> > {
> > struct mm_struct *mm = vma->vm_mm;
> > - pgd_t *pgd;
> > - pud_t *pud;
> > - pmd_t *pmd;
> > - pte_t *ptep;
> > - spinlock_t *ptl;
> > unsigned long addr;
> > - int err = -EFAULT;
> > + spinlock_t *ptl;
> > + pte_t *ptep;
> >
> > addr = page_address_in_vma(page, vma);
> > if (addr == -EFAULT)
> > - goto out;
> > -
> > - pgd = pgd_offset(mm, addr);
> > - if (!pgd_present(*pgd))
> > - goto out;
> > -
> > - pud = pud_offset(pgd, addr);
> > - if (!pud_present(*pud))
> > - goto out;
> > + return -EFAULT;
> >
> > - pmd = pmd_offset(pud, addr);
> > - if (!pmd_present(*pmd))
> > - goto out;
> > -
> > - ptep = pte_offset_map_lock(mm, pmd, addr, &ptl);
> > + ptep = page_check_address(page, mm, addr, &ptl, 0);
> > if (!ptep)
> > - goto out;
> > + return -EAGAIN;
> >
> > get_page(kpage);
> > page_add_new_anon_rmap(kpage, vma, addr);
> > @@ -180,10 +164,8 @@ static int __replace_page(struct vm_area_struct *vma, struct page *page, struct
> > try_to_free_swap(page);
> > put_page(page);
> > pte_unmap_unlock(ptep, ptl);
> > - err = 0;
> >
> > -out:
> > - return err;
> > + return 0;
> > }
> >
> > /**
> > @@ -228,9 +210,10 @@ static int write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm,
> > void *vaddr_old, *vaddr_new;
> > struct vm_area_struct *vma;
> > struct uprobe *uprobe;
> > + unsigned long pgoff;
> > loff_t addr;
> > int ret;
> > -
> > +retry:
>
> Just a check on coding style: Shouldnt we have a preceeding blank
> line before the goto label.
Yeah, that's most likely helpful to readability.
Thanks,
Ingo
next prev parent reply other threads:[~2012-06-15 12:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-07 16:59 [PATCH 0/3] uprobes fixes for 3.5 Oleg Nesterov
2012-06-07 17:00 ` [PATCH 1/3] uprobes: valid_vma() should reject VM_HUGETLB Oleg Nesterov
2012-06-15 6:22 ` Srikar Dronamraju
2012-06-07 17:00 ` [PATCH 2/3] uprobes: __copy_insn() should ensure a_ops->readpage != NULL Oleg Nesterov
2012-06-15 6:25 ` Srikar Dronamraju
2012-06-15 12:10 ` Ingo Molnar
2012-06-07 17:00 ` [PATCH 3/3] uprobes: write_opcode()->__replace_page() can race with try_to_unmap() Oleg Nesterov
2012-06-08 8:47 ` Peter Zijlstra
2012-06-08 10:03 ` Oleg Nesterov
2012-06-08 16:55 ` Oleg Nesterov
2012-06-15 6:12 ` Srikar Dronamraju
2012-06-15 12:11 ` Ingo Molnar [this message]
2012-06-15 15:48 ` Oleg Nesterov
2012-06-16 7:11 ` Ingo Molnar
2012-06-08 14:03 ` oom-killer is crazy? (Was: [PATCH 0/3] uprobes fixes for 3.5) Oleg Nesterov
2012-06-08 14:26 ` Dave Jones
2012-06-08 15:04 ` Oleg Nesterov
2012-06-08 20:21 ` [patch for-3.5-rc1] mm, oom: fix badness score underflow David Rientjes
2012-06-09 22:25 ` KOSAKI Motohiro
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=20120615121151.GB28541@gmail.com \
--to=mingo@kernel.org \
--cc=ananth@in.ibm.com \
--cc=anton@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).