mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	ananth@linux.vnet.ibm.com, lkml <linux-kernel@vger.kernel.org>
Subject: Uprobe: Bug(?) when probing small binaries
Date: Mon, 12 Feb 2018 18:46:06 +0530	[thread overview]
Message-ID: <e74318e0-0cdf-e55d-bf06-b481541e2697@linux.vnet.ibm.com> (raw)

Hi Oleg,

I'm observing a bug in the uprobe infrastructure. When target binary
is quite small, uprobe replaces 'trap' instruction at two different
places. Ex,

Simple test.c that loops for 100 seconds:

    void main()
    {
        int i = 0;
   
        while (i++ != 100) {
            printf("hi: %d", i);
            sleep(1);
        }
    }

Add a probe on function main() in test.c

  $ perf probe -x ./a.out main
    Added new event:
      probe_a:main          (on main in /home/ravi/a.out)

Start the target program and pause it.

  $ gdb --args ./a.out
    (gdb) r
    main: 1
    main: 2
    ^C

  (gdb) disassemble main
       0x000000001000069c <+8>:    mflr    r0
 
  (gdb) x/w 0x1001069c
    0x1001069c:    2080899750

Now enable the probe:

  # echo 1 > events/probe_a/main/enable

Check probed instruction:

  (gdb) disassemble main
       0x000000001000069c <+8>:    trap

*Bug*:

  (gdb) x/w 0x1001069c
    0x1001069c:  2145386504

In short, when it replaces the probe instruction, it does some corruption
in the readonly vma. This seems to be a bug.

How did I get the other address 0x1001069c?I found build_map_info()
returns these two vmas for the single probe:

  10000000-10010000 r-xp 00000000 08:05 67325595   /home/ravi/a.out
  10010000-10020000 r--p 00000000 08:05 67325595   /home/ravi/a.out

and thusregister_for_each_vmas() calls install_breakpoint() on both of
thesevmas with different vaddr.

The example is on powerpc but same issue is observed on x86 as well. As,
the code is common, it should be reproducible on every architecture.

Also, I don't observe this issue for bigger binaries (maybe for those
whose vma spans across multiple pages).

Thanks,
Ravi

             reply	other threads:[~2018-02-12 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 13:16 Ravi Bangoria [this message]
2018-02-12 15:19 ` Oleg Nesterov

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=e74318e0-0cdf-e55d-bf06-b481541e2697@linux.vnet.ibm.com \
    --to=ravi.bangoria@linux.vnet.ibm.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=oleg@redhat.com \
    --cc=srikar@linux.vnet.ibm.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

all inboxes | Powered by JetHome®