linux-user: fix getrusage and wait4 failures with invalid rusage struct
PATCH 1/1 linux-user: fix getrusage and wait4 failures with invalid rusage struct
From: Petar Jovanovic <[email protected]>
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed.
This change makes sure return values are correctly set for these cases.
--- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -3
@@ -6309,7 +6309,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,struct rusage rusage; ret =get_errno (getrusage (arg1, &rusage));if (!is_error (ret)) { -host_to_target_rusage (arg2, &rusage); + ret =host_to_target_rusage (arg2, &rusage); } }break ;
@@ -6974,6 +6974,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,abi_long status_ptr = arg2;struct rusage rusage, *rusage_ptr;abi_ulong target_rusage = arg4; +abi_long rusage_err;if (target_rusage) rusage_ptr = &rusage;else
@@ -6985,8 +6986,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,if (put_user_s32 (status, status_ptr)) goto efault; } -if (target_rusage) -host_to_target_rusage (target_rusage, &rusage); +if (target_rusage) { + rusage_err =host_to_target_rusage (target_rusage, &rusage); +if (rusage_err) { + ret = rusage_err; + } + } } }break ;
Signature · 1 line
1.7.9.5
ping
http://patchwork.ozlabs.org/patch/337703/
________________________________________
From: Petar Jovanovic [[email protected]]
Sent: Tuesday, April 08, 2014 7:24 PM
To: [email protected]
Cc: Petar Jovanovic; [email protected]
Subject: [PATCH] linux-user: fix getrusage and wait4 failures with invalid rusage struct
From: Petar Jovanovic <[email protected]>
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed.
This change makes sure return values are correctly set for these cases.
--- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
linux-user/syscall.c +8 -3
@@ -6309,7 +6309,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,struct rusage rusage; ret =get_errno (getrusage (arg1, &rusage));if (!is_error (ret)) { -host_to_target_rusage (arg2, &rusage); + ret =host_to_target_rusage (arg2, &rusage); } }break ;
@@ -6974,6 +6974,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,abi_long status_ptr = arg2;struct rusage rusage, *rusage_ptr;abi_ulong target_rusage = arg4; +abi_long rusage_err;if (target_rusage) rusage_ptr = &rusage;else
@@ -6985,8 +6986,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,if (put_user_s32 (status, status_ptr)) goto efault; } -if (target_rusage) -host_to_target_rusage (target_rusage, &rusage); +if (target_rusage) { + rusage_err =host_to_target_rusage (target_rusage, &rusage); +if (rusage_err) { + ret = rusage_err; + } + } } }break ;
--
1.7.9.5
Hi,
Thanks, looks good and fixes getrusage02 ltp test.
Added to the linux-user que:
https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream
Peter, do you prefer a new pull request for linux-user with this patch added on top, or is pulling the updated branch good enough for you?
Riku
Quoted 68 lines · Petar Jovanovic
ping
http://patchwork.ozlabs.org/patch/337703/
________________________________________
From: Petar Jovanovic [[email protected]]
Sent: Tuesday, April 08, 2014 7:24 PM
To: [email protected]
Cc: Petar Jovanovic; [email protected]
Subject: [PATCH] linux-user: fix getrusage and wait4 failures with invalid rusage structFrom: Petar Jovanovic <[email protected]>
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed.
This change makes sure return values are correctly set for these cases.Signed-off-by Petar Jovanovic <[email protected]>--- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)linux-user/syscall.c +1
-1@@ -6309,7 +6309,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, struct rusage rusage; ret =get_errno (getrusage (arg1, &rusage));if (!is_error (ret)) { -host_to_target_rusage (arg2, &rusage); + ret =host_to_target_rusage (arg2, &rusage); } }break;linux-user/syscall.c +1
-0@@ -6974,6 +6974,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, abi_long status_ptr = arg2;struct rusage rusage, *rusage_ptr;abi_ulong target_rusage = arg4; +abi_long rusage_err;if (target_rusage) rusage_ptr = &rusage;else
linux-user/syscall.c +6
-2@@ -6985,8 +6986,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (put_user_s32(status, status_ptr)) goto efault; } -if (target_rusage) -host_to_target_rusage (target_rusage, &rusage); +if (target_rusage) { + rusage_err =host_to_target_rusage (target_rusage, &rusage); +if (rusage_err) { + ret = rusage_err; + } + } }} break;--
1.7.9.5
Quoted 10 lines · Riku Voipio
Hi,
Thanks, looks good and fixes getrusage02 ltp test.
Added to the linux-user que:
https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream
Peter, do you prefer a new pull request for linux-user with this patch added on top, or is pulling the updated branch good enough for you?
Send a new cover letter email, then it will go into my folder of pending requests correctly.
thanks
-- PMM
Am 08.04.2014 19:24, schrieb Petar Jovanovic:
Quoted 17 lines
From: Petar Jovanovic <[email protected]>
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed.
This change makes sure return values are correctly set for these cases.Signed-off-by Petar Jovanovic <[email protected]>--- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)linux-user/syscall.c +0
-0
linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6315
Quoted 8 lines
linux-user/syscall.c +1
-1@@ -6309,7 +6309,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,struct rusage rusage; ret =get_errno (getrusage (arg1, &rusage));if (!is_error (ret)) { -host_to_target_rusage (arg2, &rusage); + ret =host_to_target_rusage (arg2, &rusage); } }break ;
Why do you always set ret here ...
Quoted 13 lines
linux-user/syscall.c +1
-1@@ -6974,6 +6974,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,abi_long status_ptr = arg2;struct rusage rusage, *rusage_ptr;abi_ulong target_rusage = arg4; +abi_long rusage_err;if (target_rusage) rusage_ptr = &rusage;else @@ -6985,8 +6986,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,if (put_user_s32 (status, status_ptr)) goto efault; } -if (target_rusage)
linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6997
Quoted 10 lines
linux-user/syscall.c +6
-1-host_to_target_rusage (target_rusage, &rusage); +if (target_rusage) { + rusage_err =host_to_target_rusage (target_rusage, &rusage); +if (rusage_err) { + ret = rusage_err; + } + } } }break ;
... but only on error here? Isn't obvious from the commit message.
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
________________________________________
From: Andreas Färber [[email protected]]
Sent: Monday, May 05, 2014 11:55 AM
To: Petar Jovanovic; [email protected]
Cc: [email protected]; Petar Jovanovic
Subject: Re: [Qemu-devel] [PATCH] linux-user: fix getrusage and wait4 failures with invalid rusage struct
Am 08.04.2014 19:24, schrieb Petar Jovanovic:
Quoted 52 lines
From: Petar Jovanovic <[email protected]>
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed.
This change makes sure return values are correctly set for these cases.Signed-off-by Petar Jovanovic <[email protected]>--- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)linux-user/syscall.c +1
-1@@ -6309,7 +6309,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,struct rusage rusage; ret =get_errno (getrusage (arg1, &rusage));if (!is_error (ret)) { -host_to_target_rusage (arg2, &rusage); + ret =host_to_target_rusage (arg2, &rusage); } }break ;Why do you always set ret here ...
linux-user/syscall.c +7
-2@@ -6974,6 +6974,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,abi_long status_ptr = arg2;struct rusage rusage, *rusage_ptr;abi_ulong target_rusage = arg4; +abi_long rusage_err;if (target_rusage) rusage_ptr = &rusage;else @@ -6985,8 +6986,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,if (put_user_s32 (status, status_ptr)) goto efault; } -if (target_rusage) -host_to_target_rusage (target_rusage, &rusage); +if (target_rusage) { + rusage_err =host_to_target_rusage (target_rusage, &rusage); +if (rusage_err) { + ret = rusage_err; + } + } } }break ;
Quoted 1 line
... but only on error here? Isn't obvious from the commit message.
This is due to the fact that on success, wait4() returns the process ID of the child whose state has changed. So, the code needs to take care not to override it.
Regards,
Petar