All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime
@ 2016-10-25 11:46 Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 1/4] linux-user: fix clock_gettime() Dejan Jovicevic
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dejan Jovicevic @ 2016-10-25 11:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

In this series the clock_gettime() was fixed to behave as intended when not
having valid arguments. The emulation for the system call clock_settime()
was added. Conversion of itimerspec structure and error handling in
timer_settime() syscall were corrected.

Dejan Jovicevic (4):
  linux-user: fix clock_gettime()
  linux-user: add clock_settime()
  linux-user: correct conversion of itimerspec structure
  linux-user: timer_settime fix

 linux-user/syscall.c | 62 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 37 insertions(+), 25 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/4] linux-user: fix clock_gettime()
  2016-10-25 11:46 [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime Dejan Jovicevic
@ 2016-10-25 11:46 ` Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 2/4] linux-user: add clock_settime() Dejan Jovicevic
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dejan Jovicevic @ 2016-10-25 11:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

When timespec stucture pointer points outside the accessible
address space (i.e. it's an invalid pointer), the clock_gettime()
syscall should return with -1 and set the errno to EFAULT.
This wasn't the case, since there was no check if the
host_to_target_timespec() failed. This check was added and
now the syscall behaves appropriately in this situation.

Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com>
---
 linux-user/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 03339ba..e6abfc5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11247,7 +11247,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         struct timespec ts;
         ret = get_errno(clock_gettime(arg1, &ts));
         if (!is_error(ret)) {
-            host_to_target_timespec(arg2, &ts);
+            if (host_to_target_timespec(arg2, &ts)) {
+                goto efault;
+            }
         }
         break;
     }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/4] linux-user: add clock_settime()
  2016-10-25 11:46 [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 1/4] linux-user: fix clock_gettime() Dejan Jovicevic
@ 2016-10-25 11:46 ` Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 3/4] linux-user: correct conversion of itimerspec structure Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 4/4] linux-user: timer_settime fix Dejan Jovicevic
  3 siblings, 0 replies; 5+ messages in thread
From: Dejan Jovicevic @ 2016-10-25 11:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

The implementation of the clock_settime() system call emulation
is based on converting the timespec structure values from
target to host and then calling the clock_settime() syscall on
the host.

Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com>
---
 linux-user/syscall.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e6abfc5..898f774 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11254,6 +11254,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     }
 #endif
+#ifdef TARGET_NR_clock_settime
+    case TARGET_NR_clock_settime:
+    {
+        struct timespec ts;
+        if (target_to_host_timespec(&ts, arg2)) {
+            goto efault;
+        }
+        ret = get_errno(clock_settime(arg1, &ts));
+        break;
+    }
+#endif
 #ifdef TARGET_NR_clock_getres
     case TARGET_NR_clock_getres:
     {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/4] linux-user: correct conversion of itimerspec structure
  2016-10-25 11:46 [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 1/4] linux-user: fix clock_gettime() Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 2/4] linux-user: add clock_settime() Dejan Jovicevic
