[PATCH] linux-user: fix incorrect alignment of pretcode

fanwj@mail.ustc.edu.cn posted 1 patch 11 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/7478fbcd.65885.188109d27f2.Coremail.fanwj@mail.ustc.edu.cn
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/i386/signal.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
[PATCH] linux-user: fix incorrect alignment of pretcode
Posted by fanwj@mail.ustc.edu.cn 11 months, 3 weeks ago
sigframe::pretcode & rt_sigframe::pretcode must align of 16n-sizeof(void*) instead of 16n, Because rsp align of 16n before instruction "call" in caller, After "call", push address of "call" in caller. sp of begin in callee is 16n-sizeof(void*)

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1648
Signed-off-by: Fan WenJie <fanwj@mail.ustc.edu.cn>

---
 linux-user/i386/signal.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
index 60fa07d6f9c..1f019689ae7 100644
--- a/linux-user/i386/signal.c
+++ b/linux-user/i386/signal.c
@@ -197,7 +197,8 @@ struct sigframe {
      * to it ensures that the base of the frame has an appropriate alignment
      * too.
      */
-    struct target_fpstate fpstate QEMU_ALIGNED(8);
+    abi_ulong unused QEMU_ALIGNED(8);
+    struct target_fpstate fpstate;
 };
 #define TARGET_SIGFRAME_FXSAVE_OFFSET (                                    \
     offsetof(struct sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET)
@@ -210,7 +211,8 @@ struct rt_sigframe {
     struct target_siginfo info;
     struct target_ucontext uc;
     char retcode[8];
-    struct target_fpstate fpstate QEMU_ALIGNED(8);
+    abi_ulong unused QEMU_ALIGNED(8);
+    struct target_fpstate fpstate;
 };
 #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET (                                 \
     offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET)
@@ -220,7 +222,8 @@ struct rt_sigframe {
     abi_ulong pretcode;
     struct target_ucontext uc;
     struct target_siginfo info;
-    struct target_fpstate fpstate QEMU_ALIGNED(16);
+    abi_ulong unused QEMU_ALIGNED(16);
+    struct target_fpstate fpstate;
 };
 #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET (                                 \
     offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET)
-- 
2.40.1
Re: [PATCH] linux-user: fix incorrect alignment of pretcode
Posted by Richard Henderson 11 months, 3 weeks ago
On 5/12/23 16:38, fanwj@mail.ustc.edu.cn wrote:
> sigframe::pretcode & rt_sigframe::pretcode must align of 16n-sizeof(void*) instead of 16n, Because rsp align of 16n before instruction "call" in caller, After "call", push address of "call" in caller. sp of begin in callee is 16n-sizeof(void*)
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1648
> Signed-off-by: Fan WenJie <fanwj@mail.ustc.edu.cn>
> 
> ---
>   linux-user/i386/signal.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
> index 60fa07d6f9c..1f019689ae7 100644
> --- a/linux-user/i386/signal.c
> +++ b/linux-user/i386/signal.c
> @@ -197,7 +197,8 @@ struct sigframe {
>        * to it ensures that the base of the frame has an appropriate alignment
>        * too.
>        */
> -    struct target_fpstate fpstate QEMU_ALIGNED(8);
> +    abi_ulong unused QEMU_ALIGNED(8);
> +    struct target_fpstate fpstate;
>   };

This is not the correct way to fix this problem.

You need to adjust get_sigframe(), for one, to give you the allocation desired.


r~