diff mbox

[v2,19/19] linux-user: Avoid possible misalignment in target_to_host_siginfo()

Message ID 1464360721-14359-20-git-send-email-peter.maydell@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Maydell May 27, 2016, 2:52 p.m. UTC
Reimplement target_to_host_siginfo() to use __get_user(), which
handles possibly misaligned source guest structures correctly.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 linux-user/signal.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Laurent Vivier June 7, 2016, 7:40 p.m. UTC | #1
Le 27/05/2016 à 16:52, Peter Maydell a écrit :
> Reimplement target_to_host_siginfo() to use __get_user(), which
> handles possibly misaligned source guest structures correctly.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

> ---
>  linux-user/signal.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 7e2a80f..8417da7 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -409,13 +409,18 @@ void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info)
>  /* XXX: find a solution for 64 bit (additional malloced data is needed) */
>  void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo)
>  {
> -    info->si_signo = tswap32(tinfo->si_signo);
> -    info->si_errno = tswap32(tinfo->si_errno);
> -    info->si_code = tswap32(tinfo->si_code);
> -    info->si_pid = tswap32(tinfo->_sifields._rt._pid);
> -    info->si_uid = tswap32(tinfo->_sifields._rt._uid);
> -    info->si_value.sival_ptr =
> -            (void *)(long)tswapal(tinfo->_sifields._rt._sigval.sival_ptr);
> +    /* This conversion is used only for the rt_sigqueueinfo syscall,
> +     * and so we know that the _rt fields are the valid ones.
> +     */
> +    abi_ulong sival_ptr;
> +
> +    __get_user(info->si_signo, &tinfo->si_signo);
> +    __get_user(info->si_errno, &tinfo->si_errno);
> +    __get_user(info->si_code, &tinfo->si_code);
> +    __get_user(info->si_pid, &tinfo->_sifields._rt._pid);
> +    __get_user(info->si_uid, &tinfo->_sifields._rt._uid);
> +    __get_user(sival_ptr, &tinfo->_sifields._rt._sigval.sival_ptr);
> +    info->si_value.sival_ptr = (void *)(long)sival_ptr;
>  }
>  
>  static int fatal_signal (int sig)
>
diff mbox

Patch

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 7e2a80f..8417da7 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -409,13 +409,18 @@  void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info)
 /* XXX: find a solution for 64 bit (additional malloced data is needed) */
 void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo)
 {
-    info->si_signo = tswap32(tinfo->si_signo);
-    info->si_errno = tswap32(tinfo->si_errno);
-    info->si_code = tswap32(tinfo->si_code);
-    info->si_pid = tswap32(tinfo->_sifields._rt._pid);
-    info->si_uid = tswap32(tinfo->_sifields._rt._uid);
-    info->si_value.sival_ptr =
-            (void *)(long)tswapal(tinfo->_sifields._rt._sigval.sival_ptr);
+    /* This conversion is used only for the rt_sigqueueinfo syscall,
+     * and so we know that the _rt fields are the valid ones.
+     */
+    abi_ulong sival_ptr;
+
+    __get_user(info->si_signo, &tinfo->si_signo);
+    __get_user(info->si_errno, &tinfo->si_errno);
+    __get_user(info->si_code, &tinfo->si_code);
+    __get_user(info->si_pid, &tinfo->_sifields._rt._pid);
+    __get_user(info->si_uid, &tinfo->_sifields._rt._uid);
+    __get_user(sival_ptr, &tinfo->_sifields._rt._sigval.sival_ptr);
+    info->si_value.sival_ptr = (void *)(long)sival_ptr;
 }
 
 static int fatal_signal (int sig)