Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jul 2017 21:47:15 +0300
From:      Guy Yur <guyyur@gmail.com>
To:        alc@freebsd.org
Cc:        freebsd-current <freebsd-current@freebsd.org>, kib@freebsd.org,  Sean Bruno <sbruno@freebsd.org>
Subject:   Re: emulators/qemu-user-static needs MAP_GUARD support
Message-ID:  <CAC67Hz91TXZS15qKnwNbpJwDZTL3eH%2BjY-=uQP-ca_1mZvJRug@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi Alan,

On 1 July 2017 at 23:07, Alan Cox <alan.l.cox@gmail.com> wrote:
>
> On Sat, Jul 1, 2017 at 2:46 PM, Guy Yur <guyyur@gmail.com> wrote:
>>
>> Hi,
>>
>> I tried to run armv6 /bin/sh in a chroot on an
>> amd64 host using qemu-arm-static.
>> It failed on invalid argument to mmap.
>>
>> # cp /usr/local/bin/qemu-arm-static /chroots/armv6/root/
>> # chroot /chroots/armv6 /root/qemu-arm-static /bin/sh
>> /lib/libedit.so.7: mmap of entire address space failed: Invalid argument
>>
>> ... snipped
>>
>
> MAP_ANON should not be passed to mmap(2) at the same time as MAP_GUARD.
> Passing MAP_FIXED at the same time is okay.
>

The problem is definitely in qemu user mode mmap emulation code.
https://github.com/seanbruno/qemu-bsd-user/blob/bsd-user/bsd-user/mmap.c#L464

qemu adds MAP_FIXED | MAP_ANONYMOUS if MAP_FIXED is not
set in flags when the emulated mmap call is done.
So rtld-elf passes MAP_GUARD and the kernel receives MAP_GUARD
and MAP_ANON and rejects the call.

Do you know if the MAP_ANONYMOUS is needed in the call?

I am currently using a workaround patch to convert
MAP_GUARD to MAP_PRIVATE | MAP_ANON | MAP_NOCORE
(like rtld-elf does if OS version doesn't support MAP_GUARD).
https://github.com/guyyur/freebsd-ports_patches/blob/master/emulators_qemu-sbruno__MAP_GUARD_workaround.patch
With the patch qemu-arm-static is working.

I would prefer using a better fix that retains the MAP_GUARD protections.

Thanks,
Guy



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAC67Hz91TXZS15qKnwNbpJwDZTL3eH%2BjY-=uQP-ca_1mZvJRug>