1 From 114279be2120a916e8a04feeb2ac976a10016f2f Mon Sep 17 00:00:00 2001
2 From: Oleg Nesterov <oleg@redhat.com>
3 Date: Tue, 30 Nov 2010 20:56:02 +0100
4 Subject: exec: copy-and-paste the fixes into compat_do_execve() paths
6 From: Oleg Nesterov <oleg@redhat.com>
8 commit 114279be2120a916e8a04feeb2ac976a10016f2f upstream.
10 Note: this patch targets 2.6.37 and tries to be as simple as possible.
11 That is why it adds more copy-and-paste horror into fs/compat.c and
12 uglifies fs/exec.c, this will be cleanuped later.
14 compat_copy_strings() plays with bprm->vma/mm directly and thus has
15 two problems: it lacks the RLIMIT_STACK check and argv/envp memory
16 is not visible to oom killer.
18 Export acct_arg_size() and get_arg_page(), change compat_copy_strings()
19 to use get_arg_page(), change compat_do_execve() to do acct_arg_size(0)
22 Add the fatal_signal_pending/cond_resched checks into compat_count() and
23 compat_copy_strings(), this matches the code in fs/exec.c and certainly
26 Signed-off-by: Oleg Nesterov <oleg@redhat.com>
27 Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
28 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
32 fs/compat.c | 28 +++++++++++++++-------------
33 fs/exec.c | 8 ++++----
34 include/linux/binfmts.h | 4 ++++
35 3 files changed, 23 insertions(+), 17 deletions(-)
39 @@ -1378,6 +1378,10 @@ static int compat_count(compat_uptr_t __
44 + if (fatal_signal_pending(current))
45 + return -ERESTARTNOHAND;
50 @@ -1419,6 +1423,12 @@ static int compat_copy_strings(int argc,
52 int offset, bytes_to_copy;
54 + if (fatal_signal_pending(current)) {
55 + ret = -ERESTARTNOHAND;
60 offset = pos % PAGE_SIZE;
63 @@ -1435,18 +1445,8 @@ static int compat_copy_strings(int argc,
64 if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
67 -#ifdef CONFIG_STACK_GROWSUP
68 - ret = expand_stack_downwards(bprm->vma, pos);
70 - /* We've exceed the stack rlimit. */
75 - ret = get_user_pages(current, bprm->mm, pos,
76 - 1, 1, 1, &page, NULL);
78 - /* We've exceed the stack rlimit. */
79 + page = get_arg_page(bprm, pos, 1);
84 @@ -1567,8 +1567,10 @@ int compat_do_execve(char * filename,
90 + acct_arg_size(bprm, 0);
98 @@ -157,7 +157,7 @@ out:
102 -static void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
103 +void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
105 struct mm_struct *mm = current->mm;
106 long diff = (long)(pages - bprm->vma_pages);
107 @@ -176,7 +176,7 @@ static void acct_arg_size(struct linux_b
111 -static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
112 +struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
116 @@ -290,11 +290,11 @@ static bool valid_arg_len(struct linux_b
120 -static inline void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
121 +void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
125 -static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
126 +struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
130 --- a/include/linux/binfmts.h
131 +++ b/include/linux/binfmts.h
132 @@ -60,6 +60,10 @@ struct linux_binprm{
133 unsigned long loader, exec;
136 +extern void acct_arg_size(struct linux_binprm *bprm, unsigned long pages);
137 +extern struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
140 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
141 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)