From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
"Rainer Müller" <raimue@codingfarm.de>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: [PULL 3/3] linux-user: Use memfd for open syscall emulation
Date: Wed, 3 Aug 2022 16:56:13 +0200 [thread overview]
Message-ID: <20220803145613.428167-4-laurent@vivier.eu> (raw)
In-Reply-To: <20220803145613.428167-1-laurent@vivier.eu>
From: Rainer Müller <raimue@codingfarm.de>
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üller <raimue@codingfarm.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220729154951.76268-1-raimue@codingfarm.de>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
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 dirfd, const char *pathname, int
char filename[PATH_MAX];
int fd, r;
- /* create temporary file to map stat to */
- tmpdir = getenv("TMPDIR");
- if (!tmpdir)
- tmpdir = "/tmp";
- snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
- fd = mkstemp(filename);
+ fd = memfd_create("qemu-open", 0);
if (fd < 0) {
- return fd;
+ if (errno != ENOSYS) {
+ return fd;
+ }
+ /* create temporary file to map stat to */
+ tmpdir = getenv("TMPDIR");
+ if (!tmpdir)
+ tmpdir = "/tmp";
+ snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
+ fd = mkstemp(filename);
+ if (fd < 0) {
+ return fd;
+ }
+ unlink(filename);
}
- unlink(filename);
if ((r = fake_open->fill(cpu_env, fd))) {
int e = errno;
--
2.37.1
next prev parent reply other threads:[~2022-08-03 15:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 14:56 [PULL 0/3] Linux user for 7.1 patches Laurent Vivier
2022-08-03 14:56 ` [PULL 1/3] linux-user/flatload.c: Fix setting of image_info::end_code Laurent Vivier
2022-08-03 14:56 ` [PULL 2/3] linux-user: Do not treat madvise()'s advice as a bitmask Laurent Vivier
2022-08-03 14:56 ` Laurent Vivier [this message]
2022-08-03 17:12 ` [PULL 0/3] Linux user for 7.1 patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220803145613.428167-4-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=raimue@codingfarm.de \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).