mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
exec: copy-and-paste the fixes into compat_do_execve() paths
Note: this patch targets 2.6.37 and tries to be as simple as possible. That is why it adds more copy-and-paste horror into fs/compat.c and uglifies fs/exec.c, this will be cleanuped later. compat_copy_strings() plays with bprm->vma/mm directly and thus has two problems: it lacks the RLIMIT_STACK check and argv/envp memory is not visible to oom killer. Export acct_arg_size() and get_arg_page(), change compat_copy_strings() to use get_arg_page(), change compat_do_execve() to do acct_arg_size(0) as do_execve() does. Add the fatal_signal_pending/cond_resched checks into compat_count() and compat_copy_strings(), this matches the code in fs/exec.c and certainly makes sense. Signed-off-by: Oleg Nesterov <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Cc: [email protected] Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
3c77f84572
commit
114279be21
3 changed files with 23 additions and 17 deletions
28
fs/compat.c
28
fs/compat.c
|
|
@ -1350,6 +1350,10 @@ static int compat_count(compat_uptr_t __user *argv, int max)
|
|||
argv++;
|
||||
if (i++ >= max)
|
||||
return -E2BIG;
|
||||
|
||||
if (fatal_signal_pending(current))
|
||||
return -ERESTARTNOHAND;
|
||||
cond_resched();
|
||||
}
|
||||
}
|
||||
return i;
|
||||
|
|
@ -1391,6 +1395,12 @@ static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
|
|||
while (len > 0) {
|
||||
int offset, bytes_to_copy;
|
||||
|
||||
if (fatal_signal_pending(current)) {
|
||||
ret = -ERESTARTNOHAND;
|
||||
goto out;
|
||||
}
|
||||
cond_resched();
|
||||
|
||||
offset = pos % PAGE_SIZE;
|
||||
if (offset == 0)
|
||||
offset = PAGE_SIZE;
|
||||
|
|
@ -1407,18 +1417,8 @@ static int compat_copy_strings(int argc, compat_uptr_t __user *argv,
|
|||
if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
|
||||
struct page *page;
|
||||
|
||||
#ifdef CONFIG_STACK_GROWSUP
|
||||
ret = expand_stack_downwards(bprm->vma, pos);
|
||||
if (ret < 0) {
|
||||
/* We've exceed the stack rlimit. */
|
||||
ret = -E2BIG;
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
ret = get_user_pages(current, bprm->mm, pos,
|
||||
1, 1, 1, &page, NULL);
|
||||
if (ret <= 0) {
|
||||
/* We've exceed the stack rlimit. */
|
||||
page = get_arg_page(bprm, pos, 1);
|
||||
if (!page) {
|
||||
ret = -E2BIG;
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -1539,8 +1539,10 @@ int compat_do_execve(char * filename,
|
|||
return retval;
|
||||
|
||||
out:
|
||||
if (bprm->mm)
|
||||
if (bprm->mm) {
|
||||
acct_arg_size(bprm, 0);
|
||||
mmput(bprm->mm);
|
||||
}
|
||||
|
||||
out_file:
|
||||
if (bprm->file) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue