From: Richard Henderson <richard.henderson@linaro.org>
To: "Rainer Müller" <raimue@codingfarm.de>, qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH] linux-user: Use memfd for open syscall emulation
Date: Mon, 25 Jul 2022 11:37:54 -0700 [thread overview]
Message-ID: <bfaad452-fd69-3e79-787d-cec1de8d0147@linaro.org> (raw)
In-Reply-To: <20220725162811.87985-1-raimue@codingfarm.de>
On 7/25/22 09:28, Rainer Müller wrote:
> 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>
> ---
> 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 dirfd, const char *pathname, int
> }
>
> if (fake_open->filename) {
> + int fd, r;
> +
> +#ifndef CONFIG_MEMFD
> const char *tmpdir;
> char filename[PATH_MAX];
> - int fd, r;
>
> /* create temporary file to map stat to */
> tmpdir = getenv("TMPDIR");
> @@ -8279,6 +8281,12 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int
> return fd;
> }
> unlink(filename);
> +#else
> + fd = memfd_create("qemu-open", 0);
> + if (fd < 0) {
> + return fd;
> + }
> +#endif
Even without CONFIG_MEMFD, we will have the memfd_create function available in util/.
I think you should drop the ifdefs like so:
#include "qemu/memfd.h"
fd = memfd_create(...);
if (fd < 0) {
if (errno != ENOSYS) {
return fd;
}
// tmpdir fallback
}
r~
next prev parent reply other threads:[~2022-07-25 18:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 16:28 [PATCH] linux-user: Use memfd for open syscall emulation Rainer Müller
2022-07-25 18:37 ` Richard Henderson [this message]
2022-07-29 15:49 ` [PATCH v2] " Rainer Müller
2022-07-29 16:01 ` Richard Henderson
2022-07-29 21:19 ` Rainer Müller
2022-07-29 21:29 ` 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=bfaad452-fd69-3e79-787d-cec1de8d0147@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=raimue@codingfarm.de \
/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).