Received: by 2002:ac2:5978:0:0:0:0:0 with SMTP id h24csp1701485lfp; Thu, 7 Oct 2021 11:59:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjoldiAIrXR+sspKyH1fBVcWx3MovVryArAUYV4EgpMmWzhbeGf5jrU6N/ZSqpxUPLMlrZ X-Received: by 2002:a05:600c:35d0:: with SMTP id r16mr6512776wmq.26.1633633145731; Thu, 07 Oct 2021 11:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633633145; cv=none; d=google.com; s=arc-20160816; b=b8CpUx6wFGBhHbtKvX99eyetBmcB93GnW1kZbBLcxVDTkD/FReI1JBPGYs6jp4994q vHLfPhDR36RyHO6XEbjXZGvq125ylw8wTZstTGFKP3W8Emi8htmNsYVS7LKzBiyCnuAo COhqvnY9JPj5adMifsGt1wrAI0udpf9lEgjizjFoY9mzYZzO7I+VaEFr8GPrBlpK8MC5 0F6vMM72qdCfLtR9v3rhOf6Y8Oe/KVyviwUWt5CMpkGEJMx3ilYqIaKaDI/+eXEraofA DR7f95kzJwTBD9KRyHuYwwGsKDqT/ep/uKrFB6kMs2BzIu5bYmNbKVdl2iEATd3P2/1D ZepQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:subject:from:references:cc:to; bh=DK26kQ8uXvJG8era21IMQ9X2mtth7qBwuNiZCbegIAw=; b=dfHmHfLxB07/a4Ry/Dwg+oCo2S8Uet2Q6TrLMZeWZxJq6AwbbgVJeQWMv2kTUihENP sZGjj1329nEh2rBhSwa0LBBSiCO+U6+lOyPejCeygXVE5DovymCRNXOsXC7fxuBupFaj VQcUdOdDZwnrODF97ui/5supN3L0Cqoohdww7HTJQAZ1Zq68Awwqh19EH4P1Faty0gIo 6FoNeSGMM4m87rjiJh6qjnJWIZT6/x8ZGykxP81+olCc+VdHkC5NELCNTwn5ipOCz43i apSPeXyByZ7gvK4zVHKFMVofxHNYTx4osS+Q18/+A/3UCMXfgn/byYI08pat3Q3i5m59 cigg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.72.192.73 is neither permitted nor denied by best guess record for domain of laurent@vivier.eu) smtp.mailfrom=laurent@vivier.eu Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de. [217.72.192.73]) by mx.google.com with ESMTPS id c2si325666wrd.507.2021.10.07.11.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:59:05 -0700 (PDT) Received-SPF: neutral (google.com: 217.72.192.73 is neither permitted nor denied by best guess record for domain of laurent@vivier.eu) client-ip=217.72.192.73; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.72.192.73 is neither permitted nor denied by best guess record for domain of laurent@vivier.eu) smtp.mailfrom=laurent@vivier.eu Received: from [192.168.100.1] ([82.142.3.114]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.119]) with ESMTPSA (Nemesis) id 1N1Oft-1mw2V21q8p-012nGx; Thu, 07 Oct 2021 20:59:03 +0200 To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Richard Henderson Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, assad.hashmi@linaro.org, "Eric W. Biederman" , James Bottomley , Arnd Bergmann References: <877deoevj8.fsf@linaro.org> From: Laurent Vivier Subject: Re: Approaches for same-on-same linux-user execve? Message-ID: Date: Thu, 7 Oct 2021 20:59:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <877deoevj8.fsf@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:D7ZWfmsf4Dm+3g3vz8Hi00yHHRP7z53LkHrfGGKk/KtPfyZu8eD O4jC4X9KeE0XCU0h6Vj+zyHh0/HNIPfmMxSxoZllTvUH2hFTHy5LxSkcWRJWTl2eOgCEKCQ Ra9Z+pSg5veKnfFCBC+F4+NwKNjuQkQ2bKmdfzpOEjh/Ns/4Ci5zsfGSt0T64PMoc4tZSog Qn3voLVHmGwLCR/MuSA/w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:nLovi1u1NII=:OzfrnMsdyUFtYHzV/pVcx3 Zl2lM+wdAym2VDadmpJSxr4JH2f6TeuXXJmQcet1vzg99Ld2JkF7lWYJ+3EoZosxswOdHaPZ0 wqkADAthyXKxw4rFZJ2zBsuQfH4s91AkBOs8Pcx77Sh5i0DcrHpn3V9EPQqXGTgixtR2I1XB2 VD/AlK6U7pezvfTOzPopY/gEQ44MLjElIimXMCuVjhV0U17AugDg3LZ+tFsGPnERjQyurRabB 960VaBD29l1dHfVJksAmkLCfkzlLDVH8U+oyl4kpn8ru2BMR8fjQyS7nnr4x68KE6iUgyn7cy WE2DvDFh61YGkrOxdcHrXqonBYLlbUR2+t93t0bTrq8IlzxqhCxijzamOT9R0tVDK/PE9zxzU Nqz80OYm1pTNE8akRfk5qMnWOFv7Qff4rjFyfzSOD2Eu/pLFMijRjgpqoGzfs5hD6I0k6nQZ9 9gAiSv9Qi3Z8U2RD54r0MDq+oTah1X4doQTEy6BChglrxPcD+uUY5A+Y3QZMMGQKfNORTdP1P ZPzncGiQtfIWkKXkkm8dRXwWQJuBjGUm1vm1D4go+E964cU6b3j3UPWYmqbsKoSMKHNHe9d/A DRI5JzyLGA5bmBurD5tf4zhCQj34SUtJMztjSIqmC08SEdDWeM49yz44dZYJbUoZpyfZQXatD YuV62YYuErJkS864mUHFSOGEPSjTnPF+CzdNChhvizUjp2TCB6hkiJuFgOYRnAw3IAukUzb16 4vGa8TX/SvdALQtHR8lxgFBe7hK7CqJEayPvFw== X-TUID: OFXd25FLSChK Le 07/10/2021 à 16:32, Alex Bennée a écrit : > Hi, > > I came across a use-case this week for ARM although this may be also > applicable to architectures where QEMU's emulation is ahead of the > hardware currently widely available - for example if you want to > exercise SVE code on AArch64. When the linux-user architecture is not > the same as the host architecture then binfmt_misc works perfectly fine. > > However in the case you are running same-on-same you can't use > binfmt_misc to redirect execution to using QEMU because any attempt to > trap native binaries will cause your userspace to hang as binfmt_misc > will be invoked to run the QEMU binary needed to run your application > and a deadlock ensues. > > There are some hacks you can apply at a local level like tweaking the > elf header of the binaries you want to run under emulation and adjusting > the binfmt_mask appropriately. This works but is messy and a faff to > set-up. > > An ideal setup would be would be for the kernel to catch a SIGILL from a > failing user space program and then to re-launch the process using QEMU > with the old processes maps and execution state so it could continue. > However I suspect there are enough moving parts to make this very > fragile (e.g. what happens to the results of library feature probing > code). So two approaches I can think of are: > > Trap execve in QEMU linux-user > ------------------------------ > > We could add a flag to QEMU so at the point of execve it manually > invokes the new process with QEMU, passing on the flag to persist this > behaviour. Another approach can be to use ptrace(PTRACE_SYSEMU) to catch syscalls. We need a wrapper that loads the first target binary and fork, it attach a ptrace() process and intercept the syscalls to emulate them as we do in usermode linux. I was thinking to this solution for instance to execute big-endian program (like ppc64) on little-endian system (ppc64le). But I'm not sure it fits in what you need... > > Add path mask to binfmt_misc > ---------------------------- > > The other option would be to extend binfmt_misc to have a path mask so > it only applies it's alternative execution scheme to binaries in a > particular section of the file-system (or maybe some sort of pattern?). > > Are there any other approaches you could take? Which do you think has > the most merit? I don't know if it can apply to what you want, but I wrote years ago a binfmt namespace that applies binfmt configuration only on a container but I didn't finish the work (it seems there can be some security issues in what I did): https://lore.kernel.org/lkml/20191216091220.465626-2-laurent@vivier.eu/T/ Thanks, Laurent