@ 2016-10-25 11:46 ` Dejan Jovicevic
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 4/4] linux-user: timer_settime fix Dejan Jovicevic
  3 siblings, 0 replies; 5+ messages in thread
From: Dejan Jovicevic @ 2016-10-25 11:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

__get_user() and __put_user() have certain advantages over
tswapal(). There was also a previous commit for equivalent
change for converting structure timespec.

Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com>
---
 linux-user/syscall.c | 39 +++++++++++++++++----------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 898f774..b4f53b1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6731,42 +6731,37 @@ static inline abi_long host_to_target_timespec(abi_ulong target_addr,
     return 0;
 }
 
-static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec,
+static inline abi_long target_to_host_itimerspec(struct itimerspec *host_its,
                                                  abi_ulong target_addr)
 {
-    struct target_itimerspec *target_itspec;
+    struct target_itimerspec *target_its;
 
-    if (!lock_user_struct(VERIFY_READ, target_itspec, target_addr, 1)) {
+    if (!lock_user_struct(VERIFY_READ, target_its, target_addr, 1)) {
         return -TARGET_EFAULT;
     }
-
-    host_itspec->it_interval.tv_sec =
-                            tswapal(target_itspec->it_interval.tv_sec);
-    host_itspec->it_interval.tv_nsec =
-                            tswapal(target_itspec->it_interval.tv_nsec);
-    host_itspec->it_value.tv_sec = tswapal(target_itspec->it_value.tv_sec);
-    host_itspec->it_value.tv_nsec = tswapal(target_itspec->it_value.tv_nsec);
-
-    unlock_user_struct(target_itspec, target_addr, 1);
+    __get_user(host_its->it_interval.tv_sec, &target_its->it_interval.tv_sec);
+    __get_user(host_its->it_interval.tv_nsec,
+                               &target_its->it_interval.tv_nsec);
+    __get_user(host_its->it_value.tv_sec, &target_its->it_value.tv_sec);
+    __get_user(host_its->it_value.tv_nsec, &target_its->it_value.tv_nsec);
+    unlock_user_struct(target_its, target_addr, 1);
     return 0;
 }
 
 static inline abi_long host_to_target_itimerspec(abi_ulong target_addr,
                                                struct itimerspec *host_its)
 {
-    struct target_itimerspec *target_itspec;
+    struct target_itimerspec *target_its;
 
-    if (!lock_user_struct(VERIFY_WRITE, target_itspec, target_addr, 0)) {
+    if (!lock_user_struct(VERIFY_WRITE, target_its, target_addr, 0)) {
         return -TARGET_EFAULT;
     }
-
-    target_itspec->it_interval.tv_sec = tswapal(host_its->it_interval.tv_sec);
-    target_itspec->it_interval.tv_nsec = tswapal(host_its->it_interval.tv_nsec);
-
-    target_itspec->it_value.tv_sec = tswapal(host_its->it_value.tv_sec);
-    target_itspec->it_value.tv_nsec = tswapal(host_its->it_value.tv_nsec);
-
-    unlock_user_struct(target_itspec, target_addr, 0);
+    __put_user(host_its->it_interval.tv_sec, &target_its->it_interval.tv_sec);
+    __put_user(host_its->it_interval.tv_nsec,
+                               &target_its->it_interval.tv_nsec);
+    __put_user(host_its->it_value.tv_sec, &target_its->it_value.tv_sec);
+    __put_user(host_its->it_value.tv_nsec, &target_its->it_value.tv_nsec);
+    unlock_user_struct(target_its, target_addr, 0);
     return 0;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 4/4] linux-user: timer_settime fix
  2016-10-25 11:46 [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime Dejan Jovicevic
                   ` (2 preceding siblings ...)
  2016-10-25 11:46 ` [Qemu-devel] [PATCH 3/4] linux-user: correct conversion of itimerspec structure Dejan Jovicevic
@ 2016-10-25 11:46 ` Dejan Jovicevic
  3 siblings, 0 replies; 5+ messages in thread
From: Dejan Jovicevic @ 2016-10-25 11:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio

Error handling was improved. host_to_target_itimerspec() was
invoked with arg2 passed instead of arg4.

Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com>
---
 linux-user/syscall.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b4f53b1..cad4269 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11823,10 +11823,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             timer_t htimer = g_posix_timers[timerid];
             struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};
 
-            target_to_host_itimerspec(&hspec_new, arg3);
+            if (target_to_host_itimerspec(&hspec_new, arg3)) {
+                goto efault;
+            }
             ret = get_errno(
                           timer_settime(htimer, arg2, &hspec_new, &hspec_old));
-            host_to_target_itimerspec(arg2, &hspec_old);
+            if (host_to_target_itimerspec(arg4, &hspec_old)) {
+                goto efault;
+            }
         }
         break;
     }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-10-25 11:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-25 11:46 [Qemu-devel] [PATCH 0/4] linux-user: fix timespec and itimerspec related issues, add clock_settime Dejan Jovicevic
2016-10-25 11:46 ` [Qemu-devel] [PATCH 1/4] linux-user: fix clock_gettime() Dejan Jovicevic
2016-10-25 11:46 ` [Qemu-devel] [PATCH 2/4] linux-user: add clock_settime() Dejan Jovicevic
2016-10-25 11:46 ` [Qemu-devel] [PATCH 3/4] linux-user: correct conversion of itimerspec structure Dejan Jovicevic
2016-10-25 11:46 ` [Qemu-devel] [PATCH 4/4] linux-user: timer_settime fix Dejan Jovicevic

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.