All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: Nick Piggin <npiggin@suse.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Jim Keniston <jkenisto@us.ibm.com>,
	systemtap-ml <systemtap@sources.redhat.com>,
	"Frank Ch. Eigler" <fche@redhat.com>
Subject: Re: [BUG][kprobes][vunmap?]: kprobes may cause memory corruption
Date: Wed, 28 Jan 2009 11:59:27 -0500	[thread overview]
Message-ID: <49808EEF.1020700@redhat.com> (raw)
In-Reply-To: <20090128154824.GA6025@Krystal>

Mathieu Desnoyers wrote:
> * Masami Hiramatsu (mhiramat@redhat.com) wrote:
>> Masami Hiramatsu wrote:
> Hi Masami,
> 
> This would not surprise me if it came from bug in the new vmap()
> implementation done in this commit :
> 
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=db64fe02258f1507e13fe5212a989922323685ce
> 
> Especially because going from vmap -> vm_map_ram makes this behavior
> disappear.
> 
> Looking at the commit, I notice that it delays vunmap so it's done in
> batch to minimize locking effect. I think it would be good to create a
> test case to try to isolate this, without any kprobes/text_poke
> involved, which does something like this :
> 
> load module (this is also doing vmalloc, so it might be part of the
>              problem)
>   for i (i=0; i < 400; i++) {
>     vmap()
>     vfree()
      ^^^^^ vunmap?
>   }
> unload module
> 
> Another interesting test would be :
> 
>   for i (i=0; i < 400; i++) {
>     vmalloc()
>     vfree()
>   }

Hi Mathieu,

Thank you for test ideas.
I made both of above two tests and run it. Both test modules
do NOT cause memory corruption...

> All this called in a loop. This would help isolating the "vmap" part of
> the issue. If this test is not enough, then we should maybe try
> something like this in a kernel module (which does what text_poke does
> with vmalloc, more or less) in a loop :
> 
> char somedata[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
> char copydata[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));

Should both of them have PAGE_SIZE*2?

> 
> void test_vmap(void)
> }
>   struct page *pages[2];
>   char *vaddr;
>   int i;
> 
>   for (i = 0; i < 2 * PAGE_SIZE; i++)
>     copydata[i] = somedata[i];
>   page[0] = virt_to_page(&somedata);
>   BUG_ON(!page[0]);
>   page[1] = virt_to_page(&somedata + PAGE_SIZE);
>   BUG_ON(!page[1]);
>   vaddr = vmap(pages, 2, VM_MAP, PAGE_KERNEL);
>   BUG_ON(!vaddr);
> 
>   for (i = 0; i < 2 * PAGE_SIZE; i++)
>     vaddr[i] = copydata[i] + 1;
>   
>   vunmap(vaddr);
>   
>   for (i = 0; i < 2 * PAGE_SIZE; i++)
>     BUG_ON(somedata[i] != copydata[i] + 1);
> }

Hmm, when I ran above code, it hit the last BUG_ON().
I checked that somedata[i] didn't updated.

> Given you don't seem to have hit the
>         for (i = 0; i < len; i++)
>                 BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
> test at the end of text_poke,

However, when I ran kprobe-based test, it doesn't hit the BUG_ON()
in text_poke().

> I suspect the write through the vmapped
> area is correctly done, but that the problem may lay in the mm layer.
> Maybe it's running out of pre-allocated vmap areas or something like
> this ?

I haven't seen vmalloc failure message on 2.6.29-rc2.

Thank you again,


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


  parent reply	other threads:[~2009-01-28 16:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-28  2:32 [BUG][kprobes][vunmap?]: kprobes may cause memory corruption Masami Hiramatsu
2009-01-28  2:39 ` [PATCH][bugfix?][kprobes][vunmap?]: use vm_map_ram() in text_poke() Masami Hiramatsu
2009-01-28  5:09 ` [BUG][kprobes][vunmap?]: kprobes may cause memory corruption Masami Hiramatsu
2009-01-28 15:48   ` Mathieu Desnoyers
2009-01-28 16:22     ` Mathieu Desnoyers
2009-01-28 16:59     ` Masami Hiramatsu [this message]
2009-01-28 17:13       ` Mathieu Desnoyers
2009-01-28 17:58         ` Masami Hiramatsu
2009-01-28 18:10           ` Mathieu Desnoyers
2009-02-05 22:12             ` [BUGFIX][PATCH -rc/-mm] prevent kprobes from catching spurious page faults Masami Hiramatsu
2009-02-05 23:57               ` Ingo Molnar
2009-02-06  1:13                 ` Mathieu Desnoyers
2009-02-06  2:04                   ` Ingo Molnar
2009-02-06  2:05                     ` Ingo Molnar
2009-02-06 16:30                   ` Masami Hiramatsu
2009-02-06 15:57                 ` Masami Hiramatsu
2009-03-16 22:57             ` [BUGFIX][PATCH] prevent boosting kprobes on exception address Masami Hiramatsu
2009-01-28 18:13           ` [BUG][kprobes][vunmap?]: kprobes may cause memory corruption Masami Hiramatsu

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=49808EEF.1020700@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=jkenisto@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=npiggin@suse.de \
    --cc=systemtap@sources.redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.