From nobody Thu May 16 19:22:18 2024 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 1658767188628619.7383072423335; Mon, 25 Jul 2022 09:39:48 -0700 (PDT) Received: from localhost ([::1]:36002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oG17S-0002XF-BF for importer@patchew.org; Mon, 25 Jul 2022 12:39:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oG137-00016P-Bv for qemu-devel@nongnu.org; Mon, 25 Jul 2022 12:35:18 -0400 Received: from donkey.codingfarm.de ([2a01:4f8:190:12cf::d:1]:60942) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oG133-0007mU-EX for qemu-devel@nongnu.org; Mon, 25 Jul 2022 12:35:15 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by donkey.codingfarm.de (Postfix) with ESMTPSA id 6D5AB802E3; Mon, 25 Jul 2022 18:28:11 +0200 (CEST) Received: by zebra.codingfarm.de (Postfix, from userid 1000) id 25CF540CC0; Mon, 25 Jul 2022 18:28:11 +0200 (CEST) From: =?UTF-8?q?Rainer=20M=C3=BCller?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Rainer=20M=C3=BCller?= , Laurent Vivier Subject: [PATCH] linux-user: Use memfd for open syscall emulation Date: Mon, 25 Jul 2022 18:28:11 +0200 Message-Id: <20220725162811.87985-1-raimue@codingfarm.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a01:4f8:190:12cf::d:1; envelope-from=raimue@zebra.codingfarm.de; helo=donkey.codingfarm.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, NO_DNS_FOR_FROM=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1658767190506100001 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 --- linux-user/syscall.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 991b85e6b4..3e4af930ad 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8265,9 +8265,11 @@ static int do_openat(CPUArchState *cpu_env, int dirf= d, const char *pathname, int } =20 if (fake_open->filename) { + int fd, r; + +#ifndef CONFIG_MEMFD const char *tmpdir; char filename[PATH_MAX]; - int fd, r; =20 /* create temporary file to map stat to */ tmpdir =3D getenv("TMPDIR"); @@ -8279,6 +8281,12 @@ static int do_openat(CPUArchState *cpu_env, int dirf= d, const char *pathname, int return fd; } unlink(filename); +#else + fd =3D memfd_create("qemu-open", 0); + if (fd < 0) { + return fd; + } +#endif =20 if ((r =3D fake_open->fill(cpu_env, fd))) { int e =3D errno; --=20 2.25.1