Thread (115 messages) 115 messages, 13 authors, 2015-08-27

[PATCH v3 17/31] arm64: System calls handling

flat view

From: arnd@arndb.de (Arnd Bergmann)
Date: 2012-09-07 19:43:51
Also in: linux-arch, lkml

On Friday 07 September 2012, Catalin Marinas wrote:
quoted hunk ↗ jump to hunk
+/*
+ * sys_execve() executes a new program.
+ */
+asmlinkage long sys_execve(const char __user *filenamei,
+                          const char __user *const __user *argv,
+                          const char __user *const __user *envp,
+                          struct pt_regs *regs)
+{
+       long error;
+       char * filename;
+
+       filename = getname(filenamei);
+       error = PTR_ERR(filename);
+       if (IS_ERR(filename))
+               goto out;
+       error = do_execve(filename, argv, envp, regs);
+       putname(filename);
+out:
+       return error;
+}
+
+int kernel_execve(const char *filename,
+                 const char *const argv[],
+                 const char *const envp[])
+{
+       struct pt_regs regs;
+       int ret;
+
+       memset(&regs, 0, sizeof(struct pt_regs));
+       ret = do_execve(filename,
+                       (const char __user *const __user *)argv,
+                       (const char __user *const __user *)envp, &regs);
+       if (ret < 0)
+               goto out;
+
+       /*
+        * Save argc to the register structure for userspace.
+        */
+       regs.regs[0] = ret;
+
+       /*
+        * We were successful.  We won't be returning to our caller, but
+        * instead to user space by manipulating the kernel stack.
+        */
+       asm(    "add    x0, %0, %1\n\t"
+               "mov    x1, %2\n\t"
+               "mov    x2, %3\n\t"
+               "bl     memmove\n\t"    /* copy regs to top of stack */
+               "mov    x27, #0\n\t"    /* not a syscall */
+               "mov    x28, %0\n\t"    /* thread structure */
+               "mov    sp, x0\n\t"     /* reposition stack pointer */
+               "b      ret_to_user"
+               :
+               : "r" (current_thread_info()),
+                 "Ir" (THREAD_START_SP - sizeof(regs)),
+                 "r" (&regs),
+                 "Ir" (sizeof(regs))
+               : "x0", "x1", "x2", "x27", "x28", "x30", "memory");
+
+ out:
+       return ret;
+}
Al Viro is currently reworking this code across all architectures, please have a look
at https://git.kernel.org/?p=linux/kernel/git/viro/signal.git;a=shortlog;h=refs/heads/execve2
+EXPORT_SYMBOL(kernel_execve);
You certainly don't need to export it.

	Arnd
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help