Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7627467 authored by David Howells's avatar David Howells Committed by Linus Torvalds
Browse files

Make do_execve() take a const filename pointer



Make do_execve() take a const filename pointer so that kernel_execve() compiles
correctly on ARM:

arch/arm/kernel/sys_arm.c:88: warning: passing argument 1 of 'do_execve' discards qualifiers from pointer target type

This also requires the argv and envp arguments to be consted twice, once for
the pointer array and once for the strings the array points to.  This is
because do_execve() passes a pointer to the filename (now const) to
copy_strings_kernel().  A simpler alternative would be to cast the filename
pointer in do_execve() when it's passed to copy_strings_kernel().

do_execve() may not change any of the strings it is passed as part of the argv
or envp lists as they are some of them in .rodata, so marking these strings as
const should be fine.

Further kernel_execve() and sys_execve() need to be changed to match.

This has been test built on x86_64, frv, arm and mips.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarRalf Baechle <ralf@linux-mips.org>
Acked-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent da5cabf8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -387,8 +387,9 @@ EXPORT_SYMBOL(dump_elf_task_fp);
 * sys_execve() executes a new program.
 */
asmlinkage int
do_sys_execve(const char __user *ufilename, char __user * __user *argv,
	      char __user * __user *envp, struct pt_regs *regs)
do_sys_execve(const char __user *ufilename,
	      const char __user *const __user *argv,
	      const char __user *const __user *envp, struct pt_regs *regs)
{
	int error;
	char *filename;
+9 −5
Original line number Diff line number Diff line
@@ -62,8 +62,9 @@ asmlinkage int sys_vfork(struct pt_regs *regs)
/* sys_execve() executes a new program.
 * This is called indirectly via a small wrapper
 */
asmlinkage int sys_execve(const char __user *filenamei, char __user * __user *argv,
			  char __user * __user *envp, struct pt_regs *regs)
asmlinkage int sys_execve(const char __user *filenamei,
			  const char __user *const __user *argv,
			  const char __user *const __user *envp, struct pt_regs *regs)
{
	int error;
	char * filename;
@@ -78,14 +79,17 @@ asmlinkage int sys_execve(const char __user *filenamei, char __user * __user *ar
	return error;
}

int kernel_execve(const char *filename, char *const argv[], char *const envp[])
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, (char __user * __user *)argv,
			(char __user * __user *)envp, &regs);
	ret = do_execve(filename,
			(const char __user *const __user *)argv,
			(const char __user *const __user *)envp, &regs);
	if (ret < 0)
		goto out;

+3 −2
Original line number Diff line number Diff line
@@ -384,8 +384,9 @@ asmlinkage int sys_vfork(struct pt_regs *regs)
}

asmlinkage int sys_execve(const char __user *ufilename,
			  char __user *__user *uargv,
			  char __user *__user *uenvp, struct pt_regs *regs)
			  const char __user *const __user *uargv,
			  const char __user *const __user *uenvp,
			  struct pt_regs *regs)
{
	int error;
	char *filename;
+3 −1
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@
 */
#include <linux/unistd.h>

int kernel_execve(const char *file, char **argv, char **envp)
int kernel_execve(const char *file,
		  const char *const *argv,
		  const char *const *envp)
{
	register long scno asm("r8") = __NR_execve;
	register long sc1 asm("r12") = (long)file;
+3 −1
Original line number Diff line number Diff line
@@ -209,7 +209,9 @@ copy_thread(unsigned long clone_flags,
/*
 * sys_execve() executes a new program.
 */
asmlinkage int sys_execve(const char __user *name, char __user * __user *argv, char __user * __user *envp)
asmlinkage int sys_execve(const char __user *name,
			  const char __user *const __user *argv,
			  const char __user *const __user *envp)
{
	int error;
	char *filename;
Loading