From owner-freebsd-current@freebsd.org Wed Jul 5 19:30:47 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CDCDAD8F49F for ; Wed, 5 Jul 2017 19:30:47 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pp2.rice.edu (proofpoint2.mail.rice.edu [128.42.201.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8656968DD3; Wed, 5 Jul 2017 19:30:46 +0000 (UTC) (envelope-from alc@rice.edu) Received: from pps.filterd (pp2.rice.edu [127.0.0.1]) by pp2.rice.edu (8.16.0.17/8.16.0.17) with SMTP id v65Hm3na031330; Wed, 5 Jul 2017 14:30:40 -0500 Received: from mh3.mail.rice.edu (mh3.mail.rice.edu [128.42.199.10]) by pp2.rice.edu with ESMTP id 2be6sj984f-1; Wed, 05 Jul 2017 14:30:40 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh3.mail.rice.edu, auth channel Received: from 108-254-203-201.lightspeed.hstntx.sbcglobal.net (108-254-203-201.lightspeed.hstntx.sbcglobal.net [108.254.203.201]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) (Authenticated sender: alc) by mh3.mail.rice.edu (Postfix) with ESMTPSA id 56B9840456; Wed, 5 Jul 2017 14:30:39 -0500 (CDT) Subject: Re: emulators/qemu-user-static needs MAP_GUARD support To: Guy Yur , alc@freebsd.org Cc: freebsd-current , kib@freebsd.org, Sean Bruno References: From: Alan Cox Message-ID: Date: Wed, 5 Jul 2017 14:30:38 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD i386; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611190142 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Jul 2017 19:30:47 -0000 On 07/05/2017 13:47, Guy Yur wrote: > Hi Alan, > > On 1 July 2017 at 23:07, Alan Cox wrote: >> 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 >>> >>> ... 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 >