From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57DB6C2BB48 for ; Tue, 8 Dec 2020 16:06:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C0B623B1F for ; Tue, 8 Dec 2020 16:06:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C0B623B1F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmfVd-0002Ja-CX for qemu-devel@archiver.kernel.org; Tue, 08 Dec 2020 11:06:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmfUU-0001hT-Ux for qemu-devel@nongnu.org; Tue, 08 Dec 2020 11:05:28 -0500 Received: from linux.microsoft.com ([13.77.154.182]:55730) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmfUP-00011z-Al for qemu-devel@nongnu.org; Tue, 08 Dec 2020 11:05:26 -0500 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by linux.microsoft.com (Postfix) with ESMTPSA id BA57920B717A for ; Tue, 8 Dec 2020 08:05:18 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BA57920B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607443518; bh=gLN6HN/AmcgWybrnwqgClPpFSfrI5CM9Pg8FkZnoAxA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hhFyKNrn4DLXjMKQ1AxjFnWBzShUregRzFWp9BhFu1ip1267hb/a+5HzWJXIrdjcz NQzbi4H2JJ1Yj1sAZe6djygBdBqh8Bd8qw4yderfTEy6nJLLGVu00+sAhGqhlhA6JN Yno0Fyr6yPXTEpePCva2mAYSRORWZksllyFYgC3Q= Received: by mail-pg1-f170.google.com with SMTP id e23so12535671pgk.12 for ; Tue, 08 Dec 2020 08:05:18 -0800 (PST) X-Gm-Message-State: AOAM530n9PjrFfrRy0fv9UEUaNnIg3YrVepgace3MskcTGbPFWcrNvZt RHg16IDcwyWQZo7mjN6OEoWFEzImM6sU8lpswDA= X-Google-Smtp-Source: ABdhPJySnXLHMkNi2PL7lETxkuEfnggRMvRcg7FmVsNo/Mu5k0meeTE1Qxn10Q9UqafEiCv1qmmT2Bg3ZWzNcp2OlmU= X-Received: by 2002:a63:ca0a:: with SMTP id n10mr23594905pgi.326.1607443518280; Tue, 08 Dec 2020 08:05:18 -0800 (PST) MIME-Version: 1.0 References: <20201208001727.17433-1-mcroce@linux.microsoft.com> In-Reply-To: From: Matteo Croce Date: Tue, 8 Dec 2020 17:04:42 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] linux-user: add option to chroot before emulation To: Laurent Vivier Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=13.77.154.182; envelope-from=mcroce@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -117 X-Spam_score: -11.8 X-Spam_bar: ----------- X-Spam_report: (-11.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tue, Dec 8, 2020 at 9:21 AM Laurent Vivier wrote: > > Le 08/12/2020 =C3=A0 01:17, Matteo Croce a =C3=A9crit : > > From: Matteo Croce > > > > Add a '-c' option which does a chroot() just before starting the > > emulation. This is useful when the static QEMU user binary can't > > be copied into the target root filesystem, e.g. if it's readonly. > > Did you try to use the binfmt_misc 'F' flag (fix binary)? > > https://www.kernel.org/doc/Documentation/admin-guide/binfmt-misc.rst > > ``F`` - fix binary > > The usual behaviour of binfmt_misc is to spawn the > binary lazily when the misc format file is invoked. However, > this doesn``t work very well in the face of mount namespaces and > changeroots, so the ``F`` mode opens the binary as soon as the > emulation is installed and uses the opened image to spawn the > emulator, meaning it is always available once installed, > regardless of how the environment changes. > > This can be configured with scripts/qemu-binfmt-conf.sh and > "--persistent yes"" option > Yes, this works too. Basically it's the same trick, open the binary early and then emulate. The only difference is that with binfmt emulation the procfs open still fails: # strace -feopenat chroot debian /bin/true 2>&1 |grep /proc/sys [pid 9359] openat(AT_FDCWD, "/proc/sys/vm/mmap_min_addr", O_RDONLY) =3D -1 ENOENT (No such file or directory) vs # strace -feopenat qemu-aarch64 -c debian /bin/true 2>&1 |grep /proc/sys [pid 9348] openat(AT_FDCWD, "/proc/sys/vm/mmap_min_addr", O_RDONLY) =3D 3 --=20 per aspera ad upstream