summary refs log tree commit diff stats
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2010-06-16 13:03:51 +0100
committerPaul Brook <paul@codesourcery.com>2010-06-16 13:03:51 +0100
commit97374d38583028b33074c69caf296d94cb1b9d5b (patch)
tree20dd2e75e0b7dcf623a084e19e3f5e39a9161f31 /linux-user/syscall.c
parent9e0b74a43f5ab94acdc5b450747b8f6c184e0062 (diff)
downloadfocaccia-qemu-97374d38583028b33074c69caf296d94cb1b9d5b.tar.gz
focaccia-qemu-97374d38583028b33074c69caf296d94cb1b9d5b.zip
Usermode exec-stack fix
When loading a shared library that requires an executable stack,
glibc uses the mprotext PROT_GROWSDOWN flag to achieve this.
We don't support PROT_GROWSDOWN.
Add a special case to handle changing the stack permissions in this way.

Signed-off-by: Paul Brook <paul@codesourcery.com>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e94f1eed5c..0ebe7e1c26 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5400,6 +5400,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(target_munmap(arg1, arg2));
         break;
     case TARGET_NR_mprotect:
+        {
+            TaskState *ts = ((CPUState *)cpu_env)->opaque;
+            /* Special hack to detect libc making the stack executable.  */
+            if ((arg3 & PROT_GROWSDOWN)
+                && arg1 >= ts->info->stack_limit
+                && arg1 <= ts->info->start_stack) {
+                arg3 &= ~PROT_GROWSDOWN;
+                arg2 = arg2 + arg1 - ts->info->stack_limit;
+                arg1 = ts->info->stack_limit;
+            }
+        }
         ret = get_errno(target_mprotect(arg1, arg2, arg3));
         break;
 #ifdef TARGET_NR_mremap