* [PATCH] linux-user: Fix executable page of /proc/self/maps
@ 2021-03-05 17:31 Nicolas Surbayrole
2021-03-05 18:50 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Surbayrole @ 2021-03-05 17:31 UTC (permalink / raw)
To: qemu-devel; +Cc: Nicolas Surbayrole
The guest binary and libraries are not always mapped with the
executable bit in the host process. The guest may read a
/proc/self/maps with no executable address range. The
patch bases the perm fields against the guest permission inside
Qemu.
Signed-off-by: Nicolas Surbayrole <nsurbayrole@quarkslab.com>
---
linux-user/syscall.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 389ec09764..77c40a274f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7888,9 +7888,9 @@ static int open_self_maps(void *cpu_env, int fd)
count = dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr
" %c%c%c%c %08" PRIx64 " %s %"PRId64,
h2g(min), h2g(max - 1) + 1,
- e->is_read ? 'r' : '-',
- e->is_write ? 'w' : '-',
- e->is_exec ? 'x' : '-',
+ (flags & PROT_READ) ? 'r' : '-',
+ (flags & PROT_WRITE) ? 'w' : '-',
+ (flags & PROT_EXEC) ? 'x' : '-',
e->is_priv ? 'p' : '-',
(uint64_t) e->offset, e->dev, e->inode);
if (path) {
--
2.30.1
When trying to used Qemu on amd64 host to run aarch64 binary, I've reached
an issue with /proc/self/maps.
$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
$ docker run --rm -it arm64v8/ubuntu cat /proc/self/maps
5500000000-5500008000 r--p 00000000 fe:06 141788774 /usr/bin/cat
5500008000-5500017000 ---p 00000000 00:00 0
5500017000-5500018000 r--p 00007000 fe:06 141788774 /usr/bin/cat
5500018000-5500019000 rw-p 00008000 fe:06 141788774 /usr/bin/cat
5500019000-550003a000 rw-p 00000000 00:00 0
5501019000-550101a000 ---p 00000000 00:00 0
550101a000-550181a000 rw-p 00000000 00:00 0 [stack]
550181a000-550183b000 r--p 00000000 fe:06 134329967 /usr/lib/aarch64-linux-gnu/ld-2.31.so
550183b000-550184b000 ---p 00000000 00:00 0
550184b000-550184c000 r--p 00021000 fe:06 134329967 /usr/lib/aarch64-linux-gnu/ld-2.31.so
550184c000-550184e000 rw-p 00022000 fe:06 134329967 /usr/lib/aarch64-linux-gnu/ld-2.31.so
5501850000-55019a9000 r--p 00000000 fe:06 134344388 /usr/lib/aarch64-linux-gnu/libc-2.31.so
55019a9000-55019b8000 ---p 00159000 fe:06 134344388 /usr/lib/aarch64-linux-gnu/libc-2.31.so
55019b8000-55019bb000 r--p 00158000 fe:06 134344388 /usr/lib/aarch64-linux-gnu/libc-2.31.so
55019bb000-55019be000 rw-p 0015b000 fe:06 134344388 /usr/lib/aarch64-linux-gnu/libc-2.31.so
55019be000-55019c3000 rw-p 00000000 00:00 0
No executable page is available. The same result is observed with the
last master commit. I think the perm fields should be based on
the guest permission inside Qemu, but I'd be happy to hear the rational against this.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] linux-user: Fix executable page of /proc/self/maps
2021-03-05 17:31 [PATCH] linux-user: Fix executable page of /proc/self/maps Nicolas Surbayrole
@ 2021-03-05 18:50 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2021-03-05 18:50 UTC (permalink / raw)
To: laurent, qemu-devel; +Cc: Nicolas Surbayrole
On 3/5/21 9:31 AM, Nicolas Surbayrole wrote:
> The guest binary and libraries are not always mapped with the
> executable bit in the host process. The guest may read a
> /proc/self/maps with no executable address range. The
> patch bases the perm fields against the guest permission inside
> Qemu.
>
> Signed-off-by: Nicolas Surbayrole <nsurbayrole@quarkslab.com>
> ---
> linux-user/syscall.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 389ec09764..77c40a274f 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7888,9 +7888,9 @@ static int open_self_maps(void *cpu_env, int fd)
> count = dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr
> " %c%c%c%c %08" PRIx64 " %s %"PRId64,
> h2g(min), h2g(max - 1) + 1,
> - e->is_read ? 'r' : '-',
> - e->is_write ? 'w' : '-',
> - e->is_exec ? 'x' : '-',
> + (flags & PROT_READ) ? 'r' : '-',
> + (flags & PROT_WRITE) ? 'w' : '-',
> + (flags & PROT_EXEC) ? 'x' : '-',
Use PAGE_*, as those are the bits in flags. These three just happen to be the
same.
While we're at it, use PAGE_WRITE_ORG -- PAGE_WRITE may be removed on a rwx
page in which we've translated code.
r~
> e->is_priv ? 'p' : '-',
> (uint64_t) e->offset, e->dev, e->inode);
> if (path) {
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-05 18:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-05 17:31 [PATCH] linux-user: Fix executable page of /proc/self/maps Nicolas Surbayrole
2021-03-05 18:50 ` Richard Henderson
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).