qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0
@ 2014-11-11  6:50 riku.voipio
  2014-11-11  6:50 ` [Qemu-devel] [PULL 1/2] linux-user: Do not subtract offset from end address riku.voipio
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: riku.voipio @ 2014-11-11  6:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Riku Voipio

From: Riku Voipio <riku.voipio@linaro.org>

The following changes since commit 558c2c8ddfb165a36eb95dc93125c04829d68aa7:

  Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2014-11-10 16:28:51 +0000)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20141111

for you to fetch changes up to aecc88616a64a4e0a1ae0d6986de0054ea9f37d2:

  linux-user: Fix up timer id handling (2014-11-11 08:13:09 +0200)

----------------------------------------------------------------
linux-user pull for 2.2

Two last minute fixes uncovered and fixed by Tom Musta
and Alexander Graf, thanks

----------------------------------------------------------------
Alexander Graf (1):
      linux-user: Fix up timer id handling

Tom Musta (1):
      linux-user: Do not subtract offset from end address

 linux-user/elfload.c      |  2 +-
 linux-user/syscall.c      | 54 +++++++++++++++++++++++++++++++++++++-----------------
 linux-user/syscall_defs.h |  5 +----
 3 files changed, 39 insertions(+), 22 deletions(-)

-- 
2.1.1

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

* [Qemu-devel] [PULL 1/2] linux-user: Do not subtract offset from end address
  2014-11-11  6:50 [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 riku.voipio
@ 2014-11-11  6:50 ` riku.voipio
  2014-11-11  6:50 ` [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling riku.voipio
  2014-11-11 11:04 ` [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 Peter Maydell
  2 siblings, 0 replies; 5+ messages in thread
From: riku.voipio @ 2014-11-11  6:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Tom Musta

From: Tom Musta <tommusta@gmail.com>

When computing the upper address of a program segment, do not subtract the
offset from the virtual address; instead compute the sum of the virtual address
and the memory size.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 84123ba..e2596a4 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1824,7 +1824,7 @@ static void load_elf_image(const char *image_name, int image_fd,
             if (a < loaddr) {
                 loaddr = a;
             }
-            a += phdr[i].p_memsz;
+            a = phdr[i].p_vaddr + phdr[i].p_memsz;
             if (a > hiaddr) {
                 hiaddr = a;
             }
-- 
2.1.1

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

* [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling
  2014-11-11  6:50 [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 riku.voipio
  2014-11-11  6:50 ` [Qemu-devel] [PULL 1/2] linux-user: Do not subtract offset from end address riku.voipio
@ 2014-11-11  6:50 ` riku.voipio
  2015-03-23 14:14   ` Riku Voipio
  2014-11-11 11:04 ` [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 Peter Maydell
  2 siblings, 1 reply; 5+ messages in thread
From: riku.voipio @ 2014-11-11  6:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Alexander Graf

From: Alexander Graf <agraf@suse.de>

When creating a timer handle, we give the timer id a special magic offset
of 0xcafe0000. However, we never mask that offset out of the timer id before
we start using it to dereference our timer array. So we always end up aborting
timer operations because the timer id is out of bounds.

This was not an issue before my patch e52a99f756e ("linux-user: Simplify
timerid checks on g_posix_timers range") because before we would blindly mask
anything above the first 16 bits.

This patch simplifies the code around timer id creation by introducing a proper
target_timer_id typedef that is s32, just like Linux has it. It also changes the
magic offset to a value that makes all timer ids be positive.

Reported-by: Tom Musta <tommusta@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Tom Musta <tommusta@gmail.com>
Tested-by: Tom Musta <tommusta@gmail.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c      | 54 ++++++++++++++++++++++++++++++++---------------
 linux-user/syscall_defs.h |  5 +----
 2 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a175cc1..aaac6a2 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5473,6 +5473,27 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
     return get_errno(sys_openat(dirfd, path(pathname), flags, mode));
 }
 
+#define TIMER_MAGIC 0x0caf0000
+#define TIMER_MAGIC_MASK 0xffff0000
+
+/* Convert QEMU provided timer ID back to internal 16bit index format */
+static target_timer_t get_timer_id(abi_long arg)
+{
+    target_timer_t timerid = arg;
+
+    if ((timerid & TIMER_MAGIC_MASK) != TIMER_MAGIC) {
+        return -TARGET_EINVAL;
+    }
+
+    timerid &= 0xffff;
+
+    if (timerid >= ARRAY_SIZE(g_posix_timers)) {
+        return -TARGET_EINVAL;
+    }
+
+    return timerid;
+}
+
 /* do_syscall() should always have a single exit point at the end so
    that actions, such as logging of syscall results, can be performed.
    All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -9579,7 +9600,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         /* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */
 
         struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL;
-        struct target_timer_t *ptarget_timer;
 
         int clkid = arg1;
         int timer_index = next_free_host_timer();
@@ -9601,11 +9621,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             if (ret) {
                 phtimer = NULL;
             } else {
-                if (!lock_user_struct(VERIFY_WRITE, ptarget_timer, arg3, 1)) {
+                if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) {
                     goto efault;
                 }
-                ptarget_timer->ptr = tswap32(0xcafe0000 | timer_index);
-                unlock_user_struct(ptarget_timer, arg3, 1);
             }
         }
         break;
@@ -9617,9 +9635,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     {
         /* args: timer_t timerid, int flags, const struct itimerspec *new_value,
          * struct itimerspec * old_value */
-        target_ulong timerid = arg1;
+        target_timer_t timerid = get_timer_id(arg1);
 
-        if (arg3 == 0 || timerid >= ARRAY_SIZE(g_posix_timers)) {
+        if (timerid < 0) {
+            ret = timerid;
+        } else if (arg3 == 0) {
             ret = -TARGET_EINVAL;
         } else {
             timer_t htimer = g_posix_timers[timerid];
@@ -9638,12 +9658,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_timer_gettime:
     {
         /* args: timer_t timerid, struct itimerspec *curr_value */
-        target_ulong timerid = arg1;
+        target_timer_t timerid = get_timer_id(arg1);
 
-        if (!arg2) {
-            return -TARGET_EFAULT;
-        } else if (timerid >= ARRAY_SIZE(g_posix_timers)) {
-            ret = -TARGET_EINVAL;
+        if (timerid < 0) {
+            ret = timerid;
+        } else if (!arg2) {
+            ret = -TARGET_EFAULT;
         } else {
             timer_t htimer = g_posix_timers[timerid];
             struct itimerspec hspec;
@@ -9661,10 +9681,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_timer_getoverrun:
     {
         /* args: timer_t timerid */
-        target_ulong timerid = arg1;
+        target_timer_t timerid = get_timer_id(arg1);
 
-        if (timerid >= ARRAY_SIZE(g_posix_timers)) {
-            ret = -TARGET_EINVAL;
+        if (timerid < 0) {
+            ret = timerid;
         } else {
             timer_t htimer = g_posix_timers[timerid];
             ret = get_errno(timer_getoverrun(htimer));
@@ -9677,10 +9697,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_timer_delete:
     {
         /* args: timer_t timerid */
-        target_ulong timerid = arg1;
+        target_timer_t timerid = get_timer_id(arg1);
 
-        if (timerid >= ARRAY_SIZE(g_posix_timers)) {
-            ret = -TARGET_EINVAL;
+        if (timerid < 0) {
+            ret = timerid;
         } else {
             timer_t htimer = g_posix_timers[timerid];
             ret = get_errno(timer_delete(htimer));
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index c9e6323..ebb3be1 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2564,10 +2564,7 @@ struct target_ucred {
 
 #endif
 
-
-struct target_timer_t {
-    abi_ulong ptr;
-};
+typedef int32_t target_timer_t;
 
 #define TARGET_SIGEV_MAX_SIZE 64
 
-- 
2.1.1

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

* Re: [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0
  2014-11-11  6:50 [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 riku.voipio
  2014-11-11  6:50 ` [Qemu-devel] [PULL 1/2] linux-user: Do not subtract offset from end address riku.voipio
  2014-11-11  6:50 ` [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling riku.voipio
@ 2014-11-11 11:04 ` Peter Maydell
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2014-11-11 11:04 UTC (permalink / raw)
  To: Riku Voipio; +Cc: QEMU Developers

On 11 November 2014 06:50,  <riku.voipio@linaro.org> wrote:
> From: Riku Voipio <riku.voipio@linaro.org>
>
> The following changes since commit 558c2c8ddfb165a36eb95dc93125c04829d68aa7:
>
>   Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2014-11-10 16:28:51 +0000)
>
> are available in the git repository at:
>
>   git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20141111
>
> for you to fetch changes up to aecc88616a64a4e0a1ae0d6986de0054ea9f37d2:
>
>   linux-user: Fix up timer id handling (2014-11-11 08:13:09 +0200)
>
> ----------------------------------------------------------------
> linux-user pull for 2.2
>
> Two last minute fixes uncovered and fixed by Tom Musta
> and Alexander Graf, thanks
>
> ----------------------------------------------------------------

Applied, thanks.

-- PMM

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

* Re: [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling
  2014-11-11  6:50 ` [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling riku.voipio
@ 2015-03-23 14:14   ` Riku Voipio
  0 siblings, 0 replies; 5+ messages in thread
From: Riku Voipio @ 2015-03-23 14:14 UTC (permalink / raw)
  To: qemu-devel

Hi,

Sorry for these two patches, please ignore.

Riku

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

end of thread, other threads:[~2015-03-23 14:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-11  6:50 [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 riku.voipio
2014-11-11  6:50 ` [Qemu-devel] [PULL 1/2] linux-user: Do not subtract offset from end address riku.voipio
2014-11-11  6:50 ` [Qemu-devel] [PULL 2/2] linux-user: Fix up timer id handling riku.voipio
2015-03-23 14:14   ` Riku Voipio
2014-11-11 11:04 ` [Qemu-devel] [PULL 0/2] linux-user fixes after -rc0 Peter Maydell

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).