* [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall
@ 2017-12-15 15:18 Peter Maydell
2017-12-15 15:57 ` Laurent Vivier
2018-01-19 16:33 ` Laurent Vivier
0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2017-12-15 15:18 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier, Bruno Haible
The third argument to dup3() is a flags word which may be
O_CLOEXEC. We weren't translating this flag from target to
host value, which meant that if the target used a different
value from the host (eg sparc guest and x86 host) the dup3()
call would fail EINVAL. Do the correct translation.
Fixes: https://bugs.launchpad.net/qemu/+bug/1704658
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
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 39553c8..41ded90 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8490,11 +8490,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#endif
#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
case TARGET_NR_dup3:
- ret = get_errno(dup3(arg1, arg2, arg3));
+ {
+ int host_flags;
+
+ if ((arg3 & ~TARGET_O_CLOEXEC) != 0) {
+ return -EINVAL;
+ }
+ host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
+ ret = get_errno(dup3(arg1, arg2, host_flags));
if (ret >= 0) {
fd_trans_dup(arg1, arg2);
}
break;
+ }
#endif
#ifdef TARGET_NR_getppid /* not on alpha */
case TARGET_NR_getppid:
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall
2017-12-15 15:18 [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall Peter Maydell
@ 2017-12-15 15:57 ` Laurent Vivier
2018-01-19 16:33 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2017-12-15 15:57 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Riku Voipio, Bruno Haible
Le 15/12/2017 à 16:18, Peter Maydell a écrit :
> The third argument to dup3() is a flags word which may be
> O_CLOEXEC. We weren't translating this flag from target to
> host value, which meant that if the target used a different
> value from the host (eg sparc guest and x86 host) the dup3()
> call would fail EINVAL. Do the correct translation.
>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1704658
> Reported-by: Bruno Haible <bruno@clisp.org>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> linux-user/syscall.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall
2017-12-15 15:18 [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall Peter Maydell
2017-12-15 15:57 ` Laurent Vivier
@ 2018-01-19 16:33 ` Laurent Vivier
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2018-01-19 16:33 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Riku Voipio, Bruno Haible
Le 15/12/2017 à 16:18, Peter Maydell a écrit :
> The third argument to dup3() is a flags word which may be
> O_CLOEXEC. We weren't translating this flag from target to
> host value, which meant that if the target used a different
> value from the host (eg sparc guest and x86 host) the dup3()
> call would fail EINVAL. Do the correct translation.
>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1704658
> Reported-by: Bruno Haible <bruno@clisp.org>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> 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 39553c8..41ded90 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -8490,11 +8490,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
> #endif
> #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
> case TARGET_NR_dup3:
> - ret = get_errno(dup3(arg1, arg2, arg3));
> + {
> + int host_flags;
> +
> + if ((arg3 & ~TARGET_O_CLOEXEC) != 0) {
> + return -EINVAL;
> + }
> + host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
> + ret = get_errno(dup3(arg1, arg2, host_flags));
> if (ret >= 0) {
> fd_trans_dup(arg1, arg2);
> }
> break;
> + }
> #endif
> #ifdef TARGET_NR_getppid /* not on alpha */
> case TARGET_NR_getppid:
>
Applied to my linux-user branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-19 16:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-15 15:18 [Qemu-devel] [PATCH] linux-user: Translate flags argument to dup3 syscall Peter Maydell
2017-12-15 15:57 ` Laurent Vivier
2018-01-19 16:33 ` Laurent Vivier
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).