From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Helge Deller <deller@gmx.de>
Cc: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
Richard Henderson <richard.henderson@linaro.org>,
Laurent Vivier <laurent@vivier.eu>,
qemu-arm@nongnu.org
Subject: Re: [PATCH 1/2] linux-user: Fix openat() emulation to correctly detect accesses to /proc
Date: Tue, 1 Aug 2023 22:27:03 +0100 [thread overview]
Message-ID: <ZMl4p2oLv9vhGfAV@redhat.com> (raw)
In-Reply-To: <20230801191035.374120-2-deller@gmx.de>
On Tue, Aug 01, 2023 at 09:10:34PM +0200, Helge Deller wrote:
> In qemu we catch accesses to files like /proc/cpuinfo or /proc/net/route
> and return to the guest contents which would be visible on a real system
> (instead what the host would show).
>
> This patch fixes a bug, where for example the accesses
> cat /proc////cpuinfo
> or
> cd /proc && cat cpuinfo
> will not be recognized by qemu and where qemu will wrongly show
> the contents of the host's /proc/cpuinfo file.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
>
> --
> v2:
> - use g_autofree instead of pathname on stack
> Daniel P. Berrangé requested to not put buffers on stack.
> Using g_autofree keeps code much cleaner than using
> extended semantics of realpath(), unless I can use g_autofree
> on malloced area from realpath().
g_autofree is backed by free(), so it is fine to use that
with the realpath() allocated buffer.
> ---
> linux-user/syscall.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 95727a816a..a089463969 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -8539,9 +8539,12 @@ static int open_hardware(CPUArchState *cpu_env, int fd)
> }
> #endif
>
> -int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname,
> +
> +int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *fname,
> int flags, mode_t mode, bool safe)
> {
> + g_autofree char *proc_name = g_new(char, PATH_MAX);
> + const char *pathname;
> struct fake_open {
> const char *filename;
> int (*fill)(CPUArchState *cpu_env, int fd);
> @@ -8567,6 +8570,13 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname,
> { NULL, NULL, NULL }
> };
>
> + /* if this is a file from /proc/ filesystem, expand full name */
> + if (realpath(fname, proc_name) && strncmp(proc_name, "/proc/", 6) == 0) {
> + pathname = proc_name;
> + } else {
> + pathname = fname;
> + }
> +
> if (is_proc_myself(pathname, "exe")) {
> if (safe) {
> return safe_openat(dirfd, exec_path, flags, mode);
> --
> 2.41.0
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-08-01 21:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 19:10 [PATCH 0/2] linux-user: /proc/cpuinfo fix and content emulation for arm Helge Deller
2023-08-01 19:10 ` [PATCH 1/2] linux-user: Fix openat() emulation to correctly detect accesses to /proc Helge Deller
2023-08-01 21:27 ` Daniel P. Berrangé [this message]
2023-08-01 19:10 ` [PATCH 2/2] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Helge Deller
2023-08-01 19:22 ` 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=ZMl4p2oLv9vhGfAV@redhat.com \
--to=berrange@redhat.com \
--cc=deller@gmx.de \
--cc=laurent@vivier.eu \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--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).