/[linux-patches]/genpatches-2.6/historical/2.6.10/1130_rlimit-memlock-dos.patch
Gentoo

Contents of /genpatches-2.6/historical/2.6.10/1130_rlimit-memlock-dos.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download) (as text)
Sat Jun 11 23:16:54 2005 UTC (15 years ago) by dsd
File MIME type: text/x-diff
File size: 5136 byte(s)
Import historical releases
1 # This is a BitKeeper generated diff -Nru style patch.
2 #
3 # ChangeSet
4 # 2005/01/10 11:23:42-08:00 torvalds@ppc970.osdl.org
5 # Clean up stack growth checks and move them into a common function.
6 #
7 # The grows-up and grows-down cases had all the same issues, but
8 # differered in the details. Additionlly, historical evolution of
9 # the tests had caused the result to be pretty unreadable with some
10 # rather long and complex conditionals.
11 #
12 # Fix it all up in a more readable helper function.
13 #
14 # This also adds the missing RLIMIT_MEMLOCK test.
15 #
16 # mm/mmap.c
17 # 2005/01/10 11:23:35-08:00 torvalds@ppc970.osdl.org +61 -44
18 # Clean up stack growth checks and move them into a common function.
19 #
20 # The grows-up and grows-down cases had all the same issues, but
21 # differered in the details. Additionlly, historical evolution of
22 # the tests had caused the result to be pretty unreadable with some
23 # rather long and complex conditionals.
24 #
25 # Fix it all up in a more readable helper function.
26 #
27 # This also adds the missing RLIMIT_MEMLOCK test.
28 #
29
30 Rediff
31 Remove enhanced memory accounting calls
32
33 diff -X dontdiff -urNp linux-2.6.10/mm/mmap.c linux-dsd/mm/mmap.c
34 --- linux-2.6.10/mm/mmap.c 2004-12-24 21:35:00.000000000 +0000
35 +++ linux-dsd/mm/mmap.c 2005-01-14 00:20:17.582305696 +0000
36 @@ -1319,13 +1319,58 @@ out:
37 return prev ? prev->vm_next : vma;
38 }
39
40 +/*
41 + * Verify that the stack growth is acceptable and
42 + * update accounting. This is shared with both the
43 + * grow-up and grow-down cases.
44 + */
45 +static int acct_stack_growth(struct vm_area_struct * vma, unsigned long size, unsigned long grow)
46 +{
47 + struct mm_struct *mm = vma->vm_mm;
48 + struct rlimit *rlim = current->signal->rlim;
49 +
50 + /* address space limit tests */
51 + rlim = current->signal->rlim;
52 + if (mm->total_vm + grow > rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT)
53 + return -ENOMEM;
54 +
55 + /* Stack limit test */
56 + if (size > rlim[RLIMIT_STACK].rlim_cur)
57 + return -ENOMEM;
58 +
59 + /* mlock limit tests */
60 + if (vma->vm_flags & VM_LOCKED) {
61 + unsigned long locked;
62 + unsigned long limit;
63 + locked = mm->locked_vm + grow;
64 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
65 + if (locked > limit)
66 + return -ENOMEM;
67 + }
68 +
69 + /*
70 + * Overcommit.. This must be the final test, as it will
71 + * update security statistics.
72 + */
73 + if (security_vm_enough_memory(grow))
74 + return -ENOMEM;
75 +
76 + /* Ok, everything looks good - let it rip */
77 + mm->total_vm += grow;
78 + if (vma->vm_flags & VM_LOCKED)
79 + mm->locked_vm += grow;
80 + __vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
81 + return 0;
82 +}
83 +
84 #ifdef CONFIG_STACK_GROWSUP
85 /*
86 * vma is the first one with address > vma->vm_end. Have to extend vma.
87 */
88 int expand_stack(struct vm_area_struct * vma, unsigned long address)
89 {
90 - unsigned long grow;
91 + int error;
92 + unsigned long size, grow;
93
94 if (!(vma->vm_flags & VM_GROWSUP))
95 return -EFAULT;
96 @@ -1345,28 +1390,14 @@ int expand_stack(struct vm_area_struct *
97 */
98 address += 4 + PAGE_SIZE - 1;
99 address &= PAGE_MASK;
100 + size = address - vma->vm_start;
101 grow = (address - vma->vm_end) >> PAGE_SHIFT;
102
103 - /* Overcommit.. */
104 - if (security_vm_enough_memory(grow)) {
105 - anon_vma_unlock(vma);
106 - return -ENOMEM;
107 - }
108 -
109 - if (address - vma->vm_start > current->signal->rlim[RLIMIT_STACK].rlim_cur ||
110 - ((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) >
111 - current->signal->rlim[RLIMIT_AS].rlim_cur) {
112 - anon_vma_unlock(vma);
113 - vm_unacct_memory(grow);
114 - return -ENOMEM;
115 - }
116 - vma->vm_end = address;
117 - vma->vm_mm->total_vm += grow;
118 - if (vma->vm_flags & VM_LOCKED)
119 - vma->vm_mm->locked_vm += grow;
120 - __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
121 - anon_vma_unlock(vma);
122 - return 0;
123 + error = acct_stack_growth(vma, size, grow);
124 + if (!error)
125 + vma->vm_end = address;
126 + anon_vma_unlock(vma);
127 + return error;
128 }
129
130 struct vm_area_struct *
131 @@ -1391,7 +1422,8 @@ find_extend_vma(struct mm_struct *mm, un
132 */
133 int expand_stack(struct vm_area_struct *vma, unsigned long address)
134 {
135 - unsigned long grow;
136 + int error;
137 + unsigned long size, grow;
138
139 /*
140 * We must make sure the anon_vma is allocated
141 @@ -1407,29 +1439,16 @@ int expand_stack(struct vm_area_struct *
142 * anon_vma lock to serialize against concurrent expand_stacks.
143 */
144 address &= PAGE_MASK;
145 + size = vma->vm_end - address;
146 grow = (vma->vm_start - address) >> PAGE_SHIFT;
147
148 - /* Overcommit.. */
149 - if (security_vm_enough_memory(grow)) {
150 - anon_vma_unlock(vma);
151 - return -ENOMEM;
152 - }
153 -
154 - if (vma->vm_end - address > current->signal->rlim[RLIMIT_STACK].rlim_cur ||
155 - ((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) >
156 - current->signal->rlim[RLIMIT_AS].rlim_cur) {
157 - anon_vma_unlock(vma);
158 - vm_unacct_memory(grow);
159 - return -ENOMEM;
160 - }
161 - vma->vm_start = address;
162 - vma->vm_pgoff -= grow;
163 - vma->vm_mm->total_vm += grow;
164 - if (vma->vm_flags & VM_LOCKED)
165 - vma->vm_mm->locked_vm += grow;
166 - __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
167 + error = acct_stack_growth(vma, size, grow);
168 + if (!error) {
169 + vma->vm_start = address;
170 + vma->vm_pgoff -= grow;
171 + }
172 anon_vma_unlock(vma);
173 - return 0;
174 + return error;
175 }
176
177 struct vm_area_struct *

  ViewVC Help
Powered by ViewVC 1.1.20