From: Stefano Bonifazi <stefboombastic@gmail.com>
To: Mulyadi Santosa <mulyadi.santosa@gmail.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] qemu-user: relocating target code weakness
Date: Mon, 24 Jan 2011 19:16:22 +0100 [thread overview]
Message-ID: <4D3DC1F6.9030800@gmail.com> (raw)
In-Reply-To: <AANLkTin_LVqQ-BjYtyJ1YJ3C4ok2nS_E8k_HoA7TRgqG@mail.gmail.com>
Hi!
Thank you for answering me!
> Start address in which address the ELF code section, in reality (not
> under qemu-user) should be mapped. in x86 32 bit it's 08048000, you
> can check it by yourself by executing:
> cat /proc/self/maps
>
Wait, like that I don't understand anything more.. As far as I
understood when calling mmap from within a process, its result, when no
error happen, would be the virtual address where the mapping starts.. so
if I get 0x10000000 from mmap why should it be 08048000 instead??
Inside load_elf_binary the call to mmap has elf_ppnt->p_vaddr as
required starting address (plus alignment) and MAP_FIXED flag.. so what
I get is elf_ppnt->p_vaddr as starting map address (if the call does not
fail) .. so I do not understand where does that address ELF_START_MMAP
get any role?
> however, as you already know, it might be relocated elsewhere if the
> code is PIC or PIE (Position Independent Executable).
>
Well PIC target code, inside load_elf_binary would have elf_ex.e_type ==
ET_DYN
so the mmap would be not flagged with MAP_FIXED, and the starting
address of the mapping would be chosen by the memory manager .. again
ELF_START_MMAP is not used...
> I wrote an article about understanding ELF years ago, here is the URL:
> http://www.linuxforums.org/articles/understanding-elf-using-readelf-and-objdump_125.html
>
Will you believe me if I tell you I printed that document some hours ago
without noticing you were the author? :)
I downloaded and read so much material from the Internet for studying
this stuff!!
>> what is start_mmap supposed to point at at the end? Why that
>> static value is chosen at the beginning?
> in qemu 0.13.0, linux-user/elfload.c, lines around 1728 to 1761, you
> will find that start_mmap is kinda an address that is the result of
> mmap operation that will be filled with the code in code section. It
> will be a "hint" on which address the guest code really points when
> dealing with memory address.
>
No, not for my understanding: that code for me searches for a suitable
mapping area, I can't see info->start_mmap being set anywhere else..
surely not among those lines of code
> I dare to guess that, every code executed in the guest...when
> referring to virtual address, will be get substracted by the delta of
> ELF_START_MMAP and real_base.
>
> It's like "hey, it's written A in the code, but it's mapped in B, ok
> so the delta is A-B, call it X. Then every address in the code should
> be substracted (or added, depending on how you see it) with X, then it
> will point in qemu mmaped VMA"
>
Wrong, at least for what I did understand, and from the tests I did.. I
compared different input - output assembly code, hardcoded target binary
addresses like those of static global variables (not of shared modules)
are not changed at all, producing segmentation faults when forcing a
shift of the mapping..
> See the codes, read it slowly, you wil get the idea.
I did, I do, I am changing the code for testing it.. fixing it.. but I
can't see any relocation
> PS: IMHO the real guru is still the one and only Fabrice Bellard, too
> bad he's out of qemu.
>
How is it possible that the creator of all of this is out?
Thank you very much for your help!
Best regards!
Stefano B.
next prev parent reply other threads:[~2011-01-24 18:16 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-24 11:34 [Qemu-devel] qemu-user: relocating target code weakness Stefano Bonifazi
2011-01-24 16:29 ` Mulyadi Santosa
2011-01-24 18:16 ` Stefano Bonifazi [this message]
2011-01-24 20:00 ` Mike Frysinger
2011-01-24 20:58 ` Stefano Bonifazi
2011-01-24 21:21 ` Mike Frysinger
2011-01-24 21:52 ` Stefano Bonifazi
2011-01-24 22:11 ` Mike Frysinger
2011-01-24 22:24 ` Stefano Bonifazi
2011-01-24 22:34 ` Mike Frysinger
2011-01-25 0:06 ` Mike Frysinger
2011-01-25 0:18 ` Mike Frysinger
2011-01-25 8:49 ` Stefano Bonifazi
2011-01-25 8:26 ` Stefano Bonifazi
2011-01-24 19:46 ` Richard Henderson
2011-01-24 21:44 ` Stefano Bonifazi
2011-01-24 23:32 ` Mike Frysinger
2011-01-25 8:25 ` Stefano Bonifazi
2011-01-25 1:36 ` Richard Henderson
2011-01-25 8:47 ` Stefano Bonifazi
2011-01-25 8:53 ` Mike Frysinger
2011-01-25 9:58 ` Stefano Bonifazi
2011-01-25 10:47 ` Stefano Bonifazi
2011-01-25 16:22 ` Richard Henderson
2011-01-25 19:03 ` Stefano Bonifazi
2011-01-25 11:06 ` Stefano Bonifazi
2011-01-25 16:26 ` Richard Henderson
2011-01-25 19:49 ` Stefano Bonifazi
2011-01-25 20:53 ` Lluís
2011-01-26 11:07 ` Stefano Bonifazi
2011-01-26 15:38 ` Richard Henderson
2011-01-26 17:44 ` Stefano Bonifazi
2011-01-26 20:17 ` Lluís
2011-01-26 20:19 ` Richard Henderson
2011-01-26 20:33 ` Stefano Bonifazi
2011-01-26 20:36 ` Lluís
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=4D3DC1F6.9030800@gmail.com \
--to=stefboombastic@gmail.com \
--cc=mulyadi.santosa@gmail.com \
--cc=qemu-devel@nongnu.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 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.