diff options
author | David Howells <dhowells@redhat.com> | 2010-08-17 18:52:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-17 21:07:43 -0400 |
commit | d7627467b7a8dd6944885290a03a07ceb28c10eb (patch) | |
tree | a18c83468418e878cfb2d44e4310d81b8db84ad7 /fs | |
parent | da5cabf80e2433131bf0ed8993abc0f7ea618c73 (diff) |
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: David Howells <dhowells@redhat.com>
Tested-by: Ralf Baechle <ralf@linux-mips.org>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/binfmt_misc.c | 2 | ||||
-rw-r--r-- | fs/binfmt_script.c | 3 | ||||
-rw-r--r-- | fs/exec.c | 21 |
3 files changed, 14 insertions, 12 deletions
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index 9e60fd201716..a7528b913936 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c | |||
@@ -108,7 +108,7 @@ static int load_misc_binary(struct linux_binprm *bprm, struct pt_regs *regs) | |||
108 | Node *fmt; | 108 | Node *fmt; |
109 | struct file * interp_file = NULL; | 109 | struct file * interp_file = NULL; |
110 | char iname[BINPRM_BUF_SIZE]; | 110 | char iname[BINPRM_BUF_SIZE]; |
111 | char *iname_addr = iname; | 111 | const char *iname_addr = iname; |
112 | int retval; | 112 | int retval; |
113 | int fd_binary = -1; | 113 | int fd_binary = -1; |
114 | 114 | ||
diff --git a/fs/binfmt_script.c b/fs/binfmt_script.c index aca9d55afb22..396a9884591f 100644 --- a/fs/binfmt_script.c +++ b/fs/binfmt_script.c | |||
@@ -16,7 +16,8 @@ | |||
16 | 16 | ||
17 | static int load_script(struct linux_binprm *bprm,struct pt_regs *regs) | 17 | static int load_script(struct linux_binprm *bprm,struct pt_regs *regs) |
18 | { | 18 | { |
19 | char *cp, *i_name, *i_arg; | 19 | const char *i_arg, *i_name; |
20 | char *cp; | ||
20 | struct file *file; | 21 | struct file *file; |
21 | char interp[BINPRM_BUF_SIZE]; | 22 | char interp[BINPRM_BUF_SIZE]; |
22 | int retval; | 23 | int retval; |
@@ -361,13 +361,13 @@ err: | |||
361 | /* | 361 | /* |
362 | * count() counts the number of strings in array ARGV. | 362 | * count() counts the number of strings in array ARGV. |
363 | */ | 363 | */ |
364 | static int count(char __user * __user * argv, int max) | 364 | static int count(const char __user * const __user * argv, int max) |
365 | { | 365 | { |
366 | int i = 0; | 366 | int i = 0; |
367 | 367 | ||
368 | if (argv != NULL) { | 368 | if (argv != NULL) { |
369 | for (;;) { | 369 | for (;;) { |
370 | char __user * p; | 370 | const char __user * p; |
371 | 371 | ||
372 | if (get_user(p, argv)) | 372 | if (get_user(p, argv)) |
373 | return -EFAULT; | 373 | return -EFAULT; |
@@ -387,7 +387,7 @@ static int count(char __user * __user * argv, int max) | |||
387 | * processes's memory to the new process's stack. The call to get_user_pages() | 387 | * processes's memory to the new process's stack. The call to get_user_pages() |
388 | * ensures the destination page is created and not swapped out. | 388 | * ensures the destination page is created and not swapped out. |
389 | */ | 389 | */ |
390 | static int copy_strings(int argc, char __user * __user * argv, | 390 | static int copy_strings(int argc, const char __user *const __user *argv, |
391 | struct linux_binprm *bprm) | 391 | struct linux_binprm *bprm) |
392 | { | 392 | { |
393 | struct page *kmapped_page = NULL; | 393 | struct page *kmapped_page = NULL; |
@@ -396,7 +396,7 @@ static int copy_strings(int argc, char __user * __user * argv, | |||
396 | int ret; | 396 | int ret; |
397 | 397 | ||
398 | while (argc-- > 0) { | 398 | while (argc-- > 0) { |
399 | char __user *str; | 399 | const char __user *str; |
400 | int len; | 400 | int len; |
401 | unsigned long pos; | 401 | unsigned long pos; |
402 | 402 | ||
@@ -470,12 +470,13 @@ out: | |||
470 | /* | 470 | /* |
471 | * Like copy_strings, but get argv and its values from kernel memory. | 471 | * Like copy_strings, but get argv and its values from kernel memory. |
472 | */ | 472 | */ |
473 | int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm) | 473 | int copy_strings_kernel(int argc, const char *const *argv, |
474 | struct linux_binprm *bprm) | ||
474 | { | 475 | { |
475 | int r; | 476 | int r; |
476 | mm_segment_t oldfs = get_fs(); | 477 | mm_segment_t oldfs = get_fs(); |
477 | set_fs(KERNEL_DS); | 478 | set_fs(KERNEL_DS); |
478 | r = copy_strings(argc, (char __user * __user *)argv, bprm); | 479 | r = copy_strings(argc, (const char __user *const __user *)argv, bprm); |
479 | set_fs(oldfs); | 480 | set_fs(oldfs); |
480 | return r; | 481 | return r; |
481 | } | 482 | } |
@@ -997,7 +998,7 @@ EXPORT_SYMBOL(flush_old_exec); | |||
997 | void setup_new_exec(struct linux_binprm * bprm) | 998 | void setup_new_exec(struct linux_binprm * bprm) |
998 | { | 999 | { |
999 | int i, ch; | 1000 | int i, ch; |
1000 | char * name; | 1001 | const char *name; |
1001 | char tcomm[sizeof(current->comm)]; | 1002 | char tcomm[sizeof(current->comm)]; |
1002 | 1003 | ||
1003 | arch_pick_mmap_layout(current->mm); | 1004 | arch_pick_mmap_layout(current->mm); |
@@ -1316,9 +1317,9 @@ EXPORT_SYMBOL(search_binary_handler); | |||
1316 | /* | 1317 | /* |
1317 | * sys_execve() executes a new program. | 1318 | * sys_execve() executes a new program. |
1318 | */ | 1319 | */ |
1319 | int do_execve(char * filename, | 1320 | int do_execve(const char * filename, |
1320 | char __user *__user *argv, | 1321 | const char __user *const __user *argv, |
1321 | char __user *__user *envp, | 1322 | const char __user *const __user *envp, |
1322 | struct pt_regs * regs) | 1323 | struct pt_regs * regs) |
1323 | { | 1324 | { |
1324 | struct linux_binprm *bprm; | 1325 | struct linux_binprm *bprm; |