Re: [PATCH v2 1/1] target/ppc: don't byte swap ELFv2 signal handler
On Wed, Mar 18, 2020 at 12:01:16PM -0500, Vincent Fazio wrote: > From: Vincent Fazio > > Previously, the signal handler would be byte swapped if the target and > host CPU used different endianness. This would cause a SIGSEGV when > attempting to translate the opcode pointed to by the swapped address. > > Thread 1 "qemu-ppc64" received signal SIGSEGV, Segmentation fault. > 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:351 > 351__builtin_memcpy(, ptr, sizeof(r)); > > #0 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:351 > #1 0x600a92fe in ldl_be_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:449 > #2 0x600c0790 in translator_ldl_swap at > qemu/include/exec/translator.h:201 > #3 0x6011c1ab in ppc_tr_translate_insn at > qemu/target/ppc/translate.c:7856 > #4 0x6005ae70 in translator_loop at qemu/accel/tcg/translator.c:102 > > Now, no swap is performed and execution continues properly. Patch is good, but the message still needs some work. It should point out that the necessary swap is already done at sigaction() time by the __get_user(). > > Signed-off-by: Vincent Fazio > Reviewed-by: Laurent Vivier > --- > Changes since v1: > - Drop host/target endianness callouts > - Drop unnecessary pointer cast > - Clarify commit message > > linux-user/ppc/signal.c | 6 ++ > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c > index 5b82af6cb6..b8613c5e1b 100644 > --- a/linux-user/ppc/signal.c > +++ b/linux-user/ppc/signal.c > @@ -567,10 +567,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, > env->nip = tswapl(handler->entry); > env->gpr[2] = tswapl(handler->toc); > } else { > -/* ELFv2 PPC64 function pointers are entry points, but R12 > - * must also be set */ > -env->nip = tswapl((target_ulong) ka->_sa_handler); > -env->gpr[12] = env->nip; > +/* ELFv2 PPC64 function pointers are entry points. R12 must also be > set. */ > +env->gpr[12] = env->nip = ka->_sa_handler; > } > #else > env->nip = (target_ulong) ka->_sa_handler; -- David Gibson| I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson signature.asc Description: PGP signature
Re: [PATCH v2 1/1] target/ppc: don't byte swap ELFv2 signal handler
On 3/18/20 10:01 AM, Vincent Fazio wrote: > From: Vincent Fazio > > Previously, the signal handler would be byte swapped if the target and > host CPU used different endianness. This would cause a SIGSEGV when > attempting to translate the opcode pointed to by the swapped address. > > Thread 1 "qemu-ppc64" received signal SIGSEGV, Segmentation fault. > 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:351 > 351__builtin_memcpy(, ptr, sizeof(r)); > > #0 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:351 > #1 0x600a92fe in ldl_be_p (ptr=0x4c2c0610) at > qemu/include/qemu/bswap.h:449 > #2 0x600c0790 in translator_ldl_swap at > qemu/include/exec/translator.h:201 > #3 0x6011c1ab in ppc_tr_translate_insn at > qemu/target/ppc/translate.c:7856 > #4 0x6005ae70 in translator_loop at qemu/accel/tcg/translator.c:102 > > Now, no swap is performed and execution continues properly. > > Signed-off-by: Vincent Fazio > Reviewed-by: Laurent Vivier > --- > Changes since v1: > - Drop host/target endianness callouts > - Drop unnecessary pointer cast > - Clarify commit message Reviewed-by: Richard Henderson r~
[PATCH v2 1/1] target/ppc: don't byte swap ELFv2 signal handler
From: Vincent Fazio Previously, the signal handler would be byte swapped if the target and host CPU used different endianness. This would cause a SIGSEGV when attempting to translate the opcode pointed to by the swapped address. Thread 1 "qemu-ppc64" received signal SIGSEGV, Segmentation fault. 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at qemu/include/qemu/bswap.h:351 351__builtin_memcpy(, ptr, sizeof(r)); #0 0x600a9257 in ldl_he_p (ptr=0x4c2c0610) at qemu/include/qemu/bswap.h:351 #1 0x600a92fe in ldl_be_p (ptr=0x4c2c0610) at qemu/include/qemu/bswap.h:449 #2 0x600c0790 in translator_ldl_swap at qemu/include/exec/translator.h:201 #3 0x6011c1ab in ppc_tr_translate_insn at qemu/target/ppc/translate.c:7856 #4 0x6005ae70 in translator_loop at qemu/accel/tcg/translator.c:102 Now, no swap is performed and execution continues properly. Signed-off-by: Vincent Fazio Reviewed-by: Laurent Vivier --- Changes since v1: - Drop host/target endianness callouts - Drop unnecessary pointer cast - Clarify commit message linux-user/ppc/signal.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index 5b82af6cb6..b8613c5e1b 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -567,10 +567,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->nip = tswapl(handler->entry); env->gpr[2] = tswapl(handler->toc); } else { -/* ELFv2 PPC64 function pointers are entry points, but R12 - * must also be set */ -env->nip = tswapl((target_ulong) ka->_sa_handler); -env->gpr[12] = env->nip; +/* ELFv2 PPC64 function pointers are entry points. R12 must also be set. */ +env->gpr[12] = env->nip = ka->_sa_handler; } #else env->nip = (target_ulong) ka->_sa_handler; -- 2.25.1