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 <rai...@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 if ((r = fake_open->fill(cpu_env, fd))) { int e = errno; -- 2.25.1