Re: emulators/qemu-user-static needs MAP_GUARD support

From: Alan Cox <alc_at_rice.edu>
Date: Wed, 5 Jul 2017 14:30:38 -0500
On 07/05/2017 13:47, Guy Yur wrote:
> Hi Alan,
>
> On 1 July 2017 at 23:07, Alan Cox <alan.l.cox_at_gmail.com> wrote:
>> On Sat, Jul 1, 2017 at 2:46 PM, Guy Yur <guyyur_at_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?

Try removing the MAP_ANON (or MAP_ANONYMOUS).  Adding MAP_FIXED should
not imply the addition of MAP_ANON.

> 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
>
Received on Wed Jul 05 2017 - 17:30:47 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:12 UTC