While using qemu-mips-static to build packages for MIPS32 platform, I have found the following problem: 1) mmap(2) system call returns NULL (0) instead of MAP_FAILED (-1) when len==0. 2) install(1) system utility tries to use mmap() to read source file if it resides on UFS of CD9660 file system and its size is less than 8 megabytes 3) install checks for MAP_FAILED mmap result but not for NULL. Then is passes NULL pointer to write(2) system call and it fails with EFAULT, breaking install(1). 4) print/texinfo is needed to build gmake using HEAD world and texinfo calls install(1) for zero length file. So, install fails and package build fails. How-to-Repeat: use UFS and command "touch file && install file newfile" using qemu-mips-static
Another note: problem does not crop up using nullfs-mounted file systems. And it does not exist for FreeBSD running real MIPS32 hardware.
Eugene: Hey, I forgot about this one. Did you look into my github branch (that's where this package comes from) to send a pull request? https://github.com/seanbruno/qemu-bsd-user/tree/bsd-user
(In reply to Sean Bruno from comment #2) Not sure I understand you quite right. I have no solution for pull request.
(In reply to eugen from comment #3) ah, ok. I thought you knew what code was broken. I'll add this to my "TODO" list for 2016.
Created attachment 164821 [details] return -1 when len is zero Can you try the attached patch? We should probably do the same for target_mprotect [1], ie return -1? [1] https://github.com/seanbruno/qemu-bsd-user/blob/master/bsd-user/mmap.c#L99
(In reply to mikael.urankar from comment #5) I've just put this patch to /usr/ports/emulators/qemu-sbruno/files/patch-bsd-user_mmap.c and verified that it is applied cleanly while building emulators/qemu-user-static port. However, running mips32 world with updated /usr/local/bin/qemu-mips-static binary does not fix the problem and this still fails: # chroot $dir /usr/local/bin/qemu-mips-static /bin/sh # touch file && install file newfile install: newfile: Bad address
(In reply to eugen from comment #6) Have you updated qemu in the jail?, ie something like cp -f /usr/ports/emulators/qemu-user-static/work/stage/usr/local/bin/qemu-arm-static /data/jails/11armv6/usr/local/bin/qemu-arm-static
(In reply to mikael.urankar from comment #5) Nevermind, I've just realized that I forgot to update qemu-mips-static binary located inside chroot directory and was running old one. With new one, the problem disappeared, so the patch does work. As for mprotect, I am not sure. For mmap(2), manual page clearly states what len==0 case should return MAP_FAILED (1) and errno==EINVAL. For mprotect, this error is should be returned only if "The virtual address range specified by the addr and len arguments is not valid."
Works for the same issue on armv6 for me too. Thanks a lot! Chris
A commit references this bug: Author: sbruno Date: Mon Jan 4 18:26:26 UTC 2016 New revision: 405260 URL: https://svnweb.freebsd.org/changeset/ports/405260 Log: Bump to 2.5.50.g20160103, catchup with latest bug fixes. Fix dereference of wrong pointer arg in ipc/semctl syscall. Fix return from mmap() to setEINVAL and MAP_FAILED when len is 0 PR: 203852 200613 Submitted by: mikael.urankar@gmail.com Changes: head/emulators/qemu-sbruno/Makefile head/emulators/qemu-sbruno/distinfo