]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.36.2/exec-copy-and-paste-the-fixes-into-compat_do_execve-paths.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 2.6.36.2 / exec-copy-and-paste-the-fixes-into-compat_do_execve-paths.patch
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
5
6 From: Oleg Nesterov <oleg@redhat.com>
7
8 commit 114279be2120a916e8a04feeb2ac976a10016f2f upstream.
9
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.
13
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.
17
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)
20 as do_execve() does.
21
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
24 makes sense.
25
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>
30
31 ---
32 fs/compat.c | 28 +++++++++++++++-------------
33 fs/exec.c | 8 ++++----
34 include/linux/binfmts.h | 4 ++++
35 3 files changed, 23 insertions(+), 17 deletions(-)
36
37 --- a/fs/compat.c
38 +++ b/fs/compat.c
39 @@ -1378,6 +1378,10 @@ static int compat_count(compat_uptr_t __
40 argv++;
41 if (i++ >= max)
42 return -E2BIG;
43 +
44 + if (fatal_signal_pending(current))
45 + return -ERESTARTNOHAND;
46 + cond_resched();
47 }
48 }
49 return i;
50 @@ -1419,6 +1423,12 @@ static int compat_copy_strings(int argc,
51 while (len > 0) {
52 int offset, bytes_to_copy;
53
54 + if (fatal_signal_pending(current)) {
55 + ret = -ERESTARTNOHAND;
56 + goto out;
57 + }
58 + cond_resched();
59 +
60 offset = pos % PAGE_SIZE;
61 if (offset == 0)
62 offset = PAGE_SIZE;
63 @@ -1435,18 +1445,8 @@ static int compat_copy_strings(int argc,
64 if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
65 struct page *page;
66
67 -#ifdef CONFIG_STACK_GROWSUP
68 - ret = expand_stack_downwards(bprm->vma, pos);
69 - if (ret < 0) {
70 - /* We've exceed the stack rlimit. */
71 - ret = -E2BIG;
72 - goto out;
73 - }
74 -#endif
75 - ret = get_user_pages(current, bprm->mm, pos,
76 - 1, 1, 1, &page, NULL);
77 - if (ret <= 0) {
78 - /* We've exceed the stack rlimit. */
79 + page = get_arg_page(bprm, pos, 1);
80 + if (!page) {
81 ret = -E2BIG;
82 goto out;
83 }
84 @@ -1567,8 +1567,10 @@ int compat_do_execve(char * filename,
85 return retval;
86
87 out:
88 - if (bprm->mm)
89 + if (bprm->mm) {
90 + acct_arg_size(bprm, 0);
91 mmput(bprm->mm);
92 + }
93
94 out_file:
95 if (bprm->file) {
96 --- a/fs/exec.c
97 +++ b/fs/exec.c
98 @@ -157,7 +157,7 @@ out:
99
100 #ifdef CONFIG_MMU
101
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)
104 {
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
108 #endif
109 }
110
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,
113 int write)
114 {
115 struct page *page;
116 @@ -290,11 +290,11 @@ static bool valid_arg_len(struct linux_b
117
118 #else
119
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)
122 {
123 }
124
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,
127 int write)
128 {
129 struct page *page;
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;
134 };
135
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,
138 + int write);
139 +
140 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
141 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
142