From nobody Tue Feb 10 13:17:12 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659538866421776.0106366897493; Wed, 3 Aug 2022 08:01:06 -0700 (PDT) Received: from localhost ([::1]:36490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJFrt-0002A2-CP for importer@patchew.org; Wed, 03 Aug 2022 11:01:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnK-0001n0-RR for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:37489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJFnI-0005r9-Lx for qemu-devel@nongnu.org; Wed, 03 Aug 2022 10:56:22 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MFK8N-1oCyPB33gP-00Flqs; Wed, 03 Aug 2022 16:56:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , =?UTF-8?q?Rainer=20M=C3=BCller?= , Richard Henderson Subject: [PULL 3/3] linux-user: Use memfd for open syscall emulation Date: Wed, 3 Aug 2022 16:56:13 +0200 Message-Id: <20220803145613.428167-4-laurent@vivier.eu> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220803145613.428167-1-laurent@vivier.eu> References: <20220803145613.428167-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-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ccPBPPmON2O3MKLkUeXcV/ky56w== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1659538867310100001 From: Rainer M=C3=BCller For certain paths in /proc, the open syscall is intercepted and the returned file descriptor points to a temporary file with emulated contents. If TMPDIR is not accessible or writable for the current user (for example in a read-only mounted chroot or container) tools such as ps from procps may fail unexpectedly. Trying to read one of these paths such as /proc/self/stat would return an error such as ENOENT or EROFS. To relax the requirement on a writable TMPDIR, use memfd_create() instead to create an anonymous file and return its file descriptor. Signed-off-by: Rainer M=C3=BCller Reviewed-by: Richard Henderson Message-Id: <20220729154951.76268-1-raimue@codingfarm.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b27a6552aa34..ef53feb5ab45 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8260,16 +8260,22 @@ static int do_openat(CPUArchState *cpu_env, int dir= fd, const char *pathname, int char filename[PATH_MAX]; int fd, r; =20 - /* create temporary file to map stat to */ - tmpdir =3D getenv("TMPDIR"); - if (!tmpdir) - tmpdir =3D "/tmp"; - snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir= ); - fd =3D mkstemp(filename); + fd =3D memfd_create("qemu-open", 0); if (fd < 0) { - return fd; + if (errno !=3D ENOSYS) { + return fd; + } + /* create temporary file to map stat to */ + tmpdir =3D getenv("TMPDIR"); + if (!tmpdir) + tmpdir =3D "/tmp"; + snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tm= pdir); + fd =3D mkstemp(filename); + if (fd < 0) { + return fd; + } + unlink(filename); } - unlink(filename); =20 if ((r =3D fake_open->fill(cpu_env, fd))) { int e =3D errno; --=20 2.37.1