diff mbox

linux-user: Fix fault address truncation AArch64

Message ID 1412914976-15800-1-git-send-email-amanieu@gmail.com
State New
Headers show

Commit Message

Amanieu d'Antras Oct. 10, 2014, 4:22 a.m. UTC
On AArch64 the si_addr field of siginfo_t is truncated to 32 bits
because the fault address passes through an uint32_t variable. This
is fixed by changing the variable to uint64_t.

Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
---
 linux-user/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Claudio Fontana Oct. 10, 2014, 8:02 a.m. UTC | #1
Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>

On 10.10.2014 06:22, Amanieu d'Antras wrote:
> On AArch64 the si_addr field of siginfo_t is truncated to 32 bits
> because the fault address passes through an uint32_t variable. This
> is fixed by changing the variable to uint64_t.
> 
> Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
> ---
>  linux-user/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 483eb3f..d63e093 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -1006,7 +1006,7 @@ void cpu_loop(CPUARMState *env)
>      CPUState *cs = CPU(arm_env_get_cpu(env));
>      int trapnr, sig;
>      target_siginfo_t info;
> -    uint32_t addr;
> +    uint64_t addr;
>  
>      for (;;) {
>          cpu_exec_start(cs);
>
Peter Maydell Oct. 10, 2014, 11:32 a.m. UTC | #2
On 10 October 2014 05:22, Amanieu d'Antras <amanieu@gmail.com> wrote:
> On AArch64 the si_addr field of siginfo_t is truncated to 32 bits
> because the fault address passes through an uint32_t variable. This
> is fixed by changing the variable to uint64_t.
>
> Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
> ---
>  linux-user/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 483eb3f..d63e093 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -1006,7 +1006,7 @@ void cpu_loop(CPUARMState *env)
>      CPUState *cs = CPU(arm_env_get_cpu(env));
>      int trapnr, sig;
>      target_siginfo_t info;
> -    uint32_t addr;
> +    uint64_t addr;
>
>      for (;;) {
>          cpu_exec_start(cs);

Thanks for catching this. Better to fix it by dropping
the unnecessary local variable completely and just setting
  info._sifields._sigfault._addr = env->exception.vaddress;
at the only point where we currently use 'addr', though,
I think.

-- PMM
Claudio Fontana Oct. 10, 2014, 2:58 p.m. UTC | #3
On 10.10.2014 13:32, Peter Maydell wrote:
> On 10 October 2014 05:22, Amanieu d'Antras <amanieu@gmail.com> wrote:
>> On AArch64 the si_addr field of siginfo_t is truncated to 32 bits
>> because the fault address passes through an uint32_t variable. This
>> is fixed by changing the variable to uint64_t.
>>
>> Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
>> ---
>>  linux-user/main.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/linux-user/main.c b/linux-user/main.c
>> index 483eb3f..d63e093 100644
>> --- a/linux-user/main.c
>> +++ b/linux-user/main.c
>> @@ -1006,7 +1006,7 @@ void cpu_loop(CPUARMState *env)
>>      CPUState *cs = CPU(arm_env_get_cpu(env));
>>      int trapnr, sig;
>>      target_siginfo_t info;
>> -    uint32_t addr;
>> +    uint64_t addr;
>>
>>      for (;;) {
>>          cpu_exec_start(cs);
> 
> Thanks for catching this. Better to fix it by dropping
> the unnecessary local variable completely and just setting
>   info._sifields._sigfault._addr = env->exception.vaddress;
> at the only point where we currently use 'addr', though,
> I think.
> 
> -- PMM

We do use the name code pattern in most of the functions of that file,
meaning

uint32_t / uint64_t / target_ulong addr;

and then do_something_with_addr(addr);

Ciao,

Claudio
Peter Maydell Oct. 10, 2014, 3:30 p.m. UTC | #4
On 10 October 2014 15:58, Claudio Fontana <claudio.fontana@huawei.com> wrote:
> On 10.10.2014 13:32, Peter Maydell wrote:
>> Thanks for catching this. Better to fix it by dropping
>> the unnecessary local variable completely and just setting
>>   info._sifields._sigfault._addr = env->exception.vaddress;
>> at the only point where we currently use 'addr', though,
>> I think.

> We do use the name code pattern in most of the functions of that file,
> meaning
>
> uint32_t / uint64_t / target_ulong addr;
>
> and then do_something_with_addr(addr);

In other functions the variable is used more than once,
mostly. (In cases where it is not I would also be happy
with cleanup patches which removed it.)

-- PMM
diff mbox

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index 483eb3f..d63e093 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1006,7 +1006,7 @@  void cpu_loop(CPUARMState *env)
     CPUState *cs = CPU(arm_env_get_cpu(env));
     int trapnr, sig;
     target_siginfo_t info;
-    uint32_t addr;
+    uint64_t addr;
 
     for (;;) {
         cpu_exec_start(cs);