Re: running binary in chroot using qemu-arm-static fails to mmap after r320318

2017-07-01 Thread Alan Cox
On Sat, Jul 1, 2017 at 2:46 PM, Guy Yur  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
>
> rtld-elf only passes MAP_GUARD but ktrace shows mmap
> is called with MAP_FIXED and MAP_ANON too.
> I think qemu-user-static adds the flags in bsd-user/mmap.c target_mmap().
> Does the qemu-user-static port need patching to support MAP_GUARD?
>
>
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.


> ktrace snipet:
>   1072 qemu-arm-static CALL
> openat(AT_FDCWD,0xf4ff9020,0x30)
>   1072 qemu-arm-static NAMI  "/lib/libc.so.7"
>   1072 qemu-arm-static RET   openat 3
>   1072 qemu-arm-static CALL  fstat(0x3,0x7ffe9680)
>   1072 qemu-arm-static STRU  struct stat {dev=687931144, ino=192007,
> mode=0100444, nlink=1, uid=0, gid=0, rdev=1548632,
> atime=1498921861.605975000, mtime=1498921861.608547000,
> ctime=1498921861.609724000, birthtime=1498921861.605973000,
> size=1720888, blksize=32768, blocks=3456, flags=0x2 }
>   1072 qemu-arm-static RET   fstat 0
>   1072 qemu-arm-static CALL
> mmap(0xf4ff7000,0x1000,0x1,0x41012 PRIVATE|MAP_FIXED|MAP_ANON|MAP_PREFAULT_READ>,0x,0)
>   1072 qemu-arm-static RET   mmap 4110381056/0xf4ff7000
>   1072 qemu-arm-static CALL
> mmap(0xf4ff7000,0x1000,0x1,0x40012 PREFAULT_READ>,0x3,0)
>   1072 qemu-arm-static RET   mmap 4110381056/0xf4ff7000
>   1072 qemu-arm-static CALL
> mmap(0xf4e37000,0x1c,0,0x3010 MAP_ANON|MAP_GUARD>,0x,0)
>   1072 qemu-arm-static RET   mmap -1 errno 22 Invalid argument
>
> Thanks,
> Guy
> ___
> freebsd-current@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
>
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


running binary in chroot using qemu-arm-static fails to mmap after r320318

2017-07-01 Thread Guy Yur
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

rtld-elf only passes MAP_GUARD but ktrace shows mmap
is called with MAP_FIXED and MAP_ANON too.
I think qemu-user-static adds the flags in bsd-user/mmap.c target_mmap().
Does the qemu-user-static port need patching to support MAP_GUARD?

ktrace snipet:
  1072 qemu-arm-static CALL
openat(AT_FDCWD,0xf4ff9020,0x30)
  1072 qemu-arm-static NAMI  "/lib/libc.so.7"
  1072 qemu-arm-static RET   openat 3
  1072 qemu-arm-static CALL  fstat(0x3,0x7ffe9680)
  1072 qemu-arm-static STRU  struct stat {dev=687931144, ino=192007,
mode=0100444, nlink=1, uid=0, gid=0, rdev=1548632,
atime=1498921861.605975000, mtime=1498921861.608547000,
ctime=1498921861.609724000, birthtime=1498921861.605973000,
size=1720888, blksize=32768, blocks=3456, flags=0x2 }
  1072 qemu-arm-static RET   fstat 0
  1072 qemu-arm-static CALL
mmap(0xf4ff7000,0x1000,0x1,0x41012,0x,0)
  1072 qemu-arm-static RET   mmap 4110381056/0xf4ff7000
  1072 qemu-arm-static CALL
mmap(0xf4ff7000,0x1000,0x1,0x40012,0x3,0)
  1072 qemu-arm-static RET   mmap 4110381056/0xf4ff7000
  1072 qemu-arm-static CALL
mmap(0xf4e37000,0x1c,0,0x3010,0x,0)
  1072 qemu-arm-static RET   mmap -1 errno 22 Invalid argument

Thanks,
Guy
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"