From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>,
Laurent Vivier <laurent@vivier.eu>,
Filip Bozuta <Filip.Bozuta@syrmia.com>
Subject: [PULL 02/18] linux-user: Fix 'clock_nanosleep()' implementation
Date: Thu, 27 Aug 2020 21:20:02 +0200 [thread overview]
Message-ID: <20200827192018.2442099-3-laurent@vivier.eu> (raw)
In-Reply-To: <20200827192018.2442099-1-laurent@vivier.eu>
From: Filip Bozuta <Filip.Bozuta@syrmia.com>
Implementation of syscall 'clock_nanosleep()' in 'syscall.c' uses
functions 'target_to_host_timespec()' and 'host_to_target_timespec()'
to transfer the value of 'struct timespec' between target and host.
However, the implementation doesn't check whether this conversion
succeeds and thus can return an unaproppriate error instead of 'EFAULT'
that is expected. This was confirmed with the modified LTP test suite
where testcases with bad 'struct timespec' adress for 'clock_nanosleep()'
were added. This modified LTP suite can be found at:
https://github.com/bozutaf/ltp
(Patch with this new test case will be sent to LTP mailing list soon)
Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200727201326.401519-1-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5b3fce3dc0cb..e387246d7196 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11875,7 +11875,9 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
case TARGET_NR_clock_nanosleep:
{
struct timespec ts;
- target_to_host_timespec(&ts, arg3);
+ if (target_to_host_timespec(&ts, arg3)) {
+ return -TARGET_EFAULT;
+ }
ret = get_errno(safe_clock_nanosleep(arg1, arg2,
&ts, arg4 ? &ts : NULL));
/*
@@ -11883,8 +11885,9 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
* with error -TARGET_EINTR and if arg4 is not NULL and arg2 is not
* TIMER_ABSTIME, it returns the remaining unslept time in arg4.
*/
- if (ret == -TARGET_EINTR && arg4 && arg2 != TIMER_ABSTIME) {
- host_to_target_timespec(arg4, &ts);
+ if (ret == -TARGET_EINTR && arg4 && arg2 != TIMER_ABSTIME &&
+ host_to_target_timespec(arg4, &ts)) {
+ return -TARGET_EFAULT;
}
return ret;
--
2.26.2
next prev parent reply other threads:[~2020-08-27 19:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 19:20 [PULL 00/18] Linux user for 5.2 patches Laurent Vivier
2020-08-27 19:20 ` [PULL 01/18] linux-user: Fix 'semop()' and 'semtimedop()' implementation Laurent Vivier
2020-08-27 19:20 ` Laurent Vivier [this message]
2020-08-27 19:20 ` [PULL 03/18] linux-user: syscall: ioctls: support DRM_IOCTL_I915_GETPARAM Laurent Vivier
2020-08-27 19:20 ` [PULL 04/18] linux-user: Make cpu_env accessible in strace.c Laurent Vivier
2020-08-27 19:20 ` [PULL 05/18] linux-user: Add strace support for printing arguments of truncate()/ftruncate() and getsid() Laurent Vivier
2020-08-27 19:20 ` [PULL 06/18] linux-user: Add strace support for printing arguments of syscalls used to lock and unlock memory Laurent Vivier
2020-08-27 19:20 ` [PULL 07/18] linux-user: Add an api to print enumareted argument values with strace Laurent Vivier
2020-08-27 19:20 ` [PULL 08/18] linux-user: Add strace support for printing arguments of some clock and time functions Laurent Vivier
2020-08-27 19:20 ` [PULL 09/18] linux-user: Add generic 'termbits.h' for some archs Laurent Vivier
2020-08-27 19:20 ` [PULL 10/18] linux-user: Add missing termbits types and values definitions Laurent Vivier
2020-08-27 19:20 ` [PULL 11/18] linux-user: Add strace support for printing arguments for ioctls used for terminals and serial lines Laurent Vivier
2020-08-27 19:20 ` [PULL 12/18] linux-user: detect mismatched ELF ABI in qemu-mips[n32][el] Laurent Vivier
2020-08-27 19:20 ` [PULL 13/18] linux-user: Fix 'mq_timedsend()' and 'mq_timedreceive()' Laurent Vivier
2020-08-27 19:20 ` [PULL 14/18] linux-user: fix target_to_host_timespec64() Laurent Vivier
2020-08-27 19:20 ` [PULL 15/18] linux-user: Add support for 'mq_timedsend_time64()' and 'mq_timedreceive_time64()' Laurent Vivier
2020-08-27 19:20 ` [PULL 16/18] linux-user: Add support for 'clock_nanosleep_time64()' and 'clock_adjtime64()' Laurent Vivier
2020-08-27 19:20 ` [PULL 17/18] linux-user: Add support for 'rt_sigtimedwait_time64()' and 'sched_rr_get_interval_time64()' Laurent Vivier
2020-08-27 19:20 ` [PULL 18/18] linux-user: Add support for utimensat_time64() and semtimedop_time64() Laurent Vivier
2020-08-28 12:11 ` [PULL 00/18] Linux user for 5.2 patches Peter Maydell
2020-08-28 13:36 ` Laurent Vivier
-- strict thread matches above, loose matches on Subject: below --
2020-08-28 13:37 Laurent Vivier
2020-08-28 13:37 ` [PULL 02/18] linux-user: Fix 'clock_nanosleep()' implementation Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827192018.2442099-3-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=Filip.Bozuta@syrmia.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).