From: Laurent Vivier <laurent@vivier.eu>
To: Michael Vogt <mvogt@redhat.com>, qemu-devel@nongnu.org
Cc: Michael Vogt <michael.vogt@gmail.com>,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH v7 2/2] linux-user: add strace support for openat2
Date: Sat, 28 Sep 2024 12:40:00 +0200 [thread overview]
Message-ID: <09a456b8-b8e4-4cf4-af4b-bb79f7b1bfb5@vivier.eu> (raw)
In-Reply-To: <dba054de9c2285aa0908cae22ede2c082ed5af7c.1727119903.git.mvogt@redhat.com>
Le 23/09/2024 à 21:37, Michael Vogt a écrit :
> This commit adds support for the `openat2()` to `QEMU_STRACE`. It
> will use the `openat2.h` header if available to create user
> readable flags for the `resolve` argument but does not require
> the header otherwise.
>
> It also makes `copy_struct_from_user()` available via `qemu.h`
> and `open_how_ver0` via `syscall_defs.h` so that strace.c can use
> them.
>
> Signed-off-by: Michael Vogt <mvogt@redhat.com>
> ---
> linux-user/qemu.h | 9 +++++++++
> linux-user/strace.c | 40 +++++++++++++++++++++++++++++++++++++++
> linux-user/strace.list | 3 +++
> linux-user/syscall.c | 8 +-------
> linux-user/syscall_defs.h | 5 +++++
> meson.build | 1 +
> 6 files changed, 59 insertions(+), 7 deletions(-)
>
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 2e90a97175..98ad848ab2 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -313,6 +313,15 @@ static inline bool access_ok(CPUState *cpu, int type,
> int copy_from_user(void *hptr, abi_ulong gaddr, ssize_t len);
> int copy_to_user(abi_ulong gaddr, void *hptr, ssize_t len);
>
> +/*
> + * copy_struct_from_user() copies a target struct to a host struct, in
> + * a way that guarantees backwards-compatibility for struct syscall
> + * arguments.
> + *
> + * Similar to kernels uaccess.h:copy_struct_from_user()
> + */
> +int copy_struct_from_user(void *dst, size_t ksize, abi_ptr src, size_t usize);
> +
> /* Functions for accessing guest memory. The tget and tput functions
> read/write single values, byteswapping as necessary. The lock_user function
> gets a pointer to a contiguous area of guest memory, but does not perform
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index b4d1098170..77d5108e5d 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -13,6 +13,9 @@
> #include <linux/if_packet.h>
> #include <linux/in6.h>
> #include <linux/netlink.h>
> +#ifdef HAVE_OPENAT2_H
> +#include <linux/openat2.h>
> +#endif
> #include <sched.h>
> #include "qemu.h"
> #include "user-internals.h"
> @@ -1063,6 +1066,18 @@ UNUSED static const struct flags open_flags[] = {
> FLAG_END,
> };
>
> +UNUSED static const struct flags openat2_resolve_flags[] = {
> +#ifdef HAVE_OPENAT2_H
> + FLAG_GENERIC(RESOLVE_NO_XDEV),
> + FLAG_GENERIC(RESOLVE_NO_MAGICLINKS),
> + FLAG_GENERIC(RESOLVE_NO_SYMLINKS),
> + FLAG_GENERIC(RESOLVE_BENEATH),
> + FLAG_GENERIC(RESOLVE_IN_ROOT),
> + FLAG_GENERIC(RESOLVE_CACHED),
> +#endif
> + FLAG_END,
> +};
> +
> UNUSED static const struct flags mount_flags[] = {
> #ifdef MS_BIND
> FLAG_GENERIC(MS_BIND),
> @@ -3483,6 +3498,31 @@ print_openat(CPUArchState *cpu_env, const struct syscallname *name,
> }
> #endif
>
> +#ifdef TARGET_NR_openat2
> +static void
> +print_openat2(CPUArchState *cpu_env, const struct syscallname *name,
> + abi_long arg0, abi_long arg1, abi_long arg2,
> + abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> + struct open_how_ver0 how = {0};
> +
> + print_syscall_prologue(name);
> + print_at_dirfd(arg0, 0);
> + print_string(arg1, 0);
> + if (copy_struct_from_user(&how, sizeof(how), arg2, arg3) == 0) {
I think you need also to tswap64() all the fields of how.
> + print_open_flags(how.flags, 0);
> + if (how.flags & TARGET_O_CREAT) {
> + print_file_mode(how.mode, 0);
> + }
> + print_flags(openat2_resolve_flags, how.resolve, 0);
> + } else {
> + print_pointer(arg2, 0);
> + }
> + print_raw_param("size=" TARGET_ABI_FMT_lu, arg3, 1);
Why the "size="?
You can write: print_raw_param(TARGET_ABI_FMT_lu, arg3, 1);
Thanks,
Laurent
prev parent reply other threads:[~2024-09-28 10:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 19:37 [PATCH v7 0/2] linux-user: add openat2 support in linux-user Michael Vogt
2024-09-23 19:37 ` [PATCH v7 1/2] " Michael Vogt
2024-09-28 10:45 ` Laurent Vivier
2024-09-23 19:37 ` [PATCH v7 2/2] linux-user: add strace support for openat2 Michael Vogt
2024-09-28 10:40 ` Laurent Vivier [this message]
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=09a456b8-b8e4-4cf4-af4b-bb79f7b1bfb5@vivier.eu \
--to=laurent@vivier.eu \
--cc=michael.vogt@gmail.com \
--cc=mvogt@redhat.com \
--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).