]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.2.2-2.6.39.2-201106281648.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.39.2-201106281648.patch
1 diff -urNp linux-2.6.39.2/arch/alpha/include/asm/dma-mapping.h linux-2.6.39.2/arch/alpha/include/asm/dma-mapping.h
2 --- linux-2.6.39.2/arch/alpha/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3 +++ linux-2.6.39.2/arch/alpha/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
4 @@ -3,9 +3,9 @@
5
6 #include <linux/dma-attrs.h>
7
8 -extern struct dma_map_ops *dma_ops;
9 +extern const struct dma_map_ops *dma_ops;
10
11 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
12 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
13 {
14 return dma_ops;
15 }
16 diff -urNp linux-2.6.39.2/arch/alpha/include/asm/elf.h linux-2.6.39.2/arch/alpha/include/asm/elf.h
17 --- linux-2.6.39.2/arch/alpha/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
18 +++ linux-2.6.39.2/arch/alpha/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
19 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
20
21 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
22
23 +#ifdef CONFIG_PAX_ASLR
24 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
25 +
26 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
27 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
28 +#endif
29 +
30 /* $0 is set by ld.so to a pointer to a function which might be
31 registered using atexit. This provides a mean for the dynamic
32 linker to call DT_FINI functions for shared libraries that have
33 diff -urNp linux-2.6.39.2/arch/alpha/include/asm/pgtable.h linux-2.6.39.2/arch/alpha/include/asm/pgtable.h
34 --- linux-2.6.39.2/arch/alpha/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
35 +++ linux-2.6.39.2/arch/alpha/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
36 @@ -101,6 +101,17 @@ struct vm_area_struct;
37 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
38 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
39 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
40 +
41 +#ifdef CONFIG_PAX_PAGEEXEC
42 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
43 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
44 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
45 +#else
46 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
47 +# define PAGE_COPY_NOEXEC PAGE_COPY
48 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
49 +#endif
50 +
51 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
52
53 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
54 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_apecs.c linux-2.6.39.2/arch/alpha/kernel/core_apecs.c
55 --- linux-2.6.39.2/arch/alpha/kernel/core_apecs.c 2011-05-19 00:06:34.000000000 -0400
56 +++ linux-2.6.39.2/arch/alpha/kernel/core_apecs.c 2011-05-22 19:36:30.000000000 -0400
57 @@ -305,7 +305,7 @@ apecs_write_config(struct pci_bus *bus,
58 return PCIBIOS_SUCCESSFUL;
59 }
60
61 -struct pci_ops apecs_pci_ops =
62 +const struct pci_ops apecs_pci_ops =
63 {
64 .read = apecs_read_config,
65 .write = apecs_write_config,
66 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_cia.c linux-2.6.39.2/arch/alpha/kernel/core_cia.c
67 --- linux-2.6.39.2/arch/alpha/kernel/core_cia.c 2011-05-19 00:06:34.000000000 -0400
68 +++ linux-2.6.39.2/arch/alpha/kernel/core_cia.c 2011-05-22 19:36:30.000000000 -0400
69 @@ -239,7 +239,7 @@ cia_write_config(struct pci_bus *bus, un
70 return PCIBIOS_SUCCESSFUL;
71 }
72
73 -struct pci_ops cia_pci_ops =
74 +const struct pci_ops cia_pci_ops =
75 {
76 .read = cia_read_config,
77 .write = cia_write_config,
78 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_irongate.c linux-2.6.39.2/arch/alpha/kernel/core_irongate.c
79 --- linux-2.6.39.2/arch/alpha/kernel/core_irongate.c 2011-05-19 00:06:34.000000000 -0400
80 +++ linux-2.6.39.2/arch/alpha/kernel/core_irongate.c 2011-05-22 19:36:30.000000000 -0400
81 @@ -155,7 +155,7 @@ irongate_write_config(struct pci_bus *bu
82 return PCIBIOS_SUCCESSFUL;
83 }
84
85 -struct pci_ops irongate_pci_ops =
86 +const struct pci_ops irongate_pci_ops =
87 {
88 .read = irongate_read_config,
89 .write = irongate_write_config,
90 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_lca.c linux-2.6.39.2/arch/alpha/kernel/core_lca.c
91 --- linux-2.6.39.2/arch/alpha/kernel/core_lca.c 2011-05-19 00:06:34.000000000 -0400
92 +++ linux-2.6.39.2/arch/alpha/kernel/core_lca.c 2011-05-22 19:36:30.000000000 -0400
93 @@ -231,7 +231,7 @@ lca_write_config(struct pci_bus *bus, un
94 return PCIBIOS_SUCCESSFUL;
95 }
96
97 -struct pci_ops lca_pci_ops =
98 +const struct pci_ops lca_pci_ops =
99 {
100 .read = lca_read_config,
101 .write = lca_write_config,
102 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_marvel.c linux-2.6.39.2/arch/alpha/kernel/core_marvel.c
103 --- linux-2.6.39.2/arch/alpha/kernel/core_marvel.c 2011-05-19 00:06:34.000000000 -0400
104 +++ linux-2.6.39.2/arch/alpha/kernel/core_marvel.c 2011-05-22 19:36:30.000000000 -0400
105 @@ -588,7 +588,7 @@ marvel_write_config(struct pci_bus *bus,
106 return PCIBIOS_SUCCESSFUL;
107 }
108
109 -struct pci_ops marvel_pci_ops =
110 +const struct pci_ops marvel_pci_ops =
111 {
112 .read = marvel_read_config,
113 .write = marvel_write_config,
114 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_mcpcia.c linux-2.6.39.2/arch/alpha/kernel/core_mcpcia.c
115 --- linux-2.6.39.2/arch/alpha/kernel/core_mcpcia.c 2011-05-19 00:06:34.000000000 -0400
116 +++ linux-2.6.39.2/arch/alpha/kernel/core_mcpcia.c 2011-05-22 19:36:30.000000000 -0400
117 @@ -235,7 +235,7 @@ mcpcia_write_config(struct pci_bus *bus,
118 return PCIBIOS_SUCCESSFUL;
119 }
120
121 -struct pci_ops mcpcia_pci_ops =
122 +const struct pci_ops mcpcia_pci_ops =
123 {
124 .read = mcpcia_read_config,
125 .write = mcpcia_write_config,
126 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_polaris.c linux-2.6.39.2/arch/alpha/kernel/core_polaris.c
127 --- linux-2.6.39.2/arch/alpha/kernel/core_polaris.c 2011-05-19 00:06:34.000000000 -0400
128 +++ linux-2.6.39.2/arch/alpha/kernel/core_polaris.c 2011-05-22 19:36:30.000000000 -0400
129 @@ -136,7 +136,7 @@ polaris_write_config(struct pci_bus *bus
130 return PCIBIOS_SUCCESSFUL;
131 }
132
133 -struct pci_ops polaris_pci_ops =
134 +const struct pci_ops polaris_pci_ops =
135 {
136 .read = polaris_read_config,
137 .write = polaris_write_config,
138 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_t2.c linux-2.6.39.2/arch/alpha/kernel/core_t2.c
139 --- linux-2.6.39.2/arch/alpha/kernel/core_t2.c 2011-05-19 00:06:34.000000000 -0400
140 +++ linux-2.6.39.2/arch/alpha/kernel/core_t2.c 2011-05-22 19:36:30.000000000 -0400
141 @@ -314,7 +314,7 @@ t2_write_config(struct pci_bus *bus, uns
142 return PCIBIOS_SUCCESSFUL;
143 }
144
145 -struct pci_ops t2_pci_ops =
146 +const struct pci_ops t2_pci_ops =
147 {
148 .read = t2_read_config,
149 .write = t2_write_config,
150 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_titan.c linux-2.6.39.2/arch/alpha/kernel/core_titan.c
151 --- linux-2.6.39.2/arch/alpha/kernel/core_titan.c 2011-05-19 00:06:34.000000000 -0400
152 +++ linux-2.6.39.2/arch/alpha/kernel/core_titan.c 2011-05-22 19:36:30.000000000 -0400
153 @@ -191,7 +191,7 @@ titan_write_config(struct pci_bus *bus,
154 return PCIBIOS_SUCCESSFUL;
155 }
156
157 -struct pci_ops titan_pci_ops =
158 +const struct pci_ops titan_pci_ops =
159 {
160 .read = titan_read_config,
161 .write = titan_write_config,
162 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_tsunami.c linux-2.6.39.2/arch/alpha/kernel/core_tsunami.c
163 --- linux-2.6.39.2/arch/alpha/kernel/core_tsunami.c 2011-05-19 00:06:34.000000000 -0400
164 +++ linux-2.6.39.2/arch/alpha/kernel/core_tsunami.c 2011-05-22 19:36:30.000000000 -0400
165 @@ -166,7 +166,7 @@ tsunami_write_config(struct pci_bus *bus
166 return PCIBIOS_SUCCESSFUL;
167 }
168
169 -struct pci_ops tsunami_pci_ops =
170 +const struct pci_ops tsunami_pci_ops =
171 {
172 .read = tsunami_read_config,
173 .write = tsunami_write_config,
174 diff -urNp linux-2.6.39.2/arch/alpha/kernel/core_wildfire.c linux-2.6.39.2/arch/alpha/kernel/core_wildfire.c
175 --- linux-2.6.39.2/arch/alpha/kernel/core_wildfire.c 2011-05-19 00:06:34.000000000 -0400
176 +++ linux-2.6.39.2/arch/alpha/kernel/core_wildfire.c 2011-05-22 19:36:30.000000000 -0400
177 @@ -431,7 +431,7 @@ wildfire_write_config(struct pci_bus *bu
178 return PCIBIOS_SUCCESSFUL;
179 }
180
181 -struct pci_ops wildfire_pci_ops =
182 +const struct pci_ops wildfire_pci_ops =
183 {
184 .read = wildfire_read_config,
185 .write = wildfire_write_config,
186 diff -urNp linux-2.6.39.2/arch/alpha/kernel/module.c linux-2.6.39.2/arch/alpha/kernel/module.c
187 --- linux-2.6.39.2/arch/alpha/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
188 +++ linux-2.6.39.2/arch/alpha/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
189 @@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
190
191 /* The small sections were sorted to the end of the segment.
192 The following should definitely cover them. */
193 - gp = (u64)me->module_core + me->core_size - 0x8000;
194 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
195 got = sechdrs[me->arch.gotsecindex].sh_addr;
196
197 for (i = 0; i < n; i++) {
198 diff -urNp linux-2.6.39.2/arch/alpha/kernel/osf_sys.c linux-2.6.39.2/arch/alpha/kernel/osf_sys.c
199 --- linux-2.6.39.2/arch/alpha/kernel/osf_sys.c 2011-05-19 00:06:34.000000000 -0400
200 +++ linux-2.6.39.2/arch/alpha/kernel/osf_sys.c 2011-06-13 17:19:07.000000000 -0400
201 @@ -409,7 +409,7 @@ SYSCALL_DEFINE2(osf_getdomainname, char
202 return -EFAULT;
203
204 len = namelen;
205 - if (namelen > 32)
206 + if (len > 32)
207 len = 32;
208
209 down_read(&uts_sem);
210 @@ -594,7 +594,7 @@ SYSCALL_DEFINE3(osf_sysinfo, int, comman
211 down_read(&uts_sem);
212 res = sysinfo_table[offset];
213 len = strlen(res)+1;
214 - if (len > count)
215 + if ((unsigned long)len > (unsigned long)count)
216 len = count;
217 if (copy_to_user(buf, res, len))
218 err = -EFAULT;
219 @@ -649,7 +649,7 @@ SYSCALL_DEFINE5(osf_getsysinfo, unsigned
220 return 1;
221
222 case GSI_GET_HWRPB:
223 - if (nbytes < sizeof(*hwrpb))
224 + if (nbytes > sizeof(*hwrpb))
225 return -EINVAL;
226 if (copy_to_user(buffer, hwrpb, nbytes) != 0)
227 return -EFAULT;
228 @@ -1008,6 +1008,7 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
229 {
230 struct rusage r;
231 long ret, err;
232 + unsigned int status = 0;
233 mm_segment_t old_fs;
234
235 if (!ur)
236 @@ -1016,13 +1017,15 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, i
237 old_fs = get_fs();
238
239 set_fs (KERNEL_DS);
240 - ret = sys_wait4(pid, ustatus, options, (struct rusage __user *) &r);
241 + ret = sys_wait4(pid, (unsigned int __user *) &status, options,
242 + (struct rusage __user *) &r);
243 set_fs (old_fs);
244
245 if (!access_ok(VERIFY_WRITE, ur, sizeof(*ur)))
246 return -EFAULT;
247
248 err = 0;
249 + err |= put_user(status, ustatus);
250 err |= __put_user(r.ru_utime.tv_sec, &ur->ru_utime.tv_sec);
251 err |= __put_user(r.ru_utime.tv_usec, &ur->ru_utime.tv_usec);
252 err |= __put_user(r.ru_stime.tv_sec, &ur->ru_stime.tv_sec);
253 @@ -1142,7 +1145,7 @@ arch_get_unmapped_area_1(unsigned long a
254 /* At this point: (!vma || addr < vma->vm_end). */
255 if (limit - len < addr)
256 return -ENOMEM;
257 - if (!vma || addr + len <= vma->vm_start)
258 + if (check_heap_stack_gap(vma, addr, len))
259 return addr;
260 addr = vma->vm_end;
261 vma = vma->vm_next;
262 @@ -1178,6 +1181,10 @@ arch_get_unmapped_area(struct file *filp
263 merely specific addresses, but regions of memory -- perhaps
264 this feature should be incorporated into all ports? */
265
266 +#ifdef CONFIG_PAX_RANDMMAP
267 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
268 +#endif
269 +
270 if (addr) {
271 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
272 if (addr != (unsigned long) -ENOMEM)
273 @@ -1185,8 +1192,8 @@ arch_get_unmapped_area(struct file *filp
274 }
275
276 /* Next, try allocating at TASK_UNMAPPED_BASE. */
277 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
278 - len, limit);
279 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
280 +
281 if (addr != (unsigned long) -ENOMEM)
282 return addr;
283
284 diff -urNp linux-2.6.39.2/arch/alpha/kernel/pci_iommu.c linux-2.6.39.2/arch/alpha/kernel/pci_iommu.c
285 --- linux-2.6.39.2/arch/alpha/kernel/pci_iommu.c 2011-05-19 00:06:34.000000000 -0400
286 +++ linux-2.6.39.2/arch/alpha/kernel/pci_iommu.c 2011-05-22 19:36:30.000000000 -0400
287 @@ -950,7 +950,7 @@ static int alpha_pci_set_mask(struct dev
288 return 0;
289 }
290
291 -struct dma_map_ops alpha_pci_ops = {
292 +const struct dma_map_ops alpha_pci_ops = {
293 .alloc_coherent = alpha_pci_alloc_coherent,
294 .free_coherent = alpha_pci_free_coherent,
295 .map_page = alpha_pci_map_page,
296 @@ -962,5 +962,5 @@ struct dma_map_ops alpha_pci_ops = {
297 .set_dma_mask = alpha_pci_set_mask,
298 };
299
300 -struct dma_map_ops *dma_ops = &alpha_pci_ops;
301 +const struct dma_map_ops *dma_ops = &alpha_pci_ops;
302 EXPORT_SYMBOL(dma_ops);
303 diff -urNp linux-2.6.39.2/arch/alpha/kernel/pci-noop.c linux-2.6.39.2/arch/alpha/kernel/pci-noop.c
304 --- linux-2.6.39.2/arch/alpha/kernel/pci-noop.c 2011-05-19 00:06:34.000000000 -0400
305 +++ linux-2.6.39.2/arch/alpha/kernel/pci-noop.c 2011-05-22 19:36:30.000000000 -0400
306 @@ -173,7 +173,7 @@ static int alpha_noop_set_mask(struct de
307 return 0;
308 }
309
310 -struct dma_map_ops alpha_noop_ops = {
311 +const struct dma_map_ops alpha_noop_ops = {
312 .alloc_coherent = alpha_noop_alloc_coherent,
313 .free_coherent = alpha_noop_free_coherent,
314 .map_page = alpha_noop_map_page,
315 @@ -183,7 +183,7 @@ struct dma_map_ops alpha_noop_ops = {
316 .set_dma_mask = alpha_noop_set_mask,
317 };
318
319 -struct dma_map_ops *dma_ops = &alpha_noop_ops;
320 +const struct dma_map_ops *dma_ops = &alpha_noop_ops;
321 EXPORT_SYMBOL(dma_ops);
322
323 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
324 diff -urNp linux-2.6.39.2/arch/alpha/kernel/proto.h linux-2.6.39.2/arch/alpha/kernel/proto.h
325 --- linux-2.6.39.2/arch/alpha/kernel/proto.h 2011-05-19 00:06:34.000000000 -0400
326 +++ linux-2.6.39.2/arch/alpha/kernel/proto.h 2011-05-22 19:36:30.000000000 -0400
327 @@ -17,14 +17,14 @@ struct pci_dev;
328 struct pci_controller;
329
330 /* core_apecs.c */
331 -extern struct pci_ops apecs_pci_ops;
332 +extern const struct pci_ops apecs_pci_ops;
333 extern void apecs_init_arch(void);
334 extern void apecs_pci_clr_err(void);
335 extern void apecs_machine_check(unsigned long vector, unsigned long la_ptr);
336 extern void apecs_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
337
338 /* core_cia.c */
339 -extern struct pci_ops cia_pci_ops;
340 +extern const struct pci_ops cia_pci_ops;
341 extern void cia_init_pci(void);
342 extern void cia_init_arch(void);
343 extern void pyxis_init_arch(void);
344 @@ -33,19 +33,19 @@ extern void cia_machine_check(unsigned l
345 extern void cia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
346
347 /* core_irongate.c */
348 -extern struct pci_ops irongate_pci_ops;
349 +extern const struct pci_ops irongate_pci_ops;
350 extern int irongate_pci_clr_err(void);
351 extern void irongate_init_arch(void);
352 #define irongate_pci_tbi ((void *)0)
353
354 /* core_lca.c */
355 -extern struct pci_ops lca_pci_ops;
356 +extern const struct pci_ops lca_pci_ops;
357 extern void lca_init_arch(void);
358 extern void lca_machine_check(unsigned long vector, unsigned long la_ptr);
359 extern void lca_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
360
361 /* core_marvel.c */
362 -extern struct pci_ops marvel_pci_ops;
363 +extern const struct pci_ops marvel_pci_ops;
364 extern void marvel_init_arch(void);
365 extern void marvel_kill_arch(int);
366 extern void marvel_machine_check(unsigned long, unsigned long);
367 @@ -60,14 +60,14 @@ struct io7 *marvel_next_io7(struct io7 *
368 void io7_clear_errors(struct io7 *io7);
369
370 /* core_mcpcia.c */
371 -extern struct pci_ops mcpcia_pci_ops;
372 +extern const struct pci_ops mcpcia_pci_ops;
373 extern void mcpcia_init_arch(void);
374 extern void mcpcia_init_hoses(void);
375 extern void mcpcia_machine_check(unsigned long vector, unsigned long la_ptr);
376 extern void mcpcia_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
377
378 /* core_polaris.c */
379 -extern struct pci_ops polaris_pci_ops;
380 +extern const struct pci_ops polaris_pci_ops;
381 extern int polaris_read_config_dword(struct pci_dev *, int, u32 *);
382 extern int polaris_write_config_dword(struct pci_dev *, int, u32);
383 extern void polaris_init_arch(void);
384 @@ -75,14 +75,14 @@ extern void polaris_machine_check(unsign
385 #define polaris_pci_tbi ((void *)0)
386
387 /* core_t2.c */
388 -extern struct pci_ops t2_pci_ops;
389 +extern const struct pci_ops t2_pci_ops;
390 extern void t2_init_arch(void);
391 extern void t2_kill_arch(int);
392 extern void t2_machine_check(unsigned long vector, unsigned long la_ptr);
393 extern void t2_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
394
395 /* core_titan.c */
396 -extern struct pci_ops titan_pci_ops;
397 +extern const struct pci_ops titan_pci_ops;
398 extern void titan_init_arch(void);
399 extern void titan_kill_arch(int);
400 extern void titan_machine_check(unsigned long, unsigned long);
401 @@ -90,14 +90,14 @@ extern void titan_pci_tbi(struct pci_con
402 extern struct _alpha_agp_info *titan_agp_info(void);
403
404 /* core_tsunami.c */
405 -extern struct pci_ops tsunami_pci_ops;
406 +extern const struct pci_ops tsunami_pci_ops;
407 extern void tsunami_init_arch(void);
408 extern void tsunami_kill_arch(int);
409 extern void tsunami_machine_check(unsigned long vector, unsigned long la_ptr);
410 extern void tsunami_pci_tbi(struct pci_controller *, dma_addr_t, dma_addr_t);
411
412 /* core_wildfire.c */
413 -extern struct pci_ops wildfire_pci_ops;
414 +extern const struct pci_ops wildfire_pci_ops;
415 extern void wildfire_init_arch(void);
416 extern void wildfire_kill_arch(int);
417 extern void wildfire_machine_check(unsigned long vector, unsigned long la_ptr);
418 diff -urNp linux-2.6.39.2/arch/alpha/mm/fault.c linux-2.6.39.2/arch/alpha/mm/fault.c
419 --- linux-2.6.39.2/arch/alpha/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
420 +++ linux-2.6.39.2/arch/alpha/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
421 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
422 __reload_thread(pcb);
423 }
424
425 +#ifdef CONFIG_PAX_PAGEEXEC
426 +/*
427 + * PaX: decide what to do with offenders (regs->pc = fault address)
428 + *
429 + * returns 1 when task should be killed
430 + * 2 when patched PLT trampoline was detected
431 + * 3 when unpatched PLT trampoline was detected
432 + */
433 +static int pax_handle_fetch_fault(struct pt_regs *regs)
434 +{
435 +
436 +#ifdef CONFIG_PAX_EMUPLT
437 + int err;
438 +
439 + do { /* PaX: patched PLT emulation #1 */
440 + unsigned int ldah, ldq, jmp;
441 +
442 + err = get_user(ldah, (unsigned int *)regs->pc);
443 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
444 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
445 +
446 + if (err)
447 + break;
448 +
449 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
450 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
451 + jmp == 0x6BFB0000U)
452 + {
453 + unsigned long r27, addr;
454 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
455 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
456 +
457 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
458 + err = get_user(r27, (unsigned long *)addr);
459 + if (err)
460 + break;
461 +
462 + regs->r27 = r27;
463 + regs->pc = r27;
464 + return 2;
465 + }
466 + } while (0);
467 +
468 + do { /* PaX: patched PLT emulation #2 */
469 + unsigned int ldah, lda, br;
470 +
471 + err = get_user(ldah, (unsigned int *)regs->pc);
472 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
473 + err |= get_user(br, (unsigned int *)(regs->pc+8));
474 +
475 + if (err)
476 + break;
477 +
478 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
479 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
480 + (br & 0xFFE00000U) == 0xC3E00000U)
481 + {
482 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
483 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
484 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
485 +
486 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
487 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
488 + return 2;
489 + }
490 + } while (0);
491 +
492 + do { /* PaX: unpatched PLT emulation */
493 + unsigned int br;
494 +
495 + err = get_user(br, (unsigned int *)regs->pc);
496 +
497 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
498 + unsigned int br2, ldq, nop, jmp;
499 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
500 +
501 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
502 + err = get_user(br2, (unsigned int *)addr);
503 + err |= get_user(ldq, (unsigned int *)(addr+4));
504 + err |= get_user(nop, (unsigned int *)(addr+8));
505 + err |= get_user(jmp, (unsigned int *)(addr+12));
506 + err |= get_user(resolver, (unsigned long *)(addr+16));
507 +
508 + if (err)
509 + break;
510 +
511 + if (br2 == 0xC3600000U &&
512 + ldq == 0xA77B000CU &&
513 + nop == 0x47FF041FU &&
514 + jmp == 0x6B7B0000U)
515 + {
516 + regs->r28 = regs->pc+4;
517 + regs->r27 = addr+16;
518 + regs->pc = resolver;
519 + return 3;
520 + }
521 + }
522 + } while (0);
523 +#endif
524 +
525 + return 1;
526 +}
527 +
528 +void pax_report_insns(void *pc, void *sp)
529 +{
530 + unsigned long i;
531 +
532 + printk(KERN_ERR "PAX: bytes at PC: ");
533 + for (i = 0; i < 5; i++) {
534 + unsigned int c;
535 + if (get_user(c, (unsigned int *)pc+i))
536 + printk(KERN_CONT "???????? ");
537 + else
538 + printk(KERN_CONT "%08x ", c);
539 + }
540 + printk("\n");
541 +}
542 +#endif
543
544 /*
545 * This routine handles page faults. It determines the address,
546 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
547 good_area:
548 si_code = SEGV_ACCERR;
549 if (cause < 0) {
550 - if (!(vma->vm_flags & VM_EXEC))
551 + if (!(vma->vm_flags & VM_EXEC)) {
552 +
553 +#ifdef CONFIG_PAX_PAGEEXEC
554 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
555 + goto bad_area;
556 +
557 + up_read(&mm->mmap_sem);
558 + switch (pax_handle_fetch_fault(regs)) {
559 +
560 +#ifdef CONFIG_PAX_EMUPLT
561 + case 2:
562 + case 3:
563 + return;
564 +#endif
565 +
566 + }
567 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
568 + do_group_exit(SIGKILL);
569 +#else
570 goto bad_area;
571 +#endif
572 +
573 + }
574 } else if (!cause) {
575 /* Allow reads even for write-only mappings */
576 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
577 diff -urNp linux-2.6.39.2/arch/arm/common/it8152.c linux-2.6.39.2/arch/arm/common/it8152.c
578 --- linux-2.6.39.2/arch/arm/common/it8152.c 2011-05-19 00:06:34.000000000 -0400
579 +++ linux-2.6.39.2/arch/arm/common/it8152.c 2011-05-22 19:36:30.000000000 -0400
580 @@ -221,7 +221,7 @@ static int it8152_pci_write_config(struc
581 return PCIBIOS_SUCCESSFUL;
582 }
583
584 -static struct pci_ops it8152_ops = {
585 +static const struct pci_ops it8152_ops = {
586 .read = it8152_pci_read_config,
587 .write = it8152_pci_write_config,
588 };
589 diff -urNp linux-2.6.39.2/arch/arm/common/via82c505.c linux-2.6.39.2/arch/arm/common/via82c505.c
590 --- linux-2.6.39.2/arch/arm/common/via82c505.c 2011-05-19 00:06:34.000000000 -0400
591 +++ linux-2.6.39.2/arch/arm/common/via82c505.c 2011-05-22 19:36:30.000000000 -0400
592 @@ -52,7 +52,7 @@ via82c505_write_config(struct pci_bus *b
593 return PCIBIOS_SUCCESSFUL;
594 }
595
596 -static struct pci_ops via82c505_ops = {
597 +static const struct pci_ops via82c505_ops = {
598 .read = via82c505_read_config,
599 .write = via82c505_write_config,
600 };
601 diff -urNp linux-2.6.39.2/arch/arm/include/asm/cacheflush.h linux-2.6.39.2/arch/arm/include/asm/cacheflush.h
602 --- linux-2.6.39.2/arch/arm/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
603 +++ linux-2.6.39.2/arch/arm/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
604 @@ -115,7 +115,7 @@ struct cpu_cache_fns {
605 */
606 #ifdef MULTI_CACHE
607
608 -extern struct cpu_cache_fns cpu_cache;
609 +extern const struct cpu_cache_fns cpu_cache;
610
611 #define __cpuc_flush_icache_all cpu_cache.flush_icache_all
612 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
613 diff -urNp linux-2.6.39.2/arch/arm/include/asm/elf.h linux-2.6.39.2/arch/arm/include/asm/elf.h
614 --- linux-2.6.39.2/arch/arm/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
615 +++ linux-2.6.39.2/arch/arm/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
616 @@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t
617 the loader. We need to make sure that it is out of the way of the program
618 that it will "exec", and that there is sufficient room for the brk. */
619
620 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
621 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
622 +
623 +#ifdef CONFIG_PAX_ASLR
624 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
625 +
626 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
627 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
628 +#endif
629
630 /* When the program starts, a1 contains a pointer to a function to be
631 registered with atexit, as per the SVR4 ABI. A value of 0 means we
632 @@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t
633 extern void elf_set_personality(const struct elf32_hdr *);
634 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
635
636 -struct mm_struct;
637 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
638 -#define arch_randomize_brk arch_randomize_brk
639 -
640 extern int vectors_user_mapping(void);
641 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
642 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
643 diff -urNp linux-2.6.39.2/arch/arm/include/asm/kmap_types.h linux-2.6.39.2/arch/arm/include/asm/kmap_types.h
644 --- linux-2.6.39.2/arch/arm/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
645 +++ linux-2.6.39.2/arch/arm/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
646 @@ -21,6 +21,7 @@ enum km_type {
647 KM_L1_CACHE,
648 KM_L2_CACHE,
649 KM_KDB,
650 + KM_CLEARPAGE,
651 KM_TYPE_NR
652 };
653
654 diff -urNp linux-2.6.39.2/arch/arm/include/asm/outercache.h linux-2.6.39.2/arch/arm/include/asm/outercache.h
655 --- linux-2.6.39.2/arch/arm/include/asm/outercache.h 2011-05-19 00:06:34.000000000 -0400
656 +++ linux-2.6.39.2/arch/arm/include/asm/outercache.h 2011-05-22 19:36:30.000000000 -0400
657 @@ -38,7 +38,7 @@ struct outer_cache_fns {
658
659 #ifdef CONFIG_OUTER_CACHE
660
661 -extern struct outer_cache_fns outer_cache;
662 +extern const struct outer_cache_fns outer_cache;
663
664 static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
665 {
666 diff -urNp linux-2.6.39.2/arch/arm/include/asm/page.h linux-2.6.39.2/arch/arm/include/asm/page.h
667 --- linux-2.6.39.2/arch/arm/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
668 +++ linux-2.6.39.2/arch/arm/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
669 @@ -126,7 +126,7 @@ struct cpu_user_fns {
670 };
671
672 #ifdef MULTI_USER
673 -extern struct cpu_user_fns cpu_user;
674 +extern const struct cpu_user_fns cpu_user;
675
676 #define __cpu_clear_user_highpage cpu_user.cpu_clear_user_highpage
677 #define __cpu_copy_user_highpage cpu_user.cpu_copy_user_highpage
678 diff -urNp linux-2.6.39.2/arch/arm/include/asm/uaccess.h linux-2.6.39.2/arch/arm/include/asm/uaccess.h
679 --- linux-2.6.39.2/arch/arm/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
680 +++ linux-2.6.39.2/arch/arm/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
681 @@ -403,6 +403,9 @@ extern unsigned long __must_check __strn
682
683 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
684 {
685 + if ((long)n < 0)
686 + return n;
687 +
688 if (access_ok(VERIFY_READ, from, n))
689 n = __copy_from_user(to, from, n);
690 else /* security hole - plug it */
691 @@ -412,6 +415,9 @@ static inline unsigned long __must_check
692
693 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
694 {
695 + if ((long)n < 0)
696 + return n;
697 +
698 if (access_ok(VERIFY_WRITE, to, n))
699 n = __copy_to_user(to, from, n);
700 return n;
701 diff -urNp linux-2.6.39.2/arch/arm/kernel/kgdb.c linux-2.6.39.2/arch/arm/kernel/kgdb.c
702 --- linux-2.6.39.2/arch/arm/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
703 +++ linux-2.6.39.2/arch/arm/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
704 @@ -246,7 +246,7 @@ void kgdb_arch_exit(void)
705 * and we handle the normal undef case within the do_undefinstr
706 * handler.
707 */
708 -struct kgdb_arch arch_kgdb_ops = {
709 +const struct kgdb_arch arch_kgdb_ops = {
710 #ifndef __ARMEB__
711 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
712 #else /* ! __ARMEB__ */
713 diff -urNp linux-2.6.39.2/arch/arm/kernel/process.c linux-2.6.39.2/arch/arm/kernel/process.c
714 --- linux-2.6.39.2/arch/arm/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
715 +++ linux-2.6.39.2/arch/arm/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
716 @@ -28,7 +28,6 @@
717 #include <linux/tick.h>
718 #include <linux/utsname.h>
719 #include <linux/uaccess.h>
720 -#include <linux/random.h>
721 #include <linux/hw_breakpoint.h>
722
723 #include <asm/cacheflush.h>
724 @@ -479,12 +478,6 @@ unsigned long get_wchan(struct task_stru
725 return 0;
726 }
727
728 -unsigned long arch_randomize_brk(struct mm_struct *mm)
729 -{
730 - unsigned long range_end = mm->brk + 0x02000000;
731 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
732 -}
733 -
734 #ifdef CONFIG_MMU
735 /*
736 * The vectors page is always readable from user space for the
737 diff -urNp linux-2.6.39.2/arch/arm/kernel/traps.c linux-2.6.39.2/arch/arm/kernel/traps.c
738 --- linux-2.6.39.2/arch/arm/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
739 +++ linux-2.6.39.2/arch/arm/kernel/traps.c 2011-06-13 21:30:34.000000000 -0400
740 @@ -258,6 +258,8 @@ static int __die(const char *str, int er
741
742 static DEFINE_SPINLOCK(die_lock);
743
744 +extern void gr_handle_kernel_exploit(void);
745 +
746 /*
747 * This function is protected against re-entrancy.
748 */
749 @@ -285,6 +287,9 @@ void die(const char *str, struct pt_regs
750 panic("Fatal exception in interrupt");
751 if (panic_on_oops)
752 panic("Fatal exception");
753 +
754 + gr_handle_kernel_exploit();
755 +
756 if (ret != NOTIFY_STOP)
757 do_exit(SIGSEGV);
758 }
759 diff -urNp linux-2.6.39.2/arch/arm/mach-cns3xxx/pcie.c linux-2.6.39.2/arch/arm/mach-cns3xxx/pcie.c
760 --- linux-2.6.39.2/arch/arm/mach-cns3xxx/pcie.c 2011-05-19 00:06:34.000000000 -0400
761 +++ linux-2.6.39.2/arch/arm/mach-cns3xxx/pcie.c 2011-05-22 19:36:30.000000000 -0400
762 @@ -162,7 +162,7 @@ static int cns3xxx_pci_setup(int nr, str
763 return 1;
764 }
765
766 -static struct pci_ops cns3xxx_pcie_ops = {
767 +static const struct pci_ops cns3xxx_pcie_ops = {
768 .read = cns3xxx_pci_read_config,
769 .write = cns3xxx_pci_write_config,
770 };
771 diff -urNp linux-2.6.39.2/arch/arm/mach-dove/pcie.c linux-2.6.39.2/arch/arm/mach-dove/pcie.c
772 --- linux-2.6.39.2/arch/arm/mach-dove/pcie.c 2011-05-19 00:06:34.000000000 -0400
773 +++ linux-2.6.39.2/arch/arm/mach-dove/pcie.c 2011-05-22 19:36:30.000000000 -0400
774 @@ -155,7 +155,7 @@ static int pcie_wr_conf(struct pci_bus *
775 return ret;
776 }
777
778 -static struct pci_ops pcie_ops = {
779 +static const struct pci_ops pcie_ops = {
780 .read = pcie_rd_conf,
781 .write = pcie_wr_conf,
782 };
783 diff -urNp linux-2.6.39.2/arch/arm/mach-footbridge/dc21285.c linux-2.6.39.2/arch/arm/mach-footbridge/dc21285.c
784 --- linux-2.6.39.2/arch/arm/mach-footbridge/dc21285.c 2011-05-19 00:06:34.000000000 -0400
785 +++ linux-2.6.39.2/arch/arm/mach-footbridge/dc21285.c 2011-05-22 19:36:30.000000000 -0400
786 @@ -129,7 +129,7 @@ dc21285_write_config(struct pci_bus *bus
787 return PCIBIOS_SUCCESSFUL;
788 }
789
790 -static struct pci_ops dc21285_ops = {
791 +static const struct pci_ops dc21285_ops = {
792 .read = dc21285_read_config,
793 .write = dc21285_write_config,
794 };
795 diff -urNp linux-2.6.39.2/arch/arm/mach-integrator/pci_v3.c linux-2.6.39.2/arch/arm/mach-integrator/pci_v3.c
796 --- linux-2.6.39.2/arch/arm/mach-integrator/pci_v3.c 2011-05-19 00:06:34.000000000 -0400
797 +++ linux-2.6.39.2/arch/arm/mach-integrator/pci_v3.c 2011-05-22 19:36:30.000000000 -0400
798 @@ -340,7 +340,7 @@ static int v3_write_config(struct pci_bu
799 return PCIBIOS_SUCCESSFUL;
800 }
801
802 -static struct pci_ops pci_v3_ops = {
803 +static const struct pci_ops pci_v3_ops = {
804 .read = v3_read_config,
805 .write = v3_write_config,
806 };
807 diff -urNp linux-2.6.39.2/arch/arm/mach-iop13xx/pci.c linux-2.6.39.2/arch/arm/mach-iop13xx/pci.c
808 --- linux-2.6.39.2/arch/arm/mach-iop13xx/pci.c 2011-05-19 00:06:34.000000000 -0400
809 +++ linux-2.6.39.2/arch/arm/mach-iop13xx/pci.c 2011-05-22 19:36:30.000000000 -0400
810 @@ -324,7 +324,7 @@ iop13xx_atux_write_config(struct pci_bus
811 return PCIBIOS_SUCCESSFUL;
812 }
813
814 -static struct pci_ops iop13xx_atux_ops = {
815 +static const struct pci_ops iop13xx_atux_ops = {
816 .read = iop13xx_atux_read_config,
817 .write = iop13xx_atux_write_config,
818 };
819 @@ -471,7 +471,7 @@ iop13xx_atue_write_config(struct pci_bus
820 return PCIBIOS_SUCCESSFUL;
821 }
822
823 -static struct pci_ops iop13xx_atue_ops = {
824 +static const struct pci_ops iop13xx_atue_ops = {
825 .read = iop13xx_atue_read_config,
826 .write = iop13xx_atue_write_config,
827 };
828 diff -urNp linux-2.6.39.2/arch/arm/mach-ixp2000/enp2611.c linux-2.6.39.2/arch/arm/mach-ixp2000/enp2611.c
829 --- linux-2.6.39.2/arch/arm/mach-ixp2000/enp2611.c 2011-05-19 00:06:34.000000000 -0400
830 +++ linux-2.6.39.2/arch/arm/mach-ixp2000/enp2611.c 2011-05-22 19:36:30.000000000 -0400
831 @@ -137,7 +137,7 @@ static int enp2611_pci_write_config(stru
832 return PCIBIOS_DEVICE_NOT_FOUND;
833 }
834
835 -static struct pci_ops enp2611_pci_ops = {
836 +static const struct pci_ops enp2611_pci_ops = {
837 .read = enp2611_pci_read_config,
838 .write = enp2611_pci_write_config
839 };
840 diff -urNp linux-2.6.39.2/arch/arm/mach-ixp2000/pci.c linux-2.6.39.2/arch/arm/mach-ixp2000/pci.c
841 --- linux-2.6.39.2/arch/arm/mach-ixp2000/pci.c 2011-05-19 00:06:34.000000000 -0400
842 +++ linux-2.6.39.2/arch/arm/mach-ixp2000/pci.c 2011-05-22 19:36:30.000000000 -0400
843 @@ -125,7 +125,7 @@ int ixp2000_pci_write_config(struct pci_
844 }
845
846
847 -static struct pci_ops ixp2000_pci_ops = {
848 +static const struct pci_ops ixp2000_pci_ops = {
849 .read = ixp2000_pci_read_config,
850 .write = ixp2000_pci_write_config
851 };
852 diff -urNp linux-2.6.39.2/arch/arm/mach-ixp23xx/pci.c linux-2.6.39.2/arch/arm/mach-ixp23xx/pci.c
853 --- linux-2.6.39.2/arch/arm/mach-ixp23xx/pci.c 2011-05-19 00:06:34.000000000 -0400
854 +++ linux-2.6.39.2/arch/arm/mach-ixp23xx/pci.c 2011-05-22 19:36:30.000000000 -0400
855 @@ -136,7 +136,7 @@ static int ixp23xx_pci_write_config(stru
856 return PCIBIOS_SUCCESSFUL;
857 }
858
859 -struct pci_ops ixp23xx_pci_ops = {
860 +const struct pci_ops ixp23xx_pci_ops = {
861 .read = ixp23xx_pci_read_config,
862 .write = ixp23xx_pci_write_config,
863 };
864 diff -urNp linux-2.6.39.2/arch/arm/mach-ixp4xx/common-pci.c linux-2.6.39.2/arch/arm/mach-ixp4xx/common-pci.c
865 --- linux-2.6.39.2/arch/arm/mach-ixp4xx/common-pci.c 2011-05-19 00:06:34.000000000 -0400
866 +++ linux-2.6.39.2/arch/arm/mach-ixp4xx/common-pci.c 2011-05-22 19:36:30.000000000 -0400
867 @@ -283,7 +283,7 @@ static int ixp4xx_pci_write_config(struc
868 return PCIBIOS_SUCCESSFUL;
869 }
870
871 -struct pci_ops ixp4xx_ops = {
872 +const struct pci_ops ixp4xx_ops = {
873 .read = ixp4xx_pci_read_config,
874 .write = ixp4xx_pci_write_config,
875 };
876 diff -urNp linux-2.6.39.2/arch/arm/mach-kirkwood/pcie.c linux-2.6.39.2/arch/arm/mach-kirkwood/pcie.c
877 --- linux-2.6.39.2/arch/arm/mach-kirkwood/pcie.c 2011-05-19 00:06:34.000000000 -0400
878 +++ linux-2.6.39.2/arch/arm/mach-kirkwood/pcie.c 2011-05-22 19:36:30.000000000 -0400
879 @@ -111,7 +111,7 @@ static int pcie_wr_conf(struct pci_bus *
880 return ret;
881 }
882
883 -static struct pci_ops pcie_ops = {
884 +static const struct pci_ops pcie_ops = {
885 .read = pcie_rd_conf,
886 .write = pcie_wr_conf,
887 };
888 diff -urNp linux-2.6.39.2/arch/arm/mach-ks8695/pci.c linux-2.6.39.2/arch/arm/mach-ks8695/pci.c
889 --- linux-2.6.39.2/arch/arm/mach-ks8695/pci.c 2011-05-19 00:06:34.000000000 -0400
890 +++ linux-2.6.39.2/arch/arm/mach-ks8695/pci.c 2011-05-22 19:36:30.000000000 -0400
891 @@ -136,7 +136,7 @@ static void ks8695_local_writeconfig(int
892 __raw_writel(value, KS8695_PCI_VA + KS8695_PBCD);
893 }
894
895 -static struct pci_ops ks8695_pci_ops = {
896 +static const struct pci_ops ks8695_pci_ops = {
897 .read = ks8695_pci_readconfig,
898 .write = ks8695_pci_writeconfig,
899 };
900 diff -urNp linux-2.6.39.2/arch/arm/mach-mmp/clock.c linux-2.6.39.2/arch/arm/mach-mmp/clock.c
901 --- linux-2.6.39.2/arch/arm/mach-mmp/clock.c 2011-05-19 00:06:34.000000000 -0400
902 +++ linux-2.6.39.2/arch/arm/mach-mmp/clock.c 2011-05-22 19:36:30.000000000 -0400
903 @@ -29,7 +29,7 @@ static void apbc_clk_disable(struct clk
904 __raw_writel(0, clk->clk_rst);
905 }
906
907 -struct clkops apbc_clk_ops = {
908 +const struct clkops apbc_clk_ops = {
909 .enable = apbc_clk_enable,
910 .disable = apbc_clk_disable,
911 };
912 @@ -44,7 +44,7 @@ static void apmu_clk_disable(struct clk
913 __raw_writel(0, clk->clk_rst);
914 }
915
916 -struct clkops apmu_clk_ops = {
917 +const struct clkops apmu_clk_ops = {
918 .enable = apmu_clk_enable,
919 .disable = apmu_clk_disable,
920 };
921 diff -urNp linux-2.6.39.2/arch/arm/mach-msm/iommu.c linux-2.6.39.2/arch/arm/mach-msm/iommu.c
922 --- linux-2.6.39.2/arch/arm/mach-msm/iommu.c 2011-05-19 00:06:34.000000000 -0400
923 +++ linux-2.6.39.2/arch/arm/mach-msm/iommu.c 2011-05-22 19:36:30.000000000 -0400
924 @@ -669,7 +669,7 @@ fail:
925 return 0;
926 }
927
928 -static struct iommu_ops msm_iommu_ops = {
929 +static const struct iommu_ops msm_iommu_ops = {
930 .domain_init = msm_iommu_domain_init,
931 .domain_destroy = msm_iommu_domain_destroy,
932 .attach_dev = msm_iommu_attach_dev,
933 diff -urNp linux-2.6.39.2/arch/arm/mach-msm/last_radio_log.c linux-2.6.39.2/arch/arm/mach-msm/last_radio_log.c
934 --- linux-2.6.39.2/arch/arm/mach-msm/last_radio_log.c 2011-05-19 00:06:34.000000000 -0400
935 +++ linux-2.6.39.2/arch/arm/mach-msm/last_radio_log.c 2011-05-22 19:36:30.000000000 -0400
936 @@ -48,6 +48,7 @@ static ssize_t last_radio_log_read(struc
937 }
938
939 static struct file_operations last_radio_log_fops = {
940 + /* cannot be const, see msm_init_last_radio_log */
941 .read = last_radio_log_read,
942 .llseek = default_llseek,
943 };
944 diff -urNp linux-2.6.39.2/arch/arm/mach-mv78xx0/pcie.c linux-2.6.39.2/arch/arm/mach-mv78xx0/pcie.c
945 --- linux-2.6.39.2/arch/arm/mach-mv78xx0/pcie.c 2011-05-19 00:06:34.000000000 -0400
946 +++ linux-2.6.39.2/arch/arm/mach-mv78xx0/pcie.c 2011-05-22 19:36:30.000000000 -0400
947 @@ -222,7 +222,7 @@ static int pcie_wr_conf(struct pci_bus *
948 return ret;
949 }
950
951 -static struct pci_ops pcie_ops = {
952 +static const struct pci_ops pcie_ops = {
953 .read = pcie_rd_conf,
954 .write = pcie_wr_conf,
955 };
956 diff -urNp linux-2.6.39.2/arch/arm/mach-orion5x/pci.c linux-2.6.39.2/arch/arm/mach-orion5x/pci.c
957 --- linux-2.6.39.2/arch/arm/mach-orion5x/pci.c 2011-05-19 00:06:34.000000000 -0400
958 +++ linux-2.6.39.2/arch/arm/mach-orion5x/pci.c 2011-05-22 19:36:30.000000000 -0400
959 @@ -130,7 +130,7 @@ static int pcie_wr_conf(struct pci_bus *
960 return ret;
961 }
962
963 -static struct pci_ops pcie_ops = {
964 +static const struct pci_ops pcie_ops = {
965 .read = pcie_rd_conf,
966 .write = pcie_wr_conf,
967 };
968 @@ -368,7 +368,7 @@ static int orion5x_pci_wr_conf(struct pc
969 PCI_FUNC(devfn), where, size, val);
970 }
971
972 -static struct pci_ops pci_ops = {
973 +static const struct pci_ops pci_ops = {
974 .read = orion5x_pci_rd_conf,
975 .write = orion5x_pci_wr_conf,
976 };
977 diff -urNp linux-2.6.39.2/arch/arm/mach-sa1100/pci-nanoengine.c linux-2.6.39.2/arch/arm/mach-sa1100/pci-nanoengine.c
978 --- linux-2.6.39.2/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-19 00:06:34.000000000 -0400
979 +++ linux-2.6.39.2/arch/arm/mach-sa1100/pci-nanoengine.c 2011-05-22 19:36:30.000000000 -0400
980 @@ -117,7 +117,7 @@ static int nanoengine_write_config(struc
981 return PCIBIOS_SUCCESSFUL;
982 }
983
984 -static struct pci_ops pci_nano_ops = {
985 +static const struct pci_ops pci_nano_ops = {
986 .read = nanoengine_read_config,
987 .write = nanoengine_write_config,
988 };
989 diff -urNp linux-2.6.39.2/arch/arm/mach-tegra/pcie.c linux-2.6.39.2/arch/arm/mach-tegra/pcie.c
990 --- linux-2.6.39.2/arch/arm/mach-tegra/pcie.c 2011-05-19 00:06:34.000000000 -0400
991 +++ linux-2.6.39.2/arch/arm/mach-tegra/pcie.c 2011-05-22 19:36:30.000000000 -0400
992 @@ -336,7 +336,7 @@ static int tegra_pcie_write_conf(struct
993 return PCIBIOS_SUCCESSFUL;
994 }
995
996 -static struct pci_ops tegra_pcie_ops = {
997 +static const struct pci_ops tegra_pcie_ops = {
998 .read = tegra_pcie_read_conf,
999 .write = tegra_pcie_write_conf,
1000 };
1001 diff -urNp linux-2.6.39.2/arch/arm/mach-ux500/mbox-db5500.c linux-2.6.39.2/arch/arm/mach-ux500/mbox-db5500.c
1002 --- linux-2.6.39.2/arch/arm/mach-ux500/mbox-db5500.c 2011-05-19 00:06:34.000000000 -0400
1003 +++ linux-2.6.39.2/arch/arm/mach-ux500/mbox-db5500.c 2011-05-22 19:41:32.000000000 -0400
1004 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct dev
1005 return sprintf(buf, "0x%X\n", mbox_value);
1006 }
1007
1008 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1009 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1010
1011 static int mbox_show(struct seq_file *s, void *data)
1012 {
1013 diff -urNp linux-2.6.39.2/arch/arm/mach-versatile/pci.c linux-2.6.39.2/arch/arm/mach-versatile/pci.c
1014 --- linux-2.6.39.2/arch/arm/mach-versatile/pci.c 2011-05-19 00:06:34.000000000 -0400
1015 +++ linux-2.6.39.2/arch/arm/mach-versatile/pci.c 2011-05-22 19:36:30.000000000 -0400
1016 @@ -165,7 +165,7 @@ static int versatile_write_config(struct
1017 return PCIBIOS_SUCCESSFUL;
1018 }
1019
1020 -static struct pci_ops pci_versatile_ops = {
1021 +static const struct pci_ops pci_versatile_ops = {
1022 .read = versatile_read_config,
1023 .write = versatile_write_config,
1024 };
1025 diff -urNp linux-2.6.39.2/arch/arm/mm/fault.c linux-2.6.39.2/arch/arm/mm/fault.c
1026 --- linux-2.6.39.2/arch/arm/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1027 +++ linux-2.6.39.2/arch/arm/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1028 @@ -182,6 +182,13 @@ __do_user_fault(struct task_struct *tsk,
1029 }
1030 #endif
1031
1032 +#ifdef CONFIG_PAX_PAGEEXEC
1033 + if (fsr & FSR_LNX_PF) {
1034 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1035 + do_group_exit(SIGKILL);
1036 + }
1037 +#endif
1038 +
1039 tsk->thread.address = addr;
1040 tsk->thread.error_code = fsr;
1041 tsk->thread.trap_no = 14;
1042 @@ -379,6 +386,33 @@ do_page_fault(unsigned long addr, unsign
1043 }
1044 #endif /* CONFIG_MMU */
1045
1046 +#ifdef CONFIG_PAX_PAGEEXEC
1047 +void pax_report_insns(void *pc, void *sp)
1048 +{
1049 + long i;
1050 +
1051 + printk(KERN_ERR "PAX: bytes at PC: ");
1052 + for (i = 0; i < 20; i++) {
1053 + unsigned char c;
1054 + if (get_user(c, (__force unsigned char __user *)pc+i))
1055 + printk(KERN_CONT "?? ");
1056 + else
1057 + printk(KERN_CONT "%02x ", c);
1058 + }
1059 + printk("\n");
1060 +
1061 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1062 + for (i = -1; i < 20; i++) {
1063 + unsigned long c;
1064 + if (get_user(c, (__force unsigned long __user *)sp+i))
1065 + printk(KERN_CONT "???????? ");
1066 + else
1067 + printk(KERN_CONT "%08lx ", c);
1068 + }
1069 + printk("\n");
1070 +}
1071 +#endif
1072 +
1073 /*
1074 * First Level Translation Fault Handler
1075 *
1076 diff -urNp linux-2.6.39.2/arch/arm/mm/mmap.c linux-2.6.39.2/arch/arm/mm/mmap.c
1077 --- linux-2.6.39.2/arch/arm/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
1078 +++ linux-2.6.39.2/arch/arm/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
1079 @@ -65,6 +65,10 @@ arch_get_unmapped_area(struct file *filp
1080 if (len > TASK_SIZE)
1081 return -ENOMEM;
1082
1083 +#ifdef CONFIG_PAX_RANDMMAP
1084 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1085 +#endif
1086 +
1087 if (addr) {
1088 if (do_align)
1089 addr = COLOUR_ALIGN(addr, pgoff);
1090 @@ -72,15 +76,14 @@ arch_get_unmapped_area(struct file *filp
1091 addr = PAGE_ALIGN(addr);
1092
1093 vma = find_vma(mm, addr);
1094 - if (TASK_SIZE - len >= addr &&
1095 - (!vma || addr + len <= vma->vm_start))
1096 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1097 return addr;
1098 }
1099 if (len > mm->cached_hole_size) {
1100 - start_addr = addr = mm->free_area_cache;
1101 + start_addr = addr = mm->free_area_cache;
1102 } else {
1103 - start_addr = addr = TASK_UNMAPPED_BASE;
1104 - mm->cached_hole_size = 0;
1105 + start_addr = addr = mm->mmap_base;
1106 + mm->cached_hole_size = 0;
1107 }
1108 /* 8 bits of randomness in 20 address space bits */
1109 if ((current->flags & PF_RANDOMIZE) &&
1110 @@ -100,14 +103,14 @@ full_search:
1111 * Start a new search - just in case we missed
1112 * some holes.
1113 */
1114 - if (start_addr != TASK_UNMAPPED_BASE) {
1115 - start_addr = addr = TASK_UNMAPPED_BASE;
1116 + if (start_addr != mm->mmap_base) {
1117 + start_addr = addr = mm->mmap_base;
1118 mm->cached_hole_size = 0;
1119 goto full_search;
1120 }
1121 return -ENOMEM;
1122 }
1123 - if (!vma || addr + len <= vma->vm_start) {
1124 + if (check_heap_stack_gap(vma, addr, len)) {
1125 /*
1126 * Remember the place where we stopped the search:
1127 */
1128 diff -urNp linux-2.6.39.2/arch/arm/plat-iop/pci.c linux-2.6.39.2/arch/arm/plat-iop/pci.c
1129 --- linux-2.6.39.2/arch/arm/plat-iop/pci.c 2011-05-19 00:06:34.000000000 -0400
1130 +++ linux-2.6.39.2/arch/arm/plat-iop/pci.c 2011-05-22 19:36:30.000000000 -0400
1131 @@ -161,7 +161,7 @@ iop3xx_write_config(struct pci_bus *bus,
1132 return PCIBIOS_SUCCESSFUL;
1133 }
1134
1135 -static struct pci_ops iop3xx_ops = {
1136 +static const struct pci_ops iop3xx_ops = {
1137 .read = iop3xx_read_config,
1138 .write = iop3xx_write_config,
1139 };
1140 diff -urNp linux-2.6.39.2/arch/avr32/include/asm/elf.h linux-2.6.39.2/arch/avr32/include/asm/elf.h
1141 --- linux-2.6.39.2/arch/avr32/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1142 +++ linux-2.6.39.2/arch/avr32/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1143 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpreg
1144 the loader. We need to make sure that it is out of the way of the program
1145 that it will "exec", and that there is sufficient room for the brk. */
1146
1147 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1148 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1149
1150 +#ifdef CONFIG_PAX_ASLR
1151 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1152 +
1153 +#define PAX_DELTA_MMAP_LEN 15
1154 +#define PAX_DELTA_STACK_LEN 15
1155 +#endif
1156
1157 /* This yields a mask that user programs can use to figure out what
1158 instruction set this CPU supports. This could be done in user space,
1159 diff -urNp linux-2.6.39.2/arch/avr32/include/asm/kmap_types.h linux-2.6.39.2/arch/avr32/include/asm/kmap_types.h
1160 --- linux-2.6.39.2/arch/avr32/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1161 +++ linux-2.6.39.2/arch/avr32/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1162 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1163 D(11) KM_IRQ1,
1164 D(12) KM_SOFTIRQ0,
1165 D(13) KM_SOFTIRQ1,
1166 -D(14) KM_TYPE_NR
1167 +D(14) KM_CLEARPAGE,
1168 +D(15) KM_TYPE_NR
1169 };
1170
1171 #undef D
1172 diff -urNp linux-2.6.39.2/arch/avr32/mm/fault.c linux-2.6.39.2/arch/avr32/mm/fault.c
1173 --- linux-2.6.39.2/arch/avr32/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1174 +++ linux-2.6.39.2/arch/avr32/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1175 @@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
1176
1177 int exception_trace = 1;
1178
1179 +#ifdef CONFIG_PAX_PAGEEXEC
1180 +void pax_report_insns(void *pc, void *sp)
1181 +{
1182 + unsigned long i;
1183 +
1184 + printk(KERN_ERR "PAX: bytes at PC: ");
1185 + for (i = 0; i < 20; i++) {
1186 + unsigned char c;
1187 + if (get_user(c, (unsigned char *)pc+i))
1188 + printk(KERN_CONT "???????? ");
1189 + else
1190 + printk(KERN_CONT "%02x ", c);
1191 + }
1192 + printk("\n");
1193 +}
1194 +#endif
1195 +
1196 /*
1197 * This routine handles page faults. It determines the address and the
1198 * problem, and then passes it off to one of the appropriate routines.
1199 @@ -156,6 +173,16 @@ bad_area:
1200 up_read(&mm->mmap_sem);
1201
1202 if (user_mode(regs)) {
1203 +
1204 +#ifdef CONFIG_PAX_PAGEEXEC
1205 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1206 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1207 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1208 + do_group_exit(SIGKILL);
1209 + }
1210 + }
1211 +#endif
1212 +
1213 if (exception_trace && printk_ratelimit())
1214 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1215 "sp %08lx ecr %lu\n",
1216 diff -urNp linux-2.6.39.2/arch/blackfin/kernel/kgdb.c linux-2.6.39.2/arch/blackfin/kernel/kgdb.c
1217 --- linux-2.6.39.2/arch/blackfin/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1218 +++ linux-2.6.39.2/arch/blackfin/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1219 @@ -420,7 +420,7 @@ int kgdb_arch_handle_exception(int vecto
1220 return -1; /* this means that we do not want to exit from the handler */
1221 }
1222
1223 -struct kgdb_arch arch_kgdb_ops = {
1224 +const struct kgdb_arch arch_kgdb_ops = {
1225 .gdb_bpt_instr = {0xa1},
1226 .flags = KGDB_HW_BREAKPOINT,
1227 .set_hw_breakpoint = bfin_set_hw_break,
1228 diff -urNp linux-2.6.39.2/arch/blackfin/mm/maccess.c linux-2.6.39.2/arch/blackfin/mm/maccess.c
1229 --- linux-2.6.39.2/arch/blackfin/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
1230 +++ linux-2.6.39.2/arch/blackfin/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
1231 @@ -16,7 +16,7 @@ static int validate_memory_access_addres
1232 return bfin_mem_access_type(addr, size);
1233 }
1234
1235 -long probe_kernel_read(void *dst, void *src, size_t size)
1236 +long probe_kernel_read(void *dst, const void *src, size_t size)
1237 {
1238 unsigned long lsrc = (unsigned long)src;
1239 int mem_type;
1240 @@ -55,7 +55,7 @@ long probe_kernel_read(void *dst, void *
1241 return -EFAULT;
1242 }
1243
1244 -long probe_kernel_write(void *dst, void *src, size_t size)
1245 +long probe_kernel_write(void *dst, const void *src, size_t size)
1246 {
1247 unsigned long ldst = (unsigned long)dst;
1248 int mem_type;
1249 diff -urNp linux-2.6.39.2/arch/frv/include/asm/kmap_types.h linux-2.6.39.2/arch/frv/include/asm/kmap_types.h
1250 --- linux-2.6.39.2/arch/frv/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
1251 +++ linux-2.6.39.2/arch/frv/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
1252 @@ -23,6 +23,7 @@ enum km_type {
1253 KM_IRQ1,
1254 KM_SOFTIRQ0,
1255 KM_SOFTIRQ1,
1256 + KM_CLEARPAGE,
1257 KM_TYPE_NR
1258 };
1259
1260 diff -urNp linux-2.6.39.2/arch/frv/mb93090-mb00/pci-frv.h linux-2.6.39.2/arch/frv/mb93090-mb00/pci-frv.h
1261 --- linux-2.6.39.2/arch/frv/mb93090-mb00/pci-frv.h 2011-05-19 00:06:34.000000000 -0400
1262 +++ linux-2.6.39.2/arch/frv/mb93090-mb00/pci-frv.h 2011-05-22 19:36:30.000000000 -0400
1263 @@ -34,7 +34,7 @@ void pcibios_resource_survey(void);
1264
1265 extern int __nongpreldata pcibios_last_bus;
1266 extern struct pci_bus *__nongpreldata pci_root_bus;
1267 -extern struct pci_ops *__nongpreldata pci_root_ops;
1268 +extern const struct pci_ops *__nongpreldata pci_root_ops;
1269
1270 /* pci-irq.c */
1271 extern unsigned int pcibios_irq_mask;
1272 diff -urNp linux-2.6.39.2/arch/frv/mb93090-mb00/pci-vdk.c linux-2.6.39.2/arch/frv/mb93090-mb00/pci-vdk.c
1273 --- linux-2.6.39.2/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-19 00:06:34.000000000 -0400
1274 +++ linux-2.6.39.2/arch/frv/mb93090-mb00/pci-vdk.c 2011-05-22 19:36:30.000000000 -0400
1275 @@ -27,7 +27,7 @@ unsigned int __nongpreldata pci_probe =
1276
1277 int __nongpreldata pcibios_last_bus = -1;
1278 struct pci_bus *__nongpreldata pci_root_bus;
1279 -struct pci_ops *__nongpreldata pci_root_ops;
1280 +const struct pci_ops *__nongpreldata pci_root_ops;
1281
1282 /*
1283 * The accessible PCI window does not cover the entire CPU address space, but
1284 @@ -169,7 +169,7 @@ static int pci_frv_write_config(struct p
1285 return PCIBIOS_SUCCESSFUL;
1286 }
1287
1288 -static struct pci_ops pci_direct_frv = {
1289 +static const struct pci_ops pci_direct_frv = {
1290 pci_frv_read_config,
1291 pci_frv_write_config,
1292 };
1293 @@ -356,7 +356,7 @@ void __init pcibios_fixup_bus(struct pci
1294
1295 int __init pcibios_init(void)
1296 {
1297 - struct pci_ops *dir = NULL;
1298 + const struct pci_ops *dir = NULL;
1299
1300 if (!mb93090_mb00_detected)
1301 return -ENXIO;
1302 diff -urNp linux-2.6.39.2/arch/frv/mm/elf-fdpic.c linux-2.6.39.2/arch/frv/mm/elf-fdpic.c
1303 --- linux-2.6.39.2/arch/frv/mm/elf-fdpic.c 2011-05-19 00:06:34.000000000 -0400
1304 +++ linux-2.6.39.2/arch/frv/mm/elf-fdpic.c 2011-05-22 19:36:30.000000000 -0400
1305 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(str
1306 if (addr) {
1307 addr = PAGE_ALIGN(addr);
1308 vma = find_vma(current->mm, addr);
1309 - if (TASK_SIZE - len >= addr &&
1310 - (!vma || addr + len <= vma->vm_start))
1311 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1312 goto success;
1313 }
1314
1315 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(str
1316 for (; vma; vma = vma->vm_next) {
1317 if (addr > limit)
1318 break;
1319 - if (addr + len <= vma->vm_start)
1320 + if (check_heap_stack_gap(vma, addr, len))
1321 goto success;
1322 addr = vma->vm_end;
1323 }
1324 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(str
1325 for (; vma; vma = vma->vm_next) {
1326 if (addr > limit)
1327 break;
1328 - if (addr + len <= vma->vm_start)
1329 + if (check_heap_stack_gap(vma, addr, len))
1330 goto success;
1331 addr = vma->vm_end;
1332 }
1333 diff -urNp linux-2.6.39.2/arch/ia64/hp/common/hwsw_iommu.c linux-2.6.39.2/arch/ia64/hp/common/hwsw_iommu.c
1334 --- linux-2.6.39.2/arch/ia64/hp/common/hwsw_iommu.c 2011-05-19 00:06:34.000000000 -0400
1335 +++ linux-2.6.39.2/arch/ia64/hp/common/hwsw_iommu.c 2011-05-22 19:36:30.000000000 -0400
1336 @@ -17,7 +17,7 @@
1337 #include <linux/swiotlb.h>
1338 #include <asm/machvec.h>
1339
1340 -extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1341 +extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1342
1343 /* swiotlb declarations & definitions: */
1344 extern int swiotlb_late_init_with_default_size (size_t size);
1345 @@ -33,7 +33,7 @@ static inline int use_swiotlb(struct dev
1346 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1347 }
1348
1349 -struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1350 +const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1351 {
1352 if (use_swiotlb(dev))
1353 return &swiotlb_dma_ops;
1354 diff -urNp linux-2.6.39.2/arch/ia64/hp/common/sba_iommu.c linux-2.6.39.2/arch/ia64/hp/common/sba_iommu.c
1355 --- linux-2.6.39.2/arch/ia64/hp/common/sba_iommu.c 2011-05-19 00:06:34.000000000 -0400
1356 +++ linux-2.6.39.2/arch/ia64/hp/common/sba_iommu.c 2011-05-22 19:36:30.000000000 -0400
1357 @@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_d
1358 },
1359 };
1360
1361 -extern struct dma_map_ops swiotlb_dma_ops;
1362 +extern const struct dma_map_ops swiotlb_dma_ops;
1363
1364 static int __init
1365 sba_init(void)
1366 @@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1367
1368 __setup("sbapagesize=",sba_page_override);
1369
1370 -struct dma_map_ops sba_dma_ops = {
1371 +const struct dma_map_ops sba_dma_ops = {
1372 .alloc_coherent = sba_alloc_coherent,
1373 .free_coherent = sba_free_coherent,
1374 .map_page = sba_map_page,
1375 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/dma-mapping.h linux-2.6.39.2/arch/ia64/include/asm/dma-mapping.h
1376 --- linux-2.6.39.2/arch/ia64/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1377 +++ linux-2.6.39.2/arch/ia64/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1378 @@ -14,7 +14,7 @@
1379
1380 #define DMA_ERROR_CODE 0
1381
1382 -extern struct dma_map_ops *dma_ops;
1383 +extern const struct dma_map_ops *dma_ops;
1384 extern struct ia64_machine_vector ia64_mv;
1385 extern void set_iommu_machvec(void);
1386
1387 @@ -26,7 +26,7 @@ extern void machvec_dma_sync_sg(struct d
1388 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1389 dma_addr_t *daddr, gfp_t gfp)
1390 {
1391 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1392 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1393 void *caddr;
1394
1395 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1396 @@ -37,7 +37,7 @@ static inline void *dma_alloc_coherent(s
1397 static inline void dma_free_coherent(struct device *dev, size_t size,
1398 void *caddr, dma_addr_t daddr)
1399 {
1400 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1401 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1402 debug_dma_free_coherent(dev, size, caddr, daddr);
1403 ops->free_coherent(dev, size, caddr, daddr);
1404 }
1405 @@ -51,13 +51,13 @@ static inline void dma_free_coherent(str
1406
1407 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1408 {
1409 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1410 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1411 return ops->mapping_error(dev, daddr);
1412 }
1413
1414 static inline int dma_supported(struct device *dev, u64 mask)
1415 {
1416 - struct dma_map_ops *ops = platform_dma_get_ops(dev);
1417 + const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1418 return ops->dma_supported(dev, mask);
1419 }
1420
1421 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/elf.h linux-2.6.39.2/arch/ia64/include/asm/elf.h
1422 --- linux-2.6.39.2/arch/ia64/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
1423 +++ linux-2.6.39.2/arch/ia64/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
1424 @@ -42,6 +42,13 @@
1425 */
1426 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1427
1428 +#ifdef CONFIG_PAX_ASLR
1429 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1430 +
1431 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1432 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1433 +#endif
1434 +
1435 #define PT_IA_64_UNWIND 0x70000001
1436
1437 /* IA-64 relocations: */
1438 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/machvec.h linux-2.6.39.2/arch/ia64/include/asm/machvec.h
1439 --- linux-2.6.39.2/arch/ia64/include/asm/machvec.h 2011-05-19 00:06:34.000000000 -0400
1440 +++ linux-2.6.39.2/arch/ia64/include/asm/machvec.h 2011-05-22 19:36:30.000000000 -0400
1441 @@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event
1442 /* DMA-mapping interface: */
1443 typedef void ia64_mv_dma_init (void);
1444 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1445 -typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1446 +typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1447
1448 /*
1449 * WARNING: The legacy I/O space is _architected_. Platforms are
1450 @@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(co
1451 # endif /* CONFIG_IA64_GENERIC */
1452
1453 extern void swiotlb_dma_init(void);
1454 -extern struct dma_map_ops *dma_get_ops(struct device *);
1455 +extern const struct dma_map_ops *dma_get_ops(struct device *);
1456
1457 /*
1458 * Define default versions so we can extend machvec for new platforms without having
1459 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/pgtable.h linux-2.6.39.2/arch/ia64/include/asm/pgtable.h
1460 --- linux-2.6.39.2/arch/ia64/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
1461 +++ linux-2.6.39.2/arch/ia64/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
1462 @@ -12,7 +12,7 @@
1463 * David Mosberger-Tang <davidm@hpl.hp.com>
1464 */
1465
1466 -
1467 +#include <linux/const.h>
1468 #include <asm/mman.h>
1469 #include <asm/page.h>
1470 #include <asm/processor.h>
1471 @@ -143,6 +143,17 @@
1472 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1473 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1474 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1475 +
1476 +#ifdef CONFIG_PAX_PAGEEXEC
1477 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1478 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1479 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1480 +#else
1481 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1482 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1483 +# define PAGE_COPY_NOEXEC PAGE_COPY
1484 +#endif
1485 +
1486 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1487 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1488 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1489 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/spinlock.h linux-2.6.39.2/arch/ia64/include/asm/spinlock.h
1490 --- linux-2.6.39.2/arch/ia64/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
1491 +++ linux-2.6.39.2/arch/ia64/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
1492 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spi
1493 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1494
1495 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1496 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1497 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1498 }
1499
1500 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1501 diff -urNp linux-2.6.39.2/arch/ia64/include/asm/uaccess.h linux-2.6.39.2/arch/ia64/include/asm/uaccess.h
1502 --- linux-2.6.39.2/arch/ia64/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
1503 +++ linux-2.6.39.2/arch/ia64/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
1504 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void _
1505 const void *__cu_from = (from); \
1506 long __cu_len = (n); \
1507 \
1508 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1509 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1510 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1511 __cu_len; \
1512 })
1513 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void _
1514 long __cu_len = (n); \
1515 \
1516 __chk_user_ptr(__cu_from); \
1517 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1518 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1519 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1520 __cu_len; \
1521 })
1522 diff -urNp linux-2.6.39.2/arch/ia64/kernel/dma-mapping.c linux-2.6.39.2/arch/ia64/kernel/dma-mapping.c
1523 --- linux-2.6.39.2/arch/ia64/kernel/dma-mapping.c 2011-05-19 00:06:34.000000000 -0400
1524 +++ linux-2.6.39.2/arch/ia64/kernel/dma-mapping.c 2011-05-22 19:36:30.000000000 -0400
1525 @@ -3,7 +3,7 @@
1526 /* Set this to 1 if there is a HW IOMMU in the system */
1527 int iommu_detected __read_mostly;
1528
1529 -struct dma_map_ops *dma_ops;
1530 +const struct dma_map_ops *dma_ops;
1531 EXPORT_SYMBOL(dma_ops);
1532
1533 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1534 @@ -16,7 +16,7 @@ static int __init dma_init(void)
1535 }
1536 fs_initcall(dma_init);
1537
1538 -struct dma_map_ops *dma_get_ops(struct device *dev)
1539 +const struct dma_map_ops *dma_get_ops(struct device *dev)
1540 {
1541 return dma_ops;
1542 }
1543 diff -urNp linux-2.6.39.2/arch/ia64/kernel/module.c linux-2.6.39.2/arch/ia64/kernel/module.c
1544 --- linux-2.6.39.2/arch/ia64/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
1545 +++ linux-2.6.39.2/arch/ia64/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
1546 @@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1547 void
1548 module_free (struct module *mod, void *module_region)
1549 {
1550 - if (mod && mod->arch.init_unw_table &&
1551 - module_region == mod->module_init) {
1552 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1553 unw_remove_unwind_table(mod->arch.init_unw_table);
1554 mod->arch.init_unw_table = NULL;
1555 }
1556 @@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
1557 }
1558
1559 static inline int
1560 +in_init_rx (const struct module *mod, uint64_t addr)
1561 +{
1562 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1563 +}
1564 +
1565 +static inline int
1566 +in_init_rw (const struct module *mod, uint64_t addr)
1567 +{
1568 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1569 +}
1570 +
1571 +static inline int
1572 in_init (const struct module *mod, uint64_t addr)
1573 {
1574 - return addr - (uint64_t) mod->module_init < mod->init_size;
1575 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1576 +}
1577 +
1578 +static inline int
1579 +in_core_rx (const struct module *mod, uint64_t addr)
1580 +{
1581 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1582 +}
1583 +
1584 +static inline int
1585 +in_core_rw (const struct module *mod, uint64_t addr)
1586 +{
1587 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1588 }
1589
1590 static inline int
1591 in_core (const struct module *mod, uint64_t addr)
1592 {
1593 - return addr - (uint64_t) mod->module_core < mod->core_size;
1594 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1595 }
1596
1597 static inline int
1598 @@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_
1599 break;
1600
1601 case RV_BDREL:
1602 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1603 + if (in_init_rx(mod, val))
1604 + val -= (uint64_t) mod->module_init_rx;
1605 + else if (in_init_rw(mod, val))
1606 + val -= (uint64_t) mod->module_init_rw;
1607 + else if (in_core_rx(mod, val))
1608 + val -= (uint64_t) mod->module_core_rx;
1609 + else if (in_core_rw(mod, val))
1610 + val -= (uint64_t) mod->module_core_rw;
1611 break;
1612
1613 case RV_LTV:
1614 @@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
1615 * addresses have been selected...
1616 */
1617 uint64_t gp;
1618 - if (mod->core_size > MAX_LTOFF)
1619 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1620 /*
1621 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1622 * at the end of the module.
1623 */
1624 - gp = mod->core_size - MAX_LTOFF / 2;
1625 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1626 else
1627 - gp = mod->core_size / 2;
1628 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1629 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1630 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1631 mod->arch.gp = gp;
1632 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1633 }
1634 diff -urNp linux-2.6.39.2/arch/ia64/kernel/pci-dma.c linux-2.6.39.2/arch/ia64/kernel/pci-dma.c
1635 --- linux-2.6.39.2/arch/ia64/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
1636 +++ linux-2.6.39.2/arch/ia64/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
1637 @@ -43,7 +43,7 @@ struct device fallback_dev = {
1638 .dma_mask = &fallback_dev.coherent_dma_mask,
1639 };
1640
1641 -extern struct dma_map_ops intel_dma_ops;
1642 +extern const struct dma_map_ops intel_dma_ops;
1643
1644 static int __init pci_iommu_init(void)
1645 {
1646 diff -urNp linux-2.6.39.2/arch/ia64/kernel/pci-swiotlb.c linux-2.6.39.2/arch/ia64/kernel/pci-swiotlb.c
1647 --- linux-2.6.39.2/arch/ia64/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
1648 +++ linux-2.6.39.2/arch/ia64/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
1649 @@ -22,7 +22,7 @@ static void *ia64_swiotlb_alloc_coherent
1650 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1651 }
1652
1653 -struct dma_map_ops swiotlb_dma_ops = {
1654 +const struct dma_map_ops swiotlb_dma_ops = {
1655 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1656 .free_coherent = swiotlb_free_coherent,
1657 .map_page = swiotlb_map_page,
1658 diff -urNp linux-2.6.39.2/arch/ia64/kernel/sys_ia64.c linux-2.6.39.2/arch/ia64/kernel/sys_ia64.c
1659 --- linux-2.6.39.2/arch/ia64/kernel/sys_ia64.c 2011-05-19 00:06:34.000000000 -0400
1660 +++ linux-2.6.39.2/arch/ia64/kernel/sys_ia64.c 2011-05-22 19:36:30.000000000 -0400
1661 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
1662 if (REGION_NUMBER(addr) == RGN_HPAGE)
1663 addr = 0;
1664 #endif
1665 +
1666 +#ifdef CONFIG_PAX_RANDMMAP
1667 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1668 + addr = mm->free_area_cache;
1669 + else
1670 +#endif
1671 +
1672 if (!addr)
1673 addr = mm->free_area_cache;
1674
1675 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *fil
1676 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1677 /* At this point: (!vma || addr < vma->vm_end). */
1678 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1679 - if (start_addr != TASK_UNMAPPED_BASE) {
1680 + if (start_addr != mm->mmap_base) {
1681 /* Start a new search --- just in case we missed some holes. */
1682 - addr = TASK_UNMAPPED_BASE;
1683 + addr = mm->mmap_base;
1684 goto full_search;
1685 }
1686 return -ENOMEM;
1687 }
1688 - if (!vma || addr + len <= vma->vm_start) {
1689 + if (check_heap_stack_gap(vma, addr, len)) {
1690 /* Remember the address where we stopped this search: */
1691 mm->free_area_cache = addr + len;
1692 return addr;
1693 diff -urNp linux-2.6.39.2/arch/ia64/kernel/vmlinux.lds.S linux-2.6.39.2/arch/ia64/kernel/vmlinux.lds.S
1694 --- linux-2.6.39.2/arch/ia64/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
1695 +++ linux-2.6.39.2/arch/ia64/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
1696 @@ -199,7 +199,7 @@ SECTIONS {
1697 /* Per-cpu data: */
1698 . = ALIGN(PERCPU_PAGE_SIZE);
1699 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1700 - __phys_per_cpu_start = __per_cpu_load;
1701 + __phys_per_cpu_start = per_cpu_load;
1702 /*
1703 * ensure percpu data fits
1704 * into percpu page size
1705 diff -urNp linux-2.6.39.2/arch/ia64/mm/fault.c linux-2.6.39.2/arch/ia64/mm/fault.c
1706 --- linux-2.6.39.2/arch/ia64/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
1707 +++ linux-2.6.39.2/arch/ia64/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
1708 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
1709 return pte_present(pte);
1710 }
1711
1712 +#ifdef CONFIG_PAX_PAGEEXEC
1713 +void pax_report_insns(void *pc, void *sp)
1714 +{
1715 + unsigned long i;
1716 +
1717 + printk(KERN_ERR "PAX: bytes at PC: ");
1718 + for (i = 0; i < 8; i++) {
1719 + unsigned int c;
1720 + if (get_user(c, (unsigned int *)pc+i))
1721 + printk(KERN_CONT "???????? ");
1722 + else
1723 + printk(KERN_CONT "%08x ", c);
1724 + }
1725 + printk("\n");
1726 +}
1727 +#endif
1728 +
1729 void __kprobes
1730 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1731 {
1732 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
1733 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1734 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1735
1736 - if ((vma->vm_flags & mask) != mask)
1737 + if ((vma->vm_flags & mask) != mask) {
1738 +
1739 +#ifdef CONFIG_PAX_PAGEEXEC
1740 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1741 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1742 + goto bad_area;
1743 +
1744 + up_read(&mm->mmap_sem);
1745 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1746 + do_group_exit(SIGKILL);
1747 + }
1748 +#endif
1749 +
1750 goto bad_area;
1751
1752 + }
1753 +
1754 /*
1755 * If for any reason at all we couldn't handle the fault, make
1756 * sure we exit gracefully rather than endlessly redo the
1757 diff -urNp linux-2.6.39.2/arch/ia64/mm/hugetlbpage.c linux-2.6.39.2/arch/ia64/mm/hugetlbpage.c
1758 --- linux-2.6.39.2/arch/ia64/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
1759 +++ linux-2.6.39.2/arch/ia64/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
1760 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(
1761 /* At this point: (!vmm || addr < vmm->vm_end). */
1762 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1763 return -ENOMEM;
1764 - if (!vmm || (addr + len) <= vmm->vm_start)
1765 + if (check_heap_stack_gap(vmm, addr, len))
1766 return addr;
1767 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1768 }
1769 diff -urNp linux-2.6.39.2/arch/ia64/mm/init.c linux-2.6.39.2/arch/ia64/mm/init.c
1770 --- linux-2.6.39.2/arch/ia64/mm/init.c 2011-05-19 00:06:34.000000000 -0400
1771 +++ linux-2.6.39.2/arch/ia64/mm/init.c 2011-05-22 19:36:30.000000000 -0400
1772 @@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1773 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1774 vma->vm_end = vma->vm_start + PAGE_SIZE;
1775 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1776 +
1777 +#ifdef CONFIG_PAX_PAGEEXEC
1778 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1779 + vma->vm_flags &= ~VM_EXEC;
1780 +
1781 +#ifdef CONFIG_PAX_MPROTECT
1782 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1783 + vma->vm_flags &= ~VM_MAYEXEC;
1784 +#endif
1785 +
1786 + }
1787 +#endif
1788 +
1789 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1790 down_write(&current->mm->mmap_sem);
1791 if (insert_vm_struct(current->mm, vma)) {
1792 diff -urNp linux-2.6.39.2/arch/ia64/pci/pci.c linux-2.6.39.2/arch/ia64/pci/pci.c
1793 --- linux-2.6.39.2/arch/ia64/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
1794 +++ linux-2.6.39.2/arch/ia64/pci/pci.c 2011-05-22 19:36:30.000000000 -0400
1795 @@ -109,7 +109,7 @@ static int pci_write(struct pci_bus *bus
1796 devfn, where, size, value);
1797 }
1798
1799 -struct pci_ops pci_root_ops = {
1800 +const struct pci_ops pci_root_ops = {
1801 .read = pci_read,
1802 .write = pci_write,
1803 };
1804 diff -urNp linux-2.6.39.2/arch/ia64/sn/pci/pci_dma.c linux-2.6.39.2/arch/ia64/sn/pci/pci_dma.c
1805 --- linux-2.6.39.2/arch/ia64/sn/pci/pci_dma.c 2011-05-19 00:06:34.000000000 -0400
1806 +++ linux-2.6.39.2/arch/ia64/sn/pci/pci_dma.c 2011-05-22 19:36:30.000000000 -0400
1807 @@ -465,7 +465,7 @@ int sn_pci_legacy_write(struct pci_bus *
1808 return ret;
1809 }
1810
1811 -static struct dma_map_ops sn_dma_ops = {
1812 +static const struct dma_map_ops sn_dma_ops = {
1813 .alloc_coherent = sn_dma_alloc_coherent,
1814 .free_coherent = sn_dma_free_coherent,
1815 .map_page = sn_dma_map_page,
1816 diff -urNp linux-2.6.39.2/arch/m32r/lib/usercopy.c linux-2.6.39.2/arch/m32r/lib/usercopy.c
1817 --- linux-2.6.39.2/arch/m32r/lib/usercopy.c 2011-05-19 00:06:34.000000000 -0400
1818 +++ linux-2.6.39.2/arch/m32r/lib/usercopy.c 2011-05-22 19:36:30.000000000 -0400
1819 @@ -14,6 +14,9 @@
1820 unsigned long
1821 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1822 {
1823 + if ((long)n < 0)
1824 + return n;
1825 +
1826 prefetch(from);
1827 if (access_ok(VERIFY_WRITE, to, n))
1828 __copy_user(to,from,n);
1829 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to,
1830 unsigned long
1831 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1832 {
1833 + if ((long)n < 0)
1834 + return n;
1835 +
1836 prefetchw(to);
1837 if (access_ok(VERIFY_READ, from, n))
1838 __copy_user_zeroing(to,from,n);
1839 diff -urNp linux-2.6.39.2/arch/microblaze/include/asm/device.h linux-2.6.39.2/arch/microblaze/include/asm/device.h
1840 --- linux-2.6.39.2/arch/microblaze/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
1841 +++ linux-2.6.39.2/arch/microblaze/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
1842 @@ -13,7 +13,7 @@ struct device_node;
1843
1844 struct dev_archdata {
1845 /* DMA operations on that device */
1846 - struct dma_map_ops *dma_ops;
1847 + const struct dma_map_ops *dma_ops;
1848 void *dma_data;
1849 };
1850
1851 diff -urNp linux-2.6.39.2/arch/microblaze/include/asm/dma-mapping.h linux-2.6.39.2/arch/microblaze/include/asm/dma-mapping.h
1852 --- linux-2.6.39.2/arch/microblaze/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
1853 +++ linux-2.6.39.2/arch/microblaze/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
1854 @@ -43,14 +43,14 @@ static inline unsigned long device_to_ma
1855 return 0xfffffffful;
1856 }
1857
1858 -extern struct dma_map_ops *dma_ops;
1859 +extern const struct dma_map_ops *dma_ops;
1860
1861 /*
1862 * Available generic sets of operations
1863 */
1864 -extern struct dma_map_ops dma_direct_ops;
1865 +extern const struct dma_map_ops dma_direct_ops;
1866
1867 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
1868 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
1869 {
1870 /* We don't handle the NULL dev case for ISA for now. We could
1871 * do it via an out of line call but it is not needed for now. The
1872 @@ -63,14 +63,14 @@ static inline struct dma_map_ops *get_dm
1873 return dev->archdata.dma_ops;
1874 }
1875
1876 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
1877 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
1878 {
1879 dev->archdata.dma_ops = ops;
1880 }
1881
1882 static inline int dma_supported(struct device *dev, u64 mask)
1883 {
1884 - struct dma_map_ops *ops = get_dma_ops(dev);
1885 + const struct dma_map_ops *ops = get_dma_ops(dev);
1886
1887 if (unlikely(!ops))
1888 return 0;
1889 @@ -81,7 +81,7 @@ static inline int dma_supported(struct d
1890
1891 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
1892 {
1893 - struct dma_map_ops *ops = get_dma_ops(dev);
1894 + const struct dma_map_ops *ops = get_dma_ops(dev);
1895
1896 if (unlikely(ops == NULL))
1897 return -EIO;
1898 @@ -97,7 +97,7 @@ static inline int dma_set_mask(struct de
1899
1900 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
1901 {
1902 - struct dma_map_ops *ops = get_dma_ops(dev);
1903 + const struct dma_map_ops *ops = get_dma_ops(dev);
1904 if (ops->mapping_error)
1905 return ops->mapping_error(dev, dma_addr);
1906
1907 @@ -110,7 +110,7 @@ static inline int dma_mapping_error(stru
1908 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1909 dma_addr_t *dma_handle, gfp_t flag)
1910 {
1911 - struct dma_map_ops *ops = get_dma_ops(dev);
1912 + const struct dma_map_ops *ops = get_dma_ops(dev);
1913 void *memory;
1914
1915 BUG_ON(!ops);
1916 @@ -124,7 +124,7 @@ static inline void *dma_alloc_coherent(s
1917 static inline void dma_free_coherent(struct device *dev, size_t size,
1918 void *cpu_addr, dma_addr_t dma_handle)
1919 {
1920 - struct dma_map_ops *ops = get_dma_ops(dev);
1921 + const struct dma_map_ops *ops = get_dma_ops(dev);
1922
1923 BUG_ON(!ops);
1924 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
1925 diff -urNp linux-2.6.39.2/arch/microblaze/include/asm/pci.h linux-2.6.39.2/arch/microblaze/include/asm/pci.h
1926 --- linux-2.6.39.2/arch/microblaze/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
1927 +++ linux-2.6.39.2/arch/microblaze/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
1928 @@ -54,8 +54,8 @@ static inline void pcibios_penalize_isa_
1929 }
1930
1931 #ifdef CONFIG_PCI
1932 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
1933 -extern struct dma_map_ops *get_pci_dma_ops(void);
1934 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
1935 +extern const struct dma_map_ops *get_pci_dma_ops(void);
1936 #else /* CONFIG_PCI */
1937 #define set_pci_dma_ops(d)
1938 #define get_pci_dma_ops() NULL
1939 diff -urNp linux-2.6.39.2/arch/microblaze/kernel/dma.c linux-2.6.39.2/arch/microblaze/kernel/dma.c
1940 --- linux-2.6.39.2/arch/microblaze/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
1941 +++ linux-2.6.39.2/arch/microblaze/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
1942 @@ -134,7 +134,7 @@ static inline void dma_direct_unmap_page
1943 __dma_sync_page(dma_address, 0 , size, direction);
1944 }
1945
1946 -struct dma_map_ops dma_direct_ops = {
1947 +const struct dma_map_ops dma_direct_ops = {
1948 .alloc_coherent = dma_direct_alloc_coherent,
1949 .free_coherent = dma_direct_free_coherent,
1950 .map_sg = dma_direct_map_sg,
1951 diff -urNp linux-2.6.39.2/arch/microblaze/kernel/kgdb.c linux-2.6.39.2/arch/microblaze/kernel/kgdb.c
1952 --- linux-2.6.39.2/arch/microblaze/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
1953 +++ linux-2.6.39.2/arch/microblaze/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
1954 @@ -141,7 +141,7 @@ void kgdb_arch_exit(void)
1955 /*
1956 * Global data
1957 */
1958 -struct kgdb_arch arch_kgdb_ops = {
1959 +const struct kgdb_arch arch_kgdb_ops = {
1960 #ifdef __MICROBLAZEEL__
1961 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
1962 #else
1963 diff -urNp linux-2.6.39.2/arch/microblaze/pci/indirect_pci.c linux-2.6.39.2/arch/microblaze/pci/indirect_pci.c
1964 --- linux-2.6.39.2/arch/microblaze/pci/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
1965 +++ linux-2.6.39.2/arch/microblaze/pci/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
1966 @@ -140,7 +140,7 @@ indirect_write_config(struct pci_bus *bu
1967 return PCIBIOS_SUCCESSFUL;
1968 }
1969
1970 -static struct pci_ops indirect_pci_ops = {
1971 +static const struct pci_ops indirect_pci_ops = {
1972 .read = indirect_read_config,
1973 .write = indirect_write_config,
1974 };
1975 diff -urNp linux-2.6.39.2/arch/microblaze/pci/pci-common.c linux-2.6.39.2/arch/microblaze/pci/pci-common.c
1976 --- linux-2.6.39.2/arch/microblaze/pci/pci-common.c 2011-05-19 00:06:34.000000000 -0400
1977 +++ linux-2.6.39.2/arch/microblaze/pci/pci-common.c 2011-05-22 19:36:30.000000000 -0400
1978 @@ -48,14 +48,14 @@ resource_size_t isa_mem_base;
1979 /* Default PCI flags is 0 on ppc32, modified at boot on ppc64 */
1980 unsigned int pci_flags;
1981
1982 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1983 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
1984
1985 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
1986 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
1987 {
1988 pci_dma_ops = dma_ops;
1989 }
1990
1991 -struct dma_map_ops *get_pci_dma_ops(void)
1992 +const struct dma_map_ops *get_pci_dma_ops(void)
1993 {
1994 return pci_dma_ops;
1995 }
1996 @@ -1583,7 +1583,7 @@ null_write_config(struct pci_bus *bus, u
1997 return PCIBIOS_DEVICE_NOT_FOUND;
1998 }
1999
2000 -static struct pci_ops null_pci_ops = {
2001 +static const struct pci_ops null_pci_ops = {
2002 .read = null_read_config,
2003 .write = null_write_config,
2004 };
2005 diff -urNp linux-2.6.39.2/arch/mips/alchemy/common/pci.c linux-2.6.39.2/arch/mips/alchemy/common/pci.c
2006 --- linux-2.6.39.2/arch/mips/alchemy/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2007 +++ linux-2.6.39.2/arch/mips/alchemy/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2008 @@ -51,7 +51,7 @@ static struct resource pci_mem_resource
2009 .flags = IORESOURCE_MEM
2010 };
2011
2012 -extern struct pci_ops au1x_pci_ops;
2013 +extern const struct pci_ops au1x_pci_ops;
2014
2015 static struct pci_controller au1x_controller = {
2016 .pci_ops = &au1x_pci_ops,
2017 diff -urNp linux-2.6.39.2/arch/mips/cavium-octeon/dma-octeon.c linux-2.6.39.2/arch/mips/cavium-octeon/dma-octeon.c
2018 --- linux-2.6.39.2/arch/mips/cavium-octeon/dma-octeon.c 2011-05-19 00:06:34.000000000 -0400
2019 +++ linux-2.6.39.2/arch/mips/cavium-octeon/dma-octeon.c 2011-05-22 19:36:30.000000000 -0400
2020 @@ -202,7 +202,7 @@ static phys_addr_t octeon_unity_dma_to_p
2021 }
2022
2023 struct octeon_dma_map_ops {
2024 - struct dma_map_ops dma_map_ops;
2025 + const struct dma_map_ops dma_map_ops;
2026 dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
2027 phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
2028 };
2029 @@ -324,7 +324,7 @@ static struct octeon_dma_map_ops _octeon
2030 },
2031 };
2032
2033 -struct dma_map_ops *octeon_pci_dma_map_ops;
2034 +const struct dma_map_ops *octeon_pci_dma_map_ops;
2035
2036 void __init octeon_pci_dma_init(void)
2037 {
2038 diff -urNp linux-2.6.39.2/arch/mips/cobalt/pci.c linux-2.6.39.2/arch/mips/cobalt/pci.c
2039 --- linux-2.6.39.2/arch/mips/cobalt/pci.c 2011-05-19 00:06:34.000000000 -0400
2040 +++ linux-2.6.39.2/arch/mips/cobalt/pci.c 2011-05-22 19:36:30.000000000 -0400
2041 @@ -14,7 +14,7 @@
2042
2043 #include <asm/gt64120.h>
2044
2045 -extern struct pci_ops gt64xxx_pci0_ops;
2046 +extern const struct pci_ops gt64xxx_pci0_ops;
2047
2048 static struct resource cobalt_mem_resource = {
2049 .start = GT_DEF_PCI0_MEM0_BASE,
2050 diff -urNp linux-2.6.39.2/arch/mips/include/asm/device.h linux-2.6.39.2/arch/mips/include/asm/device.h
2051 --- linux-2.6.39.2/arch/mips/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
2052 +++ linux-2.6.39.2/arch/mips/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
2053 @@ -10,7 +10,7 @@ struct dma_map_ops;
2054
2055 struct dev_archdata {
2056 /* DMA operations on that device */
2057 - struct dma_map_ops *dma_ops;
2058 + const struct dma_map_ops *dma_ops;
2059 };
2060
2061 struct pdev_archdata {
2062 diff -urNp linux-2.6.39.2/arch/mips/include/asm/dma-mapping.h linux-2.6.39.2/arch/mips/include/asm/dma-mapping.h
2063 --- linux-2.6.39.2/arch/mips/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
2064 +++ linux-2.6.39.2/arch/mips/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
2065 @@ -9,9 +9,9 @@
2066 #include <dma-coherence.h>
2067 #endif
2068
2069 -extern struct dma_map_ops *mips_dma_map_ops;
2070 +extern const struct dma_map_ops *mips_dma_map_ops;
2071
2072 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2073 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2074 {
2075 if (dev && dev->archdata.dma_ops)
2076 return dev->archdata.dma_ops;
2077 @@ -33,13 +33,13 @@ static inline void dma_mark_clean(void *
2078
2079 static inline int dma_supported(struct device *dev, u64 mask)
2080 {
2081 - struct dma_map_ops *ops = get_dma_ops(dev);
2082 + const struct dma_map_ops *ops = get_dma_ops(dev);
2083 return ops->dma_supported(dev, mask);
2084 }
2085
2086 static inline int dma_mapping_error(struct device *dev, u64 mask)
2087 {
2088 - struct dma_map_ops *ops = get_dma_ops(dev);
2089 + const struct dma_map_ops *ops = get_dma_ops(dev);
2090 return ops->mapping_error(dev, mask);
2091 }
2092
2093 @@ -61,7 +61,7 @@ static inline void *dma_alloc_coherent(s
2094 dma_addr_t *dma_handle, gfp_t gfp)
2095 {
2096 void *ret;
2097 - struct dma_map_ops *ops = get_dma_ops(dev);
2098 + const struct dma_map_ops *ops = get_dma_ops(dev);
2099
2100 ret = ops->alloc_coherent(dev, size, dma_handle, gfp);
2101
2102 @@ -73,7 +73,7 @@ static inline void *dma_alloc_coherent(s
2103 static inline void dma_free_coherent(struct device *dev, size_t size,
2104 void *vaddr, dma_addr_t dma_handle)
2105 {
2106 - struct dma_map_ops *ops = get_dma_ops(dev);
2107 + const struct dma_map_ops *ops = get_dma_ops(dev);
2108
2109 ops->free_coherent(dev, size, vaddr, dma_handle);
2110
2111 diff -urNp linux-2.6.39.2/arch/mips/include/asm/elf.h linux-2.6.39.2/arch/mips/include/asm/elf.h
2112 --- linux-2.6.39.2/arch/mips/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2113 +++ linux-2.6.39.2/arch/mips/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2114 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2115 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2116 #endif
2117
2118 +#ifdef CONFIG_PAX_ASLR
2119 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2120 +
2121 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2122 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2123 +#endif
2124 +
2125 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2126 struct linux_binprm;
2127 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2128 int uses_interp);
2129
2130 -struct mm_struct;
2131 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2132 -#define arch_randomize_brk arch_randomize_brk
2133 -
2134 #endif /* _ASM_ELF_H */
2135 diff -urNp linux-2.6.39.2/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h linux-2.6.39.2/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
2136 --- linux-2.6.39.2/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-19 00:06:34.000000000 -0400
2137 +++ linux-2.6.39.2/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h 2011-05-22 19:36:30.000000000 -0400
2138 @@ -66,7 +66,7 @@ dma_addr_t phys_to_dma(struct device *de
2139 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
2140
2141 struct dma_map_ops;
2142 -extern struct dma_map_ops *octeon_pci_dma_map_ops;
2143 +extern const struct dma_map_ops *octeon_pci_dma_map_ops;
2144 extern char *octeon_swiotlb;
2145
2146 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
2147 diff -urNp linux-2.6.39.2/arch/mips/include/asm/page.h linux-2.6.39.2/arch/mips/include/asm/page.h
2148 --- linux-2.6.39.2/arch/mips/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
2149 +++ linux-2.6.39.2/arch/mips/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
2150 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct pa
2151 #ifdef CONFIG_CPU_MIPS32
2152 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2153 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2154 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2155 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2156 #else
2157 typedef struct { unsigned long long pte; } pte_t;
2158 #define pte_val(x) ((x).pte)
2159 diff -urNp linux-2.6.39.2/arch/mips/include/asm/pci/bridge.h linux-2.6.39.2/arch/mips/include/asm/pci/bridge.h
2160 --- linux-2.6.39.2/arch/mips/include/asm/pci/bridge.h 2011-05-19 00:06:34.000000000 -0400
2161 +++ linux-2.6.39.2/arch/mips/include/asm/pci/bridge.h 2011-05-22 19:36:30.000000000 -0400
2162 @@ -849,6 +849,6 @@ struct bridge_controller {
2163 extern void register_bridge_irq(unsigned int irq);
2164 extern int request_bridge_irq(struct bridge_controller *bc);
2165
2166 -extern struct pci_ops bridge_pci_ops;
2167 +extern const struct pci_ops bridge_pci_ops;
2168
2169 #endif /* _ASM_PCI_BRIDGE_H */
2170 diff -urNp linux-2.6.39.2/arch/mips/include/asm/system.h linux-2.6.39.2/arch/mips/include/asm/system.h
2171 --- linux-2.6.39.2/arch/mips/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
2172 +++ linux-2.6.39.2/arch/mips/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
2173 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2174 */
2175 #define __ARCH_WANT_UNLOCKED_CTXSW
2176
2177 -extern unsigned long arch_align_stack(unsigned long sp);
2178 +#define arch_align_stack(x) ((x) & ~0xfUL)
2179
2180 #endif /* _ASM_SYSTEM_H */
2181 diff -urNp linux-2.6.39.2/arch/mips/kernel/binfmt_elfn32.c linux-2.6.39.2/arch/mips/kernel/binfmt_elfn32.c
2182 --- linux-2.6.39.2/arch/mips/kernel/binfmt_elfn32.c 2011-05-19 00:06:34.000000000 -0400
2183 +++ linux-2.6.39.2/arch/mips/kernel/binfmt_elfn32.c 2011-05-22 19:36:30.000000000 -0400
2184 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2185 #undef ELF_ET_DYN_BASE
2186 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2187
2188 +#ifdef CONFIG_PAX_ASLR
2189 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2190 +
2191 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2192 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2193 +#endif
2194 +
2195 #include <asm/processor.h>
2196 #include <linux/module.h>
2197 #include <linux/elfcore.h>
2198 diff -urNp linux-2.6.39.2/arch/mips/kernel/binfmt_elfo32.c linux-2.6.39.2/arch/mips/kernel/binfmt_elfo32.c
2199 --- linux-2.6.39.2/arch/mips/kernel/binfmt_elfo32.c 2011-05-19 00:06:34.000000000 -0400
2200 +++ linux-2.6.39.2/arch/mips/kernel/binfmt_elfo32.c 2011-05-22 19:36:30.000000000 -0400
2201 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2202 #undef ELF_ET_DYN_BASE
2203 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2204
2205 +#ifdef CONFIG_PAX_ASLR
2206 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2207 +
2208 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2209 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2210 +#endif
2211 +
2212 #include <asm/processor.h>
2213
2214 /*
2215 diff -urNp linux-2.6.39.2/arch/mips/kernel/kgdb.c linux-2.6.39.2/arch/mips/kernel/kgdb.c
2216 --- linux-2.6.39.2/arch/mips/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
2217 +++ linux-2.6.39.2/arch/mips/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
2218 @@ -351,7 +351,7 @@ int kgdb_arch_handle_exception(int vecto
2219 return -1;
2220 }
2221
2222 -struct kgdb_arch arch_kgdb_ops;
2223 +struct kgdb_arch arch_kgdb_ops; /* cannot be const, see kgdb_arch_init */
2224
2225 /*
2226 * We use kgdb_early_setup so that functions we need to call now don't
2227 diff -urNp linux-2.6.39.2/arch/mips/kernel/process.c linux-2.6.39.2/arch/mips/kernel/process.c
2228 --- linux-2.6.39.2/arch/mips/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
2229 +++ linux-2.6.39.2/arch/mips/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
2230 @@ -473,15 +473,3 @@ unsigned long get_wchan(struct task_stru
2231 out:
2232 return pc;
2233 }
2234 -
2235 -/*
2236 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2237 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2238 - */
2239 -unsigned long arch_align_stack(unsigned long sp)
2240 -{
2241 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2242 - sp -= get_random_int() & ~PAGE_MASK;
2243 -
2244 - return sp & ALMASK;
2245 -}
2246 diff -urNp linux-2.6.39.2/arch/mips/kernel/syscall.c linux-2.6.39.2/arch/mips/kernel/syscall.c
2247 --- linux-2.6.39.2/arch/mips/kernel/syscall.c 2011-05-19 00:06:34.000000000 -0400
2248 +++ linux-2.6.39.2/arch/mips/kernel/syscall.c 2011-05-22 19:36:30.000000000 -0400
2249 @@ -108,14 +108,18 @@ unsigned long arch_get_unmapped_area(str
2250 do_color_align = 0;
2251 if (filp || (flags & MAP_SHARED))
2252 do_color_align = 1;
2253 +
2254 +#ifdef CONFIG_PAX_RANDMMAP
2255 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2256 +#endif
2257 +
2258 if (addr) {
2259 if (do_color_align)
2260 addr = COLOUR_ALIGN(addr, pgoff);
2261 else
2262 addr = PAGE_ALIGN(addr);
2263 vmm = find_vma(current->mm, addr);
2264 - if (task_size - len >= addr &&
2265 - (!vmm || addr + len <= vmm->vm_start))
2266 + if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2267 return addr;
2268 }
2269 addr = current->mm->mmap_base;
2270 @@ -128,7 +132,7 @@ unsigned long arch_get_unmapped_area(str
2271 /* At this point: (!vmm || addr < vmm->vm_end). */
2272 if (task_size - len < addr)
2273 return -ENOMEM;
2274 - if (!vmm || addr + len <= vmm->vm_start)
2275 + if (check_heap_stack_gap(vmm, addr, len))
2276 return addr;
2277 addr = vmm->vm_end;
2278 if (do_color_align)
2279 @@ -154,33 +158,6 @@ void arch_pick_mmap_layout(struct mm_str
2280 mm->unmap_area = arch_unmap_area;
2281 }
2282
2283 -static inline unsigned long brk_rnd(void)
2284 -{
2285 - unsigned long rnd = get_random_int();
2286 -
2287 - rnd = rnd << PAGE_SHIFT;
2288 - /* 8MB for 32bit, 256MB for 64bit */
2289 - if (TASK_IS_32BIT_ADDR)
2290 - rnd = rnd & 0x7ffffful;
2291 - else
2292 - rnd = rnd & 0xffffffful;
2293 -
2294 - return rnd;
2295 -}
2296 -
2297 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2298 -{
2299 - unsigned long base = mm->brk;
2300 - unsigned long ret;
2301 -
2302 - ret = PAGE_ALIGN(base + brk_rnd());
2303 -
2304 - if (ret < mm->brk)
2305 - return mm->brk;
2306 -
2307 - return ret;
2308 -}
2309 -
2310 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
2311 unsigned long, prot, unsigned long, flags, unsigned long,
2312 fd, off_t, offset)
2313 diff -urNp linux-2.6.39.2/arch/mips/mm/dma-default.c linux-2.6.39.2/arch/mips/mm/dma-default.c
2314 --- linux-2.6.39.2/arch/mips/mm/dma-default.c 2011-05-19 00:06:34.000000000 -0400
2315 +++ linux-2.6.39.2/arch/mips/mm/dma-default.c 2011-05-22 19:36:30.000000000 -0400
2316 @@ -300,7 +300,7 @@ void dma_cache_sync(struct device *dev,
2317
2318 EXPORT_SYMBOL(dma_cache_sync);
2319
2320 -static struct dma_map_ops mips_default_dma_map_ops = {
2321 +static const struct dma_map_ops mips_default_dma_map_ops = {
2322 .alloc_coherent = mips_dma_alloc_coherent,
2323 .free_coherent = mips_dma_free_coherent,
2324 .map_page = mips_dma_map_page,
2325 @@ -315,7 +315,7 @@ static struct dma_map_ops mips_default_d
2326 .dma_supported = mips_dma_supported
2327 };
2328
2329 -struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2330 +const struct dma_map_ops *mips_dma_map_ops = &mips_default_dma_map_ops;
2331 EXPORT_SYMBOL(mips_dma_map_ops);
2332
2333 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
2334 diff -urNp linux-2.6.39.2/arch/mips/mm/fault.c linux-2.6.39.2/arch/mips/mm/fault.c
2335 --- linux-2.6.39.2/arch/mips/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
2336 +++ linux-2.6.39.2/arch/mips/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
2337 @@ -28,6 +28,23 @@
2338 #include <asm/highmem.h> /* For VMALLOC_END */
2339 #include <linux/kdebug.h>
2340
2341 +#ifdef CONFIG_PAX_PAGEEXEC
2342 +void pax_report_insns(void *pc, void *sp)
2343 +{
2344 + unsigned long i;
2345 +
2346 + printk(KERN_ERR "PAX: bytes at PC: ");
2347 + for (i = 0; i < 5; i++) {
2348 + unsigned int c;
2349 + if (get_user(c, (unsigned int *)pc+i))
2350 + printk(KERN_CONT "???????? ");
2351 + else
2352 + printk(KERN_CONT "%08x ", c);
2353 + }
2354 + printk("\n");
2355 +}
2356 +#endif
2357 +
2358 /*
2359 * This routine handles page faults. It determines the address,
2360 * and the problem, and then passes it off to one of the appropriate
2361 diff -urNp linux-2.6.39.2/arch/mips/mti-malta/malta-pci.c linux-2.6.39.2/arch/mips/mti-malta/malta-pci.c
2362 --- linux-2.6.39.2/arch/mips/mti-malta/malta-pci.c 2011-05-19 00:06:34.000000000 -0400
2363 +++ linux-2.6.39.2/arch/mips/mti-malta/malta-pci.c 2011-05-22 19:36:30.000000000 -0400
2364 @@ -64,9 +64,9 @@ static struct resource msc_io_resource =
2365 .flags = IORESOURCE_IO,
2366 };
2367
2368 -extern struct pci_ops bonito64_pci_ops;
2369 -extern struct pci_ops gt64xxx_pci0_ops;
2370 -extern struct pci_ops msc_pci_ops;
2371 +extern const struct pci_ops bonito64_pci_ops;
2372 +extern const struct pci_ops gt64xxx_pci0_ops;
2373 +extern const struct pci_ops msc_pci_ops;
2374
2375 static struct pci_controller bonito64_controller = {
2376 .pci_ops = &bonito64_pci_ops,
2377 diff -urNp linux-2.6.39.2/arch/mips/nxp/pnx8550/common/pci.c linux-2.6.39.2/arch/mips/nxp/pnx8550/common/pci.c
2378 --- linux-2.6.39.2/arch/mips/nxp/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2379 +++ linux-2.6.39.2/arch/mips/nxp/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2380 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2381 .flags = IORESOURCE_MEM
2382 };
2383
2384 -extern struct pci_ops pnx8550_pci_ops;
2385 +extern const struct pci_ops pnx8550_pci_ops;
2386
2387 static struct pci_controller pnx8550_controller = {
2388 .pci_ops = &pnx8550_pci_ops,
2389 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-au1000.c linux-2.6.39.2/arch/mips/pci/ops-au1000.c
2390 --- linux-2.6.39.2/arch/mips/pci/ops-au1000.c 2011-05-19 00:06:34.000000000 -0400
2391 +++ linux-2.6.39.2/arch/mips/pci/ops-au1000.c 2011-05-22 19:36:30.000000000 -0400
2392 @@ -302,7 +302,7 @@ static int config_write(struct pci_bus *
2393 }
2394 }
2395
2396 -struct pci_ops au1x_pci_ops = {
2397 +const struct pci_ops au1x_pci_ops = {
2398 config_read,
2399 config_write
2400 };
2401 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-bcm63xx.c linux-2.6.39.2/arch/mips/pci/ops-bcm63xx.c
2402 --- linux-2.6.39.2/arch/mips/pci/ops-bcm63xx.c 2011-05-19 00:06:34.000000000 -0400
2403 +++ linux-2.6.39.2/arch/mips/pci/ops-bcm63xx.c 2011-05-22 19:36:30.000000000 -0400
2404 @@ -173,7 +173,7 @@ static int bcm63xx_pci_write(struct pci_
2405 where, size, val);
2406 }
2407
2408 -struct pci_ops bcm63xx_pci_ops = {
2409 +const struct pci_ops bcm63xx_pci_ops = {
2410 .read = bcm63xx_pci_read,
2411 .write = bcm63xx_pci_write
2412 };
2413 @@ -402,7 +402,7 @@ static int bcm63xx_cb_write(struct pci_b
2414 return PCIBIOS_DEVICE_NOT_FOUND;
2415 }
2416
2417 -struct pci_ops bcm63xx_cb_ops = {
2418 +const struct pci_ops bcm63xx_cb_ops = {
2419 .read = bcm63xx_cb_read,
2420 .write = bcm63xx_cb_write,
2421 };
2422 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-bonito64.c linux-2.6.39.2/arch/mips/pci/ops-bonito64.c
2423 --- linux-2.6.39.2/arch/mips/pci/ops-bonito64.c 2011-05-19 00:06:34.000000000 -0400
2424 +++ linux-2.6.39.2/arch/mips/pci/ops-bonito64.c 2011-05-22 19:36:30.000000000 -0400
2425 @@ -155,7 +155,7 @@ static int bonito64_pcibios_write(struct
2426 return PCIBIOS_SUCCESSFUL;
2427 }
2428
2429 -struct pci_ops bonito64_pci_ops = {
2430 +const struct pci_ops bonito64_pci_ops = {
2431 .read = bonito64_pcibios_read,
2432 .write = bonito64_pcibios_write
2433 };
2434 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-bridge.c linux-2.6.39.2/arch/mips/pci/ops-bridge.c
2435 --- linux-2.6.39.2/arch/mips/pci/ops-bridge.c 2011-05-19 00:06:34.000000000 -0400
2436 +++ linux-2.6.39.2/arch/mips/pci/ops-bridge.c 2011-05-22 19:36:30.000000000 -0400
2437 @@ -316,7 +316,7 @@ static int pci_write_config(struct pci_b
2438 return pci_conf0_write_config(bus, devfn, where, size, value);
2439 }
2440
2441 -struct pci_ops bridge_pci_ops = {
2442 +const struct pci_ops bridge_pci_ops = {
2443 .read = pci_read_config,
2444 .write = pci_write_config,
2445 };
2446 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-emma2rh.c linux-2.6.39.2/arch/mips/pci/ops-emma2rh.c
2447 --- linux-2.6.39.2/arch/mips/pci/ops-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2448 +++ linux-2.6.39.2/arch/mips/pci/ops-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2449 @@ -176,7 +176,7 @@ static int pci_config_write(struct pci_b
2450 return PCIBIOS_SUCCESSFUL;
2451 }
2452
2453 -struct pci_ops emma2rh_pci_ops = {
2454 +const struct pci_ops emma2rh_pci_ops = {
2455 .read = pci_config_read,
2456 .write = pci_config_write,
2457 };
2458 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-gt64xxx_pci0.c linux-2.6.39.2/arch/mips/pci/ops-gt64xxx_pci0.c
2459 --- linux-2.6.39.2/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-19 00:06:34.000000000 -0400
2460 +++ linux-2.6.39.2/arch/mips/pci/ops-gt64xxx_pci0.c 2011-05-22 19:36:30.000000000 -0400
2461 @@ -146,7 +146,7 @@ static int gt64xxx_pci0_pcibios_write(st
2462 return PCIBIOS_SUCCESSFUL;
2463 }
2464
2465 -struct pci_ops gt64xxx_pci0_ops = {
2466 +const struct pci_ops gt64xxx_pci0_ops = {
2467 .read = gt64xxx_pci0_pcibios_read,
2468 .write = gt64xxx_pci0_pcibios_write
2469 };
2470 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-loongson2.c linux-2.6.39.2/arch/mips/pci/ops-loongson2.c
2471 --- linux-2.6.39.2/arch/mips/pci/ops-loongson2.c 2011-05-19 00:06:34.000000000 -0400
2472 +++ linux-2.6.39.2/arch/mips/pci/ops-loongson2.c 2011-05-22 19:36:30.000000000 -0400
2473 @@ -174,7 +174,7 @@ static int loongson_pcibios_write(struct
2474 return PCIBIOS_SUCCESSFUL;
2475 }
2476
2477 -struct pci_ops loongson_pci_ops = {
2478 +const struct pci_ops loongson_pci_ops = {
2479 .read = loongson_pcibios_read,
2480 .write = loongson_pcibios_write
2481 };
2482 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-mace.c linux-2.6.39.2/arch/mips/pci/ops-mace.c
2483 --- linux-2.6.39.2/arch/mips/pci/ops-mace.c 2011-05-19 00:06:34.000000000 -0400
2484 +++ linux-2.6.39.2/arch/mips/pci/ops-mace.c 2011-05-22 19:36:30.000000000 -0400
2485 @@ -96,7 +96,7 @@ mace_pci_write_config(struct pci_bus *bu
2486 return PCIBIOS_SUCCESSFUL;
2487 }
2488
2489 -struct pci_ops mace_pci_ops = {
2490 +const struct pci_ops mace_pci_ops = {
2491 .read = mace_pci_read_config,
2492 .write = mace_pci_write_config,
2493 };
2494 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-msc.c linux-2.6.39.2/arch/mips/pci/ops-msc.c
2495 --- linux-2.6.39.2/arch/mips/pci/ops-msc.c 2011-05-19 00:06:34.000000000 -0400
2496 +++ linux-2.6.39.2/arch/mips/pci/ops-msc.c 2011-05-22 19:36:30.000000000 -0400
2497 @@ -142,7 +142,7 @@ static int msc_pcibios_write(struct pci_
2498 return PCIBIOS_SUCCESSFUL;
2499 }
2500
2501 -struct pci_ops msc_pci_ops = {
2502 +const struct pci_ops msc_pci_ops = {
2503 .read = msc_pcibios_read,
2504 .write = msc_pcibios_write
2505 };
2506 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-nile4.c linux-2.6.39.2/arch/mips/pci/ops-nile4.c
2507 --- linux-2.6.39.2/arch/mips/pci/ops-nile4.c 2011-05-19 00:06:34.000000000 -0400
2508 +++ linux-2.6.39.2/arch/mips/pci/ops-nile4.c 2011-05-22 19:36:30.000000000 -0400
2509 @@ -141,7 +141,7 @@ static int nile4_pcibios_write(struct pc
2510 return PCIBIOS_SUCCESSFUL;
2511 }
2512
2513 -struct pci_ops nile4_pci_ops = {
2514 +const struct pci_ops nile4_pci_ops = {
2515 .read = nile4_pcibios_read,
2516 .write = nile4_pcibios_write,
2517 };
2518 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-pmcmsp.c linux-2.6.39.2/arch/mips/pci/ops-pmcmsp.c
2519 --- linux-2.6.39.2/arch/mips/pci/ops-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
2520 +++ linux-2.6.39.2/arch/mips/pci/ops-pmcmsp.c 2011-05-22 19:36:30.000000000 -0400
2521 @@ -904,7 +904,7 @@ msp_pcibios_write_config(struct pci_bus
2522 * write - function for Linux to generate PCI Configuration writes.
2523 *
2524 ****************************************************************************/
2525 -struct pci_ops msp_pci_ops = {
2526 +const struct pci_ops msp_pci_ops = {
2527 .read = msp_pcibios_read_config,
2528 .write = msp_pcibios_write_config
2529 };
2530 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-pnx8550.c linux-2.6.39.2/arch/mips/pci/ops-pnx8550.c
2531 --- linux-2.6.39.2/arch/mips/pci/ops-pnx8550.c 2011-05-19 00:06:34.000000000 -0400
2532 +++ linux-2.6.39.2/arch/mips/pci/ops-pnx8550.c 2011-05-22 19:36:30.000000000 -0400
2533 @@ -276,7 +276,7 @@ static int config_write(struct pci_bus *
2534 }
2535 }
2536
2537 -struct pci_ops pnx8550_pci_ops = {
2538 +const struct pci_ops pnx8550_pci_ops = {
2539 config_read,
2540 config_write
2541 };
2542 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-rc32434.c linux-2.6.39.2/arch/mips/pci/ops-rc32434.c
2543 --- linux-2.6.39.2/arch/mips/pci/ops-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2544 +++ linux-2.6.39.2/arch/mips/pci/ops-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2545 @@ -201,7 +201,7 @@ static int pci_config_write(struct pci_b
2546 }
2547 }
2548
2549 -struct pci_ops rc32434_pci_ops = {
2550 +const struct pci_ops rc32434_pci_ops = {
2551 .read = pci_config_read,
2552 .write = pci_config_write,
2553 };
2554 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-sni.c linux-2.6.39.2/arch/mips/pci/ops-sni.c
2555 --- linux-2.6.39.2/arch/mips/pci/ops-sni.c 2011-05-19 00:06:34.000000000 -0400
2556 +++ linux-2.6.39.2/arch/mips/pci/ops-sni.c 2011-05-22 19:36:30.000000000 -0400
2557 @@ -83,7 +83,7 @@ static int pcimt_write(struct pci_bus *b
2558 return 0;
2559 }
2560
2561 -struct pci_ops sni_pcimt_ops = {
2562 +const struct pci_ops sni_pcimt_ops = {
2563 .read = pcimt_read,
2564 .write = pcimt_write,
2565 };
2566 @@ -158,7 +158,7 @@ static int pcit_write(struct pci_bus *bu
2567 }
2568
2569
2570 -struct pci_ops sni_pcit_ops = {
2571 +const struct pci_ops sni_pcit_ops = {
2572 .read = pcit_read,
2573 .write = pcit_write,
2574 };
2575 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-titan.c linux-2.6.39.2/arch/mips/pci/ops-titan.c
2576 --- linux-2.6.39.2/arch/mips/pci/ops-titan.c 2011-05-19 00:06:34.000000000 -0400
2577 +++ linux-2.6.39.2/arch/mips/pci/ops-titan.c 2011-05-22 19:36:30.000000000 -0400
2578 @@ -105,7 +105,7 @@ static int titan_write_config(struct pci
2579 /*
2580 * Titan PCI structure
2581 */
2582 -struct pci_ops titan_pci_ops = {
2583 +const struct pci_ops titan_pci_ops = {
2584 titan_read_config,
2585 titan_write_config,
2586 };
2587 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-titan-ht.c linux-2.6.39.2/arch/mips/pci/ops-titan-ht.c
2588 --- linux-2.6.39.2/arch/mips/pci/ops-titan-ht.c 2011-05-19 00:06:34.000000000 -0400
2589 +++ linux-2.6.39.2/arch/mips/pci/ops-titan-ht.c 2011-05-22 19:36:30.000000000 -0400
2590 @@ -118,7 +118,7 @@ static int titan_ht_config_write(struct
2591 return PCIBIOS_SUCCESSFUL;
2592 }
2593
2594 -struct pci_ops titan_ht_pci_ops = {
2595 +const struct pci_ops titan_ht_pci_ops = {
2596 .read = titan_ht_config_read,
2597 .write = titan_ht_config_write,
2598 };
2599 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-tx3927.c linux-2.6.39.2/arch/mips/pci/ops-tx3927.c
2600 --- linux-2.6.39.2/arch/mips/pci/ops-tx3927.c 2011-05-19 00:06:34.000000000 -0400
2601 +++ linux-2.6.39.2/arch/mips/pci/ops-tx3927.c 2011-05-22 19:36:30.000000000 -0400
2602 @@ -121,7 +121,7 @@ static int tx3927_pci_write_config(struc
2603 return check_abort();
2604 }
2605
2606 -static struct pci_ops tx3927_pci_ops = {
2607 +static const struct pci_ops tx3927_pci_ops = {
2608 .read = tx3927_pci_read_config,
2609 .write = tx3927_pci_write_config,
2610 };
2611 diff -urNp linux-2.6.39.2/arch/mips/pci/ops-vr41xx.c linux-2.6.39.2/arch/mips/pci/ops-vr41xx.c
2612 --- linux-2.6.39.2/arch/mips/pci/ops-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2613 +++ linux-2.6.39.2/arch/mips/pci/ops-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2614 @@ -120,7 +120,7 @@ static int pci_config_write(struct pci_b
2615 return PCIBIOS_SUCCESSFUL;
2616 }
2617
2618 -struct pci_ops vr41xx_pci_ops = {
2619 +const struct pci_ops vr41xx_pci_ops = {
2620 .read = pci_config_read,
2621 .write = pci_config_write,
2622 };
2623 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-bcm1480.c linux-2.6.39.2/arch/mips/pci/pci-bcm1480.c
2624 --- linux-2.6.39.2/arch/mips/pci/pci-bcm1480.c 2011-05-19 00:06:34.000000000 -0400
2625 +++ linux-2.6.39.2/arch/mips/pci/pci-bcm1480.c 2011-05-22 19:36:30.000000000 -0400
2626 @@ -171,7 +171,7 @@ static int bcm1480_pcibios_write(struct
2627 return PCIBIOS_SUCCESSFUL;
2628 }
2629
2630 -struct pci_ops bcm1480_pci_ops = {
2631 +const struct pci_ops bcm1480_pci_ops = {
2632 bcm1480_pcibios_read,
2633 bcm1480_pcibios_write,
2634 };
2635 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-bcm1480ht.c linux-2.6.39.2/arch/mips/pci/pci-bcm1480ht.c
2636 --- linux-2.6.39.2/arch/mips/pci/pci-bcm1480ht.c 2011-05-19 00:06:34.000000000 -0400
2637 +++ linux-2.6.39.2/arch/mips/pci/pci-bcm1480ht.c 2011-05-22 19:36:30.000000000 -0400
2638 @@ -166,7 +166,7 @@ static int bcm1480ht_pcibios_get_busno(v
2639 return 0;
2640 }
2641
2642 -struct pci_ops bcm1480ht_pci_ops = {
2643 +const struct pci_ops bcm1480ht_pci_ops = {
2644 .read = bcm1480ht_pcibios_read,
2645 .write = bcm1480ht_pcibios_write,
2646 };
2647 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-bcm63xx.h linux-2.6.39.2/arch/mips/pci/pci-bcm63xx.h
2648 --- linux-2.6.39.2/arch/mips/pci/pci-bcm63xx.h 2011-05-19 00:06:34.000000000 -0400
2649 +++ linux-2.6.39.2/arch/mips/pci/pci-bcm63xx.h 2011-05-22 19:36:30.000000000 -0400
2650 @@ -16,8 +16,8 @@
2651 /*
2652 * defined in ops-bcm63xx.c
2653 */
2654 -extern struct pci_ops bcm63xx_pci_ops;
2655 -extern struct pci_ops bcm63xx_cb_ops;
2656 +extern const struct pci_ops bcm63xx_pci_ops;
2657 +extern const struct pci_ops bcm63xx_cb_ops;
2658
2659 /*
2660 * defined in pci-bcm63xx.c
2661 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-emma2rh.c linux-2.6.39.2/arch/mips/pci/pci-emma2rh.c
2662 --- linux-2.6.39.2/arch/mips/pci/pci-emma2rh.c 2011-05-19 00:06:34.000000000 -0400
2663 +++ linux-2.6.39.2/arch/mips/pci/pci-emma2rh.c 2011-05-22 19:36:30.000000000 -0400
2664 @@ -43,7 +43,7 @@ static struct resource pci_mem_resource
2665 .flags = IORESOURCE_MEM,
2666 };
2667
2668 -extern struct pci_ops emma2rh_pci_ops;
2669 +extern const struct pci_ops emma2rh_pci_ops;
2670
2671 static struct pci_controller emma2rh_pci_controller = {
2672 .pci_ops = &emma2rh_pci_ops,
2673 diff -urNp linux-2.6.39.2/arch/mips/pci/pcie-octeon.c linux-2.6.39.2/arch/mips/pci/pcie-octeon.c
2674 --- linux-2.6.39.2/arch/mips/pci/pcie-octeon.c 2011-05-19 00:06:34.000000000 -0400
2675 +++ linux-2.6.39.2/arch/mips/pci/pcie-octeon.c 2011-05-22 19:36:30.000000000 -0400
2676 @@ -1237,7 +1237,7 @@ static int octeon_pcie1_write_config(str
2677 return octeon_pcie_write_config(1, bus, devfn, reg, size, val);
2678 }
2679
2680 -static struct pci_ops octeon_pcie0_ops = {
2681 +static const struct pci_ops octeon_pcie0_ops = {
2682 octeon_pcie0_read_config,
2683 octeon_pcie0_write_config,
2684 };
2685 @@ -1258,7 +1258,7 @@ static struct pci_controller octeon_pcie
2686 .io_resource = &octeon_pcie0_io_resource,
2687 };
2688
2689 -static struct pci_ops octeon_pcie1_ops = {
2690 +static const struct pci_ops octeon_pcie1_ops = {
2691 octeon_pcie1_read_config,
2692 octeon_pcie1_write_config,
2693 };
2694 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-ip27.c linux-2.6.39.2/arch/mips/pci/pci-ip27.c
2695 --- linux-2.6.39.2/arch/mips/pci/pci-ip27.c 2011-05-19 00:06:34.000000000 -0400
2696 +++ linux-2.6.39.2/arch/mips/pci/pci-ip27.c 2011-05-22 19:36:30.000000000 -0400
2697 @@ -39,7 +39,7 @@ static struct bridge_controller bridges[
2698 struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2699 int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
2700
2701 -extern struct pci_ops bridge_pci_ops;
2702 +extern const struct pci_ops bridge_pci_ops;
2703
2704 int __cpuinit bridge_probe(nasid_t nasid, int widget_id, int masterwid)
2705 {
2706 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-ip32.c linux-2.6.39.2/arch/mips/pci/pci-ip32.c
2707 --- linux-2.6.39.2/arch/mips/pci/pci-ip32.c 2011-05-19 00:06:34.000000000 -0400
2708 +++ linux-2.6.39.2/arch/mips/pci/pci-ip32.c 2011-05-22 19:36:30.000000000 -0400
2709 @@ -82,7 +82,7 @@ static irqreturn_t macepci_error(int irq
2710 }
2711
2712
2713 -extern struct pci_ops mace_pci_ops;
2714 +extern const struct pci_ops mace_pci_ops;
2715 #ifdef CONFIG_64BIT
2716 static struct resource mace_pci_mem_resource = {
2717 .name = "SGI O2 PCI MEM",
2718 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-lasat.c linux-2.6.39.2/arch/mips/pci/pci-lasat.c
2719 --- linux-2.6.39.2/arch/mips/pci/pci-lasat.c 2011-05-19 00:06:34.000000000 -0400
2720 +++ linux-2.6.39.2/arch/mips/pci/pci-lasat.c 2011-05-22 19:36:30.000000000 -0400
2721 @@ -14,8 +14,8 @@
2722
2723 #include <irq.h>
2724
2725 -extern struct pci_ops nile4_pci_ops;
2726 -extern struct pci_ops gt64xxx_pci0_ops;
2727 +extern const struct pci_ops nile4_pci_ops;
2728 +extern const struct pci_ops gt64xxx_pci0_ops;
2729 static struct resource lasat_pci_mem_resource = {
2730 .name = "LASAT PCI MEM",
2731 .start = 0x18000000,
2732 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-octeon.c linux-2.6.39.2/arch/mips/pci/pci-octeon.c
2733 --- linux-2.6.39.2/arch/mips/pci/pci-octeon.c 2011-05-19 00:06:34.000000000 -0400
2734 +++ linux-2.6.39.2/arch/mips/pci/pci-octeon.c 2011-05-22 19:36:30.000000000 -0400
2735 @@ -334,7 +334,7 @@ static int octeon_write_config(struct pc
2736 }
2737
2738
2739 -static struct pci_ops octeon_pci_ops = {
2740 +static const struct pci_ops octeon_pci_ops = {
2741 octeon_read_config,
2742 octeon_write_config,
2743 };
2744 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-rc32434.c linux-2.6.39.2/arch/mips/pci/pci-rc32434.c
2745 --- linux-2.6.39.2/arch/mips/pci/pci-rc32434.c 2011-05-19 00:06:34.000000000 -0400
2746 +++ linux-2.6.39.2/arch/mips/pci/pci-rc32434.c 2011-05-22 19:36:30.000000000 -0400
2747 @@ -75,7 +75,7 @@ static struct resource rc32434_res_pci_i
2748 .flags = IORESOURCE_IO,
2749 };
2750
2751 -extern struct pci_ops rc32434_pci_ops;
2752 +extern const struct pci_ops rc32434_pci_ops;
2753
2754 #define PCI_MEM1_START PCI_ADDR_START
2755 #define PCI_MEM1_END (PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
2756 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-sb1250.c linux-2.6.39.2/arch/mips/pci/pci-sb1250.c
2757 --- linux-2.6.39.2/arch/mips/pci/pci-sb1250.c 2011-05-19 00:06:34.000000000 -0400
2758 +++ linux-2.6.39.2/arch/mips/pci/pci-sb1250.c 2011-05-22 19:36:30.000000000 -0400
2759 @@ -181,7 +181,7 @@ static int sb1250_pcibios_write(struct p
2760 return PCIBIOS_SUCCESSFUL;
2761 }
2762
2763 -struct pci_ops sb1250_pci_ops = {
2764 +const struct pci_ops sb1250_pci_ops = {
2765 .read = sb1250_pcibios_read,
2766 .write = sb1250_pcibios_write,
2767 };
2768 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-vr41xx.c linux-2.6.39.2/arch/mips/pci/pci-vr41xx.c
2769 --- linux-2.6.39.2/arch/mips/pci/pci-vr41xx.c 2011-05-19 00:06:34.000000000 -0400
2770 +++ linux-2.6.39.2/arch/mips/pci/pci-vr41xx.c 2011-05-22 19:36:30.000000000 -0400
2771 @@ -36,7 +36,7 @@
2772
2773 #include "pci-vr41xx.h"
2774
2775 -extern struct pci_ops vr41xx_pci_ops;
2776 +extern const struct pci_ops vr41xx_pci_ops;
2777
2778 static void __iomem *pciu_base;
2779
2780 diff -urNp linux-2.6.39.2/arch/mips/pci/pci-yosemite.c linux-2.6.39.2/arch/mips/pci/pci-yosemite.c
2781 --- linux-2.6.39.2/arch/mips/pci/pci-yosemite.c 2011-05-19 00:06:34.000000000 -0400
2782 +++ linux-2.6.39.2/arch/mips/pci/pci-yosemite.c 2011-05-22 19:36:30.000000000 -0400
2783 @@ -11,7 +11,7 @@
2784 #include <linux/pci.h>
2785 #include <asm/titan_dep.h>
2786
2787 -extern struct pci_ops titan_pci_ops;
2788 +extern const struct pci_ops titan_pci_ops;
2789
2790 static struct resource py_mem_resource = {
2791 .start = 0xe0000000UL,
2792 diff -urNp linux-2.6.39.2/arch/mips/pmc-sierra/yosemite/ht.c linux-2.6.39.2/arch/mips/pmc-sierra/yosemite/ht.c
2793 --- linux-2.6.39.2/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-19 00:06:34.000000000 -0400
2794 +++ linux-2.6.39.2/arch/mips/pmc-sierra/yosemite/ht.c 2011-05-22 19:36:30.000000000 -0400
2795 @@ -366,7 +366,7 @@ resource_size_t pcibios_align_resource(v
2796 return start;
2797 }
2798
2799 -struct pci_ops titan_pci_ops = {
2800 +const struct pci_ops titan_pci_ops = {
2801 titan_ht_config_read_byte,
2802 titan_ht_config_read_word,
2803 titan_ht_config_read_dword,
2804 diff -urNp linux-2.6.39.2/arch/mips/pnx8550/common/pci.c linux-2.6.39.2/arch/mips/pnx8550/common/pci.c
2805 --- linux-2.6.39.2/arch/mips/pnx8550/common/pci.c 2011-05-19 00:06:34.000000000 -0400
2806 +++ linux-2.6.39.2/arch/mips/pnx8550/common/pci.c 2011-05-22 19:36:30.000000000 -0400
2807 @@ -40,7 +40,7 @@ static struct resource pci_mem_resource
2808 .flags = IORESOURCE_MEM
2809 };
2810
2811 -extern struct pci_ops pnx8550_pci_ops;
2812 +extern const struct pci_ops pnx8550_pci_ops;
2813
2814 static struct pci_controller pnx8550_controller = {
2815 .pci_ops = &pnx8550_pci_ops,
2816 diff -urNp linux-2.6.39.2/arch/mips/sni/pcimt.c linux-2.6.39.2/arch/mips/sni/pcimt.c
2817 --- linux-2.6.39.2/arch/mips/sni/pcimt.c 2011-05-19 00:06:34.000000000 -0400
2818 +++ linux-2.6.39.2/arch/mips/sni/pcimt.c 2011-05-22 19:36:30.000000000 -0400
2819 @@ -183,7 +183,7 @@ static void __init sni_pcimt_resource_in
2820 request_resource(&sni_mem_resource, pcimt_mem_resources + i);
2821 }
2822
2823 -extern struct pci_ops sni_pcimt_ops;
2824 +extern const struct pci_ops sni_pcimt_ops;
2825
2826 static struct pci_controller sni_controller = {
2827 .pci_ops = &sni_pcimt_ops,
2828 diff -urNp linux-2.6.39.2/arch/mips/sni/pcit.c linux-2.6.39.2/arch/mips/sni/pcit.c
2829 --- linux-2.6.39.2/arch/mips/sni/pcit.c 2011-05-19 00:06:34.000000000 -0400
2830 +++ linux-2.6.39.2/arch/mips/sni/pcit.c 2011-05-22 19:36:30.000000000 -0400
2831 @@ -145,7 +145,7 @@ static void __init sni_pcit_resource_ini
2832 }
2833
2834
2835 -extern struct pci_ops sni_pcit_ops;
2836 +extern const struct pci_ops sni_pcit_ops;
2837
2838 static struct pci_controller sni_pcit_controller = {
2839 .pci_ops = &sni_pcit_ops,
2840 diff -urNp linux-2.6.39.2/arch/mips/wrppmc/pci.c linux-2.6.39.2/arch/mips/wrppmc/pci.c
2841 --- linux-2.6.39.2/arch/mips/wrppmc/pci.c 2011-05-19 00:06:34.000000000 -0400
2842 +++ linux-2.6.39.2/arch/mips/wrppmc/pci.c 2011-05-22 19:36:30.000000000 -0400
2843 @@ -14,7 +14,7 @@
2844
2845 #include <asm/gt64120.h>
2846
2847 -extern struct pci_ops gt64xxx_pci0_ops;
2848 +extern const struct pci_ops gt64xxx_pci0_ops;
2849
2850 static struct resource pci0_io_resource = {
2851 .name = "pci_0 io",
2852 diff -urNp linux-2.6.39.2/arch/mn10300/unit-asb2305/pci-asb2305.h linux-2.6.39.2/arch/mn10300/unit-asb2305/pci-asb2305.h
2853 --- linux-2.6.39.2/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-19 00:06:34.000000000 -0400
2854 +++ linux-2.6.39.2/arch/mn10300/unit-asb2305/pci-asb2305.h 2011-05-22 19:36:30.000000000 -0400
2855 @@ -39,7 +39,7 @@ extern void pcibios_resource_survey(void
2856
2857 extern int pcibios_last_bus;
2858 extern struct pci_bus *pci_root_bus;
2859 -extern struct pci_ops *pci_root_ops;
2860 +extern const struct pci_ops *pci_root_ops;
2861
2862 extern struct irq_routing_table *pcibios_get_irq_routing_table(void);
2863 extern int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
2864 diff -urNp linux-2.6.39.2/arch/mn10300/unit-asb2305/pci.c linux-2.6.39.2/arch/mn10300/unit-asb2305/pci.c
2865 --- linux-2.6.39.2/arch/mn10300/unit-asb2305/pci.c 2011-05-19 00:06:34.000000000 -0400
2866 +++ linux-2.6.39.2/arch/mn10300/unit-asb2305/pci.c 2011-05-22 19:36:30.000000000 -0400
2867 @@ -24,7 +24,7 @@ unsigned int pci_probe = 1;
2868
2869 int pcibios_last_bus = -1;
2870 struct pci_bus *pci_root_bus;
2871 -struct pci_ops *pci_root_ops;
2872 +const struct pci_ops *pci_root_ops;
2873
2874 /*
2875 * The accessible PCI window does not cover the entire CPU address space, but
2876 @@ -274,7 +274,7 @@ static int pci_ampci_write_config(struct
2877 }
2878 }
2879
2880 -static struct pci_ops pci_direct_ampci = {
2881 +static const struct pci_ops pci_direct_ampci = {
2882 pci_ampci_read_config,
2883 pci_ampci_write_config,
2884 };
2885 @@ -289,7 +289,7 @@ static struct pci_ops pci_direct_ampci =
2886 * This should be close to trivial, but it isn't, because there are buggy
2887 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
2888 */
2889 -static int __init pci_sanity_check(struct pci_ops *o)
2890 +static int __init pci_sanity_check(const struct pci_ops *o)
2891 {
2892 struct pci_bus bus; /* Fake bus and device */
2893 u32 x;
2894 diff -urNp linux-2.6.39.2/arch/parisc/include/asm/elf.h linux-2.6.39.2/arch/parisc/include/asm/elf.h
2895 --- linux-2.6.39.2/arch/parisc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
2896 +++ linux-2.6.39.2/arch/parisc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
2897 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration..
2898
2899 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2900
2901 +#ifdef CONFIG_PAX_ASLR
2902 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
2903 +
2904 +#define PAX_DELTA_MMAP_LEN 16
2905 +#define PAX_DELTA_STACK_LEN 16
2906 +#endif
2907 +
2908 /* This yields a mask that user programs can use to figure out what
2909 instruction set this CPU supports. This could be done in user space,
2910 but it's not easy, and we've already done it here. */
2911 diff -urNp linux-2.6.39.2/arch/parisc/include/asm/pgtable.h linux-2.6.39.2/arch/parisc/include/asm/pgtable.h
2912 --- linux-2.6.39.2/arch/parisc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
2913 +++ linux-2.6.39.2/arch/parisc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
2914 @@ -207,6 +207,17 @@ struct vm_area_struct;
2915 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2916 #define PAGE_COPY PAGE_EXECREAD
2917 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2918 +
2919 +#ifdef CONFIG_PAX_PAGEEXEC
2920 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2921 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2922 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2923 +#else
2924 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2925 +# define PAGE_COPY_NOEXEC PAGE_COPY
2926 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2927 +#endif
2928 +
2929 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2930 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2931 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2932 diff -urNp linux-2.6.39.2/arch/parisc/kernel/module.c linux-2.6.39.2/arch/parisc/kernel/module.c
2933 --- linux-2.6.39.2/arch/parisc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
2934 +++ linux-2.6.39.2/arch/parisc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
2935 @@ -96,16 +96,38 @@
2936
2937 /* three functions to determine where in the module core
2938 * or init pieces the location is */
2939 +static inline int in_init_rx(struct module *me, void *loc)
2940 +{
2941 + return (loc >= me->module_init_rx &&
2942 + loc < (me->module_init_rx + me->init_size_rx));
2943 +}
2944 +
2945 +static inline int in_init_rw(struct module *me, void *loc)
2946 +{
2947 + return (loc >= me->module_init_rw &&
2948 + loc < (me->module_init_rw + me->init_size_rw));
2949 +}
2950 +
2951 static inline int in_init(struct module *me, void *loc)
2952 {
2953 - return (loc >= me->module_init &&
2954 - loc <= (me->module_init + me->init_size));
2955 + return in_init_rx(me, loc) || in_init_rw(me, loc);
2956 +}
2957 +
2958 +static inline int in_core_rx(struct module *me, void *loc)
2959 +{
2960 + return (loc >= me->module_core_rx &&
2961 + loc < (me->module_core_rx + me->core_size_rx));
2962 +}
2963 +
2964 +static inline int in_core_rw(struct module *me, void *loc)
2965 +{
2966 + return (loc >= me->module_core_rw &&
2967 + loc < (me->module_core_rw + me->core_size_rw));
2968 }
2969
2970 static inline int in_core(struct module *me, void *loc)
2971 {
2972 - return (loc >= me->module_core &&
2973 - loc <= (me->module_core + me->core_size));
2974 + return in_core_rx(me, loc) || in_core_rw(me, loc);
2975 }
2976
2977 static inline int in_local(struct module *me, void *loc)
2978 @@ -365,13 +387,13 @@ int module_frob_arch_sections(CONST Elf_
2979 }
2980
2981 /* align things a bit */
2982 - me->core_size = ALIGN(me->core_size, 16);
2983 - me->arch.got_offset = me->core_size;
2984 - me->core_size += gots * sizeof(struct got_entry);
2985 -
2986 - me->core_size = ALIGN(me->core_size, 16);
2987 - me->arch.fdesc_offset = me->core_size;
2988 - me->core_size += fdescs * sizeof(Elf_Fdesc);
2989 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2990 + me->arch.got_offset = me->core_size_rw;
2991 + me->core_size_rw += gots * sizeof(struct got_entry);
2992 +
2993 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
2994 + me->arch.fdesc_offset = me->core_size_rw;
2995 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2996
2997 me->arch.got_max = gots;
2998 me->arch.fdesc_max = fdescs;
2999 @@ -389,7 +411,7 @@ static Elf64_Word get_got(struct module
3000
3001 BUG_ON(value == 0);
3002
3003 - got = me->module_core + me->arch.got_offset;
3004 + got = me->module_core_rw + me->arch.got_offset;
3005 for (i = 0; got[i].addr; i++)
3006 if (got[i].addr == value)
3007 goto out;
3008 @@ -407,7 +429,7 @@ static Elf64_Word get_got(struct module
3009 #ifdef CONFIG_64BIT
3010 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3011 {
3012 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3013 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3014
3015 if (!value) {
3016 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3017 @@ -425,7 +447,7 @@ static Elf_Addr get_fdesc(struct module
3018
3019 /* Create new one */
3020 fdesc->addr = value;
3021 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3022 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3023 return (Elf_Addr)fdesc;
3024 }
3025 #endif /* CONFIG_64BIT */
3026 @@ -849,7 +871,7 @@ register_unwind_table(struct module *me,
3027
3028 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3029 end = table + sechdrs[me->arch.unwind_section].sh_size;
3030 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3031 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3032
3033 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3034 me->arch.unwind_section, table, end, gp);
3035 diff -urNp linux-2.6.39.2/arch/parisc/kernel/sys_parisc.c linux-2.6.39.2/arch/parisc/kernel/sys_parisc.c
3036 --- linux-2.6.39.2/arch/parisc/kernel/sys_parisc.c 2011-05-19 00:06:34.000000000 -0400
3037 +++ linux-2.6.39.2/arch/parisc/kernel/sys_parisc.c 2011-05-22 19:36:30.000000000 -0400
3038 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(u
3039 /* At this point: (!vma || addr < vma->vm_end). */
3040 if (TASK_SIZE - len < addr)
3041 return -ENOMEM;
3042 - if (!vma || addr + len <= vma->vm_start)
3043 + if (check_heap_stack_gap(vma, addr, len))
3044 return addr;
3045 addr = vma->vm_end;
3046 }
3047 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(str
3048 /* At this point: (!vma || addr < vma->vm_end). */
3049 if (TASK_SIZE - len < addr)
3050 return -ENOMEM;
3051 - if (!vma || addr + len <= vma->vm_start)
3052 + if (check_heap_stack_gap(vma, addr, len))
3053 return addr;
3054 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3055 if (addr < vma->vm_end) /* handle wraparound */
3056 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
3057 if (flags & MAP_FIXED)
3058 return addr;
3059 if (!addr)
3060 - addr = TASK_UNMAPPED_BASE;
3061 + addr = current->mm->mmap_base;
3062
3063 if (filp) {
3064 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3065 diff -urNp linux-2.6.39.2/arch/parisc/kernel/traps.c linux-2.6.39.2/arch/parisc/kernel/traps.c
3066 --- linux-2.6.39.2/arch/parisc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
3067 +++ linux-2.6.39.2/arch/parisc/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
3068 @@ -733,9 +733,7 @@ void notrace handle_interruption(int cod
3069
3070 down_read(&current->mm->mmap_sem);
3071 vma = find_vma(current->mm,regs->iaoq[0]);
3072 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3073 - && (vma->vm_flags & VM_EXEC)) {
3074 -
3075 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3076 fault_address = regs->iaoq[0];
3077 fault_space = regs->iasq[0];
3078
3079 diff -urNp linux-2.6.39.2/arch/parisc/mm/fault.c linux-2.6.39.2/arch/parisc/mm/fault.c
3080 --- linux-2.6.39.2/arch/parisc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
3081 +++ linux-2.6.39.2/arch/parisc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
3082 @@ -15,6 +15,7 @@
3083 #include <linux/sched.h>
3084 #include <linux/interrupt.h>
3085 #include <linux/module.h>
3086 +#include <linux/unistd.h>
3087
3088 #include <asm/uaccess.h>
3089 #include <asm/traps.h>
3090 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, ex
3091 static unsigned long
3092 parisc_acctyp(unsigned long code, unsigned int inst)
3093 {
3094 - if (code == 6 || code == 16)
3095 + if (code == 6 || code == 7 || code == 16)
3096 return VM_EXEC;
3097
3098 switch (inst & 0xf0000000) {
3099 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsign
3100 }
3101 #endif
3102
3103 +#ifdef CONFIG_PAX_PAGEEXEC
3104 +/*
3105 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3106 + *
3107 + * returns 1 when task should be killed
3108 + * 2 when rt_sigreturn trampoline was detected
3109 + * 3 when unpatched PLT trampoline was detected
3110 + */
3111 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3112 +{
3113 +
3114 +#ifdef CONFIG_PAX_EMUPLT
3115 + int err;
3116 +
3117 + do { /* PaX: unpatched PLT emulation */
3118 + unsigned int bl, depwi;
3119 +
3120 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3121 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3122 +
3123 + if (err)
3124 + break;
3125 +
3126 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3127 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3128 +
3129 + err = get_user(ldw, (unsigned int *)addr);
3130 + err |= get_user(bv, (unsigned int *)(addr+4));
3131 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3132 +
3133 + if (err)
3134 + break;
3135 +
3136 + if (ldw == 0x0E801096U &&
3137 + bv == 0xEAC0C000U &&
3138 + ldw2 == 0x0E881095U)
3139 + {
3140 + unsigned int resolver, map;
3141 +
3142 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3143 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3144 + if (err)
3145 + break;
3146 +
3147 + regs->gr[20] = instruction_pointer(regs)+8;
3148 + regs->gr[21] = map;
3149 + regs->gr[22] = resolver;
3150 + regs->iaoq[0] = resolver | 3UL;
3151 + regs->iaoq[1] = regs->iaoq[0] + 4;
3152 + return 3;
3153 + }
3154 + }
3155 + } while (0);
3156 +#endif
3157 +
3158 +#ifdef CONFIG_PAX_EMUTRAMP
3159 +
3160 +#ifndef CONFIG_PAX_EMUSIGRT
3161 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3162 + return 1;
3163 +#endif
3164 +
3165 + do { /* PaX: rt_sigreturn emulation */
3166 + unsigned int ldi1, ldi2, bel, nop;
3167 +
3168 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3169 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3170 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3171 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3172 +
3173 + if (err)
3174 + break;
3175 +
3176 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3177 + ldi2 == 0x3414015AU &&
3178 + bel == 0xE4008200U &&
3179 + nop == 0x08000240U)
3180 + {
3181 + regs->gr[25] = (ldi1 & 2) >> 1;
3182 + regs->gr[20] = __NR_rt_sigreturn;
3183 + regs->gr[31] = regs->iaoq[1] + 16;
3184 + regs->sr[0] = regs->iasq[1];
3185 + regs->iaoq[0] = 0x100UL;
3186 + regs->iaoq[1] = regs->iaoq[0] + 4;
3187 + regs->iasq[0] = regs->sr[2];
3188 + regs->iasq[1] = regs->sr[2];
3189 + return 2;
3190 + }
3191 + } while (0);
3192 +#endif
3193 +
3194 + return 1;
3195 +}
3196 +
3197 +void pax_report_insns(void *pc, void *sp)
3198 +{
3199 + unsigned long i;
3200 +
3201 + printk(KERN_ERR "PAX: bytes at PC: ");
3202 + for (i = 0; i < 5; i++) {
3203 + unsigned int c;
3204 + if (get_user(c, (unsigned int *)pc+i))
3205 + printk(KERN_CONT "???????? ");
3206 + else
3207 + printk(KERN_CONT "%08x ", c);
3208 + }
3209 + printk("\n");
3210 +}
3211 +#endif
3212 +
3213 int fixup_exception(struct pt_regs *regs)
3214 {
3215 const struct exception_table_entry *fix;
3216 @@ -192,8 +303,33 @@ good_area:
3217
3218 acc_type = parisc_acctyp(code,regs->iir);
3219
3220 - if ((vma->vm_flags & acc_type) != acc_type)
3221 + if ((vma->vm_flags & acc_type) != acc_type) {
3222 +
3223 +#ifdef CONFIG_PAX_PAGEEXEC
3224 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3225 + (address & ~3UL) == instruction_pointer(regs))
3226 + {
3227 + up_read(&mm->mmap_sem);
3228 + switch (pax_handle_fetch_fault(regs)) {
3229 +
3230 +#ifdef CONFIG_PAX_EMUPLT
3231 + case 3:
3232 + return;
3233 +#endif
3234 +
3235 +#ifdef CONFIG_PAX_EMUTRAMP
3236 + case 2:
3237 + return;
3238 +#endif
3239 +
3240 + }
3241 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3242 + do_group_exit(SIGKILL);
3243 + }
3244 +#endif
3245 +
3246 goto bad_area;
3247 + }
3248
3249 /*
3250 * If for any reason at all we couldn't handle the fault, make
3251 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/device.h linux-2.6.39.2/arch/powerpc/include/asm/device.h
3252 --- linux-2.6.39.2/arch/powerpc/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
3253 +++ linux-2.6.39.2/arch/powerpc/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
3254 @@ -17,7 +17,7 @@ struct device_node;
3255 */
3256 struct dev_archdata {
3257 /* DMA operations on that device */
3258 - struct dma_map_ops *dma_ops;
3259 + const struct dma_map_ops *dma_ops;
3260
3261 /*
3262 * When an iommu is in use, dma_data is used as a ptr to the base of the
3263 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/dma-mapping.h linux-2.6.39.2/arch/powerpc/include/asm/dma-mapping.h
3264 --- linux-2.6.39.2/arch/powerpc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
3265 +++ linux-2.6.39.2/arch/powerpc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
3266 @@ -67,12 +67,13 @@ static inline unsigned long device_to_ma
3267 /*
3268 * Available generic sets of operations
3269 */
3270 +/* cannot be const */
3271 #ifdef CONFIG_PPC64
3272 -extern struct dma_map_ops dma_iommu_ops;
3273 +extern const struct dma_map_ops dma_iommu_ops;
3274 #endif
3275 -extern struct dma_map_ops dma_direct_ops;
3276 +extern const struct dma_map_ops dma_direct_ops;
3277
3278 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
3279 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
3280 {
3281 /* We don't handle the NULL dev case for ISA for now. We could
3282 * do it via an out of line call but it is not needed for now. The
3283 @@ -85,7 +86,7 @@ static inline struct dma_map_ops *get_dm
3284 return dev->archdata.dma_ops;
3285 }
3286
3287 -static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
3288 +static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
3289 {
3290 dev->archdata.dma_ops = ops;
3291 }
3292 @@ -119,7 +120,7 @@ static inline void set_dma_offset(struct
3293
3294 static inline int dma_supported(struct device *dev, u64 mask)
3295 {
3296 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3297 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3298
3299 if (unlikely(dma_ops == NULL))
3300 return 0;
3301 @@ -133,7 +134,7 @@ extern int dma_set_mask(struct device *d
3302 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
3303 dma_addr_t *dma_handle, gfp_t flag)
3304 {
3305 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3306 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3307 void *cpu_addr;
3308
3309 BUG_ON(!dma_ops);
3310 @@ -148,7 +149,7 @@ static inline void *dma_alloc_coherent(s
3311 static inline void dma_free_coherent(struct device *dev, size_t size,
3312 void *cpu_addr, dma_addr_t dma_handle)
3313 {
3314 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3315 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3316
3317 BUG_ON(!dma_ops);
3318
3319 @@ -159,7 +160,7 @@ static inline void dma_free_coherent(str
3320
3321 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
3322 {
3323 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3324 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3325
3326 if (dma_ops->mapping_error)
3327 return dma_ops->mapping_error(dev, dma_addr);
3328 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/elf.h linux-2.6.39.2/arch/powerpc/include/asm/elf.h
3329 --- linux-2.6.39.2/arch/powerpc/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
3330 +++ linux-2.6.39.2/arch/powerpc/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
3331 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3332 the loader. We need to make sure that it is out of the way of the program
3333 that it will "exec", and that there is sufficient room for the brk. */
3334
3335 -extern unsigned long randomize_et_dyn(unsigned long base);
3336 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3337 +#define ELF_ET_DYN_BASE (0x20000000)
3338 +
3339 +#ifdef CONFIG_PAX_ASLR
3340 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3341 +
3342 +#ifdef __powerpc64__
3343 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3344 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3345 +#else
3346 +#define PAX_DELTA_MMAP_LEN 15
3347 +#define PAX_DELTA_STACK_LEN 15
3348 +#endif
3349 +#endif
3350
3351 /*
3352 * Our registers are always unsigned longs, whether we're a 32 bit
3353 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(s
3354 (0x7ff >> (PAGE_SHIFT - 12)) : \
3355 (0x3ffff >> (PAGE_SHIFT - 12)))
3356
3357 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3358 -#define arch_randomize_brk arch_randomize_brk
3359 -
3360 #endif /* __KERNEL__ */
3361
3362 /*
3363 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/iommu.h linux-2.6.39.2/arch/powerpc/include/asm/iommu.h
3364 --- linux-2.6.39.2/arch/powerpc/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
3365 +++ linux-2.6.39.2/arch/powerpc/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
3366 @@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(voi
3367 extern void iommu_init_early_dart(void);
3368 extern void iommu_init_early_pasemi(void);
3369
3370 +/* dma-iommu.c */
3371 +extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
3372 +
3373 #ifdef CONFIG_PCI
3374 extern void pci_iommu_init(void);
3375 extern void pci_direct_iommu_init(void);
3376 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/kmap_types.h linux-2.6.39.2/arch/powerpc/include/asm/kmap_types.h
3377 --- linux-2.6.39.2/arch/powerpc/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
3378 +++ linux-2.6.39.2/arch/powerpc/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
3379 @@ -27,6 +27,7 @@ enum km_type {
3380 KM_PPC_SYNC_PAGE,
3381 KM_PPC_SYNC_ICACHE,
3382 KM_KDB,
3383 + KM_CLEARPAGE,
3384 KM_TYPE_NR
3385 };
3386
3387 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/page_64.h linux-2.6.39.2/arch/powerpc/include/asm/page_64.h
3388 --- linux-2.6.39.2/arch/powerpc/include/asm/page_64.h 2011-05-19 00:06:34.000000000 -0400
3389 +++ linux-2.6.39.2/arch/powerpc/include/asm/page_64.h 2011-05-22 19:36:30.000000000 -0400
3390 @@ -172,15 +172,18 @@ do { \
3391 * stack by default, so in the absence of a PT_GNU_STACK program header
3392 * we turn execute permission off.
3393 */
3394 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3395 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3396 +#define VM_STACK_DEFAULT_FLAGS32 \
3397 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3398 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3399
3400 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3401 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3402
3403 +#ifndef CONFIG_PAX_PAGEEXEC
3404 #define VM_STACK_DEFAULT_FLAGS \
3405 (is_32bit_task() ? \
3406 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3407 +#endif
3408
3409 #include <asm-generic/getorder.h>
3410
3411 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/page.h linux-2.6.39.2/arch/powerpc/include/asm/page.h
3412 --- linux-2.6.39.2/arch/powerpc/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
3413 +++ linux-2.6.39.2/arch/powerpc/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
3414 @@ -129,8 +129,9 @@ extern phys_addr_t kernstart_addr;
3415 * and needs to be executable. This means the whole heap ends
3416 * up being executable.
3417 */
3418 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3419 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3420 +#define VM_DATA_DEFAULT_FLAGS32 \
3421 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3422 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3423
3424 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3425 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3426 @@ -158,6 +159,9 @@ extern phys_addr_t kernstart_addr;
3427 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3428 #endif
3429
3430 +#define ktla_ktva(addr) (addr)
3431 +#define ktva_ktla(addr) (addr)
3432 +
3433 #ifndef __ASSEMBLY__
3434
3435 #undef STRICT_MM_TYPECHECKS
3436 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/pci.h linux-2.6.39.2/arch/powerpc/include/asm/pci.h
3437 --- linux-2.6.39.2/arch/powerpc/include/asm/pci.h 2011-05-19 00:06:34.000000000 -0400
3438 +++ linux-2.6.39.2/arch/powerpc/include/asm/pci.h 2011-05-22 19:36:30.000000000 -0400
3439 @@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq
3440 }
3441
3442 #ifdef CONFIG_PCI
3443 -extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
3444 -extern struct dma_map_ops *get_pci_dma_ops(void);
3445 +extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
3446 +extern const struct dma_map_ops *get_pci_dma_ops(void);
3447 #else /* CONFIG_PCI */
3448 #define set_pci_dma_ops(d)
3449 #define get_pci_dma_ops() NULL
3450 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/pgtable.h linux-2.6.39.2/arch/powerpc/include/asm/pgtable.h
3451 --- linux-2.6.39.2/arch/powerpc/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
3452 +++ linux-2.6.39.2/arch/powerpc/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
3453 @@ -2,6 +2,7 @@
3454 #define _ASM_POWERPC_PGTABLE_H
3455 #ifdef __KERNEL__
3456
3457 +#include <linux/const.h>
3458 #ifndef __ASSEMBLY__
3459 #include <asm/processor.h> /* For TASK_SIZE */
3460 #include <asm/mmu.h>
3461 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/pte-hash32.h linux-2.6.39.2/arch/powerpc/include/asm/pte-hash32.h
3462 --- linux-2.6.39.2/arch/powerpc/include/asm/pte-hash32.h 2011-05-19 00:06:34.000000000 -0400
3463 +++ linux-2.6.39.2/arch/powerpc/include/asm/pte-hash32.h 2011-05-22 19:36:30.000000000 -0400
3464 @@ -21,6 +21,7 @@
3465 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3466 #define _PAGE_USER 0x004 /* usermode access allowed */
3467 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3468 +#define _PAGE_EXEC _PAGE_GUARDED
3469 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3470 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3471 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3472 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/reg.h linux-2.6.39.2/arch/powerpc/include/asm/reg.h
3473 --- linux-2.6.39.2/arch/powerpc/include/asm/reg.h 2011-05-19 00:06:34.000000000 -0400
3474 +++ linux-2.6.39.2/arch/powerpc/include/asm/reg.h 2011-05-22 19:36:30.000000000 -0400
3475 @@ -201,6 +201,7 @@
3476 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3477 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3478 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3479 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3480 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3481 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3482 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3483 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/swiotlb.h linux-2.6.39.2/arch/powerpc/include/asm/swiotlb.h
3484 --- linux-2.6.39.2/arch/powerpc/include/asm/swiotlb.h 2011-05-19 00:06:34.000000000 -0400
3485 +++ linux-2.6.39.2/arch/powerpc/include/asm/swiotlb.h 2011-05-22 19:36:30.000000000 -0400
3486 @@ -13,7 +13,7 @@
3487
3488 #include <linux/swiotlb.h>
3489
3490 -extern struct dma_map_ops swiotlb_dma_ops;
3491 +extern const struct dma_map_ops swiotlb_dma_ops;
3492
3493 static inline void dma_mark_clean(void *addr, size_t size) {}
3494
3495 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/system.h linux-2.6.39.2/arch/powerpc/include/asm/system.h
3496 --- linux-2.6.39.2/arch/powerpc/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
3497 +++ linux-2.6.39.2/arch/powerpc/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
3498 @@ -533,7 +533,7 @@ __cmpxchg_local(volatile void *ptr, unsi
3499 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3500 #endif
3501
3502 -extern unsigned long arch_align_stack(unsigned long sp);
3503 +#define arch_align_stack(x) ((x) & ~0xfUL)
3504
3505 /* Used in very early kernel initialization. */
3506 extern unsigned long reloc_offset(void);
3507 diff -urNp linux-2.6.39.2/arch/powerpc/include/asm/uaccess.h linux-2.6.39.2/arch/powerpc/include/asm/uaccess.h
3508 --- linux-2.6.39.2/arch/powerpc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
3509 +++ linux-2.6.39.2/arch/powerpc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
3510 @@ -13,6 +13,8 @@
3511 #define VERIFY_READ 0
3512 #define VERIFY_WRITE 1
3513
3514 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3515 +
3516 /*
3517 * The fs value determines whether argument validity checking should be
3518 * performed or not. If get_fs() == USER_DS, checking is performed, with
3519 @@ -327,52 +329,6 @@ do { \
3520 extern unsigned long __copy_tofrom_user(void __user *to,
3521 const void __user *from, unsigned long size);
3522
3523 -#ifndef __powerpc64__
3524 -
3525 -static inline unsigned long copy_from_user(void *to,
3526 - const void __user *from, unsigned long n)
3527 -{
3528 - unsigned long over;
3529 -
3530 - if (access_ok(VERIFY_READ, from, n))
3531 - return __copy_tofrom_user((__force void __user *)to, from, n);
3532 - if ((unsigned long)from < TASK_SIZE) {
3533 - over = (unsigned long)from + n - TASK_SIZE;
3534 - return __copy_tofrom_user((__force void __user *)to, from,
3535 - n - over) + over;
3536 - }
3537 - return n;
3538 -}
3539 -
3540 -static inline unsigned long copy_to_user(void __user *to,
3541 - const void *from, unsigned long n)
3542 -{
3543 - unsigned long over;
3544 -
3545 - if (access_ok(VERIFY_WRITE, to, n))
3546 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3547 - if ((unsigned long)to < TASK_SIZE) {
3548 - over = (unsigned long)to + n - TASK_SIZE;
3549 - return __copy_tofrom_user(to, (__force void __user *)from,
3550 - n - over) + over;
3551 - }
3552 - return n;
3553 -}
3554 -
3555 -#else /* __powerpc64__ */
3556 -
3557 -#define __copy_in_user(to, from, size) \
3558 - __copy_tofrom_user((to), (from), (size))
3559 -
3560 -extern unsigned long copy_from_user(void *to, const void __user *from,
3561 - unsigned long n);
3562 -extern unsigned long copy_to_user(void __user *to, const void *from,
3563 - unsigned long n);
3564 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3565 - unsigned long n);
3566 -
3567 -#endif /* __powerpc64__ */
3568 -
3569 static inline unsigned long __copy_from_user_inatomic(void *to,
3570 const void __user *from, unsigned long n)
3571 {
3572 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_
3573 if (ret == 0)
3574 return 0;
3575 }
3576 +
3577 + if (!__builtin_constant_p(n))
3578 + check_object_size(to, n, false);
3579 +
3580 return __copy_tofrom_user((__force void __user *)to, from, n);
3581 }
3582
3583 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_us
3584 if (ret == 0)
3585 return 0;
3586 }
3587 +
3588 + if (!__builtin_constant_p(n))
3589 + check_object_size(from, n, true);
3590 +
3591 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3592 }
3593
3594 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_us
3595 return __copy_to_user_inatomic(to, from, size);
3596 }
3597
3598 +#ifndef __powerpc64__
3599 +
3600 +static inline unsigned long __must_check copy_from_user(void *to,
3601 + const void __user *from, unsigned long n)
3602 +{
3603 + unsigned long over;
3604 +
3605 + if ((long)n < 0)
3606 + return n;
3607 +
3608 + if (access_ok(VERIFY_READ, from, n)) {
3609 + if (!__builtin_constant_p(n))
3610 + check_object_size(to, n, false);
3611 + return __copy_tofrom_user((__force void __user *)to, from, n);
3612 + }
3613 + if ((unsigned long)from < TASK_SIZE) {
3614 + over = (unsigned long)from + n - TASK_SIZE;
3615 + if (!__builtin_constant_p(n - over))
3616 + check_object_size(to, n - over, false);
3617 + return __copy_tofrom_user((__force void __user *)to, from,
3618 + n - over) + over;
3619 + }
3620 + return n;
3621 +}
3622 +
3623 +static inline unsigned long __must_check copy_to_user(void __user *to,
3624 + const void *from, unsigned long n)
3625 +{
3626 + unsigned long over;
3627 +
3628 + if ((long)n < 0)
3629 + return n;
3630 +
3631 + if (access_ok(VERIFY_WRITE, to, n)) {
3632 + if (!__builtin_constant_p(n))
3633 + check_object_size(from, n, true);
3634 + return __copy_tofrom_user(to, (__force void __user *)from, n);
3635 + }
3636 + if ((unsigned long)to < TASK_SIZE) {
3637 + over = (unsigned long)to + n - TASK_SIZE;
3638 + if (!__builtin_constant_p(n))
3639 + check_object_size(from, n - over, true);
3640 + return __copy_tofrom_user(to, (__force void __user *)from,
3641 + n - over) + over;
3642 + }
3643 + return n;
3644 +}
3645 +
3646 +#else /* __powerpc64__ */
3647 +
3648 +#define __copy_in_user(to, from, size) \
3649 + __copy_tofrom_user((to), (from), (size))
3650 +
3651 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
3652 +{
3653 + if ((long)n < 0 || n > INT_MAX)
3654 + return n;
3655 +
3656 + if (!__builtin_constant_p(n))
3657 + check_object_size(to, n, false);
3658 +
3659 + if (likely(access_ok(VERIFY_READ, from, n)))
3660 + n = __copy_from_user(to, from, n);
3661 + else
3662 + memset(to, 0, n);
3663 + return n;
3664 +}
3665 +
3666 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
3667 +{
3668 + if ((long)n < 0 || n > INT_MAX)
3669 + return n;
3670 +
3671 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
3672 + if (!__builtin_constant_p(n))
3673 + check_object_size(from, n, true);
3674 + n = __copy_to_user(to, from, n);
3675 + }
3676 + return n;
3677 +}
3678 +
3679 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
3680 + unsigned long n);
3681 +
3682 +#endif /* __powerpc64__ */
3683 +
3684 extern unsigned long __clear_user(void __user *addr, unsigned long size);
3685
3686 static inline unsigned long clear_user(void __user *addr, unsigned long size)
3687 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/dma.c linux-2.6.39.2/arch/powerpc/kernel/dma.c
3688 --- linux-2.6.39.2/arch/powerpc/kernel/dma.c 2011-05-19 00:06:34.000000000 -0400
3689 +++ linux-2.6.39.2/arch/powerpc/kernel/dma.c 2011-05-22 19:36:30.000000000 -0400
3690 @@ -136,7 +136,7 @@ static inline void dma_direct_sync_singl
3691 }
3692 #endif
3693
3694 -struct dma_map_ops dma_direct_ops = {
3695 +const struct dma_map_ops dma_direct_ops = {
3696 .alloc_coherent = dma_direct_alloc_coherent,
3697 .free_coherent = dma_direct_free_coherent,
3698 .map_sg = dma_direct_map_sg,
3699 @@ -157,7 +157,7 @@ EXPORT_SYMBOL(dma_direct_ops);
3700
3701 int dma_set_mask(struct device *dev, u64 dma_mask)
3702 {
3703 - struct dma_map_ops *dma_ops = get_dma_ops(dev);
3704 + const struct dma_map_ops *dma_ops = get_dma_ops(dev);
3705
3706 if (ppc_md.dma_set_mask)
3707 return ppc_md.dma_set_mask(dev, dma_mask);
3708 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/dma-iommu.c linux-2.6.39.2/arch/powerpc/kernel/dma-iommu.c
3709 --- linux-2.6.39.2/arch/powerpc/kernel/dma-iommu.c 2011-05-19 00:06:34.000000000 -0400
3710 +++ linux-2.6.39.2/arch/powerpc/kernel/dma-iommu.c 2011-05-22 19:36:30.000000000 -0400
3711 @@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct de
3712 }
3713
3714 /* We support DMA to/from any memory page via the iommu */
3715 -static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3716 +int dma_iommu_dma_supported(struct device *dev, u64 mask)
3717 {
3718 struct iommu_table *tbl = get_iommu_table_base(dev);
3719
3720 @@ -90,7 +90,7 @@ static int dma_iommu_dma_supported(struc
3721 return 1;
3722 }
3723
3724 -struct dma_map_ops dma_iommu_ops = {
3725 +struct dma_map_ops dma_iommu_ops = { /* cannot be const, see arch/powerpc/platforms/cell/iommu.c */
3726 .alloc_coherent = dma_iommu_alloc_coherent,
3727 .free_coherent = dma_iommu_free_coherent,
3728 .map_sg = dma_iommu_map_sg,
3729 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/dma-swiotlb.c linux-2.6.39.2/arch/powerpc/kernel/dma-swiotlb.c
3730 --- linux-2.6.39.2/arch/powerpc/kernel/dma-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
3731 +++ linux-2.6.39.2/arch/powerpc/kernel/dma-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
3732 @@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3733 * map_page, and unmap_page on highmem, use normal dma_ops
3734 * for everything else.
3735 */
3736 -struct dma_map_ops swiotlb_dma_ops = {
3737 +const struct dma_map_ops swiotlb_dma_ops = {
3738 .alloc_coherent = dma_direct_alloc_coherent,
3739 .free_coherent = dma_direct_free_coherent,
3740 .map_sg = swiotlb_map_sg_attrs,
3741 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/exceptions-64e.S linux-2.6.39.2/arch/powerpc/kernel/exceptions-64e.S
3742 --- linux-2.6.39.2/arch/powerpc/kernel/exceptions-64e.S 2011-05-19 00:06:34.000000000 -0400
3743 +++ linux-2.6.39.2/arch/powerpc/kernel/exceptions-64e.S 2011-05-22 19:36:30.000000000 -0400
3744 @@ -495,6 +495,7 @@ storage_fault_common:
3745 std r14,_DAR(r1)
3746 std r15,_DSISR(r1)
3747 addi r3,r1,STACK_FRAME_OVERHEAD
3748 + bl .save_nvgprs
3749 mr r4,r14
3750 mr r5,r15
3751 ld r14,PACA_EXGEN+EX_R14(r13)
3752 @@ -504,8 +505,7 @@ storage_fault_common:
3753 cmpdi r3,0
3754 bne- 1f
3755 b .ret_from_except_lite
3756 -1: bl .save_nvgprs
3757 - mr r5,r3
3758 +1: mr r5,r3
3759 addi r3,r1,STACK_FRAME_OVERHEAD
3760 ld r4,_DAR(r1)
3761 bl .bad_page_fault
3762 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/exceptions-64s.S linux-2.6.39.2/arch/powerpc/kernel/exceptions-64s.S
3763 --- linux-2.6.39.2/arch/powerpc/kernel/exceptions-64s.S 2011-05-19 00:06:34.000000000 -0400
3764 +++ linux-2.6.39.2/arch/powerpc/kernel/exceptions-64s.S 2011-05-22 19:36:30.000000000 -0400
3765 @@ -848,10 +848,10 @@ handle_page_fault:
3766 11: ld r4,_DAR(r1)
3767 ld r5,_DSISR(r1)
3768 addi r3,r1,STACK_FRAME_OVERHEAD
3769 + bl .save_nvgprs
3770 bl .do_page_fault
3771 cmpdi r3,0
3772 beq+ 13f
3773 - bl .save_nvgprs
3774 mr r5,r3
3775 addi r3,r1,STACK_FRAME_OVERHEAD
3776 lwz r4,_DAR(r1)
3777 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/ibmebus.c linux-2.6.39.2/arch/powerpc/kernel/ibmebus.c
3778 --- linux-2.6.39.2/arch/powerpc/kernel/ibmebus.c 2011-05-19 00:06:34.000000000 -0400
3779 +++ linux-2.6.39.2/arch/powerpc/kernel/ibmebus.c 2011-05-22 19:36:30.000000000 -0400
3780 @@ -128,7 +128,7 @@ static int ibmebus_dma_supported(struct
3781 return 1;
3782 }
3783
3784 -static struct dma_map_ops ibmebus_dma_ops = {
3785 +static const struct dma_map_ops ibmebus_dma_ops = {
3786 .alloc_coherent = ibmebus_alloc_coherent,
3787 .free_coherent = ibmebus_free_coherent,
3788 .map_sg = ibmebus_map_sg,
3789 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/kgdb.c linux-2.6.39.2/arch/powerpc/kernel/kgdb.c
3790 --- linux-2.6.39.2/arch/powerpc/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
3791 +++ linux-2.6.39.2/arch/powerpc/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
3792 @@ -422,7 +422,7 @@ int kgdb_arch_handle_exception(int vecto
3793 /*
3794 * Global data
3795 */
3796 -struct kgdb_arch arch_kgdb_ops = {
3797 +const struct kgdb_arch arch_kgdb_ops = {
3798 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3799 };
3800
3801 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/module_32.c linux-2.6.39.2/arch/powerpc/kernel/module_32.c
3802 --- linux-2.6.39.2/arch/powerpc/kernel/module_32.c 2011-05-19 00:06:34.000000000 -0400
3803 +++ linux-2.6.39.2/arch/powerpc/kernel/module_32.c 2011-05-22 19:36:30.000000000 -0400
3804 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3805 me->arch.core_plt_section = i;
3806 }
3807 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3808 - printk("Module doesn't contain .plt or .init.plt sections.\n");
3809 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3810 return -ENOEXEC;
3811 }
3812
3813 @@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *locati
3814
3815 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3816 /* Init, or core PLT? */
3817 - if (location >= mod->module_core
3818 - && location < mod->module_core + mod->core_size)
3819 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3820 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3821 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3822 - else
3823 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3824 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3825 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3826 + else {
3827 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3828 + return ~0UL;
3829 + }
3830
3831 /* Find this entry, or if that fails, the next avail. entry */
3832 while (entry->jump[0]) {
3833 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/module.c linux-2.6.39.2/arch/powerpc/kernel/module.c
3834 --- linux-2.6.39.2/arch/powerpc/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
3835 +++ linux-2.6.39.2/arch/powerpc/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
3836 @@ -31,11 +31,24 @@
3837
3838 LIST_HEAD(module_bug_list);
3839
3840 +#ifdef CONFIG_PAX_KERNEXEC
3841 void *module_alloc(unsigned long size)
3842 {
3843 if (size == 0)
3844 return NULL;
3845
3846 + return vmalloc(size);
3847 +}
3848 +
3849 +void *module_alloc_exec(unsigned long size)
3850 +#else
3851 +void *module_alloc(unsigned long size)
3852 +#endif
3853 +
3854 +{
3855 + if (size == 0)
3856 + return NULL;
3857 +
3858 return vmalloc_exec(size);
3859 }
3860
3861 @@ -45,6 +58,13 @@ void module_free(struct module *mod, voi
3862 vfree(module_region);
3863 }
3864
3865 +#ifdef CONFIG_PAX_KERNEXEC
3866 +void module_free_exec(struct module *mod, void *module_region)
3867 +{
3868 + module_free(mod, module_region);
3869 +}
3870 +#endif
3871 +
3872 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3873 const Elf_Shdr *sechdrs,
3874 const char *name)
3875 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/pci-common.c linux-2.6.39.2/arch/powerpc/kernel/pci-common.c
3876 --- linux-2.6.39.2/arch/powerpc/kernel/pci-common.c 2011-05-19 00:06:34.000000000 -0400
3877 +++ linux-2.6.39.2/arch/powerpc/kernel/pci-common.c 2011-05-22 19:36:30.000000000 -0400
3878 @@ -53,14 +53,14 @@ resource_size_t isa_mem_base;
3879 unsigned int ppc_pci_flags = 0;
3880
3881
3882 -static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3883 +static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3884
3885 -void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3886 +void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3887 {
3888 pci_dma_ops = dma_ops;
3889 }
3890
3891 -struct dma_map_ops *get_pci_dma_ops(void)
3892 +const struct dma_map_ops *get_pci_dma_ops(void)
3893 {
3894 return pci_dma_ops;
3895 }
3896 @@ -1639,7 +1639,7 @@ null_write_config(struct pci_bus *bus, u
3897 return PCIBIOS_DEVICE_NOT_FOUND;
3898 }
3899
3900 -static struct pci_ops null_pci_ops =
3901 +static const struct pci_ops null_pci_ops =
3902 {
3903 .read = null_read_config,
3904 .write = null_write_config,
3905 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/process.c linux-2.6.39.2/arch/powerpc/kernel/process.c
3906 --- linux-2.6.39.2/arch/powerpc/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
3907 +++ linux-2.6.39.2/arch/powerpc/kernel/process.c 2011-05-22 19:41:32.000000000 -0400
3908 @@ -655,8 +655,8 @@ void show_regs(struct pt_regs * regs)
3909 * Lookup NIP late so we have the best change of getting the
3910 * above info out without failing
3911 */
3912 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3913 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3914 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3915 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3916 #endif
3917 show_stack(current, (unsigned long *) regs->gpr[1]);
3918 if (!user_mode(regs))
3919 @@ -1146,10 +1146,10 @@ void show_stack(struct task_struct *tsk,
3920 newsp = stack[0];
3921 ip = stack[STACK_FRAME_LR_SAVE];
3922 if (!firstframe || ip != lr) {
3923 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3924 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3925 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3926 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3927 - printk(" (%pS)",
3928 + printk(" (%pA)",
3929 (void *)current->ret_stack[curr_frame].ret);
3930 curr_frame--;
3931 }
3932 @@ -1169,7 +1169,7 @@ void show_stack(struct task_struct *tsk,
3933 struct pt_regs *regs = (struct pt_regs *)
3934 (sp + STACK_FRAME_OVERHEAD);
3935 lr = regs->link;
3936 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
3937 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
3938 regs->trap, (void *)regs->nip, (void *)lr);
3939 firstframe = 1;
3940 }
3941 @@ -1244,58 +1244,3 @@ void thread_info_cache_init(void)
3942 }
3943
3944 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3945 -
3946 -unsigned long arch_align_stack(unsigned long sp)
3947 -{
3948 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3949 - sp -= get_random_int() & ~PAGE_MASK;
3950 - return sp & ~0xf;
3951 -}
3952 -
3953 -static inline unsigned long brk_rnd(void)
3954 -{
3955 - unsigned long rnd = 0;
3956 -
3957 - /* 8MB for 32bit, 1GB for 64bit */
3958 - if (is_32bit_task())
3959 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3960 - else
3961 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3962 -
3963 - return rnd << PAGE_SHIFT;
3964 -}
3965 -
3966 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3967 -{
3968 - unsigned long base = mm->brk;
3969 - unsigned long ret;
3970 -
3971 -#ifdef CONFIG_PPC_STD_MMU_64
3972 - /*
3973 - * If we are using 1TB segments and we are allowed to randomise
3974 - * the heap, we can put it above 1TB so it is backed by a 1TB
3975 - * segment. Otherwise the heap will be in the bottom 1TB
3976 - * which always uses 256MB segments and this may result in a
3977 - * performance penalty.
3978 - */
3979 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3980 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3981 -#endif
3982 -
3983 - ret = PAGE_ALIGN(base + brk_rnd());
3984 -
3985 - if (ret < mm->brk)
3986 - return mm->brk;
3987 -
3988 - return ret;
3989 -}
3990 -
3991 -unsigned long randomize_et_dyn(unsigned long base)
3992 -{
3993 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3994 -
3995 - if (ret < base)
3996 - return base;
3997 -
3998 - return ret;
3999 -}
4000 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/rtas_pci.c linux-2.6.39.2/arch/powerpc/kernel/rtas_pci.c
4001 --- linux-2.6.39.2/arch/powerpc/kernel/rtas_pci.c 2011-05-19 00:06:34.000000000 -0400
4002 +++ linux-2.6.39.2/arch/powerpc/kernel/rtas_pci.c 2011-05-22 19:36:30.000000000 -0400
4003 @@ -149,7 +149,7 @@ static int rtas_pci_write_config(struct
4004 return PCIBIOS_DEVICE_NOT_FOUND;
4005 }
4006
4007 -static struct pci_ops rtas_pci_ops = {
4008 +static const struct pci_ops rtas_pci_ops = {
4009 .read = rtas_pci_read_config,
4010 .write = rtas_pci_write_config,
4011 };
4012 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/signal_32.c linux-2.6.39.2/arch/powerpc/kernel/signal_32.c
4013 --- linux-2.6.39.2/arch/powerpc/kernel/signal_32.c 2011-05-19 00:06:34.000000000 -0400
4014 +++ linux-2.6.39.2/arch/powerpc/kernel/signal_32.c 2011-05-22 19:36:30.000000000 -0400
4015 @@ -858,7 +858,7 @@ int handle_rt_signal32(unsigned long sig
4016 /* Save user registers on the stack */
4017 frame = &rt_sf->uc.uc_mcontext;
4018 addr = frame;
4019 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4020 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4021 if (save_user_regs(regs, frame, 0, 1))
4022 goto badframe;
4023 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4024 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/signal_64.c linux-2.6.39.2/arch/powerpc/kernel/signal_64.c
4025 --- linux-2.6.39.2/arch/powerpc/kernel/signal_64.c 2011-05-19 00:06:34.000000000 -0400
4026 +++ linux-2.6.39.2/arch/powerpc/kernel/signal_64.c 2011-05-22 19:36:30.000000000 -0400
4027 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
4028 current->thread.fpscr.val = 0;
4029
4030 /* Set up to return from userspace. */
4031 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4032 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4033 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4034 } else {
4035 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4036 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/traps.c linux-2.6.39.2/arch/powerpc/kernel/traps.c
4037 --- linux-2.6.39.2/arch/powerpc/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
4038 +++ linux-2.6.39.2/arch/powerpc/kernel/traps.c 2011-06-13 21:33:04.000000000 -0400
4039 @@ -96,6 +96,8 @@ static void pmac_backlight_unblank(void)
4040 static inline void pmac_backlight_unblank(void) { }
4041 #endif
4042
4043 +extern void gr_handle_kernel_exploit(void);
4044 +
4045 int die(const char *str, struct pt_regs *regs, long err)
4046 {
4047 static struct {
4048 @@ -170,6 +172,8 @@ int die(const char *str, struct pt_regs
4049 if (panic_on_oops)
4050 panic("Fatal exception");
4051
4052 + gr_handle_kernel_exploit();
4053 +
4054 oops_exit();
4055 do_exit(err);
4056
4057 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/vdso.c linux-2.6.39.2/arch/powerpc/kernel/vdso.c
4058 --- linux-2.6.39.2/arch/powerpc/kernel/vdso.c 2011-05-19 00:06:34.000000000 -0400
4059 +++ linux-2.6.39.2/arch/powerpc/kernel/vdso.c 2011-05-22 19:36:30.000000000 -0400
4060 @@ -36,6 +36,7 @@
4061 #include <asm/firmware.h>
4062 #include <asm/vdso.h>
4063 #include <asm/vdso_datapage.h>
4064 +#include <asm/mman.h>
4065
4066 #include "setup.h"
4067
4068 @@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct l
4069 vdso_base = VDSO32_MBASE;
4070 #endif
4071
4072 - current->mm->context.vdso_base = 0;
4073 + current->mm->context.vdso_base = ~0UL;
4074
4075 /* vDSO has a problem and was disabled, just don't "enable" it for the
4076 * process
4077 @@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct l
4078 vdso_base = get_unmapped_area(NULL, vdso_base,
4079 (vdso_pages << PAGE_SHIFT) +
4080 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4081 - 0, 0);
4082 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4083 if (IS_ERR_VALUE(vdso_base)) {
4084 rc = vdso_base;
4085 goto fail_mmapsem;
4086 diff -urNp linux-2.6.39.2/arch/powerpc/kernel/vio.c linux-2.6.39.2/arch/powerpc/kernel/vio.c
4087 --- linux-2.6.39.2/arch/powerpc/kernel/vio.c 2011-05-19 00:06:34.000000000 -0400
4088 +++ linux-2.6.39.2/arch/powerpc/kernel/vio.c 2011-05-22 19:36:30.000000000 -0400
4089 @@ -605,11 +605,12 @@ static int vio_dma_iommu_dma_supported(s
4090 return dma_iommu_ops.dma_supported(dev, mask);
4091 }
4092
4093 -struct dma_map_ops vio_dma_mapping_ops = {
4094 +const struct dma_map_ops vio_dma_mapping_ops = {
4095 .alloc_coherent = vio_dma_iommu_alloc_coherent,
4096 .free_coherent = vio_dma_iommu_free_coherent,
4097 .map_sg = vio_dma_iommu_map_sg,
4098 .unmap_sg = vio_dma_iommu_unmap_sg,
4099 + .dma_supported = dma_iommu_dma_supported,
4100 .map_page = vio_dma_iommu_map_page,
4101 .unmap_page = vio_dma_iommu_unmap_page,
4102 .dma_supported = vio_dma_iommu_dma_supported,
4103 diff -urNp linux-2.6.39.2/arch/powerpc/lib/usercopy_64.c linux-2.6.39.2/arch/powerpc/lib/usercopy_64.c
4104 --- linux-2.6.39.2/arch/powerpc/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
4105 +++ linux-2.6.39.2/arch/powerpc/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
4106 @@ -9,22 +9,6 @@
4107 #include <linux/module.h>
4108 #include <asm/uaccess.h>
4109
4110 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4111 -{
4112 - if (likely(access_ok(VERIFY_READ, from, n)))
4113 - n = __copy_from_user(to, from, n);
4114 - else
4115 - memset(to, 0, n);
4116 - return n;
4117 -}
4118 -
4119 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4120 -{
4121 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4122 - n = __copy_to_user(to, from, n);
4123 - return n;
4124 -}
4125 -
4126 unsigned long copy_in_user(void __user *to, const void __user *from,
4127 unsigned long n)
4128 {
4129 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *
4130 return n;
4131 }
4132
4133 -EXPORT_SYMBOL(copy_from_user);
4134 -EXPORT_SYMBOL(copy_to_user);
4135 EXPORT_SYMBOL(copy_in_user);
4136
4137 diff -urNp linux-2.6.39.2/arch/powerpc/mm/fault.c linux-2.6.39.2/arch/powerpc/mm/fault.c
4138 --- linux-2.6.39.2/arch/powerpc/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
4139 +++ linux-2.6.39.2/arch/powerpc/mm/fault.c 2011-05-22 19:36:30.000000000 -0400
4140 @@ -31,6 +31,10 @@
4141 #include <linux/kdebug.h>
4142 #include <linux/perf_event.h>
4143 #include <linux/magic.h>
4144 +#include <linux/slab.h>
4145 +#include <linux/pagemap.h>
4146 +#include <linux/compiler.h>
4147 +#include <linux/unistd.h>
4148
4149 #include <asm/firmware.h>
4150 #include <asm/page.h>
4151 @@ -42,6 +46,7 @@
4152 #include <asm/tlbflush.h>
4153 #include <asm/siginfo.h>
4154 #include <mm/mmu_decl.h>
4155 +#include <asm/ptrace.h>
4156
4157 #ifdef CONFIG_KPROBES
4158 static inline int notify_page_fault(struct pt_regs *regs)
4159 @@ -65,6 +70,33 @@ static inline int notify_page_fault(stru
4160 }
4161 #endif
4162
4163 +#ifdef CONFIG_PAX_PAGEEXEC
4164 +/*
4165 + * PaX: decide what to do with offenders (regs->nip = fault address)
4166 + *
4167 + * returns 1 when task should be killed
4168 + */
4169 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4170 +{
4171 + return 1;
4172 +}
4173 +
4174 +void pax_report_insns(void *pc, void *sp)
4175 +{
4176 + unsigned long i;
4177 +
4178 + printk(KERN_ERR "PAX: bytes at PC: ");
4179 + for (i = 0; i < 5; i++) {
4180 + unsigned int c;
4181 + if (get_user(c, (unsigned int __user *)pc+i))
4182 + printk(KERN_CONT "???????? ");
4183 + else
4184 + printk(KERN_CONT "%08x ", c);
4185 + }
4186 + printk("\n");
4187 +}
4188 +#endif
4189 +
4190 /*
4191 * Check whether the instruction at regs->nip is a store using
4192 * an update addressing form which will update r1.
4193 @@ -135,7 +167,7 @@ int __kprobes do_page_fault(struct pt_re
4194 * indicate errors in DSISR but can validly be set in SRR1.
4195 */
4196 if (trap == 0x400)
4197 - error_code &= 0x48200000;
4198 + error_code &= 0x58200000;
4199 else
4200 is_write = error_code & DSISR_ISSTORE;
4201 #else
4202 @@ -258,7 +290,7 @@ good_area:
4203 * "undefined". Of those that can be set, this is the only
4204 * one which seems bad.
4205 */
4206 - if (error_code & 0x10000000)
4207 + if (error_code & DSISR_GUARDED)
4208 /* Guarded storage error. */
4209 goto bad_area;
4210 #endif /* CONFIG_8xx */
4211 @@ -273,7 +305,7 @@ good_area:
4212 * processors use the same I/D cache coherency mechanism
4213 * as embedded.
4214 */
4215 - if (error_code & DSISR_PROTFAULT)
4216 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4217 goto bad_area;
4218 #endif /* CONFIG_PPC_STD_MMU */
4219
4220 @@ -342,6 +374,23 @@ bad_area:
4221 bad_area_nosemaphore:
4222 /* User mode accesses cause a SIGSEGV */
4223 if (user_mode(regs)) {
4224 +
4225 +#ifdef CONFIG_PAX_PAGEEXEC
4226 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4227 +#ifdef CONFIG_PPC_STD_MMU
4228 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4229 +#else
4230 + if (is_exec && regs->nip == address) {
4231 +#endif
4232 + switch (pax_handle_fetch_fault(regs)) {
4233 + }
4234 +
4235 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4236 + do_group_exit(SIGKILL);
4237 + }
4238 + }
4239 +#endif
4240 +
4241 _exception(SIGSEGV, regs, code, address);
4242 return 0;
4243 }
4244 diff -urNp linux-2.6.39.2/arch/powerpc/mm/mmap_64.c linux-2.6.39.2/arch/powerpc/mm/mmap_64.c
4245 --- linux-2.6.39.2/arch/powerpc/mm/mmap_64.c 2011-05-19 00:06:34.000000000 -0400
4246 +++ linux-2.6.39.2/arch/powerpc/mm/mmap_64.c 2011-05-22 19:36:30.000000000 -0400
4247 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_str
4248 */
4249 if (mmap_is_legacy()) {
4250 mm->mmap_base = TASK_UNMAPPED_BASE;
4251 +
4252 +#ifdef CONFIG_PAX_RANDMMAP
4253 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4254 + mm->mmap_base += mm->delta_mmap;
4255 +#endif
4256 +
4257 mm->get_unmapped_area = arch_get_unmapped_area;
4258 mm->unmap_area = arch_unmap_area;
4259 } else {
4260 mm->mmap_base = mmap_base();
4261 +
4262 +#ifdef CONFIG_PAX_RANDMMAP
4263 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4264 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4265 +#endif
4266 +
4267 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4268 mm->unmap_area = arch_unmap_area_topdown;
4269 }
4270 diff -urNp linux-2.6.39.2/arch/powerpc/mm/slice.c linux-2.6.39.2/arch/powerpc/mm/slice.c
4271 --- linux-2.6.39.2/arch/powerpc/mm/slice.c 2011-05-19 00:06:34.000000000 -0400
4272 +++ linux-2.6.39.2/arch/powerpc/mm/slice.c 2011-05-22 19:36:30.000000000 -0400
4273 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_
4274 if ((mm->task_size - len) < addr)
4275 return 0;
4276 vma = find_vma(mm, addr);
4277 - return (!vma || (addr + len) <= vma->vm_start);
4278 + return check_heap_stack_gap(vma, addr, len);
4279 }
4280
4281 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4282 @@ -256,7 +256,7 @@ full_search:
4283 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4284 continue;
4285 }
4286 - if (!vma || addr + len <= vma->vm_start) {
4287 + if (check_heap_stack_gap(vma, addr, len)) {
4288 /*
4289 * Remember the place where we stopped the search:
4290 */
4291 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_top
4292 }
4293 }
4294
4295 - addr = mm->mmap_base;
4296 - while (addr > len) {
4297 + if (mm->mmap_base < len)
4298 + addr = -ENOMEM;
4299 + else
4300 + addr = mm->mmap_base - len;
4301 +
4302 + while (!IS_ERR_VALUE(addr)) {
4303 /* Go down by chunk size */
4304 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4305 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4306
4307 /* Check for hit with different page size */
4308 mask = slice_range_to_mask(addr, len);
4309 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_top
4310 * return with success:
4311 */
4312 vma = find_vma(mm, addr);
4313 - if (!vma || (addr + len) <= vma->vm_start) {
4314 + if (check_heap_stack_gap(vma, addr, len)) {
4315 /* remember the address as a hint for next time */
4316 if (use_cache)
4317 mm->free_area_cache = addr;
4318 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_top
4319 mm->cached_hole_size = vma->vm_start - addr;
4320
4321 /* try just below the current vma->vm_start */
4322 - addr = vma->vm_start;
4323 + addr = skip_heap_stack_gap(vma, len);
4324 }
4325
4326 /*
4327 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(un
4328 if (fixed && addr > (mm->task_size - len))
4329 return -EINVAL;
4330
4331 +#ifdef CONFIG_PAX_RANDMMAP
4332 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4333 + addr = 0;
4334 +#endif
4335 +
4336 /* If hint, make sure it matches our alignment restrictions */
4337 if (!fixed && addr) {
4338 addr = _ALIGN_UP(addr, 1ul << pshift);
4339 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/52xx/efika.c linux-2.6.39.2/arch/powerpc/platforms/52xx/efika.c
4340 --- linux-2.6.39.2/arch/powerpc/platforms/52xx/efika.c 2011-05-19 00:06:34.000000000 -0400
4341 +++ linux-2.6.39.2/arch/powerpc/platforms/52xx/efika.c 2011-05-22 19:36:30.000000000 -0400
4342 @@ -60,7 +60,7 @@ static int rtas_write_config(struct pci_
4343 return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
4344 }
4345
4346 -static struct pci_ops rtas_pci_ops = {
4347 +static const struct pci_ops rtas_pci_ops = {
4348 .read = rtas_read_config,
4349 .write = rtas_write_config,
4350 };
4351 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_pci.c linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_pci.c
4352 --- linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-19 00:06:34.000000000 -0400
4353 +++ linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_pci.c 2011-05-22 19:36:30.000000000 -0400
4354 @@ -234,7 +234,7 @@ static int celleb_fake_pci_write_config(
4355 return PCIBIOS_SUCCESSFUL;
4356 }
4357
4358 -static struct pci_ops celleb_fake_pci_ops = {
4359 +static const struct pci_ops celleb_fake_pci_ops = {
4360 .read = celleb_fake_pci_read_config,
4361 .write = celleb_fake_pci_write_config,
4362 };
4363 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_epci.c linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_epci.c
4364 --- linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-19 00:06:34.000000000 -0400
4365 +++ linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_epci.c 2011-05-22 19:36:30.000000000 -0400
4366 @@ -245,7 +245,7 @@ static int celleb_epci_write_config(stru
4367 return celleb_epci_check_abort(hose, addr);
4368 }
4369
4370 -struct pci_ops celleb_epci_ops = {
4371 +const struct pci_ops celleb_epci_ops = {
4372 .read = celleb_epci_read_config,
4373 .write = celleb_epci_write_config,
4374 };
4375 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_pciex.c linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_pciex.c
4376 --- linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-19 00:06:34.000000000 -0400
4377 +++ linux-2.6.39.2/arch/powerpc/platforms/cell/celleb_scc_pciex.c 2011-05-22 19:36:30.000000000 -0400
4378 @@ -399,7 +399,7 @@ static int scc_pciex_write_config(struct
4379 return PCIBIOS_SUCCESSFUL;
4380 }
4381
4382 -static struct pci_ops scc_pciex_pci_ops = {
4383 +static const struct pci_ops scc_pciex_pci_ops = {
4384 scc_pciex_read_config,
4385 scc_pciex_write_config,
4386 };
4387 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/cell/iommu.c linux-2.6.39.2/arch/powerpc/platforms/cell/iommu.c
4388 --- linux-2.6.39.2/arch/powerpc/platforms/cell/iommu.c 2011-05-19 00:06:34.000000000 -0400
4389 +++ linux-2.6.39.2/arch/powerpc/platforms/cell/iommu.c 2011-05-22 19:36:30.000000000 -0400
4390 @@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struc
4391
4392 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
4393
4394 -struct dma_map_ops dma_iommu_fixed_ops = {
4395 +const struct dma_map_ops dma_iommu_fixed_ops = {
4396 .alloc_coherent = dma_fixed_alloc_coherent,
4397 .free_coherent = dma_fixed_free_coherent,
4398 .map_sg = dma_fixed_map_sg,
4399 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/chrp/pci.c linux-2.6.39.2/arch/powerpc/platforms/chrp/pci.c
4400 --- linux-2.6.39.2/arch/powerpc/platforms/chrp/pci.c 2011-05-19 00:06:34.000000000 -0400
4401 +++ linux-2.6.39.2/arch/powerpc/platforms/chrp/pci.c 2011-05-22 19:36:30.000000000 -0400
4402 @@ -84,7 +84,7 @@ int gg2_write_config(struct pci_bus *bus
4403 return PCIBIOS_SUCCESSFUL;
4404 }
4405
4406 -static struct pci_ops gg2_pci_ops =
4407 +static const struct pci_ops gg2_pci_ops =
4408 {
4409 .read = gg2_read_config,
4410 .write = gg2_write_config,
4411 @@ -122,7 +122,7 @@ int rtas_write_config(struct pci_bus *bu
4412 return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
4413 }
4414
4415 -static struct pci_ops rtas_pci_ops =
4416 +static const struct pci_ops rtas_pci_ops =
4417 {
4418 .read = rtas_read_config,
4419 .write = rtas_write_config,
4420 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/iseries/pci.c linux-2.6.39.2/arch/powerpc/platforms/iseries/pci.c
4421 --- linux-2.6.39.2/arch/powerpc/platforms/iseries/pci.c 2011-05-19 00:06:34.000000000 -0400
4422 +++ linux-2.6.39.2/arch/powerpc/platforms/iseries/pci.c 2011-05-22 19:36:30.000000000 -0400
4423 @@ -533,7 +533,7 @@ static int iSeries_pci_write_config(stru
4424 return 0;
4425 }
4426
4427 -static struct pci_ops iSeries_pci_ops = {
4428 +static const struct pci_ops iSeries_pci_ops = {
4429 .read = iSeries_pci_read_config,
4430 .write = iSeries_pci_write_config
4431 };
4432 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/maple/pci.c linux-2.6.39.2/arch/powerpc/platforms/maple/pci.c
4433 --- linux-2.6.39.2/arch/powerpc/platforms/maple/pci.c 2011-05-19 00:06:34.000000000 -0400
4434 +++ linux-2.6.39.2/arch/powerpc/platforms/maple/pci.c 2011-05-22 19:36:30.000000000 -0400
4435 @@ -180,7 +180,7 @@ static int u3_agp_write_config(struct pc
4436 return PCIBIOS_SUCCESSFUL;
4437 }
4438
4439 -static struct pci_ops u3_agp_pci_ops =
4440 +static const struct pci_ops u3_agp_pci_ops =
4441 {
4442 .read = u3_agp_read_config,
4443 .write = u3_agp_write_config,
4444 @@ -276,7 +276,7 @@ static int u3_ht_write_config(struct pci
4445 return PCIBIOS_SUCCESSFUL;
4446 }
4447
4448 -static struct pci_ops u3_ht_pci_ops =
4449 +static const struct pci_ops u3_ht_pci_ops =
4450 {
4451 .read = u3_ht_read_config,
4452 .write = u3_ht_write_config,
4453 @@ -381,7 +381,7 @@ static int u4_pcie_write_config(struct p
4454 return PCIBIOS_SUCCESSFUL;
4455 }
4456
4457 -static struct pci_ops u4_pcie_pci_ops =
4458 +static const struct pci_ops u4_pcie_pci_ops =
4459 {
4460 .read = u4_pcie_read_config,
4461 .write = u4_pcie_write_config,
4462 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/pasemi/pci.c linux-2.6.39.2/arch/powerpc/platforms/pasemi/pci.c
4463 --- linux-2.6.39.2/arch/powerpc/platforms/pasemi/pci.c 2011-05-19 00:06:34.000000000 -0400
4464 +++ linux-2.6.39.2/arch/powerpc/platforms/pasemi/pci.c 2011-05-22 19:36:30.000000000 -0400
4465 @@ -176,7 +176,7 @@ static int pa_pxp_write_config(struct pc
4466 return PCIBIOS_SUCCESSFUL;
4467 }
4468
4469 -static struct pci_ops pa_pxp_ops = {
4470 +static const struct pci_ops pa_pxp_ops = {
4471 .read = pa_pxp_read_config,
4472 .write = pa_pxp_write_config,
4473 };
4474 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/powermac/pci.c linux-2.6.39.2/arch/powerpc/platforms/powermac/pci.c
4475 --- linux-2.6.39.2/arch/powerpc/platforms/powermac/pci.c 2011-05-19 00:06:34.000000000 -0400
4476 +++ linux-2.6.39.2/arch/powerpc/platforms/powermac/pci.c 2011-05-22 19:36:30.000000000 -0400
4477 @@ -218,7 +218,7 @@ static int macrisc_write_config(struct p
4478 return PCIBIOS_SUCCESSFUL;
4479 }
4480
4481 -static struct pci_ops macrisc_pci_ops =
4482 +static const struct pci_ops macrisc_pci_ops =
4483 {
4484 .read = macrisc_read_config,
4485 .write = macrisc_write_config,
4486 @@ -273,7 +273,7 @@ chaos_write_config(struct pci_bus *bus,
4487 return macrisc_write_config(bus, devfn, offset, len, val);
4488 }
4489
4490 -static struct pci_ops chaos_pci_ops =
4491 +static const struct pci_ops chaos_pci_ops =
4492 {
4493 .read = chaos_read_config,
4494 .write = chaos_write_config,
4495 diff -urNp linux-2.6.39.2/arch/powerpc/platforms/ps3/system-bus.c linux-2.6.39.2/arch/powerpc/platforms/ps3/system-bus.c
4496 --- linux-2.6.39.2/arch/powerpc/platforms/ps3/system-bus.c 2011-05-19 00:06:34.000000000 -0400
4497 +++ linux-2.6.39.2/arch/powerpc/platforms/ps3/system-bus.c 2011-05-22 19:36:30.000000000 -0400
4498 @@ -695,7 +695,7 @@ static int ps3_dma_supported(struct devi
4499 return mask >= DMA_BIT_MASK(32);
4500 }
4501
4502 -static struct dma_map_ops ps3_sb_dma_ops = {
4503 +static const struct dma_map_ops ps3_sb_dma_ops = {
4504 .alloc_coherent = ps3_alloc_coherent,
4505 .free_coherent = ps3_free_coherent,
4506 .map_sg = ps3_sb_map_sg,
4507 @@ -705,7 +705,7 @@ static struct dma_map_ops ps3_sb_dma_ops
4508 .unmap_page = ps3_unmap_page,
4509 };
4510
4511 -static struct dma_map_ops ps3_ioc0_dma_ops = {
4512 +static const struct dma_map_ops ps3_ioc0_dma_ops = {
4513 .alloc_coherent = ps3_alloc_coherent,
4514 .free_coherent = ps3_free_coherent,
4515 .map_sg = ps3_ioc0_map_sg,
4516 diff -urNp linux-2.6.39.2/arch/powerpc/sysdev/fsl_pci.c linux-2.6.39.2/arch/powerpc/sysdev/fsl_pci.c
4517 --- linux-2.6.39.2/arch/powerpc/sysdev/fsl_pci.c 2011-05-19 00:06:34.000000000 -0400
4518 +++ linux-2.6.39.2/arch/powerpc/sysdev/fsl_pci.c 2011-05-22 19:36:30.000000000 -0400
4519 @@ -573,7 +573,7 @@ static int mpc83xx_pcie_write_config(str
4520 return PCIBIOS_SUCCESSFUL;
4521 }
4522
4523 -static struct pci_ops mpc83xx_pcie_ops = {
4524 +static const struct pci_ops mpc83xx_pcie_ops = {
4525 .read = mpc83xx_pcie_read_config,
4526 .write = mpc83xx_pcie_write_config,
4527 };
4528 diff -urNp linux-2.6.39.2/arch/powerpc/sysdev/indirect_pci.c linux-2.6.39.2/arch/powerpc/sysdev/indirect_pci.c
4529 --- linux-2.6.39.2/arch/powerpc/sysdev/indirect_pci.c 2011-05-19 00:06:34.000000000 -0400
4530 +++ linux-2.6.39.2/arch/powerpc/sysdev/indirect_pci.c 2011-05-22 19:36:30.000000000 -0400
4531 @@ -148,7 +148,7 @@ indirect_write_config(struct pci_bus *bu
4532 return PCIBIOS_SUCCESSFUL;
4533 }
4534
4535 -static struct pci_ops indirect_pci_ops =
4536 +static const struct pci_ops indirect_pci_ops =
4537 {
4538 .read = indirect_read_config,
4539 .write = indirect_write_config,
4540 diff -urNp linux-2.6.39.2/arch/powerpc/sysdev/ppc4xx_pci.c linux-2.6.39.2/arch/powerpc/sysdev/ppc4xx_pci.c
4541 --- linux-2.6.39.2/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-19 00:06:34.000000000 -0400
4542 +++ linux-2.6.39.2/arch/powerpc/sysdev/ppc4xx_pci.c 2011-05-22 19:36:30.000000000 -0400
4543 @@ -1514,7 +1514,7 @@ static int ppc4xx_pciex_write_config(str
4544 return PCIBIOS_SUCCESSFUL;
4545 }
4546
4547 -static struct pci_ops ppc4xx_pciex_pci_ops =
4548 +static const struct pci_ops ppc4xx_pciex_pci_ops =
4549 {
4550 .read = ppc4xx_pciex_read_config,
4551 .write = ppc4xx_pciex_write_config,
4552 diff -urNp linux-2.6.39.2/arch/powerpc/sysdev/tsi108_pci.c linux-2.6.39.2/arch/powerpc/sysdev/tsi108_pci.c
4553 --- linux-2.6.39.2/arch/powerpc/sysdev/tsi108_pci.c 2011-05-19 00:06:34.000000000 -0400
4554 +++ linux-2.6.39.2/arch/powerpc/sysdev/tsi108_pci.c 2011-05-22 19:36:30.000000000 -0400
4555 @@ -190,7 +190,7 @@ void tsi108_clear_pci_cfg_error(void)
4556 tsi108_clear_pci_error(tsi108_pci_cfg_phys);
4557 }
4558
4559 -static struct pci_ops tsi108_direct_pci_ops = {
4560 +static const struct pci_ops tsi108_direct_pci_ops = {
4561 .read = tsi108_direct_read_config,
4562 .write = tsi108_direct_write_config,
4563 };
4564 diff -urNp linux-2.6.39.2/arch/s390/include/asm/elf.h linux-2.6.39.2/arch/s390/include/asm/elf.h
4565 --- linux-2.6.39.2/arch/s390/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
4566 +++ linux-2.6.39.2/arch/s390/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
4567 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4568 the loader. We need to make sure that it is out of the way of the program
4569 that it will "exec", and that there is sufficient room for the brk. */
4570
4571 -extern unsigned long randomize_et_dyn(unsigned long base);
4572 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4573 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4574 +
4575 +#ifdef CONFIG_PAX_ASLR
4576 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4577 +
4578 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4579 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
4580 +#endif
4581
4582 /* This yields a mask that user programs can use to figure out what
4583 instruction set this CPU supports. */
4584 @@ -222,7 +228,4 @@ struct linux_binprm;
4585 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4586 int arch_setup_additional_pages(struct linux_binprm *, int);
4587
4588 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4589 -#define arch_randomize_brk arch_randomize_brk
4590 -
4591 #endif
4592 diff -urNp linux-2.6.39.2/arch/s390/include/asm/system.h linux-2.6.39.2/arch/s390/include/asm/system.h
4593 --- linux-2.6.39.2/arch/s390/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4594 +++ linux-2.6.39.2/arch/s390/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4595 @@ -255,7 +255,7 @@ extern void (*_machine_restart)(char *co
4596 extern void (*_machine_halt)(void);
4597 extern void (*_machine_power_off)(void);
4598
4599 -extern unsigned long arch_align_stack(unsigned long sp);
4600 +#define arch_align_stack(x) ((x) & ~0xfUL)
4601
4602 static inline int tprot(unsigned long addr)
4603 {
4604 diff -urNp linux-2.6.39.2/arch/s390/include/asm/uaccess.h linux-2.6.39.2/arch/s390/include/asm/uaccess.h
4605 --- linux-2.6.39.2/arch/s390/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
4606 +++ linux-2.6.39.2/arch/s390/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
4607 @@ -234,6 +234,10 @@ static inline unsigned long __must_check
4608 copy_to_user(void __user *to, const void *from, unsigned long n)
4609 {
4610 might_fault();
4611 +
4612 + if ((long)n < 0)
4613 + return n;
4614 +
4615 if (access_ok(VERIFY_WRITE, to, n))
4616 n = __copy_to_user(to, from, n);
4617 return n;
4618 @@ -259,6 +263,9 @@ copy_to_user(void __user *to, const void
4619 static inline unsigned long __must_check
4620 __copy_from_user(void *to, const void __user *from, unsigned long n)
4621 {
4622 + if ((long)n < 0)
4623 + return n;
4624 +
4625 if (__builtin_constant_p(n) && (n <= 256))
4626 return uaccess.copy_from_user_small(n, from, to);
4627 else
4628 @@ -293,6 +300,10 @@ copy_from_user(void *to, const void __us
4629 unsigned int sz = __compiletime_object_size(to);
4630
4631 might_fault();
4632 +
4633 + if ((long)n < 0)
4634 + return n;
4635 +
4636 if (unlikely(sz != -1 && sz < n)) {
4637 copy_from_user_overflow();
4638 return n;
4639 diff -urNp linux-2.6.39.2/arch/s390/Kconfig linux-2.6.39.2/arch/s390/Kconfig
4640 --- linux-2.6.39.2/arch/s390/Kconfig 2011-05-19 00:06:34.000000000 -0400
4641 +++ linux-2.6.39.2/arch/s390/Kconfig 2011-05-22 19:36:30.000000000 -0400
4642 @@ -234,11 +234,9 @@ config S390_EXEC_PROTECT
4643 prompt "Data execute protection"
4644 help
4645 This option allows to enable a buffer overflow protection for user
4646 - space programs and it also selects the addressing mode option above.
4647 - The kernel parameter noexec=on will enable this feature and also
4648 - switch the addressing modes, default is disabled. Enabling this (via
4649 - kernel parameter) on machines earlier than IBM System z9 this will
4650 - reduce system performance.
4651 + space programs.
4652 + Enabling this (via kernel parameter) on machines earlier than IBM
4653 + System z9 this will reduce system performance.
4654
4655 comment "Code generation options"
4656
4657 diff -urNp linux-2.6.39.2/arch/s390/kernel/module.c linux-2.6.39.2/arch/s390/kernel/module.c
4658 --- linux-2.6.39.2/arch/s390/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
4659 +++ linux-2.6.39.2/arch/s390/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
4660 @@ -168,11 +168,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
4661
4662 /* Increase core size by size of got & plt and set start
4663 offsets for got and plt. */
4664 - me->core_size = ALIGN(me->core_size, 4);
4665 - me->arch.got_offset = me->core_size;
4666 - me->core_size += me->arch.got_size;
4667 - me->arch.plt_offset = me->core_size;
4668 - me->core_size += me->arch.plt_size;
4669 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4670 + me->arch.got_offset = me->core_size_rw;
4671 + me->core_size_rw += me->arch.got_size;
4672 + me->arch.plt_offset = me->core_size_rx;
4673 + me->core_size_rx += me->arch.plt_size;
4674 return 0;
4675 }
4676
4677 @@ -258,7 +258,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4678 if (info->got_initialized == 0) {
4679 Elf_Addr *gotent;
4680
4681 - gotent = me->module_core + me->arch.got_offset +
4682 + gotent = me->module_core_rw + me->arch.got_offset +
4683 info->got_offset;
4684 *gotent = val;
4685 info->got_initialized = 1;
4686 @@ -282,7 +282,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4687 else if (r_type == R_390_GOTENT ||
4688 r_type == R_390_GOTPLTENT)
4689 *(unsigned int *) loc =
4690 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4691 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4692 else if (r_type == R_390_GOT64 ||
4693 r_type == R_390_GOTPLT64)
4694 *(unsigned long *) loc = val;
4695 @@ -296,7 +296,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4696 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4697 if (info->plt_initialized == 0) {
4698 unsigned int *ip;
4699 - ip = me->module_core + me->arch.plt_offset +
4700 + ip = me->module_core_rx + me->arch.plt_offset +
4701 info->plt_offset;
4702 #ifndef CONFIG_64BIT
4703 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4704 @@ -321,7 +321,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4705 val - loc + 0xffffUL < 0x1ffffeUL) ||
4706 (r_type == R_390_PLT32DBL &&
4707 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4708 - val = (Elf_Addr) me->module_core +
4709 + val = (Elf_Addr) me->module_core_rx +
4710 me->arch.plt_offset +
4711 info->plt_offset;
4712 val += rela->r_addend - loc;
4713 @@ -343,7 +343,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4714 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4715 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4716 val = val + rela->r_addend -
4717 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4718 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4719 if (r_type == R_390_GOTOFF16)
4720 *(unsigned short *) loc = val;
4721 else if (r_type == R_390_GOTOFF32)
4722 @@ -353,7 +353,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4723 break;
4724 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4725 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4726 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4727 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4728 rela->r_addend - loc;
4729 if (r_type == R_390_GOTPC)
4730 *(unsigned int *) loc = val;
4731 diff -urNp linux-2.6.39.2/arch/s390/kernel/process.c linux-2.6.39.2/arch/s390/kernel/process.c
4732 --- linux-2.6.39.2/arch/s390/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4733 +++ linux-2.6.39.2/arch/s390/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4734 @@ -334,39 +334,3 @@ unsigned long get_wchan(struct task_stru
4735 }
4736 return 0;
4737 }
4738 -
4739 -unsigned long arch_align_stack(unsigned long sp)
4740 -{
4741 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4742 - sp -= get_random_int() & ~PAGE_MASK;
4743 - return sp & ~0xf;
4744 -}
4745 -
4746 -static inline unsigned long brk_rnd(void)
4747 -{
4748 - /* 8MB for 32bit, 1GB for 64bit */
4749 - if (is_32bit_task())
4750 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4751 - else
4752 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4753 -}
4754 -
4755 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4756 -{
4757 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4758 -
4759 - if (ret < mm->brk)
4760 - return mm->brk;
4761 - return ret;
4762 -}
4763 -
4764 -unsigned long randomize_et_dyn(unsigned long base)
4765 -{
4766 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4767 -
4768 - if (!(current->flags & PF_RANDOMIZE))
4769 - return base;
4770 - if (ret < base)
4771 - return base;
4772 - return ret;
4773 -}
4774 diff -urNp linux-2.6.39.2/arch/s390/kernel/setup.c linux-2.6.39.2/arch/s390/kernel/setup.c
4775 --- linux-2.6.39.2/arch/s390/kernel/setup.c 2011-05-19 00:06:34.000000000 -0400
4776 +++ linux-2.6.39.2/arch/s390/kernel/setup.c 2011-05-22 19:36:30.000000000 -0400
4777 @@ -271,7 +271,7 @@ static int __init early_parse_mem(char *
4778 }
4779 early_param("mem", early_parse_mem);
4780
4781 -unsigned int user_mode = HOME_SPACE_MODE;
4782 +unsigned int user_mode = SECONDARY_SPACE_MODE;
4783 EXPORT_SYMBOL_GPL(user_mode);
4784
4785 static int set_amode_and_uaccess(unsigned long user_amode,
4786 @@ -300,17 +300,6 @@ static int set_amode_and_uaccess(unsigne
4787 }
4788 }
4789
4790 -/*
4791 - * Switch kernel/user addressing modes?
4792 - */
4793 -static int __init early_parse_switch_amode(char *p)
4794 -{
4795 - if (user_mode != SECONDARY_SPACE_MODE)
4796 - user_mode = PRIMARY_SPACE_MODE;
4797 - return 0;
4798 -}
4799 -early_param("switch_amode", early_parse_switch_amode);
4800 -
4801 static int __init early_parse_user_mode(char *p)
4802 {
4803 if (p && strcmp(p, "primary") == 0)
4804 @@ -327,20 +316,6 @@ static int __init early_parse_user_mode(
4805 }
4806 early_param("user_mode", early_parse_user_mode);
4807
4808 -#ifdef CONFIG_S390_EXEC_PROTECT
4809 -/*
4810 - * Enable execute protection?
4811 - */
4812 -static int __init early_parse_noexec(char *p)
4813 -{
4814 - if (!strncmp(p, "off", 3))
4815 - return 0;
4816 - user_mode = SECONDARY_SPACE_MODE;
4817 - return 0;
4818 -}
4819 -early_param("noexec", early_parse_noexec);
4820 -#endif /* CONFIG_S390_EXEC_PROTECT */
4821 -
4822 static void setup_addressing_mode(void)
4823 {
4824 if (user_mode == SECONDARY_SPACE_MODE) {
4825 diff -urNp linux-2.6.39.2/arch/s390/mm/maccess.c linux-2.6.39.2/arch/s390/mm/maccess.c
4826 --- linux-2.6.39.2/arch/s390/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
4827 +++ linux-2.6.39.2/arch/s390/mm/maccess.c 2011-05-22 19:36:30.000000000 -0400
4828 @@ -45,7 +45,7 @@ static long probe_kernel_write_odd(void
4829 return rc ? rc : count;
4830 }
4831
4832 -long probe_kernel_write(void *dst, void *src, size_t size)
4833 +long probe_kernel_write(void *dst, const void *src, size_t size)
4834 {
4835 long copied = 0;
4836
4837 diff -urNp linux-2.6.39.2/arch/s390/mm/mmap.c linux-2.6.39.2/arch/s390/mm/mmap.c
4838 --- linux-2.6.39.2/arch/s390/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
4839 +++ linux-2.6.39.2/arch/s390/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
4840 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_str
4841 */
4842 if (mmap_is_legacy()) {
4843 mm->mmap_base = TASK_UNMAPPED_BASE;
4844 +
4845 +#ifdef CONFIG_PAX_RANDMMAP
4846 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4847 + mm->mmap_base += mm->delta_mmap;
4848 +#endif
4849 +
4850 mm->get_unmapped_area = arch_get_unmapped_area;
4851 mm->unmap_area = arch_unmap_area;
4852 } else {
4853 mm->mmap_base = mmap_base();
4854 +
4855 +#ifdef CONFIG_PAX_RANDMMAP
4856 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4857 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4858 +#endif
4859 +
4860 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4861 mm->unmap_area = arch_unmap_area_topdown;
4862 }
4863 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_str
4864 */
4865 if (mmap_is_legacy()) {
4866 mm->mmap_base = TASK_UNMAPPED_BASE;
4867 +
4868 +#ifdef CONFIG_PAX_RANDMMAP
4869 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4870 + mm->mmap_base += mm->delta_mmap;
4871 +#endif
4872 +
4873 mm->get_unmapped_area = s390_get_unmapped_area;
4874 mm->unmap_area = arch_unmap_area;
4875 } else {
4876 mm->mmap_base = mmap_base();
4877 +
4878 +#ifdef CONFIG_PAX_RANDMMAP
4879 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4880 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4881 +#endif
4882 +
4883 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4884 mm->unmap_area = arch_unmap_area_topdown;
4885 }
4886 diff -urNp linux-2.6.39.2/arch/score/include/asm/system.h linux-2.6.39.2/arch/score/include/asm/system.h
4887 --- linux-2.6.39.2/arch/score/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
4888 +++ linux-2.6.39.2/arch/score/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
4889 @@ -17,7 +17,7 @@ do { \
4890 #define finish_arch_switch(prev) do {} while (0)
4891
4892 typedef void (*vi_handler_t)(void);
4893 -extern unsigned long arch_align_stack(unsigned long sp);
4894 +#define arch_align_stack(x) (x)
4895
4896 #define mb() barrier()
4897 #define rmb() barrier()
4898 diff -urNp linux-2.6.39.2/arch/score/kernel/process.c linux-2.6.39.2/arch/score/kernel/process.c
4899 --- linux-2.6.39.2/arch/score/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
4900 +++ linux-2.6.39.2/arch/score/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
4901 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_stru
4902
4903 return task_pt_regs(task)->cp0_epc;
4904 }
4905 -
4906 -unsigned long arch_align_stack(unsigned long sp)
4907 -{
4908 - return sp;
4909 -}
4910 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/ops-dreamcast.c linux-2.6.39.2/arch/sh/drivers/pci/ops-dreamcast.c
4911 --- linux-2.6.39.2/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-19 00:06:34.000000000 -0400
4912 +++ linux-2.6.39.2/arch/sh/drivers/pci/ops-dreamcast.c 2011-05-22 19:36:30.000000000 -0400
4913 @@ -76,7 +76,7 @@ static int gapspci_write(struct pci_bus
4914 return PCIBIOS_SUCCESSFUL;
4915 }
4916
4917 -struct pci_ops gapspci_pci_ops = {
4918 +const struct pci_ops gapspci_pci_ops = {
4919 .read = gapspci_read,
4920 .write = gapspci_write,
4921 };
4922 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/ops-sh4.c linux-2.6.39.2/arch/sh/drivers/pci/ops-sh4.c
4923 --- linux-2.6.39.2/arch/sh/drivers/pci/ops-sh4.c 2011-05-19 00:06:34.000000000 -0400
4924 +++ linux-2.6.39.2/arch/sh/drivers/pci/ops-sh4.c 2011-05-22 19:36:30.000000000 -0400
4925 @@ -96,7 +96,7 @@ static int sh4_pci_write(struct pci_bus
4926 return PCIBIOS_SUCCESSFUL;
4927 }
4928
4929 -struct pci_ops sh4_pci_ops = {
4930 +const struct pci_ops sh4_pci_ops = {
4931 .read = sh4_pci_read,
4932 .write = sh4_pci_write,
4933 };
4934 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/ops-sh5.c linux-2.6.39.2/arch/sh/drivers/pci/ops-sh5.c
4935 --- linux-2.6.39.2/arch/sh/drivers/pci/ops-sh5.c 2011-05-19 00:06:34.000000000 -0400
4936 +++ linux-2.6.39.2/arch/sh/drivers/pci/ops-sh5.c 2011-05-22 19:36:30.000000000 -0400
4937 @@ -62,7 +62,7 @@ static int sh5pci_write(struct pci_bus *
4938 return PCIBIOS_SUCCESSFUL;
4939 }
4940
4941 -struct pci_ops sh5_pci_ops = {
4942 +const struct pci_ops sh5_pci_ops = {
4943 .read = sh5pci_read,
4944 .write = sh5pci_write,
4945 };
4946 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/ops-sh7786.c linux-2.6.39.2/arch/sh/drivers/pci/ops-sh7786.c
4947 --- linux-2.6.39.2/arch/sh/drivers/pci/ops-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4948 +++ linux-2.6.39.2/arch/sh/drivers/pci/ops-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4949 @@ -165,7 +165,7 @@ out:
4950 return ret;
4951 }
4952
4953 -struct pci_ops sh7786_pci_ops = {
4954 +const struct pci_ops sh7786_pci_ops = {
4955 .read = sh7786_pcie_read,
4956 .write = sh7786_pcie_write,
4957 };
4958 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/pcie-sh7786.c linux-2.6.39.2/arch/sh/drivers/pci/pcie-sh7786.c
4959 --- linux-2.6.39.2/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-19 00:06:34.000000000 -0400
4960 +++ linux-2.6.39.2/arch/sh/drivers/pci/pcie-sh7786.c 2011-05-22 19:36:30.000000000 -0400
4961 @@ -109,7 +109,7 @@ static struct resource sh7786_pci2_resou
4962 },
4963 };
4964
4965 -extern struct pci_ops sh7786_pci_ops;
4966 +extern const struct pci_ops sh7786_pci_ops;
4967
4968 #define DEFINE_CONTROLLER(start, idx) \
4969 { \
4970 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/pci-sh4.h linux-2.6.39.2/arch/sh/drivers/pci/pci-sh4.h
4971 --- linux-2.6.39.2/arch/sh/drivers/pci/pci-sh4.h 2011-05-19 00:06:34.000000000 -0400
4972 +++ linux-2.6.39.2/arch/sh/drivers/pci/pci-sh4.h 2011-05-22 19:36:30.000000000 -0400
4973 @@ -161,7 +161,7 @@
4974 #define SH4_PCIPDR 0x220 /* Port IO Data Register */
4975
4976 /* arch/sh/kernel/drivers/pci/ops-sh4.c */
4977 -extern struct pci_ops sh4_pci_ops;
4978 +extern const struct pci_ops sh4_pci_ops;
4979 int pci_fixup_pcic(struct pci_channel *chan);
4980
4981 struct sh4_pci_address_space {
4982 diff -urNp linux-2.6.39.2/arch/sh/drivers/pci/pci-sh5.h linux-2.6.39.2/arch/sh/drivers/pci/pci-sh5.h
4983 --- linux-2.6.39.2/arch/sh/drivers/pci/pci-sh5.h 2011-05-19 00:06:34.000000000 -0400
4984 +++ linux-2.6.39.2/arch/sh/drivers/pci/pci-sh5.h 2011-05-22 19:36:30.000000000 -0400
4985 @@ -105,6 +105,6 @@ extern unsigned long pcicr_virt;
4986 #define PCISH5_MEM_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4987 #define PCISH5_IO_SIZCONV(x) (((x / 0x40000) - 1) << 18)
4988
4989 -extern struct pci_ops sh5_pci_ops;
4990 +extern const struct pci_ops sh5_pci_ops;
4991
4992 #endif /* __PCI_SH5_H */
4993 diff -urNp linux-2.6.39.2/arch/sh/include/asm/dma-mapping.h linux-2.6.39.2/arch/sh/include/asm/dma-mapping.h
4994 --- linux-2.6.39.2/arch/sh/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
4995 +++ linux-2.6.39.2/arch/sh/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
4996 @@ -1,10 +1,10 @@
4997 #ifndef __ASM_SH_DMA_MAPPING_H
4998 #define __ASM_SH_DMA_MAPPING_H
4999
5000 -extern struct dma_map_ops *dma_ops;
5001 +extern const struct dma_map_ops *dma_ops;
5002 extern void no_iommu_init(void);
5003
5004 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5005 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5006 {
5007 return dma_ops;
5008 }
5009 @@ -14,7 +14,7 @@ static inline struct dma_map_ops *get_dm
5010
5011 static inline int dma_supported(struct device *dev, u64 mask)
5012 {
5013 - struct dma_map_ops *ops = get_dma_ops(dev);
5014 + const struct dma_map_ops *ops = get_dma_ops(dev);
5015
5016 if (ops->dma_supported)
5017 return ops->dma_supported(dev, mask);
5018 @@ -24,7 +24,7 @@ static inline int dma_supported(struct d
5019
5020 static inline int dma_set_mask(struct device *dev, u64 mask)
5021 {
5022 - struct dma_map_ops *ops = get_dma_ops(dev);
5023 + const struct dma_map_ops *ops = get_dma_ops(dev);
5024
5025 if (!dev->dma_mask || !dma_supported(dev, mask))
5026 return -EIO;
5027 @@ -44,7 +44,7 @@ void dma_cache_sync(struct device *dev,
5028
5029 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
5030 {
5031 - struct dma_map_ops *ops = get_dma_ops(dev);
5032 + const struct dma_map_ops *ops = get_dma_ops(dev);
5033
5034 if (ops->mapping_error)
5035 return ops->mapping_error(dev, dma_addr);
5036 @@ -55,7 +55,7 @@ static inline int dma_mapping_error(stru
5037 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5038 dma_addr_t *dma_handle, gfp_t gfp)
5039 {
5040 - struct dma_map_ops *ops = get_dma_ops(dev);
5041 + const struct dma_map_ops *ops = get_dma_ops(dev);
5042 void *memory;
5043
5044 if (dma_alloc_from_coherent(dev, size, dma_handle, &memory))
5045 @@ -72,7 +72,7 @@ static inline void *dma_alloc_coherent(s
5046 static inline void dma_free_coherent(struct device *dev, size_t size,
5047 void *vaddr, dma_addr_t dma_handle)
5048 {
5049 - struct dma_map_ops *ops = get_dma_ops(dev);
5050 + const struct dma_map_ops *ops = get_dma_ops(dev);
5051
5052 if (dma_release_from_coherent(dev, get_order(size), vaddr))
5053 return;
5054 diff -urNp linux-2.6.39.2/arch/sh/kernel/dma-nommu.c linux-2.6.39.2/arch/sh/kernel/dma-nommu.c
5055 --- linux-2.6.39.2/arch/sh/kernel/dma-nommu.c 2011-05-19 00:06:34.000000000 -0400
5056 +++ linux-2.6.39.2/arch/sh/kernel/dma-nommu.c 2011-05-22 19:36:30.000000000 -0400
5057 @@ -62,7 +62,7 @@ static void nommu_sync_sg(struct device
5058 }
5059 #endif
5060
5061 -struct dma_map_ops nommu_dma_ops = {
5062 +const struct dma_map_ops nommu_dma_ops = {
5063 .alloc_coherent = dma_generic_alloc_coherent,
5064 .free_coherent = dma_generic_free_coherent,
5065 .map_page = nommu_map_page,
5066 diff -urNp linux-2.6.39.2/arch/sh/kernel/kgdb.c linux-2.6.39.2/arch/sh/kernel/kgdb.c
5067 --- linux-2.6.39.2/arch/sh/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
5068 +++ linux-2.6.39.2/arch/sh/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
5069 @@ -319,7 +319,7 @@ void kgdb_arch_exit(void)
5070 unregister_die_notifier(&kgdb_notifier);
5071 }
5072
5073 -struct kgdb_arch arch_kgdb_ops = {
5074 +const struct kgdb_arch arch_kgdb_ops = {
5075 /* Breakpoint instruction: trapa #0x3c */
5076 #ifdef CONFIG_CPU_LITTLE_ENDIAN
5077 .gdb_bpt_instr = { 0x3c, 0xc3 },
5078 diff -urNp linux-2.6.39.2/arch/sh/mm/consistent.c linux-2.6.39.2/arch/sh/mm/consistent.c
5079 --- linux-2.6.39.2/arch/sh/mm/consistent.c 2011-05-19 00:06:34.000000000 -0400
5080 +++ linux-2.6.39.2/arch/sh/mm/consistent.c 2011-05-22 19:36:30.000000000 -0400
5081 @@ -22,7 +22,7 @@
5082
5083 #define PREALLOC_DMA_DEBUG_ENTRIES 4096
5084
5085 -struct dma_map_ops *dma_ops;
5086 +const struct dma_map_ops *dma_ops;
5087 EXPORT_SYMBOL(dma_ops);
5088
5089 static int __init dma_init(void)
5090 diff -urNp linux-2.6.39.2/arch/sh/mm/mmap.c linux-2.6.39.2/arch/sh/mm/mmap.c
5091 --- linux-2.6.39.2/arch/sh/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
5092 +++ linux-2.6.39.2/arch/sh/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
5093 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(str
5094 addr = PAGE_ALIGN(addr);
5095
5096 vma = find_vma(mm, addr);
5097 - if (TASK_SIZE - len >= addr &&
5098 - (!vma || addr + len <= vma->vm_start))
5099 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5100 return addr;
5101 }
5102
5103 @@ -106,7 +105,7 @@ full_search:
5104 }
5105 return -ENOMEM;
5106 }
5107 - if (likely(!vma || addr + len <= vma->vm_start)) {
5108 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5109 /*
5110 * Remember the place where we stopped the search:
5111 */
5112 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct fi
5113 addr = PAGE_ALIGN(addr);
5114
5115 vma = find_vma(mm, addr);
5116 - if (TASK_SIZE - len >= addr &&
5117 - (!vma || addr + len <= vma->vm_start))
5118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5119 return addr;
5120 }
5121
5122 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct fi
5123 /* make sure it can fit in the remaining address space */
5124 if (likely(addr > len)) {
5125 vma = find_vma(mm, addr-len);
5126 - if (!vma || addr <= vma->vm_start) {
5127 + if (check_heap_stack_gap(vma, addr - len, len)) {
5128 /* remember the address as a hint for next time */
5129 return (mm->free_area_cache = addr-len);
5130 }
5131 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct fi
5132 if (unlikely(mm->mmap_base < len))
5133 goto bottomup;
5134
5135 - addr = mm->mmap_base-len;
5136 - if (do_colour_align)
5137 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5138 + addr = mm->mmap_base - len;
5139
5140 do {
5141 + if (do_colour_align)
5142 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5143 /*
5144 * Lookup failure means no vma is above this address,
5145 * else if new region fits below vma->vm_start,
5146 * return with success:
5147 */
5148 vma = find_vma(mm, addr);
5149 - if (likely(!vma || addr+len <= vma->vm_start)) {
5150 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5151 /* remember the address as a hint for next time */
5152 return (mm->free_area_cache = addr);
5153 }
5154 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct fi
5155 mm->cached_hole_size = vma->vm_start - addr;
5156
5157 /* try just below the current vma->vm_start */
5158 - addr = vma->vm_start-len;
5159 - if (do_colour_align)
5160 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5161 - } while (likely(len < vma->vm_start));
5162 + addr = skip_heap_stack_gap(vma, len);
5163 + } while (!IS_ERR_VALUE(addr));
5164
5165 bottomup:
5166 /*
5167 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/atomic_64.h linux-2.6.39.2/arch/sparc/include/asm/atomic_64.h
5168 --- linux-2.6.39.2/arch/sparc/include/asm/atomic_64.h 2011-05-19 00:06:34.000000000 -0400
5169 +++ linux-2.6.39.2/arch/sparc/include/asm/atomic_64.h 2011-05-22 19:36:30.000000000 -0400
5170 @@ -14,18 +14,40 @@
5171 #define ATOMIC64_INIT(i) { (i) }
5172
5173 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5174 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5175 +{
5176 + return v->counter;
5177 +}
5178 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5179 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5180 +{
5181 + return v->counter;
5182 +}
5183
5184 #define atomic_set(v, i) (((v)->counter) = i)
5185 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5186 +{
5187 + v->counter = i;
5188 +}
5189 #define atomic64_set(v, i) (((v)->counter) = i)
5190 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5191 +{
5192 + v->counter = i;
5193 +}
5194
5195 extern void atomic_add(int, atomic_t *);
5196 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5197 extern void atomic64_add(long, atomic64_t *);
5198 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5199 extern void atomic_sub(int, atomic_t *);
5200 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5201 extern void atomic64_sub(long, atomic64_t *);
5202 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5203
5204 extern int atomic_add_ret(int, atomic_t *);
5205 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5206 extern long atomic64_add_ret(long, atomic64_t *);
5207 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5208 extern int atomic_sub_ret(int, atomic_t *);
5209 extern long atomic64_sub_ret(long, atomic64_t *);
5210
5211 @@ -33,12 +55,24 @@ extern long atomic64_sub_ret(long, atomi
5212 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5213
5214 #define atomic_inc_return(v) atomic_add_ret(1, v)
5215 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5216 +{
5217 + return atomic_add_ret_unchecked(1, v);
5218 +}
5219 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5220 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5221 +{
5222 + return atomic64_add_ret_unchecked(1, v);
5223 +}
5224
5225 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5226 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5227
5228 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5229 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5230 +{
5231 + return atomic_add_ret_unchecked(i, v);
5232 +}
5233 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5234
5235 /*
5236 @@ -50,6 +84,7 @@ extern long atomic64_sub_ret(long, atomi
5237 * other cases.
5238 */
5239 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5240 +#define atomic_inc_and_test_unchecked(v) (atomic_inc_return_unchecked(v) == 0)
5241 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5242
5243 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5244 @@ -59,30 +94,59 @@ extern long atomic64_sub_ret(long, atomi
5245 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5246
5247 #define atomic_inc(v) atomic_add(1, v)
5248 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5249 +{
5250 + atomic_add_unchecked(1, v);
5251 +}
5252 #define atomic64_inc(v) atomic64_add(1, v)
5253 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5254 +{
5255 + atomic64_add_unchecked(1, v);
5256 +}
5257
5258 #define atomic_dec(v) atomic_sub(1, v)
5259 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5260 +{
5261 + atomic_sub_unchecked(1, v);
5262 +}
5263 #define atomic64_dec(v) atomic64_sub(1, v)
5264 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5265 +{
5266 + atomic64_sub_unchecked(1, v);
5267 +}
5268
5269 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5270 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5271
5272 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5273 +#define atomic_cmpxchg_unchecked(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5275 +#define atomic_xchg_unchecked(v, new) (xchg(&((v)->counter), new))
5276
5277 static inline int atomic_add_unless(atomic_t *v, int a, int u)
5278 {
5279 - int c, old;
5280 + int c, old, new;
5281 c = atomic_read(v);
5282 for (;;) {
5283 - if (unlikely(c == (u)))
5284 + if (unlikely(c == u))
5285 break;
5286 - old = atomic_cmpxchg((v), c, c + (a));
5287 +
5288 + asm volatile("addcc %2, %0, %0\n"
5289 +
5290 +#ifdef CONFIG_PAX_REFCOUNT
5291 + "tvs %%icc, 6\n"
5292 +#endif
5293 +
5294 + : "=r" (new)
5295 + : "0" (c), "ir" (a)
5296 + : "cc");
5297 +
5298 + old = atomic_cmpxchg(v, c, new);
5299 if (likely(old == c))
5300 break;
5301 c = old;
5302 }
5303 - return c != (u);
5304 + return c != u;
5305 }
5306
5307 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
5308 @@ -93,17 +157,28 @@ static inline int atomic_add_unless(atom
5309
5310 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5311 {
5312 - long c, old;
5313 + long c, old, new;
5314 c = atomic64_read(v);
5315 for (;;) {
5316 - if (unlikely(c == (u)))
5317 + if (unlikely(c == u))
5318 break;
5319 - old = atomic64_cmpxchg((v), c, c + (a));
5320 +
5321 + asm volatile("addcc %2, %0, %0\n"
5322 +
5323 +#ifdef CONFIG_PAX_REFCOUNT
5324 + "tvs %%xcc, 6\n"
5325 +#endif
5326 +
5327 + : "=r" (new)
5328 + : "0" (c), "ir" (a)
5329 + : "cc");
5330 +
5331 + old = atomic64_cmpxchg(v, c, new);
5332 if (likely(old == c))
5333 break;
5334 c = old;
5335 }
5336 - return c != (u);
5337 + return c != u;
5338 }
5339
5340 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5341 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/cache.h linux-2.6.39.2/arch/sparc/include/asm/cache.h
5342 --- linux-2.6.39.2/arch/sparc/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
5343 +++ linux-2.6.39.2/arch/sparc/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
5344 @@ -10,7 +10,7 @@
5345 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5346
5347 #define L1_CACHE_SHIFT 5
5348 -#define L1_CACHE_BYTES 32
5349 +#define L1_CACHE_BYTES 32U
5350
5351 #ifdef CONFIG_SPARC32
5352 #define SMP_CACHE_BYTES_SHIFT 5
5353 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/dma-mapping.h linux-2.6.39.2/arch/sparc/include/asm/dma-mapping.h
5354 --- linux-2.6.39.2/arch/sparc/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
5355 +++ linux-2.6.39.2/arch/sparc/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
5356 @@ -12,10 +12,10 @@ extern int dma_supported(struct device *
5357 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
5358 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
5359
5360 -extern struct dma_map_ops *dma_ops, pci32_dma_ops;
5361 +extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
5362 extern struct bus_type pci_bus_type;
5363
5364 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
5365 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
5366 {
5367 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
5368 if (dev->bus == &pci_bus_type)
5369 @@ -29,7 +29,7 @@ static inline struct dma_map_ops *get_dm
5370 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
5371 dma_addr_t *dma_handle, gfp_t flag)
5372 {
5373 - struct dma_map_ops *ops = get_dma_ops(dev);
5374 + const struct dma_map_ops *ops = get_dma_ops(dev);
5375 void *cpu_addr;
5376
5377 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
5378 @@ -40,7 +40,7 @@ static inline void *dma_alloc_coherent(s
5379 static inline void dma_free_coherent(struct device *dev, size_t size,
5380 void *cpu_addr, dma_addr_t dma_handle)
5381 {
5382 - struct dma_map_ops *ops = get_dma_ops(dev);
5383 + const struct dma_map_ops *ops = get_dma_ops(dev);
5384
5385 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
5386 ops->free_coherent(dev, size, cpu_addr, dma_handle);
5387 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/elf_32.h linux-2.6.39.2/arch/sparc/include/asm/elf_32.h
5388 --- linux-2.6.39.2/arch/sparc/include/asm/elf_32.h 2011-05-19 00:06:34.000000000 -0400
5389 +++ linux-2.6.39.2/arch/sparc/include/asm/elf_32.h 2011-05-22 19:36:30.000000000 -0400
5390 @@ -114,6 +114,13 @@ typedef struct {
5391
5392 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5393
5394 +#ifdef CONFIG_PAX_ASLR
5395 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5396 +
5397 +#define PAX_DELTA_MMAP_LEN 16
5398 +#define PAX_DELTA_STACK_LEN 16
5399 +#endif
5400 +
5401 /* This yields a mask that user programs can use to figure out what
5402 instruction set this cpu supports. This can NOT be done in userspace
5403 on Sparc. */
5404 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/elf_64.h linux-2.6.39.2/arch/sparc/include/asm/elf_64.h
5405 --- linux-2.6.39.2/arch/sparc/include/asm/elf_64.h 2011-05-19 00:06:34.000000000 -0400
5406 +++ linux-2.6.39.2/arch/sparc/include/asm/elf_64.h 2011-05-22 19:36:30.000000000 -0400
5407 @@ -162,6 +162,12 @@ typedef struct {
5408 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5409 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5410
5411 +#ifdef CONFIG_PAX_ASLR
5412 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5413 +
5414 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5415 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5416 +#endif
5417
5418 /* This yields a mask that user programs can use to figure out what
5419 instruction set this cpu supports. */
5420 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/pgtable_32.h linux-2.6.39.2/arch/sparc/include/asm/pgtable_32.h
5421 --- linux-2.6.39.2/arch/sparc/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
5422 +++ linux-2.6.39.2/arch/sparc/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
5423 @@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5424 BTFIXUPDEF_INT(page_none)
5425 BTFIXUPDEF_INT(page_copy)
5426 BTFIXUPDEF_INT(page_readonly)
5427 +
5428 +#ifdef CONFIG_PAX_PAGEEXEC
5429 +BTFIXUPDEF_INT(page_shared_noexec)
5430 +BTFIXUPDEF_INT(page_copy_noexec)
5431 +BTFIXUPDEF_INT(page_readonly_noexec)
5432 +#endif
5433 +
5434 BTFIXUPDEF_INT(page_kernel)
5435
5436 #define PMD_SHIFT SUN4C_PMD_SHIFT
5437 @@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
5438 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5439 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5440
5441 +#ifdef CONFIG_PAX_PAGEEXEC
5442 +extern pgprot_t PAGE_SHARED_NOEXEC;
5443 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5444 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5445 +#else
5446 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5447 +# define PAGE_COPY_NOEXEC PAGE_COPY
5448 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5449 +#endif
5450 +
5451 extern unsigned long page_kernel;
5452
5453 #ifdef MODULE
5454 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.39.2/arch/sparc/include/asm/pgtsrmmu.h
5455 --- linux-2.6.39.2/arch/sparc/include/asm/pgtsrmmu.h 2011-05-19 00:06:34.000000000 -0400
5456 +++ linux-2.6.39.2/arch/sparc/include/asm/pgtsrmmu.h 2011-05-22 19:36:30.000000000 -0400
5457 @@ -115,6 +115,13 @@
5458 SRMMU_EXEC | SRMMU_REF)
5459 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5460 SRMMU_EXEC | SRMMU_REF)
5461 +
5462 +#ifdef CONFIG_PAX_PAGEEXEC
5463 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5464 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5465 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5466 +#endif
5467 +
5468 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5469 SRMMU_DIRTY | SRMMU_REF)
5470
5471 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/spinlock_64.h linux-2.6.39.2/arch/sparc/include/asm/spinlock_64.h
5472 --- linux-2.6.39.2/arch/sparc/include/asm/spinlock_64.h 2011-05-19 00:06:34.000000000 -0400
5473 +++ linux-2.6.39.2/arch/sparc/include/asm/spinlock_64.h 2011-05-22 19:36:30.000000000 -0400
5474 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(
5475
5476 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5477
5478 -static void inline arch_read_lock(arch_rwlock_t *lock)
5479 +static inline void arch_read_lock(arch_rwlock_t *lock)
5480 {
5481 unsigned long tmp1, tmp2;
5482
5483 __asm__ __volatile__ (
5484 "1: ldsw [%2], %0\n"
5485 " brlz,pn %0, 2f\n"
5486 -"4: add %0, 1, %1\n"
5487 +"4: addcc %0, 1, %1\n"
5488 +
5489 +#ifdef CONFIG_PAX_REFCOUNT
5490 +" tvs %%icc, 6\n"
5491 +#endif
5492 +
5493 " cas [%2], %0, %1\n"
5494 " cmp %0, %1\n"
5495 " bne,pn %%icc, 1b\n"
5496 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_r
5497 " .previous"
5498 : "=&r" (tmp1), "=&r" (tmp2)
5499 : "r" (lock)
5500 - : "memory");
5501 + : "memory", "cc");
5502 }
5503
5504 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5505 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5506 {
5507 int tmp1, tmp2;
5508
5509 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch
5510 "1: ldsw [%2], %0\n"
5511 " brlz,a,pn %0, 2f\n"
5512 " mov 0, %0\n"
5513 -" add %0, 1, %1\n"
5514 +" addcc %0, 1, %1\n"
5515 +
5516 +#ifdef CONFIG_PAX_REFCOUNT
5517 +" tvs %%icc, 6\n"
5518 +#endif
5519 +
5520 " cas [%2], %0, %1\n"
5521 " cmp %0, %1\n"
5522 " bne,pn %%icc, 1b\n"
5523 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch
5524 return tmp1;
5525 }
5526
5527 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5528 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5529 {
5530 unsigned long tmp1, tmp2;
5531
5532 __asm__ __volatile__(
5533 "1: lduw [%2], %0\n"
5534 -" sub %0, 1, %1\n"
5535 +" subcc %0, 1, %1\n"
5536 +
5537 +#ifdef CONFIG_PAX_REFCOUNT
5538 +" tvs %%icc, 6\n"
5539 +#endif
5540 +
5541 " cas [%2], %0, %1\n"
5542 " cmp %0, %1\n"
5543 " bne,pn %%xcc, 1b\n"
5544 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch
5545 : "memory");
5546 }
5547
5548 -static void inline arch_write_lock(arch_rwlock_t *lock)
5549 +static inline void arch_write_lock(arch_rwlock_t *lock)
5550 {
5551 unsigned long mask, tmp1, tmp2;
5552
5553 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_
5554 : "memory");
5555 }
5556
5557 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5558 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5559 {
5560 __asm__ __volatile__(
5561 " stw %%g0, [%0]"
5562 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arc
5563 : "memory");
5564 }
5565
5566 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5567 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5568 {
5569 unsigned long mask, tmp1, tmp2, result;
5570
5571 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/thread_info_32.h linux-2.6.39.2/arch/sparc/include/asm/thread_info_32.h
5572 --- linux-2.6.39.2/arch/sparc/include/asm/thread_info_32.h 2011-05-19 00:06:34.000000000 -0400
5573 +++ linux-2.6.39.2/arch/sparc/include/asm/thread_info_32.h 2011-06-03 01:14:03.000000000 -0400
5574 @@ -50,6 +50,8 @@ struct thread_info {
5575 unsigned long w_saved;
5576
5577 struct restart_block restart_block;
5578 +
5579 + unsigned long lowest_stack;
5580 };
5581
5582 /*
5583 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/thread_info_64.h linux-2.6.39.2/arch/sparc/include/asm/thread_info_64.h
5584 --- linux-2.6.39.2/arch/sparc/include/asm/thread_info_64.h 2011-05-19 00:06:34.000000000 -0400
5585 +++ linux-2.6.39.2/arch/sparc/include/asm/thread_info_64.h 2011-06-03 01:14:21.000000000 -0400
5586 @@ -63,6 +63,8 @@ struct thread_info {
5587 struct pt_regs *kern_una_regs;
5588 unsigned int kern_una_insn;
5589
5590 + unsigned long lowest_stack;
5591 +
5592 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5593 };
5594
5595 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/uaccess_32.h linux-2.6.39.2/arch/sparc/include/asm/uaccess_32.h
5596 --- linux-2.6.39.2/arch/sparc/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
5597 +++ linux-2.6.39.2/arch/sparc/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
5598 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __
5599
5600 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5601 {
5602 - if (n && __access_ok((unsigned long) to, n))
5603 + if ((long)n < 0)
5604 + return n;
5605 +
5606 + if (n && __access_ok((unsigned long) to, n)) {
5607 + if (!__builtin_constant_p(n))
5608 + check_object_size(from, n, true);
5609 return __copy_user(to, (__force void __user *) from, n);
5610 - else
5611 + } else
5612 return n;
5613 }
5614
5615 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5616 {
5617 + if ((long)n < 0)
5618 + return n;
5619 +
5620 + if (!__builtin_constant_p(n))
5621 + check_object_size(from, n, true);
5622 +
5623 return __copy_user(to, (__force void __user *) from, n);
5624 }
5625
5626 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5627 {
5628 - if (n && __access_ok((unsigned long) from, n))
5629 + if ((long)n < 0)
5630 + return n;
5631 +
5632 + if (n && __access_ok((unsigned long) from, n)) {
5633 + if (!__builtin_constant_p(n))
5634 + check_object_size(to, n, false);
5635 return __copy_user((__force void __user *) to, from, n);
5636 - else
5637 + } else
5638 return n;
5639 }
5640
5641 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5642 {
5643 + if ((long)n < 0)
5644 + return n;
5645 +
5646 return __copy_user((__force void __user *) to, from, n);
5647 }
5648
5649 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/uaccess_64.h linux-2.6.39.2/arch/sparc/include/asm/uaccess_64.h
5650 --- linux-2.6.39.2/arch/sparc/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
5651 +++ linux-2.6.39.2/arch/sparc/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
5652 @@ -10,6 +10,7 @@
5653 #include <linux/compiler.h>
5654 #include <linux/string.h>
5655 #include <linux/thread_info.h>
5656 +#include <linux/kernel.h>
5657 #include <asm/asi.h>
5658 #include <asm/system.h>
5659 #include <asm/spitfire.h>
5660 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixu
5661 static inline unsigned long __must_check
5662 copy_from_user(void *to, const void __user *from, unsigned long size)
5663 {
5664 - unsigned long ret = ___copy_from_user(to, from, size);
5665 + unsigned long ret;
5666
5667 + if ((long)size < 0 || size > INT_MAX)
5668 + return size;
5669 +
5670 + if (!__builtin_constant_p(size))
5671 + check_object_size(to, size, false);
5672 +
5673 + ret = ___copy_from_user(to, from, size);
5674 if (unlikely(ret))
5675 ret = copy_from_user_fixup(to, from, size);
5676
5677 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(
5678 static inline unsigned long __must_check
5679 copy_to_user(void __user *to, const void *from, unsigned long size)
5680 {
5681 - unsigned long ret = ___copy_to_user(to, from, size);
5682 + unsigned long ret;
5683 +
5684 + if ((long)size < 0 || size > INT_MAX)
5685 + return size;
5686 +
5687 + if (!__builtin_constant_p(size))
5688 + check_object_size(from, size, true);
5689
5690 + ret = ___copy_to_user(to, from, size);
5691 if (unlikely(ret))
5692 ret = copy_to_user_fixup(to, from, size);
5693 return ret;
5694 diff -urNp linux-2.6.39.2/arch/sparc/include/asm/uaccess.h linux-2.6.39.2/arch/sparc/include/asm/uaccess.h
5695 --- linux-2.6.39.2/arch/sparc/include/asm/uaccess.h 2011-05-19 00:06:34.000000000 -0400
5696 +++ linux-2.6.39.2/arch/sparc/include/asm/uaccess.h 2011-05-22 19:36:30.000000000 -0400
5697 @@ -1,5 +1,13 @@
5698 #ifndef ___ASM_SPARC_UACCESS_H
5699 #define ___ASM_SPARC_UACCESS_H
5700 +
5701 +#ifdef __KERNEL__
5702 +#ifndef __ASSEMBLY__
5703 +#include <linux/types.h>
5704 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5705 +#endif
5706 +#endif
5707 +
5708 #if defined(__sparc__) && defined(__arch64__)
5709 #include <asm/uaccess_64.h>
5710 #else
5711 diff -urNp linux-2.6.39.2/arch/sparc/kernel/iommu.c linux-2.6.39.2/arch/sparc/kernel/iommu.c
5712 --- linux-2.6.39.2/arch/sparc/kernel/iommu.c 2011-05-19 00:06:34.000000000 -0400
5713 +++ linux-2.6.39.2/arch/sparc/kernel/iommu.c 2011-05-22 19:36:30.000000000 -0400
5714 @@ -824,7 +824,7 @@ static void dma_4u_sync_sg_for_cpu(struc
5715 spin_unlock_irqrestore(&iommu->lock, flags);
5716 }
5717
5718 -static struct dma_map_ops sun4u_dma_ops = {
5719 +static const struct dma_map_ops sun4u_dma_ops = {
5720 .alloc_coherent = dma_4u_alloc_coherent,
5721 .free_coherent = dma_4u_free_coherent,
5722 .map_page = dma_4u_map_page,
5723 @@ -835,7 +835,7 @@ static struct dma_map_ops sun4u_dma_ops
5724 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
5725 };
5726
5727 -struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5728 +const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
5729 EXPORT_SYMBOL(dma_ops);
5730
5731 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
5732 diff -urNp linux-2.6.39.2/arch/sparc/kernel/ioport.c linux-2.6.39.2/arch/sparc/kernel/ioport.c
5733 --- linux-2.6.39.2/arch/sparc/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
5734 +++ linux-2.6.39.2/arch/sparc/kernel/ioport.c 2011-05-22 19:36:30.000000000 -0400
5735 @@ -402,7 +402,7 @@ static void sbus_sync_sg_for_device(stru
5736 BUG();
5737 }
5738
5739 -struct dma_map_ops sbus_dma_ops = {
5740 +const struct dma_map_ops sbus_dma_ops = {
5741 .alloc_coherent = sbus_alloc_coherent,
5742 .free_coherent = sbus_free_coherent,
5743 .map_page = sbus_map_page,
5744 @@ -653,7 +653,7 @@ static void pci32_sync_sg_for_device(str
5745 }
5746 }
5747
5748 -struct dma_map_ops pci32_dma_ops = {
5749 +const struct dma_map_ops pci32_dma_ops = {
5750 .alloc_coherent = pci32_alloc_coherent,
5751 .free_coherent = pci32_free_coherent,
5752 .map_page = pci32_map_page,
5753 diff -urNp linux-2.6.39.2/arch/sparc/kernel/kgdb_32.c linux-2.6.39.2/arch/sparc/kernel/kgdb_32.c
5754 --- linux-2.6.39.2/arch/sparc/kernel/kgdb_32.c 2011-05-19 00:06:34.000000000 -0400
5755 +++ linux-2.6.39.2/arch/sparc/kernel/kgdb_32.c 2011-05-22 19:36:30.000000000 -0400
5756 @@ -164,7 +164,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5757 regs->npc = regs->pc + 4;
5758 }
5759
5760 -struct kgdb_arch arch_kgdb_ops = {
5761 +const struct kgdb_arch arch_kgdb_ops = {
5762 /* Breakpoint instruction: ta 0x7d */
5763 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
5764 };
5765 diff -urNp linux-2.6.39.2/arch/sparc/kernel/kgdb_64.c linux-2.6.39.2/arch/sparc/kernel/kgdb_64.c
5766 --- linux-2.6.39.2/arch/sparc/kernel/kgdb_64.c 2011-05-19 00:06:34.000000000 -0400
5767 +++ linux-2.6.39.2/arch/sparc/kernel/kgdb_64.c 2011-05-22 19:36:30.000000000 -0400
5768 @@ -187,7 +187,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
5769 regs->tnpc = regs->tpc + 4;
5770 }
5771
5772 -struct kgdb_arch arch_kgdb_ops = {
5773 +const struct kgdb_arch arch_kgdb_ops = {
5774 /* Breakpoint instruction: ta 0x72 */
5775 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
5776 };
5777 diff -urNp linux-2.6.39.2/arch/sparc/kernel/Makefile linux-2.6.39.2/arch/sparc/kernel/Makefile
5778 --- linux-2.6.39.2/arch/sparc/kernel/Makefile 2011-05-19 00:06:34.000000000 -0400
5779 +++ linux-2.6.39.2/arch/sparc/kernel/Makefile 2011-05-22 19:36:30.000000000 -0400
5780 @@ -3,7 +3,7 @@
5781 #
5782
5783 asflags-y := -ansi
5784 -ccflags-y := -Werror
5785 +#ccflags-y := -Werror
5786
5787 extra-y := head_$(BITS).o
5788 extra-y += init_task.o
5789 diff -urNp linux-2.6.39.2/arch/sparc/kernel/pcic.c linux-2.6.39.2/arch/sparc/kernel/pcic.c
5790 --- linux-2.6.39.2/arch/sparc/kernel/pcic.c 2011-05-19 00:06:34.000000000 -0400
5791 +++ linux-2.6.39.2/arch/sparc/kernel/pcic.c 2011-05-22 19:36:30.000000000 -0400
5792 @@ -268,7 +268,7 @@ static int pcic_write_config(struct pci_
5793 return -EINVAL;
5794 }
5795
5796 -static struct pci_ops pcic_ops = {
5797 +static const struct pci_ops pcic_ops = {
5798 .read = pcic_read_config,
5799 .write = pcic_write_config,
5800 };
5801 diff -urNp linux-2.6.39.2/arch/sparc/kernel/pci_common.c linux-2.6.39.2/arch/sparc/kernel/pci_common.c
5802 --- linux-2.6.39.2/arch/sparc/kernel/pci_common.c 2011-05-19 00:06:34.000000000 -0400
5803 +++ linux-2.6.39.2/arch/sparc/kernel/pci_common.c 2011-05-22 19:36:30.000000000 -0400
5804 @@ -249,7 +249,7 @@ static int sun4u_write_pci_cfg(struct pc
5805 return PCIBIOS_SUCCESSFUL;
5806 }
5807
5808 -struct pci_ops sun4u_pci_ops = {
5809 +const struct pci_ops sun4u_pci_ops = {
5810 .read = sun4u_read_pci_cfg,
5811 .write = sun4u_write_pci_cfg,
5812 };
5813 @@ -310,7 +310,7 @@ static int sun4v_write_pci_cfg(struct pc
5814 return PCIBIOS_SUCCESSFUL;
5815 }
5816
5817 -struct pci_ops sun4v_pci_ops = {
5818 +const struct pci_ops sun4v_pci_ops = {
5819 .read = sun4v_read_pci_cfg,
5820 .write = sun4v_write_pci_cfg,
5821 };
5822 diff -urNp linux-2.6.39.2/arch/sparc/kernel/pci_impl.h linux-2.6.39.2/arch/sparc/kernel/pci_impl.h
5823 --- linux-2.6.39.2/arch/sparc/kernel/pci_impl.h 2011-05-19 00:06:34.000000000 -0400
5824 +++ linux-2.6.39.2/arch/sparc/kernel/pci_impl.h 2011-05-22 19:36:30.000000000 -0400
5825 @@ -175,8 +175,8 @@ extern void pci_config_write8(u8 *addr,
5826 extern void pci_config_write16(u16 *addr, u16 val);
5827 extern void pci_config_write32(u32 *addr, u32 val);
5828
5829 -extern struct pci_ops sun4u_pci_ops;
5830 -extern struct pci_ops sun4v_pci_ops;
5831 +extern const struct pci_ops sun4u_pci_ops;
5832 +extern const struct pci_ops sun4v_pci_ops;
5833
5834 extern volatile int pci_poke_in_progress;
5835 extern volatile int pci_poke_cpu;
5836 diff -urNp linux-2.6.39.2/arch/sparc/kernel/pci_sun4v.c linux-2.6.39.2/arch/sparc/kernel/pci_sun4v.c
5837 --- linux-2.6.39.2/arch/sparc/kernel/pci_sun4v.c 2011-05-19 00:06:34.000000000 -0400
5838 +++ linux-2.6.39.2/arch/sparc/kernel/pci_sun4v.c 2011-05-22 19:36:30.000000000 -0400
5839 @@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct devic
5840 spin_unlock_irqrestore(&iommu->lock, flags);
5841 }
5842
5843 -static struct dma_map_ops sun4v_dma_ops = {
5844 +static const struct dma_map_ops sun4v_dma_ops = {
5845 .alloc_coherent = dma_4v_alloc_coherent,
5846 .free_coherent = dma_4v_free_coherent,
5847 .map_page = dma_4v_map_page,
5848 diff -urNp linux-2.6.39.2/arch/sparc/kernel/process_32.c linux-2.6.39.2/arch/sparc/kernel/process_32.c
5849 --- linux-2.6.39.2/arch/sparc/kernel/process_32.c 2011-05-19 00:06:34.000000000 -0400
5850 +++ linux-2.6.39.2/arch/sparc/kernel/process_32.c 2011-05-22 19:41:32.000000000 -0400
5851 @@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
5852 rw->ins[4], rw->ins[5],
5853 rw->ins[6],
5854 rw->ins[7]);
5855 - printk("%pS\n", (void *) rw->ins[7]);
5856 + printk("%pA\n", (void *) rw->ins[7]);
5857 rw = (struct reg_window32 *) rw->ins[6];
5858 }
5859 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5860 @@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
5861
5862 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5863 r->psr, r->pc, r->npc, r->y, print_tainted());
5864 - printk("PC: <%pS>\n", (void *) r->pc);
5865 + printk("PC: <%pA>\n", (void *) r->pc);
5866 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5867 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5868 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5869 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5870 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5871 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5872 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5873 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5874
5875 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5876 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5877 @@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk,
5878 rw = (struct reg_window32 *) fp;
5879 pc = rw->ins[7];
5880 printk("[%08lx : ", pc);
5881 - printk("%pS ] ", (void *) pc);
5882 + printk("%pA ] ", (void *) pc);
5883 fp = rw->ins[6];
5884 } while (++count < 16);
5885 printk("\n");
5886 diff -urNp linux-2.6.39.2/arch/sparc/kernel/process_64.c linux-2.6.39.2/arch/sparc/kernel/process_64.c
5887 --- linux-2.6.39.2/arch/sparc/kernel/process_64.c 2011-05-19 00:06:34.000000000 -0400
5888 +++ linux-2.6.39.2/arch/sparc/kernel/process_64.c 2011-05-22 19:41:32.000000000 -0400
5889 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_reg
5890 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5891 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5892 if (regs->tstate & TSTATE_PRIV)
5893 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5894 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5895 }
5896
5897 void show_regs(struct pt_regs *regs)
5898 {
5899 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5900 regs->tpc, regs->tnpc, regs->y, print_tainted());
5901 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5902 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5903 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5904 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5905 regs->u_regs[3]);
5906 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5907 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5908 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5909 regs->u_regs[15]);
5910 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5911 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5912 show_regwindow(regs);
5913 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5914 }
5915 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void
5916 ((tp && tp->task) ? tp->task->pid : -1));
5917
5918 if (gp->tstate & TSTATE_PRIV) {
5919 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5920 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5921 (void *) gp->tpc,
5922 (void *) gp->o7,
5923 (void *) gp->i7,
5924 diff -urNp linux-2.6.39.2/arch/sparc/kernel/sys_sparc_32.c linux-2.6.39.2/arch/sparc/kernel/sys_sparc_32.c
5925 --- linux-2.6.39.2/arch/sparc/kernel/sys_sparc_32.c 2011-05-19 00:06:34.000000000 -0400
5926 +++ linux-2.6.39.2/arch/sparc/kernel/sys_sparc_32.c 2011-05-22 19:36:30.000000000 -0400
5927 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
5928 if (ARCH_SUN4C && len > 0x20000000)
5929 return -ENOMEM;
5930 if (!addr)
5931 - addr = TASK_UNMAPPED_BASE;
5932 + addr = current->mm->mmap_base;
5933
5934 if (flags & MAP_SHARED)
5935 addr = COLOUR_ALIGN(addr);
5936 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(str
5937 }
5938 if (TASK_SIZE - PAGE_SIZE - len < addr)
5939 return -ENOMEM;
5940 - if (!vmm || addr + len <= vmm->vm_start)
5941 + if (check_heap_stack_gap(vmm, addr, len))
5942 return addr;
5943 addr = vmm->vm_end;
5944 if (flags & MAP_SHARED)
5945 diff -urNp linux-2.6.39.2/arch/sparc/kernel/sys_sparc_64.c linux-2.6.39.2/arch/sparc/kernel/sys_sparc_64.c
5946 --- linux-2.6.39.2/arch/sparc/kernel/sys_sparc_64.c 2011-05-19 00:06:34.000000000 -0400
5947 +++ linux-2.6.39.2/arch/sparc/kernel/sys_sparc_64.c 2011-05-22 19:36:30.000000000 -0400
5948 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
5949 /* We do not accept a shared mapping if it would violate
5950 * cache aliasing constraints.
5951 */
5952 - if ((flags & MAP_SHARED) &&
5953 + if ((filp || (flags & MAP_SHARED)) &&
5954 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5955 return -EINVAL;
5956 return addr;
5957 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
5958 if (filp || (flags & MAP_SHARED))
5959 do_color_align = 1;
5960
5961 +#ifdef CONFIG_PAX_RANDMMAP
5962 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5963 +#endif
5964 +
5965 if (addr) {
5966 if (do_color_align)
5967 addr = COLOUR_ALIGN(addr, pgoff);
5968 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(str
5969 addr = PAGE_ALIGN(addr);
5970
5971 vma = find_vma(mm, addr);
5972 - if (task_size - len >= addr &&
5973 - (!vma || addr + len <= vma->vm_start))
5974 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5975 return addr;
5976 }
5977
5978 if (len > mm->cached_hole_size) {
5979 - start_addr = addr = mm->free_area_cache;
5980 + start_addr = addr = mm->free_area_cache;
5981 } else {
5982 - start_addr = addr = TASK_UNMAPPED_BASE;
5983 + start_addr = addr = mm->mmap_base;
5984 mm->cached_hole_size = 0;
5985 }
5986
5987 @@ -174,14 +177,14 @@ full_search:
5988 vma = find_vma(mm, VA_EXCLUDE_END);
5989 }
5990 if (unlikely(task_size < addr)) {
5991 - if (start_addr != TASK_UNMAPPED_BASE) {
5992 - start_addr = addr = TASK_UNMAPPED_BASE;
5993 + if (start_addr != mm->mmap_base) {
5994 + start_addr = addr = mm->mmap_base;
5995 mm->cached_hole_size = 0;
5996 goto full_search;
5997 }
5998 return -ENOMEM;
5999 }
6000 - if (likely(!vma || addr + len <= vma->vm_start)) {
6001 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6002 /*
6003 * Remember the place where we stopped the search:
6004 */
6005 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct fi
6006 /* We do not accept a shared mapping if it would violate
6007 * cache aliasing constraints.
6008 */
6009 - if ((flags & MAP_SHARED) &&
6010 + if ((filp || (flags & MAP_SHARED)) &&
6011 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6012 return -EINVAL;
6013 return addr;
6014 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct fi
6015 addr = PAGE_ALIGN(addr);
6016
6017 vma = find_vma(mm, addr);
6018 - if (task_size - len >= addr &&
6019 - (!vma || addr + len <= vma->vm_start))
6020 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6021 return addr;
6022 }
6023
6024 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct fi
6025 /* make sure it can fit in the remaining address space */
6026 if (likely(addr > len)) {
6027 vma = find_vma(mm, addr-len);
6028 - if (!vma || addr <= vma->vm_start) {
6029 + if (check_heap_stack_gap(vma, addr - len, len)) {
6030 /* remember the address as a hint for next time */
6031 return (mm->free_area_cache = addr-len);
6032 }
6033 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct fi
6034 if (unlikely(mm->mmap_base < len))
6035 goto bottomup;
6036
6037 - addr = mm->mmap_base-len;
6038 - if (do_color_align)
6039 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6040 + addr = mm->mmap_base - len;
6041
6042 do {
6043 + if (do_color_align)
6044 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6045 /*
6046 * Lookup failure means no vma is above this address,
6047 * else if new region fits below vma->vm_start,
6048 * return with success:
6049 */
6050 vma = find_vma(mm, addr);
6051 - if (likely(!vma || addr+len <= vma->vm_start)) {
6052 + if (likely(check_heap_stack_gap(vma, addr, len))) {
6053 /* remember the address as a hint for next time */
6054 return (mm->free_area_cache = addr);
6055 }
6056 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct fi
6057 mm->cached_hole_size = vma->vm_start - addr;
6058
6059 /* try just below the current vma->vm_start */
6060 - addr = vma->vm_start-len;
6061 - if (do_color_align)
6062 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6063 - } while (likely(len < vma->vm_start));
6064 + addr = skip_heap_stack_gap(vma, len);
6065 + } while (!IS_ERR_VALUE(addr));
6066
6067 bottomup:
6068 /*
6069 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_str
6070 gap == RLIM_INFINITY ||
6071 sysctl_legacy_va_layout) {
6072 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6073 +
6074 +#ifdef CONFIG_PAX_RANDMMAP
6075 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6076 + mm->mmap_base += mm->delta_mmap;
6077 +#endif
6078 +
6079 mm->get_unmapped_area = arch_get_unmapped_area;
6080 mm->unmap_area = arch_unmap_area;
6081 } else {
6082 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_str
6083 gap = (task_size / 6 * 5);
6084
6085 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6086 +
6087 +#ifdef CONFIG_PAX_RANDMMAP
6088 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6089 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6090 +#endif
6091 +
6092 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6093 mm->unmap_area = arch_unmap_area_topdown;
6094 }
6095 diff -urNp linux-2.6.39.2/arch/sparc/kernel/traps_32.c linux-2.6.39.2/arch/sparc/kernel/traps_32.c
6096 --- linux-2.6.39.2/arch/sparc/kernel/traps_32.c 2011-05-19 00:06:34.000000000 -0400
6097 +++ linux-2.6.39.2/arch/sparc/kernel/traps_32.c 2011-06-13 21:29:23.000000000 -0400
6098 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned lo
6099 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6100 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6101
6102 +extern void gr_handle_kernel_exploit(void);
6103 +
6104 void die_if_kernel(char *str, struct pt_regs *regs)
6105 {
6106 static int die_counter;
6107 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_
6108 count++ < 30 &&
6109 (((unsigned long) rw) >= PAGE_OFFSET) &&
6110 !(((unsigned long) rw) & 0x7)) {
6111 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6112 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6113 (void *) rw->ins[7]);
6114 rw = (struct reg_window32 *)rw->ins[6];
6115 }
6116 }
6117 printk("Instruction DUMP:");
6118 instruction_dump ((unsigned long *) regs->pc);
6119 - if(regs->psr & PSR_PS)
6120 + if(regs->psr & PSR_PS) {
6121 + gr_handle_kernel_exploit();
6122 do_exit(SIGKILL);
6123 + }
6124 do_exit(SIGSEGV);
6125 }
6126
6127 diff -urNp linux-2.6.39.2/arch/sparc/kernel/traps_64.c linux-2.6.39.2/arch/sparc/kernel/traps_64.c
6128 --- linux-2.6.39.2/arch/sparc/kernel/traps_64.c 2011-05-19 00:06:34.000000000 -0400
6129 +++ linux-2.6.39.2/arch/sparc/kernel/traps_64.c 2011-06-13 21:28:54.000000000 -0400
6130 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_
6131 i + 1,
6132 p->trapstack[i].tstate, p->trapstack[i].tpc,
6133 p->trapstack[i].tnpc, p->trapstack[i].tt);
6134 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6135 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6136 }
6137 }
6138
6139 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long
6140
6141 lvl -= 0x100;
6142 if (regs->tstate & TSTATE_PRIV) {
6143 +
6144 +#ifdef CONFIG_PAX_REFCOUNT
6145 + if (lvl == 6)
6146 + pax_report_refcount_overflow(regs);
6147 +#endif
6148 +
6149 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6150 die_if_kernel(buffer, regs);
6151 }
6152 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long
6153 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6154 {
6155 char buffer[32];
6156 -
6157 +
6158 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6159 0, lvl, SIGTRAP) == NOTIFY_STOP)
6160 return;
6161
6162 +#ifdef CONFIG_PAX_REFCOUNT
6163 + if (lvl == 6)
6164 + pax_report_refcount_overflow(regs);
6165 +#endif
6166 +
6167 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6168
6169 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6170 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt
6171 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6172 printk("%s" "ERROR(%d): ",
6173 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6174 - printk("TPC<%pS>\n", (void *) regs->tpc);
6175 + printk("TPC<%pA>\n", (void *) regs->tpc);
6176 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6177 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6178 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6179 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type,
6180 smp_processor_id(),
6181 (type & 0x1) ? 'I' : 'D',
6182 regs->tpc);
6183 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6184 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6185 panic("Irrecoverable Cheetah+ parity error.");
6186 }
6187
6188 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type,
6189 smp_processor_id(),
6190 (type & 0x1) ? 'I' : 'D',
6191 regs->tpc);
6192 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6193 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6194 }
6195
6196 struct sun4v_error_entry {
6197 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_r
6198
6199 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6200 regs->tpc, tl);
6201 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6202 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6203 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6204 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6205 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6206 (void *) regs->u_regs[UREG_I7]);
6207 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6208 "pte[%lx] error[%lx]\n",
6209 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_r
6210
6211 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6212 regs->tpc, tl);
6213 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6214 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6215 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6216 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6217 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6218 (void *) regs->u_regs[UREG_I7]);
6219 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6220 "pte[%lx] error[%lx]\n",
6221 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk,
6222 fp = (unsigned long)sf->fp + STACK_BIAS;
6223 }
6224
6225 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6226 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6227 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6228 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6229 int index = tsk->curr_ret_stack;
6230 if (tsk->ret_stack && index >= graph) {
6231 pc = tsk->ret_stack[index - graph].ret;
6232 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6233 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6234 graph++;
6235 }
6236 }
6237 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_
6238 return (struct reg_window *) (fp + STACK_BIAS);
6239 }
6240
6241 +extern void gr_handle_kernel_exploit(void);
6242 +
6243 void die_if_kernel(char *str, struct pt_regs *regs)
6244 {
6245 static int die_counter;
6246 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_
6247 while (rw &&
6248 count++ < 30 &&
6249 kstack_valid(tp, (unsigned long) rw)) {
6250 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6251 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6252 (void *) rw->ins[7]);
6253
6254 rw = kernel_stack_up(rw);
6255 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_
6256 }
6257 user_instruction_dump ((unsigned int __user *) regs->tpc);
6258 }
6259 - if (regs->tstate & TSTATE_PRIV)
6260 + if (regs->tstate & TSTATE_PRIV) {
6261 + gr_handle_kernel_exploit();
6262 do_exit(SIGKILL);
6263 + }
6264 do_exit(SIGSEGV);
6265 }
6266 EXPORT_SYMBOL(die_if_kernel);
6267 diff -urNp linux-2.6.39.2/arch/sparc/kernel/unaligned_64.c linux-2.6.39.2/arch/sparc/kernel/unaligned_64.c
6268 --- linux-2.6.39.2/arch/sparc/kernel/unaligned_64.c 2011-05-19 00:06:34.000000000 -0400
6269 +++ linux-2.6.39.2/arch/sparc/kernel/unaligned_64.c 2011-05-22 19:41:32.000000000 -0400
6270 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs
6271 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6272
6273 if (__ratelimit(&ratelimit)) {
6274 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6275 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6276 regs->tpc, (void *) regs->tpc);
6277 }
6278 }
6279 diff -urNp linux-2.6.39.2/arch/sparc/lib/atomic_64.S linux-2.6.39.2/arch/sparc/lib/atomic_64.S
6280 --- linux-2.6.39.2/arch/sparc/lib/atomic_64.S 2011-05-19 00:06:34.000000000 -0400
6281 +++ linux-2.6.39.2/arch/sparc/lib/atomic_64.S 2011-05-22 19:36:30.000000000 -0400
6282 @@ -18,7 +18,12 @@
6283 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6284 BACKOFF_SETUP(%o2)
6285 1: lduw [%o1], %g1
6286 - add %g1, %o0, %g7
6287 + addcc %g1, %o0, %g7
6288 +
6289 +#ifdef CONFIG_PAX_REFCOUNT
6290 + tvs %icc, 6
6291 +#endif
6292 +
6293 cas [%o1], %g1, %g7
6294 cmp %g1, %g7
6295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6296 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = at
6297 2: BACKOFF_SPIN(%o2, %o3, 1b)
6298 .size atomic_add, .-atomic_add
6299
6300 + .globl atomic_add_unchecked
6301 + .type atomic_add_unchecked,#function
6302 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6303 + BACKOFF_SETUP(%o2)
6304 +1: lduw [%o1], %g1
6305 + add %g1, %o0, %g7
6306 + cas [%o1], %g1, %g7
6307 + cmp %g1, %g7
6308 + bne,pn %icc, 2f
6309 + nop
6310 + retl
6311 + nop
6312 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 + .size atomic_add_unchecked, .-atomic_add_unchecked
6314 +
6315 .globl atomic_sub
6316 .type atomic_sub,#function
6317 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6318 BACKOFF_SETUP(%o2)
6319 1: lduw [%o1], %g1
6320 - sub %g1, %o0, %g7
6321 + subcc %g1, %o0, %g7
6322 +
6323 +#ifdef CONFIG_PAX_REFCOUNT
6324 + tvs %icc, 6
6325 +#endif
6326 +
6327 cas [%o1], %g1, %g7
6328 cmp %g1, %g7
6329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6330 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = at
6331 2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 .size atomic_sub, .-atomic_sub
6333
6334 + .globl atomic_sub_unchecked
6335 + .type atomic_sub_unchecked,#function
6336 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6337 + BACKOFF_SETUP(%o2)
6338 +1: lduw [%o1], %g1
6339 + sub %g1, %o0, %g7
6340 + cas [%o1], %g1, %g7
6341 + cmp %g1, %g7
6342 + bne,pn %icc, 2f
6343 + nop
6344 + retl
6345 + nop
6346 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6347 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6348 +
6349 .globl atomic_add_ret
6350 .type atomic_add_ret,#function
6351 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6352 BACKOFF_SETUP(%o2)
6353 1: lduw [%o1], %g1
6354 - add %g1, %o0, %g7
6355 + addcc %g1, %o0, %g7
6356 +
6357 +#ifdef CONFIG_PAX_REFCOUNT
6358 + tvs %icc, 6
6359 +#endif
6360 +
6361 cas [%o1], %g1, %g7
6362 cmp %g1, %g7
6363 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6364 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1
6365 2: BACKOFF_SPIN(%o2, %o3, 1b)
6366 .size atomic_add_ret, .-atomic_add_ret
6367
6368 + .globl atomic_add_ret_unchecked
6369 + .type atomic_add_ret_unchecked,#function
6370 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6371 + BACKOFF_SETUP(%o2)
6372 +1: lduw [%o1], %g1
6373 + addcc %g1, %o0, %g7
6374 + cas [%o1], %g1, %g7
6375 + cmp %g1, %g7
6376 + bne,pn %icc, 2f
6377 + add %g7, %o0, %g7
6378 + sra %g7, 0, %o0
6379 + retl
6380 + nop
6381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6382 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6383 +
6384 .globl atomic_sub_ret
6385 .type atomic_sub_ret,#function
6386 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6387 BACKOFF_SETUP(%o2)
6388 1: lduw [%o1], %g1
6389 - sub %g1, %o0, %g7
6390 + subcc %g1, %o0, %g7
6391 +
6392 +#ifdef CONFIG_PAX_REFCOUNT
6393 + tvs %icc, 6
6394 +#endif
6395 +
6396 cas [%o1], %g1, %g7
6397 cmp %g1, %g7
6398 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6399 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1
6400 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - add %g1, %o0, %g7
6404 + addcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 =
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 .size atomic64_add, .-atomic64_add
6416
6417 + .globl atomic64_add_unchecked
6418 + .type atomic64_add_unchecked,#function
6419 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6420 + BACKOFF_SETUP(%o2)
6421 +1: ldx [%o1], %g1
6422 + addcc %g1, %o0, %g7
6423 + casx [%o1], %g1, %g7
6424 + cmp %g1, %g7
6425 + bne,pn %xcc, 2f
6426 + nop
6427 + retl
6428 + nop
6429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6430 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6431 +
6432 .globl atomic64_sub
6433 .type atomic64_sub,#function
6434 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6435 BACKOFF_SETUP(%o2)
6436 1: ldx [%o1], %g1
6437 - sub %g1, %o0, %g7
6438 + subcc %g1, %o0, %g7
6439 +
6440 +#ifdef CONFIG_PAX_REFCOUNT
6441 + tvs %xcc, 6
6442 +#endif
6443 +
6444 casx [%o1], %g1, %g7
6445 cmp %g1, %g7
6446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6447 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 =
6448 2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 .size atomic64_sub, .-atomic64_sub
6450
6451 + .globl atomic64_sub_unchecked
6452 + .type atomic64_sub_unchecked,#function
6453 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6454 + BACKOFF_SETUP(%o2)
6455 +1: ldx [%o1], %g1
6456 + subcc %g1, %o0, %g7
6457 + casx [%o1], %g1, %g7
6458 + cmp %g1, %g7
6459 + bne,pn %xcc, 2f
6460 + nop
6461 + retl
6462 + nop
6463 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6464 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6465 +
6466 .globl atomic64_add_ret
6467 .type atomic64_add_ret,#function
6468 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6469 BACKOFF_SETUP(%o2)
6470 1: ldx [%o1], %g1
6471 - add %g1, %o0, %g7
6472 + addcc %g1, %o0, %g7
6473 +
6474 +#ifdef CONFIG_PAX_REFCOUNT
6475 + tvs %xcc, 6
6476 +#endif
6477 +
6478 casx [%o1], %g1, %g7
6479 cmp %g1, %g7
6480 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6481 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o
6482 2: BACKOFF_SPIN(%o2, %o3, 1b)
6483 .size atomic64_add_ret, .-atomic64_add_ret
6484
6485 + .globl atomic64_add_ret_unchecked
6486 + .type atomic64_add_ret_unchecked,#function
6487 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6488 + BACKOFF_SETUP(%o2)
6489 +1: ldx [%o1], %g1
6490 + addcc %g1, %o0, %g7
6491 + casx [%o1], %g1, %g7
6492 + cmp %g1, %g7
6493 + bne,pn %xcc, 2f
6494 + add %g7, %o0, %g7
6495 + mov %g7, %o0
6496 + retl
6497 + nop
6498 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6499 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6500 +
6501 .globl atomic64_sub_ret
6502 .type atomic64_sub_ret,#function
6503 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6504 BACKOFF_SETUP(%o2)
6505 1: ldx [%o1], %g1
6506 - sub %g1, %o0, %g7
6507 + subcc %g1, %o0, %g7
6508 +
6509 +#ifdef CONFIG_PAX_REFCOUNT
6510 + tvs %xcc, 6
6511 +#endif
6512 +
6513 casx [%o1], %g1, %g7
6514 cmp %g1, %g7
6515 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6516 diff -urNp linux-2.6.39.2/arch/sparc/lib/ksyms.c linux-2.6.39.2/arch/sparc/lib/ksyms.c
6517 --- linux-2.6.39.2/arch/sparc/lib/ksyms.c 2011-05-19 00:06:34.000000000 -0400
6518 +++ linux-2.6.39.2/arch/sparc/lib/ksyms.c 2011-05-22 19:36:30.000000000 -0400
6519 @@ -142,12 +142,17 @@ EXPORT_SYMBOL(__downgrade_write);
6520
6521 /* Atomic counter implementation. */
6522 EXPORT_SYMBOL(atomic_add);
6523 +EXPORT_SYMBOL(atomic_add_unchecked);
6524 EXPORT_SYMBOL(atomic_add_ret);
6525 EXPORT_SYMBOL(atomic_sub);
6526 +EXPORT_SYMBOL(atomic_sub_unchecked);
6527 EXPORT_SYMBOL(atomic_sub_ret);
6528 EXPORT_SYMBOL(atomic64_add);
6529 +EXPORT_SYMBOL(atomic64_add_unchecked);
6530 EXPORT_SYMBOL(atomic64_add_ret);
6531 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6532 EXPORT_SYMBOL(atomic64_sub);
6533 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6534 EXPORT_SYMBOL(atomic64_sub_ret);
6535
6536 /* Atomic bit operations. */
6537 diff -urNp linux-2.6.39.2/arch/sparc/lib/Makefile linux-2.6.39.2/arch/sparc/lib/Makefile
6538 --- linux-2.6.39.2/arch/sparc/lib/Makefile 2011-05-19 00:06:34.000000000 -0400
6539 +++ linux-2.6.39.2/arch/sparc/lib/Makefile 2011-05-22 19:36:30.000000000 -0400
6540 @@ -2,7 +2,7 @@
6541 #
6542
6543 asflags-y := -ansi -DST_DIV0=0x02
6544 -ccflags-y := -Werror
6545 +#ccflags-y := -Werror
6546
6547 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6548 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6549 diff -urNp linux-2.6.39.2/arch/sparc/Makefile linux-2.6.39.2/arch/sparc/Makefile
6550 --- linux-2.6.39.2/arch/sparc/Makefile 2011-05-19 00:06:34.000000000 -0400
6551 +++ linux-2.6.39.2/arch/sparc/Makefile 2011-05-22 19:41:32.000000000 -0400
6552 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
6553 # Export what is needed by arch/sparc/boot/Makefile
6554 export VMLINUX_INIT VMLINUX_MAIN
6555 VMLINUX_INIT := $(head-y) $(init-y)
6556 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
6557 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
6558 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
6559 VMLINUX_MAIN += $(drivers-y) $(net-y)
6560
6561 diff -urNp linux-2.6.39.2/arch/sparc/mm/fault_32.c linux-2.6.39.2/arch/sparc/mm/fault_32.c
6562 --- linux-2.6.39.2/arch/sparc/mm/fault_32.c 2011-05-19 00:06:34.000000000 -0400
6563 +++ linux-2.6.39.2/arch/sparc/mm/fault_32.c 2011-05-22 19:36:30.000000000 -0400
6564 @@ -22,6 +22,9 @@
6565 #include <linux/interrupt.h>
6566 #include <linux/module.h>
6567 #include <linux/kdebug.h>
6568 +#include <linux/slab.h>
6569 +#include <linux/pagemap.h>
6570 +#include <linux/compiler.h>
6571
6572 #include <asm/system.h>
6573 #include <asm/page.h>
6574 @@ -209,6 +212,268 @@ static unsigned long compute_si_addr(str
6575 return safe_compute_effective_address(regs, insn);
6576 }
6577
6578 +#ifdef CONFIG_PAX_PAGEEXEC
6579 +#ifdef CONFIG_PAX_DLRESOLVE
6580 +static void pax_emuplt_close(struct vm_area_struct *vma)
6581 +{
6582 + vma->vm_mm->call_dl_resolve = 0UL;
6583 +}
6584 +
6585 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6586 +{
6587 + unsigned int *kaddr;
6588 +
6589 + vmf->page = alloc_page(GFP_HIGHUSER);
6590 + if (!vmf->page)
6591 + return VM_FAULT_OOM;
6592 +
6593 + kaddr = kmap(vmf->page);
6594 + memset(kaddr, 0, PAGE_SIZE);
6595 + kaddr[0] = 0x9DE3BFA8U; /* save */
6596 + flush_dcache_page(vmf->page);
6597 + kunmap(vmf->page);
6598 + return VM_FAULT_MAJOR;
6599 +}
6600 +
6601 +static const struct vm_operations_struct pax_vm_ops = {
6602 + .close = pax_emuplt_close,
6603 + .fault = pax_emuplt_fault
6604 +};
6605 +
6606 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6607 +{
6608 + int ret;
6609 +
6610 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6611 + vma->vm_mm = current->mm;
6612 + vma->vm_start = addr;
6613 + vma->vm_end = addr + PAGE_SIZE;
6614 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6615 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6616 + vma->vm_ops = &pax_vm_ops;
6617 +
6618 + ret = insert_vm_struct(current->mm, vma);
6619 + if (ret)
6620 + return ret;
6621 +
6622 + ++current->mm->total_vm;
6623 + return 0;
6624 +}
6625 +#endif
6626 +
6627 +/*
6628 + * PaX: decide what to do with offenders (regs->pc = fault address)
6629 + *
6630 + * returns 1 when task should be killed
6631 + * 2 when patched PLT trampoline was detected
6632 + * 3 when unpatched PLT trampoline was detected
6633 + */
6634 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6635 +{
6636 +
6637 +#ifdef CONFIG_PAX_EMUPLT
6638 + int err;
6639 +
6640 + do { /* PaX: patched PLT emulation #1 */
6641 + unsigned int sethi1, sethi2, jmpl;
6642 +
6643 + err = get_user(sethi1, (unsigned int *)regs->pc);
6644 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6645 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6646 +
6647 + if (err)
6648 + break;
6649 +
6650 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6651 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6652 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6653 + {
6654 + unsigned int addr;
6655 +
6656 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6657 + addr = regs->u_regs[UREG_G1];
6658 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6659 + regs->pc = addr;
6660 + regs->npc = addr+4;
6661 + return 2;
6662 + }
6663 + } while (0);
6664 +
6665 + { /* PaX: patched PLT emulation #2 */
6666 + unsigned int ba;
6667 +
6668 + err = get_user(ba, (unsigned int *)regs->pc);
6669 +
6670 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6671 + unsigned int addr;
6672 +
6673 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6674 + regs->pc = addr;
6675 + regs->npc = addr+4;
6676 + return 2;
6677 + }
6678 + }
6679 +
6680 + do { /* PaX: patched PLT emulation #3 */
6681 + unsigned int sethi, jmpl, nop;
6682 +
6683 + err = get_user(sethi, (unsigned int *)regs->pc);
6684 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6685 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6686 +
6687 + if (err)
6688 + break;
6689 +
6690 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6691 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6692 + nop == 0x01000000U)
6693 + {
6694 + unsigned int addr;
6695 +
6696 + addr = (sethi & 0x003FFFFFU) << 10;
6697 + regs->u_regs[UREG_G1] = addr;
6698 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6699 + regs->pc = addr;
6700 + regs->npc = addr+4;
6701 + return 2;
6702 + }
6703 + } while (0);
6704 +
6705 + do { /* PaX: unpatched PLT emulation step 1 */
6706 + unsigned int sethi, ba, nop;
6707 +
6708 + err = get_user(sethi, (unsigned int *)regs->pc);
6709 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6710 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6711 +
6712 + if (err)
6713 + break;
6714 +
6715 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6716 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6717 + nop == 0x01000000U)
6718 + {
6719 + unsigned int addr, save, call;
6720 +
6721 + if ((ba & 0xFFC00000U) == 0x30800000U)
6722 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6723 + else
6724 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6725 +
6726 + err = get_user(save, (unsigned int *)addr);
6727 + err |= get_user(call, (unsigned int *)(addr+4));
6728 + err |= get_user(nop, (unsigned int *)(addr+8));
6729 + if (err)
6730 + break;
6731 +
6732 +#ifdef CONFIG_PAX_DLRESOLVE
6733 + if (save == 0x9DE3BFA8U &&
6734 + (call & 0xC0000000U) == 0x40000000U &&
6735 + nop == 0x01000000U)
6736 + {
6737 + struct vm_area_struct *vma;
6738 + unsigned long call_dl_resolve;
6739 +
6740 + down_read(&current->mm->mmap_sem);
6741 + call_dl_resolve = current->mm->call_dl_resolve;
6742 + up_read(&current->mm->mmap_sem);
6743 + if (likely(call_dl_resolve))
6744 + goto emulate;
6745 +
6746 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6747 +
6748 + down_write(&current->mm->mmap_sem);
6749 + if (current->mm->call_dl_resolve) {
6750 + call_dl_resolve = current->mm->call_dl_resolve;
6751 + up_write(&current->mm->mmap_sem);
6752 + if (vma)
6753 + kmem_cache_free(vm_area_cachep, vma);
6754 + goto emulate;
6755 + }
6756 +
6757 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6758 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6759 + up_write(&current->mm->mmap_sem);
6760 + if (vma)
6761 + kmem_cache_free(vm_area_cachep, vma);
6762 + return 1;
6763 + }
6764 +
6765 + if (pax_insert_vma(vma, call_dl_resolve)) {
6766 + up_write(&current->mm->mmap_sem);
6767 + kmem_cache_free(vm_area_cachep, vma);
6768 + return 1;
6769 + }
6770 +
6771 + current->mm->call_dl_resolve = call_dl_resolve;
6772 + up_write(&current->mm->mmap_sem);
6773 +
6774 +emulate:
6775 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6776 + regs->pc = call_dl_resolve;
6777 + regs->npc = addr+4;
6778 + return 3;
6779 + }
6780 +#endif
6781 +
6782 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6783 + if ((save & 0xFFC00000U) == 0x05000000U &&
6784 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6785 + nop == 0x01000000U)
6786 + {
6787 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6788 + regs->u_regs[UREG_G2] = addr + 4;
6789 + addr = (save & 0x003FFFFFU) << 10;
6790 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6791 + regs->pc = addr;
6792 + regs->npc = addr+4;
6793 + return 3;
6794 + }
6795 + }
6796 + } while (0);
6797 +
6798 + do { /* PaX: unpatched PLT emulation step 2 */
6799 + unsigned int save, call, nop;
6800 +
6801 + err = get_user(save, (unsigned int *)(regs->pc-4));
6802 + err |= get_user(call, (unsigned int *)regs->pc);
6803 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6804 + if (err)
6805 + break;
6806 +
6807 + if (save == 0x9DE3BFA8U &&
6808 + (call & 0xC0000000U) == 0x40000000U &&
6809 + nop == 0x01000000U)
6810 + {
6811 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6812 +
6813 + regs->u_regs[UREG_RETPC] = regs->pc;
6814 + regs->pc = dl_resolve;
6815 + regs->npc = dl_resolve+4;
6816 + return 3;
6817 + }
6818 + } while (0);
6819 +#endif
6820 +
6821 + return 1;
6822 +}
6823 +
6824 +void pax_report_insns(void *pc, void *sp)
6825 +{
6826 + unsigned long i;
6827 +
6828 + printk(KERN_ERR "PAX: bytes at PC: ");
6829 + for (i = 0; i < 8; i++) {
6830 + unsigned int c;
6831 + if (get_user(c, (unsigned int *)pc+i))
6832 + printk(KERN_CONT "???????? ");
6833 + else
6834 + printk(KERN_CONT "%08x ", c);
6835 + }
6836 + printk("\n");
6837 +}
6838 +#endif
6839 +
6840 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6841 int text_fault)
6842 {
6843 @@ -281,6 +546,24 @@ good_area:
6844 if(!(vma->vm_flags & VM_WRITE))
6845 goto bad_area;
6846 } else {
6847 +
6848 +#ifdef CONFIG_PAX_PAGEEXEC
6849 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6850 + up_read(&mm->mmap_sem);
6851 + switch (pax_handle_fetch_fault(regs)) {
6852 +
6853 +#ifdef CONFIG_PAX_EMUPLT
6854 + case 2:
6855 + case 3:
6856 + return;
6857 +#endif
6858 +
6859 + }
6860 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6861 + do_group_exit(SIGKILL);
6862 + }
6863 +#endif
6864 +
6865 /* Allow reads even for write-only mappings */
6866 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6867 goto bad_area;
6868 diff -urNp linux-2.6.39.2/arch/sparc/mm/fault_64.c linux-2.6.39.2/arch/sparc/mm/fault_64.c
6869 --- linux-2.6.39.2/arch/sparc/mm/fault_64.c 2011-05-19 00:06:34.000000000 -0400
6870 +++ linux-2.6.39.2/arch/sparc/mm/fault_64.c 2011-05-22 19:41:32.000000000 -0400
6871 @@ -21,6 +21,9 @@
6872 #include <linux/kprobes.h>
6873 #include <linux/kdebug.h>
6874 #include <linux/percpu.h>
6875 +#include <linux/slab.h>
6876 +#include <linux/pagemap.h>
6877 +#include <linux/compiler.h>
6878
6879 #include <asm/page.h>
6880 #include <asm/pgtable.h>
6881 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(stru
6882 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6883 regs->tpc);
6884 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6885 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6886 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6887 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6888 dump_stack();
6889 unhandled_fault(regs->tpc, current, regs);
6890 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32b
6891 show_regs(regs);
6892 }
6893
6894 +#ifdef CONFIG_PAX_PAGEEXEC
6895 +#ifdef CONFIG_PAX_DLRESOLVE
6896 +static void pax_emuplt_close(struct vm_area_struct *vma)
6897 +{
6898 + vma->vm_mm->call_dl_resolve = 0UL;
6899 +}
6900 +
6901 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6902 +{
6903 + unsigned int *kaddr;
6904 +
6905 + vmf->page = alloc_page(GFP_HIGHUSER);
6906 + if (!vmf->page)
6907 + return VM_FAULT_OOM;
6908 +
6909 + kaddr = kmap(vmf->page);
6910 + memset(kaddr, 0, PAGE_SIZE);
6911 + kaddr[0] = 0x9DE3BFA8U; /* save */
6912 + flush_dcache_page(vmf->page);
6913 + kunmap(vmf->page);
6914 + return VM_FAULT_MAJOR;
6915 +}
6916 +
6917 +static const struct vm_operations_struct pax_vm_ops = {
6918 + .close = pax_emuplt_close,
6919 + .fault = pax_emuplt_fault
6920 +};
6921 +
6922 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6923 +{
6924 + int ret;
6925 +
6926 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6927 + vma->vm_mm = current->mm;
6928 + vma->vm_start = addr;
6929 + vma->vm_end = addr + PAGE_SIZE;
6930 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6931 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6932 + vma->vm_ops = &pax_vm_ops;
6933 +
6934 + ret = insert_vm_struct(current->mm, vma);
6935 + if (ret)
6936 + return ret;
6937 +
6938 + ++current->mm->total_vm;
6939 + return 0;
6940 +}
6941 +#endif
6942 +
6943 +/*
6944 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6945 + *
6946 + * returns 1 when task should be killed
6947 + * 2 when patched PLT trampoline was detected
6948 + * 3 when unpatched PLT trampoline was detected
6949 + */
6950 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6951 +{
6952 +
6953 +#ifdef CONFIG_PAX_EMUPLT
6954 + int err;
6955 +
6956 + do { /* PaX: patched PLT emulation #1 */
6957 + unsigned int sethi1, sethi2, jmpl;
6958 +
6959 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6960 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6961 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6962 +
6963 + if (err)
6964 + break;
6965 +
6966 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6967 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6968 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6969 + {
6970 + unsigned long addr;
6971 +
6972 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6973 + addr = regs->u_regs[UREG_G1];
6974 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6975 +
6976 + if (test_thread_flag(TIF_32BIT))
6977 + addr &= 0xFFFFFFFFUL;
6978 +
6979 + regs->tpc = addr;
6980 + regs->tnpc = addr+4;
6981 + return 2;
6982 + }
6983 + } while (0);
6984 +
6985 + { /* PaX: patched PLT emulation #2 */
6986 + unsigned int ba;
6987 +
6988 + err = get_user(ba, (unsigned int *)regs->tpc);
6989 +
6990 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6991 + unsigned long addr;
6992 +
6993 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6994 +
6995 + if (test_thread_flag(TIF_32BIT))
6996 + addr &= 0xFFFFFFFFUL;
6997 +
6998 + regs->tpc = addr;
6999 + regs->tnpc = addr+4;
7000 + return 2;
7001 + }
7002 + }
7003 +
7004 + do { /* PaX: patched PLT emulation #3 */
7005 + unsigned int sethi, jmpl, nop;
7006 +
7007 + err = get_user(sethi, (unsigned int *)regs->tpc);
7008 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
7009 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7010 +
7011 + if (err)
7012 + break;
7013 +
7014 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7015 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
7016 + nop == 0x01000000U)
7017 + {
7018 + unsigned long addr;
7019 +
7020 + addr = (sethi & 0x003FFFFFU) << 10;
7021 + regs->u_regs[UREG_G1] = addr;
7022 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7023 +
7024 + if (test_thread_flag(TIF_32BIT))
7025 + addr &= 0xFFFFFFFFUL;
7026 +
7027 + regs->tpc = addr;
7028 + regs->tnpc = addr+4;
7029 + return 2;
7030 + }
7031 + } while (0);
7032 +
7033 + do { /* PaX: patched PLT emulation #4 */
7034 + unsigned int sethi, mov1, call, mov2;
7035 +
7036 + err = get_user(sethi, (unsigned int *)regs->tpc);
7037 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7038 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7039 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7040 +
7041 + if (err)
7042 + break;
7043 +
7044 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7045 + mov1 == 0x8210000FU &&
7046 + (call & 0xC0000000U) == 0x40000000U &&
7047 + mov2 == 0x9E100001U)
7048 + {
7049 + unsigned long addr;
7050 +
7051 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7052 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7053 +
7054 + if (test_thread_flag(TIF_32BIT))
7055 + addr &= 0xFFFFFFFFUL;
7056 +
7057 + regs->tpc = addr;
7058 + regs->tnpc = addr+4;
7059 + return 2;
7060 + }
7061 + } while (0);
7062 +
7063 + do { /* PaX: patched PLT emulation #5 */
7064 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7065 +
7066 + err = get_user(sethi, (unsigned int *)regs->tpc);
7067 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7068 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7069 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7070 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7071 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7072 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7073 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7074 +
7075 + if (err)
7076 + break;
7077 +
7078 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7079 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7080 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7081 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7082 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7083 + sllx == 0x83287020U &&
7084 + jmpl == 0x81C04005U &&
7085 + nop == 0x01000000U)
7086 + {
7087 + unsigned long addr;
7088 +
7089 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7090 + regs->u_regs[UREG_G1] <<= 32;
7091 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7092 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7093 + regs->tpc = addr;
7094 + regs->tnpc = addr+4;
7095 + return 2;
7096 + }
7097 + } while (0);
7098 +
7099 + do { /* PaX: patched PLT emulation #6 */
7100 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7101 +
7102 + err = get_user(sethi, (unsigned int *)regs->tpc);
7103 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7104 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7105 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7106 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7107 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7108 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7109 +
7110 + if (err)
7111 + break;
7112 +
7113 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7114 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7115 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7116 + sllx == 0x83287020U &&
7117 + (or & 0xFFFFE000U) == 0x8A116000U &&
7118 + jmpl == 0x81C04005U &&
7119 + nop == 0x01000000U)
7120 + {
7121 + unsigned long addr;
7122 +
7123 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7124 + regs->u_regs[UREG_G1] <<= 32;
7125 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7126 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7127 + regs->tpc = addr;
7128 + regs->tnpc = addr+4;
7129 + return 2;
7130 + }
7131 + } while (0);
7132 +
7133 + do { /* PaX: unpatched PLT emulation step 1 */
7134 + unsigned int sethi, ba, nop;
7135 +
7136 + err = get_user(sethi, (unsigned int *)regs->tpc);
7137 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7138 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7139 +
7140 + if (err)
7141 + break;
7142 +
7143 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7144 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7145 + nop == 0x01000000U)
7146 + {
7147 + unsigned long addr;
7148 + unsigned int save, call;
7149 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7150 +
7151 + if ((ba & 0xFFC00000U) == 0x30800000U)
7152 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7153 + else
7154 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7155 +
7156 + if (test_thread_flag(TIF_32BIT))
7157 + addr &= 0xFFFFFFFFUL;
7158 +
7159 + err = get_user(save, (unsigned int *)addr);
7160 + err |= get_user(call, (unsigned int *)(addr+4));
7161 + err |= get_user(nop, (unsigned int *)(addr+8));
7162 + if (err)
7163 + break;
7164 +
7165 +#ifdef CONFIG_PAX_DLRESOLVE
7166 + if (save == 0x9DE3BFA8U &&
7167 + (call & 0xC0000000U) == 0x40000000U &&
7168 + nop == 0x01000000U)
7169 + {
7170 + struct vm_area_struct *vma;
7171 + unsigned long call_dl_resolve;
7172 +
7173 + down_read(&current->mm->mmap_sem);
7174 + call_dl_resolve = current->mm->call_dl_resolve;
7175 + up_read(&current->mm->mmap_sem);
7176 + if (likely(call_dl_resolve))
7177 + goto emulate;
7178 +
7179 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7180 +
7181 + down_write(&current->mm->mmap_sem);
7182 + if (current->mm->call_dl_resolve) {
7183 + call_dl_resolve = current->mm->call_dl_resolve;
7184 + up_write(&current->mm->mmap_sem);
7185 + if (vma)
7186 + kmem_cache_free(vm_area_cachep, vma);
7187 + goto emulate;
7188 + }
7189 +
7190 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7191 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7192 + up_write(&current->mm->mmap_sem);
7193 + if (vma)
7194 + kmem_cache_free(vm_area_cachep, vma);
7195 + return 1;
7196 + }
7197 +
7198 + if (pax_insert_vma(vma, call_dl_resolve)) {
7199 + up_write(&current->mm->mmap_sem);
7200 + kmem_cache_free(vm_area_cachep, vma);
7201 + return 1;
7202 + }
7203 +
7204 + current->mm->call_dl_resolve = call_dl_resolve;
7205 + up_write(&current->mm->mmap_sem);
7206 +
7207 +emulate:
7208 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7209 + regs->tpc = call_dl_resolve;
7210 + regs->tnpc = addr+4;
7211 + return 3;
7212 + }
7213 +#endif
7214 +
7215 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7216 + if ((save & 0xFFC00000U) == 0x05000000U &&
7217 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7218 + nop == 0x01000000U)
7219 + {
7220 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7221 + regs->u_regs[UREG_G2] = addr + 4;
7222 + addr = (save & 0x003FFFFFU) << 10;
7223 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7224 +
7225 + if (test_thread_flag(TIF_32BIT))
7226 + addr &= 0xFFFFFFFFUL;
7227 +
7228 + regs->tpc = addr;
7229 + regs->tnpc = addr+4;
7230 + return 3;
7231 + }
7232 +
7233 + /* PaX: 64-bit PLT stub */
7234 + err = get_user(sethi1, (unsigned int *)addr);
7235 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7236 + err |= get_user(or1, (unsigned int *)(addr+8));
7237 + err |= get_user(or2, (unsigned int *)(addr+12));
7238 + err |= get_user(sllx, (unsigned int *)(addr+16));
7239 + err |= get_user(add, (unsigned int *)(addr+20));
7240 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7241 + err |= get_user(nop, (unsigned int *)(addr+28));
7242 + if (err)
7243 + break;
7244 +
7245 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7246 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7247 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7248 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7249 + sllx == 0x89293020U &&
7250 + add == 0x8A010005U &&
7251 + jmpl == 0x89C14000U &&
7252 + nop == 0x01000000U)
7253 + {
7254 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7255 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7256 + regs->u_regs[UREG_G4] <<= 32;
7257 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7258 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7259 + regs->u_regs[UREG_G4] = addr + 24;
7260 + addr = regs->u_regs[UREG_G5];
7261 + regs->tpc = addr;
7262 + regs->tnpc = addr+4;
7263 + return 3;
7264 + }
7265 + }
7266 + } while (0);
7267 +
7268 +#ifdef CONFIG_PAX_DLRESOLVE
7269 + do { /* PaX: unpatched PLT emulation step 2 */
7270 + unsigned int save, call, nop;
7271 +
7272 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7273 + err |= get_user(call, (unsigned int *)regs->tpc);
7274 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7275 + if (err)
7276 + break;
7277 +
7278 + if (save == 0x9DE3BFA8U &&
7279 + (call & 0xC0000000U) == 0x40000000U &&
7280 + nop == 0x01000000U)
7281 + {
7282 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7283 +
7284 + if (test_thread_flag(TIF_32BIT))
7285 + dl_resolve &= 0xFFFFFFFFUL;
7286 +
7287 + regs->u_regs[UREG_RETPC] = regs->tpc;
7288 + regs->tpc = dl_resolve;
7289 + regs->tnpc = dl_resolve+4;
7290 + return 3;
7291 + }
7292 + } while (0);
7293 +#endif
7294 +
7295 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7296 + unsigned int sethi, ba, nop;
7297 +
7298 + err = get_user(sethi, (unsigned int *)regs->tpc);
7299 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7300 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7301 +
7302 + if (err)
7303 + break;
7304 +
7305 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7306 + (ba & 0xFFF00000U) == 0x30600000U &&
7307 + nop == 0x01000000U)
7308 + {
7309 + unsigned long addr;
7310 +
7311 + addr = (sethi & 0x003FFFFFU) << 10;
7312 + regs->u_regs[UREG_G1] = addr;
7313 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7314 +
7315 + if (test_thread_flag(TIF_32BIT))
7316 + addr &= 0xFFFFFFFFUL;
7317 +
7318 + regs->tpc = addr;
7319 + regs->tnpc = addr+4;
7320 + return 2;
7321 + }
7322 + } while (0);
7323 +
7324 +#endif
7325 +
7326 + return 1;
7327 +}
7328 +
7329 +void pax_report_insns(void *pc, void *sp)
7330 +{
7331 + unsigned long i;
7332 +
7333 + printk(KERN_ERR "PAX: bytes at PC: ");
7334 + for (i = 0; i < 8; i++) {
7335 + unsigned int c;
7336 + if (get_user(c, (unsigned int *)pc+i))
7337 + printk(KERN_CONT "???????? ");
7338 + else
7339 + printk(KERN_CONT "%08x ", c);
7340 + }
7341 + printk("\n");
7342 +}
7343 +#endif
7344 +
7345 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7346 {
7347 struct mm_struct *mm = current->mm;
7348 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fau
7349 if (!vma)
7350 goto bad_area;
7351
7352 +#ifdef CONFIG_PAX_PAGEEXEC
7353 + /* PaX: detect ITLB misses on non-exec pages */
7354 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7355 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7356 + {
7357 + if (address != regs->tpc)
7358 + goto good_area;
7359 +
7360 + up_read(&mm->mmap_sem);
7361 + switch (pax_handle_fetch_fault(regs)) {
7362 +
7363 +#ifdef CONFIG_PAX_EMUPLT
7364 + case 2:
7365 + case 3:
7366 + return;
7367 +#endif
7368 +
7369 + }
7370 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7371 + do_group_exit(SIGKILL);
7372 + }
7373 +#endif
7374 +
7375 /* Pure DTLB misses do not tell us whether the fault causing
7376 * load/store/atomic was a write or not, it only says that there
7377 * was no match. So in such a case we (carefully) read the
7378 diff -urNp linux-2.6.39.2/arch/sparc/mm/hugetlbpage.c linux-2.6.39.2/arch/sparc/mm/hugetlbpage.c
7379 --- linux-2.6.39.2/arch/sparc/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
7380 +++ linux-2.6.39.2/arch/sparc/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
7381 @@ -68,7 +68,7 @@ full_search:
7382 }
7383 return -ENOMEM;
7384 }
7385 - if (likely(!vma || addr + len <= vma->vm_start)) {
7386 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7387 /*
7388 * Remember the place where we stopped the search:
7389 */
7390 @@ -107,7 +107,7 @@ hugetlb_get_unmapped_area_topdown(struct
7391 /* make sure it can fit in the remaining address space */
7392 if (likely(addr > len)) {
7393 vma = find_vma(mm, addr-len);
7394 - if (!vma || addr <= vma->vm_start) {
7395 + if (check_heap_stack_gap(vma, addr - len, len)) {
7396 /* remember the address as a hint for next time */
7397 return (mm->free_area_cache = addr-len);
7398 }
7399 @@ -116,16 +116,17 @@ hugetlb_get_unmapped_area_topdown(struct
7400 if (unlikely(mm->mmap_base < len))
7401 goto bottomup;
7402
7403 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7404 + addr = mm->mmap_base - len;
7405
7406 do {
7407 + addr &= HPAGE_MASK;
7408 /*
7409 * Lookup failure means no vma is above this address,
7410 * else if new region fits below vma->vm_start,
7411 * return with success:
7412 */
7413 vma = find_vma(mm, addr);
7414 - if (likely(!vma || addr+len <= vma->vm_start)) {
7415 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7416 /* remember the address as a hint for next time */
7417 return (mm->free_area_cache = addr);
7418 }
7419 @@ -135,8 +136,8 @@ hugetlb_get_unmapped_area_topdown(struct
7420 mm->cached_hole_size = vma->vm_start - addr;
7421
7422 /* try just below the current vma->vm_start */
7423 - addr = (vma->vm_start-len) & HPAGE_MASK;
7424 - } while (likely(len < vma->vm_start));
7425 + addr = skip_heap_stack_gap(vma, len);
7426 + } while (!IS_ERR_VALUE(addr));
7427
7428 bottomup:
7429 /*
7430 @@ -182,8 +183,7 @@ hugetlb_get_unmapped_area(struct file *f
7431 if (addr) {
7432 addr = ALIGN(addr, HPAGE_SIZE);
7433 vma = find_vma(mm, addr);
7434 - if (task_size - len >= addr &&
7435 - (!vma || addr + len <= vma->vm_start))
7436 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7437 return addr;
7438 }
7439 if (mm->get_unmapped_area == arch_get_unmapped_area)
7440 diff -urNp linux-2.6.39.2/arch/sparc/mm/init_32.c linux-2.6.39.2/arch/sparc/mm/init_32.c
7441 --- linux-2.6.39.2/arch/sparc/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
7442 +++ linux-2.6.39.2/arch/sparc/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
7443 @@ -318,6 +318,9 @@ extern void device_scan(void);
7444 pgprot_t PAGE_SHARED __read_mostly;
7445 EXPORT_SYMBOL(PAGE_SHARED);
7446
7447 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7448 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7449 +
7450 void __init paging_init(void)
7451 {
7452 switch(sparc_cpu_model) {
7453 @@ -346,17 +349,17 @@ void __init paging_init(void)
7454
7455 /* Initialize the protection map with non-constant, MMU dependent values. */
7456 protection_map[0] = PAGE_NONE;
7457 - protection_map[1] = PAGE_READONLY;
7458 - protection_map[2] = PAGE_COPY;
7459 - protection_map[3] = PAGE_COPY;
7460 + protection_map[1] = PAGE_READONLY_NOEXEC;
7461 + protection_map[2] = PAGE_COPY_NOEXEC;
7462 + protection_map[3] = PAGE_COPY_NOEXEC;
7463 protection_map[4] = PAGE_READONLY;
7464 protection_map[5] = PAGE_READONLY;
7465 protection_map[6] = PAGE_COPY;
7466 protection_map[7] = PAGE_COPY;
7467 protection_map[8] = PAGE_NONE;
7468 - protection_map[9] = PAGE_READONLY;
7469 - protection_map[10] = PAGE_SHARED;
7470 - protection_map[11] = PAGE_SHARED;
7471 + protection_map[9] = PAGE_READONLY_NOEXEC;
7472 + protection_map[10] = PAGE_SHARED_NOEXEC;
7473 + protection_map[11] = PAGE_SHARED_NOEXEC;
7474 protection_map[12] = PAGE_READONLY;
7475 protection_map[13] = PAGE_READONLY;
7476 protection_map[14] = PAGE_SHARED;
7477 diff -urNp linux-2.6.39.2/arch/sparc/mm/Makefile linux-2.6.39.2/arch/sparc/mm/Makefile
7478 --- linux-2.6.39.2/arch/sparc/mm/Makefile 2011-05-19 00:06:34.000000000 -0400
7479 +++ linux-2.6.39.2/arch/sparc/mm/Makefile 2011-05-22 19:36:30.000000000 -0400
7480 @@ -2,7 +2,7 @@
7481 #
7482
7483 asflags-y := -ansi
7484 -ccflags-y := -Werror
7485 +#ccflags-y := -Werror
7486
7487 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
7488 obj-y += fault_$(BITS).o
7489 diff -urNp linux-2.6.39.2/arch/sparc/mm/srmmu.c linux-2.6.39.2/arch/sparc/mm/srmmu.c
7490 --- linux-2.6.39.2/arch/sparc/mm/srmmu.c 2011-05-19 00:06:34.000000000 -0400
7491 +++ linux-2.6.39.2/arch/sparc/mm/srmmu.c 2011-05-22 19:36:30.000000000 -0400
7492 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7493 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7494 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7495 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7496 +
7497 +#ifdef CONFIG_PAX_PAGEEXEC
7498 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7499 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7500 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7501 +#endif
7502 +
7503 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7504 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7505
7506 diff -urNp linux-2.6.39.2/arch/tile/kernel/pci.c linux-2.6.39.2/arch/tile/kernel/pci.c
7507 --- linux-2.6.39.2/arch/tile/kernel/pci.c 2011-06-25 12:55:22.000000000 -0400
7508 +++ linux-2.6.39.2/arch/tile/kernel/pci.c 2011-06-25 13:00:25.000000000 -0400
7509 @@ -60,7 +60,7 @@ int __write_once tile_plx_gen1;
7510 static struct pci_controller controllers[TILE_NUM_PCIE];
7511 static int num_controllers;
7512
7513 -static struct pci_ops tile_cfg_ops;
7514 +static const struct pci_ops tile_cfg_ops;
7515
7516
7517 /*
7518 @@ -563,7 +563,7 @@ static int __devinit tile_cfg_write(stru
7519 }
7520
7521
7522 -static struct pci_ops tile_cfg_ops = {
7523 +static const struct pci_ops tile_cfg_ops = {
7524 .read = tile_cfg_read,
7525 .write = tile_cfg_write,
7526 };
7527 diff -urNp linux-2.6.39.2/arch/um/include/asm/kmap_types.h linux-2.6.39.2/arch/um/include/asm/kmap_types.h
7528 --- linux-2.6.39.2/arch/um/include/asm/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
7529 +++ linux-2.6.39.2/arch/um/include/asm/kmap_types.h 2011-05-22 19:36:30.000000000 -0400
7530 @@ -23,6 +23,7 @@ enum km_type {
7531 KM_IRQ1,
7532 KM_SOFTIRQ0,
7533 KM_SOFTIRQ1,
7534 + KM_CLEARPAGE,
7535 KM_TYPE_NR
7536 };
7537
7538 diff -urNp linux-2.6.39.2/arch/um/include/asm/page.h linux-2.6.39.2/arch/um/include/asm/page.h
7539 --- linux-2.6.39.2/arch/um/include/asm/page.h 2011-05-19 00:06:34.000000000 -0400
7540 +++ linux-2.6.39.2/arch/um/include/asm/page.h 2011-05-22 19:36:30.000000000 -0400
7541 @@ -14,6 +14,9 @@
7542 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7543 #define PAGE_MASK (~(PAGE_SIZE-1))
7544
7545 +#define ktla_ktva(addr) (addr)
7546 +#define ktva_ktla(addr) (addr)
7547 +
7548 #ifndef __ASSEMBLY__
7549
7550 struct page;
7551 diff -urNp linux-2.6.39.2/arch/um/kernel/process.c linux-2.6.39.2/arch/um/kernel/process.c
7552 --- linux-2.6.39.2/arch/um/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
7553 +++ linux-2.6.39.2/arch/um/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
7554 @@ -404,22 +404,6 @@ int singlestepping(void * t)
7555 return 2;
7556 }
7557
7558 -/*
7559 - * Only x86 and x86_64 have an arch_align_stack().
7560 - * All other arches have "#define arch_align_stack(x) (x)"
7561 - * in their asm/system.h
7562 - * As this is included in UML from asm-um/system-generic.h,
7563 - * we can use it to behave as the subarch does.
7564 - */
7565 -#ifndef arch_align_stack
7566 -unsigned long arch_align_stack(unsigned long sp)
7567 -{
7568 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7569 - sp -= get_random_int() % 8192;
7570 - return sp & ~0xf;
7571 -}
7572 -#endif
7573 -
7574 unsigned long get_wchan(struct task_struct *p)
7575 {
7576 unsigned long stack_page, sp, ip;
7577 diff -urNp linux-2.6.39.2/arch/um/sys-i386/syscalls.c linux-2.6.39.2/arch/um/sys-i386/syscalls.c
7578 --- linux-2.6.39.2/arch/um/sys-i386/syscalls.c 2011-05-19 00:06:34.000000000 -0400
7579 +++ linux-2.6.39.2/arch/um/sys-i386/syscalls.c 2011-05-22 19:36:30.000000000 -0400
7580 @@ -11,6 +11,21 @@
7581 #include "asm/uaccess.h"
7582 #include "asm/unistd.h"
7583
7584 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
7585 +{
7586 + unsigned long pax_task_size = TASK_SIZE;
7587 +
7588 +#ifdef CONFIG_PAX_SEGMEXEC
7589 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
7590 + pax_task_size = SEGMEXEC_TASK_SIZE;
7591 +#endif
7592 +
7593 + if (len > pax_task_size || addr > pax_task_size - len)
7594 + return -EINVAL;
7595 +
7596 + return 0;
7597 +}
7598 +
7599 /*
7600 * The prototype on i386 is:
7601 *
7602 diff -urNp linux-2.6.39.2/arch/unicore32/kernel/pci.c linux-2.6.39.2/arch/unicore32/kernel/pci.c
7603 --- linux-2.6.39.2/arch/unicore32/kernel/pci.c 2011-05-19 00:06:34.000000000 -0400
7604 +++ linux-2.6.39.2/arch/unicore32/kernel/pci.c 2011-05-22 19:36:30.000000000 -0400
7605 @@ -66,7 +66,7 @@ puv3_write_config(struct pci_bus *bus, u
7606 return PCIBIOS_SUCCESSFUL;
7607 }
7608
7609 -struct pci_ops pci_puv3_ops = {
7610 +const struct pci_ops pci_puv3_ops = {
7611 .read = puv3_read_config,
7612 .write = puv3_write_config,
7613 };
7614 diff -urNp linux-2.6.39.2/arch/x86/boot/bitops.h linux-2.6.39.2/arch/x86/boot/bitops.h
7615 --- linux-2.6.39.2/arch/x86/boot/bitops.h 2011-05-19 00:06:34.000000000 -0400
7616 +++ linux-2.6.39.2/arch/x86/boot/bitops.h 2011-05-22 19:36:30.000000000 -0400
7617 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int
7618 u8 v;
7619 const u32 *p = (const u32 *)addr;
7620
7621 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7622 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7623 return v;
7624 }
7625
7626 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int
7627
7628 static inline void set_bit(int nr, void *addr)
7629 {
7630 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7631 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7632 }
7633
7634 #endif /* BOOT_BITOPS_H */
7635 diff -urNp linux-2.6.39.2/arch/x86/boot/boot.h linux-2.6.39.2/arch/x86/boot/boot.h
7636 --- linux-2.6.39.2/arch/x86/boot/boot.h 2011-05-19 00:06:34.000000000 -0400
7637 +++ linux-2.6.39.2/arch/x86/boot/boot.h 2011-05-22 19:36:30.000000000 -0400
7638 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7639 static inline u16 ds(void)
7640 {
7641 u16 seg;
7642 - asm("movw %%ds,%0" : "=rm" (seg));
7643 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7644 return seg;
7645 }
7646
7647 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t
7648 static inline int memcmp(const void *s1, const void *s2, size_t len)
7649 {
7650 u8 diff;
7651 - asm("repe; cmpsb; setnz %0"
7652 + asm volatile("repe; cmpsb; setnz %0"
7653 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7654 return diff;
7655 }
7656 diff -urNp linux-2.6.39.2/arch/x86/boot/compressed/head_32.S linux-2.6.39.2/arch/x86/boot/compressed/head_32.S
7657 --- linux-2.6.39.2/arch/x86/boot/compressed/head_32.S 2011-05-19 00:06:34.000000000 -0400
7658 +++ linux-2.6.39.2/arch/x86/boot/compressed/head_32.S 2011-05-22 19:36:30.000000000 -0400
7659 @@ -76,7 +76,7 @@ ENTRY(startup_32)
7660 notl %eax
7661 andl %eax, %ebx
7662 #else
7663 - movl $LOAD_PHYSICAL_ADDR, %ebx
7664 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7665 #endif
7666
7667 /* Target address to relocate to for decompression */
7668 @@ -162,7 +162,7 @@ relocated:
7669 * and where it was actually loaded.
7670 */
7671 movl %ebp, %ebx
7672 - subl $LOAD_PHYSICAL_ADDR, %ebx
7673 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7674 jz 2f /* Nothing to be done if loaded at compiled addr. */
7675 /*
7676 * Process relocations.
7677 @@ -170,8 +170,7 @@ relocated:
7678
7679 1: subl $4, %edi
7680 movl (%edi), %ecx
7681 - testl %ecx, %ecx
7682 - jz 2f
7683 + jecxz 2f
7684 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7685 jmp 1b
7686 2:
7687 diff -urNp linux-2.6.39.2/arch/x86/boot/compressed/head_64.S linux-2.6.39.2/arch/x86/boot/compressed/head_64.S
7688 --- linux-2.6.39.2/arch/x86/boot/compressed/head_64.S 2011-05-19 00:06:34.000000000 -0400
7689 +++ linux-2.6.39.2/arch/x86/boot/compressed/head_64.S 2011-05-22 19:36:30.000000000 -0400
7690 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7691 notl %eax
7692 andl %eax, %ebx
7693 #else
7694 - movl $LOAD_PHYSICAL_ADDR, %ebx
7695 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7696 #endif
7697
7698 /* Target address to relocate to for decompression */
7699 @@ -233,7 +233,7 @@ ENTRY(startup_64)
7700 notq %rax
7701 andq %rax, %rbp
7702 #else
7703 - movq $LOAD_PHYSICAL_ADDR, %rbp
7704 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7705 #endif
7706
7707 /* Target address to relocate to for decompression */
7708 diff -urNp linux-2.6.39.2/arch/x86/boot/compressed/misc.c linux-2.6.39.2/arch/x86/boot/compressed/misc.c
7709 --- linux-2.6.39.2/arch/x86/boot/compressed/misc.c 2011-05-19 00:06:34.000000000 -0400
7710 +++ linux-2.6.39.2/arch/x86/boot/compressed/misc.c 2011-05-22 19:36:30.000000000 -0400
7711 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7712 case PT_LOAD:
7713 #ifdef CONFIG_RELOCATABLE
7714 dest = output;
7715 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7716 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7717 #else
7718 dest = (void *)(phdr->p_paddr);
7719 #endif
7720 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *
7721 error("Destination address too large");
7722 #endif
7723 #ifndef CONFIG_RELOCATABLE
7724 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7725 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7726 error("Wrong destination address");
7727 #endif
7728
7729 diff -urNp linux-2.6.39.2/arch/x86/boot/compressed/relocs.c linux-2.6.39.2/arch/x86/boot/compressed/relocs.c
7730 --- linux-2.6.39.2/arch/x86/boot/compressed/relocs.c 2011-05-19 00:06:34.000000000 -0400
7731 +++ linux-2.6.39.2/arch/x86/boot/compressed/relocs.c 2011-05-22 19:36:30.000000000 -0400
7732 @@ -13,8 +13,11 @@
7733
7734 static void die(char *fmt, ...);
7735
7736 +#include "../../../../include/generated/autoconf.h"
7737 +
7738 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7739 static Elf32_Ehdr ehdr;
7740 +static Elf32_Phdr *phdr;
7741 static unsigned long reloc_count, reloc_idx;
7742 static unsigned long *relocs;
7743
7744 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7745 }
7746 }
7747
7748 +static void read_phdrs(FILE *fp)
7749 +{
7750 + unsigned int i;
7751 +
7752 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7753 + if (!phdr) {
7754 + die("Unable to allocate %d program headers\n",
7755 + ehdr.e_phnum);
7756 + }
7757 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7758 + die("Seek to %d failed: %s\n",
7759 + ehdr.e_phoff, strerror(errno));
7760 + }
7761 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7762 + die("Cannot read ELF program headers: %s\n",
7763 + strerror(errno));
7764 + }
7765 + for(i = 0; i < ehdr.e_phnum; i++) {
7766 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7767 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7768 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7769 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7770 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7771 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7772 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7773 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7774 + }
7775 +
7776 +}
7777 +
7778 static void read_shdrs(FILE *fp)
7779 {
7780 - int i;
7781 + unsigned int i;
7782 Elf32_Shdr shdr;
7783
7784 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7785 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7786
7787 static void read_strtabs(FILE *fp)
7788 {
7789 - int i;
7790 + unsigned int i;
7791 for (i = 0; i < ehdr.e_shnum; i++) {
7792 struct section *sec = &secs[i];
7793 if (sec->shdr.sh_type != SHT_STRTAB) {
7794 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7795
7796 static void read_symtabs(FILE *fp)
7797 {
7798 - int i,j;
7799 + unsigned int i,j;
7800 for (i = 0; i < ehdr.e_shnum; i++) {
7801 struct section *sec = &secs[i];
7802 if (sec->shdr.sh_type != SHT_SYMTAB) {
7803 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7804
7805 static void read_relocs(FILE *fp)
7806 {
7807 - int i,j;
7808 + unsigned int i,j;
7809 + uint32_t base;
7810 +
7811 for (i = 0; i < ehdr.e_shnum; i++) {
7812 struct section *sec = &secs[i];
7813 if (sec->shdr.sh_type != SHT_REL) {
7814 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7815 die("Cannot read symbol table: %s\n",
7816 strerror(errno));
7817 }
7818 + base = 0;
7819 + for (j = 0; j < ehdr.e_phnum; j++) {
7820 + if (phdr[j].p_type != PT_LOAD )
7821 + continue;
7822 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
7823 + continue;
7824 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7825 + break;
7826 + }
7827 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7828 Elf32_Rel *rel = &sec->reltab[j];
7829 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7830 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7831 rel->r_info = elf32_to_cpu(rel->r_info);
7832 }
7833 }
7834 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
7835
7836 static void print_absolute_symbols(void)
7837 {
7838 - int i;
7839 + unsigned int i;
7840 printf("Absolute symbols\n");
7841 printf(" Num: Value Size Type Bind Visibility Name\n");
7842 for (i = 0; i < ehdr.e_shnum; i++) {
7843 struct section *sec = &secs[i];
7844 char *sym_strtab;
7845 Elf32_Sym *sh_symtab;
7846 - int j;
7847 + unsigned int j;
7848
7849 if (sec->shdr.sh_type != SHT_SYMTAB) {
7850 continue;
7851 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
7852
7853 static void print_absolute_relocs(void)
7854 {
7855 - int i, printed = 0;
7856 + unsigned int i, printed = 0;
7857
7858 for (i = 0; i < ehdr.e_shnum; i++) {
7859 struct section *sec = &secs[i];
7860 struct section *sec_applies, *sec_symtab;
7861 char *sym_strtab;
7862 Elf32_Sym *sh_symtab;
7863 - int j;
7864 + unsigned int j;
7865 if (sec->shdr.sh_type != SHT_REL) {
7866 continue;
7867 }
7868 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
7869
7870 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7871 {
7872 - int i;
7873 + unsigned int i;
7874 /* Walk through the relocations */
7875 for (i = 0; i < ehdr.e_shnum; i++) {
7876 char *sym_strtab;
7877 Elf32_Sym *sh_symtab;
7878 struct section *sec_applies, *sec_symtab;
7879 - int j;
7880 + unsigned int j;
7881 struct section *sec = &secs[i];
7882
7883 if (sec->shdr.sh_type != SHT_REL) {
7884 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(El
7885 !is_rel_reloc(sym_name(sym_strtab, sym))) {
7886 continue;
7887 }
7888 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7889 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7890 + continue;
7891 +
7892 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7893 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7894 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7895 + continue;
7896 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7897 + continue;
7898 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7899 + continue;
7900 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7901 + continue;
7902 +#endif
7903 +
7904 switch (r_type) {
7905 case R_386_NONE:
7906 case R_386_PC32:
7907 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, co
7908
7909 static void emit_relocs(int as_text)
7910 {
7911 - int i;
7912 + unsigned int i;
7913 /* Count how many relocations I have and allocate space for them. */
7914 reloc_count = 0;
7915 walk_relocs(count_reloc);
7916 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
7917 fname, strerror(errno));
7918 }
7919 read_ehdr(fp);
7920 + read_phdrs(fp);
7921 read_shdrs(fp);
7922 read_strtabs(fp);
7923 read_symtabs(fp);
7924 diff -urNp linux-2.6.39.2/arch/x86/boot/cpucheck.c linux-2.6.39.2/arch/x86/boot/cpucheck.c
7925 --- linux-2.6.39.2/arch/x86/boot/cpucheck.c 2011-05-19 00:06:34.000000000 -0400
7926 +++ linux-2.6.39.2/arch/x86/boot/cpucheck.c 2011-05-22 19:36:30.000000000 -0400
7927 @@ -74,7 +74,7 @@ static int has_fpu(void)
7928 u16 fcw = -1, fsw = -1;
7929 u32 cr0;
7930
7931 - asm("movl %%cr0,%0" : "=r" (cr0));
7932 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7933 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7934 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7935 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7936 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7937 {
7938 u32 f0, f1;
7939
7940 - asm("pushfl ; "
7941 + asm volatile("pushfl ; "
7942 "pushfl ; "
7943 "popl %0 ; "
7944 "movl %0,%1 ; "
7945 @@ -115,7 +115,7 @@ static void get_flags(void)
7946 set_bit(X86_FEATURE_FPU, cpu.flags);
7947
7948 if (has_eflag(X86_EFLAGS_ID)) {
7949 - asm("cpuid"
7950 + asm volatile("cpuid"
7951 : "=a" (max_intel_level),
7952 "=b" (cpu_vendor[0]),
7953 "=d" (cpu_vendor[1]),
7954 @@ -124,7 +124,7 @@ static void get_flags(void)
7955
7956 if (max_intel_level >= 0x00000001 &&
7957 max_intel_level <= 0x0000ffff) {
7958 - asm("cpuid"
7959 + asm volatile("cpuid"
7960 : "=a" (tfms),
7961 "=c" (cpu.flags[4]),
7962 "=d" (cpu.flags[0])
7963 @@ -136,7 +136,7 @@ static void get_flags(void)
7964 cpu.model += ((tfms >> 16) & 0xf) << 4;
7965 }
7966
7967 - asm("cpuid"
7968 + asm volatile("cpuid"
7969 : "=a" (max_amd_level)
7970 : "a" (0x80000000)
7971 : "ebx", "ecx", "edx");
7972 @@ -144,7 +144,7 @@ static void get_flags(void)
7973 if (max_amd_level >= 0x80000001 &&
7974 max_amd_level <= 0x8000ffff) {
7975 u32 eax = 0x80000001;
7976 - asm("cpuid"
7977 + asm volatile("cpuid"
7978 : "+a" (eax),
7979 "=c" (cpu.flags[6]),
7980 "=d" (cpu.flags[1])
7981 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7982 u32 ecx = MSR_K7_HWCR;
7983 u32 eax, edx;
7984
7985 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7986 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7987 eax &= ~(1 << 15);
7988 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7989 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7990
7991 get_flags(); /* Make sure it really did something */
7992 err = check_flags();
7993 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
7994 u32 ecx = MSR_VIA_FCR;
7995 u32 eax, edx;
7996
7997 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7998 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7999 eax |= (1<<1)|(1<<7);
8000 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8001 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8002
8003 set_bit(X86_FEATURE_CX8, cpu.flags);
8004 err = check_flags();
8005 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
8006 u32 eax, edx;
8007 u32 level = 1;
8008
8009 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8010 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8011 - asm("cpuid"
8012 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8013 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8014 + asm volatile("cpuid"
8015 : "+a" (level), "=d" (cpu.flags[0])
8016 : : "ecx", "ebx");
8017 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8018 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8019
8020 err = check_flags();
8021 }
8022 diff -urNp linux-2.6.39.2/arch/x86/boot/header.S linux-2.6.39.2/arch/x86/boot/header.S
8023 --- linux-2.6.39.2/arch/x86/boot/header.S 2011-05-19 00:06:34.000000000 -0400
8024 +++ linux-2.6.39.2/arch/x86/boot/header.S 2011-05-22 19:36:30.000000000 -0400
8025 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical
8026 # single linked list of
8027 # struct setup_data
8028
8029 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8030 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8031
8032 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8033 #define VO_INIT_SIZE (VO__end - VO__text)
8034 diff -urNp linux-2.6.39.2/arch/x86/boot/memory.c linux-2.6.39.2/arch/x86/boot/memory.c
8035 --- linux-2.6.39.2/arch/x86/boot/memory.c 2011-05-19 00:06:34.000000000 -0400
8036 +++ linux-2.6.39.2/arch/x86/boot/memory.c 2011-05-22 19:36:30.000000000 -0400
8037 @@ -19,7 +19,7 @@
8038
8039 static int detect_memory_e820(void)
8040 {
8041 - int count = 0;
8042 + unsigned int count = 0;
8043 struct biosregs ireg, oreg;
8044 struct e820entry *desc = boot_params.e820_map;
8045 static struct e820entry buf; /* static so it is zeroed */
8046 diff -urNp linux-2.6.39.2/arch/x86/boot/video.c linux-2.6.39.2/arch/x86/boot/video.c
8047 --- linux-2.6.39.2/arch/x86/boot/video.c 2011-05-19 00:06:34.000000000 -0400
8048 +++ linux-2.6.39.2/arch/x86/boot/video.c 2011-05-22 19:36:30.000000000 -0400
8049 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8050 static unsigned int get_entry(void)
8051 {
8052 char entry_buf[4];
8053 - int i, len = 0;
8054 + unsigned int i, len = 0;
8055 int key;
8056 unsigned int v;
8057
8058 diff -urNp linux-2.6.39.2/arch/x86/boot/video-vesa.c linux-2.6.39.2/arch/x86/boot/video-vesa.c
8059 --- linux-2.6.39.2/arch/x86/boot/video-vesa.c 2011-05-19 00:06:34.000000000 -0400
8060 +++ linux-2.6.39.2/arch/x86/boot/video-vesa.c 2011-05-22 19:36:30.000000000 -0400
8061 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8062
8063 boot_params.screen_info.vesapm_seg = oreg.es;
8064 boot_params.screen_info.vesapm_off = oreg.di;
8065 + boot_params.screen_info.vesapm_size = oreg.cx;
8066 }
8067
8068 /*
8069 diff -urNp linux-2.6.39.2/arch/x86/ia32/ia32_aout.c linux-2.6.39.2/arch/x86/ia32/ia32_aout.c
8070 --- linux-2.6.39.2/arch/x86/ia32/ia32_aout.c 2011-05-19 00:06:34.000000000 -0400
8071 +++ linux-2.6.39.2/arch/x86/ia32/ia32_aout.c 2011-05-22 19:41:32.000000000 -0400
8072 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, st
8073 unsigned long dump_start, dump_size;
8074 struct user32 dump;
8075
8076 + memset(&dump, 0, sizeof(dump));
8077 +
8078 fs = get_fs();
8079 set_fs(KERNEL_DS);
8080 has_dumped = 1;
8081 diff -urNp linux-2.6.39.2/arch/x86/ia32/ia32entry.S linux-2.6.39.2/arch/x86/ia32/ia32entry.S
8082 --- linux-2.6.39.2/arch/x86/ia32/ia32entry.S 2011-05-19 00:06:34.000000000 -0400
8083 +++ linux-2.6.39.2/arch/x86/ia32/ia32entry.S 2011-05-23 17:16:01.000000000 -0400
8084 @@ -13,6 +13,7 @@
8085 #include <asm/thread_info.h>
8086 #include <asm/segment.h>
8087 #include <asm/irqflags.h>
8088 +#include <asm/pgtable.h>
8089 #include <linux/linkage.h>
8090
8091 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8092 @@ -95,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8093 ENDPROC(native_irq_enable_sysexit)
8094 #endif
8095
8096 + .macro pax_enter_kernel_user
8097 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8098 + call pax_enter_kernel_user
8099 +#endif
8100 + .endm
8101 +
8102 + .macro pax_exit_kernel_user
8103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8104 + call pax_exit_kernel_user
8105 +#endif
8106 +#ifdef CONFIG_PAX_RANDKSTACK
8107 + pushq %rax
8108 + call pax_randomize_kstack
8109 + popq %rax
8110 +#endif
8111 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8112 + call pax_erase_kstack
8113 +#endif
8114 + .endm
8115 +
8116 + .macro pax_erase_kstack
8117 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8118 + call pax_erase_kstack
8119 +#endif
8120 + .endm
8121 +
8122 /*
8123 * 32bit SYSENTER instruction entry.
8124 *
8125 @@ -121,7 +148,7 @@ ENTRY(ia32_sysenter_target)
8126 CFI_REGISTER rsp,rbp
8127 SWAPGS_UNSAFE_STACK
8128 movq PER_CPU_VAR(kernel_stack), %rsp
8129 - addq $(KERNEL_STACK_OFFSET),%rsp
8130 + pax_enter_kernel_user
8131 /*
8132 * No need to follow this irqs on/off section: the syscall
8133 * disabled irqs, here we enable it straight after entry:
8134 @@ -134,7 +161,8 @@ ENTRY(ia32_sysenter_target)
8135 CFI_REL_OFFSET rsp,0
8136 pushfq_cfi
8137 /*CFI_REL_OFFSET rflags,0*/
8138 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
8139 + GET_THREAD_INFO(%r10)
8140 + movl TI_sysenter_return(%r10), %r10d
8141 CFI_REGISTER rip,r10
8142 pushq_cfi $__USER32_CS
8143 /*CFI_REL_OFFSET cs,0*/
8144 @@ -146,6 +174,12 @@ ENTRY(ia32_sysenter_target)
8145 SAVE_ARGS 0,0,1
8146 /* no need to do an access_ok check here because rbp has been
8147 32bit zero extended */
8148 +
8149 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8150 + mov $PAX_USER_SHADOW_BASE,%r10
8151 + add %r10,%rbp
8152 +#endif
8153 +
8154 1: movl (%rbp),%ebp
8155 .section __ex_table,"a"
8156 .quad 1b,ia32_badarg
8157 @@ -168,6 +202,7 @@ sysenter_dispatch:
8158 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8159 jnz sysexit_audit
8160 sysexit_from_sys_call:
8161 + pax_exit_kernel_user
8162 andl $~TS_COMPAT,TI_status(%r10)
8163 /* clear IF, that popfq doesn't enable interrupts early */
8164 andl $~0x200,EFLAGS-R11(%rsp)
8165 @@ -194,6 +229,9 @@ sysexit_from_sys_call:
8166 movl %eax,%esi /* 2nd arg: syscall number */
8167 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8168 call audit_syscall_entry
8169 +
8170 + pax_erase_kstack
8171 +
8172 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8173 cmpq $(IA32_NR_syscalls-1),%rax
8174 ja ia32_badsys
8175 @@ -246,6 +284,9 @@ sysenter_tracesys:
8176 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8177 movq %rsp,%rdi /* &pt_regs -> arg1 */
8178 call syscall_trace_enter
8179 +
8180 + pax_erase_kstack
8181 +
8182 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8183 RESTORE_REST
8184 cmpq $(IA32_NR_syscalls-1),%rax
8185 @@ -277,19 +318,24 @@ ENDPROC(ia32_sysenter_target)
8186 ENTRY(ia32_cstar_target)
8187 CFI_STARTPROC32 simple
8188 CFI_SIGNAL_FRAME
8189 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8190 + CFI_DEF_CFA rsp,0
8191 CFI_REGISTER rip,rcx
8192 /*CFI_REGISTER rflags,r11*/
8193 SWAPGS_UNSAFE_STACK
8194 movl %esp,%r8d
8195 CFI_REGISTER rsp,r8
8196 movq PER_CPU_VAR(kernel_stack),%rsp
8197 +
8198 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8199 + pax_enter_kernel_user
8200 +#endif
8201 +
8202 /*
8203 * No need to follow this irqs on/off section: the syscall
8204 * disabled irqs and here we enable it straight after entry:
8205 */
8206 ENABLE_INTERRUPTS(CLBR_NONE)
8207 - SAVE_ARGS 8,1,1
8208 + SAVE_ARGS 8*6,1,1
8209 movl %eax,%eax /* zero extension */
8210 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8211 movq %rcx,RIP-ARGOFFSET(%rsp)
8212 @@ -305,6 +351,12 @@ ENTRY(ia32_cstar_target)
8213 /* no need to do an access_ok check here because r8 has been
8214 32bit zero extended */
8215 /* hardware stack frame is complete now */
8216 +
8217 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8218 + mov $PAX_USER_SHADOW_BASE,%r10
8219 + add %r10,%r8
8220 +#endif
8221 +
8222 1: movl (%r8),%r9d
8223 .section __ex_table,"a"
8224 .quad 1b,ia32_badarg
8225 @@ -327,6 +379,7 @@ cstar_dispatch:
8226 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8227 jnz sysretl_audit
8228 sysretl_from_sys_call:
8229 + pax_exit_kernel_user
8230 andl $~TS_COMPAT,TI_status(%r10)
8231 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8232 movl RIP-ARGOFFSET(%rsp),%ecx
8233 @@ -364,6 +417,9 @@ cstar_tracesys:
8234 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8235 movq %rsp,%rdi /* &pt_regs -> arg1 */
8236 call syscall_trace_enter
8237 +
8238 + pax_erase_kstack
8239 +
8240 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8241 RESTORE_REST
8242 xchgl %ebp,%r9d
8243 @@ -409,6 +465,7 @@ ENTRY(ia32_syscall)
8244 CFI_REL_OFFSET rip,RIP-RIP
8245 PARAVIRT_ADJUST_EXCEPTION_FRAME
8246 SWAPGS
8247 + pax_enter_kernel_user
8248 /*
8249 * No need to follow this irqs on/off section: the syscall
8250 * disabled irqs and here we enable it straight after entry:
8251 @@ -441,6 +498,9 @@ ia32_tracesys:
8252 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8253 movq %rsp,%rdi /* &pt_regs -> arg1 */
8254 call syscall_trace_enter
8255 +
8256 + pax_erase_kstack
8257 +
8258 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8259 RESTORE_REST
8260 cmpq $(IA32_NR_syscalls-1),%rax
8261 diff -urNp linux-2.6.39.2/arch/x86/ia32/ia32_signal.c linux-2.6.39.2/arch/x86/ia32/ia32_signal.c
8262 --- linux-2.6.39.2/arch/x86/ia32/ia32_signal.c 2011-05-19 00:06:34.000000000 -0400
8263 +++ linux-2.6.39.2/arch/x86/ia32/ia32_signal.c 2011-05-22 19:36:30.000000000 -0400
8264 @@ -403,7 +403,7 @@ static void __user *get_sigframe(struct
8265 sp -= frame_size;
8266 /* Align the stack pointer according to the i386 ABI,
8267 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8268 - sp = ((sp + 4) & -16ul) - 4;
8269 + sp = ((sp - 12) & -16ul) - 4;
8270 return (void __user *) sp;
8271 }
8272
8273 @@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_s
8274 * These are actually not used anymore, but left because some
8275 * gdb versions depend on them as a marker.
8276 */
8277 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8278 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8279 } put_user_catch(err);
8280
8281 if (err)
8282 @@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct
8283 0xb8,
8284 __NR_ia32_rt_sigreturn,
8285 0x80cd,
8286 - 0,
8287 + 0
8288 };
8289
8290 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8291 @@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct
8292
8293 if (ka->sa.sa_flags & SA_RESTORER)
8294 restorer = ka->sa.sa_restorer;
8295 + else if (current->mm->context.vdso)
8296 + /* Return stub is in 32bit vsyscall page */
8297 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8298 else
8299 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8300 - rt_sigreturn);
8301 + restorer = &frame->retcode;
8302 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8303
8304 /*
8305 * Not actually used anymore, but left because some gdb
8306 * versions need it.
8307 */
8308 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8309 + put_user_ex(*((const u64 *)&code), (u64 *)frame->retcode);
8310 } put_user_catch(err);
8311
8312 if (err)
8313 diff -urNp linux-2.6.39.2/arch/x86/include/asm/alternative.h linux-2.6.39.2/arch/x86/include/asm/alternative.h
8314 --- linux-2.6.39.2/arch/x86/include/asm/alternative.h 2011-05-19 00:06:34.000000000 -0400
8315 +++ linux-2.6.39.2/arch/x86/include/asm/alternative.h 2011-05-22 19:36:30.000000000 -0400
8316 @@ -94,7 +94,7 @@ static inline int alternatives_text_rese
8317 ".section .discard,\"aw\",@progbits\n" \
8318 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8319 ".previous\n" \
8320 - ".section .altinstr_replacement, \"ax\"\n" \
8321 + ".section .altinstr_replacement, \"a\"\n" \
8322 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8323 ".previous"
8324
8325 diff -urNp linux-2.6.39.2/arch/x86/include/asm/apm.h linux-2.6.39.2/arch/x86/include/asm/apm.h
8326 --- linux-2.6.39.2/arch/x86/include/asm/apm.h 2011-05-19 00:06:34.000000000 -0400
8327 +++ linux-2.6.39.2/arch/x86/include/asm/apm.h 2011-05-22 19:36:30.000000000 -0400
8328 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
8329 __asm__ __volatile__(APM_DO_ZERO_SEGS
8330 "pushl %%edi\n\t"
8331 "pushl %%ebp\n\t"
8332 - "lcall *%%cs:apm_bios_entry\n\t"
8333 + "lcall *%%ss:apm_bios_entry\n\t"
8334 "setc %%al\n\t"
8335 "popl %%ebp\n\t"
8336 "popl %%edi\n\t"
8337 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
8338 __asm__ __volatile__(APM_DO_ZERO_SEGS
8339 "pushl %%edi\n\t"
8340 "pushl %%ebp\n\t"
8341 - "lcall *%%cs:apm_bios_entry\n\t"
8342 + "lcall *%%ss:apm_bios_entry\n\t"
8343 "setc %%bl\n\t"
8344 "popl %%ebp\n\t"
8345 "popl %%edi\n\t"
8346 diff -urNp linux-2.6.39.2/arch/x86/include/asm/atomic64_32.h linux-2.6.39.2/arch/x86/include/asm/atomic64_32.h
8347 --- linux-2.6.39.2/arch/x86/include/asm/atomic64_32.h 2011-05-19 00:06:34.000000000 -0400
8348 +++ linux-2.6.39.2/arch/x86/include/asm/atomic64_32.h 2011-05-22 19:36:30.000000000 -0400
8349 @@ -12,6 +12,14 @@ typedef struct {
8350 u64 __aligned(8) counter;
8351 } atomic64_t;
8352
8353 +#ifdef CONFIG_PAX_REFCOUNT
8354 +typedef struct {
8355 + u64 __aligned(8) counter;
8356 +} atomic64_unchecked_t;
8357 +#else
8358 +typedef atomic64_t atomic64_unchecked_t;
8359 +#endif
8360 +
8361 #define ATOMIC64_INIT(val) { (val) }
8362
8363 #ifdef CONFIG_X86_CMPXCHG64
8364 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg
8365 }
8366
8367 /**
8368 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
8369 + * @p: pointer to type atomic64_unchecked_t
8370 + * @o: expected value
8371 + * @n: new value
8372 + *
8373 + * Atomically sets @v to @n if it was equal to @o and returns
8374 + * the old value.
8375 + */
8376 +
8377 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
8378 +{
8379 + return cmpxchg64(&v->counter, o, n);
8380 +}
8381 +
8382 +/**
8383 * atomic64_xchg - xchg atomic64 variable
8384 * @v: pointer to type atomic64_t
8385 * @n: value to assign
8386 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64
8387 }
8388
8389 /**
8390 + * atomic64_set_unchecked - set atomic64 variable
8391 + * @v: pointer to type atomic64_unchecked_t
8392 + * @n: value to assign
8393 + *
8394 + * Atomically sets the value of @v to @n.
8395 + */
8396 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
8397 +{
8398 + unsigned high = (unsigned)(i >> 32);
8399 + unsigned low = (unsigned)i;
8400 + asm volatile(ATOMIC64_ALTERNATIVE(set)
8401 + : "+b" (low), "+c" (high)
8402 + : "S" (v)
8403 + : "eax", "edx", "memory"
8404 + );
8405 +}
8406 +
8407 +/**
8408 * atomic64_read - read atomic64 variable
8409 * @v: pointer to type atomic64_t
8410 *
8411 @@ -93,6 +134,22 @@ static inline long long atomic64_read(at
8412 }
8413
8414 /**
8415 + * atomic64_read_unchecked - read atomic64 variable
8416 + * @v: pointer to type atomic64_unchecked_t
8417 + *
8418 + * Atomically reads the value of @v and returns it.
8419 + */
8420 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
8421 +{
8422 + long long r;
8423 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
8424 + : "=A" (r), "+c" (v)
8425 + : : "memory"
8426 + );
8427 + return r;
8428 + }
8429 +
8430 +/**
8431 * atomic64_add_return - add and return
8432 * @i: integer value to add
8433 * @v: pointer to type atomic64_t
8434 @@ -108,6 +165,22 @@ static inline long long atomic64_add_ret
8435 return i;
8436 }
8437
8438 +/**
8439 + * atomic64_add_return_unchecked - add and return
8440 + * @i: integer value to add
8441 + * @v: pointer to type atomic64_unchecked_t
8442 + *
8443 + * Atomically adds @i to @v and returns @i + *@v
8444 + */
8445 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
8446 +{
8447 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
8448 + : "+A" (i), "+c" (v)
8449 + : : "memory"
8450 + );
8451 + return i;
8452 +}
8453 +
8454 /*
8455 * Other variants with different arithmetic operators:
8456 */
8457 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_ret
8458 return a;
8459 }
8460
8461 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8462 +{
8463 + long long a;
8464 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
8465 + : "=A" (a)
8466 + : "S" (v)
8467 + : "memory", "ecx"
8468 + );
8469 + return a;
8470 +}
8471 +
8472 static inline long long atomic64_dec_return(atomic64_t *v)
8473 {
8474 long long a;
8475 @@ -159,6 +243,22 @@ static inline long long atomic64_add(lon
8476 }
8477
8478 /**
8479 + * atomic64_add_unchecked - add integer to atomic64 variable
8480 + * @i: integer value to add
8481 + * @v: pointer to type atomic64_unchecked_t
8482 + *
8483 + * Atomically adds @i to @v.
8484 + */
8485 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8486 +{
8487 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8488 + : "+A" (i), "+c" (v)
8489 + : : "memory"
8490 + );
8491 + return i;
8492 +}
8493 +
8494 +/**
8495 * atomic64_sub - subtract the atomic64 variable
8496 * @i: integer value to subtract
8497 * @v: pointer to type atomic64_t
8498 diff -urNp linux-2.6.39.2/arch/x86/include/asm/atomic64_64.h linux-2.6.39.2/arch/x86/include/asm/atomic64_64.h
8499 --- linux-2.6.39.2/arch/x86/include/asm/atomic64_64.h 2011-05-19 00:06:34.000000000 -0400
8500 +++ linux-2.6.39.2/arch/x86/include/asm/atomic64_64.h 2011-05-22 19:36:30.000000000 -0400
8501 @@ -18,7 +18,19 @@
8502 */
8503 static inline long atomic64_read(const atomic64_t *v)
8504 {
8505 - return (*(volatile long *)&(v)->counter);
8506 + return (*(volatile const long *)&(v)->counter);
8507 +}
8508 +
8509 +/**
8510 + * atomic64_read_unchecked - read atomic64 variable
8511 + * @v: pointer of type atomic64_unchecked_t
8512 + *
8513 + * Atomically reads the value of @v.
8514 + * Doesn't imply a read memory barrier.
8515 + */
8516 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8517 +{
8518 + return (*(volatile const long *)&(v)->counter);
8519 }
8520
8521 /**
8522 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64
8523 }
8524
8525 /**
8526 + * atomic64_set_unchecked - set atomic64 variable
8527 + * @v: pointer to type atomic64_unchecked_t
8528 + * @i: required value
8529 + *
8530 + * Atomically sets the value of @v to @i.
8531 + */
8532 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8533 +{
8534 + v->counter = i;
8535 +}
8536 +
8537 +/**
8538 * atomic64_add - add integer to atomic64 variable
8539 * @i: integer value to add
8540 * @v: pointer to type atomic64_t
8541 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64
8542 */
8543 static inline void atomic64_add(long i, atomic64_t *v)
8544 {
8545 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
8546 +
8547 +#ifdef CONFIG_PAX_REFCOUNT
8548 + "jno 0f\n"
8549 + LOCK_PREFIX "subq %1,%0\n"
8550 + "int $4\n0:\n"
8551 + _ASM_EXTABLE(0b, 0b)
8552 +#endif
8553 +
8554 + : "=m" (v->counter)
8555 + : "er" (i), "m" (v->counter));
8556 +}
8557 +
8558 +/**
8559 + * atomic64_add_unchecked - add integer to atomic64 variable
8560 + * @i: integer value to add
8561 + * @v: pointer to type atomic64_unchecked_t
8562 + *
8563 + * Atomically adds @i to @v.
8564 + */
8565 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8566 +{
8567 asm volatile(LOCK_PREFIX "addq %1,%0"
8568 : "=m" (v->counter)
8569 : "er" (i), "m" (v->counter));
8570 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i,
8571 */
8572 static inline void atomic64_sub(long i, atomic64_t *v)
8573 {
8574 - asm volatile(LOCK_PREFIX "subq %1,%0"
8575 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8576 +
8577 +#ifdef CONFIG_PAX_REFCOUNT
8578 + "jno 0f\n"
8579 + LOCK_PREFIX "addq %1,%0\n"
8580 + "int $4\n0:\n"
8581 + _ASM_EXTABLE(0b, 0b)
8582 +#endif
8583 +
8584 + : "=m" (v->counter)
8585 + : "er" (i), "m" (v->counter));
8586 +}
8587 +
8588 +/**
8589 + * atomic64_sub_unchecked - subtract the atomic64 variable
8590 + * @i: integer value to subtract
8591 + * @v: pointer to type atomic64_unchecked_t
8592 + *
8593 + * Atomically subtracts @i from @v.
8594 + */
8595 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8596 +{
8597 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8598 : "=m" (v->counter)
8599 : "er" (i), "m" (v->counter));
8600 }
8601 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(
8602 {
8603 unsigned char c;
8604
8605 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8606 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8607 +
8608 +#ifdef CONFIG_PAX_REFCOUNT
8609 + "jno 0f\n"
8610 + LOCK_PREFIX "addq %2,%0\n"
8611 + "int $4\n0:\n"
8612 + _ASM_EXTABLE(0b, 0b)
8613 +#endif
8614 +
8615 + "sete %1\n"
8616 : "=m" (v->counter), "=qm" (c)
8617 : "er" (i), "m" (v->counter) : "memory");
8618 return c;
8619 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(
8620 */
8621 static inline void atomic64_inc(atomic64_t *v)
8622 {
8623 + asm volatile(LOCK_PREFIX "incq %0\n"
8624 +
8625 +#ifdef CONFIG_PAX_REFCOUNT
8626 + "jno 0f\n"
8627 + LOCK_PREFIX "decq %0\n"
8628 + "int $4\n0:\n"
8629 + _ASM_EXTABLE(0b, 0b)
8630 +#endif
8631 +
8632 + : "=m" (v->counter)
8633 + : "m" (v->counter));
8634 +}
8635 +
8636 +/**
8637 + * atomic64_inc_unchecked - increment atomic64 variable
8638 + * @v: pointer to type atomic64_unchecked_t
8639 + *
8640 + * Atomically increments @v by 1.
8641 + */
8642 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8643 +{
8644 asm volatile(LOCK_PREFIX "incq %0"
8645 : "=m" (v->counter)
8646 : "m" (v->counter));
8647 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64
8648 */
8649 static inline void atomic64_dec(atomic64_t *v)
8650 {
8651 - asm volatile(LOCK_PREFIX "decq %0"
8652 + asm volatile(LOCK_PREFIX "decq %0\n"
8653 +
8654 +#ifdef CONFIG_PAX_REFCOUNT
8655 + "jno 0f\n"
8656 + LOCK_PREFIX "incq %0\n"
8657 + "int $4\n0:\n"
8658 + _ASM_EXTABLE(0b, 0b)
8659 +#endif
8660 +
8661 + : "=m" (v->counter)
8662 + : "m" (v->counter));
8663 +}
8664 +
8665 +/**
8666 + * atomic64_dec_unchecked - decrement atomic64 variable
8667 + * @v: pointer to type atomic64_t
8668 + *
8669 + * Atomically decrements @v by 1.
8670 + */
8671 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8672 +{
8673 + asm volatile(LOCK_PREFIX "decq %0\n"
8674 : "=m" (v->counter)
8675 : "m" (v->counter));
8676 }
8677 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(
8678 {
8679 unsigned char c;
8680
8681 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8682 + asm volatile(LOCK_PREFIX "decq %0\n"
8683 +
8684 +#ifdef CONFIG_PAX_REFCOUNT
8685 + "jno 0f\n"
8686 + LOCK_PREFIX "incq %0\n"
8687 + "int $4\n0:\n"
8688 + _ASM_EXTABLE(0b, 0b)
8689 +#endif
8690 +
8691 + "sete %1\n"
8692 : "=m" (v->counter), "=qm" (c)
8693 : "m" (v->counter) : "memory");
8694 return c != 0;
8695 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(
8696 {
8697 unsigned char c;
8698
8699 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8700 + asm volatile(LOCK_PREFIX "incq %0\n"
8701 +
8702 +#ifdef CONFIG_PAX_REFCOUNT
8703 + "jno 0f\n"
8704 + LOCK_PREFIX "decq %0\n"
8705 + "int $4\n0:\n"
8706 + _ASM_EXTABLE(0b, 0b)
8707 +#endif
8708 +
8709 + "sete %1\n"
8710 : "=m" (v->counter), "=qm" (c)
8711 : "m" (v->counter) : "memory");
8712 return c != 0;
8713 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(
8714 {
8715 unsigned char c;
8716
8717 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8718 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8719 +
8720 +#ifdef CONFIG_PAX_REFCOUNT
8721 + "jno 0f\n"
8722 + LOCK_PREFIX "subq %2,%0\n"
8723 + "int $4\n0:\n"
8724 + _ASM_EXTABLE(0b, 0b)
8725 +#endif
8726 +
8727 + "sets %1\n"
8728 : "=m" (v->counter), "=qm" (c)
8729 : "er" (i), "m" (v->counter) : "memory");
8730 return c;
8731 @@ -171,7 +317,31 @@ static inline int atomic64_add_negative(
8732 static inline long atomic64_add_return(long i, atomic64_t *v)
8733 {
8734 long __i = i;
8735 - asm volatile(LOCK_PREFIX "xaddq %0, %1;"
8736 + asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
8737 +
8738 +#ifdef CONFIG_PAX_REFCOUNT
8739 + "jno 0f\n"
8740 + "movq %0, %1\n"
8741 + "int $4\n0:\n"
8742 + _ASM_EXTABLE(0b, 0b)
8743 +#endif
8744 +
8745 + : "+r" (i), "+m" (v->counter)
8746 + : : "memory");
8747 + return i + __i;
8748 +}
8749 +
8750 +/**
8751 + * atomic64_add_return_unchecked - add and return
8752 + * @i: integer value to add
8753 + * @v: pointer to type atomic64_unchecked_t
8754 + *
8755 + * Atomically adds @i to @v and returns @i + @v
8756 + */
8757 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8758 +{
8759 + long __i = i;
8760 + asm volatile(LOCK_PREFIX "xaddq %0, %1"
8761 : "+r" (i), "+m" (v->counter)
8762 : : "memory");
8763 return i + __i;
8764 @@ -183,6 +353,10 @@ static inline long atomic64_sub_return(l
8765 }
8766
8767 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8768 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8769 +{
8770 + return atomic64_add_return_unchecked(1, v);
8771 +}
8772 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8773
8774 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8775 @@ -190,6 +364,11 @@ static inline long atomic64_cmpxchg(atom
8776 return cmpxchg(&v->counter, old, new);
8777 }
8778
8779 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8780 +{
8781 + return cmpxchg(&v->counter, old, new);
8782 +}
8783 +
8784 static inline long atomic64_xchg(atomic64_t *v, long new)
8785 {
8786 return xchg(&v->counter, new);
8787 @@ -206,17 +385,30 @@ static inline long atomic64_xchg(atomic6
8788 */
8789 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8790 {
8791 - long c, old;
8792 + long c, old, new;
8793 c = atomic64_read(v);
8794 for (;;) {
8795 - if (unlikely(c == (u)))
8796 + if (unlikely(c == u))
8797 break;
8798 - old = atomic64_cmpxchg((v), c, c + (a));
8799 +
8800 + asm volatile("add %2,%0\n"
8801 +
8802 +#ifdef CONFIG_PAX_REFCOUNT
8803 + "jno 0f\n"
8804 + "sub %2,%0\n"
8805 + "int $4\n0:\n"
8806 + _ASM_EXTABLE(0b, 0b)
8807 +#endif
8808 +
8809 + : "=r" (new)
8810 + : "0" (c), "ir" (a));
8811 +
8812 + old = atomic64_cmpxchg(v, c, new);
8813 if (likely(old == c))
8814 break;
8815 c = old;
8816 }
8817 - return c != (u);
8818 + return c != u;
8819 }
8820
8821 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8822 diff -urNp linux-2.6.39.2/arch/x86/include/asm/atomic.h linux-2.6.39.2/arch/x86/include/asm/atomic.h
8823 --- linux-2.6.39.2/arch/x86/include/asm/atomic.h 2011-05-19 00:06:34.000000000 -0400
8824 +++ linux-2.6.39.2/arch/x86/include/asm/atomic.h 2011-05-22 19:36:30.000000000 -0400
8825 @@ -22,7 +22,18 @@
8826 */
8827 static inline int atomic_read(const atomic_t *v)
8828 {
8829 - return (*(volatile int *)&(v)->counter);
8830 + return (*(volatile const int *)&(v)->counter);
8831 +}
8832 +
8833 +/**
8834 + * atomic_read_unchecked - read atomic variable
8835 + * @v: pointer of type atomic_unchecked_t
8836 + *
8837 + * Atomically reads the value of @v.
8838 + */
8839 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8840 +{
8841 + return (*(volatile const int *)&(v)->counter);
8842 }
8843
8844 /**
8845 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *
8846 }
8847
8848 /**
8849 + * atomic_set_unchecked - set atomic variable
8850 + * @v: pointer of type atomic_unchecked_t
8851 + * @i: required value
8852 + *
8853 + * Atomically sets the value of @v to @i.
8854 + */
8855 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8856 +{
8857 + v->counter = i;
8858 +}
8859 +
8860 +/**
8861 * atomic_add - add integer to atomic variable
8862 * @i: integer value to add
8863 * @v: pointer of type atomic_t
8864 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *
8865 */
8866 static inline void atomic_add(int i, atomic_t *v)
8867 {
8868 - asm volatile(LOCK_PREFIX "addl %1,%0"
8869 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8870 +
8871 +#ifdef CONFIG_PAX_REFCOUNT
8872 + "jno 0f\n"
8873 + LOCK_PREFIX "subl %1,%0\n"
8874 + "int $4\n0:\n"
8875 + _ASM_EXTABLE(0b, 0b)
8876 +#endif
8877 +
8878 + : "+m" (v->counter)
8879 + : "ir" (i));
8880 +}
8881 +
8882 +/**
8883 + * atomic_add_unchecked - add integer to atomic variable
8884 + * @i: integer value to add
8885 + * @v: pointer of type atomic_unchecked_t
8886 + *
8887 + * Atomically adds @i to @v.
8888 + */
8889 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8890 +{
8891 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
8892 : "+m" (v->counter)
8893 : "ir" (i));
8894 }
8895 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, ato
8896 */
8897 static inline void atomic_sub(int i, atomic_t *v)
8898 {
8899 - asm volatile(LOCK_PREFIX "subl %1,%0"
8900 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8901 +
8902 +#ifdef CONFIG_PAX_REFCOUNT
8903 + "jno 0f\n"
8904 + LOCK_PREFIX "addl %1,%0\n"
8905 + "int $4\n0:\n"
8906 + _ASM_EXTABLE(0b, 0b)
8907 +#endif
8908 +
8909 + : "+m" (v->counter)
8910 + : "ir" (i));
8911 +}
8912 +
8913 +/**
8914 + * atomic_sub_unchecked - subtract integer from atomic variable
8915 + * @i: integer value to subtract
8916 + * @v: pointer of type atomic_unchecked_t
8917 + *
8918 + * Atomically subtracts @i from @v.
8919 + */
8920 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8921 +{
8922 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
8923 : "+m" (v->counter)
8924 : "ir" (i));
8925 }
8926 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(in
8927 {
8928 unsigned char c;
8929
8930 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8931 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
8932 +
8933 +#ifdef CONFIG_PAX_REFCOUNT
8934 + "jno 0f\n"
8935 + LOCK_PREFIX "addl %2,%0\n"
8936 + "int $4\n0:\n"
8937 + _ASM_EXTABLE(0b, 0b)
8938 +#endif
8939 +
8940 + "sete %1\n"
8941 : "+m" (v->counter), "=qm" (c)
8942 : "ir" (i) : "memory");
8943 return c;
8944 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(in
8945 */
8946 static inline void atomic_inc(atomic_t *v)
8947 {
8948 - asm volatile(LOCK_PREFIX "incl %0"
8949 + asm volatile(LOCK_PREFIX "incl %0\n"
8950 +
8951 +#ifdef CONFIG_PAX_REFCOUNT
8952 + "jno 0f\n"
8953 + LOCK_PREFIX "decl %0\n"
8954 + "int $4\n0:\n"
8955 + _ASM_EXTABLE(0b, 0b)
8956 +#endif
8957 +
8958 + : "+m" (v->counter));
8959 +}
8960 +
8961 +/**
8962 + * atomic_inc_unchecked - increment atomic variable
8963 + * @v: pointer of type atomic_unchecked_t
8964 + *
8965 + * Atomically increments @v by 1.
8966 + */
8967 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8968 +{
8969 + asm volatile(LOCK_PREFIX "incl %0\n"
8970 : "+m" (v->counter));
8971 }
8972
8973 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *
8974 */
8975 static inline void atomic_dec(atomic_t *v)
8976 {
8977 - asm volatile(LOCK_PREFIX "decl %0"
8978 + asm volatile(LOCK_PREFIX "decl %0\n"
8979 +
8980 +#ifdef CONFIG_PAX_REFCOUNT
8981 + "jno 0f\n"
8982 + LOCK_PREFIX "incl %0\n"
8983 + "int $4\n0:\n"
8984 + _ASM_EXTABLE(0b, 0b)
8985 +#endif
8986 +
8987 + : "+m" (v->counter));
8988 +}
8989 +
8990 +/**
8991 + * atomic_dec_unchecked - decrement atomic variable
8992 + * @v: pointer of type atomic_unchecked_t
8993 + *
8994 + * Atomically decrements @v by 1.
8995 + */
8996 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8997 +{
8998 + asm volatile(LOCK_PREFIX "decl %0\n"
8999 : "+m" (v->counter));
9000 }
9001
9002 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(at
9003 {
9004 unsigned char c;
9005
9006 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9007 + asm volatile(LOCK_PREFIX "decl %0\n"
9008 +
9009 +#ifdef CONFIG_PAX_REFCOUNT
9010 + "jno 0f\n"
9011 + LOCK_PREFIX "incl %0\n"
9012 + "int $4\n0:\n"
9013 + _ASM_EXTABLE(0b, 0b)
9014 +#endif
9015 +
9016 + "sete %1\n"
9017 : "+m" (v->counter), "=qm" (c)
9018 : : "memory");
9019 return c != 0;
9020 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(at
9021 {
9022 unsigned char c;
9023
9024 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9025 + asm volatile(LOCK_PREFIX "incl %0\n"
9026 +
9027 +#ifdef CONFIG_PAX_REFCOUNT
9028 + "jno 0f\n"
9029 + LOCK_PREFIX "decl %0\n"
9030 + "int $4\n0:\n"
9031 + _ASM_EXTABLE(0b, 0b)
9032 +#endif
9033 +
9034 + "sete %1\n"
9035 + : "+m" (v->counter), "=qm" (c)
9036 + : : "memory");
9037 + return c != 0;
9038 +}
9039 +
9040 +/**
9041 + * atomic_inc_and_test_unchecked - increment and test
9042 + * @v: pointer of type atomic_unchecked_t
9043 + *
9044 + * Atomically increments @v by 1
9045 + * and returns true if the result is zero, or false for all
9046 + * other cases.
9047 + */
9048 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9049 +{
9050 + unsigned char c;
9051 +
9052 + asm volatile(LOCK_PREFIX "incl %0\n"
9053 + "sete %1\n"
9054 : "+m" (v->counter), "=qm" (c)
9055 : : "memory");
9056 return c != 0;
9057 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(in
9058 {
9059 unsigned char c;
9060
9061 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9062 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9063 +
9064 +#ifdef CONFIG_PAX_REFCOUNT
9065 + "jno 0f\n"
9066 + LOCK_PREFIX "subl %2,%0\n"
9067 + "int $4\n0:\n"
9068 + _ASM_EXTABLE(0b, 0b)
9069 +#endif
9070 +
9071 + "sets %1\n"
9072 : "+m" (v->counter), "=qm" (c)
9073 : "ir" (i) : "memory");
9074 return c;
9075 @@ -180,6 +342,46 @@ static inline int atomic_add_return(int
9076 #endif
9077 /* Modern 486+ processor */
9078 __i = i;
9079 + asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9080 +
9081 +#ifdef CONFIG_PAX_REFCOUNT
9082 + "jno 0f\n"
9083 + "movl %0, %1\n"
9084 + "int $4\n0:\n"
9085 + _ASM_EXTABLE(0b, 0b)
9086 +#endif
9087 +
9088 + : "+r" (i), "+m" (v->counter)
9089 + : : "memory");
9090 + return i + __i;
9091 +
9092 +#ifdef CONFIG_M386
9093 +no_xadd: /* Legacy 386 processor */
9094 + local_irq_save(flags);
9095 + __i = atomic_read(v);
9096 + atomic_set(v, i + __i);
9097 + local_irq_restore(flags);
9098 + return i + __i;
9099 +#endif
9100 +}
9101 +
9102 +/**
9103 + * atomic_add_return_unchecked - add integer and return
9104 + * @v: pointer of type atomic_unchecked_t
9105 + * @i: integer value to add
9106 + *
9107 + * Atomically adds @i to @v and returns @i + @v
9108 + */
9109 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9110 +{
9111 + int __i;
9112 +#ifdef CONFIG_M386
9113 + unsigned long flags;
9114 + if (unlikely(boot_cpu_data.x86 <= 3))
9115 + goto no_xadd;
9116 +#endif
9117 + /* Modern 486+ processor */
9118 + __i = i;
9119 asm volatile(LOCK_PREFIX "xaddl %0, %1"
9120 : "+r" (i), "+m" (v->counter)
9121 : : "memory");
9122 @@ -208,6 +410,10 @@ static inline int atomic_sub_return(int
9123 }
9124
9125 #define atomic_inc_return(v) (atomic_add_return(1, v))
9126 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9127 +{
9128 + return atomic_add_return_unchecked(1, v);
9129 +}
9130 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9131
9132 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9133 @@ -215,11 +421,21 @@ static inline int atomic_cmpxchg(atomic_
9134 return cmpxchg(&v->counter, old, new);
9135 }
9136
9137 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9138 +{
9139 + return cmpxchg(&v->counter, old, new);
9140 +}
9141 +
9142 static inline int atomic_xchg(atomic_t *v, int new)
9143 {
9144 return xchg(&v->counter, new);
9145 }
9146
9147 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9148 +{
9149 + return xchg(&v->counter, new);
9150 +}
9151 +
9152 /**
9153 * atomic_add_unless - add unless the number is already a given value
9154 * @v: pointer of type atomic_t
9155 @@ -231,21 +447,77 @@ static inline int atomic_xchg(atomic_t *
9156 */
9157 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9158 {
9159 - int c, old;
9160 + int c, old, new;
9161 c = atomic_read(v);
9162 for (;;) {
9163 - if (unlikely(c == (u)))
9164 + if (unlikely(c == u))
9165 break;
9166 - old = atomic_cmpxchg((v), c, c + (a));
9167 +
9168 + asm volatile("addl %2,%0\n"
9169 +
9170 +#ifdef CONFIG_PAX_REFCOUNT
9171 + "jno 0f\n"
9172 + "subl %2,%0\n"
9173 + "int $4\n0:\n"
9174 + _ASM_EXTABLE(0b, 0b)
9175 +#endif
9176 +
9177 + : "=r" (new)
9178 + : "0" (c), "ir" (a));
9179 +
9180 + old = atomic_cmpxchg(v, c, new);
9181 if (likely(old == c))
9182 break;
9183 c = old;
9184 }
9185 - return c != (u);
9186 + return c != u;
9187 }
9188
9189 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9190
9191 +/**
9192 + * atomic_inc_not_zero_hint - increment if not null
9193 + * @v: pointer of type atomic_t
9194 + * @hint: probable value of the atomic before the increment
9195 + *
9196 + * This version of atomic_inc_not_zero() gives a hint of probable
9197 + * value of the atomic. This helps processor to not read the memory
9198 + * before doing the atomic read/modify/write cycle, lowering
9199 + * number of bus transactions on some arches.
9200 + *
9201 + * Returns: 0 if increment was not done, 1 otherwise.
9202 + */
9203 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9204 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9205 +{
9206 + int val, c = hint, new;
9207 +
9208 + /* sanity test, should be removed by compiler if hint is a constant */
9209 + if (!hint)
9210 + return atomic_inc_not_zero(v);
9211 +
9212 + do {
9213 + asm volatile("incl %0\n"
9214 +
9215 +#ifdef CONFIG_PAX_REFCOUNT
9216 + "jno 0f\n"
9217 + "decl %0\n"
9218 + "int $4\n0:\n"
9219 + _ASM_EXTABLE(0b, 0b)
9220 +#endif
9221 +
9222 + : "=r" (new)
9223 + : "0" (c));
9224 +
9225 + val = atomic_cmpxchg(v, c, new);
9226 + if (val == c)
9227 + return 1;
9228 + c = val;
9229 + } while (c);
9230 +
9231 + return 0;
9232 +}
9233 +
9234 /*
9235 * atomic_dec_if_positive - decrement by 1 if old value positive
9236 * @v: pointer of type atomic_t
9237 diff -urNp linux-2.6.39.2/arch/x86/include/asm/bitops.h linux-2.6.39.2/arch/x86/include/asm/bitops.h
9238 --- linux-2.6.39.2/arch/x86/include/asm/bitops.h 2011-05-19 00:06:34.000000000 -0400
9239 +++ linux-2.6.39.2/arch/x86/include/asm/bitops.h 2011-05-22 19:36:30.000000000 -0400
9240 @@ -38,7 +38,7 @@
9241 * a mask operation on a byte.
9242 */
9243 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9244 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9245 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9246 #define CONST_MASK(nr) (1 << ((nr) & 7))
9247
9248 /**
9249 diff -urNp linux-2.6.39.2/arch/x86/include/asm/boot.h linux-2.6.39.2/arch/x86/include/asm/boot.h
9250 --- linux-2.6.39.2/arch/x86/include/asm/boot.h 2011-05-19 00:06:34.000000000 -0400
9251 +++ linux-2.6.39.2/arch/x86/include/asm/boot.h 2011-05-22 19:36:30.000000000 -0400
9252 @@ -11,10 +11,15 @@
9253 #include <asm/pgtable_types.h>
9254
9255 /* Physical address where kernel should be loaded. */
9256 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9257 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9258 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9259 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9260
9261 +#ifndef __ASSEMBLY__
9262 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9263 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9264 +#endif
9265 +
9266 /* Minimum kernel alignment, as a power of two */
9267 #ifdef CONFIG_X86_64
9268 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9269 diff -urNp linux-2.6.39.2/arch/x86/include/asm/cacheflush.h linux-2.6.39.2/arch/x86/include/asm/cacheflush.h
9270 --- linux-2.6.39.2/arch/x86/include/asm/cacheflush.h 2011-05-19 00:06:34.000000000 -0400
9271 +++ linux-2.6.39.2/arch/x86/include/asm/cacheflush.h 2011-05-22 19:36:30.000000000 -0400
9272 @@ -26,7 +26,7 @@ static inline unsigned long get_page_mem
9273 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9274
9275 if (pg_flags == _PGMT_DEFAULT)
9276 - return -1;
9277 + return ~0UL;
9278 else if (pg_flags == _PGMT_WC)
9279 return _PAGE_CACHE_WC;
9280 else if (pg_flags == _PGMT_UC_MINUS)
9281 diff -urNp linux-2.6.39.2/arch/x86/include/asm/cache.h linux-2.6.39.2/arch/x86/include/asm/cache.h
9282 --- linux-2.6.39.2/arch/x86/include/asm/cache.h 2011-05-19 00:06:34.000000000 -0400
9283 +++ linux-2.6.39.2/arch/x86/include/asm/cache.h 2011-05-22 19:36:30.000000000 -0400
9284 @@ -5,12 +5,13 @@
9285
9286 /* L1 cache line size */
9287 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9288 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9289 +#define L1_CACHE_BYTES (_AC(1,U) << L1_CACHE_SHIFT)
9290
9291 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9292 +#define __read_only __attribute__((__section__(".data..read_only")))
9293
9294 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9295 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9296 +#define INTERNODE_CACHE_BYTES (_AC(1,U) << INTERNODE_CACHE_SHIFT)
9297
9298 #ifdef CONFIG_X86_VSMP
9299 #ifdef CONFIG_SMP
9300 diff -urNp linux-2.6.39.2/arch/x86/include/asm/checksum_32.h linux-2.6.39.2/arch/x86/include/asm/checksum_32.h
9301 --- linux-2.6.39.2/arch/x86/include/asm/checksum_32.h 2011-05-19 00:06:34.000000000 -0400
9302 +++ linux-2.6.39.2/arch/x86/include/asm/checksum_32.h 2011-05-22 19:36:30.000000000 -0400
9303 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
9304 int len, __wsum sum,
9305 int *src_err_ptr, int *dst_err_ptr);
9306
9307 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9308 + int len, __wsum sum,
9309 + int *src_err_ptr, int *dst_err_ptr);
9310 +
9311 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9312 + int len, __wsum sum,
9313 + int *src_err_ptr, int *dst_err_ptr);
9314 +
9315 /*
9316 * Note: when you get a NULL pointer exception here this means someone
9317 * passed in an incorrect kernel address to one of these functions.
9318 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
9319 int *err_ptr)
9320 {
9321 might_sleep();
9322 - return csum_partial_copy_generic((__force void *)src, dst,
9323 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9324 len, sum, err_ptr, NULL);
9325 }
9326
9327 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_us
9328 {
9329 might_sleep();
9330 if (access_ok(VERIFY_WRITE, dst, len))
9331 - return csum_partial_copy_generic(src, (__force void *)dst,
9332 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9333 len, sum, NULL, err_ptr);
9334
9335 if (len)
9336 diff -urNp linux-2.6.39.2/arch/x86/include/asm/cpufeature.h linux-2.6.39.2/arch/x86/include/asm/cpufeature.h
9337 --- linux-2.6.39.2/arch/x86/include/asm/cpufeature.h 2011-06-03 00:04:13.000000000 -0400
9338 +++ linux-2.6.39.2/arch/x86/include/asm/cpufeature.h 2011-06-03 00:32:04.000000000 -0400
9339 @@ -351,7 +351,7 @@ static __always_inline __pure bool __sta
9340 ".section .discard,\"aw\",@progbits\n"
9341 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
9342 ".previous\n"
9343 - ".section .altinstr_replacement,\"ax\"\n"
9344 + ".section .altinstr_replacement,\"a\"\n"
9345 "3: movb $1,%0\n"
9346 "4:\n"
9347 ".previous\n"
9348 diff -urNp linux-2.6.39.2/arch/x86/include/asm/desc_defs.h linux-2.6.39.2/arch/x86/include/asm/desc_defs.h
9349 --- linux-2.6.39.2/arch/x86/include/asm/desc_defs.h 2011-05-19 00:06:34.000000000 -0400
9350 +++ linux-2.6.39.2/arch/x86/include/asm/desc_defs.h 2011-05-22 19:36:30.000000000 -0400
9351 @@ -31,6 +31,12 @@ struct desc_struct {
9352 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9353 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9354 };
9355 + struct {
9356 + u16 offset_low;
9357 + u16 seg;
9358 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9359 + unsigned offset_high: 16;
9360 + } gate;
9361 };
9362 } __attribute__((packed));
9363
9364 diff -urNp linux-2.6.39.2/arch/x86/include/asm/desc.h linux-2.6.39.2/arch/x86/include/asm/desc.h
9365 --- linux-2.6.39.2/arch/x86/include/asm/desc.h 2011-05-19 00:06:34.000000000 -0400
9366 +++ linux-2.6.39.2/arch/x86/include/asm/desc.h 2011-05-22 19:36:30.000000000 -0400
9367 @@ -4,6 +4,7 @@
9368 #include <asm/desc_defs.h>
9369 #include <asm/ldt.h>
9370 #include <asm/mmu.h>
9371 +#include <asm/pgtable.h>
9372 #include <linux/smp.h>
9373
9374 static inline void fill_ldt(struct desc_struct *desc,
9375 @@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_
9376 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9377 desc->type = (info->read_exec_only ^ 1) << 1;
9378 desc->type |= info->contents << 2;
9379 + desc->type |= info->seg_not_present ^ 1;
9380 desc->s = 1;
9381 desc->dpl = 0x3;
9382 desc->p = info->seg_not_present ^ 1;
9383 @@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_
9384 }
9385
9386 extern struct desc_ptr idt_descr;
9387 -extern gate_desc idt_table[];
9388 -
9389 -struct gdt_page {
9390 - struct desc_struct gdt[GDT_ENTRIES];
9391 -} __attribute__((aligned(PAGE_SIZE)));
9392 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9393 +extern gate_desc idt_table[256];
9394
9395 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9396 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9397 {
9398 - return per_cpu(gdt_page, cpu).gdt;
9399 + return cpu_gdt_table[cpu];
9400 }
9401
9402 #ifdef CONFIG_X86_64
9403 @@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *
9404 unsigned long base, unsigned dpl, unsigned flags,
9405 unsigned short seg)
9406 {
9407 - gate->a = (seg << 16) | (base & 0xffff);
9408 - gate->b = (base & 0xffff0000) |
9409 - (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9410 + gate->gate.offset_low = base;
9411 + gate->gate.seg = seg;
9412 + gate->gate.reserved = 0;
9413 + gate->gate.type = type;
9414 + gate->gate.s = 0;
9415 + gate->gate.dpl = dpl;
9416 + gate->gate.p = 1;
9417 + gate->gate.offset_high = base >> 16;
9418 }
9419
9420 #endif
9421 @@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(str
9422 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9423 const gate_desc *gate)
9424 {
9425 + pax_open_kernel();
9426 memcpy(&idt[entry], gate, sizeof(*gate));
9427 + pax_close_kernel();
9428 }
9429
9430 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9431 const void *desc)
9432 {
9433 + pax_open_kernel();
9434 memcpy(&ldt[entry], desc, 8);
9435 + pax_close_kernel();
9436 }
9437
9438 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9439 @@ -139,7 +146,10 @@ static inline void native_write_gdt_entr
9440 size = sizeof(struct desc_struct);
9441 break;
9442 }
9443 +
9444 + pax_open_kernel();
9445 memcpy(&gdt[entry], desc, size);
9446 + pax_close_kernel();
9447 }
9448
9449 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9450 @@ -211,7 +221,9 @@ static inline void native_set_ldt(const
9451
9452 static inline void native_load_tr_desc(void)
9453 {
9454 + pax_open_kernel();
9455 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9456 + pax_close_kernel();
9457 }
9458
9459 static inline void native_load_gdt(const struct desc_ptr *dtr)
9460 @@ -246,8 +258,10 @@ static inline void native_load_tls(struc
9461 unsigned int i;
9462 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9463
9464 + pax_open_kernel();
9465 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9466 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9467 + pax_close_kernel();
9468 }
9469
9470 #define _LDT_empty(info) \
9471 @@ -309,7 +323,7 @@ static inline void set_desc_limit(struct
9472 desc->limit = (limit >> 16) & 0xf;
9473 }
9474
9475 -static inline void _set_gate(int gate, unsigned type, void *addr,
9476 +static inline void _set_gate(int gate, unsigned type, const void *addr,
9477 unsigned dpl, unsigned ist, unsigned seg)
9478 {
9479 gate_desc s;
9480 @@ -327,7 +341,7 @@ static inline void _set_gate(int gate, u
9481 * Pentium F0 0F bugfix can have resulted in the mapped
9482 * IDT being write-protected.
9483 */
9484 -static inline void set_intr_gate(unsigned int n, void *addr)
9485 +static inline void set_intr_gate(unsigned int n, const void *addr)
9486 {
9487 BUG_ON((unsigned)n > 0xFF);
9488 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9489 @@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsig
9490 /*
9491 * This routine sets up an interrupt gate at directory privilege level 3.
9492 */
9493 -static inline void set_system_intr_gate(unsigned int n, void *addr)
9494 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
9495 {
9496 BUG_ON((unsigned)n > 0xFF);
9497 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9498 }
9499
9500 -static inline void set_system_trap_gate(unsigned int n, void *addr)
9501 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
9502 {
9503 BUG_ON((unsigned)n > 0xFF);
9504 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9505 }
9506
9507 -static inline void set_trap_gate(unsigned int n, void *addr)
9508 +static inline void set_trap_gate(unsigned int n, const void *addr)
9509 {
9510 BUG_ON((unsigned)n > 0xFF);
9511 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9512 @@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigne
9513 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9514 {
9515 BUG_ON((unsigned)n > 0xFF);
9516 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9517 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9518 }
9519
9520 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9521 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9522 {
9523 BUG_ON((unsigned)n > 0xFF);
9524 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9525 }
9526
9527 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9528 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9529 {
9530 BUG_ON((unsigned)n > 0xFF);
9531 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9532 }
9533
9534 +#ifdef CONFIG_X86_32
9535 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9536 +{
9537 + struct desc_struct d;
9538 +
9539 + if (likely(limit))
9540 + limit = (limit - 1UL) >> PAGE_SHIFT;
9541 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
9542 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9543 +}
9544 +#endif
9545 +
9546 #endif /* _ASM_X86_DESC_H */
9547 diff -urNp linux-2.6.39.2/arch/x86/include/asm/device.h linux-2.6.39.2/arch/x86/include/asm/device.h
9548 --- linux-2.6.39.2/arch/x86/include/asm/device.h 2011-05-19 00:06:34.000000000 -0400
9549 +++ linux-2.6.39.2/arch/x86/include/asm/device.h 2011-05-22 19:36:30.000000000 -0400
9550 @@ -6,7 +6,7 @@ struct dev_archdata {
9551 void *acpi_handle;
9552 #endif
9553 #ifdef CONFIG_X86_64
9554 -struct dma_map_ops *dma_ops;
9555 + const struct dma_map_ops *dma_ops;
9556 #endif
9557 #if defined(CONFIG_DMAR) || defined(CONFIG_AMD_IOMMU)
9558 void *iommu; /* hook for IOMMU specific extension */
9559 diff -urNp linux-2.6.39.2/arch/x86/include/asm/dma-mapping.h linux-2.6.39.2/arch/x86/include/asm/dma-mapping.h
9560 --- linux-2.6.39.2/arch/x86/include/asm/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
9561 +++ linux-2.6.39.2/arch/x86/include/asm/dma-mapping.h 2011-05-22 19:36:30.000000000 -0400
9562 @@ -26,9 +26,9 @@ extern int iommu_merge;
9563 extern struct device x86_dma_fallback_dev;
9564 extern int panic_on_overflow;
9565
9566 -extern struct dma_map_ops *dma_ops;
9567 +extern const struct dma_map_ops *dma_ops;
9568
9569 -static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9570 +static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9571 {
9572 #ifdef CONFIG_X86_32
9573 return dma_ops;
9574 @@ -45,7 +45,7 @@ static inline struct dma_map_ops *get_dm
9575 /* Make sure we keep the same behaviour */
9576 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9577 {
9578 - struct dma_map_ops *ops = get_dma_ops(dev);
9579 + const struct dma_map_ops *ops = get_dma_ops(dev);
9580 if (ops->mapping_error)
9581 return ops->mapping_error(dev, dma_addr);
9582
9583 @@ -115,7 +115,7 @@ static inline void *
9584 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9585 gfp_t gfp)
9586 {
9587 - struct dma_map_ops *ops = get_dma_ops(dev);
9588 + const struct dma_map_ops *ops = get_dma_ops(dev);
9589 void *memory;
9590
9591 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9592 @@ -142,7 +142,7 @@ dma_alloc_coherent(struct device *dev, s
9593 static inline void dma_free_coherent(struct device *dev, size_t size,
9594 void *vaddr, dma_addr_t bus)
9595 {
9596 - struct dma_map_ops *ops = get_dma_ops(dev);
9597 + const struct dma_map_ops *ops = get_dma_ops(dev);
9598
9599 WARN_ON(irqs_disabled()); /* for portability */
9600
9601 diff -urNp linux-2.6.39.2/arch/x86/include/asm/e820.h linux-2.6.39.2/arch/x86/include/asm/e820.h
9602 --- linux-2.6.39.2/arch/x86/include/asm/e820.h 2011-05-19 00:06:34.000000000 -0400
9603 +++ linux-2.6.39.2/arch/x86/include/asm/e820.h 2011-05-22 19:36:30.000000000 -0400
9604 @@ -69,7 +69,7 @@ struct e820map {
9605 #define ISA_START_ADDRESS 0xa0000
9606 #define ISA_END_ADDRESS 0x100000
9607
9608 -#define BIOS_BEGIN 0x000a0000
9609 +#define BIOS_BEGIN 0x000c0000
9610 #define BIOS_END 0x00100000
9611
9612 #define BIOS_ROM_BASE 0xffe00000
9613 diff -urNp linux-2.6.39.2/arch/x86/include/asm/elf.h linux-2.6.39.2/arch/x86/include/asm/elf.h
9614 --- linux-2.6.39.2/arch/x86/include/asm/elf.h 2011-05-19 00:06:34.000000000 -0400
9615 +++ linux-2.6.39.2/arch/x86/include/asm/elf.h 2011-05-22 19:36:30.000000000 -0400
9616 @@ -237,7 +237,25 @@ extern int force_personality32;
9617 the loader. We need to make sure that it is out of the way of the program
9618 that it will "exec", and that there is sufficient room for the brk. */
9619
9620 +#ifdef CONFIG_PAX_SEGMEXEC
9621 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9622 +#else
9623 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9624 +#endif
9625 +
9626 +#ifdef CONFIG_PAX_ASLR
9627 +#ifdef CONFIG_X86_32
9628 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9629 +
9630 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9631 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9632 +#else
9633 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
9634 +
9635 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9636 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9637 +#endif
9638 +#endif
9639
9640 /* This yields a mask that user programs can use to figure out what
9641 instruction set this CPU supports. This could be done in user space,
9642 @@ -291,8 +309,7 @@ do { \
9643 #define ARCH_DLINFO \
9644 do { \
9645 if (vdso_enabled) \
9646 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
9647 - (unsigned long)current->mm->context.vdso); \
9648 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
9649 } while (0)
9650
9651 #define AT_SYSINFO 32
9652 @@ -303,7 +320,7 @@ do { \
9653
9654 #endif /* !CONFIG_X86_32 */
9655
9656 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
9657 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
9658
9659 #define VDSO_ENTRY \
9660 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
9661 @@ -317,7 +334,4 @@ extern int arch_setup_additional_pages(s
9662 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
9663 #define compat_arch_setup_additional_pages syscall32_setup_pages
9664
9665 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9666 -#define arch_randomize_brk arch_randomize_brk
9667 -
9668 #endif /* _ASM_X86_ELF_H */
9669 diff -urNp linux-2.6.39.2/arch/x86/include/asm/emergency-restart.h linux-2.6.39.2/arch/x86/include/asm/emergency-restart.h
9670 --- linux-2.6.39.2/arch/x86/include/asm/emergency-restart.h 2011-05-19 00:06:34.000000000 -0400
9671 +++ linux-2.6.39.2/arch/x86/include/asm/emergency-restart.h 2011-05-22 19:36:30.000000000 -0400
9672 @@ -15,6 +15,6 @@ enum reboot_type {
9673
9674 extern enum reboot_type reboot_type;
9675
9676 -extern void machine_emergency_restart(void);
9677 +extern void machine_emergency_restart(void) __noreturn;
9678
9679 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
9680 diff -urNp linux-2.6.39.2/arch/x86/include/asm/futex.h linux-2.6.39.2/arch/x86/include/asm/futex.h
9681 --- linux-2.6.39.2/arch/x86/include/asm/futex.h 2011-05-19 00:06:34.000000000 -0400
9682 +++ linux-2.6.39.2/arch/x86/include/asm/futex.h 2011-05-22 19:36:30.000000000 -0400
9683 @@ -12,16 +12,18 @@
9684 #include <asm/system.h>
9685
9686 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
9687 + typecheck(u32 *, uaddr); \
9688 asm volatile("1:\t" insn "\n" \
9689 "2:\t.section .fixup,\"ax\"\n" \
9690 "3:\tmov\t%3, %1\n" \
9691 "\tjmp\t2b\n" \
9692 "\t.previous\n" \
9693 _ASM_EXTABLE(1b, 3b) \
9694 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
9695 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 *)____m(uaddr))\
9696 : "i" (-EFAULT), "0" (oparg), "1" (0))
9697
9698 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
9699 + typecheck(u32 *, uaddr); \
9700 asm volatile("1:\tmovl %2, %0\n" \
9701 "\tmovl\t%0, %3\n" \
9702 "\t" insn "\n" \
9703 @@ -34,7 +36,7 @@
9704 _ASM_EXTABLE(1b, 4b) \
9705 _ASM_EXTABLE(2b, 4b) \
9706 : "=&a" (oldval), "=&r" (ret), \
9707 - "+m" (*uaddr), "=&r" (tem) \
9708 + "+m" (*(u32 *)____m(uaddr)), "=&r" (tem) \
9709 : "r" (oparg), "i" (-EFAULT), "1" (0))
9710
9711 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
9712 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser
9713
9714 switch (op) {
9715 case FUTEX_OP_SET:
9716 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
9717 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
9718 break;
9719 case FUTEX_OP_ADD:
9720 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
9721 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
9722 uaddr, oparg);
9723 break;
9724 case FUTEX_OP_OR:
9725 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_i
9726 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
9727 return -EFAULT;
9728
9729 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
9730 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
9731 "2:\t.section .fixup, \"ax\"\n"
9732 "3:\tmov %3, %0\n"
9733 "\tjmp 2b\n"
9734 "\t.previous\n"
9735 _ASM_EXTABLE(1b, 3b)
9736 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
9737 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
9738 : "i" (-EFAULT), "r" (newval), "1" (oldval)
9739 : "memory"
9740 );
9741 diff -urNp linux-2.6.39.2/arch/x86/include/asm/hw_irq.h linux-2.6.39.2/arch/x86/include/asm/hw_irq.h
9742 --- linux-2.6.39.2/arch/x86/include/asm/hw_irq.h 2011-05-19 00:06:34.000000000 -0400
9743 +++ linux-2.6.39.2/arch/x86/include/asm/hw_irq.h 2011-05-22 19:36:30.000000000 -0400
9744 @@ -137,8 +137,8 @@ extern void setup_ioapic_dest(void);
9745 extern void enable_IO_APIC(void);
9746
9747 /* Statistics */
9748 -extern atomic_t irq_err_count;
9749 -extern atomic_t irq_mis_count;
9750 +extern atomic_unchecked_t irq_err_count;
9751 +extern atomic_unchecked_t irq_mis_count;
9752
9753 /* EISA */
9754 extern void eisa_set_level_irq(unsigned int irq);
9755 diff -urNp linux-2.6.39.2/arch/x86/include/asm/i387.h linux-2.6.39.2/arch/x86/include/asm/i387.h
9756 --- linux-2.6.39.2/arch/x86/include/asm/i387.h 2011-05-19 00:06:34.000000000 -0400
9757 +++ linux-2.6.39.2/arch/x86/include/asm/i387.h 2011-05-22 19:36:30.000000000 -0400
9758 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struc
9759 {
9760 int err;
9761
9762 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9763 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9764 + fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
9765 +#endif
9766 +
9767 /* See comment in fxsave() below. */
9768 #ifdef CONFIG_AS_FXSAVEQ
9769 asm volatile("1: fxrstorq %[fx]\n\t"
9770 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i38
9771 {
9772 int err;
9773
9774 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9775 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
9776 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
9777 +#endif
9778 +
9779 /*
9780 * Clear the bytes not touched by the fxsave and reserved
9781 * for the SW usage.
9782 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu
9783 #endif /* CONFIG_X86_64 */
9784
9785 /* We need a safe address that is cheap to find and that is already
9786 - in L1 during context switch. The best choices are unfortunately
9787 - different for UP and SMP */
9788 -#ifdef CONFIG_SMP
9789 -#define safe_address (__per_cpu_offset[0])
9790 -#else
9791 -#define safe_address (kstat_cpu(0).cpustat.user)
9792 -#endif
9793 + in L1 during context switch. */
9794 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
9795
9796 /*
9797 * These must be called with preempt disabled
9798 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void
9799 struct thread_info *me = current_thread_info();
9800 preempt_disable();
9801 if (me->status & TS_USEDFPU)
9802 - __save_init_fpu(me->task);
9803 + __save_init_fpu(current);
9804 else
9805 clts();
9806 }
9807 diff -urNp linux-2.6.39.2/arch/x86/include/asm/io.h linux-2.6.39.2/arch/x86/include/asm/io.h
9808 --- linux-2.6.39.2/arch/x86/include/asm/io.h 2011-05-19 00:06:34.000000000 -0400
9809 +++ linux-2.6.39.2/arch/x86/include/asm/io.h 2011-05-22 19:36:30.000000000 -0400
9810 @@ -216,6 +216,17 @@ extern void set_iounmap_nonlazy(void);
9811
9812 #include <linux/vmalloc.h>
9813
9814 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
9815 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
9816 +{
9817 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9818 +}
9819 +
9820 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
9821 +{
9822 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
9823 +}
9824 +
9825 /*
9826 * Convert a virtual cached pointer to an uncached pointer
9827 */
9828 diff -urNp linux-2.6.39.2/arch/x86/include/asm/iommu.h linux-2.6.39.2/arch/x86/include/asm/iommu.h
9829 --- linux-2.6.39.2/arch/x86/include/asm/iommu.h 2011-05-19 00:06:34.000000000 -0400
9830 +++ linux-2.6.39.2/arch/x86/include/asm/iommu.h 2011-05-22 19:36:30.000000000 -0400
9831 @@ -1,7 +1,7 @@
9832 #ifndef _ASM_X86_IOMMU_H
9833 #define _ASM_X86_IOMMU_H
9834
9835 -extern struct dma_map_ops nommu_dma_ops;
9836 +extern const struct dma_map_ops nommu_dma_ops;
9837 extern int force_iommu, no_iommu;
9838 extern int iommu_detected;
9839 extern int iommu_pass_through;
9840 diff -urNp linux-2.6.39.2/arch/x86/include/asm/irqflags.h linux-2.6.39.2/arch/x86/include/asm/irqflags.h
9841 --- linux-2.6.39.2/arch/x86/include/asm/irqflags.h 2011-05-19 00:06:34.000000000 -0400
9842 +++ linux-2.6.39.2/arch/x86/include/asm/irqflags.h 2011-05-22 19:36:30.000000000 -0400
9843 @@ -140,6 +140,11 @@ static inline unsigned long arch_local_i
9844 sti; \
9845 sysexit
9846
9847 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
9848 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
9849 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
9850 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
9851 +
9852 #else
9853 #define INTERRUPT_RETURN iret
9854 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
9855 diff -urNp linux-2.6.39.2/arch/x86/include/asm/kprobes.h linux-2.6.39.2/arch/x86/include/asm/kprobes.h
9856 --- linux-2.6.39.2/arch/x86/include/asm/kprobes.h 2011-05-19 00:06:34.000000000 -0400
9857 +++ linux-2.6.39.2/arch/x86/include/asm/kprobes.h 2011-05-22 19:36:30.000000000 -0400
9858 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
9859 #define RELATIVEJUMP_SIZE 5
9860 #define RELATIVECALL_OPCODE 0xe8
9861 #define RELATIVE_ADDR_SIZE 4
9862 -#define MAX_STACK_SIZE 64
9863 -#define MIN_STACK_SIZE(ADDR) \
9864 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
9865 - THREAD_SIZE - (unsigned long)(ADDR))) \
9866 - ? (MAX_STACK_SIZE) \
9867 - : (((unsigned long)current_thread_info()) + \
9868 - THREAD_SIZE - (unsigned long)(ADDR)))
9869 +#define MAX_STACK_SIZE 64UL
9870 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
9871
9872 #define flush_insn_slot(p) do { } while (0)
9873
9874 diff -urNp linux-2.6.39.2/arch/x86/include/asm/kvm_host.h linux-2.6.39.2/arch/x86/include/asm/kvm_host.h
9875 --- linux-2.6.39.2/arch/x86/include/asm/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
9876 +++ linux-2.6.39.2/arch/x86/include/asm/kvm_host.h 2011-05-22 19:36:30.000000000 -0400
9877 @@ -419,7 +419,7 @@ struct kvm_arch {
9878 unsigned int n_used_mmu_pages;
9879 unsigned int n_requested_mmu_pages;
9880 unsigned int n_max_mmu_pages;
9881 - atomic_t invlpg_counter;
9882 + atomic_unchecked_t invlpg_counter;
9883 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
9884 /*
9885 * Hash table of struct kvm_mmu_page.
9886 @@ -599,7 +599,7 @@ struct kvm_arch_async_pf {
9887 bool direct_map;
9888 };
9889
9890 -extern struct kvm_x86_ops *kvm_x86_ops;
9891 +extern const struct kvm_x86_ops *kvm_x86_ops;
9892
9893 int kvm_mmu_module_init(void);
9894 void kvm_mmu_module_exit(void);
9895 diff -urNp linux-2.6.39.2/arch/x86/include/asm/local.h linux-2.6.39.2/arch/x86/include/asm/local.h
9896 --- linux-2.6.39.2/arch/x86/include/asm/local.h 2011-05-19 00:06:34.000000000 -0400
9897 +++ linux-2.6.39.2/arch/x86/include/asm/local.h 2011-05-22 19:36:30.000000000 -0400
9898 @@ -18,26 +18,58 @@ typedef struct {
9899
9900 static inline void local_inc(local_t *l)
9901 {
9902 - asm volatile(_ASM_INC "%0"
9903 + asm volatile(_ASM_INC "%0\n"
9904 +
9905 +#ifdef CONFIG_PAX_REFCOUNT
9906 + "jno 0f\n"
9907 + _ASM_DEC "%0\n"
9908 + "int $4\n0:\n"
9909 + _ASM_EXTABLE(0b, 0b)
9910 +#endif
9911 +
9912 : "+m" (l->a.counter));
9913 }
9914
9915 static inline void local_dec(local_t *l)
9916 {
9917 - asm volatile(_ASM_DEC "%0"
9918 + asm volatile(_ASM_DEC "%0\n"
9919 +
9920 +#ifdef CONFIG_PAX_REFCOUNT
9921 + "jno 0f\n"
9922 + _ASM_INC "%0\n"
9923 + "int $4\n0:\n"
9924 + _ASM_EXTABLE(0b, 0b)
9925 +#endif
9926 +
9927 : "+m" (l->a.counter));
9928 }
9929
9930 static inline void local_add(long i, local_t *l)
9931 {
9932 - asm volatile(_ASM_ADD "%1,%0"
9933 + asm volatile(_ASM_ADD "%1,%0\n"
9934 +
9935 +#ifdef CONFIG_PAX_REFCOUNT
9936 + "jno 0f\n"
9937 + _ASM_SUB "%1,%0\n"
9938 + "int $4\n0:\n"
9939 + _ASM_EXTABLE(0b, 0b)
9940 +#endif
9941 +
9942 : "+m" (l->a.counter)
9943 : "ir" (i));
9944 }
9945
9946 static inline void local_sub(long i, local_t *l)
9947 {
9948 - asm volatile(_ASM_SUB "%1,%0"
9949 + asm volatile(_ASM_SUB "%1,%0\n"
9950 +
9951 +#ifdef CONFIG_PAX_REFCOUNT
9952 + "jno 0f\n"
9953 + _ASM_ADD "%1,%0\n"
9954 + "int $4\n0:\n"
9955 + _ASM_EXTABLE(0b, 0b)
9956 +#endif
9957 +
9958 : "+m" (l->a.counter)
9959 : "ir" (i));
9960 }
9961 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(lon
9962 {
9963 unsigned char c;
9964
9965 - asm volatile(_ASM_SUB "%2,%0; sete %1"
9966 + asm volatile(_ASM_SUB "%2,%0\n"
9967 +
9968 +#ifdef CONFIG_PAX_REFCOUNT
9969 + "jno 0f\n"
9970 + _ASM_ADD "%2,%0\n"
9971 + "int $4\n0:\n"
9972 + _ASM_EXTABLE(0b, 0b)
9973 +#endif
9974 +
9975 + "sete %1\n"
9976 : "+m" (l->a.counter), "=qm" (c)
9977 : "ir" (i) : "memory");
9978 return c;
9979 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(loc
9980 {
9981 unsigned char c;
9982
9983 - asm volatile(_ASM_DEC "%0; sete %1"
9984 + asm volatile(_ASM_DEC "%0\n"
9985 +
9986 +#ifdef CONFIG_PAX_REFCOUNT
9987 + "jno 0f\n"
9988 + _ASM_INC "%0\n"
9989 + "int $4\n0:\n"
9990 + _ASM_EXTABLE(0b, 0b)
9991 +#endif
9992 +
9993 + "sete %1\n"
9994 : "+m" (l->a.counter), "=qm" (c)
9995 : : "memory");
9996 return c != 0;
9997 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(loc
9998 {
9999 unsigned char c;
10000
10001 - asm volatile(_ASM_INC "%0; sete %1"
10002 + asm volatile(_ASM_INC "%0\n"
10003 +
10004 +#ifdef CONFIG_PAX_REFCOUNT
10005 + "jno 0f\n"
10006 + _ASM_DEC "%0\n"
10007 + "int $4\n0:\n"
10008 + _ASM_EXTABLE(0b, 0b)
10009 +#endif
10010 +
10011 + "sete %1\n"
10012 : "+m" (l->a.counter), "=qm" (c)
10013 : : "memory");
10014 return c != 0;
10015 @@ -110,7 +169,16 @@ static inline int local_add_negative(lon
10016 {
10017 unsigned char c;
10018
10019 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10020 + asm volatile(_ASM_ADD "%2,%0\n"
10021 +
10022 +#ifdef CONFIG_PAX_REFCOUNT
10023 + "jno 0f\n"
10024 + _ASM_SUB "%2,%0\n"
10025 + "int $4\n0:\n"
10026 + _ASM_EXTABLE(0b, 0b)
10027 +#endif
10028 +
10029 + "sets %1\n"
10030 : "+m" (l->a.counter), "=qm" (c)
10031 : "ir" (i) : "memory");
10032 return c;
10033 @@ -133,7 +201,15 @@ static inline long local_add_return(long
10034 #endif
10035 /* Modern 486+ processor */
10036 __i = i;
10037 - asm volatile(_ASM_XADD "%0, %1;"
10038 + asm volatile(_ASM_XADD "%0, %1\n"
10039 +
10040 +#ifdef CONFIG_PAX_REFCOUNT
10041 + "jno 0f\n"
10042 + _ASM_MOV "%0,%1\n"
10043 + "int $4\n0:\n"
10044 + _ASM_EXTABLE(0b, 0b)
10045 +#endif
10046 +
10047 : "+r" (i), "+m" (l->a.counter)
10048 : : "memory");
10049 return i + __i;
10050 diff -urNp linux-2.6.39.2/arch/x86/include/asm/mce.h linux-2.6.39.2/arch/x86/include/asm/mce.h
10051 --- linux-2.6.39.2/arch/x86/include/asm/mce.h 2011-05-19 00:06:34.000000000 -0400
10052 +++ linux-2.6.39.2/arch/x86/include/asm/mce.h 2011-05-22 19:36:30.000000000 -0400
10053 @@ -198,7 +198,7 @@ int mce_notify_irq(void);
10054 void mce_notify_process(void);
10055
10056 DECLARE_PER_CPU(struct mce, injectm);
10057 -extern struct file_operations mce_chrdev_ops;
10058 +extern struct file_operations mce_chrdev_ops; /* cannot be const, see arch/x86/kernel/cpu/mcheck/mce. */
10059
10060 /*
10061 * Exception handler
10062 diff -urNp linux-2.6.39.2/arch/x86/include/asm/microcode.h linux-2.6.39.2/arch/x86/include/asm/microcode.h
10063 --- linux-2.6.39.2/arch/x86/include/asm/microcode.h 2011-05-19 00:06:34.000000000 -0400
10064 +++ linux-2.6.39.2/arch/x86/include/asm/microcode.h 2011-05-22 19:36:30.000000000 -0400
10065 @@ -12,13 +12,13 @@ struct device;
10066 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
10067
10068 struct microcode_ops {
10069 - enum ucode_state (*request_microcode_user) (int cpu,
10070 + enum ucode_state (* const request_microcode_user) (int cpu,
10071 const void __user *buf, size_t size);
10072
10073 - enum ucode_state (*request_microcode_fw) (int cpu,
10074 + enum ucode_state (* const request_microcode_fw) (int cpu,
10075 struct device *device);
10076
10077 - void (*microcode_fini_cpu) (int cpu);
10078 + void (* const microcode_fini_cpu) (int cpu);
10079
10080 /*
10081 * The generic 'microcode_core' part guarantees that
10082 @@ -38,16 +38,16 @@ struct ucode_cpu_info {
10083 extern struct ucode_cpu_info ucode_cpu_info[];
10084
10085 #ifdef CONFIG_MICROCODE_INTEL
10086 -extern struct microcode_ops * __init init_intel_microcode(void);
10087 +extern const struct microcode_ops * __init init_intel_microcode(void);
10088 #else
10089 -static inline struct microcode_ops * __init init_intel_microcode(void)
10090 +static inline const struct microcode_ops * __init init_intel_microcode(void)
10091 {
10092 return NULL;
10093 }
10094 #endif /* CONFIG_MICROCODE_INTEL */
10095
10096 #ifdef CONFIG_MICROCODE_AMD
10097 -extern struct microcode_ops * __init init_amd_microcode(void);
10098 +extern const struct microcode_ops * __init init_amd_microcode(void);
10099
10100 static inline void get_ucode_data(void *to, const u8 *from, size_t n)
10101 {
10102 @@ -55,7 +55,7 @@ static inline void get_ucode_data(void *
10103 }
10104
10105 #else
10106 -static inline struct microcode_ops * __init init_amd_microcode(void)
10107 +static inline const struct microcode_ops * __init init_amd_microcode(void)
10108 {
10109 return NULL;
10110 }
10111 diff -urNp linux-2.6.39.2/arch/x86/include/asm/mman.h linux-2.6.39.2/arch/x86/include/asm/mman.h
10112 --- linux-2.6.39.2/arch/x86/include/asm/mman.h 2011-05-19 00:06:34.000000000 -0400
10113 +++ linux-2.6.39.2/arch/x86/include/asm/mman.h 2011-05-22 19:36:30.000000000 -0400
10114 @@ -5,4 +5,14 @@
10115
10116 #include <asm-generic/mman.h>
10117
10118 +#ifdef __KERNEL__
10119 +#ifndef __ASSEMBLY__
10120 +#ifdef CONFIG_X86_32
10121 +#define arch_mmap_check i386_mmap_check
10122 +int i386_mmap_check(unsigned long addr, unsigned long len,
10123 + unsigned long flags);
10124 +#endif
10125 +#endif
10126 +#endif
10127 +
10128 #endif /* _ASM_X86_MMAN_H */
10129 diff -urNp linux-2.6.39.2/arch/x86/include/asm/mmu_context.h linux-2.6.39.2/arch/x86/include/asm/mmu_context.h
10130 --- linux-2.6.39.2/arch/x86/include/asm/mmu_context.h 2011-05-19 00:06:34.000000000 -0400
10131 +++ linux-2.6.39.2/arch/x86/include/asm/mmu_context.h 2011-05-22 19:36:30.000000000 -0400
10132 @@ -24,6 +24,21 @@ void destroy_context(struct mm_struct *m
10133
10134 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10135 {
10136 +
10137 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10138 + unsigned int i;
10139 + pgd_t *pgd;
10140 +
10141 + pax_open_kernel();
10142 + pgd = get_cpu_pgd(smp_processor_id());
10143 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10144 + if (paravirt_enabled())
10145 + set_pgd(pgd+i, native_make_pgd(0));
10146 + else
10147 + pgd[i] = native_make_pgd(0);
10148 + pax_close_kernel();
10149 +#endif
10150 +
10151 #ifdef CONFIG_SMP
10152 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10153 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10154 @@ -34,16 +49,30 @@ static inline void switch_mm(struct mm_s
10155 struct task_struct *tsk)
10156 {
10157 unsigned cpu = smp_processor_id();
10158 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
10159 + int tlbstate = TLBSTATE_OK;
10160 +#endif
10161
10162 if (likely(prev != next)) {
10163 #ifdef CONFIG_SMP
10164 +#ifdef CONFIG_X86_32
10165 + tlbstate = percpu_read(cpu_tlbstate.state);
10166 +#endif
10167 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10168 percpu_write(cpu_tlbstate.active_mm, next);
10169 #endif
10170 cpumask_set_cpu(cpu, mm_cpumask(next));
10171
10172 /* Re-load page tables */
10173 +#ifdef CONFIG_PAX_PER_CPU_PGD
10174 + pax_open_kernel();
10175 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10176 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10177 + pax_close_kernel();
10178 + load_cr3(get_cpu_pgd(cpu));
10179 +#else
10180 load_cr3(next->pgd);
10181 +#endif
10182
10183 /* stop flush ipis for the previous mm */
10184 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10185 @@ -53,9 +82,38 @@ static inline void switch_mm(struct mm_s
10186 */
10187 if (unlikely(prev->context.ldt != next->context.ldt))
10188 load_LDT_nolock(&next->context);
10189 - }
10190 +
10191 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10192 + if (!(__supported_pte_mask & _PAGE_NX)) {
10193 + smp_mb__before_clear_bit();
10194 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10195 + smp_mb__after_clear_bit();
10196 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10197 + }
10198 +#endif
10199 +
10200 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10201 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10202 + prev->context.user_cs_limit != next->context.user_cs_limit))
10203 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10204 #ifdef CONFIG_SMP
10205 + else if (unlikely(tlbstate != TLBSTATE_OK))
10206 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10207 +#endif
10208 +#endif
10209 +
10210 + }
10211 else {
10212 +
10213 +#ifdef CONFIG_PAX_PER_CPU_PGD
10214 + pax_open_kernel();
10215 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10216 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10217 + pax_close_kernel();
10218 + load_cr3(get_cpu_pgd(cpu));
10219 +#endif
10220 +
10221 +#ifdef CONFIG_SMP
10222 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10223 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10224
10225 @@ -64,11 +122,28 @@ static inline void switch_mm(struct mm_s
10226 * tlb flush IPI delivery. We must reload CR3
10227 * to make sure to use no freed page tables.
10228 */
10229 +
10230 +#ifndef CONFIG_PAX_PER_CPU_PGD
10231 load_cr3(next->pgd);
10232 +#endif
10233 +
10234 load_LDT_nolock(&next->context);
10235 +
10236 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10237 + if (!(__supported_pte_mask & _PAGE_NX))
10238 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10239 +#endif
10240 +
10241 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10242 +#ifdef CONFIG_PAX_PAGEEXEC
10243 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10244 +#endif
10245 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10246 +#endif
10247 +
10248 }
10249 - }
10250 #endif
10251 + }
10252 }
10253
10254 #define activate_mm(prev, next) \
10255 diff -urNp linux-2.6.39.2/arch/x86/include/asm/mmu.h linux-2.6.39.2/arch/x86/include/asm/mmu.h
10256 --- linux-2.6.39.2/arch/x86/include/asm/mmu.h 2011-05-19 00:06:34.000000000 -0400
10257 +++ linux-2.6.39.2/arch/x86/include/asm/mmu.h 2011-05-22 19:36:30.000000000 -0400
10258 @@ -9,10 +9,22 @@
10259 * we put the segment information here.
10260 */
10261 typedef struct {
10262 - void *ldt;
10263 + struct desc_struct *ldt;
10264 int size;
10265 struct mutex lock;
10266 - void *vdso;
10267 + unsigned long vdso;
10268 +
10269 +#ifdef CONFIG_X86_32
10270 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10271 + unsigned long user_cs_base;
10272 + unsigned long user_cs_limit;
10273 +
10274 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10275 + cpumask_t cpu_user_cs_mask;
10276 +#endif
10277 +
10278 +#endif
10279 +#endif
10280
10281 #ifdef CONFIG_X86_64
10282 /* True if mm supports a task running in 32 bit compatibility mode. */
10283 diff -urNp linux-2.6.39.2/arch/x86/include/asm/module.h linux-2.6.39.2/arch/x86/include/asm/module.h
10284 --- linux-2.6.39.2/arch/x86/include/asm/module.h 2011-05-19 00:06:34.000000000 -0400
10285 +++ linux-2.6.39.2/arch/x86/include/asm/module.h 2011-05-22 19:41:32.000000000 -0400
10286 @@ -5,6 +5,7 @@
10287
10288 #ifdef CONFIG_X86_64
10289 /* X86_64 does not define MODULE_PROC_FAMILY */
10290 +#define MODULE_PROC_FAMILY ""
10291 #elif defined CONFIG_M386
10292 #define MODULE_PROC_FAMILY "386 "
10293 #elif defined CONFIG_M486
10294 @@ -59,8 +60,30 @@
10295 #error unknown processor family
10296 #endif
10297
10298 -#ifdef CONFIG_X86_32
10299 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10300 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10301 +#define MODULE_PAX_UDEREF "UDEREF "
10302 +#else
10303 +#define MODULE_PAX_UDEREF ""
10304 +#endif
10305 +
10306 +#ifdef CONFIG_PAX_KERNEXEC
10307 +#define MODULE_PAX_KERNEXEC "KERNEXEC "
10308 +#else
10309 +#define MODULE_PAX_KERNEXEC ""
10310 #endif
10311
10312 +#ifdef CONFIG_PAX_REFCOUNT
10313 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
10314 +#else
10315 +#define MODULE_PAX_REFCOUNT ""
10316 +#endif
10317 +
10318 +#ifdef CONFIG_GRKERNSEC
10319 +#define MODULE_GRSEC "GRSECURITY "
10320 +#else
10321 +#define MODULE_GRSEC ""
10322 +#endif
10323 +
10324 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_GRSEC MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF MODULE_PAX_REFCOUNT
10325 +
10326 #endif /* _ASM_X86_MODULE_H */
10327 diff -urNp linux-2.6.39.2/arch/x86/include/asm/page_64_types.h linux-2.6.39.2/arch/x86/include/asm/page_64_types.h
10328 --- linux-2.6.39.2/arch/x86/include/asm/page_64_types.h 2011-05-19 00:06:34.000000000 -0400
10329 +++ linux-2.6.39.2/arch/x86/include/asm/page_64_types.h 2011-05-22 19:36:30.000000000 -0400
10330 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10331
10332 /* duplicated to the one in bootmem.h */
10333 extern unsigned long max_pfn;
10334 -extern unsigned long phys_base;
10335 +extern const unsigned long phys_base;
10336
10337 extern unsigned long __phys_addr(unsigned long);
10338 #define __phys_reloc_hide(x) (x)
10339 diff -urNp linux-2.6.39.2/arch/x86/include/asm/paravirt.h linux-2.6.39.2/arch/x86/include/asm/paravirt.h
10340 --- linux-2.6.39.2/arch/x86/include/asm/paravirt.h 2011-05-19 00:06:34.000000000 -0400
10341 +++ linux-2.6.39.2/arch/x86/include/asm/paravirt.h 2011-05-22 19:36:30.000000000 -0400
10342 @@ -739,6 +739,21 @@ static inline void __set_fixmap(unsigned
10343 pv_mmu_ops.set_fixmap(idx, phys, flags);
10344 }
10345
10346 +#ifdef CONFIG_PAX_KERNEXEC
10347 +static inline unsigned long pax_open_kernel(void)
10348 +{
10349 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10350 +}
10351 +
10352 +static inline unsigned long pax_close_kernel(void)
10353 +{
10354 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10355 +}
10356 +#else
10357 +static inline unsigned long pax_open_kernel(void) { return 0; }
10358 +static inline unsigned long pax_close_kernel(void) { return 0; }
10359 +#endif
10360 +
10361 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10362
10363 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10364 @@ -955,7 +970,7 @@ extern void default_banner(void);
10365
10366 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10367 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10368 -#define PARA_INDIRECT(addr) *%cs:addr
10369 +#define PARA_INDIRECT(addr) *%ss:addr
10370 #endif
10371
10372 #define INTERRUPT_RETURN \
10373 @@ -1032,6 +1047,21 @@ extern void default_banner(void);
10374 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10375 CLBR_NONE, \
10376 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10377 +
10378 +#define GET_CR0_INTO_RDI \
10379 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10380 + mov %rax,%rdi
10381 +
10382 +#define SET_RDI_INTO_CR0 \
10383 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10384 +
10385 +#define GET_CR3_INTO_RDI \
10386 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10387 + mov %rax,%rdi
10388 +
10389 +#define SET_RDI_INTO_CR3 \
10390 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10391 +
10392 #endif /* CONFIG_X86_32 */
10393
10394 #endif /* __ASSEMBLY__ */
10395 diff -urNp linux-2.6.39.2/arch/x86/include/asm/paravirt_types.h linux-2.6.39.2/arch/x86/include/asm/paravirt_types.h
10396 --- linux-2.6.39.2/arch/x86/include/asm/paravirt_types.h 2011-05-19 00:06:34.000000000 -0400
10397 +++ linux-2.6.39.2/arch/x86/include/asm/paravirt_types.h 2011-05-22 19:36:30.000000000 -0400
10398 @@ -317,6 +317,12 @@ struct pv_mmu_ops {
10399 an mfn. We can tell which is which from the index. */
10400 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10401 phys_addr_t phys, pgprot_t flags);
10402 +
10403 +#ifdef CONFIG_PAX_KERNEXEC
10404 + unsigned long (*pax_open_kernel)(void);
10405 + unsigned long (*pax_close_kernel)(void);
10406 +#endif
10407 +
10408 };
10409
10410 struct arch_spinlock;
10411 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pci_x86.h linux-2.6.39.2/arch/x86/include/asm/pci_x86.h
10412 --- linux-2.6.39.2/arch/x86/include/asm/pci_x86.h 2011-05-19 00:06:34.000000000 -0400
10413 +++ linux-2.6.39.2/arch/x86/include/asm/pci_x86.h 2011-05-22 19:36:30.000000000 -0400
10414 @@ -93,16 +93,16 @@ extern int (*pcibios_enable_irq)(struct
10415 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10416
10417 struct pci_raw_ops {
10418 - int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10419 + int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10420 int reg, int len, u32 *val);
10421 - int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10422 + int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10423 int reg, int len, u32 val);
10424 };
10425
10426 -extern struct pci_raw_ops *raw_pci_ops;
10427 -extern struct pci_raw_ops *raw_pci_ext_ops;
10428 +extern const struct pci_raw_ops *raw_pci_ops;
10429 +extern const struct pci_raw_ops *raw_pci_ext_ops;
10430
10431 -extern struct pci_raw_ops pci_direct_conf1;
10432 +extern const struct pci_raw_ops pci_direct_conf1;
10433 extern bool port_cf9_safe;
10434
10435 /* arch_initcall level */
10436 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgalloc.h linux-2.6.39.2/arch/x86/include/asm/pgalloc.h
10437 --- linux-2.6.39.2/arch/x86/include/asm/pgalloc.h 2011-05-19 00:06:34.000000000 -0400
10438 +++ linux-2.6.39.2/arch/x86/include/asm/pgalloc.h 2011-05-22 19:36:30.000000000 -0400
10439 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(s
10440 pmd_t *pmd, pte_t *pte)
10441 {
10442 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10443 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10444 +}
10445 +
10446 +static inline void pmd_populate_user(struct mm_struct *mm,
10447 + pmd_t *pmd, pte_t *pte)
10448 +{
10449 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10450 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10451 }
10452
10453 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable-2level.h linux-2.6.39.2/arch/x86/include/asm/pgtable-2level.h
10454 --- linux-2.6.39.2/arch/x86/include/asm/pgtable-2level.h 2011-05-19 00:06:34.000000000 -0400
10455 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable-2level.h 2011-05-22 19:36:30.000000000 -0400
10456 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t
10457
10458 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10459 {
10460 + pax_open_kernel();
10461 *pmdp = pmd;
10462 + pax_close_kernel();
10463 }
10464
10465 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10466 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable_32.h linux-2.6.39.2/arch/x86/include/asm/pgtable_32.h
10467 --- linux-2.6.39.2/arch/x86/include/asm/pgtable_32.h 2011-05-19 00:06:34.000000000 -0400
10468 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable_32.h 2011-05-22 19:36:30.000000000 -0400
10469 @@ -25,9 +25,6 @@
10470 struct mm_struct;
10471 struct vm_area_struct;
10472
10473 -extern pgd_t swapper_pg_dir[1024];
10474 -extern pgd_t initial_page_table[1024];
10475 -
10476 static inline void pgtable_cache_init(void) { }
10477 static inline void check_pgt_cache(void) { }
10478 void paging_init(void);
10479 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, u
10480 # include <asm/pgtable-2level.h>
10481 #endif
10482
10483 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
10484 +extern pgd_t initial_page_table[PTRS_PER_PGD];
10485 +#ifdef CONFIG_X86_PAE
10486 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
10487 +#endif
10488 +
10489 #if defined(CONFIG_HIGHPTE)
10490 #define pte_offset_map(dir, address) \
10491 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
10492 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, u
10493 /* Clear a kernel PTE and flush it from the TLB */
10494 #define kpte_clear_flush(ptep, vaddr) \
10495 do { \
10496 + pax_open_kernel(); \
10497 pte_clear(&init_mm, (vaddr), (ptep)); \
10498 + pax_close_kernel(); \
10499 __flush_tlb_one((vaddr)); \
10500 } while (0)
10501
10502 @@ -74,6 +79,9 @@ do { \
10503
10504 #endif /* !__ASSEMBLY__ */
10505
10506 +#define HAVE_ARCH_UNMAPPED_AREA
10507 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
10508 +
10509 /*
10510 * kern_addr_valid() is (1) for FLATMEM and (0) for
10511 * SPARSEMEM and DISCONTIGMEM
10512 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable_32_types.h linux-2.6.39.2/arch/x86/include/asm/pgtable_32_types.h
10513 --- linux-2.6.39.2/arch/x86/include/asm/pgtable_32_types.h 2011-05-19 00:06:34.000000000 -0400
10514 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable_32_types.h 2011-05-22 19:36:30.000000000 -0400
10515 @@ -8,7 +8,7 @@
10516 */
10517 #ifdef CONFIG_X86_PAE
10518 # include <asm/pgtable-3level_types.h>
10519 -# define PMD_SIZE (1UL << PMD_SHIFT)
10520 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
10521 # define PMD_MASK (~(PMD_SIZE - 1))
10522 #else
10523 # include <asm/pgtable-2level_types.h>
10524 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set
10525 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
10526 #endif
10527
10528 +#ifdef CONFIG_PAX_KERNEXEC
10529 +#ifndef __ASSEMBLY__
10530 +extern unsigned char MODULES_EXEC_VADDR[];
10531 +extern unsigned char MODULES_EXEC_END[];
10532 +#endif
10533 +#include <asm/boot.h>
10534 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
10535 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
10536 +#else
10537 +#define ktla_ktva(addr) (addr)
10538 +#define ktva_ktla(addr) (addr)
10539 +#endif
10540 +
10541 #define MODULES_VADDR VMALLOC_START
10542 #define MODULES_END VMALLOC_END
10543 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
10544 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable-3level.h linux-2.6.39.2/arch/x86/include/asm/pgtable-3level.h
10545 --- linux-2.6.39.2/arch/x86/include/asm/pgtable-3level.h 2011-05-19 00:06:34.000000000 -0400
10546 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable-3level.h 2011-05-22 19:36:30.000000000 -0400
10547 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic
10548
10549 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10550 {
10551 + pax_open_kernel();
10552 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10553 + pax_close_kernel();
10554 }
10555
10556 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10557 {
10558 + pax_open_kernel();
10559 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10560 + pax_close_kernel();
10561 }
10562
10563 /*
10564 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable_64.h linux-2.6.39.2/arch/x86/include/asm/pgtable_64.h
10565 --- linux-2.6.39.2/arch/x86/include/asm/pgtable_64.h 2011-05-19 00:06:34.000000000 -0400
10566 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable_64.h 2011-05-22 19:36:30.000000000 -0400
10567 @@ -16,10 +16,13 @@
10568
10569 extern pud_t level3_kernel_pgt[512];
10570 extern pud_t level3_ident_pgt[512];
10571 +extern pud_t level3_vmalloc_pgt[512];
10572 +extern pud_t level3_vmemmap_pgt[512];
10573 +extern pud_t level2_vmemmap_pgt[512];
10574 extern pmd_t level2_kernel_pgt[512];
10575 extern pmd_t level2_fixmap_pgt[512];
10576 -extern pmd_t level2_ident_pgt[512];
10577 -extern pgd_t init_level4_pgt[];
10578 +extern pmd_t level2_ident_pgt[512*2];
10579 +extern pgd_t init_level4_pgt[512];
10580
10581 #define swapper_pg_dir init_level4_pgt
10582
10583 @@ -61,7 +64,9 @@ static inline void native_set_pte_atomic
10584
10585 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10586 {
10587 + pax_open_kernel();
10588 *pmdp = pmd;
10589 + pax_close_kernel();
10590 }
10591
10592 static inline void native_pmd_clear(pmd_t *pmd)
10593 @@ -107,7 +112,9 @@ static inline void native_pud_clear(pud_
10594
10595 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
10596 {
10597 + pax_open_kernel();
10598 *pgdp = pgd;
10599 + pax_close_kernel();
10600 }
10601
10602 static inline void native_pgd_clear(pgd_t *pgd)
10603 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable_64_types.h linux-2.6.39.2/arch/x86/include/asm/pgtable_64_types.h
10604 --- linux-2.6.39.2/arch/x86/include/asm/pgtable_64_types.h 2011-05-19 00:06:34.000000000 -0400
10605 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable_64_types.h 2011-05-22 19:36:30.000000000 -0400
10606 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
10607 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
10608 #define MODULES_END _AC(0xffffffffff000000, UL)
10609 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
10610 +#define MODULES_EXEC_VADDR MODULES_VADDR
10611 +#define MODULES_EXEC_END MODULES_END
10612 +
10613 +#define ktla_ktva(addr) (addr)
10614 +#define ktva_ktla(addr) (addr)
10615
10616 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
10617 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable.h linux-2.6.39.2/arch/x86/include/asm/pgtable.h
10618 --- linux-2.6.39.2/arch/x86/include/asm/pgtable.h 2011-05-19 00:06:34.000000000 -0400
10619 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable.h 2011-05-22 19:36:30.000000000 -0400
10620 @@ -81,12 +81,51 @@ extern struct mm_struct *pgd_page_get_mm
10621
10622 #define arch_end_context_switch(prev) do {} while(0)
10623
10624 +#define pax_open_kernel() native_pax_open_kernel()
10625 +#define pax_close_kernel() native_pax_close_kernel()
10626 #endif /* CONFIG_PARAVIRT */
10627
10628 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
10629 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10630 +
10631 +#ifdef CONFIG_PAX_KERNEXEC
10632 +static inline unsigned long native_pax_open_kernel(void)
10633 +{
10634 + unsigned long cr0;
10635 +
10636 + preempt_disable();
10637 + barrier();
10638 + cr0 = read_cr0() ^ X86_CR0_WP;
10639 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
10640 + write_cr0(cr0);
10641 + return cr0 ^ X86_CR0_WP;
10642 +}
10643 +
10644 +static inline unsigned long native_pax_close_kernel(void)
10645 +{
10646 + unsigned long cr0;
10647 +
10648 + cr0 = read_cr0() ^ X86_CR0_WP;
10649 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
10650 + write_cr0(cr0);
10651 + barrier();
10652 + preempt_enable_no_resched();
10653 + return cr0 ^ X86_CR0_WP;
10654 +}
10655 +#else
10656 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
10657 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
10658 +#endif
10659 +
10660 /*
10661 * The following only work if pte_present() is true.
10662 * Undefined behaviour if not..
10663 */
10664 +static inline int pte_user(pte_t pte)
10665 +{
10666 + return pte_val(pte) & _PAGE_USER;
10667 +}
10668 +
10669 static inline int pte_dirty(pte_t pte)
10670 {
10671 return pte_flags(pte) & _PAGE_DIRTY;
10672 @@ -196,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t
10673 return pte_clear_flags(pte, _PAGE_RW);
10674 }
10675
10676 +static inline pte_t pte_mkread(pte_t pte)
10677 +{
10678 + return __pte(pte_val(pte) | _PAGE_USER);
10679 +}
10680 +
10681 static inline pte_t pte_mkexec(pte_t pte)
10682 {
10683 - return pte_clear_flags(pte, _PAGE_NX);
10684 +#ifdef CONFIG_X86_PAE
10685 + if (__supported_pte_mask & _PAGE_NX)
10686 + return pte_clear_flags(pte, _PAGE_NX);
10687 + else
10688 +#endif
10689 + return pte_set_flags(pte, _PAGE_USER);
10690 +}
10691 +
10692 +static inline pte_t pte_exprotect(pte_t pte)
10693 +{
10694 +#ifdef CONFIG_X86_PAE
10695 + if (__supported_pte_mask & _PAGE_NX)
10696 + return pte_set_flags(pte, _PAGE_NX);
10697 + else
10698 +#endif
10699 + return pte_clear_flags(pte, _PAGE_USER);
10700 }
10701
10702 static inline pte_t pte_mkdirty(pte_t pte)
10703 @@ -390,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long
10704 #endif
10705
10706 #ifndef __ASSEMBLY__
10707 +
10708 +#ifdef CONFIG_PAX_PER_CPU_PGD
10709 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
10710 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
10711 +{
10712 + return cpu_pgd[cpu];
10713 +}
10714 +#endif
10715 +
10716 #include <linux/mm_types.h>
10717
10718 static inline int pte_none(pte_t pte)
10719 @@ -560,7 +628,7 @@ static inline pud_t *pud_offset(pgd_t *p
10720
10721 static inline int pgd_bad(pgd_t pgd)
10722 {
10723 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
10724 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
10725 }
10726
10727 static inline int pgd_none(pgd_t pgd)
10728 @@ -583,7 +651,12 @@ static inline int pgd_none(pgd_t pgd)
10729 * pgd_offset() returns a (pgd_t *)
10730 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
10731 */
10732 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
10733 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
10734 +
10735 +#ifdef CONFIG_PAX_PER_CPU_PGD
10736 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
10737 +#endif
10738 +
10739 /*
10740 * a shortcut which implies the use of the kernel's pgd, instead
10741 * of a process's
10742 @@ -594,6 +667,20 @@ static inline int pgd_none(pgd_t pgd)
10743 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
10744 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
10745
10746 +#ifdef CONFIG_X86_32
10747 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
10748 +#else
10749 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
10750 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
10751 +
10752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10753 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
10754 +#else
10755 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
10756 +#endif
10757 +
10758 +#endif
10759 +
10760 #ifndef __ASSEMBLY__
10761
10762 extern int direct_gbpages;
10763 @@ -758,11 +845,23 @@ static inline void pmdp_set_wrprotect(st
10764 * dst and src can be on the same page, but the range must not overlap,
10765 * and must not cross a page boundary.
10766 */
10767 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
10768 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
10769 {
10770 - memcpy(dst, src, count * sizeof(pgd_t));
10771 + pax_open_kernel();
10772 + while (count--)
10773 + *dst++ = *src++;
10774 + pax_close_kernel();
10775 }
10776
10777 +#ifdef CONFIG_PAX_PER_CPU_PGD
10778 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10779 +#endif
10780 +
10781 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10782 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
10783 +#else
10784 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
10785 +#endif
10786
10787 #include <asm-generic/pgtable.h>
10788 #endif /* __ASSEMBLY__ */
10789 diff -urNp linux-2.6.39.2/arch/x86/include/asm/pgtable_types.h linux-2.6.39.2/arch/x86/include/asm/pgtable_types.h
10790 --- linux-2.6.39.2/arch/x86/include/asm/pgtable_types.h 2011-05-19 00:06:34.000000000 -0400
10791 +++ linux-2.6.39.2/arch/x86/include/asm/pgtable_types.h 2011-05-22 19:36:30.000000000 -0400
10792 @@ -16,13 +16,12 @@
10793 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
10794 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
10795 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
10796 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
10797 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
10798 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
10799 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
10800 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
10801 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
10802 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
10803 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
10804 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
10805 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
10806 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
10807
10808 /* If _PAGE_BIT_PRESENT is clear, we use these: */
10809 @@ -40,7 +39,6 @@
10810 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
10811 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
10812 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
10813 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
10814 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
10815 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
10816 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
10817 @@ -57,8 +55,10 @@
10818
10819 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
10820 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
10821 -#else
10822 +#elif defined(CONFIG_KMEMCHECK)
10823 #define _PAGE_NX (_AT(pteval_t, 0))
10824 +#else
10825 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
10826 #endif
10827
10828 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
10829 @@ -96,6 +96,9 @@
10830 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
10831 _PAGE_ACCESSED)
10832
10833 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
10834 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
10835 +
10836 #define __PAGE_KERNEL_EXEC \
10837 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
10838 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
10839 @@ -106,8 +109,8 @@
10840 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
10841 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
10842 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
10843 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
10844 -#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
10845 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
10846 +#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
10847 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
10848 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
10849 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
10850 @@ -166,8 +169,8 @@
10851 * bits are combined, this will alow user to access the high address mapped
10852 * VDSO in the presence of CONFIG_COMPAT_VDSO
10853 */
10854 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
10855 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
10856 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10857 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
10858 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
10859 #endif
10860
10861 @@ -205,7 +208,17 @@ static inline pgdval_t pgd_flags(pgd_t p
10862 {
10863 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
10864 }
10865 +#endif
10866
10867 +#if PAGETABLE_LEVELS == 3
10868 +#include <asm-generic/pgtable-nopud.h>
10869 +#endif
10870 +
10871 +#if PAGETABLE_LEVELS == 2
10872 +#include <asm-generic/pgtable-nopmd.h>
10873 +#endif
10874 +
10875 +#ifndef __ASSEMBLY__
10876 #if PAGETABLE_LEVELS > 3
10877 typedef struct { pudval_t pud; } pud_t;
10878
10879 @@ -219,8 +232,6 @@ static inline pudval_t native_pud_val(pu
10880 return pud.pud;
10881 }
10882 #else
10883 -#include <asm-generic/pgtable-nopud.h>
10884 -
10885 static inline pudval_t native_pud_val(pud_t pud)
10886 {
10887 return native_pgd_val(pud.pgd);
10888 @@ -240,8 +251,6 @@ static inline pmdval_t native_pmd_val(pm
10889 return pmd.pmd;
10890 }
10891 #else
10892 -#include <asm-generic/pgtable-nopmd.h>
10893 -
10894 static inline pmdval_t native_pmd_val(pmd_t pmd)
10895 {
10896 return native_pgd_val(pmd.pud.pgd);
10897 @@ -281,7 +290,6 @@ typedef struct page *pgtable_t;
10898
10899 extern pteval_t __supported_pte_mask;
10900 extern void set_nx(void);
10901 -extern int nx_enabled;
10902
10903 #define pgprot_writecombine pgprot_writecombine
10904 extern pgprot_t pgprot_writecombine(pgprot_t prot);
10905 diff -urNp linux-2.6.39.2/arch/x86/include/asm/processor.h linux-2.6.39.2/arch/x86/include/asm/processor.h
10906 --- linux-2.6.39.2/arch/x86/include/asm/processor.h 2011-05-19 00:06:34.000000000 -0400
10907 +++ linux-2.6.39.2/arch/x86/include/asm/processor.h 2011-05-22 19:36:30.000000000 -0400
10908 @@ -266,7 +266,7 @@ struct tss_struct {
10909
10910 } ____cacheline_aligned;
10911
10912 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10913 +extern struct tss_struct init_tss[NR_CPUS];
10914
10915 /*
10916 * Save the original ist values for checking stack pointers during debugging
10917 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(co
10918 */
10919 #define TASK_SIZE PAGE_OFFSET
10920 #define TASK_SIZE_MAX TASK_SIZE
10921 +
10922 +#ifdef CONFIG_PAX_SEGMEXEC
10923 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10924 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10925 +#else
10926 #define STACK_TOP TASK_SIZE
10927 -#define STACK_TOP_MAX STACK_TOP
10928 +#endif
10929 +
10930 +#define STACK_TOP_MAX TASK_SIZE
10931
10932 #define INIT_THREAD { \
10933 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10934 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10935 .vm86_info = NULL, \
10936 .sysenter_cs = __KERNEL_CS, \
10937 .io_bitmap_ptr = NULL, \
10938 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(co
10939 */
10940 #define INIT_TSS { \
10941 .x86_tss = { \
10942 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10943 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10944 .ss0 = __KERNEL_DS, \
10945 .ss1 = __KERNEL_CS, \
10946 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10947 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(co
10948 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10949
10950 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10951 -#define KSTK_TOP(info) \
10952 -({ \
10953 - unsigned long *__ptr = (unsigned long *)(info); \
10954 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10955 -})
10956 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10957
10958 /*
10959 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10960 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(str
10961 #define task_pt_regs(task) \
10962 ({ \
10963 struct pt_regs *__regs__; \
10964 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10965 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10966 __regs__ - 1; \
10967 })
10968
10969 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(str
10970 /*
10971 * User space process size. 47bits minus one guard page.
10972 */
10973 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10974 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10975
10976 /* This decides where the kernel will search for a free chunk of vm
10977 * space during mmap's.
10978 */
10979 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10980 - 0xc0000000 : 0xFFFFe000)
10981 + 0xc0000000 : 0xFFFFf000)
10982
10983 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10984 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10985 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(str
10986 #define STACK_TOP_MAX TASK_SIZE_MAX
10987
10988 #define INIT_THREAD { \
10989 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10990 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10991 }
10992
10993 #define INIT_TSS { \
10994 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10995 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10996 }
10997
10998 /*
10999 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs
11000 */
11001 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11002
11003 +#ifdef CONFIG_PAX_SEGMEXEC
11004 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11005 +#endif
11006 +
11007 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11008
11009 /* Get/set a process' ability to use the timestamp counter instruction */
11010 diff -urNp linux-2.6.39.2/arch/x86/include/asm/ptrace.h linux-2.6.39.2/arch/x86/include/asm/ptrace.h
11011 --- linux-2.6.39.2/arch/x86/include/asm/ptrace.h 2011-05-19 00:06:34.000000000 -0400
11012 +++ linux-2.6.39.2/arch/x86/include/asm/ptrace.h 2011-05-22 19:36:30.000000000 -0400
11013 @@ -152,28 +152,29 @@ static inline unsigned long regs_return_
11014 }
11015
11016 /*
11017 - * user_mode_vm(regs) determines whether a register set came from user mode.
11018 + * user_mode(regs) determines whether a register set came from user mode.
11019 * This is true if V8086 mode was enabled OR if the register set was from
11020 * protected mode with RPL-3 CS value. This tricky test checks that with
11021 * one comparison. Many places in the kernel can bypass this full check
11022 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11023 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11024 + * be used.
11025 */
11026 -static inline int user_mode(struct pt_regs *regs)
11027 +static inline int user_mode_novm(struct pt_regs *regs)
11028 {
11029 #ifdef CONFIG_X86_32
11030 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11031 #else
11032 - return !!(regs->cs & 3);
11033 + return !!(regs->cs & SEGMENT_RPL_MASK);
11034 #endif
11035 }
11036
11037 -static inline int user_mode_vm(struct pt_regs *regs)
11038 +static inline int user_mode(struct pt_regs *regs)
11039 {
11040 #ifdef CONFIG_X86_32
11041 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11042 USER_RPL;
11043 #else
11044 - return user_mode(regs);
11045 + return user_mode_novm(regs);
11046 #endif
11047 }
11048
11049 diff -urNp linux-2.6.39.2/arch/x86/include/asm/reboot.h linux-2.6.39.2/arch/x86/include/asm/reboot.h
11050 --- linux-2.6.39.2/arch/x86/include/asm/reboot.h 2011-05-19 00:06:34.000000000 -0400
11051 +++ linux-2.6.39.2/arch/x86/include/asm/reboot.h 2011-05-22 19:36:30.000000000 -0400
11052 @@ -6,19 +6,19 @@
11053 struct pt_regs;
11054
11055 struct machine_ops {
11056 - void (*restart)(char *cmd);
11057 - void (*halt)(void);
11058 - void (*power_off)(void);
11059 + void (* __noreturn restart)(char *cmd);
11060 + void (* __noreturn halt)(void);
11061 + void (* __noreturn power_off)(void);
11062 void (*shutdown)(void);
11063 void (*crash_shutdown)(struct pt_regs *);
11064 - void (*emergency_restart)(void);
11065 + void (* __noreturn emergency_restart)(void);
11066 };
11067
11068 extern struct machine_ops machine_ops;
11069
11070 void native_machine_crash_shutdown(struct pt_regs *regs);
11071 void native_machine_shutdown(void);
11072 -void machine_real_restart(unsigned int type);
11073 +void machine_real_restart(unsigned int type) __noreturn;
11074 /* These must match dispatch_table in reboot_32.S */
11075 #define MRR_BIOS 0
11076 #define MRR_APM 1
11077 diff -urNp linux-2.6.39.2/arch/x86/include/asm/rwsem.h linux-2.6.39.2/arch/x86/include/asm/rwsem.h
11078 --- linux-2.6.39.2/arch/x86/include/asm/rwsem.h 2011-05-19 00:06:34.000000000 -0400
11079 +++ linux-2.6.39.2/arch/x86/include/asm/rwsem.h 2011-05-22 19:36:30.000000000 -0400
11080 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw
11081 {
11082 asm volatile("# beginning down_read\n\t"
11083 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11084 +
11085 +#ifdef CONFIG_PAX_REFCOUNT
11086 + "jno 0f\n"
11087 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11088 + "int $4\n0:\n"
11089 + _ASM_EXTABLE(0b, 0b)
11090 +#endif
11091 +
11092 /* adds 0x00000001 */
11093 " jns 1f\n"
11094 " call call_rwsem_down_read_failed\n"
11095 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(st
11096 "1:\n\t"
11097 " mov %1,%2\n\t"
11098 " add %3,%2\n\t"
11099 +
11100 +#ifdef CONFIG_PAX_REFCOUNT
11101 + "jno 0f\n"
11102 + "sub %3,%2\n"
11103 + "int $4\n0:\n"
11104 + _ASM_EXTABLE(0b, 0b)
11105 +#endif
11106 +
11107 " jle 2f\n\t"
11108 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11109 " jnz 1b\n\t"
11110 @@ -104,6 +120,14 @@ static inline void __down_write_nested(s
11111 long tmp;
11112 asm volatile("# beginning down_write\n\t"
11113 LOCK_PREFIX " xadd %1,(%2)\n\t"
11114 +
11115 +#ifdef CONFIG_PAX_REFCOUNT
11116 + "jno 0f\n"
11117 + "mov %1,(%2)\n"
11118 + "int $4\n0:\n"
11119 + _ASM_EXTABLE(0b, 0b)
11120 +#endif
11121 +
11122 /* adds 0xffff0001, returns the old value */
11123 " test %1,%1\n\t"
11124 /* was the count 0 before? */
11125 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_s
11126 long tmp;
11127 asm volatile("# beginning __up_read\n\t"
11128 LOCK_PREFIX " xadd %1,(%2)\n\t"
11129 +
11130 +#ifdef CONFIG_PAX_REFCOUNT
11131 + "jno 0f\n"
11132 + "mov %1,(%2)\n"
11133 + "int $4\n0:\n"
11134 + _ASM_EXTABLE(0b, 0b)
11135 +#endif
11136 +
11137 /* subtracts 1, returns the old value */
11138 " jns 1f\n\t"
11139 " call call_rwsem_wake\n" /* expects old value in %edx */
11140 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_
11141 long tmp;
11142 asm volatile("# beginning __up_write\n\t"
11143 LOCK_PREFIX " xadd %1,(%2)\n\t"
11144 +
11145 +#ifdef CONFIG_PAX_REFCOUNT
11146 + "jno 0f\n"
11147 + "mov %1,(%2)\n"
11148 + "int $4\n0:\n"
11149 + _ASM_EXTABLE(0b, 0b)
11150 +#endif
11151 +
11152 /* subtracts 0xffff0001, returns the old value */
11153 " jns 1f\n\t"
11154 " call call_rwsem_wake\n" /* expects old value in %edx */
11155 @@ -176,6 +216,14 @@ static inline void __downgrade_write(str
11156 {
11157 asm volatile("# beginning __downgrade_write\n\t"
11158 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11159 +
11160 +#ifdef CONFIG_PAX_REFCOUNT
11161 + "jno 0f\n"
11162 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11163 + "int $4\n0:\n"
11164 + _ASM_EXTABLE(0b, 0b)
11165 +#endif
11166 +
11167 /*
11168 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11169 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11170 @@ -194,7 +242,15 @@ static inline void __downgrade_write(str
11171 */
11172 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11173 {
11174 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11175 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11176 +
11177 +#ifdef CONFIG_PAX_REFCOUNT
11178 + "jno 0f\n"
11179 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11180 + "int $4\n0:\n"
11181 + _ASM_EXTABLE(0b, 0b)
11182 +#endif
11183 +
11184 : "+m" (sem->count)
11185 : "er" (delta));
11186 }
11187 @@ -206,7 +262,15 @@ static inline long rwsem_atomic_update(l
11188 {
11189 long tmp = delta;
11190
11191 - asm volatile(LOCK_PREFIX "xadd %0,%1"
11192 + asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11193 +
11194 +#ifdef CONFIG_PAX_REFCOUNT
11195 + "jno 0f\n"
11196 + "mov %0,%1\n"
11197 + "int $4\n0:\n"
11198 + _ASM_EXTABLE(0b, 0b)
11199 +#endif
11200 +
11201 : "+r" (tmp), "+m" (sem->count)
11202 : : "memory");
11203
11204 diff -urNp linux-2.6.39.2/arch/x86/include/asm/segment.h linux-2.6.39.2/arch/x86/include/asm/segment.h
11205 --- linux-2.6.39.2/arch/x86/include/asm/segment.h 2011-05-19 00:06:34.000000000 -0400
11206 +++ linux-2.6.39.2/arch/x86/include/asm/segment.h 2011-05-22 19:36:30.000000000 -0400
11207 @@ -64,8 +64,8 @@
11208 * 26 - ESPFIX small SS
11209 * 27 - per-cpu [ offset to per-cpu data area ]
11210 * 28 - stack_canary-20 [ for stack protector ]
11211 - * 29 - unused
11212 - * 30 - unused
11213 + * 29 - PCI BIOS CS
11214 + * 30 - PCI BIOS DS
11215 * 31 - TSS for double fault handler
11216 */
11217 #define GDT_ENTRY_TLS_MIN 6
11218 @@ -79,6 +79,8 @@
11219
11220 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
11221
11222 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11223 +
11224 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
11225
11226 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
11227 @@ -104,6 +106,12 @@
11228 #define __KERNEL_STACK_CANARY 0
11229 #endif
11230
11231 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
11232 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11233 +
11234 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
11235 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11236 +
11237 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11238
11239 /*
11240 @@ -141,7 +149,7 @@
11241 */
11242
11243 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11244 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11245 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11246
11247
11248 #else
11249 @@ -165,6 +173,8 @@
11250 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11251 #define __USER32_DS __USER_DS
11252
11253 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11254 +
11255 #define GDT_ENTRY_TSS 8 /* needs two entries */
11256 #define GDT_ENTRY_LDT 10 /* needs two entries */
11257 #define GDT_ENTRY_TLS_MIN 12
11258 @@ -185,6 +195,7 @@
11259 #endif
11260
11261 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
11262 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
11263 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
11264 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
11265 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
11266 diff -urNp linux-2.6.39.2/arch/x86/include/asm/smp.h linux-2.6.39.2/arch/x86/include/asm/smp.h
11267 --- linux-2.6.39.2/arch/x86/include/asm/smp.h 2011-05-19 00:06:34.000000000 -0400
11268 +++ linux-2.6.39.2/arch/x86/include/asm/smp.h 2011-05-22 19:36:30.000000000 -0400
11269 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_
11270 /* cpus sharing the last level cache: */
11271 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
11272 DECLARE_PER_CPU(u16, cpu_llc_id);
11273 -DECLARE_PER_CPU(int, cpu_number);
11274 +DECLARE_PER_CPU(unsigned int, cpu_number);
11275
11276 static inline struct cpumask *cpu_sibling_mask(int cpu)
11277 {
11278 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitd
11279 extern int safe_smp_processor_id(void);
11280
11281 #elif defined(CONFIG_X86_64_SMP)
11282 -#define raw_smp_processor_id() (percpu_read(cpu_number))
11283 -
11284 -#define stack_smp_processor_id() \
11285 -({ \
11286 - struct thread_info *ti; \
11287 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11288 - ti->cpu; \
11289 -})
11290 +#define raw_smp_processor_id() (percpu_read(cpu_number))
11291 +#define stack_smp_processor_id() raw_smp_processor_id()
11292 #define safe_smp_processor_id() smp_processor_id()
11293
11294 #endif
11295 diff -urNp linux-2.6.39.2/arch/x86/include/asm/spinlock.h linux-2.6.39.2/arch/x86/include/asm/spinlock.h
11296 --- linux-2.6.39.2/arch/x86/include/asm/spinlock.h 2011-05-19 00:06:34.000000000 -0400
11297 +++ linux-2.6.39.2/arch/x86/include/asm/spinlock.h 2011-05-22 19:36:30.000000000 -0400
11298 @@ -249,6 +249,14 @@ static inline int arch_write_can_lock(ar
11299 static inline void arch_read_lock(arch_rwlock_t *rw)
11300 {
11301 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11302 +
11303 +#ifdef CONFIG_PAX_REFCOUNT
11304 + "jno 0f\n"
11305 + LOCK_PREFIX " addl $1,(%0)\n"
11306 + "int $4\n0:\n"
11307 + _ASM_EXTABLE(0b, 0b)
11308 +#endif
11309 +
11310 "jns 1f\n"
11311 "call __read_lock_failed\n\t"
11312 "1:\n"
11313 @@ -258,6 +266,14 @@ static inline void arch_read_lock(arch_r
11314 static inline void arch_write_lock(arch_rwlock_t *rw)
11315 {
11316 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11317 +
11318 +#ifdef CONFIG_PAX_REFCOUNT
11319 + "jno 0f\n"
11320 + LOCK_PREFIX " addl %1,(%0)\n"
11321 + "int $4\n0:\n"
11322 + _ASM_EXTABLE(0b, 0b)
11323 +#endif
11324 +
11325 "jz 1f\n"
11326 "call __write_lock_failed\n\t"
11327 "1:\n"
11328 @@ -286,12 +302,29 @@ static inline int arch_write_trylock(arc
11329
11330 static inline void arch_read_unlock(arch_rwlock_t *rw)
11331 {
11332 - asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11333 + asm volatile(LOCK_PREFIX "incl %0\n"
11334 +
11335 +#ifdef CONFIG_PAX_REFCOUNT
11336 + "jno 0f\n"
11337 + LOCK_PREFIX "decl %0\n"
11338 + "int $4\n0:\n"
11339 + _ASM_EXTABLE(0b, 0b)
11340 +#endif
11341 +
11342 + :"+m" (rw->lock) : : "memory");
11343 }
11344
11345 static inline void arch_write_unlock(arch_rwlock_t *rw)
11346 {
11347 - asm volatile(LOCK_PREFIX "addl %1, %0"
11348 + asm volatile(LOCK_PREFIX "addl %1, %0\n"
11349 +
11350 +#ifdef CONFIG_PAX_REFCOUNT
11351 + "jno 0f\n"
11352 + LOCK_PREFIX "subl %1, %0\n"
11353 + "int $4\n0:\n"
11354 + _ASM_EXTABLE(0b, 0b)
11355 +#endif
11356 +
11357 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11358 }
11359
11360 diff -urNp linux-2.6.39.2/arch/x86/include/asm/stackprotector.h linux-2.6.39.2/arch/x86/include/asm/stackprotector.h
11361 --- linux-2.6.39.2/arch/x86/include/asm/stackprotector.h 2011-05-19 00:06:34.000000000 -0400
11362 +++ linux-2.6.39.2/arch/x86/include/asm/stackprotector.h 2011-05-22 19:36:30.000000000 -0400
11363 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_se
11364
11365 static inline void load_stack_canary_segment(void)
11366 {
11367 -#ifdef CONFIG_X86_32
11368 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11369 asm volatile ("mov %0, %%gs" : : "r" (0));
11370 #endif
11371 }
11372 diff -urNp linux-2.6.39.2/arch/x86/include/asm/stacktrace.h linux-2.6.39.2/arch/x86/include/asm/stacktrace.h
11373 --- linux-2.6.39.2/arch/x86/include/asm/stacktrace.h 2011-05-19 00:06:34.000000000 -0400
11374 +++ linux-2.6.39.2/arch/x86/include/asm/stacktrace.h 2011-05-22 19:36:30.000000000 -0400
11375 @@ -11,28 +11,20 @@
11376
11377 extern int kstack_depth_to_print;
11378
11379 -struct thread_info;
11380 +struct task_struct;
11381 struct stacktrace_ops;
11382
11383 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
11384 - unsigned long *stack,
11385 - unsigned long bp,
11386 - const struct stacktrace_ops *ops,
11387 - void *data,
11388 - unsigned long *end,
11389 - int *graph);
11390 -
11391 -extern unsigned long
11392 -print_context_stack(struct thread_info *tinfo,
11393 - unsigned long *stack, unsigned long bp,
11394 - const struct stacktrace_ops *ops, void *data,
11395 - unsigned long *end, int *graph);
11396 -
11397 -extern unsigned long
11398 -print_context_stack_bp(struct thread_info *tinfo,
11399 - unsigned long *stack, unsigned long bp,
11400 - const struct stacktrace_ops *ops, void *data,
11401 - unsigned long *end, int *graph);
11402 +typedef unsigned long walk_stack_t(struct task_struct *task,
11403 + void *stack_start,
11404 + unsigned long *stack,
11405 + unsigned long bp,
11406 + const struct stacktrace_ops *ops,
11407 + void *data,
11408 + unsigned long *end,
11409 + int *graph);
11410 +
11411 +extern walk_stack_t print_context_stack;
11412 +extern walk_stack_t print_context_stack_bp;
11413
11414 /* Generic stack tracer with callbacks */
11415
11416 @@ -43,7 +35,7 @@ struct stacktrace_ops {
11417 void (*address)(void *data, unsigned long address, int reliable);
11418 /* On negative return stop dumping */
11419 int (*stack)(void *data, char *name);
11420 - walk_stack_t walk_stack;
11421 + walk_stack_t *walk_stack;
11422 };
11423
11424 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
11425 diff -urNp linux-2.6.39.2/arch/x86/include/asm/system.h linux-2.6.39.2/arch/x86/include/asm/system.h
11426 --- linux-2.6.39.2/arch/x86/include/asm/system.h 2011-05-19 00:06:34.000000000 -0400
11427 +++ linux-2.6.39.2/arch/x86/include/asm/system.h 2011-05-22 19:36:30.000000000 -0400
11428 @@ -129,7 +129,7 @@ do { \
11429 "call __switch_to\n\t" \
11430 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11431 __switch_canary \
11432 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
11433 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11434 "movq %%rax,%%rdi\n\t" \
11435 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11436 "jnz ret_from_fork\n\t" \
11437 @@ -140,7 +140,7 @@ do { \
11438 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11439 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11440 [_tif_fork] "i" (_TIF_FORK), \
11441 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
11442 + [thread_info] "m" (current_tinfo), \
11443 [current_task] "m" (current_task) \
11444 __switch_canary_iparam \
11445 : "memory", "cc" __EXTRA_CLOBBER)
11446 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(un
11447 {
11448 unsigned long __limit;
11449 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11450 - return __limit + 1;
11451 + return __limit;
11452 }
11453
11454 static inline void native_clts(void)
11455 @@ -340,12 +340,12 @@ void enable_hlt(void);
11456
11457 void cpu_idle_wait(void);
11458
11459 -extern unsigned long arch_align_stack(unsigned long sp);
11460 +#define arch_align_stack(x) ((x) & ~0xfUL)
11461 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11462
11463 void default_idle(void);
11464
11465 -void stop_this_cpu(void *dummy);
11466 +void stop_this_cpu(void *dummy) __noreturn;
11467
11468 /*
11469 * Force strict CPU ordering.
11470 diff -urNp linux-2.6.39.2/arch/x86/include/asm/thread_info.h linux-2.6.39.2/arch/x86/include/asm/thread_info.h
11471 --- linux-2.6.39.2/arch/x86/include/asm/thread_info.h 2011-05-19 00:06:34.000000000 -0400
11472 +++ linux-2.6.39.2/arch/x86/include/asm/thread_info.h 2011-05-22 19:36:30.000000000 -0400
11473 @@ -10,6 +10,7 @@
11474 #include <linux/compiler.h>
11475 #include <asm/page.h>
11476 #include <asm/types.h>
11477 +#include <asm/percpu.h>
11478
11479 /*
11480 * low level task data that entry.S needs immediate access to
11481 @@ -24,7 +25,6 @@ struct exec_domain;
11482 #include <asm/atomic.h>
11483
11484 struct thread_info {
11485 - struct task_struct *task; /* main task structure */
11486 struct exec_domain *exec_domain; /* execution domain */
11487 __u32 flags; /* low level flags */
11488 __u32 status; /* thread synchronous flags */
11489 @@ -34,18 +34,12 @@ struct thread_info {
11490 mm_segment_t addr_limit;
11491 struct restart_block restart_block;
11492 void __user *sysenter_return;
11493 -#ifdef CONFIG_X86_32
11494 - unsigned long previous_esp; /* ESP of the previous stack in
11495 - case of nested (IRQ) stacks
11496 - */
11497 - __u8 supervisor_stack[0];
11498 -#endif
11499 + unsigned long lowest_stack;
11500 int uaccess_err;
11501 };
11502
11503 -#define INIT_THREAD_INFO(tsk) \
11504 +#define INIT_THREAD_INFO \
11505 { \
11506 - .task = &tsk, \
11507 .exec_domain = &default_exec_domain, \
11508 .flags = 0, \
11509 .cpu = 0, \
11510 @@ -56,7 +50,7 @@ struct thread_info {
11511 }, \
11512 }
11513
11514 -#define init_thread_info (init_thread_union.thread_info)
11515 +#define init_thread_info (init_thread_union.stack)
11516 #define init_stack (init_thread_union.stack)
11517
11518 #else /* !__ASSEMBLY__ */
11519 @@ -170,6 +164,23 @@ struct thread_info {
11520 ret; \
11521 })
11522
11523 +#ifdef __ASSEMBLY__
11524 +/* how to get the thread information struct from ASM */
11525 +#define GET_THREAD_INFO(reg) \
11526 + mov PER_CPU_VAR(current_tinfo), reg
11527 +
11528 +/* use this one if reg already contains %esp */
11529 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
11530 +#else
11531 +/* how to get the thread information struct from C */
11532 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
11533 +
11534 +static __always_inline struct thread_info *current_thread_info(void)
11535 +{
11536 + return percpu_read_stable(current_tinfo);
11537 +}
11538 +#endif
11539 +
11540 #ifdef CONFIG_X86_32
11541
11542 #define STACK_WARN (THREAD_SIZE/8)
11543 @@ -180,35 +191,13 @@ struct thread_info {
11544 */
11545 #ifndef __ASSEMBLY__
11546
11547 -
11548 /* how to get the current stack pointer from C */
11549 register unsigned long current_stack_pointer asm("esp") __used;
11550
11551 -/* how to get the thread information struct from C */
11552 -static inline struct thread_info *current_thread_info(void)
11553 -{
11554 - return (struct thread_info *)
11555 - (current_stack_pointer & ~(THREAD_SIZE - 1));
11556 -}
11557 -
11558 -#else /* !__ASSEMBLY__ */
11559 -
11560 -/* how to get the thread information struct from ASM */
11561 -#define GET_THREAD_INFO(reg) \
11562 - movl $-THREAD_SIZE, reg; \
11563 - andl %esp, reg
11564 -
11565 -/* use this one if reg already contains %esp */
11566 -#define GET_THREAD_INFO_WITH_ESP(reg) \
11567 - andl $-THREAD_SIZE, reg
11568 -
11569 #endif
11570
11571 #else /* X86_32 */
11572
11573 -#include <asm/percpu.h>
11574 -#define KERNEL_STACK_OFFSET (5*8)
11575 -
11576 /*
11577 * macros/functions for gaining access to the thread information structure
11578 * preempt_count needs to be 1 initially, until the scheduler is functional.
11579 @@ -216,21 +205,8 @@ static inline struct thread_info *curren
11580 #ifndef __ASSEMBLY__
11581 DECLARE_PER_CPU(unsigned long, kernel_stack);
11582
11583 -static inline struct thread_info *current_thread_info(void)
11584 -{
11585 - struct thread_info *ti;
11586 - ti = (void *)(percpu_read_stable(kernel_stack) +
11587 - KERNEL_STACK_OFFSET - THREAD_SIZE);
11588 - return ti;
11589 -}
11590 -
11591 -#else /* !__ASSEMBLY__ */
11592 -
11593 -/* how to get the thread information struct from ASM */
11594 -#define GET_THREAD_INFO(reg) \
11595 - movq PER_CPU_VAR(kernel_stack),reg ; \
11596 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
11597 -
11598 +/* how to get the current stack pointer from C */
11599 +register unsigned long current_stack_pointer asm("rsp") __used;
11600 #endif
11601
11602 #endif /* !X86_32 */
11603 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
11604 extern void free_thread_info(struct thread_info *ti);
11605 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
11606 #define arch_task_cache_init arch_task_cache_init
11607 +
11608 +#define __HAVE_THREAD_FUNCTIONS
11609 +#define task_thread_info(task) (&(task)->tinfo)
11610 +#define task_stack_page(task) ((task)->stack)
11611 +#define setup_thread_stack(p, org) do {} while (0)
11612 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
11613 +
11614 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
11615 +extern struct task_struct *alloc_task_struct_node(int node);
11616 +extern void free_task_struct(struct task_struct *);
11617 +
11618 #endif
11619 #endif /* _ASM_X86_THREAD_INFO_H */
11620 diff -urNp linux-2.6.39.2/arch/x86/include/asm/uaccess_32.h linux-2.6.39.2/arch/x86/include/asm/uaccess_32.h
11621 --- linux-2.6.39.2/arch/x86/include/asm/uaccess_32.h 2011-05-19 00:06:34.000000000 -0400
11622 +++ linux-2.6.39.2/arch/x86/include/asm/uaccess_32.h 2011-05-22 19:36:30.000000000 -0400
11623 @@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_u
11624 static __always_inline unsigned long __must_check
11625 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11626 {
11627 + pax_track_stack();
11628 +
11629 + if ((long)n < 0)
11630 + return n;
11631 +
11632 if (__builtin_constant_p(n)) {
11633 unsigned long ret;
11634
11635 @@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to,
11636 return ret;
11637 }
11638 }
11639 + if (!__builtin_constant_p(n))
11640 + check_object_size(from, n, true);
11641 return __copy_to_user_ll(to, from, n);
11642 }
11643
11644 @@ -83,12 +90,16 @@ static __always_inline unsigned long __m
11645 __copy_to_user(void __user *to, const void *from, unsigned long n)
11646 {
11647 might_fault();
11648 +
11649 return __copy_to_user_inatomic(to, from, n);
11650 }
11651
11652 static __always_inline unsigned long
11653 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11654 {
11655 + if ((long)n < 0)
11656 + return n;
11657 +
11658 /* Avoid zeroing the tail if the copy fails..
11659 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11660 * but as the zeroing behaviour is only significant when n is not
11661 @@ -138,6 +149,12 @@ static __always_inline unsigned long
11662 __copy_from_user(void *to, const void __user *from, unsigned long n)
11663 {
11664 might_fault();
11665 +
11666 + pax_track_stack();
11667 +
11668 + if ((long)n < 0)
11669 + return n;
11670 +
11671 if (__builtin_constant_p(n)) {
11672 unsigned long ret;
11673
11674 @@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __
11675 return ret;
11676 }
11677 }
11678 + if (!__builtin_constant_p(n))
11679 + check_object_size(to, n, false);
11680 return __copy_from_user_ll(to, from, n);
11681 }
11682
11683 @@ -160,6 +179,10 @@ static __always_inline unsigned long __c
11684 const void __user *from, unsigned long n)
11685 {
11686 might_fault();
11687 +
11688 + if ((long)n < 0)
11689 + return n;
11690 +
11691 if (__builtin_constant_p(n)) {
11692 unsigned long ret;
11693
11694 @@ -182,15 +205,19 @@ static __always_inline unsigned long
11695 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11696 unsigned long n)
11697 {
11698 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11699 -}
11700 + if ((long)n < 0)
11701 + return n;
11702
11703 -unsigned long __must_check copy_to_user(void __user *to,
11704 - const void *from, unsigned long n);
11705 -unsigned long __must_check _copy_from_user(void *to,
11706 - const void __user *from,
11707 - unsigned long n);
11708 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11709 +}
11710
11711 +extern void copy_to_user_overflow(void)
11712 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11713 + __compiletime_error("copy_to_user() buffer size is not provably correct")
11714 +#else
11715 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
11716 +#endif
11717 +;
11718
11719 extern void copy_from_user_overflow(void)
11720 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11721 @@ -200,17 +227,61 @@ extern void copy_from_user_overflow(void
11722 #endif
11723 ;
11724
11725 -static inline unsigned long __must_check copy_from_user(void *to,
11726 - const void __user *from,
11727 - unsigned long n)
11728 +/**
11729 + * copy_to_user: - Copy a block of data into user space.
11730 + * @to: Destination address, in user space.
11731 + * @from: Source address, in kernel space.
11732 + * @n: Number of bytes to copy.
11733 + *
11734 + * Context: User context only. This function may sleep.
11735 + *
11736 + * Copy data from kernel space to user space.
11737 + *
11738 + * Returns number of bytes that could not be copied.
11739 + * On success, this will be zero.
11740 + */
11741 +static inline unsigned long __must_check
11742 +copy_to_user(void __user *to, const void *from, unsigned long n)
11743 +{
11744 + int sz = __compiletime_object_size(from);
11745 +
11746 + if (unlikely(sz != -1 && sz < n))
11747 + copy_to_user_overflow();
11748 + else if (access_ok(VERIFY_WRITE, to, n))
11749 + n = __copy_to_user(to, from, n);
11750 + return n;
11751 +}
11752 +
11753 +/**
11754 + * copy_from_user: - Copy a block of data from user space.
11755 + * @to: Destination address, in kernel space.
11756 + * @from: Source address, in user space.
11757 + * @n: Number of bytes to copy.
11758 + *
11759 + * Context: User context only. This function may sleep.
11760 + *
11761 + * Copy data from user space to kernel space.
11762 + *
11763 + * Returns number of bytes that could not be copied.
11764 + * On success, this will be zero.
11765 + *
11766 + * If some data could not be copied, this function will pad the copied
11767 + * data to the requested size using zero bytes.
11768 + */
11769 +static inline unsigned long __must_check
11770 +copy_from_user(void *to, const void __user *from, unsigned long n)
11771 {
11772 int sz = __compiletime_object_size(to);
11773
11774 - if (likely(sz == -1 || sz >= n))
11775 - n = _copy_from_user(to, from, n);
11776 - else
11777 + if (unlikely(sz != -1 && sz < n))
11778 copy_from_user_overflow();
11779 -
11780 + else if (access_ok(VERIFY_READ, from, n))
11781 + n = __copy_from_user(to, from, n);
11782 + else if ((long)n > 0) {
11783 + if (!__builtin_constant_p(n))
11784 + check_object_size(to, n, false);
11785 + memset(to, 0, n);
11786 + }
11787 return n;
11788 }
11789
11790 diff -urNp linux-2.6.39.2/arch/x86/include/asm/uaccess_64.h linux-2.6.39.2/arch/x86/include/asm/uaccess_64.h
11791 --- linux-2.6.39.2/arch/x86/include/asm/uaccess_64.h 2011-05-19 00:06:34.000000000 -0400
11792 +++ linux-2.6.39.2/arch/x86/include/asm/uaccess_64.h 2011-05-22 19:36:30.000000000 -0400
11793 @@ -11,6 +11,9 @@
11794 #include <asm/alternative.h>
11795 #include <asm/cpufeature.h>
11796 #include <asm/page.h>
11797 +#include <asm/pgtable.h>
11798 +
11799 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11800
11801 /*
11802 * Copy To/From Userspace
11803 @@ -37,26 +40,26 @@ copy_user_generic(void *to, const void *
11804 return ret;
11805 }
11806
11807 -__must_check unsigned long
11808 -_copy_to_user(void __user *to, const void *from, unsigned len);
11809 -__must_check unsigned long
11810 -_copy_from_user(void *to, const void __user *from, unsigned len);
11811 +static __always_inline __must_check unsigned long
11812 +__copy_to_user(void __user *to, const void *from, unsigned len);
11813 +static __always_inline __must_check unsigned long
11814 +__copy_from_user(void *to, const void __user *from, unsigned len);
11815 __must_check unsigned long
11816 copy_in_user(void __user *to, const void __user *from, unsigned len);
11817
11818 static inline unsigned long __must_check copy_from_user(void *to,
11819 const void __user *from,
11820 - unsigned long n)
11821 + unsigned n)
11822 {
11823 - int sz = __compiletime_object_size(to);
11824 -
11825 might_fault();
11826 - if (likely(sz == -1 || sz >= n))
11827 - n = _copy_from_user(to, from, n);
11828 -#ifdef CONFIG_DEBUG_VM
11829 - else
11830 - WARN(1, "Buffer overflow detected!\n");
11831 -#endif
11832 +
11833 + if (access_ok(VERIFY_READ, from, n))
11834 + n = __copy_from_user(to, from, n);
11835 + else if ((int)n > 0) {
11836 + if (!__builtin_constant_p(n))
11837 + check_object_size(to, n, false);
11838 + memset(to, 0, n);
11839 + }
11840 return n;
11841 }
11842
11843 @@ -65,110 +68,198 @@ int copy_to_user(void __user *dst, const
11844 {
11845 might_fault();
11846
11847 - return _copy_to_user(dst, src, size);
11848 + if (access_ok(VERIFY_WRITE, dst, size))
11849 + size = __copy_to_user(dst, src, size);
11850 + return size;
11851 }
11852
11853 static __always_inline __must_check
11854 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11855 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned size)
11856 {
11857 - int ret = 0;
11858 + int sz = __compiletime_object_size(dst);
11859 + unsigned ret = 0;
11860
11861 might_fault();
11862 - if (!__builtin_constant_p(size))
11863 - return copy_user_generic(dst, (__force void *)src, size);
11864 +
11865 + pax_track_stack();
11866 +
11867 + if ((int)size < 0)
11868 + return size;
11869 +
11870 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11871 + if (!__access_ok(VERIFY_READ, src, size))
11872 + return size;
11873 +#endif
11874 +
11875 + if (unlikely(sz != -1 && sz < size)) {
11876 +#ifdef CONFIG_DEBUG_VM
11877 + WARN(1, "Buffer overflow detected!\n");
11878 +#endif
11879 + return size;
11880 + }
11881 +
11882 + if (!__builtin_constant_p(size)) {
11883 + check_object_size(dst, size, false);
11884 +
11885 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11886 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11887 + src += PAX_USER_SHADOW_BASE;
11888 +#endif
11889 +
11890 + return copy_user_generic(dst, (__force const void *)src, size);
11891 + }
11892 switch (size) {
11893 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11894 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11895 ret, "b", "b", "=q", 1);
11896 return ret;
11897 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11898 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11899 ret, "w", "w", "=r", 2);
11900 return ret;
11901 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11902 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11903 ret, "l", "k", "=r", 4);
11904 return ret;
11905 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11906 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11907 ret, "q", "", "=r", 8);
11908 return ret;
11909 case 10:
11910 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11911 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11912 ret, "q", "", "=r", 10);
11913 if (unlikely(ret))
11914 return ret;
11915 __get_user_asm(*(u16 *)(8 + (char *)dst),
11916 - (u16 __user *)(8 + (char __user *)src),
11917 + (const u16 __user *)(8 + (const char __user *)src),
11918 ret, "w", "w", "=r", 2);
11919 return ret;
11920 case 16:
11921 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11922 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11923 ret, "q", "", "=r", 16);
11924 if (unlikely(ret))
11925 return ret;
11926 __get_user_asm(*(u64 *)(8 + (char *)dst),
11927 - (u64 __user *)(8 + (char __user *)src),
11928 + (const u64 __user *)(8 + (const char __user *)src),
11929 ret, "q", "", "=r", 8);
11930 return ret;
11931 default:
11932 - return copy_user_generic(dst, (__force void *)src, size);
11933 +
11934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11935 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11936 + src += PAX_USER_SHADOW_BASE;
11937 +#endif
11938 +
11939 + return copy_user_generic(dst, (__force const void *)src, size);
11940 }
11941 }
11942
11943 static __always_inline __must_check
11944 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11945 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned size)
11946 {
11947 - int ret = 0;
11948 + int sz = __compiletime_object_size(src);
11949 + unsigned ret = 0;
11950
11951 might_fault();
11952 - if (!__builtin_constant_p(size))
11953 +
11954 + pax_track_stack();
11955 +
11956 + if ((int)size < 0)
11957 + return size;
11958 +
11959 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11960 + if (!__access_ok(VERIFY_WRITE, dst, size))
11961 + return size;
11962 +#endif
11963 +
11964 + if (unlikely(sz != -1 && sz < size)) {
11965 +#ifdef CONFIG_DEBUG_VM
11966 + WARN(1, "Buffer overflow detected!\n");
11967 +#endif
11968 + return size;
11969 + }
11970 +
11971 + if (!__builtin_constant_p(size)) {
11972 + check_object_size(src, size, true);
11973 +
11974 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11975 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11976 + dst += PAX_USER_SHADOW_BASE;
11977 +#endif
11978 +
11979 return copy_user_generic((__force void *)dst, src, size);
11980 + }
11981 switch (size) {
11982 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11983 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11984 ret, "b", "b", "iq", 1);
11985 return ret;
11986 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11987 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11988 ret, "w", "w", "ir", 2);
11989 return ret;
11990 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11991 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11992 ret, "l", "k", "ir", 4);
11993 return ret;
11994 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11995 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11996 ret, "q", "", "er", 8);
11997 return ret;
11998 case 10:
11999 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12000 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12001 ret, "q", "", "er", 10);
12002 if (unlikely(ret))
12003 return ret;
12004 asm("":::"memory");
12005 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12006 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12007 ret, "w", "w", "ir", 2);
12008 return ret;
12009 case 16:
12010 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12011 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12012 ret, "q", "", "er", 16);
12013 if (unlikely(ret))
12014 return ret;
12015 asm("":::"memory");
12016 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12017 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12018 ret, "q", "", "er", 8);
12019 return ret;
12020 default:
12021 +
12022 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12023 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12024 + dst += PAX_USER_SHADOW_BASE;
12025 +#endif
12026 +
12027 return copy_user_generic((__force void *)dst, src, size);
12028 }
12029 }
12030
12031 static __always_inline __must_check
12032 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12033 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12034 {
12035 - int ret = 0;
12036 + unsigned ret = 0;
12037
12038 might_fault();
12039 - if (!__builtin_constant_p(size))
12040 +
12041 + if ((int)size < 0)
12042 + return size;
12043 +
12044 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12045 + if (!__access_ok(VERIFY_READ, src, size))
12046 + return size;
12047 + if (!__access_ok(VERIFY_WRITE, dst, size))
12048 + return size;
12049 +#endif
12050 +
12051 + if (!__builtin_constant_p(size)) {
12052 +
12053 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12054 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12055 + src += PAX_USER_SHADOW_BASE;
12056 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12057 + dst += PAX_USER_SHADOW_BASE;
12058 +#endif
12059 +
12060 return copy_user_generic((__force void *)dst,
12061 - (__force void *)src, size);
12062 + (__force const void *)src, size);
12063 + }
12064 switch (size) {
12065 case 1: {
12066 u8 tmp;
12067 - __get_user_asm(tmp, (u8 __user *)src,
12068 + __get_user_asm(tmp, (const u8 __user *)src,
12069 ret, "b", "b", "=q", 1);
12070 if (likely(!ret))
12071 __put_user_asm(tmp, (u8 __user *)dst,
12072 @@ -177,7 +268,7 @@ int __copy_in_user(void __user *dst, con
12073 }
12074 case 2: {
12075 u16 tmp;
12076 - __get_user_asm(tmp, (u16 __user *)src,
12077 + __get_user_asm(tmp, (const u16 __user *)src,
12078 ret, "w", "w", "=r", 2);
12079 if (likely(!ret))
12080 __put_user_asm(tmp, (u16 __user *)dst,
12081 @@ -187,7 +278,7 @@ int __copy_in_user(void __user *dst, con
12082
12083 case 4: {
12084 u32 tmp;
12085 - __get_user_asm(tmp, (u32 __user *)src,
12086 + __get_user_asm(tmp, (const u32 __user *)src,
12087 ret, "l", "k", "=r", 4);
12088 if (likely(!ret))
12089 __put_user_asm(tmp, (u32 __user *)dst,
12090 @@ -196,7 +287,7 @@ int __copy_in_user(void __user *dst, con
12091 }
12092 case 8: {
12093 u64 tmp;
12094 - __get_user_asm(tmp, (u64 __user *)src,
12095 + __get_user_asm(tmp, (const u64 __user *)src,
12096 ret, "q", "", "=r", 8);
12097 if (likely(!ret))
12098 __put_user_asm(tmp, (u64 __user *)dst,
12099 @@ -204,8 +295,16 @@ int __copy_in_user(void __user *dst, con
12100 return ret;
12101 }
12102 default:
12103 +
12104 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12105 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12106 + src += PAX_USER_SHADOW_BASE;
12107 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12108 + dst += PAX_USER_SHADOW_BASE;
12109 +#endif
12110 +
12111 return copy_user_generic((__force void *)dst,
12112 - (__force void *)src, size);
12113 + (__force const void *)src, size);
12114 }
12115 }
12116
12117 @@ -222,33 +321,72 @@ __must_check unsigned long __clear_user(
12118 static __must_check __always_inline int
12119 __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
12120 {
12121 + pax_track_stack();
12122 +
12123 + if ((int)size < 0)
12124 + return size;
12125 +
12126 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12127 + if (!__access_ok(VERIFY_READ, src, size))
12128 + return size;
12129 +
12130 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12131 + src += PAX_USER_SHADOW_BASE;
12132 +#endif
12133 +
12134 return copy_user_generic(dst, (__force const void *)src, size);
12135 }
12136
12137 -static __must_check __always_inline int
12138 +static __must_check __always_inline unsigned long
12139 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12140 {
12141 + if ((int)size < 0)
12142 + return size;
12143 +
12144 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12145 + if (!__access_ok(VERIFY_WRITE, dst, size))
12146 + return size;
12147 +
12148 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12149 + dst += PAX_USER_SHADOW_BASE;
12150 +#endif
12151 +
12152 return copy_user_generic((__force void *)dst, src, size);
12153 }
12154
12155 -extern long __copy_user_nocache(void *dst, const void __user *src,
12156 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12157 unsigned size, int zerorest);
12158
12159 -static inline int
12160 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12161 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12162 {
12163 might_sleep();
12164 +
12165 + if ((int)size < 0)
12166 + return size;
12167 +
12168 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12169 + if (!__access_ok(VERIFY_READ, src, size))
12170 + return size;
12171 +#endif
12172 +
12173 return __copy_user_nocache(dst, src, size, 1);
12174 }
12175
12176 -static inline int
12177 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12178 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12179 unsigned size)
12180 {
12181 + if ((int)size < 0)
12182 + return size;
12183 +
12184 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12185 + if (!__access_ok(VERIFY_READ, src, size))
12186 + return size;
12187 +#endif
12188 +
12189 return __copy_user_nocache(dst, src, size, 0);
12190 }
12191
12192 -unsigned long
12193 +extern unsigned long
12194 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12195
12196 #endif /* _ASM_X86_UACCESS_64_H */
12197 diff -urNp linux-2.6.39.2/arch/x86/include/asm/uaccess.h linux-2.6.39.2/arch/x86/include/asm/uaccess.h
12198 --- linux-2.6.39.2/arch/x86/include/asm/uaccess.h 2011-06-03 00:04:13.000000000 -0400
12199 +++ linux-2.6.39.2/arch/x86/include/asm/uaccess.h 2011-06-03 00:32:04.000000000 -0400
12200 @@ -8,12 +8,15 @@
12201 #include <linux/thread_info.h>
12202 #include <linux/prefetch.h>
12203 #include <linux/string.h>
12204 +#include <linux/sched.h>
12205 #include <asm/asm.h>
12206 #include <asm/page.h>
12207
12208 #define VERIFY_READ 0
12209 #define VERIFY_WRITE 1
12210
12211 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12212 +
12213 /*
12214 * The fs value determines whether argument validity checking should be
12215 * performed or not. If get_fs() == USER_DS, checking is performed, with
12216 @@ -29,7 +32,12 @@
12217
12218 #define get_ds() (KERNEL_DS)
12219 #define get_fs() (current_thread_info()->addr_limit)
12220 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12221 +void __set_fs(mm_segment_t x);
12222 +void set_fs(mm_segment_t x);
12223 +#else
12224 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12225 +#endif
12226
12227 #define segment_eq(a, b) ((a).seg == (b).seg)
12228
12229 @@ -77,7 +85,33 @@
12230 * checks that the pointer is in the user space range - after calling
12231 * this function, memory access functions may still return -EFAULT.
12232 */
12233 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12234 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12235 +#define access_ok(type, addr, size) \
12236 +({ \
12237 + long __size = size; \
12238 + unsigned long __addr = (unsigned long)addr; \
12239 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12240 + unsigned long __end_ao = __addr + __size - 1; \
12241 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12242 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12243 + while(__addr_ao <= __end_ao) { \
12244 + char __c_ao; \
12245 + __addr_ao += PAGE_SIZE; \
12246 + if (__size > PAGE_SIZE) \
12247 + cond_resched(); \
12248 + if (__get_user(__c_ao, (char __user *)__addr)) \
12249 + break; \
12250 + if (type != VERIFY_WRITE) { \
12251 + __addr = __addr_ao; \
12252 + continue; \
12253 + } \
12254 + if (__put_user(__c_ao, (char __user *)__addr)) \
12255 + break; \
12256 + __addr = __addr_ao; \
12257 + } \
12258 + } \
12259 + __ret_ao; \
12260 +})
12261
12262 /*
12263 * The exception table consists of pairs of addresses: the first is the
12264 @@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12265 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12266 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12267
12268 -
12269 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12270 +#define __copyuser_seg "gs;"
12271 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12272 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12273 +#else
12274 +#define __copyuser_seg
12275 +#define __COPYUSER_SET_ES
12276 +#define __COPYUSER_RESTORE_ES
12277 +#endif
12278
12279 #ifdef CONFIG_X86_32
12280 #define __put_user_asm_u64(x, addr, err, errret) \
12281 - asm volatile("1: movl %%eax,0(%2)\n" \
12282 - "2: movl %%edx,4(%2)\n" \
12283 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12284 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12285 "3:\n" \
12286 ".section .fixup,\"ax\"\n" \
12287 "4: movl %3,%0\n" \
12288 @@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12289 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12290
12291 #define __put_user_asm_ex_u64(x, addr) \
12292 - asm volatile("1: movl %%eax,0(%1)\n" \
12293 - "2: movl %%edx,4(%1)\n" \
12294 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12295 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12296 "3:\n" \
12297 _ASM_EXTABLE(1b, 2b - 1b) \
12298 _ASM_EXTABLE(2b, 3b - 2b) \
12299 @@ -374,7 +416,7 @@ do { \
12300 } while (0)
12301
12302 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12303 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12304 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12305 "2:\n" \
12306 ".section .fixup,\"ax\"\n" \
12307 "3: mov %3,%0\n" \
12308 @@ -382,7 +424,7 @@ do { \
12309 " jmp 2b\n" \
12310 ".previous\n" \
12311 _ASM_EXTABLE(1b, 3b) \
12312 - : "=r" (err), ltype(x) \
12313 + : "=r" (err), ltype (x) \
12314 : "m" (__m(addr)), "i" (errret), "0" (err))
12315
12316 #define __get_user_size_ex(x, ptr, size) \
12317 @@ -407,7 +449,7 @@ do { \
12318 } while (0)
12319
12320 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12321 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12322 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12323 "2:\n" \
12324 _ASM_EXTABLE(1b, 2b - 1b) \
12325 : ltype(x) : "m" (__m(addr)))
12326 @@ -424,13 +466,24 @@ do { \
12327 int __gu_err; \
12328 unsigned long __gu_val; \
12329 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12330 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12331 + (x) = (__typeof__(*(ptr)))__gu_val; \
12332 __gu_err; \
12333 })
12334
12335 /* FIXME: this hack is definitely wrong -AK */
12336 struct __large_struct { unsigned long buf[100]; };
12337 -#define __m(x) (*(struct __large_struct __user *)(x))
12338 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12339 +#define ____m(x) \
12340 +({ \
12341 + unsigned long ____x = (unsigned long)(x); \
12342 + if (____x < PAX_USER_SHADOW_BASE) \
12343 + ____x += PAX_USER_SHADOW_BASE; \
12344 + (void __user *)____x; \
12345 +})
12346 +#else
12347 +#define ____m(x) (x)
12348 +#endif
12349 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12350
12351 /*
12352 * Tell gcc we read from memory instead of writing: this is because
12353 @@ -438,7 +491,7 @@ struct __large_struct { unsigned long bu
12354 * aliasing issues.
12355 */
12356 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12357 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12358 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12359 "2:\n" \
12360 ".section .fixup,\"ax\"\n" \
12361 "3: mov %3,%0\n" \
12362 @@ -446,10 +499,10 @@ struct __large_struct { unsigned long bu
12363 ".previous\n" \
12364 _ASM_EXTABLE(1b, 3b) \
12365 : "=r"(err) \
12366 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12367 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12368
12369 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12370 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12371 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12372 "2:\n" \
12373 _ASM_EXTABLE(1b, 2b - 1b) \
12374 : : ltype(x), "m" (__m(addr)))
12375 @@ -488,8 +541,12 @@ struct __large_struct { unsigned long bu
12376 * On error, the variable @x is set to zero.
12377 */
12378
12379 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12380 +#define __get_user(x, ptr) get_user((x), (ptr))
12381 +#else
12382 #define __get_user(x, ptr) \
12383 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12384 +#endif
12385
12386 /**
12387 * __put_user: - Write a simple value into user space, with less checking.
12388 @@ -511,8 +568,12 @@ struct __large_struct { unsigned long bu
12389 * Returns zero on success, or -EFAULT on error.
12390 */
12391
12392 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12393 +#define __put_user(x, ptr) put_user((x), (ptr))
12394 +#else
12395 #define __put_user(x, ptr) \
12396 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12397 +#endif
12398
12399 #define __get_user_unaligned __get_user
12400 #define __put_user_unaligned __put_user
12401 @@ -530,7 +591,7 @@ struct __large_struct { unsigned long bu
12402 #define get_user_ex(x, ptr) do { \
12403 unsigned long __gue_val; \
12404 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12405 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12406 + (x) = (__typeof__(*(ptr)))__gue_val; \
12407 } while (0)
12408
12409 #ifdef CONFIG_X86_WP_WORKS_OK
12410 @@ -567,6 +628,7 @@ extern struct movsl_mask {
12411
12412 #define ARCH_HAS_NOCACHE_UACCESS 1
12413
12414 +#define ARCH_HAS_SORT_EXTABLE
12415 #ifdef CONFIG_X86_32
12416 # include "uaccess_32.h"
12417 #else
12418 diff -urNp linux-2.6.39.2/arch/x86/include/asm/vgtod.h linux-2.6.39.2/arch/x86/include/asm/vgtod.h
12419 --- linux-2.6.39.2/arch/x86/include/asm/vgtod.h 2011-05-19 00:06:34.000000000 -0400
12420 +++ linux-2.6.39.2/arch/x86/include/asm/vgtod.h 2011-05-22 19:36:30.000000000 -0400
12421 @@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12422 int sysctl_enabled;
12423 struct timezone sys_tz;
12424 struct { /* extract of a clocksource struct */
12425 + char name[8];
12426 cycle_t (*vread)(void);
12427 cycle_t cycle_last;
12428 cycle_t mask;
12429 diff -urNp linux-2.6.39.2/arch/x86/include/asm/vsyscall.h linux-2.6.39.2/arch/x86/include/asm/vsyscall.h
12430 --- linux-2.6.39.2/arch/x86/include/asm/vsyscall.h 2011-05-19 00:06:34.000000000 -0400
12431 +++ linux-2.6.39.2/arch/x86/include/asm/vsyscall.h 2011-05-22 19:36:30.000000000 -0400
12432 @@ -15,9 +15,10 @@ enum vsyscall_num {
12433
12434 #ifdef __KERNEL__
12435 #include <linux/seqlock.h>
12436 +#include <linux/getcpu.h>
12437 +#include <linux/time.h>
12438
12439 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12440 -#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12441
12442 /* Definitions for CONFIG_GENERIC_TIME definitions */
12443 #define __section_vsyscall_gtod_data __attribute__ \
12444 @@ -31,7 +32,6 @@ enum vsyscall_num {
12445 #define VGETCPU_LSL 2
12446
12447 extern int __vgetcpu_mode;
12448 -extern volatile unsigned long __jiffies;
12449
12450 /* kernel space (writeable) */
12451 extern int vgetcpu_mode;
12452 @@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12453
12454 extern void map_vsyscall(void);
12455
12456 +extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12457 +extern time_t vtime(time_t *t);
12458 +extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12459 #endif /* __KERNEL__ */
12460
12461 #endif /* _ASM_X86_VSYSCALL_H */
12462 diff -urNp linux-2.6.39.2/arch/x86/include/asm/xen/pci.h linux-2.6.39.2/arch/x86/include/asm/xen/pci.h
12463 --- linux-2.6.39.2/arch/x86/include/asm/xen/pci.h 2011-05-19 00:06:34.000000000 -0400
12464 +++ linux-2.6.39.2/arch/x86/include/asm/xen/pci.h 2011-05-22 19:36:30.000000000 -0400
12465 @@ -33,7 +33,7 @@ struct xen_pci_frontend_ops {
12466 void (*disable_msix)(struct pci_dev *dev);
12467 };
12468
12469 -extern struct xen_pci_frontend_ops *xen_pci_frontend;
12470 +extern const struct xen_pci_frontend_ops *xen_pci_frontend;
12471
12472 static inline int xen_pci_frontend_enable_msi(struct pci_dev *dev,
12473 int vectors[])
12474 diff -urNp linux-2.6.39.2/arch/x86/include/asm/xsave.h linux-2.6.39.2/arch/x86/include/asm/xsave.h
12475 --- linux-2.6.39.2/arch/x86/include/asm/xsave.h 2011-05-19 00:06:34.000000000 -0400
12476 +++ linux-2.6.39.2/arch/x86/include/asm/xsave.h 2011-05-22 19:36:30.000000000 -0400
12477 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsav
12478 {
12479 int err;
12480
12481 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12482 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
12483 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
12484 +#endif
12485 +
12486 /*
12487 * Clear the xsave header first, so that reserved fields are
12488 * initialized to zero.
12489 @@ -100,6 +105,11 @@ static inline int xrestore_user(struct x
12490 u32 lmask = mask;
12491 u32 hmask = mask >> 32;
12492
12493 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12494 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
12495 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
12496 +#endif
12497 +
12498 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
12499 "2:\n"
12500 ".section .fixup,\"ax\"\n"
12501 diff -urNp linux-2.6.39.2/arch/x86/Kconfig linux-2.6.39.2/arch/x86/Kconfig
12502 --- linux-2.6.39.2/arch/x86/Kconfig 2011-05-19 00:06:34.000000000 -0400
12503 +++ linux-2.6.39.2/arch/x86/Kconfig 2011-05-22 19:41:32.000000000 -0400
12504 @@ -224,7 +224,7 @@ config X86_HT
12505
12506 config X86_32_LAZY_GS
12507 def_bool y
12508 - depends on X86_32 && !CC_STACKPROTECTOR
12509 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12510
12511 config ARCH_HWEIGHT_CFLAGS
12512 string
12513 @@ -1022,7 +1022,7 @@ choice
12514
12515 config NOHIGHMEM
12516 bool "off"
12517 - depends on !X86_NUMAQ
12518 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12519 ---help---
12520 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12521 However, the address space of 32-bit x86 processors is only 4
12522 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
12523
12524 config HIGHMEM4G
12525 bool "4GB"
12526 - depends on !X86_NUMAQ
12527 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12528 ---help---
12529 Select this if you have a 32-bit processor and between 1 and 4
12530 gigabytes of physical RAM.
12531 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
12532 hex
12533 default 0xB0000000 if VMSPLIT_3G_OPT
12534 default 0x80000000 if VMSPLIT_2G
12535 - default 0x78000000 if VMSPLIT_2G_OPT
12536 + default 0x70000000 if VMSPLIT_2G_OPT
12537 default 0x40000000 if VMSPLIT_1G
12538 default 0xC0000000
12539 depends on X86_32
12540 @@ -1457,7 +1457,7 @@ config ARCH_USES_PG_UNCACHED
12541
12542 config EFI
12543 bool "EFI runtime service support"
12544 - depends on ACPI
12545 + depends on ACPI && !PAX_KERNEXEC
12546 ---help---
12547 This enables the kernel to use EFI runtime services that are
12548 available (such as the EFI variable services).
12549 @@ -1487,6 +1487,7 @@ config SECCOMP
12550
12551 config CC_STACKPROTECTOR
12552 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
12553 + depends on X86_64 || !PAX_MEMORY_UDEREF
12554 ---help---
12555 This option turns on the -fstack-protector GCC feature. This
12556 feature puts, at the beginning of functions, a canary value on
12557 @@ -1544,6 +1545,7 @@ config KEXEC_JUMP
12558 config PHYSICAL_START
12559 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
12560 default "0x1000000"
12561 + range 0x400000 0x40000000
12562 ---help---
12563 This gives the physical address where the kernel is loaded.
12564
12565 @@ -1607,6 +1609,7 @@ config X86_NEED_RELOCS
12566 config PHYSICAL_ALIGN
12567 hex "Alignment value to which kernel should be aligned" if X86_32
12568 default "0x1000000"
12569 + range 0x400000 0x1000000 if PAX_KERNEXEC
12570 range 0x2000 0x1000000
12571 ---help---
12572 This value puts the alignment restrictions on physical address
12573 @@ -1638,9 +1641,10 @@ config HOTPLUG_CPU
12574 Say N if you want to disable CPU hotplug.
12575
12576 config COMPAT_VDSO
12577 - def_bool y
12578 + def_bool n
12579 prompt "Compat VDSO support"
12580 depends on X86_32 || IA32_EMULATION
12581 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
12582 ---help---
12583 Map the 32-bit VDSO to the predictable old-style address too.
12584
12585 diff -urNp linux-2.6.39.2/arch/x86/Kconfig.cpu linux-2.6.39.2/arch/x86/Kconfig.cpu
12586 --- linux-2.6.39.2/arch/x86/Kconfig.cpu 2011-05-19 00:06:34.000000000 -0400
12587 +++ linux-2.6.39.2/arch/x86/Kconfig.cpu 2011-05-22 19:36:30.000000000 -0400
12588 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
12589
12590 config X86_F00F_BUG
12591 def_bool y
12592 - depends on M586MMX || M586TSC || M586 || M486 || M386
12593 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
12594
12595 config X86_INVD_BUG
12596 def_bool y
12597 @@ -358,7 +358,7 @@ config X86_POPAD_OK
12598
12599 config X86_ALIGNMENT_16
12600 def_bool y
12601 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12602 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12603
12604 config X86_INTEL_USERCOPY
12605 def_bool y
12606 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
12607 # generates cmov.
12608 config X86_CMOV
12609 def_bool y
12610 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12611 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12612
12613 config X86_MINIMUM_CPU_FAMILY
12614 int
12615 diff -urNp linux-2.6.39.2/arch/x86/Kconfig.debug linux-2.6.39.2/arch/x86/Kconfig.debug
12616 --- linux-2.6.39.2/arch/x86/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
12617 +++ linux-2.6.39.2/arch/x86/Kconfig.debug 2011-05-22 19:36:30.000000000 -0400
12618 @@ -101,7 +101,7 @@ config X86_PTDUMP
12619 config DEBUG_RODATA
12620 bool "Write protect kernel read-only data structures"
12621 default y
12622 - depends on DEBUG_KERNEL
12623 + depends on DEBUG_KERNEL && BROKEN
12624 ---help---
12625 Mark the kernel read-only data as write-protected in the pagetables,
12626 in order to catch accidental (and incorrect) writes to such const
12627 @@ -119,7 +119,7 @@ config DEBUG_RODATA_TEST
12628
12629 config DEBUG_SET_MODULE_RONX
12630 bool "Set loadable kernel module data as NX and text as RO"
12631 - depends on MODULES
12632 + depends on MODULES && BROKEN
12633 ---help---
12634 This option helps catch unintended modifications to loadable
12635 kernel module's text and read-only data. It also prevents execution
12636 diff -urNp linux-2.6.39.2/arch/x86/kernel/acpi/sleep.c linux-2.6.39.2/arch/x86/kernel/acpi/sleep.c
12637 --- linux-2.6.39.2/arch/x86/kernel/acpi/sleep.c 2011-05-19 00:06:34.000000000 -0400
12638 +++ linux-2.6.39.2/arch/x86/kernel/acpi/sleep.c 2011-05-22 19:36:30.000000000 -0400
12639 @@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
12640 header->trampoline_segment = trampoline_address() >> 4;
12641 #ifdef CONFIG_SMP
12642 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
12643 +
12644 + pax_open_kernel();
12645 early_gdt_descr.address =
12646 (unsigned long)get_cpu_gdt_table(smp_processor_id());
12647 + pax_close_kernel();
12648 +
12649 initial_gs = per_cpu_offset(smp_processor_id());
12650 #endif
12651 initial_code = (unsigned long)wakeup_long64;
12652 diff -urNp linux-2.6.39.2/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.39.2/arch/x86/kernel/acpi/wakeup_32.S
12653 --- linux-2.6.39.2/arch/x86/kernel/acpi/wakeup_32.S 2011-05-19 00:06:34.000000000 -0400
12654 +++ linux-2.6.39.2/arch/x86/kernel/acpi/wakeup_32.S 2011-05-22 19:36:30.000000000 -0400
12655 @@ -30,13 +30,11 @@ wakeup_pmode_return:
12656 # and restore the stack ... but you need gdt for this to work
12657 movl saved_context_esp, %esp
12658
12659 - movl %cs:saved_magic, %eax
12660 - cmpl $0x12345678, %eax
12661 + cmpl $0x12345678, saved_magic
12662 jne bogus_magic
12663
12664 # jump to place where we left off
12665 - movl saved_eip, %eax
12666 - jmp *%eax
12667 + jmp *(saved_eip)
12668
12669 bogus_magic:
12670 jmp bogus_magic
12671 diff -urNp linux-2.6.39.2/arch/x86/kernel/alternative.c linux-2.6.39.2/arch/x86/kernel/alternative.c
12672 --- linux-2.6.39.2/arch/x86/kernel/alternative.c 2011-05-19 00:06:34.000000000 -0400
12673 +++ linux-2.6.39.2/arch/x86/kernel/alternative.c 2011-05-22 19:36:30.000000000 -0400
12674 @@ -248,7 +248,7 @@ static void alternatives_smp_lock(const
12675 if (!*poff || ptr < text || ptr >= text_end)
12676 continue;
12677 /* turn DS segment override prefix into lock prefix */
12678 - if (*ptr == 0x3e)
12679 + if (*ktla_ktva(ptr) == 0x3e)
12680 text_poke(ptr, ((unsigned char []){0xf0}), 1);
12681 };
12682 mutex_unlock(&text_mutex);
12683 @@ -269,7 +269,7 @@ static void alternatives_smp_unlock(cons
12684 if (!*poff || ptr < text || ptr >= text_end)
12685 continue;
12686 /* turn lock prefix into DS segment override prefix */
12687 - if (*ptr == 0xf0)
12688 + if (*ktla_ktva(ptr) == 0xf0)
12689 text_poke(ptr, ((unsigned char []){0x3E}), 1);
12690 };
12691 mutex_unlock(&text_mutex);
12692 @@ -438,7 +438,7 @@ void __init_or_module apply_paravirt(str
12693
12694 BUG_ON(p->len > MAX_PATCH_LEN);
12695 /* prep the buffer with the original instructions */
12696 - memcpy(insnbuf, p->instr, p->len);
12697 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
12698 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
12699 (unsigned long)p->instr, p->len);
12700
12701 @@ -506,7 +506,7 @@ void __init alternative_instructions(voi
12702 if (smp_alt_once)
12703 free_init_pages("SMP alternatives",
12704 (unsigned long)__smp_locks,
12705 - (unsigned long)__smp_locks_end);
12706 + PAGE_ALIGN((unsigned long)__smp_locks_end));
12707
12708 restart_nmi();
12709 }
12710 @@ -523,13 +523,17 @@ void __init alternative_instructions(voi
12711 * instructions. And on the local CPU you need to be protected again NMI or MCE
12712 * handlers seeing an inconsistent instruction while you patch.
12713 */
12714 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
12715 +void *__kprobes text_poke_early(void *addr, const void *opcode,
12716 size_t len)
12717 {
12718 unsigned long flags;
12719 local_irq_save(flags);
12720 - memcpy(addr, opcode, len);
12721 +
12722 + pax_open_kernel();
12723 + memcpy(ktla_ktva(addr), opcode, len);
12724 sync_core();
12725 + pax_close_kernel();
12726 +
12727 local_irq_restore(flags);
12728 /* Could also do a CLFLUSH here to speed up CPU recovery; but
12729 that causes hangs on some VIA CPUs. */
12730 @@ -551,36 +555,22 @@ void *__init_or_module text_poke_early(v
12731 */
12732 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
12733 {
12734 - unsigned long flags;
12735 - char *vaddr;
12736 + unsigned char *vaddr = ktla_ktva(addr);
12737 struct page *pages[2];
12738 - int i;
12739 + size_t i;
12740
12741 if (!core_kernel_text((unsigned long)addr)) {
12742 - pages[0] = vmalloc_to_page(addr);
12743 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
12744 + pages[0] = vmalloc_to_page(vaddr);
12745 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
12746 } else {
12747 - pages[0] = virt_to_page(addr);
12748 + pages[0] = virt_to_page(vaddr);
12749 WARN_ON(!PageReserved(pages[0]));
12750 - pages[1] = virt_to_page(addr + PAGE_SIZE);
12751 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
12752 }
12753 BUG_ON(!pages[0]);
12754 - local_irq_save(flags);
12755 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
12756 - if (pages[1])
12757 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
12758 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
12759 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
12760 - clear_fixmap(FIX_TEXT_POKE0);
12761 - if (pages[1])
12762 - clear_fixmap(FIX_TEXT_POKE1);
12763 - local_flush_tlb();
12764 - sync_core();
12765 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
12766 - that causes hangs on some VIA CPUs. */
12767 + text_poke_early(addr, opcode, len);
12768 for (i = 0; i < len; i++)
12769 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
12770 - local_irq_restore(flags);
12771 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
12772 return addr;
12773 }
12774
12775 @@ -682,9 +672,9 @@ void __kprobes text_poke_smp_batch(struc
12776 #if defined(CONFIG_DYNAMIC_FTRACE) || defined(HAVE_JUMP_LABEL)
12777
12778 #ifdef CONFIG_X86_64
12779 -unsigned char ideal_nop5[5] = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12780 +unsigned char ideal_nop5[5] __read_only = { 0x66, 0x66, 0x66, 0x66, 0x90 };
12781 #else
12782 -unsigned char ideal_nop5[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12783 +unsigned char ideal_nop5[5] __read_only = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
12784 #endif
12785
12786 void __init arch_init_ideal_nop5(void)
12787 diff -urNp linux-2.6.39.2/arch/x86/kernel/amd_iommu.c linux-2.6.39.2/arch/x86/kernel/amd_iommu.c
12788 --- linux-2.6.39.2/arch/x86/kernel/amd_iommu.c 2011-06-25 12:55:22.000000000 -0400
12789 +++ linux-2.6.39.2/arch/x86/kernel/amd_iommu.c 2011-06-25 13:00:25.000000000 -0400
12790 @@ -49,7 +49,7 @@ static DEFINE_SPINLOCK(iommu_pd_list_loc
12791 */
12792 static struct protection_domain *pt_domain;
12793
12794 -static struct iommu_ops amd_iommu_ops;
12795 +static const struct iommu_ops amd_iommu_ops;
12796
12797 /*
12798 * general struct to manage commands send to an IOMMU
12799 @@ -2307,7 +2307,7 @@ static void prealloc_protection_domains(
12800 }
12801 }
12802
12803 -static struct dma_map_ops amd_iommu_dma_ops = {
12804 +static const struct dma_map_ops amd_iommu_dma_ops = {
12805 .alloc_coherent = alloc_coherent,
12806 .free_coherent = free_coherent,
12807 .map_page = map_page,
12808 @@ -2624,7 +2624,7 @@ static int amd_iommu_domain_has_cap(stru
12809 return 0;
12810 }
12811
12812 -static struct iommu_ops amd_iommu_ops = {
12813 +static const struct iommu_ops amd_iommu_ops = {
12814 .domain_init = amd_iommu_domain_init,
12815 .domain_destroy = amd_iommu_domain_destroy,
12816 .attach_dev = amd_iommu_attach_device,
12817 diff -urNp linux-2.6.39.2/arch/x86/kernel/apic/apic.c linux-2.6.39.2/arch/x86/kernel/apic/apic.c
12818 --- linux-2.6.39.2/arch/x86/kernel/apic/apic.c 2011-05-19 00:06:34.000000000 -0400
12819 +++ linux-2.6.39.2/arch/x86/kernel/apic/apic.c 2011-05-22 19:36:30.000000000 -0400
12820 @@ -1821,7 +1821,7 @@ void smp_error_interrupt(struct pt_regs
12821 apic_write(APIC_ESR, 0);
12822 v1 = apic_read(APIC_ESR);
12823 ack_APIC_irq();
12824 - atomic_inc(&irq_err_count);
12825 + atomic_inc_unchecked(&irq_err_count);
12826
12827 /*
12828 * Here is what the APIC error bits mean:
12829 @@ -2204,6 +2204,8 @@ static int __cpuinit apic_cluster_num(vo
12830 u16 *bios_cpu_apicid;
12831 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
12832
12833 + pax_track_stack();
12834 +
12835 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
12836 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
12837
12838 diff -urNp linux-2.6.39.2/arch/x86/kernel/apic/io_apic.c linux-2.6.39.2/arch/x86/kernel/apic/io_apic.c
12839 --- linux-2.6.39.2/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:04:13.000000000 -0400
12840 +++ linux-2.6.39.2/arch/x86/kernel/apic/io_apic.c 2011-06-03 00:42:37.000000000 -0400
12841 @@ -623,7 +623,7 @@ struct IO_APIC_route_entry **alloc_ioapi
12842 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
12843 GFP_ATOMIC);
12844 if (!ioapic_entries)
12845 - return 0;
12846 + return NULL;
12847
12848 for (apic = 0; apic < nr_ioapics; apic++) {
12849 ioapic_entries[apic] =
12850 @@ -640,7 +640,7 @@ nomem:
12851 kfree(ioapic_entries[apic]);
12852 kfree(ioapic_entries);
12853
12854 - return 0;
12855 + return NULL;
12856 }
12857
12858 /*
12859 @@ -1040,7 +1040,7 @@ int IO_APIC_get_PCI_irq_vector(int bus,
12860 }
12861 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12862
12863 -void lock_vector_lock(void)
12864 +void lock_vector_lock(void) __acquires(vector_lock)
12865 {
12866 /* Used to the online set of cpus does not change
12867 * during assign_irq_vector.
12868 @@ -1048,7 +1048,7 @@ void lock_vector_lock(void)
12869 raw_spin_lock(&vector_lock);
12870 }
12871
12872 -void unlock_vector_lock(void)
12873 +void unlock_vector_lock(void) __releases(vector_lock)
12874 {
12875 raw_spin_unlock(&vector_lock);
12876 }
12877 @@ -2379,7 +2379,7 @@ static void ack_apic_edge(struct irq_dat
12878 ack_APIC_irq();
12879 }
12880
12881 -atomic_t irq_mis_count;
12882 +atomic_unchecked_t irq_mis_count;
12883
12884 /*
12885 * IO-APIC versions below 0x20 don't support EOI register.
12886 @@ -2487,7 +2487,7 @@ static void ack_apic_level(struct irq_da
12887 * at the cpu.
12888 */
12889 if (!(v & (1 << (i & 0x1f)))) {
12890 - atomic_inc(&irq_mis_count);
12891 + atomic_inc_unchecked(&irq_mis_count);
12892
12893 eoi_ioapic_irq(irq, cfg);
12894 }
12895 diff -urNp linux-2.6.39.2/arch/x86/kernel/apm_32.c linux-2.6.39.2/arch/x86/kernel/apm_32.c
12896 --- linux-2.6.39.2/arch/x86/kernel/apm_32.c 2011-05-19 00:06:34.000000000 -0400
12897 +++ linux-2.6.39.2/arch/x86/kernel/apm_32.c 2011-05-22 19:36:30.000000000 -0400
12898 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
12899 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12900 * even though they are called in protected mode.
12901 */
12902 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12903 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12904 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12905
12906 static const char driver_version[] = "1.16ac"; /* no spaces */
12907 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
12908 BUG_ON(cpu != 0);
12909 gdt = get_cpu_gdt_table(cpu);
12910 save_desc_40 = gdt[0x40 / 8];
12911 +
12912 + pax_open_kernel();
12913 gdt[0x40 / 8] = bad_bios_desc;
12914 + pax_close_kernel();
12915
12916 apm_irq_save(flags);
12917 APM_DO_SAVE_SEGS;
12918 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
12919 &call->esi);
12920 APM_DO_RESTORE_SEGS;
12921 apm_irq_restore(flags);
12922 +
12923 + pax_open_kernel();
12924 gdt[0x40 / 8] = save_desc_40;
12925 + pax_close_kernel();
12926 +
12927 put_cpu();
12928
12929 return call->eax & 0xff;
12930 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void
12931 BUG_ON(cpu != 0);
12932 gdt = get_cpu_gdt_table(cpu);
12933 save_desc_40 = gdt[0x40 / 8];
12934 +
12935 + pax_open_kernel();
12936 gdt[0x40 / 8] = bad_bios_desc;
12937 + pax_close_kernel();
12938
12939 apm_irq_save(flags);
12940 APM_DO_SAVE_SEGS;
12941 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void
12942 &call->eax);
12943 APM_DO_RESTORE_SEGS;
12944 apm_irq_restore(flags);
12945 +
12946 + pax_open_kernel();
12947 gdt[0x40 / 8] = save_desc_40;
12948 + pax_close_kernel();
12949 +
12950 put_cpu();
12951 return error;
12952 }
12953 @@ -2351,12 +2365,15 @@ static int __init apm_init(void)
12954 * code to that CPU.
12955 */
12956 gdt = get_cpu_gdt_table(0);
12957 +
12958 + pax_open_kernel();
12959 set_desc_base(&gdt[APM_CS >> 3],
12960 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12961 set_desc_base(&gdt[APM_CS_16 >> 3],
12962 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12963 set_desc_base(&gdt[APM_DS >> 3],
12964 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12965 + pax_close_kernel();
12966
12967 proc_create("apm", 0, NULL, &apm_file_ops);
12968
12969 diff -urNp linux-2.6.39.2/arch/x86/kernel/asm-offsets_64.c linux-2.6.39.2/arch/x86/kernel/asm-offsets_64.c
12970 --- linux-2.6.39.2/arch/x86/kernel/asm-offsets_64.c 2011-05-19 00:06:34.000000000 -0400
12971 +++ linux-2.6.39.2/arch/x86/kernel/asm-offsets_64.c 2011-05-22 19:36:30.000000000 -0400
12972 @@ -69,6 +69,7 @@ int main(void)
12973 BLANK();
12974 #undef ENTRY
12975
12976 + DEFINE(TSS_size, sizeof(struct tss_struct));
12977 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12978 BLANK();
12979
12980 diff -urNp linux-2.6.39.2/arch/x86/kernel/asm-offsets.c linux-2.6.39.2/arch/x86/kernel/asm-offsets.c
12981 --- linux-2.6.39.2/arch/x86/kernel/asm-offsets.c 2011-05-19 00:06:34.000000000 -0400
12982 +++ linux-2.6.39.2/arch/x86/kernel/asm-offsets.c 2011-05-25 17:35:48.000000000 -0400
12983 @@ -33,6 +33,8 @@ void common(void) {
12984 OFFSET(TI_status, thread_info, status);
12985 OFFSET(TI_addr_limit, thread_info, addr_limit);
12986 OFFSET(TI_preempt_count, thread_info, preempt_count);
12987 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12988 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12989
12990 BLANK();
12991 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12992 @@ -53,8 +55,26 @@ void common(void) {
12993 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12994 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12995 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12996 +
12997 +#ifdef CONFIG_PAX_KERNEXEC
12998 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12999 +#endif
13000 +
13001 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13002 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13003 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13004 +#ifdef CONFIG_X86_64
13005 + OFFSET(PV_MMU_set_pgd, pv_mmu_ops, set_pgd);
13006 +#endif
13007 #endif
13008
13009 +#endif
13010 +
13011 + BLANK();
13012 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13013 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13014 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13015 +
13016 #ifdef CONFIG_XEN
13017 BLANK();
13018 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13019 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/amd.c linux-2.6.39.2/arch/x86/kernel/cpu/amd.c
13020 --- linux-2.6.39.2/arch/x86/kernel/cpu/amd.c 2011-06-03 00:04:13.000000000 -0400
13021 +++ linux-2.6.39.2/arch/x86/kernel/cpu/amd.c 2011-06-03 00:32:04.000000000 -0400
13022 @@ -647,7 +647,7 @@ static unsigned int __cpuinit amd_size_c
13023 unsigned int size)
13024 {
13025 /* AMD errata T13 (order #21922) */
13026 - if ((c->x86 == 6)) {
13027 + if (c->x86 == 6) {
13028 /* Duron Rev A0 */
13029 if (c->x86_model == 3 && c->x86_mask == 0)
13030 size = 64;
13031 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/common.c linux-2.6.39.2/arch/x86/kernel/cpu/common.c
13032 --- linux-2.6.39.2/arch/x86/kernel/cpu/common.c 2011-06-03 00:04:13.000000000 -0400
13033 +++ linux-2.6.39.2/arch/x86/kernel/cpu/common.c 2011-06-03 00:32:04.000000000 -0400
13034 @@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitcon
13035
13036 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13037
13038 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13039 -#ifdef CONFIG_X86_64
13040 - /*
13041 - * We need valid kernel segments for data and code in long mode too
13042 - * IRET will check the segment types kkeil 2000/10/28
13043 - * Also sysret mandates a special GDT layout
13044 - *
13045 - * TLS descriptors are currently at a different place compared to i386.
13046 - * Hopefully nobody expects them at a fixed place (Wine?)
13047 - */
13048 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13049 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13050 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13051 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13052 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13053 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13054 -#else
13055 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13056 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13057 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13058 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13059 - /*
13060 - * Segments used for calling PnP BIOS have byte granularity.
13061 - * They code segments and data segments have fixed 64k limits,
13062 - * the transfer segment sizes are set at run time.
13063 - */
13064 - /* 32-bit code */
13065 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13066 - /* 16-bit code */
13067 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13068 - /* 16-bit data */
13069 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13070 - /* 16-bit data */
13071 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13072 - /* 16-bit data */
13073 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13074 - /*
13075 - * The APM segments have byte granularity and their bases
13076 - * are set at run time. All have 64k limits.
13077 - */
13078 - /* 32-bit code */
13079 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13080 - /* 16-bit code */
13081 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13082 - /* data */
13083 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13084 -
13085 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13086 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13087 - GDT_STACK_CANARY_INIT
13088 -#endif
13089 -} };
13090 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13091 -
13092 static int __init x86_xsave_setup(char *s)
13093 {
13094 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13095 @@ -352,7 +298,7 @@ void switch_to_new_gdt(int cpu)
13096 {
13097 struct desc_ptr gdt_descr;
13098
13099 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13100 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13101 gdt_descr.size = GDT_SIZE - 1;
13102 load_gdt(&gdt_descr);
13103 /* Reload the per-cpu base */
13104 @@ -824,6 +770,10 @@ static void __cpuinit identify_cpu(struc
13105 /* Filter out anything that depends on CPUID levels we don't have */
13106 filter_cpuid_features(c, true);
13107
13108 +#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || (defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32))
13109 + setup_clear_cpu_cap(X86_FEATURE_SEP);
13110 +#endif
13111 +
13112 /* If the model name is still unset, do table lookup. */
13113 if (!c->x86_model_id[0]) {
13114 const char *p;
13115 @@ -1003,6 +953,9 @@ static __init int setup_disablecpuid(cha
13116 }
13117 __setup("clearcpuid=", setup_disablecpuid);
13118
13119 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13120 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
13121 +
13122 #ifdef CONFIG_X86_64
13123 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13124
13125 @@ -1018,7 +971,7 @@ DEFINE_PER_CPU(struct task_struct *, cur
13126 EXPORT_PER_CPU_SYMBOL(current_task);
13127
13128 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13129 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13130 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13131 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13132
13133 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13134 @@ -1083,7 +1036,7 @@ struct pt_regs * __cpuinit idle_regs(str
13135 {
13136 memset(regs, 0, sizeof(struct pt_regs));
13137 regs->fs = __KERNEL_PERCPU;
13138 - regs->gs = __KERNEL_STACK_CANARY;
13139 + savesegment(gs, regs->gs);
13140
13141 return regs;
13142 }
13143 @@ -1138,7 +1091,7 @@ void __cpuinit cpu_init(void)
13144 int i;
13145
13146 cpu = stack_smp_processor_id();
13147 - t = &per_cpu(init_tss, cpu);
13148 + t = init_tss + cpu;
13149 oist = &per_cpu(orig_ist, cpu);
13150
13151 #ifdef CONFIG_NUMA
13152 @@ -1164,7 +1117,7 @@ void __cpuinit cpu_init(void)
13153 switch_to_new_gdt(cpu);
13154 loadsegment(fs, 0);
13155
13156 - load_idt((const struct desc_ptr *)&idt_descr);
13157 + load_idt(&idt_descr);
13158
13159 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13160 syscall_init();
13161 @@ -1173,7 +1126,6 @@ void __cpuinit cpu_init(void)
13162 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13163 barrier();
13164
13165 - x86_configure_nx();
13166 if (cpu != 0)
13167 enable_x2apic();
13168
13169 @@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
13170 {
13171 int cpu = smp_processor_id();
13172 struct task_struct *curr = current;
13173 - struct tss_struct *t = &per_cpu(init_tss, cpu);
13174 + struct tss_struct *t = init_tss + cpu;
13175 struct thread_struct *thread = &curr->thread;
13176
13177 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13178 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/intel.c linux-2.6.39.2/arch/x86/kernel/cpu/intel.c
13179 --- linux-2.6.39.2/arch/x86/kernel/cpu/intel.c 2011-05-19 00:06:34.000000000 -0400
13180 +++ linux-2.6.39.2/arch/x86/kernel/cpu/intel.c 2011-05-22 19:36:30.000000000 -0400
13181 @@ -161,7 +161,7 @@ static void __cpuinit trap_init_f00f_bug
13182 * Update the IDT descriptor and reload the IDT so that
13183 * it uses the read-only mapped virtual address.
13184 */
13185 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13186 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13187 load_idt(&idt_descr);
13188 }
13189 #endif
13190 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/Makefile linux-2.6.39.2/arch/x86/kernel/cpu/Makefile
13191 --- linux-2.6.39.2/arch/x86/kernel/cpu/Makefile 2011-05-19 00:06:34.000000000 -0400
13192 +++ linux-2.6.39.2/arch/x86/kernel/cpu/Makefile 2011-05-22 19:36:30.000000000 -0400
13193 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13194 CFLAGS_REMOVE_perf_event.o = -pg
13195 endif
13196
13197 -# Make sure load_percpu_segment has no stackprotector
13198 -nostackp := $(call cc-option, -fno-stack-protector)
13199 -CFLAGS_common.o := $(nostackp)
13200 -
13201 obj-y := intel_cacheinfo.o scattered.o topology.o
13202 obj-y += proc.o capflags.o powerflags.o common.o
13203 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13204 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/mcheck/mce.c linux-2.6.39.2/arch/x86/kernel/cpu/mcheck/mce.c
13205 --- linux-2.6.39.2/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-19 00:06:34.000000000 -0400
13206 +++ linux-2.6.39.2/arch/x86/kernel/cpu/mcheck/mce.c 2011-05-22 19:36:30.000000000 -0400
13207 @@ -46,6 +46,7 @@
13208 #include <asm/ipi.h>
13209 #include <asm/mce.h>
13210 #include <asm/msr.h>
13211 +#include <asm/local.h>
13212
13213 #include "mce-internal.h"
13214
13215 @@ -220,7 +221,7 @@ static void print_mce(struct mce *m)
13216 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13217 m->cs, m->ip);
13218
13219 - if (m->cs == __KERNEL_CS)
13220 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13221 print_symbol("{%s}", m->ip);
13222 pr_cont("\n");
13223 }
13224 @@ -244,10 +245,10 @@ static void print_mce(struct mce *m)
13225
13226 #define PANIC_TIMEOUT 5 /* 5 seconds */
13227
13228 -static atomic_t mce_paniced;
13229 +static atomic_unchecked_t mce_paniced;
13230
13231 static int fake_panic;
13232 -static atomic_t mce_fake_paniced;
13233 +static atomic_unchecked_t mce_fake_paniced;
13234
13235 /* Panic in progress. Enable interrupts and wait for final IPI */
13236 static void wait_for_panic(void)
13237 @@ -271,7 +272,7 @@ static void mce_panic(char *msg, struct
13238 /*
13239 * Make sure only one CPU runs in machine check panic
13240 */
13241 - if (atomic_inc_return(&mce_paniced) > 1)
13242 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13243 wait_for_panic();
13244 barrier();
13245
13246 @@ -279,7 +280,7 @@ static void mce_panic(char *msg, struct
13247 console_verbose();
13248 } else {
13249 /* Don't log too much for fake panic */
13250 - if (atomic_inc_return(&mce_fake_paniced) > 1)
13251 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13252 return;
13253 }
13254 /* First print corrected ones that are still unlogged */
13255 @@ -647,7 +648,7 @@ static int mce_timed_out(u64 *t)
13256 * might have been modified by someone else.
13257 */
13258 rmb();
13259 - if (atomic_read(&mce_paniced))
13260 + if (atomic_read_unchecked(&mce_paniced))
13261 wait_for_panic();
13262 if (!monarch_timeout)
13263 goto out;
13264 @@ -1461,14 +1462,14 @@ void __cpuinit mcheck_cpu_init(struct cp
13265 */
13266
13267 static DEFINE_SPINLOCK(mce_state_lock);
13268 -static int open_count; /* #times opened */
13269 +static local_t open_count; /* #times opened */
13270 static int open_exclu; /* already open exclusive? */
13271
13272 static int mce_open(struct inode *inode, struct file *file)
13273 {
13274 spin_lock(&mce_state_lock);
13275
13276 - if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13277 + if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13278 spin_unlock(&mce_state_lock);
13279
13280 return -EBUSY;
13281 @@ -1476,7 +1477,7 @@ static int mce_open(struct inode *inode,
13282
13283 if (file->f_flags & O_EXCL)
13284 open_exclu = 1;
13285 - open_count++;
13286 + local_inc(&open_count);
13287
13288 spin_unlock(&mce_state_lock);
13289
13290 @@ -1487,7 +1488,7 @@ static int mce_release(struct inode *ino
13291 {
13292 spin_lock(&mce_state_lock);
13293
13294 - open_count--;
13295 + local_dec(&open_count);
13296 open_exclu = 0;
13297
13298 spin_unlock(&mce_state_lock);
13299 @@ -2174,7 +2175,7 @@ struct dentry *mce_get_debugfs_dir(void)
13300 static void mce_reset(void)
13301 {
13302 cpu_missing = 0;
13303 - atomic_set(&mce_fake_paniced, 0);
13304 + atomic_set_unchecked(&mce_fake_paniced, 0);
13305 atomic_set(&mce_executing, 0);
13306 atomic_set(&mce_callin, 0);
13307 atomic_set(&global_nwo, 0);
13308 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/main.c linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/main.c
13309 --- linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/main.c 2011-05-19 00:06:34.000000000 -0400
13310 +++ linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/main.c 2011-05-22 19:36:30.000000000 -0400
13311 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
13312 u64 size_or_mask, size_and_mask;
13313 static bool mtrr_aps_delayed_init;
13314
13315 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
13316 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
13317
13318 const struct mtrr_ops *mtrr_if;
13319
13320 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/mtrr.h linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/mtrr.h
13321 --- linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-19 00:06:34.000000000 -0400
13322 +++ linux-2.6.39.2/arch/x86/kernel/cpu/mtrr/mtrr.h 2011-05-22 19:36:30.000000000 -0400
13323 @@ -12,19 +12,19 @@
13324 extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES];
13325
13326 struct mtrr_ops {
13327 - u32 vendor;
13328 - u32 use_intel_if;
13329 - void (*set)(unsigned int reg, unsigned long base,
13330 + const u32 vendor;
13331 + const u32 use_intel_if;
13332 + void (* const set)(unsigned int reg, unsigned long base,
13333 unsigned long size, mtrr_type type);
13334 - void (*set_all)(void);
13335 + void (* const set_all)(void);
13336
13337 - void (*get)(unsigned int reg, unsigned long *base,
13338 + void (* const get)(unsigned int reg, unsigned long *base,
13339 unsigned long *size, mtrr_type *type);
13340 - int (*get_free_region)(unsigned long base, unsigned long size,
13341 + int (* const get_free_region)(unsigned long base, unsigned long size,
13342 int replace_reg);
13343 - int (*validate_add_page)(unsigned long base, unsigned long size,
13344 + int (* const validate_add_page)(unsigned long base, unsigned long size,
13345 unsigned int type);
13346 - int (*have_wrcomb)(void);
13347 + int (* const have_wrcomb)(void);
13348 };
13349
13350 extern int generic_get_free_region(unsigned long base, unsigned long size,
13351 diff -urNp linux-2.6.39.2/arch/x86/kernel/cpu/perf_event.c linux-2.6.39.2/arch/x86/kernel/cpu/perf_event.c
13352 --- linux-2.6.39.2/arch/x86/kernel/cpu/perf_event.c 2011-05-19 00:06:34.000000000 -0400
13353 +++ linux-2.6.39.2/arch/x86/kernel/cpu/perf_event.c 2011-05-22 19:36:30.000000000 -0400
13354 @@ -774,6 +774,8 @@ static int x86_schedule_events(struct cp
13355 int i, j, w, wmax, num = 0;
13356 struct hw_perf_event *hwc;
13357
13358 + pax_track_stack();
13359 +
13360 bitmap_zero(used_mask, X86_PMC_IDX_MAX);
13361
13362 for (i = 0; i < n; i++) {
13363 @@ -1878,7 +1880,7 @@ perf_callchain_user(struct perf_callchai
13364 break;
13365
13366 perf_callchain_store(entry, frame.return_address);
13367 - fp = frame.next_frame;
13368 + fp = (__force const void __user *)frame.next_frame;
13369 }
13370 }
13371
13372 diff -urNp linux-2.6.39.2/arch/x86/kernel/crash.c linux-2.6.39.2/arch/x86/kernel/crash.c
13373 --- linux-2.6.39.2/arch/x86/kernel/crash.c 2011-05-19 00:06:34.000000000 -0400
13374 +++ linux-2.6.39.2/arch/x86/kernel/crash.c 2011-05-22 19:36:30.000000000 -0400
13375 @@ -42,7 +42,7 @@ static void kdump_nmi_callback(int cpu,
13376 regs = args->regs;
13377
13378 #ifdef CONFIG_X86_32
13379 - if (!user_mode_vm(regs)) {
13380 + if (!user_mode(regs)) {
13381 crash_fixup_ss_esp(&fixed_regs, regs);
13382 regs = &fixed_regs;
13383 }
13384 diff -urNp linux-2.6.39.2/arch/x86/kernel/doublefault_32.c linux-2.6.39.2/arch/x86/kernel/doublefault_32.c
13385 --- linux-2.6.39.2/arch/x86/kernel/doublefault_32.c 2011-05-19 00:06:34.000000000 -0400
13386 +++ linux-2.6.39.2/arch/x86/kernel/doublefault_32.c 2011-05-22 19:36:30.000000000 -0400
13387 @@ -11,7 +11,7 @@
13388
13389 #define DOUBLEFAULT_STACKSIZE (1024)
13390 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
13391 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
13392 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
13393
13394 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
13395
13396 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
13397 unsigned long gdt, tss;
13398
13399 store_gdt(&gdt_desc);
13400 - gdt = gdt_desc.address;
13401 + gdt = (unsigned long)gdt_desc.address;
13402
13403 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
13404
13405 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cach
13406 /* 0x2 bit is always set */
13407 .flags = X86_EFLAGS_SF | 0x2,
13408 .sp = STACK_START,
13409 - .es = __USER_DS,
13410 + .es = __KERNEL_DS,
13411 .cs = __KERNEL_CS,
13412 .ss = __KERNEL_DS,
13413 - .ds = __USER_DS,
13414 + .ds = __KERNEL_DS,
13415 .fs = __KERNEL_PERCPU,
13416
13417 .__cr3 = __pa_nodebug(swapper_pg_dir),
13418 diff -urNp linux-2.6.39.2/arch/x86/kernel/dumpstack_32.c linux-2.6.39.2/arch/x86/kernel/dumpstack_32.c
13419 --- linux-2.6.39.2/arch/x86/kernel/dumpstack_32.c 2011-05-19 00:06:34.000000000 -0400
13420 +++ linux-2.6.39.2/arch/x86/kernel/dumpstack_32.c 2011-05-22 19:36:30.000000000 -0400
13421 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task
13422 bp = stack_frame(task, regs);
13423
13424 for (;;) {
13425 - struct thread_info *context;
13426 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13427
13428 - context = (struct thread_info *)
13429 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
13430 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
13431 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13432
13433 - stack = (unsigned long *)context->previous_esp;
13434 - if (!stack)
13435 + if (stack_start == task_stack_page(task))
13436 break;
13437 + stack = *(unsigned long **)stack_start;
13438 if (ops->stack(data, "IRQ") < 0)
13439 break;
13440 touch_nmi_watchdog();
13441 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs
13442 * When in-kernel, we also print out the stack and code at the
13443 * time of the fault..
13444 */
13445 - if (!user_mode_vm(regs)) {
13446 + if (!user_mode(regs)) {
13447 unsigned int code_prologue = code_bytes * 43 / 64;
13448 unsigned int code_len = code_bytes;
13449 unsigned char c;
13450 u8 *ip;
13451 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
13452
13453 printk(KERN_EMERG "Stack:\n");
13454 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
13455
13456 printk(KERN_EMERG "Code: ");
13457
13458 - ip = (u8 *)regs->ip - code_prologue;
13459 + ip = (u8 *)regs->ip - code_prologue + cs_base;
13460 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
13461 /* try starting at IP */
13462 - ip = (u8 *)regs->ip;
13463 + ip = (u8 *)regs->ip + cs_base;
13464 code_len = code_len - code_prologue + 1;
13465 }
13466 for (i = 0; i < code_len; i++, ip++) {
13467 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs
13468 printk(" Bad EIP value.");
13469 break;
13470 }
13471 - if (ip == (u8 *)regs->ip)
13472 + if (ip == (u8 *)regs->ip + cs_base)
13473 printk("<%02x> ", c);
13474 else
13475 printk("%02x ", c);
13476 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
13477 {
13478 unsigned short ud2;
13479
13480 + ip = ktla_ktva(ip);
13481 if (ip < PAGE_OFFSET)
13482 return 0;
13483 if (probe_kernel_address((unsigned short *)ip, ud2))
13484 diff -urNp linux-2.6.39.2/arch/x86/kernel/dumpstack_64.c linux-2.6.39.2/arch/x86/kernel/dumpstack_64.c
13485 --- linux-2.6.39.2/arch/x86/kernel/dumpstack_64.c 2011-05-19 00:06:34.000000000 -0400
13486 +++ linux-2.6.39.2/arch/x86/kernel/dumpstack_64.c 2011-05-22 19:36:30.000000000 -0400
13487 @@ -147,9 +147,9 @@ void dump_trace(struct task_struct *task
13488 unsigned long *irq_stack_end =
13489 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
13490 unsigned used = 0;
13491 - struct thread_info *tinfo;
13492 int graph = 0;
13493 unsigned long dummy;
13494 + void *stack_start;
13495
13496 if (!task)
13497 task = current;
13498 @@ -167,10 +167,10 @@ void dump_trace(struct task_struct *task
13499 * current stack address. If the stacks consist of nested
13500 * exceptions
13501 */
13502 - tinfo = task_thread_info(task);
13503 for (;;) {
13504 char *id;
13505 unsigned long *estack_end;
13506 +
13507 estack_end = in_exception_stack(cpu, (unsigned long)stack,
13508 &used, &id);
13509
13510 @@ -178,7 +178,7 @@ void dump_trace(struct task_struct *task
13511 if (ops->stack(data, id) < 0)
13512 break;
13513
13514 - bp = ops->walk_stack(tinfo, stack, bp, ops,
13515 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
13516 data, estack_end, &graph);
13517 ops->stack(data, "<EOE>");
13518 /*
13519 @@ -197,7 +197,7 @@ void dump_trace(struct task_struct *task
13520 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
13521 if (ops->stack(data, "IRQ") < 0)
13522 break;
13523 - bp = ops->walk_stack(tinfo, stack, bp,
13524 + bp = ops->walk_stack(task, irq_stack, stack, bp,
13525 ops, data, irq_stack_end, &graph);
13526 /*
13527 * We link to the next stack (which would be
13528 @@ -218,7 +218,8 @@ void dump_trace(struct task_struct *task
13529 /*
13530 * This handles the process stack:
13531 */
13532 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
13533 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
13534 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
13535 put_cpu();
13536 }
13537 EXPORT_SYMBOL(dump_trace);
13538 diff -urNp linux-2.6.39.2/arch/x86/kernel/dumpstack.c linux-2.6.39.2/arch/x86/kernel/dumpstack.c
13539 --- linux-2.6.39.2/arch/x86/kernel/dumpstack.c 2011-05-19 00:06:34.000000000 -0400
13540 +++ linux-2.6.39.2/arch/x86/kernel/dumpstack.c 2011-05-22 19:41:32.000000000 -0400
13541 @@ -2,6 +2,9 @@
13542 * Copyright (C) 1991, 1992 Linus Torvalds
13543 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
13544 */
13545 +#ifdef CONFIG_GRKERNSEC_HIDESYM
13546 +#define __INCLUDED_BY_HIDESYM 1
13547 +#endif
13548 #include <linux/kallsyms.h>
13549 #include <linux/kprobes.h>
13550 #include <linux/uaccess.h>
13551 @@ -35,9 +38,8 @@ void printk_address(unsigned long addres
13552 static void
13553 print_ftrace_graph_addr(unsigned long addr, void *data,
13554 const struct stacktrace_ops *ops,
13555 - struct thread_info *tinfo, int *graph)
13556 + struct task_struct *task, int *graph)
13557 {
13558 - struct task_struct *task = tinfo->task;
13559 unsigned long ret_addr;
13560 int index = task->curr_ret_stack;
13561
13562 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long ad
13563 static inline void
13564 print_ftrace_graph_addr(unsigned long addr, void *data,
13565 const struct stacktrace_ops *ops,
13566 - struct thread_info *tinfo, int *graph)
13567 + struct task_struct *task, int *graph)
13568 { }
13569 #endif
13570
13571 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long ad
13572 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
13573 */
13574
13575 -static inline int valid_stack_ptr(struct thread_info *tinfo,
13576 - void *p, unsigned int size, void *end)
13577 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
13578 {
13579 - void *t = tinfo;
13580 if (end) {
13581 if (p < end && p >= (end-THREAD_SIZE))
13582 return 1;
13583 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct
13584 }
13585
13586 unsigned long
13587 -print_context_stack(struct thread_info *tinfo,
13588 +print_context_stack(struct task_struct *task, void *stack_start,
13589 unsigned long *stack, unsigned long bp,
13590 const struct stacktrace_ops *ops, void *data,
13591 unsigned long *end, int *graph)
13592 {
13593 struct stack_frame *frame = (struct stack_frame *)bp;
13594
13595 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
13596 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
13597 unsigned long addr;
13598
13599 addr = *stack;
13600 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *
13601 } else {
13602 ops->address(data, addr, 0);
13603 }
13604 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13605 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13606 }
13607 stack++;
13608 }
13609 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *
13610 EXPORT_SYMBOL_GPL(print_context_stack);
13611
13612 unsigned long
13613 -print_context_stack_bp(struct thread_info *tinfo,
13614 +print_context_stack_bp(struct task_struct *task, void *stack_start,
13615 unsigned long *stack, unsigned long bp,
13616 const struct stacktrace_ops *ops, void *data,
13617 unsigned long *end, int *graph)
13618 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_inf
13619 struct stack_frame *frame = (struct stack_frame *)bp;
13620 unsigned long *ret_addr = &frame->return_address;
13621
13622 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
13623 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
13624 unsigned long addr = *ret_addr;
13625
13626 if (!__kernel_text_address(addr))
13627 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_inf
13628 ops->address(data, addr, 1);
13629 frame = frame->next_frame;
13630 ret_addr = &frame->return_address;
13631 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
13632 + print_ftrace_graph_addr(addr, data, ops, task, graph);
13633 }
13634
13635 return (unsigned long)frame;
13636 @@ -202,7 +202,7 @@ void dump_stack(void)
13637
13638 bp = stack_frame(current, NULL);
13639 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
13640 - current->pid, current->comm, print_tainted(),
13641 + task_pid_nr(current), current->comm, print_tainted(),
13642 init_utsname()->release,
13643 (int)strcspn(init_utsname()->version, " "),
13644 init_utsname()->version);
13645 @@ -238,6 +238,8 @@ unsigned __kprobes long oops_begin(void)
13646 }
13647 EXPORT_SYMBOL_GPL(oops_begin);
13648
13649 +extern void gr_handle_kernel_exploit(void);
13650 +
13651 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
13652 {
13653 if (regs && kexec_should_crash(current))
13654 @@ -259,7 +261,10 @@ void __kprobes oops_end(unsigned long fl
13655 panic("Fatal exception in interrupt");
13656 if (panic_on_oops)
13657 panic("Fatal exception");
13658 - do_exit(signr);
13659 +
13660 + gr_handle_kernel_exploit();
13661 +
13662 + do_group_exit(signr);
13663 }
13664
13665 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
13666 @@ -286,7 +291,7 @@ int __kprobes __die(const char *str, str
13667
13668 show_registers(regs);
13669 #ifdef CONFIG_X86_32
13670 - if (user_mode_vm(regs)) {
13671 + if (user_mode(regs)) {
13672 sp = regs->sp;
13673 ss = regs->ss & 0xffff;
13674 } else {
13675 @@ -314,7 +319,7 @@ void die(const char *str, struct pt_regs
13676 unsigned long flags = oops_begin();
13677 int sig = SIGSEGV;
13678
13679 - if (!user_mode_vm(regs))
13680 + if (!user_mode(regs))
13681 report_bug(regs->ip, regs);
13682
13683 if (__die(str, regs, err))
13684 diff -urNp linux-2.6.39.2/arch/x86/kernel/early_printk.c linux-2.6.39.2/arch/x86/kernel/early_printk.c
13685 --- linux-2.6.39.2/arch/x86/kernel/early_printk.c 2011-05-19 00:06:34.000000000 -0400
13686 +++ linux-2.6.39.2/arch/x86/kernel/early_printk.c 2011-05-22 19:36:30.000000000 -0400
13687 @@ -7,6 +7,7 @@
13688 #include <linux/pci_regs.h>
13689 #include <linux/pci_ids.h>
13690 #include <linux/errno.h>
13691 +#include <linux/sched.h>
13692 #include <asm/io.h>
13693 #include <asm/processor.h>
13694 #include <asm/fcntl.h>
13695 @@ -179,6 +180,8 @@ asmlinkage void early_printk(const char
13696 int n;
13697 va_list ap;
13698
13699 + pax_track_stack();
13700 +
13701 va_start(ap, fmt);
13702 n = vscnprintf(buf, sizeof(buf), fmt, ap);
13703 early_console->write(early_console, buf, n);
13704 diff -urNp linux-2.6.39.2/arch/x86/kernel/entry_32.S linux-2.6.39.2/arch/x86/kernel/entry_32.S
13705 --- linux-2.6.39.2/arch/x86/kernel/entry_32.S 2011-05-19 00:06:34.000000000 -0400
13706 +++ linux-2.6.39.2/arch/x86/kernel/entry_32.S 2011-05-23 17:07:00.000000000 -0400
13707 @@ -185,13 +185,146 @@
13708 /*CFI_REL_OFFSET gs, PT_GS*/
13709 .endm
13710 .macro SET_KERNEL_GS reg
13711 +
13712 +#ifdef CONFIG_CC_STACKPROTECTOR
13713 movl $(__KERNEL_STACK_CANARY), \reg
13714 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
13715 + movl $(__USER_DS), \reg
13716 +#else
13717 + xorl \reg, \reg
13718 +#endif
13719 +
13720 movl \reg, %gs
13721 .endm
13722
13723 #endif /* CONFIG_X86_32_LAZY_GS */
13724
13725 -.macro SAVE_ALL
13726 +.macro pax_enter_kernel
13727 +#ifdef CONFIG_PAX_KERNEXEC
13728 + call pax_enter_kernel
13729 +#endif
13730 +.endm
13731 +
13732 +.macro pax_exit_kernel
13733 +#ifdef CONFIG_PAX_KERNEXEC
13734 + call pax_exit_kernel
13735 +#endif
13736 +.endm
13737 +
13738 +#ifdef CONFIG_PAX_KERNEXEC
13739 +ENTRY(pax_enter_kernel)
13740 +#ifdef CONFIG_PARAVIRT
13741 + pushl %eax
13742 + pushl %ecx
13743 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13744 + mov %eax, %esi
13745 +#else
13746 + mov %cr0, %esi
13747 +#endif
13748 + bts $16, %esi
13749 + jnc 1f
13750 + mov %cs, %esi
13751 + cmp $__KERNEL_CS, %esi
13752 + jz 3f
13753 + ljmp $__KERNEL_CS, $3f
13754 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13755 +2:
13756 +#ifdef CONFIG_PARAVIRT
13757 + mov %esi, %eax
13758 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13759 +#else
13760 + mov %esi, %cr0
13761 +#endif
13762 +3:
13763 +#ifdef CONFIG_PARAVIRT
13764 + popl %ecx
13765 + popl %eax
13766 +#endif
13767 + ret
13768 +ENDPROC(pax_enter_kernel)
13769 +
13770 +ENTRY(pax_exit_kernel)
13771 +#ifdef CONFIG_PARAVIRT
13772 + pushl %eax
13773 + pushl %ecx
13774 +#endif
13775 + mov %cs, %esi
13776 + cmp $__KERNEXEC_KERNEL_CS, %esi
13777 + jnz 2f
13778 +#ifdef CONFIG_PARAVIRT
13779 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13780 + mov %eax, %esi
13781 +#else
13782 + mov %cr0, %esi
13783 +#endif
13784 + btr $16, %esi
13785 + ljmp $__KERNEL_CS, $1f
13786 +1:
13787 +#ifdef CONFIG_PARAVIRT
13788 + mov %esi, %eax
13789 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13790 +#else
13791 + mov %esi, %cr0
13792 +#endif
13793 +2:
13794 +#ifdef CONFIG_PARAVIRT
13795 + popl %ecx
13796 + popl %eax
13797 +#endif
13798 + ret
13799 +ENDPROC(pax_exit_kernel)
13800 +#endif
13801 +
13802 +.macro pax_erase_kstack
13803 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13804 + call pax_erase_kstack
13805 +#endif
13806 +.endm
13807 +
13808 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13809 +/*
13810 + * ebp: thread_info
13811 + * ecx, edx: can be clobbered
13812 + */
13813 +ENTRY(pax_erase_kstack)
13814 + pushl %edi
13815 + pushl %eax
13816 +
13817 + mov TI_lowest_stack(%ebp), %edi
13818 + mov $-0xBEEF, %eax
13819 + std
13820 +
13821 +1: mov %edi, %ecx
13822 + and $THREAD_SIZE_asm - 1, %ecx
13823 + shr $2, %ecx
13824 + repne scasl
13825 + jecxz 2f
13826 +
13827 + cmp $2*16, %ecx
13828 + jc 2f
13829 +
13830 + mov $2*16, %ecx
13831 + repe scasl
13832 + jecxz 2f
13833 + jne 1b
13834 +
13835 +2: cld
13836 + mov %esp, %ecx
13837 + sub %edi, %ecx
13838 + shr $2, %ecx
13839 + rep stosl
13840 +
13841 + mov TI_task_thread_sp0(%ebp), %edi
13842 + sub $128, %edi
13843 + mov %edi, TI_lowest_stack(%ebp)
13844 +
13845 + popl %eax
13846 + popl %edi
13847 + ret
13848 +ENDPROC(pax_erase_kstack)
13849 +#endif
13850 +
13851 +.macro __SAVE_ALL _DS
13852 cld
13853 PUSH_GS
13854 pushl_cfi %fs
13855 @@ -214,7 +347,7 @@
13856 CFI_REL_OFFSET ecx, 0
13857 pushl_cfi %ebx
13858 CFI_REL_OFFSET ebx, 0
13859 - movl $(__USER_DS), %edx
13860 + movl $\_DS, %edx
13861 movl %edx, %ds
13862 movl %edx, %es
13863 movl $(__KERNEL_PERCPU), %edx
13864 @@ -222,6 +355,15 @@
13865 SET_KERNEL_GS %edx
13866 .endm
13867
13868 +.macro SAVE_ALL
13869 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13870 + __SAVE_ALL __KERNEL_DS
13871 + pax_enter_kernel
13872 +#else
13873 + __SAVE_ALL __USER_DS
13874 +#endif
13875 +.endm
13876 +
13877 .macro RESTORE_INT_REGS
13878 popl_cfi %ebx
13879 CFI_RESTORE ebx
13880 @@ -332,7 +474,15 @@ check_userspace:
13881 movb PT_CS(%esp), %al
13882 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13883 cmpl $USER_RPL, %eax
13884 +
13885 +#ifdef CONFIG_PAX_KERNEXEC
13886 + jae resume_userspace
13887 +
13888 + PAX_EXIT_KERNEL
13889 + jmp resume_kernel
13890 +#else
13891 jb resume_kernel # not returning to v8086 or userspace
13892 +#endif
13893
13894 ENTRY(resume_userspace)
13895 LOCKDEP_SYS_EXIT
13896 @@ -344,7 +494,7 @@ ENTRY(resume_userspace)
13897 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13898 # int/exception return?
13899 jne work_pending
13900 - jmp restore_all
13901 + jmp restore_all_pax
13902 END(ret_from_exception)
13903
13904 #ifdef CONFIG_PREEMPT
13905 @@ -394,23 +544,34 @@ sysenter_past_esp:
13906 /*CFI_REL_OFFSET cs, 0*/
13907 /*
13908 * Push current_thread_info()->sysenter_return to the stack.
13909 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13910 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
13911 */
13912 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13913 + pushl_cfi $0
13914 CFI_REL_OFFSET eip, 0
13915
13916 pushl_cfi %eax
13917 SAVE_ALL
13918 + GET_THREAD_INFO(%ebp)
13919 + movl TI_sysenter_return(%ebp),%ebp
13920 + movl %ebp,PT_EIP(%esp)
13921 ENABLE_INTERRUPTS(CLBR_NONE)
13922
13923 /*
13924 * Load the potential sixth argument from user stack.
13925 * Careful about security.
13926 */
13927 + movl PT_OLDESP(%esp),%ebp
13928 +
13929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13930 + mov PT_OLDSS(%esp),%ds
13931 +1: movl %ds:(%ebp),%ebp
13932 + push %ss
13933 + pop %ds
13934 +#else
13935 cmpl $__PAGE_OFFSET-3,%ebp
13936 jae syscall_fault
13937 1: movl (%ebp),%ebp
13938 +#endif
13939 +
13940 movl %ebp,PT_EBP(%esp)
13941 .section __ex_table,"a"
13942 .align 4
13943 @@ -433,12 +594,23 @@ sysenter_do_call:
13944 testl $_TIF_ALLWORK_MASK, %ecx
13945 jne sysexit_audit
13946 sysenter_exit:
13947 +
13948 +#ifdef CONFIG_PAX_RANDKSTACK
13949 + pushl_cfi %eax
13950 + call pax_randomize_kstack
13951 + popl_cfi %eax
13952 +#endif
13953 +
13954 + pax_erase_kstack
13955 +
13956 /* if something modifies registers it must also disable sysexit */
13957 movl PT_EIP(%esp), %edx
13958 movl PT_OLDESP(%esp), %ecx
13959 xorl %ebp,%ebp
13960 TRACE_IRQS_ON
13961 1: mov PT_FS(%esp), %fs
13962 +2: mov PT_DS(%esp), %ds
13963 +3: mov PT_ES(%esp), %es
13964 PTGS_TO_GS
13965 ENABLE_INTERRUPTS_SYSEXIT
13966
13967 @@ -455,6 +627,9 @@ sysenter_audit:
13968 movl %eax,%edx /* 2nd arg: syscall number */
13969 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13970 call audit_syscall_entry
13971 +
13972 + pax_erase_kstack
13973 +
13974 pushl_cfi %ebx
13975 movl PT_EAX(%esp),%eax /* reload syscall number */
13976 jmp sysenter_do_call
13977 @@ -481,11 +656,17 @@ sysexit_audit:
13978
13979 CFI_ENDPROC
13980 .pushsection .fixup,"ax"
13981 -2: movl $0,PT_FS(%esp)
13982 +4: movl $0,PT_FS(%esp)
13983 + jmp 1b
13984 +5: movl $0,PT_DS(%esp)
13985 + jmp 1b
13986 +6: movl $0,PT_ES(%esp)
13987 jmp 1b
13988 .section __ex_table,"a"
13989 .align 4
13990 - .long 1b,2b
13991 + .long 1b,4b
13992 + .long 2b,5b
13993 + .long 3b,6b
13994 .popsection
13995 PTGS_TO_GS_EX
13996 ENDPROC(ia32_sysenter_target)
13997 @@ -518,6 +699,14 @@ syscall_exit:
13998 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13999 jne syscall_exit_work
14000
14001 +restore_all_pax:
14002 +
14003 +#ifdef CONFIG_PAX_RANDKSTACK
14004 + call pax_randomize_kstack
14005 +#endif
14006 +
14007 + pax_erase_kstack
14008 +
14009 restore_all:
14010 TRACE_IRQS_IRET
14011 restore_all_notrace:
14012 @@ -577,14 +766,21 @@ ldt_ss:
14013 * compensating for the offset by changing to the ESPFIX segment with
14014 * a base address that matches for the difference.
14015 */
14016 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
14017 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
14018 mov %esp, %edx /* load kernel esp */
14019 mov PT_OLDESP(%esp), %eax /* load userspace esp */
14020 mov %dx, %ax /* eax: new kernel esp */
14021 sub %eax, %edx /* offset (low word is 0) */
14022 +#ifdef CONFIG_SMP
14023 + movl PER_CPU_VAR(cpu_number), %ebx
14024 + shll $PAGE_SHIFT_asm, %ebx
14025 + addl $cpu_gdt_table, %ebx
14026 +#else
14027 + movl $cpu_gdt_table, %ebx
14028 +#endif
14029 shr $16, %edx
14030 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
14031 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
14032 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
14033 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
14034 pushl_cfi $__ESPFIX_SS
14035 pushl_cfi %eax /* new kernel esp */
14036 /* Disable interrupts, but do not irqtrace this section: we
14037 @@ -613,29 +809,23 @@ work_resched:
14038 movl TI_flags(%ebp), %ecx
14039 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
14040 # than syscall tracing?
14041 - jz restore_all
14042 + jz restore_all_pax
14043 testb $_TIF_NEED_RESCHED, %cl
14044 jnz work_resched
14045
14046 work_notifysig: # deal with pending signals and
14047 # notify-resume requests
14048 + movl %esp, %eax
14049 #ifdef CONFIG_VM86
14050 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
14051 - movl %esp, %eax
14052 - jne work_notifysig_v86 # returning to kernel-space or
14053 + jz 1f # returning to kernel-space or
14054 # vm86-space
14055 - xorl %edx, %edx
14056 - call do_notify_resume
14057 - jmp resume_userspace_sig
14058
14059 - ALIGN
14060 -work_notifysig_v86:
14061 pushl_cfi %ecx # save ti_flags for do_notify_resume
14062 call save_v86_state # %eax contains pt_regs pointer
14063 popl_cfi %ecx
14064 movl %eax, %esp
14065 -#else
14066 - movl %esp, %eax
14067 +1:
14068 #endif
14069 xorl %edx, %edx
14070 call do_notify_resume
14071 @@ -648,6 +838,9 @@ syscall_trace_entry:
14072 movl $-ENOSYS,PT_EAX(%esp)
14073 movl %esp, %eax
14074 call syscall_trace_enter
14075 +
14076 + pax_erase_kstack
14077 +
14078 /* What it returned is what we'll actually use. */
14079 cmpl $(nr_syscalls), %eax
14080 jnae syscall_call
14081 @@ -670,6 +863,10 @@ END(syscall_exit_work)
14082
14083 RING0_INT_FRAME # can't unwind into user space anyway
14084 syscall_fault:
14085 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14086 + push %ss
14087 + pop %ds
14088 +#endif
14089 GET_THREAD_INFO(%ebp)
14090 movl $-EFAULT,PT_EAX(%esp)
14091 jmp resume_userspace
14092 @@ -752,6 +949,36 @@ ptregs_clone:
14093 CFI_ENDPROC
14094 ENDPROC(ptregs_clone)
14095
14096 + ALIGN;
14097 +ENTRY(kernel_execve)
14098 + CFI_STARTPROC
14099 + pushl_cfi %ebp
14100 + sub $PT_OLDSS+4,%esp
14101 + pushl_cfi %edi
14102 + pushl_cfi %ecx
14103 + pushl_cfi %eax
14104 + lea 3*4(%esp),%edi
14105 + mov $PT_OLDSS/4+1,%ecx
14106 + xorl %eax,%eax
14107 + rep stosl
14108 + popl_cfi %eax
14109 + popl_cfi %ecx
14110 + popl_cfi %edi
14111 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
14112 + pushl_cfi %esp
14113 + call sys_execve
14114 + add $4,%esp
14115 + CFI_ADJUST_CFA_OFFSET -4
14116 + GET_THREAD_INFO(%ebp)
14117 + test %eax,%eax
14118 + jz syscall_exit
14119 + add $PT_OLDSS+4,%esp
14120 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
14121 + popl_cfi %ebp
14122 + ret
14123 + CFI_ENDPROC
14124 +ENDPROC(kernel_execve)
14125 +
14126 .macro FIXUP_ESPFIX_STACK
14127 /*
14128 * Switch back for ESPFIX stack to the normal zerobased stack
14129 @@ -761,8 +988,15 @@ ENDPROC(ptregs_clone)
14130 * normal stack and adjusts ESP with the matching offset.
14131 */
14132 /* fixup the stack */
14133 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
14134 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
14135 +#ifdef CONFIG_SMP
14136 + movl PER_CPU_VAR(cpu_number), %ebx
14137 + shll $PAGE_SHIFT_asm, %ebx
14138 + addl $cpu_gdt_table, %ebx
14139 +#else
14140 + movl $cpu_gdt_table, %ebx
14141 +#endif
14142 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
14143 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
14144 shl $16, %eax
14145 addl %esp, %eax /* the adjusted stack pointer */
14146 pushl_cfi $__KERNEL_DS
14147 @@ -1213,7 +1447,6 @@ return_to_handler:
14148 jmp *%ecx
14149 #endif
14150
14151 -.section .rodata,"a"
14152 #include "syscall_table_32.S"
14153
14154 syscall_table_size=(.-sys_call_table)
14155 @@ -1259,9 +1492,12 @@ error_code:
14156 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
14157 REG_TO_PTGS %ecx
14158 SET_KERNEL_GS %ecx
14159 - movl $(__USER_DS), %ecx
14160 + movl $(__KERNEL_DS), %ecx
14161 movl %ecx, %ds
14162 movl %ecx, %es
14163 +
14164 + pax_enter_kernel
14165 +
14166 TRACE_IRQS_OFF
14167 movl %esp,%eax # pt_regs pointer
14168 call *%edi
14169 @@ -1346,6 +1582,9 @@ nmi_stack_correct:
14170 xorl %edx,%edx # zero error code
14171 movl %esp,%eax # pt_regs pointer
14172 call do_nmi
14173 +
14174 + pax_exit_kernel
14175 +
14176 jmp restore_all_notrace
14177 CFI_ENDPROC
14178
14179 @@ -1382,6 +1621,9 @@ nmi_espfix_stack:
14180 FIXUP_ESPFIX_STACK # %eax == %esp
14181 xorl %edx,%edx # zero error code
14182 call do_nmi
14183 +
14184 + pax_exit_kernel
14185 +
14186 RESTORE_REGS
14187 lss 12+4(%esp), %esp # back to espfix stack
14188 CFI_ADJUST_CFA_OFFSET -24
14189 diff -urNp linux-2.6.39.2/arch/x86/kernel/entry_64.S linux-2.6.39.2/arch/x86/kernel/entry_64.S
14190 --- linux-2.6.39.2/arch/x86/kernel/entry_64.S 2011-05-19 00:06:34.000000000 -0400
14191 +++ linux-2.6.39.2/arch/x86/kernel/entry_64.S 2011-05-23 17:10:49.000000000 -0400
14192 @@ -53,6 +53,7 @@
14193 #include <asm/paravirt.h>
14194 #include <asm/ftrace.h>
14195 #include <asm/percpu.h>
14196 +#include <asm/pgtable.h>
14197
14198 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14199 #include <linux/elf-em.h>
14200 @@ -176,6 +177,259 @@ ENTRY(native_usergs_sysret64)
14201 ENDPROC(native_usergs_sysret64)
14202 #endif /* CONFIG_PARAVIRT */
14203
14204 + .macro ljmpq sel, off
14205 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
14206 + .byte 0x48; ljmp *1234f(%rip)
14207 + .pushsection .rodata
14208 + .align 16
14209 + 1234: .quad \off; .word \sel
14210 + .popsection
14211 +#else
14212 + pushq $\sel
14213 + pushq $\off
14214 + lretq
14215 +#endif
14216 + .endm
14217 +
14218 + .macro pax_enter_kernel
14219 +#ifdef CONFIG_PAX_KERNEXEC
14220 + call pax_enter_kernel
14221 +#endif
14222 + .endm
14223 +
14224 + .macro pax_exit_kernel
14225 +#ifdef CONFIG_PAX_KERNEXEC
14226 + call pax_exit_kernel
14227 +#endif
14228 + .endm
14229 +
14230 +#ifdef CONFIG_PAX_KERNEXEC
14231 +ENTRY(pax_enter_kernel)
14232 + pushq %rdi
14233 +
14234 +#ifdef CONFIG_PARAVIRT
14235 + PV_SAVE_REGS(CLBR_RDI)
14236 +#endif
14237 +
14238 + GET_CR0_INTO_RDI
14239 + bts $16,%rdi
14240 + jnc 1f
14241 + mov %cs,%edi
14242 + cmp $__KERNEL_CS,%edi
14243 + jz 3f
14244 + ljmpq __KERNEL_CS,3f
14245 +1: ljmpq __KERNEXEC_KERNEL_CS,2f
14246 +2: SET_RDI_INTO_CR0
14247 +3:
14248 +
14249 +#ifdef CONFIG_PARAVIRT
14250 + PV_RESTORE_REGS(CLBR_RDI)
14251 +#endif
14252 +
14253 + popq %rdi
14254 + retq
14255 +ENDPROC(pax_enter_kernel)
14256 +
14257 +ENTRY(pax_exit_kernel)
14258 + pushq %rdi
14259 +
14260 +#ifdef CONFIG_PARAVIRT
14261 + PV_SAVE_REGS(CLBR_RDI)
14262 +#endif
14263 +
14264 + mov %cs,%rdi
14265 + cmp $__KERNEXEC_KERNEL_CS,%edi
14266 + jnz 2f
14267 + GET_CR0_INTO_RDI
14268 + btr $16,%rdi
14269 + ljmpq __KERNEL_CS,1f
14270 +1: SET_RDI_INTO_CR0
14271 +2:
14272 +
14273 +#ifdef CONFIG_PARAVIRT
14274 + PV_RESTORE_REGS(CLBR_RDI);
14275 +#endif
14276 +
14277 + popq %rdi
14278 + retq
14279 +ENDPROC(pax_exit_kernel)
14280 +#endif
14281 +
14282 + .macro pax_enter_kernel_user
14283 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14284 + call pax_enter_kernel_user
14285 +#endif
14286 + .endm
14287 +
14288 + .macro pax_exit_kernel_user
14289 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14290 + call pax_exit_kernel_user
14291 +#endif
14292 +#ifdef CONFIG_PAX_RANDKSTACK
14293 + push %rax
14294 + call pax_randomize_kstack
14295 + pop %rax
14296 +#endif
14297 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14298 + call pax_erase_kstack
14299 +#endif
14300 + .endm
14301 +
14302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14303 +ENTRY(pax_enter_kernel_user)
14304 + pushq %rdi
14305 + pushq %rbx
14306 +
14307 +#ifdef CONFIG_PARAVIRT
14308 + PV_SAVE_REGS(CLBR_RDI)
14309 +#endif
14310 +
14311 + GET_CR3_INTO_RDI
14312 + mov %rdi,%rbx
14313 + add $__START_KERNEL_map,%rbx
14314 + sub phys_base(%rip),%rbx
14315 +
14316 +#ifdef CONFIG_PARAVIRT
14317 + pushq %rdi
14318 + cmpl $0, pv_info+PARAVIRT_enabled
14319 + jz 1f
14320 + i = 0
14321 + .rept USER_PGD_PTRS
14322 + mov i*8(%rbx),%rsi
14323 + mov $0,%sil
14324 + lea i*8(%rbx),%rdi
14325 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14326 + i = i + 1
14327 + .endr
14328 + jmp 2f
14329 +1:
14330 +#endif
14331 +
14332 + i = 0
14333 + .rept USER_PGD_PTRS
14334 + movb $0,i*8(%rbx)
14335 + i = i + 1
14336 + .endr
14337 +
14338 +#ifdef CONFIG_PARAVIRT
14339 +2: popq %rdi
14340 +#endif
14341 + SET_RDI_INTO_CR3
14342 +
14343 +#ifdef CONFIG_PAX_KERNEXEC
14344 + GET_CR0_INTO_RDI
14345 + bts $16,%rdi
14346 + SET_RDI_INTO_CR0
14347 +#endif
14348 +
14349 +#ifdef CONFIG_PARAVIRT
14350 + PV_RESTORE_REGS(CLBR_RDI)
14351 +#endif
14352 +
14353 + popq %rbx
14354 + popq %rdi
14355 + retq
14356 +ENDPROC(pax_enter_kernel_user)
14357 +
14358 +ENTRY(pax_exit_kernel_user)
14359 + push %rdi
14360 +
14361 +#ifdef CONFIG_PARAVIRT
14362 + pushq %rbx
14363 + PV_SAVE_REGS(CLBR_RDI)
14364 +#endif
14365 +
14366 +#ifdef CONFIG_PAX_KERNEXEC
14367 + GET_CR0_INTO_RDI
14368 + btr $16,%rdi
14369 + SET_RDI_INTO_CR0
14370 +#endif
14371 +
14372 + GET_CR3_INTO_RDI
14373 + add $__START_KERNEL_map,%rdi
14374 + sub phys_base(%rip),%rdi
14375 +
14376 +#ifdef CONFIG_PARAVIRT
14377 + cmpl $0, pv_info+PARAVIRT_enabled
14378 + jz 1f
14379 + mov %rdi,%rbx
14380 + i = 0
14381 + .rept USER_PGD_PTRS
14382 + mov i*8(%rbx),%rsi
14383 + mov $0x67,%sil
14384 + lea i*8(%rbx),%rdi
14385 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd)
14386 + i = i + 1
14387 + .endr
14388 + jmp 2f
14389 +1:
14390 +#endif
14391 +
14392 + i = 0
14393 + .rept USER_PGD_PTRS
14394 + movb $0x67,i*8(%rdi)
14395 + i = i + 1
14396 + .endr
14397 +
14398 +#ifdef CONFIG_PARAVIRT
14399 +2: PV_RESTORE_REGS(CLBR_RDI)
14400 + popq %rbx
14401 +#endif
14402 +
14403 + popq %rdi
14404 + retq
14405 +ENDPROC(pax_exit_kernel_user)
14406 +#endif
14407 +
14408 + .macro pax_erase_kstack
14409 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14410 + call pax_erase_kstack
14411 +#endif
14412 + .endm
14413 +
14414 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14415 +/*
14416 + * r10: thread_info
14417 + * rcx, rdx: can be clobbered
14418 + */
14419 +ENTRY(pax_erase_kstack)
14420 + pushq %rdi
14421 + pushq %rax
14422 +
14423 + GET_THREAD_INFO(%r10)
14424 + mov TI_lowest_stack(%r10), %rdi
14425 + mov $-0xBEEF, %rax
14426 + std
14427 +
14428 +1: mov %edi, %ecx
14429 + and $THREAD_SIZE_asm - 1, %ecx
14430 + shr $3, %ecx
14431 + repne scasq
14432 + jecxz 2f
14433 +
14434 + cmp $2*8, %ecx
14435 + jc 2f
14436 +
14437 + mov $2*8, %ecx
14438 + repe scasq
14439 + jecxz 2f
14440 + jne 1b
14441 +
14442 +2: cld
14443 + mov %esp, %ecx
14444 + sub %edi, %ecx
14445 + shr $3, %ecx
14446 + rep stosq
14447 +
14448 + mov TI_task_thread_sp0(%r10), %rdi
14449 + sub $256, %rdi
14450 + mov %rdi, TI_lowest_stack(%r10)
14451 +
14452 + popq %rax
14453 + popq %rdi
14454 + ret
14455 +ENDPROC(pax_erase_kstack)
14456 +#endif
14457
14458 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14459 #ifdef CONFIG_TRACE_IRQFLAGS
14460 @@ -318,7 +572,7 @@ ENTRY(save_args)
14461 leaq -RBP+8(%rsp),%rdi /* arg1 for handler */
14462 movq_cfi rbp, 8 /* push %rbp */
14463 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
14464 - testl $3, CS(%rdi)
14465 + testb $3, CS(%rdi)
14466 je 1f
14467 SWAPGS
14468 /*
14469 @@ -409,7 +663,7 @@ ENTRY(ret_from_fork)
14470
14471 RESTORE_REST
14472
14473 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14474 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14475 je int_ret_from_sys_call
14476
14477 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14478 @@ -455,7 +709,7 @@ END(ret_from_fork)
14479 ENTRY(system_call)
14480 CFI_STARTPROC simple
14481 CFI_SIGNAL_FRAME
14482 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14483 + CFI_DEF_CFA rsp,0
14484 CFI_REGISTER rip,rcx
14485 /*CFI_REGISTER rflags,r11*/
14486 SWAPGS_UNSAFE_STACK
14487 @@ -468,12 +722,13 @@ ENTRY(system_call_after_swapgs)
14488
14489 movq %rsp,PER_CPU_VAR(old_rsp)
14490 movq PER_CPU_VAR(kernel_stack),%rsp
14491 + pax_enter_kernel_user
14492 /*
14493 * No need to follow this irqs off/on section - it's straight
14494 * and short:
14495 */
14496 ENABLE_INTERRUPTS(CLBR_NONE)
14497 - SAVE_ARGS 8,1
14498 + SAVE_ARGS 8*6,1
14499 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14500 movq %rcx,RIP-ARGOFFSET(%rsp)
14501 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14502 @@ -502,6 +757,7 @@ sysret_check:
14503 andl %edi,%edx
14504 jnz sysret_careful
14505 CFI_REMEMBER_STATE
14506 + pax_exit_kernel_user
14507 /*
14508 * sysretq will re-enable interrupts:
14509 */
14510 @@ -560,6 +816,9 @@ auditsys:
14511 movq %rax,%rsi /* 2nd arg: syscall number */
14512 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14513 call audit_syscall_entry
14514 +
14515 + pax_erase_kstack
14516 +
14517 LOAD_ARGS 0 /* reload call-clobbered registers */
14518 jmp system_call_fastpath
14519
14520 @@ -590,6 +849,9 @@ tracesys:
14521 FIXUP_TOP_OF_STACK %rdi
14522 movq %rsp,%rdi
14523 call syscall_trace_enter
14524 +
14525 + pax_erase_kstack
14526 +
14527 /*
14528 * Reload arg registers from stack in case ptrace changed them.
14529 * We don't reload %rax because syscall_trace_enter() returned
14530 @@ -611,7 +873,7 @@ tracesys:
14531 GLOBAL(int_ret_from_sys_call)
14532 DISABLE_INTERRUPTS(CLBR_NONE)
14533 TRACE_IRQS_OFF
14534 - testl $3,CS-ARGOFFSET(%rsp)
14535 + testb $3,CS-ARGOFFSET(%rsp)
14536 je retint_restore_args
14537 movl $_TIF_ALLWORK_MASK,%edi
14538 /* edi: mask to check */
14539 @@ -793,6 +1055,16 @@ END(interrupt)
14540 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14541 call save_args
14542 PARTIAL_FRAME 0
14543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14544 + testb $3, CS(%rdi)
14545 + jnz 1f
14546 + pax_enter_kernel
14547 + jmp 2f
14548 +1: pax_enter_kernel_user
14549 +2:
14550 +#else
14551 + pax_enter_kernel
14552 +#endif
14553 call \func
14554 .endm
14555
14556 @@ -825,7 +1097,7 @@ ret_from_intr:
14557 CFI_ADJUST_CFA_OFFSET -8
14558 exit_intr:
14559 GET_THREAD_INFO(%rcx)
14560 - testl $3,CS-ARGOFFSET(%rsp)
14561 + testb $3,CS-ARGOFFSET(%rsp)
14562 je retint_kernel
14563
14564 /* Interrupt came from user space */
14565 @@ -847,12 +1119,14 @@ retint_swapgs: /* return to user-space
14566 * The iretq could re-enable interrupts:
14567 */
14568 DISABLE_INTERRUPTS(CLBR_ANY)
14569 + pax_exit_kernel_user
14570 TRACE_IRQS_IRETQ
14571 SWAPGS
14572 jmp restore_args
14573
14574 retint_restore_args: /* return to kernel space */
14575 DISABLE_INTERRUPTS(CLBR_ANY)
14576 + pax_exit_kernel
14577 /*
14578 * The iretq could re-enable interrupts:
14579 */
14580 @@ -1027,6 +1301,16 @@ ENTRY(\sym)
14581 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14582 call error_entry
14583 DEFAULT_FRAME 0
14584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14585 + testb $3, CS(%rsp)
14586 + jnz 1f
14587 + pax_enter_kernel
14588 + jmp 2f
14589 +1: pax_enter_kernel_user
14590 +2:
14591 +#else
14592 + pax_enter_kernel
14593 +#endif
14594 movq %rsp,%rdi /* pt_regs pointer */
14595 xorl %esi,%esi /* no error code */
14596 call \do_sym
14597 @@ -1044,6 +1328,16 @@ ENTRY(\sym)
14598 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14599 call save_paranoid
14600 TRACE_IRQS_OFF
14601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14602 + testb $3, CS(%rsp)
14603 + jnz 1f
14604 + pax_enter_kernel
14605 + jmp 2f
14606 +1: pax_enter_kernel_user
14607 +2:
14608 +#else
14609 + pax_enter_kernel
14610 +#endif
14611 movq %rsp,%rdi /* pt_regs pointer */
14612 xorl %esi,%esi /* no error code */
14613 call \do_sym
14614 @@ -1052,7 +1346,7 @@ ENTRY(\sym)
14615 END(\sym)
14616 .endm
14617
14618 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14619 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14620 .macro paranoidzeroentry_ist sym do_sym ist
14621 ENTRY(\sym)
14622 INTR_FRAME
14623 @@ -1062,8 +1356,24 @@ ENTRY(\sym)
14624 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14625 call save_paranoid
14626 TRACE_IRQS_OFF
14627 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14628 + testb $3, CS(%rsp)
14629 + jnz 1f
14630 + pax_enter_kernel
14631 + jmp 2f
14632 +1: pax_enter_kernel_user
14633 +2:
14634 +#else
14635 + pax_enter_kernel
14636 +#endif
14637 movq %rsp,%rdi /* pt_regs pointer */
14638 xorl %esi,%esi /* no error code */
14639 +#ifdef CONFIG_SMP
14640 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14641 + lea init_tss(%r12), %r12
14642 +#else
14643 + lea init_tss(%rip), %r12
14644 +#endif
14645 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14646 call \do_sym
14647 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14648 @@ -1080,6 +1390,16 @@ ENTRY(\sym)
14649 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14650 call error_entry
14651 DEFAULT_FRAME 0
14652 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14653 + testb $3, CS(%rsp)
14654 + jnz 1f
14655 + pax_enter_kernel
14656 + jmp 2f
14657 +1: pax_enter_kernel_user
14658 +2:
14659 +#else
14660 + pax_enter_kernel
14661 +#endif
14662 movq %rsp,%rdi /* pt_regs pointer */
14663 movq ORIG_RAX(%rsp),%rsi /* get error code */
14664 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14665 @@ -1099,6 +1419,16 @@ ENTRY(\sym)
14666 call save_paranoid
14667 DEFAULT_FRAME 0
14668 TRACE_IRQS_OFF
14669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14670 + testb $3, CS(%rsp)
14671 + jnz 1f
14672 + pax_enter_kernel
14673 + jmp 2f
14674 +1: pax_enter_kernel_user
14675 +2:
14676 +#else
14677 + pax_enter_kernel
14678 +#endif
14679 movq %rsp,%rdi /* pt_regs pointer */
14680 movq ORIG_RAX(%rsp),%rsi /* get error code */
14681 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14682 @@ -1361,14 +1691,27 @@ ENTRY(paranoid_exit)
14683 TRACE_IRQS_OFF
14684 testl %ebx,%ebx /* swapgs needed? */
14685 jnz paranoid_restore
14686 - testl $3,CS(%rsp)
14687 + testb $3,CS(%rsp)
14688 jnz paranoid_userspace
14689 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14690 + pax_exit_kernel
14691 + TRACE_IRQS_IRETQ 0
14692 + SWAPGS_UNSAFE_STACK
14693 + RESTORE_ALL 8
14694 + jmp irq_return
14695 +#endif
14696 paranoid_swapgs:
14697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14698 + pax_exit_kernel_user
14699 +#else
14700 + pax_exit_kernel
14701 +#endif
14702 TRACE_IRQS_IRETQ 0
14703 SWAPGS_UNSAFE_STACK
14704 RESTORE_ALL 8
14705 jmp irq_return
14706 paranoid_restore:
14707 + pax_exit_kernel
14708 TRACE_IRQS_IRETQ 0
14709 RESTORE_ALL 8
14710 jmp irq_return
14711 @@ -1426,7 +1769,7 @@ ENTRY(error_entry)
14712 movq_cfi r14, R14+8
14713 movq_cfi r15, R15+8
14714 xorl %ebx,%ebx
14715 - testl $3,CS+8(%rsp)
14716 + testb $3,CS+8(%rsp)
14717 je error_kernelspace
14718 error_swapgs:
14719 SWAPGS
14720 @@ -1490,6 +1833,16 @@ ENTRY(nmi)
14721 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14722 call save_paranoid
14723 DEFAULT_FRAME 0
14724 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14725 + testb $3, CS(%rsp)
14726 + jnz 1f
14727 + pax_enter_kernel
14728 + jmp 2f
14729 +1: pax_enter_kernel_user
14730 +2:
14731 +#else
14732 + pax_enter_kernel
14733 +#endif
14734 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14735 movq %rsp,%rdi
14736 movq $-1,%rsi
14737 @@ -1500,11 +1853,25 @@ ENTRY(nmi)
14738 DISABLE_INTERRUPTS(CLBR_NONE)
14739 testl %ebx,%ebx /* swapgs needed? */
14740 jnz nmi_restore
14741 - testl $3,CS(%rsp)
14742 + testb $3,CS(%rsp)
14743 jnz nmi_userspace
14744 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14745 + pax_exit_kernel
14746 + SWAPGS_UNSAFE_STACK
14747 + RESTORE_ALL 8
14748 + jmp irq_return
14749 +#endif
14750 nmi_swapgs:
14751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14752 + pax_exit_kernel_user
14753 +#else
14754 + pax_exit_kernel
14755 +#endif
14756 SWAPGS_UNSAFE_STACK
14757 + RESTORE_ALL 8
14758 + jmp irq_return
14759 nmi_restore:
14760 + pax_exit_kernel
14761 RESTORE_ALL 8
14762 jmp irq_return
14763 nmi_userspace:
14764 diff -urNp linux-2.6.39.2/arch/x86/kernel/ftrace.c linux-2.6.39.2/arch/x86/kernel/ftrace.c
14765 --- linux-2.6.39.2/arch/x86/kernel/ftrace.c 2011-05-19 00:06:34.000000000 -0400
14766 +++ linux-2.6.39.2/arch/x86/kernel/ftrace.c 2011-05-22 19:36:30.000000000 -0400
14767 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the
14768 static void *mod_code_newcode; /* holds the text to write to the IP */
14769
14770 static unsigned nmi_wait_count;
14771 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14772 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14773
14774 int ftrace_arch_read_dyn_info(char *buf, int size)
14775 {
14776 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf,
14777
14778 r = snprintf(buf, size, "%u %u",
14779 nmi_wait_count,
14780 - atomic_read(&nmi_update_count));
14781 + atomic_read_unchecked(&nmi_update_count));
14782 return r;
14783 }
14784
14785 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14786
14787 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14788 smp_rmb();
14789 + pax_open_kernel();
14790 ftrace_mod_code();
14791 - atomic_inc(&nmi_update_count);
14792 + pax_close_kernel();
14793 + atomic_inc_unchecked(&nmi_update_count);
14794 }
14795 /* Must have previous changes seen before executions */
14796 smp_mb();
14797 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, uns
14798 {
14799 unsigned char replaced[MCOUNT_INSN_SIZE];
14800
14801 + ip = ktla_ktva(ip);
14802 +
14803 /*
14804 * Note: Due to modules and __init, code can
14805 * disappear and change, we need to protect against faulting
14806 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_fun
14807 unsigned char old[MCOUNT_INSN_SIZE], *new;
14808 int ret;
14809
14810 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14811 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14812 new = ftrace_call_replace(ip, (unsigned long)func);
14813 ret = ftrace_modify_code(ip, old, new);
14814
14815 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long
14816 {
14817 unsigned char code[MCOUNT_INSN_SIZE];
14818
14819 + ip = ktla_ktva(ip);
14820 +
14821 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14822 return -EFAULT;
14823
14824 diff -urNp linux-2.6.39.2/arch/x86/kernel/head32.c linux-2.6.39.2/arch/x86/kernel/head32.c
14825 --- linux-2.6.39.2/arch/x86/kernel/head32.c 2011-05-19 00:06:34.000000000 -0400
14826 +++ linux-2.6.39.2/arch/x86/kernel/head32.c 2011-05-22 19:36:30.000000000 -0400
14827 @@ -19,6 +19,7 @@
14828 #include <asm/io_apic.h>
14829 #include <asm/bios_ebda.h>
14830 #include <asm/tlbflush.h>
14831 +#include <asm/boot.h>
14832
14833 static void __init i386_default_early_setup(void)
14834 {
14835 @@ -34,7 +35,7 @@ void __init i386_start_kernel(void)
14836 {
14837 memblock_init();
14838
14839 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14840 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14841
14842 #ifdef CONFIG_BLK_DEV_INITRD
14843 /* Reserve INITRD */
14844 diff -urNp linux-2.6.39.2/arch/x86/kernel/head_32.S linux-2.6.39.2/arch/x86/kernel/head_32.S
14845 --- linux-2.6.39.2/arch/x86/kernel/head_32.S 2011-05-19 00:06:34.000000000 -0400
14846 +++ linux-2.6.39.2/arch/x86/kernel/head_32.S 2011-05-22 19:36:30.000000000 -0400
14847 @@ -25,6 +25,12 @@
14848 /* Physical address */
14849 #define pa(X) ((X) - __PAGE_OFFSET)
14850
14851 +#ifdef CONFIG_PAX_KERNEXEC
14852 +#define ta(X) (X)
14853 +#else
14854 +#define ta(X) ((X) - __PAGE_OFFSET)
14855 +#endif
14856 +
14857 /*
14858 * References to members of the new_cpu_data structure.
14859 */
14860 @@ -54,11 +60,7 @@
14861 * and small than max_low_pfn, otherwise will waste some page table entries
14862 */
14863
14864 -#if PTRS_PER_PMD > 1
14865 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14866 -#else
14867 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14868 -#endif
14869 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14870
14871 /* Number of possible pages in the lowmem region */
14872 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14873 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_P
14874 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14875
14876 /*
14877 + * Real beginning of normal "text" segment
14878 + */
14879 +ENTRY(stext)
14880 +ENTRY(_stext)
14881 +
14882 +/*
14883 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14884 * %esi points to the real-mode code as a 32-bit pointer.
14885 * CS and DS must be 4 GB flat segments, but we don't depend on
14886 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14887 * can.
14888 */
14889 __HEAD
14890 +
14891 +#ifdef CONFIG_PAX_KERNEXEC
14892 + jmp startup_32
14893 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14894 +.fill PAGE_SIZE-5,1,0xcc
14895 +#endif
14896 +
14897 ENTRY(startup_32)
14898 movl pa(stack_start),%ecx
14899
14900 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14901 2:
14902 leal -__PAGE_OFFSET(%ecx),%esp
14903
14904 +#ifdef CONFIG_SMP
14905 + movl $pa(cpu_gdt_table),%edi
14906 + movl $__per_cpu_load,%eax
14907 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14908 + rorl $16,%eax
14909 + movb %al,__KERNEL_PERCPU + 4(%edi)
14910 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14911 + movl $__per_cpu_end - 1,%eax
14912 + subl $__per_cpu_start,%eax
14913 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14914 +#endif
14915 +
14916 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14917 + movl $NR_CPUS,%ecx
14918 + movl $pa(cpu_gdt_table),%edi
14919 +1:
14920 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14921 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14922 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14923 + addl $PAGE_SIZE_asm,%edi
14924 + loop 1b
14925 +#endif
14926 +
14927 +#ifdef CONFIG_PAX_KERNEXEC
14928 + movl $pa(boot_gdt),%edi
14929 + movl $__LOAD_PHYSICAL_ADDR,%eax
14930 + movw %ax,__BOOT_CS + 2(%edi)
14931 + rorl $16,%eax
14932 + movb %al,__BOOT_CS + 4(%edi)
14933 + movb %ah,__BOOT_CS + 7(%edi)
14934 + rorl $16,%eax
14935 +
14936 + ljmp $(__BOOT_CS),$1f
14937 +1:
14938 +
14939 + movl $NR_CPUS,%ecx
14940 + movl $pa(cpu_gdt_table),%edi
14941 + addl $__PAGE_OFFSET,%eax
14942 +1:
14943 + movw %ax,__KERNEL_CS + 2(%edi)
14944 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14945 + rorl $16,%eax
14946 + movb %al,__KERNEL_CS + 4(%edi)
14947 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14948 + movb %ah,__KERNEL_CS + 7(%edi)
14949 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14950 + rorl $16,%eax
14951 + addl $PAGE_SIZE_asm,%edi
14952 + loop 1b
14953 +#endif
14954 +
14955 /*
14956 * Clear BSS first so that there are no surprises...
14957 */
14958 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14959 movl %eax, pa(max_pfn_mapped)
14960
14961 /* Do early initialization of the fixmap area */
14962 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14963 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14964 +#ifdef CONFIG_COMPAT_VDSO
14965 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14966 +#else
14967 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14968 +#endif
14969 #else /* Not PAE */
14970
14971 page_pde_offset = (__PAGE_OFFSET >> 20);
14972 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14973 movl %eax, pa(max_pfn_mapped)
14974
14975 /* Do early initialization of the fixmap area */
14976 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14977 - movl %eax,pa(initial_page_table+0xffc)
14978 +#ifdef CONFIG_COMPAT_VDSO
14979 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14980 +#else
14981 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14982 +#endif
14983 #endif
14984
14985 #ifdef CONFIG_PARAVIRT
14986 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14987 cmpl $num_subarch_entries, %eax
14988 jae bad_subarch
14989
14990 - movl pa(subarch_entries)(,%eax,4), %eax
14991 - subl $__PAGE_OFFSET, %eax
14992 - jmp *%eax
14993 + jmp *pa(subarch_entries)(,%eax,4)
14994
14995 bad_subarch:
14996 WEAK(lguest_entry)
14997 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14998 __INITDATA
14999
15000 subarch_entries:
15001 - .long default_entry /* normal x86/PC */
15002 - .long lguest_entry /* lguest hypervisor */
15003 - .long xen_entry /* Xen hypervisor */
15004 - .long default_entry /* Moorestown MID */
15005 + .long ta(default_entry) /* normal x86/PC */
15006 + .long ta(lguest_entry) /* lguest hypervisor */
15007 + .long ta(xen_entry) /* Xen hypervisor */
15008 + .long ta(default_entry) /* Moorestown MID */
15009 num_subarch_entries = (. - subarch_entries) / 4
15010 .previous
15011 #else
15012 @@ -312,6 +382,7 @@ default_entry:
15013 orl %edx,%eax
15014 movl %eax,%cr4
15015
15016 +#ifdef CONFIG_X86_PAE
15017 testb $X86_CR4_PAE, %al # check if PAE is enabled
15018 jz 6f
15019
15020 @@ -340,6 +411,9 @@ default_entry:
15021 /* Make changes effective */
15022 wrmsr
15023
15024 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
15025 +#endif
15026 +
15027 6:
15028
15029 /*
15030 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
15031 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
15032 movl %eax,%ss # after changing gdt.
15033
15034 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
15035 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
15036 movl %eax,%ds
15037 movl %eax,%es
15038
15039 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
15040 */
15041 cmpb $0,ready
15042 jne 1f
15043 - movl $gdt_page,%eax
15044 + movl $cpu_gdt_table,%eax
15045 movl $stack_canary,%ecx
15046 +#ifdef CONFIG_SMP
15047 + addl $__per_cpu_load,%ecx
15048 +#endif
15049 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
15050 shrl $16, %ecx
15051 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
15052 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
15053 1:
15054 -#endif
15055 movl $(__KERNEL_STACK_CANARY),%eax
15056 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15057 + movl $(__USER_DS),%eax
15058 +#else
15059 + xorl %eax,%eax
15060 +#endif
15061 movl %eax,%gs
15062
15063 xorl %eax,%eax # Clear LDT
15064 @@ -558,22 +639,22 @@ early_page_fault:
15065 jmp early_fault
15066
15067 early_fault:
15068 - cld
15069 #ifdef CONFIG_PRINTK
15070 + cmpl $1,%ss:early_recursion_flag
15071 + je hlt_loop
15072 + incl %ss:early_recursion_flag
15073 + cld
15074 pusha
15075 movl $(__KERNEL_DS),%eax
15076 movl %eax,%ds
15077 movl %eax,%es
15078 - cmpl $2,early_recursion_flag
15079 - je hlt_loop
15080 - incl early_recursion_flag
15081 movl %cr2,%eax
15082 pushl %eax
15083 pushl %edx /* trapno */
15084 pushl $fault_msg
15085 call printk
15086 +; call dump_stack
15087 #endif
15088 - call dump_stack
15089 hlt_loop:
15090 hlt
15091 jmp hlt_loop
15092 @@ -581,8 +662,11 @@ hlt_loop:
15093 /* This is the default interrupt "handler" :-) */
15094 ALIGN
15095 ignore_int:
15096 - cld
15097 #ifdef CONFIG_PRINTK
15098 + cmpl $2,%ss:early_recursion_flag
15099 + je hlt_loop
15100 + incl %ss:early_recursion_flag
15101 + cld
15102 pushl %eax
15103 pushl %ecx
15104 pushl %edx
15105 @@ -591,9 +675,6 @@ ignore_int:
15106 movl $(__KERNEL_DS),%eax
15107 movl %eax,%ds
15108 movl %eax,%es
15109 - cmpl $2,early_recursion_flag
15110 - je hlt_loop
15111 - incl early_recursion_flag
15112 pushl 16(%esp)
15113 pushl 24(%esp)
15114 pushl 32(%esp)
15115 @@ -622,29 +703,43 @@ ENTRY(initial_code)
15116 /*
15117 * BSS section
15118 */
15119 -__PAGE_ALIGNED_BSS
15120 - .align PAGE_SIZE
15121 #ifdef CONFIG_X86_PAE
15122 +.section .initial_pg_pmd,"a",@progbits
15123 initial_pg_pmd:
15124 .fill 1024*KPMDS,4,0
15125 #else
15126 +.section .initial_page_table,"a",@progbits
15127 ENTRY(initial_page_table)
15128 .fill 1024,4,0
15129 #endif
15130 +.section .initial_pg_fixmap,"a",@progbits
15131 initial_pg_fixmap:
15132 .fill 1024,4,0
15133 +.section .empty_zero_page,"a",@progbits
15134 ENTRY(empty_zero_page)
15135 .fill 4096,1,0
15136 +.section .swapper_pg_dir,"a",@progbits
15137 ENTRY(swapper_pg_dir)
15138 +#ifdef CONFIG_X86_PAE
15139 + .fill 4,8,0
15140 +#else
15141 .fill 1024,4,0
15142 +#endif
15143 +
15144 +/*
15145 + * The IDT has to be page-aligned to simplify the Pentium
15146 + * F0 0F bug workaround.. We have a special link segment
15147 + * for this.
15148 + */
15149 +.section .idt,"a",@progbits
15150 +ENTRY(idt_table)
15151 + .fill 256,8,0
15152
15153 /*
15154 * This starts the data section.
15155 */
15156 #ifdef CONFIG_X86_PAE
15157 -__PAGE_ALIGNED_DATA
15158 - /* Page-aligned for the benefit of paravirt? */
15159 - .align PAGE_SIZE
15160 +.section .initial_page_table,"a",@progbits
15161 ENTRY(initial_page_table)
15162 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15163 # if KPMDS == 3
15164 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15165 # error "Kernel PMDs should be 1, 2 or 3"
15166 # endif
15167 .align PAGE_SIZE /* needs to be page-sized too */
15168 +
15169 +#ifdef CONFIG_PAX_PER_CPU_PGD
15170 +ENTRY(cpu_pgd)
15171 + .rept NR_CPUS
15172 + .fill 4,8,0
15173 + .endr
15174 +#endif
15175 +
15176 #endif
15177
15178 .data
15179 .balign 4
15180 ENTRY(stack_start)
15181 - .long init_thread_union+THREAD_SIZE
15182 + .long init_thread_union+THREAD_SIZE-8
15183 +
15184 +ready: .byte 0
15185
15186 +.section .rodata,"a",@progbits
15187 early_recursion_flag:
15188 .long 0
15189
15190 -ready: .byte 0
15191 -
15192 int_msg:
15193 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15194
15195 @@ -707,7 +811,7 @@ fault_msg:
15196 .word 0 # 32 bit align gdt_desc.address
15197 boot_gdt_descr:
15198 .word __BOOT_DS+7
15199 - .long boot_gdt - __PAGE_OFFSET
15200 + .long pa(boot_gdt)
15201
15202 .word 0 # 32-bit align idt_desc.address
15203 idt_descr:
15204 @@ -718,7 +822,7 @@ idt_descr:
15205 .word 0 # 32 bit align gdt_desc.address
15206 ENTRY(early_gdt_descr)
15207 .word GDT_ENTRIES*8-1
15208 - .long gdt_page /* Overwritten for secondary CPUs */
15209 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15210
15211 /*
15212 * The boot_gdt must mirror the equivalent in setup.S and is
15213 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15214 .align L1_CACHE_BYTES
15215 ENTRY(boot_gdt)
15216 .fill GDT_ENTRY_BOOT_CS,8,0
15217 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15218 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15219 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15220 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15221 +
15222 + .align PAGE_SIZE_asm
15223 +ENTRY(cpu_gdt_table)
15224 + .rept NR_CPUS
15225 + .quad 0x0000000000000000 /* NULL descriptor */
15226 + .quad 0x0000000000000000 /* 0x0b reserved */
15227 + .quad 0x0000000000000000 /* 0x13 reserved */
15228 + .quad 0x0000000000000000 /* 0x1b reserved */
15229 +
15230 +#ifdef CONFIG_PAX_KERNEXEC
15231 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15232 +#else
15233 + .quad 0x0000000000000000 /* 0x20 unused */
15234 +#endif
15235 +
15236 + .quad 0x0000000000000000 /* 0x28 unused */
15237 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15238 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15239 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15240 + .quad 0x0000000000000000 /* 0x4b reserved */
15241 + .quad 0x0000000000000000 /* 0x53 reserved */
15242 + .quad 0x0000000000000000 /* 0x5b reserved */
15243 +
15244 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15245 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15246 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15247 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15248 +
15249 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15250 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15251 +
15252 + /*
15253 + * Segments used for calling PnP BIOS have byte granularity.
15254 + * The code segments and data segments have fixed 64k limits,
15255 + * the transfer segment sizes are set at run time.
15256 + */
15257 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15258 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15259 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15260 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15261 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15262 +
15263 + /*
15264 + * The APM segments have byte granularity and their bases
15265 + * are set at run time. All have 64k limits.
15266 + */
15267 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15268 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15269 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15270 +
15271 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15272 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15273 + .quad 0x0040910000000018 /* 0xe0 - STACK_CANARY */
15274 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15275 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15276 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15277 +
15278 + /* Be sure this is zeroed to avoid false validations in Xen */
15279 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15280 + .endr
15281 diff -urNp linux-2.6.39.2/arch/x86/kernel/head_64.S linux-2.6.39.2/arch/x86/kernel/head_64.S
15282 --- linux-2.6.39.2/arch/x86/kernel/head_64.S 2011-05-19 00:06:34.000000000 -0400
15283 +++ linux-2.6.39.2/arch/x86/kernel/head_64.S 2011-05-22 19:36:30.000000000 -0400
15284 @@ -19,6 +19,7 @@
15285 #include <asm/cache.h>
15286 #include <asm/processor-flags.h>
15287 #include <asm/percpu.h>
15288 +#include <asm/cpufeature.h>
15289
15290 #ifdef CONFIG_PARAVIRT
15291 #include <asm/asm-offsets.h>
15292 @@ -38,6 +39,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
15293 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15294 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15295 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15296 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15297 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15298 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15299 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15300
15301 .text
15302 __HEAD
15303 @@ -85,35 +90,22 @@ startup_64:
15304 */
15305 addq %rbp, init_level4_pgt + 0(%rip)
15306 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15307 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15308 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15309 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15310
15311 addq %rbp, level3_ident_pgt + 0(%rip)
15312 +#ifndef CONFIG_XEN
15313 + addq %rbp, level3_ident_pgt + 8(%rip)
15314 +#endif
15315
15316 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15317 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15318 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15319
15320 - addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15321 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15322 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15323
15324 - /* Add an Identity mapping if I am above 1G */
15325 - leaq _text(%rip), %rdi
15326 - andq $PMD_PAGE_MASK, %rdi
15327 -
15328 - movq %rdi, %rax
15329 - shrq $PUD_SHIFT, %rax
15330 - andq $(PTRS_PER_PUD - 1), %rax
15331 - jz ident_complete
15332 -
15333 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15334 - leaq level3_ident_pgt(%rip), %rbx
15335 - movq %rdx, 0(%rbx, %rax, 8)
15336 -
15337 - movq %rdi, %rax
15338 - shrq $PMD_SHIFT, %rax
15339 - andq $(PTRS_PER_PMD - 1), %rax
15340 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15341 - leaq level2_spare_pgt(%rip), %rbx
15342 - movq %rdx, 0(%rbx, %rax, 8)
15343 -ident_complete:
15344 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15345 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15346
15347 /*
15348 * Fixup the kernel text+data virtual addresses. Note that
15349 @@ -160,8 +152,8 @@ ENTRY(secondary_startup_64)
15350 * after the boot processor executes this code.
15351 */
15352
15353 - /* Enable PAE mode and PGE */
15354 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15355 + /* Enable PAE mode and PSE/PGE */
15356 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15357 movq %rax, %cr4
15358
15359 /* Setup early boot stage 4 level pagetables. */
15360 @@ -183,9 +175,14 @@ ENTRY(secondary_startup_64)
15361 movl $MSR_EFER, %ecx
15362 rdmsr
15363 btsl $_EFER_SCE, %eax /* Enable System Call */
15364 - btl $20,%edi /* No Execute supported? */
15365 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15366 jnc 1f
15367 btsl $_EFER_NX, %eax
15368 + leaq init_level4_pgt(%rip), %rdi
15369 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15370 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15371 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15372 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15373 1: wrmsr /* Make changes effective */
15374
15375 /* Setup cr0 */
15376 @@ -269,7 +266,7 @@ ENTRY(secondary_startup_64)
15377 bad_address:
15378 jmp bad_address
15379
15380 - .section ".init.text","ax"
15381 + __INIT
15382 #ifdef CONFIG_EARLY_PRINTK
15383 .globl early_idt_handlers
15384 early_idt_handlers:
15385 @@ -314,18 +311,23 @@ ENTRY(early_idt_handler)
15386 #endif /* EARLY_PRINTK */
15387 1: hlt
15388 jmp 1b
15389 + .previous
15390
15391 #ifdef CONFIG_EARLY_PRINTK
15392 + __INITDATA
15393 early_recursion_flag:
15394 .long 0
15395 + .previous
15396
15397 + .section .rodata,"a",@progbits
15398 early_idt_msg:
15399 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15400 early_idt_ripmsg:
15401 .asciz "RIP %s\n"
15402 -#endif /* CONFIG_EARLY_PRINTK */
15403 .previous
15404 +#endif /* CONFIG_EARLY_PRINTK */
15405
15406 + .section .rodata,"a",@progbits
15407 #define NEXT_PAGE(name) \
15408 .balign PAGE_SIZE; \
15409 ENTRY(name)
15410 @@ -338,7 +340,6 @@ ENTRY(name)
15411 i = i + 1 ; \
15412 .endr
15413
15414 - .data
15415 /*
15416 * This default setting generates an ident mapping at address 0x100000
15417 * and a mapping for the kernel that precisely maps virtual address
15418 @@ -349,13 +350,36 @@ NEXT_PAGE(init_level4_pgt)
15419 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15420 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15421 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15422 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15423 + .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
15424 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15425 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15426 .org init_level4_pgt + L4_START_KERNEL*8, 0
15427 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15428 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15429
15430 +#ifdef CONFIG_PAX_PER_CPU_PGD
15431 +NEXT_PAGE(cpu_pgd)
15432 + .rept NR_CPUS
15433 + .fill 512,8,0
15434 + .endr
15435 +#endif
15436 +
15437 NEXT_PAGE(level3_ident_pgt)
15438 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15439 +#ifdef CONFIG_XEN
15440 .fill 511,8,0
15441 +#else
15442 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15443 + .fill 510,8,0
15444 +#endif
15445 +
15446 +NEXT_PAGE(level3_vmalloc_pgt)
15447 + .fill 512,8,0
15448 +
15449 +NEXT_PAGE(level3_vmemmap_pgt)
15450 + .fill L3_VMEMMAP_START,8,0
15451 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15452
15453 NEXT_PAGE(level3_kernel_pgt)
15454 .fill L3_START_KERNEL,8,0
15455 @@ -363,20 +387,23 @@ NEXT_PAGE(level3_kernel_pgt)
15456 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15457 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15458
15459 +NEXT_PAGE(level2_vmemmap_pgt)
15460 + .fill 512,8,0
15461 +
15462 NEXT_PAGE(level2_fixmap_pgt)
15463 - .fill 506,8,0
15464 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15465 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15466 - .fill 5,8,0
15467 + .fill 507,8,0
15468 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15469 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15470 + .fill 4,8,0
15471
15472 -NEXT_PAGE(level1_fixmap_pgt)
15473 +NEXT_PAGE(level1_vsyscall_pgt)
15474 .fill 512,8,0
15475
15476 -NEXT_PAGE(level2_ident_pgt)
15477 - /* Since I easily can, map the first 1G.
15478 + /* Since I easily can, map the first 2G.
15479 * Don't set NX because code runs from these pages.
15480 */
15481 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15482 +NEXT_PAGE(level2_ident_pgt)
15483 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15484
15485 NEXT_PAGE(level2_kernel_pgt)
15486 /*
15487 @@ -389,33 +416,55 @@ NEXT_PAGE(level2_kernel_pgt)
15488 * If you want to increase this then increase MODULES_VADDR
15489 * too.)
15490 */
15491 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15492 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15493 -
15494 -NEXT_PAGE(level2_spare_pgt)
15495 - .fill 512, 8, 0
15496 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15497
15498 #undef PMDS
15499 #undef NEXT_PAGE
15500
15501 - .data
15502 + .align PAGE_SIZE
15503 +ENTRY(cpu_gdt_table)
15504 + .rept NR_CPUS
15505 + .quad 0x0000000000000000 /* NULL descriptor */
15506 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15507 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15508 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15509 + .quad 0x00cffb000000ffff /* __USER32_CS */
15510 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15511 + .quad 0x00affb000000ffff /* __USER_CS */
15512 +
15513 +#ifdef CONFIG_PAX_KERNEXEC
15514 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15515 +#else
15516 + .quad 0x0 /* unused */
15517 +#endif
15518 +
15519 + .quad 0,0 /* TSS */
15520 + .quad 0,0 /* LDT */
15521 + .quad 0,0,0 /* three TLS descriptors */
15522 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15523 + /* asm/segment.h:GDT_ENTRIES must match this */
15524 +
15525 + /* zero the remaining page */
15526 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15527 + .endr
15528 +
15529 .align 16
15530 .globl early_gdt_descr
15531 early_gdt_descr:
15532 .word GDT_ENTRIES*8-1
15533 early_gdt_descr_base:
15534 - .quad INIT_PER_CPU_VAR(gdt_page)
15535 + .quad cpu_gdt_table
15536
15537 ENTRY(phys_base)
15538 /* This must match the first entry in level2_kernel_pgt */
15539 .quad 0x0000000000000000
15540
15541 #include "../../x86/xen/xen-head.S"
15542 -
15543 - .section .bss, "aw", @nobits
15544 +
15545 + .section .rodata,"a",@progbits
15546 .align L1_CACHE_BYTES
15547 ENTRY(idt_table)
15548 - .skip IDT_ENTRIES * 16
15549 + .fill 512,8,0
15550
15551 __PAGE_ALIGNED_BSS
15552 .align PAGE_SIZE
15553 diff -urNp linux-2.6.39.2/arch/x86/kernel/i386_ksyms_32.c linux-2.6.39.2/arch/x86/kernel/i386_ksyms_32.c
15554 --- linux-2.6.39.2/arch/x86/kernel/i386_ksyms_32.c 2011-05-19 00:06:34.000000000 -0400
15555 +++ linux-2.6.39.2/arch/x86/kernel/i386_ksyms_32.c 2011-05-22 19:36:30.000000000 -0400
15556 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15557 EXPORT_SYMBOL(cmpxchg8b_emu);
15558 #endif
15559
15560 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15561 +
15562 /* Networking helper routines. */
15563 EXPORT_SYMBOL(csum_partial_copy_generic);
15564 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15565 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15566
15567 EXPORT_SYMBOL(__get_user_1);
15568 EXPORT_SYMBOL(__get_user_2);
15569 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15570
15571 EXPORT_SYMBOL(csum_partial);
15572 EXPORT_SYMBOL(empty_zero_page);
15573 +
15574 +#ifdef CONFIG_PAX_KERNEXEC
15575 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15576 +#endif
15577 diff -urNp linux-2.6.39.2/arch/x86/kernel/i8259.c linux-2.6.39.2/arch/x86/kernel/i8259.c
15578 --- linux-2.6.39.2/arch/x86/kernel/i8259.c 2011-05-19 00:06:34.000000000 -0400
15579 +++ linux-2.6.39.2/arch/x86/kernel/i8259.c 2011-05-22 19:36:30.000000000 -0400
15580 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15581 "spurious 8259A interrupt: IRQ%d.\n", irq);
15582 spurious_irq_mask |= irqmask;
15583 }
15584 - atomic_inc(&irq_err_count);
15585 + atomic_inc_unchecked(&irq_err_count);
15586 /*
15587 * Theoretically we do not have to handle this IRQ,
15588 * but in Linux this does not cause problems and is
15589 diff -urNp linux-2.6.39.2/arch/x86/kernel/init_task.c linux-2.6.39.2/arch/x86/kernel/init_task.c
15590 --- linux-2.6.39.2/arch/x86/kernel/init_task.c 2011-05-19 00:06:34.000000000 -0400
15591 +++ linux-2.6.39.2/arch/x86/kernel/init_task.c 2011-05-22 19:36:30.000000000 -0400
15592 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighan
15593 * way process stacks are handled. This is done by having a special
15594 * "init_task" linker map entry..
15595 */
15596 -union thread_union init_thread_union __init_task_data =
15597 - { INIT_THREAD_INFO(init_task) };
15598 +union thread_union init_thread_union __init_task_data;
15599
15600 /*
15601 * Initial task structure.
15602 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15603 * section. Since TSS's are completely CPU-local, we want them
15604 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15605 */
15606 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15607 -
15608 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15609 +EXPORT_SYMBOL(init_tss);
15610 diff -urNp linux-2.6.39.2/arch/x86/kernel/ioport.c linux-2.6.39.2/arch/x86/kernel/ioport.c
15611 --- linux-2.6.39.2/arch/x86/kernel/ioport.c 2011-05-19 00:06:34.000000000 -0400
15612 +++ linux-2.6.39.2/arch/x86/kernel/ioport.c 2011-05-22 19:41:32.000000000 -0400
15613 @@ -6,6 +6,7 @@
15614 #include <linux/sched.h>
15615 #include <linux/kernel.h>
15616 #include <linux/capability.h>
15617 +#include <linux/security.h>
15618 #include <linux/errno.h>
15619 #include <linux/types.h>
15620 #include <linux/ioport.h>
15621 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long
15622
15623 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15624 return -EINVAL;
15625 +#ifdef CONFIG_GRKERNSEC_IO
15626 + if (turn_on && grsec_disable_privio) {
15627 + gr_handle_ioperm();
15628 + return -EPERM;
15629 + }
15630 +#endif
15631 if (turn_on && !capable(CAP_SYS_RAWIO))
15632 return -EPERM;
15633
15634 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long
15635 * because the ->io_bitmap_max value must match the bitmap
15636 * contents:
15637 */
15638 - tss = &per_cpu(init_tss, get_cpu());
15639 + tss = init_tss + get_cpu();
15640
15641 if (turn_on)
15642 bitmap_clear(t->io_bitmap_ptr, from, num);
15643 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct
15644 return -EINVAL;
15645 /* Trying to gain more privileges? */
15646 if (level > old) {
15647 +#ifdef CONFIG_GRKERNSEC_IO
15648 + if (grsec_disable_privio) {
15649 + gr_handle_iopl();
15650 + return -EPERM;
15651 + }
15652 +#endif
15653 if (!capable(CAP_SYS_RAWIO))
15654 return -EPERM;
15655 }
15656 diff -urNp linux-2.6.39.2/arch/x86/kernel/irq_32.c linux-2.6.39.2/arch/x86/kernel/irq_32.c
15657 --- linux-2.6.39.2/arch/x86/kernel/irq_32.c 2011-05-19 00:06:34.000000000 -0400
15658 +++ linux-2.6.39.2/arch/x86/kernel/irq_32.c 2011-05-22 19:36:30.000000000 -0400
15659 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15660 __asm__ __volatile__("andl %%esp,%0" :
15661 "=r" (sp) : "0" (THREAD_SIZE - 1));
15662
15663 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15664 + return sp < STACK_WARN;
15665 }
15666
15667 static void print_stack_overflow(void)
15668 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(
15669 * per-CPU IRQ handling contexts (thread information and stack)
15670 */
15671 union irq_ctx {
15672 - struct thread_info tinfo;
15673 - u32 stack[THREAD_SIZE/sizeof(u32)];
15674 + unsigned long previous_esp;
15675 + u32 stack[THREAD_SIZE/sizeof(u32)];
15676 } __attribute__((aligned(THREAD_SIZE)));
15677
15678 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15679 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, vo
15680 static inline int
15681 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15682 {
15683 - union irq_ctx *curctx, *irqctx;
15684 + union irq_ctx *irqctx;
15685 u32 *isp, arg1, arg2;
15686
15687 - curctx = (union irq_ctx *) current_thread_info();
15688 irqctx = __this_cpu_read(hardirq_ctx);
15689
15690 /*
15691 @@ -87,21 +86,17 @@ execute_on_irq_stack(int overflow, struc
15692 * handler) we can't do that and just have to keep using the
15693 * current stack (which is the irq stack already after all)
15694 */
15695 - if (unlikely(curctx == irqctx))
15696 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15697 return 0;
15698
15699 /* build the stack frame on the IRQ stack */
15700 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15701 - irqctx->tinfo.task = curctx->tinfo.task;
15702 - irqctx->tinfo.previous_esp = current_stack_pointer;
15703 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15704 + irqctx->previous_esp = current_stack_pointer;
15705 + add_preempt_count(HARDIRQ_OFFSET);
15706
15707 - /*
15708 - * Copy the softirq bits in preempt_count so that the
15709 - * softirq checks work in the hardirq context.
15710 - */
15711 - irqctx->tinfo.preempt_count =
15712 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15713 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15714 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15715 + __set_fs(MAKE_MM_SEG(0));
15716 +#endif
15717
15718 if (unlikely(overflow))
15719 call_on_stack(print_stack_overflow, isp);
15720 @@ -113,6 +108,12 @@ execute_on_irq_stack(int overflow, struc
15721 : "0" (irq), "1" (desc), "2" (isp),
15722 "D" (desc->handle_irq)
15723 : "memory", "cc", "ecx");
15724 +
15725 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15726 + __set_fs(current_thread_info()->addr_limit);
15727 +#endif
15728 +
15729 + sub_preempt_count(HARDIRQ_OFFSET);
15730 return 1;
15731 }
15732
15733 @@ -121,29 +122,11 @@ execute_on_irq_stack(int overflow, struc
15734 */
15735 void __cpuinit irq_ctx_init(int cpu)
15736 {
15737 - union irq_ctx *irqctx;
15738 -
15739 if (per_cpu(hardirq_ctx, cpu))
15740 return;
15741
15742 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15743 - THREAD_FLAGS,
15744 - THREAD_ORDER));
15745 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15746 - irqctx->tinfo.cpu = cpu;
15747 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15748 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15749 -
15750 - per_cpu(hardirq_ctx, cpu) = irqctx;
15751 -
15752 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15753 - THREAD_FLAGS,
15754 - THREAD_ORDER));
15755 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15756 - irqctx->tinfo.cpu = cpu;
15757 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15758 -
15759 - per_cpu(softirq_ctx, cpu) = irqctx;
15760 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15761 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15762
15763 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15764 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15765 @@ -152,7 +135,6 @@ void __cpuinit irq_ctx_init(int cpu)
15766 asmlinkage void do_softirq(void)
15767 {
15768 unsigned long flags;
15769 - struct thread_info *curctx;
15770 union irq_ctx *irqctx;
15771 u32 *isp;
15772
15773 @@ -162,15 +144,22 @@ asmlinkage void do_softirq(void)
15774 local_irq_save(flags);
15775
15776 if (local_softirq_pending()) {
15777 - curctx = current_thread_info();
15778 irqctx = __this_cpu_read(softirq_ctx);
15779 - irqctx->tinfo.task = curctx->task;
15780 - irqctx->tinfo.previous_esp = current_stack_pointer;
15781 + irqctx->previous_esp = current_stack_pointer;
15782
15783 /* build the stack frame on the softirq stack */
15784 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15785 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15786 +
15787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15788 + __set_fs(MAKE_MM_SEG(0));
15789 +#endif
15790
15791 call_on_stack(__do_softirq, isp);
15792 +
15793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15794 + __set_fs(current_thread_info()->addr_limit);
15795 +#endif
15796 +
15797 /*
15798 * Shouldn't happen, we returned above if in_interrupt():
15799 */
15800 diff -urNp linux-2.6.39.2/arch/x86/kernel/irq.c linux-2.6.39.2/arch/x86/kernel/irq.c
15801 --- linux-2.6.39.2/arch/x86/kernel/irq.c 2011-05-19 00:06:34.000000000 -0400
15802 +++ linux-2.6.39.2/arch/x86/kernel/irq.c 2011-05-22 19:36:30.000000000 -0400
15803 @@ -17,7 +17,7 @@
15804 #include <asm/mce.h>
15805 #include <asm/hw_irq.h>
15806
15807 -atomic_t irq_err_count;
15808 +atomic_unchecked_t irq_err_count;
15809
15810 /* Function pointer for generic interrupt vector handling */
15811 void (*x86_platform_ipi_callback)(void) = NULL;
15812 @@ -116,9 +116,9 @@ int arch_show_interrupts(struct seq_file
15813 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15814 seq_printf(p, " Machine check polls\n");
15815 #endif
15816 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15817 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15818 #if defined(CONFIG_X86_IO_APIC)
15819 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15820 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15821 #endif
15822 return 0;
15823 }
15824 @@ -158,10 +158,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15825
15826 u64 arch_irq_stat(void)
15827 {
15828 - u64 sum = atomic_read(&irq_err_count);
15829 + u64 sum = atomic_read_unchecked(&irq_err_count);
15830
15831 #ifdef CONFIG_X86_IO_APIC
15832 - sum += atomic_read(&irq_mis_count);
15833 + sum += atomic_read_unchecked(&irq_mis_count);
15834 #endif
15835 return sum;
15836 }
15837 diff -urNp linux-2.6.39.2/arch/x86/kernel/kgdb.c linux-2.6.39.2/arch/x86/kernel/kgdb.c
15838 --- linux-2.6.39.2/arch/x86/kernel/kgdb.c 2011-05-19 00:06:34.000000000 -0400
15839 +++ linux-2.6.39.2/arch/x86/kernel/kgdb.c 2011-05-22 19:36:30.000000000 -0400
15840 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem,
15841 #ifdef CONFIG_X86_32
15842 switch (regno) {
15843 case GDB_SS:
15844 - if (!user_mode_vm(regs))
15845 + if (!user_mode(regs))
15846 *(unsigned long *)mem = __KERNEL_DS;
15847 break;
15848 case GDB_SP:
15849 - if (!user_mode_vm(regs))
15850 + if (!user_mode(regs))
15851 *(unsigned long *)mem = kernel_stack_pointer(regs);
15852 break;
15853 case GDB_GS:
15854 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vec
15855 case 'k':
15856 /* clear the trace bit */
15857 linux_regs->flags &= ~X86_EFLAGS_TF;
15858 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15859 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15860
15861 /* set the trace bit if we're stepping */
15862 if (remcomInBuffer[0] == 's') {
15863 linux_regs->flags |= X86_EFLAGS_TF;
15864 - atomic_set(&kgdb_cpu_doing_single_step,
15865 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15866 raw_smp_processor_id());
15867 }
15868
15869 @@ -534,7 +534,7 @@ static int __kgdb_notify(struct die_args
15870 return NOTIFY_DONE;
15871
15872 case DIE_DEBUG:
15873 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15874 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15875 if (user_mode(regs))
15876 return single_step_cont(regs, args);
15877 break;
15878 @@ -710,7 +710,7 @@ void kgdb_arch_set_pc(struct pt_regs *re
15879 regs->ip = ip;
15880 }
15881
15882 -struct kgdb_arch arch_kgdb_ops = {
15883 +const struct kgdb_arch arch_kgdb_ops = {
15884 /* Breakpoint instruction: */
15885 .gdb_bpt_instr = { 0xcc },
15886 .flags = KGDB_HW_BREAKPOINT,
15887 diff -urNp linux-2.6.39.2/arch/x86/kernel/kprobes.c linux-2.6.39.2/arch/x86/kernel/kprobes.c
15888 --- linux-2.6.39.2/arch/x86/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
15889 +++ linux-2.6.39.2/arch/x86/kernel/kprobes.c 2011-05-22 19:36:30.000000000 -0400
15890 @@ -115,8 +115,11 @@ static void __kprobes __synthesize_relat
15891 } __attribute__((packed)) *insn;
15892
15893 insn = (struct __arch_relative_insn *)from;
15894 +
15895 + pax_open_kernel();
15896 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15897 insn->op = op;
15898 + pax_close_kernel();
15899 }
15900
15901 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15902 @@ -153,7 +156,7 @@ static int __kprobes can_boost(kprobe_op
15903 kprobe_opcode_t opcode;
15904 kprobe_opcode_t *orig_opcodes = opcodes;
15905
15906 - if (search_exception_tables((unsigned long)opcodes))
15907 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15908 return 0; /* Page fault may occur on this address. */
15909
15910 retry:
15911 @@ -314,7 +317,9 @@ static int __kprobes __copy_instruction(
15912 }
15913 }
15914 insn_get_length(&insn);
15915 + pax_open_kernel();
15916 memcpy(dest, insn.kaddr, insn.length);
15917 + pax_close_kernel();
15918
15919 #ifdef CONFIG_X86_64
15920 if (insn_rip_relative(&insn)) {
15921 @@ -338,7 +343,9 @@ static int __kprobes __copy_instruction(
15922 (u8 *) dest;
15923 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15924 disp = (u8 *) dest + insn_offset_displacement(&insn);
15925 + pax_open_kernel();
15926 *(s32 *) disp = (s32) newdisp;
15927 + pax_close_kernel();
15928 }
15929 #endif
15930 return insn.length;
15931 @@ -352,12 +359,12 @@ static void __kprobes arch_copy_kprobe(s
15932 */
15933 __copy_instruction(p->ainsn.insn, p->addr, 0);
15934
15935 - if (can_boost(p->addr))
15936 + if (can_boost(ktla_ktva(p->addr)))
15937 p->ainsn.boostable = 0;
15938 else
15939 p->ainsn.boostable = -1;
15940
15941 - p->opcode = *p->addr;
15942 + p->opcode = *(ktla_ktva(p->addr));
15943 }
15944
15945 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15946 @@ -474,7 +481,7 @@ static void __kprobes setup_singlestep(s
15947 * nor set current_kprobe, because it doesn't use single
15948 * stepping.
15949 */
15950 - regs->ip = (unsigned long)p->ainsn.insn;
15951 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15952 preempt_enable_no_resched();
15953 return;
15954 }
15955 @@ -493,7 +500,7 @@ static void __kprobes setup_singlestep(s
15956 if (p->opcode == BREAKPOINT_INSTRUCTION)
15957 regs->ip = (unsigned long)p->addr;
15958 else
15959 - regs->ip = (unsigned long)p->ainsn.insn;
15960 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15961 }
15962
15963 /*
15964 @@ -572,7 +579,7 @@ static int __kprobes kprobe_handler(stru
15965 setup_singlestep(p, regs, kcb, 0);
15966 return 1;
15967 }
15968 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15969 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15970 /*
15971 * The breakpoint instruction was removed right
15972 * after we hit it. Another cpu has removed
15973 @@ -817,7 +824,7 @@ static void __kprobes resume_execution(s
15974 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15975 {
15976 unsigned long *tos = stack_addr(regs);
15977 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15978 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15979 unsigned long orig_ip = (unsigned long)p->addr;
15980 kprobe_opcode_t *insn = p->ainsn.insn;
15981
15982 @@ -999,7 +1006,7 @@ int __kprobes kprobe_exceptions_notify(s
15983 struct die_args *args = data;
15984 int ret = NOTIFY_DONE;
15985
15986 - if (args->regs && user_mode_vm(args->regs))
15987 + if (args->regs && user_mode(args->regs))
15988 return ret;
15989
15990 switch (val) {
15991 @@ -1381,7 +1388,7 @@ int __kprobes arch_prepare_optimized_kpr
15992 * Verify if the address gap is in 2GB range, because this uses
15993 * a relative jump.
15994 */
15995 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15996 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15997 if (abs(rel) > 0x7fffffff)
15998 return -ERANGE;
15999
16000 @@ -1402,11 +1409,11 @@ int __kprobes arch_prepare_optimized_kpr
16001 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
16002
16003 /* Set probe function call */
16004 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
16005 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
16006
16007 /* Set returning jmp instruction at the tail of out-of-line buffer */
16008 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
16009 - (u8 *)op->kp.addr + op->optinsn.size);
16010 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
16011
16012 flush_icache_range((unsigned long) buf,
16013 (unsigned long) buf + TMPL_END_IDX +
16014 @@ -1428,7 +1435,7 @@ static void __kprobes setup_optimize_kpr
16015 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
16016
16017 /* Backup instructions which will be replaced by jump address */
16018 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
16019 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
16020 RELATIVE_ADDR_SIZE);
16021
16022 insn_buf[0] = RELATIVEJUMP_OPCODE;
16023 diff -urNp linux-2.6.39.2/arch/x86/kernel/ldt.c linux-2.6.39.2/arch/x86/kernel/ldt.c
16024 --- linux-2.6.39.2/arch/x86/kernel/ldt.c 2011-05-19 00:06:34.000000000 -0400
16025 +++ linux-2.6.39.2/arch/x86/kernel/ldt.c 2011-05-22 19:36:30.000000000 -0400
16026 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, i
16027 if (reload) {
16028 #ifdef CONFIG_SMP
16029 preempt_disable();
16030 - load_LDT(pc);
16031 + load_LDT_nolock(pc);
16032 if (!cpumask_equal(mm_cpumask(current->mm),
16033 cpumask_of(smp_processor_id())))
16034 smp_call_function(flush_ldt, current->mm, 1);
16035 preempt_enable();
16036 #else
16037 - load_LDT(pc);
16038 + load_LDT_nolock(pc);
16039 #endif
16040 }
16041 if (oldsize) {
16042 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t
16043 return err;
16044
16045 for (i = 0; i < old->size; i++)
16046 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
16047 + write_ldt_entry(new->ldt, i, old->ldt + i);
16048 return 0;
16049 }
16050
16051 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct
16052 retval = copy_ldt(&mm->context, &old_mm->context);
16053 mutex_unlock(&old_mm->context.lock);
16054 }
16055 +
16056 + if (tsk == current) {
16057 + mm->context.vdso = 0;
16058 +
16059 +#ifdef CONFIG_X86_32
16060 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16061 + mm->context.user_cs_base = 0UL;
16062 + mm->context.user_cs_limit = ~0UL;
16063 +
16064 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16065 + cpus_clear(mm->context.cpu_user_cs_mask);
16066 +#endif
16067 +
16068 +#endif
16069 +#endif
16070 +
16071 + }
16072 +
16073 return retval;
16074 }
16075
16076 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, u
16077 }
16078 }
16079
16080 +#ifdef CONFIG_PAX_SEGMEXEC
16081 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
16082 + error = -EINVAL;
16083 + goto out_unlock;
16084 + }
16085 +#endif
16086 +
16087 fill_ldt(&ldt, &ldt_info);
16088 if (oldmode)
16089 ldt.avl = 0;
16090 diff -urNp linux-2.6.39.2/arch/x86/kernel/machine_kexec_32.c linux-2.6.39.2/arch/x86/kernel/machine_kexec_32.c
16091 --- linux-2.6.39.2/arch/x86/kernel/machine_kexec_32.c 2011-05-19 00:06:34.000000000 -0400
16092 +++ linux-2.6.39.2/arch/x86/kernel/machine_kexec_32.c 2011-05-22 19:36:30.000000000 -0400
16093 @@ -27,7 +27,7 @@
16094 #include <asm/cacheflush.h>
16095 #include <asm/debugreg.h>
16096
16097 -static void set_idt(void *newidt, __u16 limit)
16098 +static void set_idt(struct desc_struct *newidt, __u16 limit)
16099 {
16100 struct desc_ptr curidt;
16101
16102 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16
16103 }
16104
16105
16106 -static void set_gdt(void *newgdt, __u16 limit)
16107 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
16108 {
16109 struct desc_ptr curgdt;
16110
16111 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
16112 }
16113
16114 control_page = page_address(image->control_code_page);
16115 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
16116 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
16117
16118 relocate_kernel_ptr = control_page;
16119 page_list[PA_CONTROL_PAGE] = __pa(control_page);
16120 diff -urNp linux-2.6.39.2/arch/x86/kernel/microcode_amd.c linux-2.6.39.2/arch/x86/kernel/microcode_amd.c
16121 --- linux-2.6.39.2/arch/x86/kernel/microcode_amd.c 2011-05-19 00:06:34.000000000 -0400
16122 +++ linux-2.6.39.2/arch/x86/kernel/microcode_amd.c 2011-05-22 19:36:30.000000000 -0400
16123 @@ -339,7 +339,7 @@ static void microcode_fini_cpu_amd(int c
16124 uci->mc = NULL;
16125 }
16126
16127 -static struct microcode_ops microcode_amd_ops = {
16128 +static const struct microcode_ops microcode_amd_ops = {
16129 .request_microcode_user = request_microcode_user,
16130 .request_microcode_fw = request_microcode_amd,
16131 .collect_cpu_info = collect_cpu_info_amd,
16132 @@ -347,7 +347,7 @@ static struct microcode_ops microcode_am
16133 .microcode_fini_cpu = microcode_fini_cpu_amd,
16134 };
16135
16136 -struct microcode_ops * __init init_amd_microcode(void)
16137 +const struct microcode_ops * __init init_amd_microcode(void)
16138 {
16139 return &microcode_amd_ops;
16140 }
16141 diff -urNp linux-2.6.39.2/arch/x86/kernel/microcode_core.c linux-2.6.39.2/arch/x86/kernel/microcode_core.c
16142 --- linux-2.6.39.2/arch/x86/kernel/microcode_core.c 2011-05-19 00:06:34.000000000 -0400
16143 +++ linux-2.6.39.2/arch/x86/kernel/microcode_core.c 2011-05-22 19:36:30.000000000 -0400
16144 @@ -93,7 +93,7 @@ MODULE_LICENSE("GPL");
16145
16146 #define MICROCODE_VERSION "2.00"
16147
16148 -static struct microcode_ops *microcode_ops;
16149 +static const struct microcode_ops *microcode_ops;
16150
16151 /*
16152 * Synchronization.
16153 diff -urNp linux-2.6.39.2/arch/x86/kernel/microcode_intel.c linux-2.6.39.2/arch/x86/kernel/microcode_intel.c
16154 --- linux-2.6.39.2/arch/x86/kernel/microcode_intel.c 2011-05-19 00:06:34.000000000 -0400
16155 +++ linux-2.6.39.2/arch/x86/kernel/microcode_intel.c 2011-05-22 19:36:30.000000000 -0400
16156 @@ -440,13 +440,13 @@ static enum ucode_state request_microcod
16157
16158 static int get_ucode_user(void *to, const void *from, size_t n)
16159 {
16160 - return copy_from_user(to, from, n);
16161 + return copy_from_user(to, (__force const void __user *)from, n);
16162 }
16163
16164 static enum ucode_state
16165 request_microcode_user(int cpu, const void __user *buf, size_t size)
16166 {
16167 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16168 + return generic_load_microcode(cpu, (__force void *)buf, size, &get_ucode_user);
16169 }
16170
16171 static void microcode_fini_cpu(int cpu)
16172 @@ -457,7 +457,7 @@ static void microcode_fini_cpu(int cpu)
16173 uci->mc = NULL;
16174 }
16175
16176 -static struct microcode_ops microcode_intel_ops = {
16177 +static const struct microcode_ops microcode_intel_ops = {
16178 .request_microcode_user = request_microcode_user,
16179 .request_microcode_fw = request_microcode_fw,
16180 .collect_cpu_info = collect_cpu_info,
16181 @@ -465,7 +465,7 @@ static struct microcode_ops microcode_in
16182 .microcode_fini_cpu = microcode_fini_cpu,
16183 };
16184
16185 -struct microcode_ops * __init init_intel_microcode(void)
16186 +const struct microcode_ops * __init init_intel_microcode(void)
16187 {
16188 return &microcode_intel_ops;
16189 }
16190 diff -urNp linux-2.6.39.2/arch/x86/kernel/module.c linux-2.6.39.2/arch/x86/kernel/module.c
16191 --- linux-2.6.39.2/arch/x86/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
16192 +++ linux-2.6.39.2/arch/x86/kernel/module.c 2011-05-22 19:36:30.000000000 -0400
16193 @@ -35,21 +35,66 @@
16194 #define DEBUGP(fmt...)
16195 #endif
16196
16197 -void *module_alloc(unsigned long size)
16198 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16199 {
16200 if (PAGE_ALIGN(size) > MODULES_LEN)
16201 return NULL;
16202 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16203 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16204 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16205 -1, __builtin_return_address(0));
16206 }
16207
16208 +void *module_alloc(unsigned long size)
16209 +{
16210 +
16211 +#ifdef CONFIG_PAX_KERNEXEC
16212 + return __module_alloc(size, PAGE_KERNEL);
16213 +#else
16214 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16215 +#endif
16216 +
16217 +}
16218 +
16219 /* Free memory returned from module_alloc */
16220 void module_free(struct module *mod, void *module_region)
16221 {
16222 vfree(module_region);
16223 }
16224
16225 +#ifdef CONFIG_PAX_KERNEXEC
16226 +#ifdef CONFIG_X86_32
16227 +void *module_alloc_exec(unsigned long size)
16228 +{
16229 + struct vm_struct *area;
16230 +
16231 + if (size == 0)
16232 + return NULL;
16233 +
16234 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16235 + return area ? area->addr : NULL;
16236 +}
16237 +EXPORT_SYMBOL(module_alloc_exec);
16238 +
16239 +void module_free_exec(struct module *mod, void *module_region)
16240 +{
16241 + vunmap(module_region);
16242 +}
16243 +EXPORT_SYMBOL(module_free_exec);
16244 +#else
16245 +void module_free_exec(struct module *mod, void *module_region)
16246 +{
16247 + module_free(mod, module_region);
16248 +}
16249 +EXPORT_SYMBOL(module_free_exec);
16250 +
16251 +void *module_alloc_exec(unsigned long size)
16252 +{
16253 + return __module_alloc(size, PAGE_KERNEL_RX);
16254 +}
16255 +EXPORT_SYMBOL(module_alloc_exec);
16256 +#endif
16257 +#endif
16258 +
16259 /* We don't need anything special. */
16260 int module_frob_arch_sections(Elf_Ehdr *hdr,
16261 Elf_Shdr *sechdrs,
16262 @@ -69,14 +114,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16263 unsigned int i;
16264 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16265 Elf32_Sym *sym;
16266 - uint32_t *location;
16267 + uint32_t *plocation, location;
16268
16269 DEBUGP("Applying relocate section %u to %u\n", relsec,
16270 sechdrs[relsec].sh_info);
16271 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16272 /* This is where to make the change */
16273 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16274 - + rel[i].r_offset;
16275 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16276 + location = (uint32_t)plocation;
16277 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16278 + plocation = ktla_ktva((void *)plocation);
16279 /* This is the symbol it is referring to. Note that all
16280 undefined symbols have been resolved. */
16281 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16282 @@ -85,11 +132,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16283 switch (ELF32_R_TYPE(rel[i].r_info)) {
16284 case R_386_32:
16285 /* We add the value into the location given */
16286 - *location += sym->st_value;
16287 + pax_open_kernel();
16288 + *plocation += sym->st_value;
16289 + pax_close_kernel();
16290 break;
16291 case R_386_PC32:
16292 /* Add the value, subtract its postition */
16293 - *location += sym->st_value - (uint32_t)location;
16294 + pax_open_kernel();
16295 + *plocation += sym->st_value - location;
16296 + pax_close_kernel();
16297 break;
16298 default:
16299 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16300 @@ -145,21 +196,30 @@ int apply_relocate_add(Elf64_Shdr *sechd
16301 case R_X86_64_NONE:
16302 break;
16303 case R_X86_64_64:
16304 + pax_open_kernel();
16305 *(u64 *)loc = val;
16306 + pax_close_kernel();
16307 break;
16308 case R_X86_64_32:
16309 + pax_open_kernel();
16310 *(u32 *)loc = val;
16311 + pax_close_kernel();
16312 if (val != *(u32 *)loc)
16313 goto overflow;
16314 break;
16315 case R_X86_64_32S:
16316 + pax_open_kernel();
16317 *(s32 *)loc = val;
16318 + pax_close_kernel();
16319 if ((s64)val != *(s32 *)loc)
16320 goto overflow;
16321 break;
16322 case R_X86_64_PC32:
16323 val -= (u64)loc;
16324 + pax_open_kernel();
16325 *(u32 *)loc = val;
16326 + pax_close_kernel();
16327 +
16328 #if 0
16329 if ((s64)val != *(s32 *)loc)
16330 goto overflow;
16331 diff -urNp linux-2.6.39.2/arch/x86/kernel/paravirt.c linux-2.6.39.2/arch/x86/kernel/paravirt.c
16332 --- linux-2.6.39.2/arch/x86/kernel/paravirt.c 2011-05-19 00:06:34.000000000 -0400
16333 +++ linux-2.6.39.2/arch/x86/kernel/paravirt.c 2011-05-22 19:36:30.000000000 -0400
16334 @@ -122,7 +122,7 @@ unsigned paravirt_patch_jmp(void *insnbu
16335 * corresponding structure. */
16336 static void *get_call_destination(u8 type)
16337 {
16338 - struct paravirt_patch_template tmpl = {
16339 + const struct paravirt_patch_template tmpl = {
16340 .pv_init_ops = pv_init_ops,
16341 .pv_time_ops = pv_time_ops,
16342 .pv_cpu_ops = pv_cpu_ops,
16343 @@ -133,6 +133,9 @@ static void *get_call_destination(u8 typ
16344 .pv_lock_ops = pv_lock_ops,
16345 #endif
16346 };
16347 +
16348 + pax_track_stack();
16349 +
16350 return *((void **)&tmpl + type);
16351 }
16352
16353 @@ -145,14 +148,14 @@ unsigned paravirt_patch_default(u8 type,
16354 if (opfunc == NULL)
16355 /* If there's no function, patch it with a ud2a (BUG) */
16356 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16357 - else if (opfunc == _paravirt_nop)
16358 + else if (opfunc == (void *)_paravirt_nop)
16359 /* If the operation is a nop, then nop the callsite */
16360 ret = paravirt_patch_nop();
16361
16362 /* identity functions just return their single argument */
16363 - else if (opfunc == _paravirt_ident_32)
16364 + else if (opfunc == (void *)_paravirt_ident_32)
16365 ret = paravirt_patch_ident_32(insnbuf, len);
16366 - else if (opfunc == _paravirt_ident_64)
16367 + else if (opfunc == (void *)_paravirt_ident_64)
16368 ret = paravirt_patch_ident_64(insnbuf, len);
16369
16370 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16371 @@ -178,7 +181,7 @@ unsigned paravirt_patch_insns(void *insn
16372 if (insn_len > len || start == NULL)
16373 insn_len = len;
16374 else
16375 - memcpy(insnbuf, start, insn_len);
16376 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16377
16378 return insn_len;
16379 }
16380 @@ -294,22 +297,22 @@ void arch_flush_lazy_mmu_mode(void)
16381 preempt_enable();
16382 }
16383
16384 -struct pv_info pv_info = {
16385 +struct pv_info pv_info __read_only = {
16386 .name = "bare hardware",
16387 .paravirt_enabled = 0,
16388 .kernel_rpl = 0,
16389 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
16390 };
16391
16392 -struct pv_init_ops pv_init_ops = {
16393 +struct pv_init_ops pv_init_ops __read_only = {
16394 .patch = native_patch,
16395 };
16396
16397 -struct pv_time_ops pv_time_ops = {
16398 +struct pv_time_ops pv_time_ops __read_only = {
16399 .sched_clock = native_sched_clock,
16400 };
16401
16402 -struct pv_irq_ops pv_irq_ops = {
16403 +struct pv_irq_ops pv_irq_ops __read_only = {
16404 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16405 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16406 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16407 @@ -321,7 +324,7 @@ struct pv_irq_ops pv_irq_ops = {
16408 #endif
16409 };
16410
16411 -struct pv_cpu_ops pv_cpu_ops = {
16412 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16413 .cpuid = native_cpuid,
16414 .get_debugreg = native_get_debugreg,
16415 .set_debugreg = native_set_debugreg,
16416 @@ -382,7 +385,7 @@ struct pv_cpu_ops pv_cpu_ops = {
16417 .end_context_switch = paravirt_nop,
16418 };
16419
16420 -struct pv_apic_ops pv_apic_ops = {
16421 +struct pv_apic_ops pv_apic_ops __read_only = {
16422 #ifdef CONFIG_X86_LOCAL_APIC
16423 .startup_ipi_hook = paravirt_nop,
16424 #endif
16425 @@ -396,7 +399,7 @@ struct pv_apic_ops pv_apic_ops = {
16426 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16427 #endif
16428
16429 -struct pv_mmu_ops pv_mmu_ops = {
16430 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16431
16432 .read_cr2 = native_read_cr2,
16433 .write_cr2 = native_write_cr2,
16434 @@ -465,6 +468,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16435 },
16436
16437 .set_fixmap = native_set_fixmap,
16438 +
16439 +#ifdef CONFIG_PAX_KERNEXEC
16440 + .pax_open_kernel = native_pax_open_kernel,
16441 + .pax_close_kernel = native_pax_close_kernel,
16442 +#endif
16443 +
16444 };
16445
16446 EXPORT_SYMBOL_GPL(pv_time_ops);
16447 diff -urNp linux-2.6.39.2/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.39.2/arch/x86/kernel/paravirt-spinlocks.c
16448 --- linux-2.6.39.2/arch/x86/kernel/paravirt-spinlocks.c 2011-05-19 00:06:34.000000000 -0400
16449 +++ linux-2.6.39.2/arch/x86/kernel/paravirt-spinlocks.c 2011-05-22 19:36:30.000000000 -0400
16450 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t
16451 arch_spin_lock(lock);
16452 }
16453
16454 -struct pv_lock_ops pv_lock_ops = {
16455 +struct pv_lock_ops pv_lock_ops __read_only = {
16456 #ifdef CONFIG_SMP
16457 .spin_is_locked = __ticket_spin_is_locked,
16458 .spin_is_contended = __ticket_spin_is_contended,
16459 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-calgary_64.c linux-2.6.39.2/arch/x86/kernel/pci-calgary_64.c
16460 --- linux-2.6.39.2/arch/x86/kernel/pci-calgary_64.c 2011-05-19 00:06:34.000000000 -0400
16461 +++ linux-2.6.39.2/arch/x86/kernel/pci-calgary_64.c 2011-05-22 19:36:30.000000000 -0400
16462 @@ -179,13 +179,13 @@ static void calioc2_dump_error_regs(stru
16463 static void calgary_init_bitmap_from_tce_table(struct iommu_table *tbl);
16464 static void get_tce_space_from_tar(void);
16465
16466 -static struct cal_chipset_ops calgary_chip_ops = {
16467 +static const struct cal_chipset_ops calgary_chip_ops = {
16468 .handle_quirks = calgary_handle_quirks,
16469 .tce_cache_blast = calgary_tce_cache_blast,
16470 .dump_error_regs = calgary_dump_error_regs
16471 };
16472
16473 -static struct cal_chipset_ops calioc2_chip_ops = {
16474 +static const struct cal_chipset_ops calioc2_chip_ops = {
16475 .handle_quirks = calioc2_handle_quirks,
16476 .tce_cache_blast = calioc2_tce_cache_blast,
16477 .dump_error_regs = calioc2_dump_error_regs
16478 @@ -476,7 +476,7 @@ static void calgary_free_coherent(struct
16479 free_pages((unsigned long)vaddr, get_order(size));
16480 }
16481
16482 -static struct dma_map_ops calgary_dma_ops = {
16483 +static const struct dma_map_ops calgary_dma_ops = {
16484 .alloc_coherent = calgary_alloc_coherent,
16485 .free_coherent = calgary_free_coherent,
16486 .map_sg = calgary_map_sg,
16487 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-dma.c linux-2.6.39.2/arch/x86/kernel/pci-dma.c
16488 --- linux-2.6.39.2/arch/x86/kernel/pci-dma.c 2011-05-19 00:06:34.000000000 -0400
16489 +++ linux-2.6.39.2/arch/x86/kernel/pci-dma.c 2011-05-22 19:36:30.000000000 -0400
16490 @@ -16,7 +16,7 @@
16491
16492 static int forbid_dac __read_mostly;
16493
16494 -struct dma_map_ops *dma_ops = &nommu_dma_ops;
16495 +const struct dma_map_ops *dma_ops = &nommu_dma_ops;
16496 EXPORT_SYMBOL(dma_ops);
16497
16498 static int iommu_sac_force __read_mostly;
16499 @@ -250,7 +250,7 @@ early_param("iommu", iommu_setup);
16500
16501 int dma_supported(struct device *dev, u64 mask)
16502 {
16503 - struct dma_map_ops *ops = get_dma_ops(dev);
16504 + const struct dma_map_ops *ops = get_dma_ops(dev);
16505
16506 #ifdef CONFIG_PCI
16507 if (mask > 0xffffffff && forbid_dac > 0) {
16508 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-gart_64.c linux-2.6.39.2/arch/x86/kernel/pci-gart_64.c
16509 --- linux-2.6.39.2/arch/x86/kernel/pci-gart_64.c 2011-05-19 00:06:34.000000000 -0400
16510 +++ linux-2.6.39.2/arch/x86/kernel/pci-gart_64.c 2011-05-22 19:36:30.000000000 -0400
16511 @@ -695,7 +695,7 @@ static __init int init_amd_gatt(struct a
16512 return -1;
16513 }
16514
16515 -static struct dma_map_ops gart_dma_ops = {
16516 +static const struct dma_map_ops gart_dma_ops = {
16517 .map_sg = gart_map_sg,
16518 .unmap_sg = gart_unmap_sg,
16519 .map_page = gart_map_page,
16520 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-iommu_table.c linux-2.6.39.2/arch/x86/kernel/pci-iommu_table.c
16521 --- linux-2.6.39.2/arch/x86/kernel/pci-iommu_table.c 2011-05-19 00:06:34.000000000 -0400
16522 +++ linux-2.6.39.2/arch/x86/kernel/pci-iommu_table.c 2011-05-22 19:36:30.000000000 -0400
16523 @@ -2,7 +2,7 @@
16524 #include <asm/iommu_table.h>
16525 #include <linux/string.h>
16526 #include <linux/kallsyms.h>
16527 -
16528 +#include <linux/sched.h>
16529
16530 #define DEBUG 1
16531
16532 @@ -53,6 +53,8 @@ void __init check_iommu_entries(struct i
16533 char sym_p[KSYM_SYMBOL_LEN];
16534 char sym_q[KSYM_SYMBOL_LEN];
16535
16536 + pax_track_stack();
16537 +
16538 /* Simple cyclic dependency checker. */
16539 for (p = start; p < finish; p++) {
16540 q = find_dependents_of(start, finish, p);
16541 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-nommu.c linux-2.6.39.2/arch/x86/kernel/pci-nommu.c
16542 --- linux-2.6.39.2/arch/x86/kernel/pci-nommu.c 2011-05-19 00:06:34.000000000 -0400
16543 +++ linux-2.6.39.2/arch/x86/kernel/pci-nommu.c 2011-05-22 19:36:30.000000000 -0400
16544 @@ -95,7 +95,7 @@ static void nommu_sync_sg_for_device(str
16545 flush_write_buffers();
16546 }
16547
16548 -struct dma_map_ops nommu_dma_ops = {
16549 +const struct dma_map_ops nommu_dma_ops = {
16550 .alloc_coherent = dma_generic_alloc_coherent,
16551 .free_coherent = nommu_free_coherent,
16552 .map_sg = nommu_map_sg,
16553 diff -urNp linux-2.6.39.2/arch/x86/kernel/pci-swiotlb.c linux-2.6.39.2/arch/x86/kernel/pci-swiotlb.c
16554 --- linux-2.6.39.2/arch/x86/kernel/pci-swiotlb.c 2011-05-19 00:06:34.000000000 -0400
16555 +++ linux-2.6.39.2/arch/x86/kernel/pci-swiotlb.c 2011-05-22 19:36:30.000000000 -0400
16556 @@ -26,7 +26,7 @@ static void *x86_swiotlb_alloc_coherent(
16557 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
16558 }
16559
16560 -static struct dma_map_ops swiotlb_dma_ops = {
16561 +static const struct dma_map_ops swiotlb_dma_ops = {
16562 .mapping_error = swiotlb_dma_mapping_error,
16563 .alloc_coherent = x86_swiotlb_alloc_coherent,
16564 .free_coherent = swiotlb_free_coherent,
16565 diff -urNp linux-2.6.39.2/arch/x86/kernel/process_32.c linux-2.6.39.2/arch/x86/kernel/process_32.c
16566 --- linux-2.6.39.2/arch/x86/kernel/process_32.c 2011-06-25 12:55:22.000000000 -0400
16567 +++ linux-2.6.39.2/arch/x86/kernel/process_32.c 2011-06-25 13:00:25.000000000 -0400
16568 @@ -65,6 +65,7 @@ asmlinkage void ret_from_fork(void) __as
16569 unsigned long thread_saved_pc(struct task_struct *tsk)
16570 {
16571 return ((unsigned long *)tsk->thread.sp)[3];
16572 +//XXX return tsk->thread.eip;
16573 }
16574
16575 #ifndef CONFIG_SMP
16576 @@ -126,15 +127,14 @@ void __show_regs(struct pt_regs *regs, i
16577 unsigned long sp;
16578 unsigned short ss, gs;
16579
16580 - if (user_mode_vm(regs)) {
16581 + if (user_mode(regs)) {
16582 sp = regs->sp;
16583 ss = regs->ss & 0xffff;
16584 - gs = get_user_gs(regs);
16585 } else {
16586 sp = kernel_stack_pointer(regs);
16587 savesegment(ss, ss);
16588 - savesegment(gs, gs);
16589 }
16590 + gs = get_user_gs(regs);
16591
16592 show_regs_common();
16593
16594 @@ -196,13 +196,14 @@ int copy_thread(unsigned long clone_flag
16595 struct task_struct *tsk;
16596 int err;
16597
16598 - childregs = task_pt_regs(p);
16599 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16600 *childregs = *regs;
16601 childregs->ax = 0;
16602 childregs->sp = sp;
16603
16604 p->thread.sp = (unsigned long) childregs;
16605 p->thread.sp0 = (unsigned long) (childregs+1);
16606 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16607
16608 p->thread.ip = (unsigned long) ret_from_fork;
16609
16610 @@ -292,7 +293,7 @@ __switch_to(struct task_struct *prev_p,
16611 struct thread_struct *prev = &prev_p->thread,
16612 *next = &next_p->thread;
16613 int cpu = smp_processor_id();
16614 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16615 + struct tss_struct *tss = init_tss + cpu;
16616 bool preload_fpu;
16617
16618 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16619 @@ -327,6 +328,10 @@ __switch_to(struct task_struct *prev_p,
16620 */
16621 lazy_save_gs(prev->gs);
16622
16623 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16624 + __set_fs(task_thread_info(next_p)->addr_limit);
16625 +#endif
16626 +
16627 /*
16628 * Load the per-thread Thread-Local Storage descriptor.
16629 */
16630 @@ -362,6 +367,9 @@ __switch_to(struct task_struct *prev_p,
16631 */
16632 arch_end_context_switch(next_p);
16633
16634 + percpu_write(current_task, next_p);
16635 + percpu_write(current_tinfo, &next_p->tinfo);
16636 +
16637 if (preload_fpu)
16638 __math_state_restore();
16639
16640 @@ -371,8 +379,6 @@ __switch_to(struct task_struct *prev_p,
16641 if (prev->gs | next->gs)
16642 lazy_load_gs(next->gs);
16643
16644 - percpu_write(current_task, next_p);
16645 -
16646 return prev_p;
16647 }
16648
16649 @@ -402,4 +408,3 @@ unsigned long get_wchan(struct task_stru
16650 } while (count++ < 16);
16651 return 0;
16652 }
16653 -
16654 diff -urNp linux-2.6.39.2/arch/x86/kernel/process_64.c linux-2.6.39.2/arch/x86/kernel/process_64.c
16655 --- linux-2.6.39.2/arch/x86/kernel/process_64.c 2011-06-25 12:55:22.000000000 -0400
16656 +++ linux-2.6.39.2/arch/x86/kernel/process_64.c 2011-06-25 13:00:25.000000000 -0400
16657 @@ -87,7 +87,7 @@ static void __exit_idle(void)
16658 void exit_idle(void)
16659 {
16660 /* idle loop has pid 0 */
16661 - if (current->pid)
16662 + if (task_pid_nr(current))
16663 return;
16664 __exit_idle();
16665 }
16666 @@ -260,8 +260,7 @@ int copy_thread(unsigned long clone_flag
16667 struct pt_regs *childregs;
16668 struct task_struct *me = current;
16669
16670 - childregs = ((struct pt_regs *)
16671 - (THREAD_SIZE + task_stack_page(p))) - 1;
16672 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16673 *childregs = *regs;
16674
16675 childregs->ax = 0;
16676 @@ -273,6 +272,7 @@ int copy_thread(unsigned long clone_flag
16677 p->thread.sp = (unsigned long) childregs;
16678 p->thread.sp0 = (unsigned long) (childregs+1);
16679 p->thread.usersp = me->thread.usersp;
16680 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16681
16682 set_tsk_thread_flag(p, TIF_FORK);
16683
16684 @@ -375,7 +375,7 @@ __switch_to(struct task_struct *prev_p,
16685 struct thread_struct *prev = &prev_p->thread;
16686 struct thread_struct *next = &next_p->thread;
16687 int cpu = smp_processor_id();
16688 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16689 + struct tss_struct *tss = init_tss + cpu;
16690 unsigned fsindex, gsindex;
16691 bool preload_fpu;
16692
16693 @@ -471,10 +471,9 @@ __switch_to(struct task_struct *prev_p,
16694 prev->usersp = percpu_read(old_rsp);
16695 percpu_write(old_rsp, next->usersp);
16696 percpu_write(current_task, next_p);
16697 + percpu_write(current_tinfo, &next_p->tinfo);
16698
16699 - percpu_write(kernel_stack,
16700 - (unsigned long)task_stack_page(next_p) +
16701 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16702 + percpu_write(kernel_stack, next->sp0);
16703
16704 /*
16705 * Now maybe reload the debug registers and handle I/O bitmaps
16706 @@ -536,12 +535,11 @@ unsigned long get_wchan(struct task_stru
16707 if (!p || p == current || p->state == TASK_RUNNING)
16708 return 0;
16709 stack = (unsigned long)task_stack_page(p);
16710 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16711 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16712 return 0;
16713 fp = *(u64 *)(p->thread.sp);
16714 do {
16715 - if (fp < (unsigned long)stack ||
16716 - fp >= (unsigned long)stack+THREAD_SIZE)
16717 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16718 return 0;
16719 ip = *(u64 *)(fp+8);
16720 if (!in_sched_functions(ip))
16721 diff -urNp linux-2.6.39.2/arch/x86/kernel/process.c linux-2.6.39.2/arch/x86/kernel/process.c
16722 --- linux-2.6.39.2/arch/x86/kernel/process.c 2011-05-19 00:06:34.000000000 -0400
16723 +++ linux-2.6.39.2/arch/x86/kernel/process.c 2011-05-22 19:36:30.000000000 -0400
16724 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_stru
16725
16726 void free_thread_info(struct thread_info *ti)
16727 {
16728 - free_thread_xstate(ti->task);
16729 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
16730 }
16731
16732 +static struct kmem_cache *task_struct_cachep;
16733 +
16734 void arch_task_cache_init(void)
16735 {
16736 - task_xstate_cachep =
16737 - kmem_cache_create("task_xstate", xstate_size,
16738 + /* create a slab on which task_structs can be allocated */
16739 + task_struct_cachep =
16740 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16741 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16742 +
16743 + task_xstate_cachep =
16744 + kmem_cache_create("task_xstate", xstate_size,
16745 __alignof__(union thread_xstate),
16746 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16747 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16748 +}
16749 +
16750 +struct task_struct *alloc_task_struct_node(int node)
16751 +{
16752 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16753 +}
16754 +
16755 +void free_task_struct(struct task_struct *task)
16756 +{
16757 + free_thread_xstate(task);
16758 + kmem_cache_free(task_struct_cachep, task);
16759 }
16760
16761 /*
16762 @@ -70,7 +87,7 @@ void exit_thread(void)
16763 unsigned long *bp = t->io_bitmap_ptr;
16764
16765 if (bp) {
16766 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16767 + struct tss_struct *tss = init_tss + get_cpu();
16768
16769 t->io_bitmap_ptr = NULL;
16770 clear_thread_flag(TIF_IO_BITMAP);
16771 @@ -106,7 +123,7 @@ void show_regs_common(void)
16772
16773 printk(KERN_CONT "\n");
16774 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16775 - current->pid, current->comm, print_tainted(),
16776 + task_pid_nr(current), current->comm, print_tainted(),
16777 init_utsname()->release,
16778 (int)strcspn(init_utsname()->version, " "),
16779 init_utsname()->version);
16780 @@ -120,6 +137,9 @@ void flush_thread(void)
16781 {
16782 struct task_struct *tsk = current;
16783
16784 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16785 + loadsegment(gs, 0);
16786 +#endif
16787 flush_ptrace_hw_breakpoint(tsk);
16788 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16789 /*
16790 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), voi
16791 regs.di = (unsigned long) arg;
16792
16793 #ifdef CONFIG_X86_32
16794 - regs.ds = __USER_DS;
16795 - regs.es = __USER_DS;
16796 + regs.ds = __KERNEL_DS;
16797 + regs.es = __KERNEL_DS;
16798 regs.fs = __KERNEL_PERCPU;
16799 - regs.gs = __KERNEL_STACK_CANARY;
16800 + savesegment(gs, regs.gs);
16801 #else
16802 regs.ss = __KERNEL_DS;
16803 #endif
16804 @@ -401,7 +421,7 @@ void default_idle(void)
16805 EXPORT_SYMBOL(default_idle);
16806 #endif
16807
16808 -void stop_this_cpu(void *dummy)
16809 +__noreturn void stop_this_cpu(void *dummy)
16810 {
16811 local_irq_disable();
16812 /*
16813 @@ -665,16 +685,34 @@ static int __init idle_setup(char *str)
16814 }
16815 early_param("idle", idle_setup);
16816
16817 -unsigned long arch_align_stack(unsigned long sp)
16818 +#ifdef CONFIG_PAX_RANDKSTACK
16819 +asmlinkage void pax_randomize_kstack(void)
16820 {
16821 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16822 - sp -= get_random_int() % 8192;
16823 - return sp & ~0xf;
16824 -}
16825 + struct thread_struct *thread = &current->thread;
16826 + unsigned long time;
16827
16828 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16829 -{
16830 - unsigned long range_end = mm->brk + 0x02000000;
16831 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16832 -}
16833 + if (!randomize_va_space)
16834 + return;
16835 +
16836 + rdtscl(time);
16837 +
16838 + /* P4 seems to return a 0 LSB, ignore it */
16839 +#ifdef CONFIG_MPENTIUM4
16840 + time &= 0x3EUL;
16841 + time <<= 2;
16842 +#elif defined(CONFIG_X86_64)
16843 + time &= 0xFUL;
16844 + time <<= 4;
16845 +#else
16846 + time &= 0x1FUL;
16847 + time <<= 3;
16848 +#endif
16849 +
16850 + thread->sp0 ^= time;
16851 + load_sp0(init_tss + smp_processor_id(), thread);
16852
16853 +#ifdef CONFIG_X86_64
16854 + percpu_write(kernel_stack, thread->sp0);
16855 +#endif
16856 +}
16857 +#endif
16858 diff -urNp linux-2.6.39.2/arch/x86/kernel/ptrace.c linux-2.6.39.2/arch/x86/kernel/ptrace.c
16859 --- linux-2.6.39.2/arch/x86/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
16860 +++ linux-2.6.39.2/arch/x86/kernel/ptrace.c 2011-05-22 19:36:30.000000000 -0400
16861 @@ -821,7 +821,7 @@ long arch_ptrace(struct task_struct *chi
16862 unsigned long addr, unsigned long data)
16863 {
16864 int ret;
16865 - unsigned long __user *datap = (unsigned long __user *)data;
16866 + unsigned long __user *datap = (__force unsigned long __user *)data;
16867
16868 switch (request) {
16869 /* read the word at location addr in the USER area. */
16870 @@ -906,14 +906,14 @@ long arch_ptrace(struct task_struct *chi
16871 if ((int) addr < 0)
16872 return -EIO;
16873 ret = do_get_thread_area(child, addr,
16874 - (struct user_desc __user *)data);
16875 + (__force struct user_desc __user *) data);
16876 break;
16877
16878 case PTRACE_SET_THREAD_AREA:
16879 if ((int) addr < 0)
16880 return -EIO;
16881 ret = do_set_thread_area(child, addr,
16882 - (struct user_desc __user *)data, 0);
16883 + (__force struct user_desc __user *) data, 0);
16884 break;
16885 #endif
16886
16887 @@ -1330,7 +1330,7 @@ static void fill_sigtrap_info(struct tas
16888 memset(info, 0, sizeof(*info));
16889 info->si_signo = SIGTRAP;
16890 info->si_code = si_code;
16891 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16892 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16893 }
16894
16895 void user_single_step_siginfo(struct task_struct *tsk,
16896 @@ -1363,7 +1363,7 @@ void send_sigtrap(struct task_struct *ts
16897 * We must return the syscall number to actually look up in the table.
16898 * This can be -1L to skip running any syscall at all.
16899 */
16900 -asmregparm long syscall_trace_enter(struct pt_regs *regs)
16901 +long syscall_trace_enter(struct pt_regs *regs)
16902 {
16903 long ret = 0;
16904
16905 @@ -1408,7 +1408,7 @@ asmregparm long syscall_trace_enter(stru
16906 return ret ?: regs->orig_ax;
16907 }
16908
16909 -asmregparm void syscall_trace_leave(struct pt_regs *regs)
16910 +void syscall_trace_leave(struct pt_regs *regs)
16911 {
16912 bool step;
16913
16914 diff -urNp linux-2.6.39.2/arch/x86/kernel/pvclock.c linux-2.6.39.2/arch/x86/kernel/pvclock.c
16915 --- linux-2.6.39.2/arch/x86/kernel/pvclock.c 2011-05-19 00:06:34.000000000 -0400
16916 +++ linux-2.6.39.2/arch/x86/kernel/pvclock.c 2011-05-22 19:36:30.000000000 -0400
16917 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvc
16918 return pv_tsc_khz;
16919 }
16920
16921 -static atomic64_t last_value = ATOMIC64_INIT(0);
16922 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16923
16924 void pvclock_resume(void)
16925 {
16926 - atomic64_set(&last_value, 0);
16927 + atomic64_set_unchecked(&last_value, 0);
16928 }
16929
16930 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16931 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct
16932 * updating at the same time, and one of them could be slightly behind,
16933 * making the assumption that last_value always go forward fail to hold.
16934 */
16935 - last = atomic64_read(&last_value);
16936 + last = atomic64_read_unchecked(&last_value);
16937 do {
16938 if (ret < last)
16939 return last;
16940 - last = atomic64_cmpxchg(&last_value, last, ret);
16941 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16942 } while (unlikely(last != ret));
16943
16944 return ret;
16945 diff -urNp linux-2.6.39.2/arch/x86/kernel/reboot.c linux-2.6.39.2/arch/x86/kernel/reboot.c
16946 --- linux-2.6.39.2/arch/x86/kernel/reboot.c 2011-05-19 00:06:34.000000000 -0400
16947 +++ linux-2.6.39.2/arch/x86/kernel/reboot.c 2011-05-23 17:07:00.000000000 -0400
16948 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16949 EXPORT_SYMBOL(pm_power_off);
16950
16951 static const struct desc_ptr no_idt = {};
16952 -static int reboot_mode;
16953 +static unsigned short reboot_mode;
16954 enum reboot_type reboot_type = BOOT_KBD;
16955 int reboot_force;
16956
16957 @@ -307,13 +307,17 @@ core_initcall(reboot_init);
16958 extern const unsigned char machine_real_restart_asm[];
16959 extern const u64 machine_real_restart_gdt[3];
16960
16961 -void machine_real_restart(unsigned int type)
16962 +__noreturn void machine_real_restart(unsigned int type)
16963 {
16964 void *restart_va;
16965 unsigned long restart_pa;
16966 - void (*restart_lowmem)(unsigned int);
16967 + void (* __noreturn restart_lowmem)(unsigned int);
16968 u64 *lowmem_gdt;
16969
16970 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16971 + struct desc_struct *gdt;
16972 +#endif
16973 +
16974 local_irq_disable();
16975
16976 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16977 @@ -339,14 +343,14 @@ void machine_real_restart(unsigned int t
16978 boot)". This seems like a fairly standard thing that gets set by
16979 REBOOT.COM programs, and the previous reset routine did this
16980 too. */
16981 - *((unsigned short *)0x472) = reboot_mode;
16982 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16983
16984 /* Patch the GDT in the low memory trampoline */
16985 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16986
16987 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16988 restart_pa = virt_to_phys(restart_va);
16989 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16990 + restart_lowmem = (void *)restart_pa;
16991
16992 /* GDT[0]: GDT self-pointer */
16993 lowmem_gdt[0] =
16994 @@ -357,7 +361,33 @@ void machine_real_restart(unsigned int t
16995 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16996
16997 /* Jump to the identity-mapped low memory code */
16998 +
16999 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17000 + gdt = get_cpu_gdt_table(smp_processor_id());
17001 + pax_open_kernel();
17002 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17003 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
17004 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
17005 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
17006 +#endif
17007 +#ifdef CONFIG_PAX_KERNEXEC
17008 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
17009 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
17010 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
17011 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
17012 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
17013 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
17014 +#endif
17015 + pax_close_kernel();
17016 +#endif
17017 +
17018 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17019 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
17020 + unreachable();
17021 +#else
17022 restart_lowmem(type);
17023 +#endif
17024 +
17025 }
17026 #ifdef CONFIG_APM_MODULE
17027 EXPORT_SYMBOL(machine_real_restart);
17028 @@ -478,7 +508,7 @@ void __attribute__((weak)) mach_reboot_f
17029 {
17030 }
17031
17032 -static void native_machine_emergency_restart(void)
17033 +__noreturn static void native_machine_emergency_restart(void)
17034 {
17035 int i;
17036
17037 @@ -593,13 +623,13 @@ void native_machine_shutdown(void)
17038 #endif
17039 }
17040
17041 -static void __machine_emergency_restart(int emergency)
17042 +static __noreturn void __machine_emergency_restart(int emergency)
17043 {
17044 reboot_emergency = emergency;
17045 machine_ops.emergency_restart();
17046 }
17047
17048 -static void native_machine_restart(char *__unused)
17049 +static __noreturn void native_machine_restart(char *__unused)
17050 {
17051 printk("machine restart\n");
17052
17053 @@ -608,7 +638,7 @@ static void native_machine_restart(char
17054 __machine_emergency_restart(0);
17055 }
17056
17057 -static void native_machine_halt(void)
17058 +static __noreturn void native_machine_halt(void)
17059 {
17060 /* stop other cpus and apics */
17061 machine_shutdown();
17062 @@ -619,7 +649,7 @@ static void native_machine_halt(void)
17063 stop_this_cpu(NULL);
17064 }
17065
17066 -static void native_machine_power_off(void)
17067 +__noreturn static void native_machine_power_off(void)
17068 {
17069 if (pm_power_off) {
17070 if (!reboot_force)
17071 @@ -628,6 +658,7 @@ static void native_machine_power_off(voi
17072 }
17073 /* a fallback in case there is no PM info available */
17074 tboot_shutdown(TB_SHUTDOWN_HALT);
17075 + unreachable();
17076 }
17077
17078 struct machine_ops machine_ops = {
17079 diff -urNp linux-2.6.39.2/arch/x86/kernel/setup.c linux-2.6.39.2/arch/x86/kernel/setup.c
17080 --- linux-2.6.39.2/arch/x86/kernel/setup.c 2011-06-25 12:55:22.000000000 -0400
17081 +++ linux-2.6.39.2/arch/x86/kernel/setup.c 2011-06-25 13:00:25.000000000 -0400
17082 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
17083 * area (640->1Mb) as ram even though it is not.
17084 * take them out.
17085 */
17086 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
17087 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
17088 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
17089 }
17090
17091 @@ -775,14 +775,14 @@ void __init setup_arch(char **cmdline_p)
17092
17093 if (!boot_params.hdr.root_flags)
17094 root_mountflags &= ~MS_RDONLY;
17095 - init_mm.start_code = (unsigned long) _text;
17096 - init_mm.end_code = (unsigned long) _etext;
17097 + init_mm.start_code = ktla_ktva((unsigned long) _text);
17098 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
17099 init_mm.end_data = (unsigned long) _edata;
17100 init_mm.brk = _brk_end;
17101
17102 - code_resource.start = virt_to_phys(_text);
17103 - code_resource.end = virt_to_phys(_etext)-1;
17104 - data_resource.start = virt_to_phys(_etext);
17105 + code_resource.start = virt_to_phys(ktla_ktva(_text));
17106 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
17107 + data_resource.start = virt_to_phys(_sdata);
17108 data_resource.end = virt_to_phys(_edata)-1;
17109 bss_resource.start = virt_to_phys(&__bss_start);
17110 bss_resource.end = virt_to_phys(&__bss_stop)-1;
17111 diff -urNp linux-2.6.39.2/arch/x86/kernel/setup_percpu.c linux-2.6.39.2/arch/x86/kernel/setup_percpu.c
17112 --- linux-2.6.39.2/arch/x86/kernel/setup_percpu.c 2011-05-19 00:06:34.000000000 -0400
17113 +++ linux-2.6.39.2/arch/x86/kernel/setup_percpu.c 2011-06-04 20:08:30.000000000 -0400
17114 @@ -21,19 +21,17 @@
17115 #include <asm/cpu.h>
17116 #include <asm/stackprotector.h>
17117
17118 -DEFINE_PER_CPU(int, cpu_number);
17119 +#ifdef CONFIG_SMP
17120 +DEFINE_PER_CPU(unsigned int, cpu_number);
17121 EXPORT_PER_CPU_SYMBOL(cpu_number);
17122 +#endif
17123
17124 -#ifdef CONFIG_X86_64
17125 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
17126 -#else
17127 -#define BOOT_PERCPU_OFFSET 0
17128 -#endif
17129
17130 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
17131 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
17132
17133 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
17134 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
17135 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17136 };
17137 EXPORT_SYMBOL(__per_cpu_offset);
17138 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(
17139 {
17140 #ifdef CONFIG_X86_32
17141 struct desc_struct gdt;
17142 + unsigned long base = per_cpu_offset(cpu);
17143
17144 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17145 - 0x2 | DESCTYPE_S, 0x8);
17146 - gdt.s = 1;
17147 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17148 + 0x83 | DESCTYPE_S, 0xC);
17149 write_gdt_entry(get_cpu_gdt_table(cpu),
17150 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17151 #endif
17152 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17153 /* alrighty, percpu areas up and running */
17154 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17155 for_each_possible_cpu(cpu) {
17156 +#ifdef CONFIG_CC_STACKPROTECTOR
17157 +#ifdef CONFIG_X86_32
17158 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
17159 +#endif
17160 +#endif
17161 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17162 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17163 per_cpu(cpu_number, cpu) = cpu;
17164 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17165 */
17166 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17167 #endif
17168 +#ifdef CONFIG_CC_STACKPROTECTOR
17169 +#ifdef CONFIG_X86_32
17170 + if (!cpu)
17171 + per_cpu(stack_canary.canary, cpu) = canary;
17172 +#endif
17173 +#endif
17174 /*
17175 * Up to this point, the boot CPU has been using .init.data
17176 * area. Reload any changed state for the boot CPU.
17177 diff -urNp linux-2.6.39.2/arch/x86/kernel/signal.c linux-2.6.39.2/arch/x86/kernel/signal.c
17178 --- linux-2.6.39.2/arch/x86/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
17179 +++ linux-2.6.39.2/arch/x86/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
17180 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsi
17181 * Align the stack pointer according to the i386 ABI,
17182 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17183 */
17184 - sp = ((sp + 4) & -16ul) - 4;
17185 + sp = ((sp - 12) & -16ul) - 4;
17186 #else /* !CONFIG_X86_32 */
17187 sp = round_down(sp, 16) - 8;
17188 #endif
17189 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, str
17190 * Return an always-bogus address instead so we will die with SIGSEGV.
17191 */
17192 if (onsigstack && !likely(on_sig_stack(sp)))
17193 - return (void __user *)-1L;
17194 + return (__force void __user *)-1L;
17195
17196 /* save i387 state */
17197 if (used_math() && save_i387_xstate(*fpstate) < 0)
17198 - return (void __user *)-1L;
17199 + return (__force void __user *)-1L;
17200
17201 return (void __user *)sp;
17202 }
17203 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigactio
17204 }
17205
17206 if (current->mm->context.vdso)
17207 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17208 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17209 else
17210 - restorer = &frame->retcode;
17211 + restorer = (void __user *)&frame->retcode;
17212 if (ka->sa.sa_flags & SA_RESTORER)
17213 restorer = ka->sa.sa_restorer;
17214
17215 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigactio
17216 * reasons and because gdb uses it as a signature to notice
17217 * signal handler stack frames.
17218 */
17219 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17220 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17221
17222 if (err)
17223 return -EFAULT;
17224 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, str
17225 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17226
17227 /* Set up to return from userspace. */
17228 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17229 + if (current->mm->context.vdso)
17230 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17231 + else
17232 + restorer = (void __user *)&frame->retcode;
17233 if (ka->sa.sa_flags & SA_RESTORER)
17234 restorer = ka->sa.sa_restorer;
17235 put_user_ex(restorer, &frame->pretcode);
17236 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, str
17237 * reasons and because gdb uses it as a signature to notice
17238 * signal handler stack frames.
17239 */
17240 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17241 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17242 } put_user_catch(err);
17243
17244 if (err)
17245 @@ -773,6 +776,8 @@ static void do_signal(struct pt_regs *re
17246 int signr;
17247 sigset_t *oldset;
17248
17249 + pax_track_stack();
17250 +
17251 /*
17252 * We want the common case to go fast, which is why we may in certain
17253 * cases get here from kernel mode. Just return without doing anything
17254 @@ -780,7 +785,7 @@ static void do_signal(struct pt_regs *re
17255 * X86_32: vm86 regs switched out by assembly code before reaching
17256 * here, so testing against kernel CS suffices.
17257 */
17258 - if (!user_mode(regs))
17259 + if (!user_mode_novm(regs))
17260 return;
17261
17262 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
17263 diff -urNp linux-2.6.39.2/arch/x86/kernel/smpboot.c linux-2.6.39.2/arch/x86/kernel/smpboot.c
17264 --- linux-2.6.39.2/arch/x86/kernel/smpboot.c 2011-06-25 12:55:22.000000000 -0400
17265 +++ linux-2.6.39.2/arch/x86/kernel/smpboot.c 2011-06-25 13:00:25.000000000 -0400
17266 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int api
17267 set_idle_for_cpu(cpu, c_idle.idle);
17268 do_rest:
17269 per_cpu(current_task, cpu) = c_idle.idle;
17270 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17271 #ifdef CONFIG_X86_32
17272 /* Stack for startup_32 can be just as for start_secondary onwards */
17273 irq_ctx_init(cpu);
17274 #else
17275 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17276 initial_gs = per_cpu_offset(cpu);
17277 - per_cpu(kernel_stack, cpu) =
17278 - (unsigned long)task_stack_page(c_idle.idle) -
17279 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17280 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17281 #endif
17282 +
17283 + pax_open_kernel();
17284 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17285 + pax_close_kernel();
17286 +
17287 initial_code = (unsigned long)start_secondary;
17288 stack_start = c_idle.idle->thread.sp;
17289
17290 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int
17291
17292 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17293
17294 +#ifdef CONFIG_PAX_PER_CPU_PGD
17295 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17296 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17297 + KERNEL_PGD_PTRS);
17298 +#endif
17299 +
17300 err = do_boot_cpu(apicid, cpu);
17301 if (err) {
17302 pr_debug("do_boot_cpu failed %d\n", err);
17303 diff -urNp linux-2.6.39.2/arch/x86/kernel/step.c linux-2.6.39.2/arch/x86/kernel/step.c
17304 --- linux-2.6.39.2/arch/x86/kernel/step.c 2011-05-19 00:06:34.000000000 -0400
17305 +++ linux-2.6.39.2/arch/x86/kernel/step.c 2011-05-22 19:36:30.000000000 -0400
17306 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struc
17307 struct desc_struct *desc;
17308 unsigned long base;
17309
17310 - seg &= ~7UL;
17311 + seg >>= 3;
17312
17313 mutex_lock(&child->mm->context.lock);
17314 - if (unlikely((seg >> 3) >= child->mm->context.size))
17315 + if (unlikely(seg >= child->mm->context.size))
17316 addr = -1L; /* bogus selector, access would fault */
17317 else {
17318 desc = child->mm->context.ldt + seg;
17319 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struc
17320 addr += base;
17321 }
17322 mutex_unlock(&child->mm->context.lock);
17323 - }
17324 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17325 + addr = ktla_ktva(addr);
17326
17327 return addr;
17328 }
17329 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct t
17330 unsigned char opcode[15];
17331 unsigned long addr = convert_ip_to_linear(child, regs);
17332
17333 + if (addr == -EINVAL)
17334 + return 0;
17335 +
17336 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17337 for (i = 0; i < copied; i++) {
17338 switch (opcode[i]) {
17339 @@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct t
17340
17341 #ifdef CONFIG_X86_64
17342 case 0x40 ... 0x4f:
17343 - if (regs->cs != __USER_CS)
17344 + if ((regs->cs & 0xffff) != __USER_CS)
17345 /* 32-bit mode: register increment */
17346 return 0;
17347 /* 64-bit mode: REX prefix */
17348 diff -urNp linux-2.6.39.2/arch/x86/kernel/syscall_table_32.S linux-2.6.39.2/arch/x86/kernel/syscall_table_32.S
17349 --- linux-2.6.39.2/arch/x86/kernel/syscall_table_32.S 2011-05-19 00:06:34.000000000 -0400
17350 +++ linux-2.6.39.2/arch/x86/kernel/syscall_table_32.S 2011-05-22 19:36:30.000000000 -0400
17351 @@ -1,3 +1,4 @@
17352 +.section .rodata,"a",@progbits
17353 ENTRY(sys_call_table)
17354 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17355 .long sys_exit
17356 diff -urNp linux-2.6.39.2/arch/x86/kernel/sys_i386_32.c linux-2.6.39.2/arch/x86/kernel/sys_i386_32.c
17357 --- linux-2.6.39.2/arch/x86/kernel/sys_i386_32.c 2011-05-19 00:06:34.000000000 -0400
17358 +++ linux-2.6.39.2/arch/x86/kernel/sys_i386_32.c 2011-05-22 19:36:30.000000000 -0400
17359 @@ -24,17 +24,224 @@
17360
17361 #include <asm/syscalls.h>
17362
17363 -/*
17364 - * Do a system call from kernel instead of calling sys_execve so we
17365 - * end up with proper pt_regs.
17366 - */
17367 -int kernel_execve(const char *filename,
17368 - const char *const argv[],
17369 - const char *const envp[])
17370 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17371 {
17372 - long __res;
17373 - asm volatile ("int $0x80"
17374 - : "=a" (__res)
17375 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17376 - return __res;
17377 + unsigned long pax_task_size = TASK_SIZE;
17378 +
17379 +#ifdef CONFIG_PAX_SEGMEXEC
17380 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17381 + pax_task_size = SEGMEXEC_TASK_SIZE;
17382 +#endif
17383 +
17384 + if (len > pax_task_size || addr > pax_task_size - len)
17385 + return -EINVAL;
17386 +
17387 + return 0;
17388 +}
17389 +
17390 +unsigned long
17391 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17392 + unsigned long len, unsigned long pgoff, unsigned long flags)
17393 +{
17394 + struct mm_struct *mm = current->mm;
17395 + struct vm_area_struct *vma;
17396 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17397 +
17398 +#ifdef CONFIG_PAX_SEGMEXEC
17399 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17400 + pax_task_size = SEGMEXEC_TASK_SIZE;
17401 +#endif
17402 +
17403 + pax_task_size -= PAGE_SIZE;
17404 +
17405 + if (len > pax_task_size)
17406 + return -ENOMEM;
17407 +
17408 + if (flags & MAP_FIXED)
17409 + return addr;
17410 +
17411 +#ifdef CONFIG_PAX_RANDMMAP
17412 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17413 +#endif
17414 +
17415 + if (addr) {
17416 + addr = PAGE_ALIGN(addr);
17417 + if (pax_task_size - len >= addr) {
17418 + vma = find_vma(mm, addr);
17419 + if (check_heap_stack_gap(vma, addr, len))
17420 + return addr;
17421 + }
17422 + }
17423 + if (len > mm->cached_hole_size) {
17424 + start_addr = addr = mm->free_area_cache;
17425 + } else {
17426 + start_addr = addr = mm->mmap_base;
17427 + mm->cached_hole_size = 0;
17428 + }
17429 +
17430 +#ifdef CONFIG_PAX_PAGEEXEC
17431 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17432 + start_addr = 0x00110000UL;
17433 +
17434 +#ifdef CONFIG_PAX_RANDMMAP
17435 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17436 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17437 +#endif
17438 +
17439 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17440 + start_addr = addr = mm->mmap_base;
17441 + else
17442 + addr = start_addr;
17443 + }
17444 +#endif
17445 +
17446 +full_search:
17447 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17448 + /* At this point: (!vma || addr < vma->vm_end). */
17449 + if (pax_task_size - len < addr) {
17450 + /*
17451 + * Start a new search - just in case we missed
17452 + * some holes.
17453 + */
17454 + if (start_addr != mm->mmap_base) {
17455 + start_addr = addr = mm->mmap_base;
17456 + mm->cached_hole_size = 0;
17457 + goto full_search;
17458 + }
17459 + return -ENOMEM;
17460 + }
17461 + if (check_heap_stack_gap(vma, addr, len))
17462 + break;
17463 + if (addr + mm->cached_hole_size < vma->vm_start)
17464 + mm->cached_hole_size = vma->vm_start - addr;
17465 + addr = vma->vm_end;
17466 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17467 + start_addr = addr = mm->mmap_base;
17468 + mm->cached_hole_size = 0;
17469 + goto full_search;
17470 + }
17471 + }
17472 +
17473 + /*
17474 + * Remember the place where we stopped the search:
17475 + */
17476 + mm->free_area_cache = addr + len;
17477 + return addr;
17478 +}
17479 +
17480 +unsigned long
17481 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17482 + const unsigned long len, const unsigned long pgoff,
17483 + const unsigned long flags)
17484 +{
17485 + struct vm_area_struct *vma;
17486 + struct mm_struct *mm = current->mm;
17487 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17488 +
17489 +#ifdef CONFIG_PAX_SEGMEXEC
17490 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17491 + pax_task_size = SEGMEXEC_TASK_SIZE;
17492 +#endif
17493 +
17494 + pax_task_size -= PAGE_SIZE;
17495 +
17496 + /* requested length too big for entire address space */
17497 + if (len > pax_task_size)
17498 + return -ENOMEM;
17499 +
17500 + if (flags & MAP_FIXED)
17501 + return addr;
17502 +
17503 +#ifdef CONFIG_PAX_PAGEEXEC
17504 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17505 + goto bottomup;
17506 +#endif
17507 +
17508 +#ifdef CONFIG_PAX_RANDMMAP
17509 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17510 +#endif
17511 +
17512 + /* requesting a specific address */
17513 + if (addr) {
17514 + addr = PAGE_ALIGN(addr);
17515 + if (pax_task_size - len >= addr) {
17516 + vma = find_vma(mm, addr);
17517 + if (check_heap_stack_gap(vma, addr, len))
17518 + return addr;
17519 + }
17520 + }
17521 +
17522 + /* check if free_area_cache is useful for us */
17523 + if (len <= mm->cached_hole_size) {
17524 + mm->cached_hole_size = 0;
17525 + mm->free_area_cache = mm->mmap_base;
17526 + }
17527 +
17528 + /* either no address requested or can't fit in requested address hole */
17529 + addr = mm->free_area_cache;
17530 +
17531 + /* make sure it can fit in the remaining address space */
17532 + if (addr > len) {
17533 + vma = find_vma(mm, addr-len);
17534 + if (check_heap_stack_gap(vma, addr - len, len))
17535 + /* remember the address as a hint for next time */
17536 + return (mm->free_area_cache = addr-len);
17537 + }
17538 +
17539 + if (mm->mmap_base < len)
17540 + goto bottomup;
17541 +
17542 + addr = mm->mmap_base-len;
17543 +
17544 + do {
17545 + /*
17546 + * Lookup failure means no vma is above this address,
17547 + * else if new region fits below vma->vm_start,
17548 + * return with success:
17549 + */
17550 + vma = find_vma(mm, addr);
17551 + if (check_heap_stack_gap(vma, addr, len))
17552 + /* remember the address as a hint for next time */
17553 + return (mm->free_area_cache = addr);
17554 +
17555 + /* remember the largest hole we saw so far */
17556 + if (addr + mm->cached_hole_size < vma->vm_start)
17557 + mm->cached_hole_size = vma->vm_start - addr;
17558 +
17559 + /* try just below the current vma->vm_start */
17560 + addr = skip_heap_stack_gap(vma, len);
17561 + } while (!IS_ERR_VALUE(addr));
17562 +
17563 +bottomup:
17564 + /*
17565 + * A failed mmap() very likely causes application failure,
17566 + * so fall back to the bottom-up function here. This scenario
17567 + * can happen with large stack limits and large mmap()
17568 + * allocations.
17569 + */
17570 +
17571 +#ifdef CONFIG_PAX_SEGMEXEC
17572 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17573 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17574 + else
17575 +#endif
17576 +
17577 + mm->mmap_base = TASK_UNMAPPED_BASE;
17578 +
17579 +#ifdef CONFIG_PAX_RANDMMAP
17580 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17581 + mm->mmap_base += mm->delta_mmap;
17582 +#endif
17583 +
17584 + mm->free_area_cache = mm->mmap_base;
17585 + mm->cached_hole_size = ~0UL;
17586 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17587 + /*
17588 + * Restore the topdown base:
17589 + */
17590 + mm->mmap_base = base;
17591 + mm->free_area_cache = base;
17592 + mm->cached_hole_size = ~0UL;
17593 +
17594 + return addr;
17595 }
17596 diff -urNp linux-2.6.39.2/arch/x86/kernel/sys_x86_64.c linux-2.6.39.2/arch/x86/kernel/sys_x86_64.c
17597 --- linux-2.6.39.2/arch/x86/kernel/sys_x86_64.c 2011-05-19 00:06:34.000000000 -0400
17598 +++ linux-2.6.39.2/arch/x86/kernel/sys_x86_64.c 2011-05-22 19:36:30.000000000 -0400
17599 @@ -32,8 +32,8 @@ out:
17600 return error;
17601 }
17602
17603 -static void find_start_end(unsigned long flags, unsigned long *begin,
17604 - unsigned long *end)
17605 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17606 + unsigned long *begin, unsigned long *end)
17607 {
17608 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17609 unsigned long new_begin;
17610 @@ -52,7 +52,7 @@ static void find_start_end(unsigned long
17611 *begin = new_begin;
17612 }
17613 } else {
17614 - *begin = TASK_UNMAPPED_BASE;
17615 + *begin = mm->mmap_base;
17616 *end = TASK_SIZE;
17617 }
17618 }
17619 @@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp
17620 if (flags & MAP_FIXED)
17621 return addr;
17622
17623 - find_start_end(flags, &begin, &end);
17624 + find_start_end(mm, flags, &begin, &end);
17625
17626 if (len > end)
17627 return -ENOMEM;
17628
17629 +#ifdef CONFIG_PAX_RANDMMAP
17630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17631 +#endif
17632 +
17633 if (addr) {
17634 addr = PAGE_ALIGN(addr);
17635 vma = find_vma(mm, addr);
17636 - if (end - len >= addr &&
17637 - (!vma || addr + len <= vma->vm_start))
17638 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17639 return addr;
17640 }
17641 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17642 @@ -106,7 +109,7 @@ full_search:
17643 }
17644 return -ENOMEM;
17645 }
17646 - if (!vma || addr + len <= vma->vm_start) {
17647 + if (check_heap_stack_gap(vma, addr, len)) {
17648 /*
17649 * Remember the place where we stopped the search:
17650 */
17651 @@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct fi
17652 {
17653 struct vm_area_struct *vma;
17654 struct mm_struct *mm = current->mm;
17655 - unsigned long addr = addr0;
17656 + unsigned long base = mm->mmap_base, addr = addr0;
17657
17658 /* requested length too big for entire address space */
17659 if (len > TASK_SIZE)
17660 @@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct fi
17661 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17662 goto bottomup;
17663
17664 +#ifdef CONFIG_PAX_RANDMMAP
17665 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17666 +#endif
17667 +
17668 /* requesting a specific address */
17669 if (addr) {
17670 addr = PAGE_ALIGN(addr);
17671 - vma = find_vma(mm, addr);
17672 - if (TASK_SIZE - len >= addr &&
17673 - (!vma || addr + len <= vma->vm_start))
17674 - return addr;
17675 + if (TASK_SIZE - len >= addr) {
17676 + vma = find_vma(mm, addr);
17677 + if (check_heap_stack_gap(vma, addr, len))
17678 + return addr;
17679 + }
17680 }
17681
17682 /* check if free_area_cache is useful for us */
17683 @@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct fi
17684 /* make sure it can fit in the remaining address space */
17685 if (addr > len) {
17686 vma = find_vma(mm, addr-len);
17687 - if (!vma || addr <= vma->vm_start)
17688 + if (check_heap_stack_gap(vma, addr - len, len))
17689 /* remember the address as a hint for next time */
17690 return mm->free_area_cache = addr-len;
17691 }
17692 @@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct fi
17693 * return with success:
17694 */
17695 vma = find_vma(mm, addr);
17696 - if (!vma || addr+len <= vma->vm_start)
17697 + if (check_heap_stack_gap(vma, addr, len))
17698 /* remember the address as a hint for next time */
17699 return mm->free_area_cache = addr;
17700
17701 @@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct fi
17702 mm->cached_hole_size = vma->vm_start - addr;
17703
17704 /* try just below the current vma->vm_start */
17705 - addr = vma->vm_start-len;
17706 - } while (len < vma->vm_start);
17707 + addr = skip_heap_stack_gap(vma, len);
17708 + } while (!IS_ERR_VALUE(addr));
17709
17710 bottomup:
17711 /*
17712 @@ -198,13 +206,21 @@ bottomup:
17713 * can happen with large stack limits and large mmap()
17714 * allocations.
17715 */
17716 + mm->mmap_base = TASK_UNMAPPED_BASE;
17717 +
17718 +#ifdef CONFIG_PAX_RANDMMAP
17719 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17720 + mm->mmap_base += mm->delta_mmap;
17721 +#endif
17722 +
17723 + mm->free_area_cache = mm->mmap_base;
17724 mm->cached_hole_size = ~0UL;
17725 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17726 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17727 /*
17728 * Restore the topdown base:
17729 */
17730 - mm->free_area_cache = mm->mmap_base;
17731 + mm->mmap_base = base;
17732 + mm->free_area_cache = base;
17733 mm->cached_hole_size = ~0UL;
17734
17735 return addr;
17736 diff -urNp linux-2.6.39.2/arch/x86/kernel/tboot.c linux-2.6.39.2/arch/x86/kernel/tboot.c
17737 --- linux-2.6.39.2/arch/x86/kernel/tboot.c 2011-05-19 00:06:34.000000000 -0400
17738 +++ linux-2.6.39.2/arch/x86/kernel/tboot.c 2011-05-22 19:36:30.000000000 -0400
17739 @@ -218,7 +218,7 @@ static int tboot_setup_sleep(void)
17740
17741 void tboot_shutdown(u32 shutdown_type)
17742 {
17743 - void (*shutdown)(void);
17744 + void (* __noreturn shutdown)(void);
17745
17746 if (!tboot_enabled())
17747 return;
17748 @@ -240,7 +240,7 @@ void tboot_shutdown(u32 shutdown_type)
17749
17750 switch_to_tboot_pt();
17751
17752 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17753 + shutdown = (void *)tboot->shutdown_entry;
17754 shutdown();
17755
17756 /* should not reach here */
17757 @@ -297,7 +297,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1
17758 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17759 }
17760
17761 -static atomic_t ap_wfs_count;
17762 +static atomic_unchecked_t ap_wfs_count;
17763
17764 static int tboot_wait_for_aps(int num_aps)
17765 {
17766 @@ -321,9 +321,9 @@ static int __cpuinit tboot_cpu_callback(
17767 {
17768 switch (action) {
17769 case CPU_DYING:
17770 - atomic_inc(&ap_wfs_count);
17771 + atomic_inc_unchecked(&ap_wfs_count);
17772 if (num_online_cpus() == 1)
17773 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17774 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17775 return NOTIFY_BAD;
17776 break;
17777 }
17778 @@ -342,7 +342,7 @@ static __init int tboot_late_init(void)
17779
17780 tboot_create_trampoline();
17781
17782 - atomic_set(&ap_wfs_count, 0);
17783 + atomic_set_unchecked(&ap_wfs_count, 0);
17784 register_hotcpu_notifier(&tboot_cpu_notifier);
17785 return 0;
17786 }
17787 diff -urNp linux-2.6.39.2/arch/x86/kernel/time.c linux-2.6.39.2/arch/x86/kernel/time.c
17788 --- linux-2.6.39.2/arch/x86/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
17789 +++ linux-2.6.39.2/arch/x86/kernel/time.c 2011-05-22 19:36:30.000000000 -0400
17790 @@ -22,17 +22,13 @@
17791 #include <asm/hpet.h>
17792 #include <asm/time.h>
17793
17794 -#ifdef CONFIG_X86_64
17795 -volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
17796 -#endif
17797 -
17798 unsigned long profile_pc(struct pt_regs *regs)
17799 {
17800 unsigned long pc = instruction_pointer(regs);
17801
17802 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17803 + if (!user_mode(regs) && in_lock_functions(pc)) {
17804 #ifdef CONFIG_FRAME_POINTER
17805 - return *(unsigned long *)(regs->bp + sizeof(long));
17806 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17807 #else
17808 unsigned long *sp =
17809 (unsigned long *)kernel_stack_pointer(regs);
17810 @@ -41,11 +37,17 @@ unsigned long profile_pc(struct pt_regs
17811 * or above a saved flags. Eflags has bits 22-31 zero,
17812 * kernel addresses don't.
17813 */
17814 +
17815 +#ifdef CONFIG_PAX_KERNEXEC
17816 + return ktla_ktva(sp[0]);
17817 +#else
17818 if (sp[0] >> 22)
17819 return sp[0];
17820 if (sp[1] >> 22)
17821 return sp[1];
17822 #endif
17823 +
17824 +#endif
17825 }
17826 return pc;
17827 }
17828 diff -urNp linux-2.6.39.2/arch/x86/kernel/tls.c linux-2.6.39.2/arch/x86/kernel/tls.c
17829 --- linux-2.6.39.2/arch/x86/kernel/tls.c 2011-05-19 00:06:34.000000000 -0400
17830 +++ linux-2.6.39.2/arch/x86/kernel/tls.c 2011-05-22 19:36:30.000000000 -0400
17831 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
17832 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17833 return -EINVAL;
17834
17835 +#ifdef CONFIG_PAX_SEGMEXEC
17836 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17837 + return -EINVAL;
17838 +#endif
17839 +
17840 set_tls_desc(p, idx, &info, 1);
17841
17842 return 0;
17843 diff -urNp linux-2.6.39.2/arch/x86/kernel/trampoline_32.S linux-2.6.39.2/arch/x86/kernel/trampoline_32.S
17844 --- linux-2.6.39.2/arch/x86/kernel/trampoline_32.S 2011-05-19 00:06:34.000000000 -0400
17845 +++ linux-2.6.39.2/arch/x86/kernel/trampoline_32.S 2011-05-22 19:36:30.000000000 -0400
17846 @@ -32,6 +32,12 @@
17847 #include <asm/segment.h>
17848 #include <asm/page_types.h>
17849
17850 +#ifdef CONFIG_PAX_KERNEXEC
17851 +#define ta(X) (X)
17852 +#else
17853 +#define ta(X) ((X) - __PAGE_OFFSET)
17854 +#endif
17855 +
17856 #ifdef CONFIG_SMP
17857
17858 .section ".x86_trampoline","a"
17859 @@ -62,7 +68,7 @@ r_base = .
17860 inc %ax # protected mode (PE) bit
17861 lmsw %ax # into protected mode
17862 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17863 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17864 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17865
17866 # These need to be in the same 64K segment as the above;
17867 # hence we don't use the boot_gdt_descr defined in head.S
17868 diff -urNp linux-2.6.39.2/arch/x86/kernel/trampoline_64.S linux-2.6.39.2/arch/x86/kernel/trampoline_64.S
17869 --- linux-2.6.39.2/arch/x86/kernel/trampoline_64.S 2011-05-19 00:06:34.000000000 -0400
17870 +++ linux-2.6.39.2/arch/x86/kernel/trampoline_64.S 2011-05-22 19:36:30.000000000 -0400
17871 @@ -90,7 +90,7 @@ startup_32:
17872 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17873 movl %eax, %ds
17874
17875 - movl $X86_CR4_PAE, %eax
17876 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17877 movl %eax, %cr4 # Enable PAE mode
17878
17879 # Setup trampoline 4 level pagetables
17880 @@ -138,7 +138,7 @@ tidt:
17881 # so the kernel can live anywhere
17882 .balign 4
17883 tgdt:
17884 - .short tgdt_end - tgdt # gdt limit
17885 + .short tgdt_end - tgdt - 1 # gdt limit
17886 .long tgdt - r_base
17887 .short 0
17888 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17889 diff -urNp linux-2.6.39.2/arch/x86/kernel/traps.c linux-2.6.39.2/arch/x86/kernel/traps.c
17890 --- linux-2.6.39.2/arch/x86/kernel/traps.c 2011-05-19 00:06:34.000000000 -0400
17891 +++ linux-2.6.39.2/arch/x86/kernel/traps.c 2011-05-22 19:36:30.000000000 -0400
17892 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17893
17894 /* Do we ignore FPU interrupts ? */
17895 char ignore_fpu_irq;
17896 -
17897 -/*
17898 - * The IDT has to be page-aligned to simplify the Pentium
17899 - * F0 0F bug workaround.
17900 - */
17901 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17902 #endif
17903
17904 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17905 @@ -117,13 +111,13 @@ static inline void preempt_conditional_c
17906 }
17907
17908 static void __kprobes
17909 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17910 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17911 long error_code, siginfo_t *info)
17912 {
17913 struct task_struct *tsk = current;
17914
17915 #ifdef CONFIG_X86_32
17916 - if (regs->flags & X86_VM_MASK) {
17917 + if (v8086_mode(regs)) {
17918 /*
17919 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17920 * On nmi (interrupt 2), do_trap should not be called.
17921 @@ -134,7 +128,7 @@ do_trap(int trapnr, int signr, char *str
17922 }
17923 #endif
17924
17925 - if (!user_mode(regs))
17926 + if (!user_mode_novm(regs))
17927 goto kernel_trap;
17928
17929 #ifdef CONFIG_X86_32
17930 @@ -157,7 +151,7 @@ trap_signal:
17931 printk_ratelimit()) {
17932 printk(KERN_INFO
17933 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17934 - tsk->comm, tsk->pid, str,
17935 + tsk->comm, task_pid_nr(tsk), str,
17936 regs->ip, regs->sp, error_code);
17937 print_vma_addr(" in ", regs->ip);
17938 printk("\n");
17939 @@ -174,8 +168,20 @@ kernel_trap:
17940 if (!fixup_exception(regs)) {
17941 tsk->thread.error_code = error_code;
17942 tsk->thread.trap_no = trapnr;
17943 +
17944 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17945 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17946 + str = "PAX: suspicious stack segment fault";
17947 +#endif
17948 +
17949 die(str, regs, error_code);
17950 }
17951 +
17952 +#ifdef CONFIG_PAX_REFCOUNT
17953 + if (trapnr == 4)
17954 + pax_report_refcount_overflow(regs);
17955 +#endif
17956 +
17957 return;
17958
17959 #ifdef CONFIG_X86_32
17960 @@ -264,14 +270,30 @@ do_general_protection(struct pt_regs *re
17961 conditional_sti(regs);
17962
17963 #ifdef CONFIG_X86_32
17964 - if (regs->flags & X86_VM_MASK)
17965 + if (v8086_mode(regs))
17966 goto gp_in_vm86;
17967 #endif
17968
17969 tsk = current;
17970 - if (!user_mode(regs))
17971 + if (!user_mode_novm(regs))
17972 goto gp_in_kernel;
17973
17974 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17975 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17976 + struct mm_struct *mm = tsk->mm;
17977 + unsigned long limit;
17978 +
17979 + down_write(&mm->mmap_sem);
17980 + limit = mm->context.user_cs_limit;
17981 + if (limit < TASK_SIZE) {
17982 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17983 + up_write(&mm->mmap_sem);
17984 + return;
17985 + }
17986 + up_write(&mm->mmap_sem);
17987 + }
17988 +#endif
17989 +
17990 tsk->thread.error_code = error_code;
17991 tsk->thread.trap_no = 13;
17992
17993 @@ -304,6 +326,13 @@ gp_in_kernel:
17994 if (notify_die(DIE_GPF, "general protection fault", regs,
17995 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17996 return;
17997 +
17998 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17999 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
18000 + die("PAX: suspicious general protection fault", regs, error_code);
18001 + else
18002 +#endif
18003 +
18004 die("general protection fault", regs, error_code);
18005 }
18006
18007 @@ -569,7 +598,7 @@ dotraplinkage void __kprobes do_debug(st
18008 /* It's safe to allow irq's after DR6 has been saved */
18009 preempt_conditional_sti(regs);
18010
18011 - if (regs->flags & X86_VM_MASK) {
18012 + if (v8086_mode(regs)) {
18013 handle_vm86_trap((struct kernel_vm86_regs *) regs,
18014 error_code, 1);
18015 preempt_conditional_cli(regs);
18016 @@ -583,7 +612,7 @@ dotraplinkage void __kprobes do_debug(st
18017 * We already checked v86 mode above, so we can check for kernel mode
18018 * by just checking the CPL of CS.
18019 */
18020 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
18021 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
18022 tsk->thread.debugreg6 &= ~DR_STEP;
18023 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
18024 regs->flags &= ~X86_EFLAGS_TF;
18025 @@ -612,7 +641,7 @@ void math_error(struct pt_regs *regs, in
18026 return;
18027 conditional_sti(regs);
18028
18029 - if (!user_mode_vm(regs))
18030 + if (!user_mode(regs))
18031 {
18032 if (!fixup_exception(regs)) {
18033 task->thread.error_code = error_code;
18034 @@ -723,7 +752,7 @@ asmlinkage void __attribute__((weak)) sm
18035 void __math_state_restore(void)
18036 {
18037 struct thread_info *thread = current_thread_info();
18038 - struct task_struct *tsk = thread->task;
18039 + struct task_struct *tsk = current;
18040
18041 /*
18042 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
18043 @@ -750,8 +779,7 @@ void __math_state_restore(void)
18044 */
18045 asmlinkage void math_state_restore(void)
18046 {
18047 - struct thread_info *thread = current_thread_info();
18048 - struct task_struct *tsk = thread->task;
18049 + struct task_struct *tsk = current;
18050
18051 if (!tsk_used_math(tsk)) {
18052 local_irq_enable();
18053 diff -urNp linux-2.6.39.2/arch/x86/kernel/vm86_32.c linux-2.6.39.2/arch/x86/kernel/vm86_32.c
18054 --- linux-2.6.39.2/arch/x86/kernel/vm86_32.c 2011-05-19 00:06:34.000000000 -0400
18055 +++ linux-2.6.39.2/arch/x86/kernel/vm86_32.c 2011-05-22 19:41:32.000000000 -0400
18056 @@ -41,6 +41,7 @@
18057 #include <linux/ptrace.h>
18058 #include <linux/audit.h>
18059 #include <linux/stddef.h>
18060 +#include <linux/grsecurity.h>
18061
18062 #include <asm/uaccess.h>
18063 #include <asm/io.h>
18064 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct ke
18065 do_exit(SIGSEGV);
18066 }
18067
18068 - tss = &per_cpu(init_tss, get_cpu());
18069 + tss = init_tss + get_cpu();
18070 current->thread.sp0 = current->thread.saved_sp0;
18071 current->thread.sysenter_cs = __KERNEL_CS;
18072 load_sp0(tss, &current->thread);
18073 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __use
18074 struct task_struct *tsk;
18075 int tmp, ret = -EPERM;
18076
18077 +#ifdef CONFIG_GRKERNSEC_VM86
18078 + if (!capable(CAP_SYS_RAWIO)) {
18079 + gr_handle_vm86();
18080 + goto out;
18081 + }
18082 +#endif
18083 +
18084 tsk = current;
18085 if (tsk->thread.saved_sp0)
18086 goto out;
18087 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned
18088 int tmp, ret;
18089 struct vm86plus_struct __user *v86;
18090
18091 +#ifdef CONFIG_GRKERNSEC_VM86
18092 + if (!capable(CAP_SYS_RAWIO)) {
18093 + gr_handle_vm86();
18094 + ret = -EPERM;
18095 + goto out;
18096 + }
18097 +#endif
18098 +
18099 tsk = current;
18100 switch (cmd) {
18101 case VM86_REQUEST_IRQ:
18102 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm
18103 tsk->thread.saved_fs = info->regs32->fs;
18104 tsk->thread.saved_gs = get_user_gs(info->regs32);
18105
18106 - tss = &per_cpu(init_tss, get_cpu());
18107 + tss = init_tss + get_cpu();
18108 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
18109 if (cpu_has_sep)
18110 tsk->thread.sysenter_cs = 0;
18111 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_re
18112 goto cannot_handle;
18113 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
18114 goto cannot_handle;
18115 - intr_ptr = (unsigned long __user *) (i << 2);
18116 + intr_ptr = (__force unsigned long __user *) (i << 2);
18117 if (get_user(segoffs, intr_ptr))
18118 goto cannot_handle;
18119 if ((segoffs >> 16) == BIOSSEG)
18120 diff -urNp linux-2.6.39.2/arch/x86/kernel/vmlinux.lds.S linux-2.6.39.2/arch/x86/kernel/vmlinux.lds.S
18121 --- linux-2.6.39.2/arch/x86/kernel/vmlinux.lds.S 2011-05-19 00:06:34.000000000 -0400
18122 +++ linux-2.6.39.2/arch/x86/kernel/vmlinux.lds.S 2011-05-22 19:36:30.000000000 -0400
18123 @@ -26,6 +26,13 @@
18124 #include <asm/page_types.h>
18125 #include <asm/cache.h>
18126 #include <asm/boot.h>
18127 +#include <asm/segment.h>
18128 +
18129 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18130 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18131 +#else
18132 +#define __KERNEL_TEXT_OFFSET 0
18133 +#endif
18134
18135 #undef i386 /* in case the preprocessor is a 32bit one */
18136
18137 @@ -34,11 +41,9 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONF
18138 #ifdef CONFIG_X86_32
18139 OUTPUT_ARCH(i386)
18140 ENTRY(phys_startup_32)
18141 -jiffies = jiffies_64;
18142 #else
18143 OUTPUT_ARCH(i386:x86-64)
18144 ENTRY(phys_startup_64)
18145 -jiffies_64 = jiffies;
18146 #endif
18147
18148 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
18149 @@ -69,31 +74,46 @@ jiffies_64 = jiffies;
18150
18151 PHDRS {
18152 text PT_LOAD FLAGS(5); /* R_E */
18153 +#ifdef CONFIG_X86_32
18154 + module PT_LOAD FLAGS(5); /* R_E */
18155 +#endif
18156 +#ifdef CONFIG_XEN
18157 + rodata PT_LOAD FLAGS(5); /* R_E */
18158 +#else
18159 + rodata PT_LOAD FLAGS(4); /* R__ */
18160 +#endif
18161 data PT_LOAD FLAGS(6); /* RW_ */
18162 #ifdef CONFIG_X86_64
18163 user PT_LOAD FLAGS(5); /* R_E */
18164 +#endif
18165 + init.begin PT_LOAD FLAGS(6); /* RW_ */
18166 #ifdef CONFIG_SMP
18167 percpu PT_LOAD FLAGS(6); /* RW_ */
18168 #endif
18169 + text.init PT_LOAD FLAGS(5); /* R_E */
18170 + text.exit PT_LOAD FLAGS(5); /* R_E */
18171 init PT_LOAD FLAGS(7); /* RWE */
18172 -#endif
18173 note PT_NOTE FLAGS(0); /* ___ */
18174 }
18175
18176 SECTIONS
18177 {
18178 #ifdef CONFIG_X86_32
18179 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18180 - phys_startup_32 = startup_32 - LOAD_OFFSET;
18181 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18182 #else
18183 - . = __START_KERNEL;
18184 - phys_startup_64 = startup_64 - LOAD_OFFSET;
18185 + . = __START_KERNEL;
18186 #endif
18187
18188 /* Text and read-only data */
18189 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
18190 - _text = .;
18191 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18192 /* bootstrapping code */
18193 +#ifdef CONFIG_X86_32
18194 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18195 +#else
18196 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18197 +#endif
18198 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18199 + _text = .;
18200 HEAD_TEXT
18201 #ifdef CONFIG_X86_32
18202 . = ALIGN(PAGE_SIZE);
18203 @@ -109,13 +129,47 @@ SECTIONS
18204 IRQENTRY_TEXT
18205 *(.fixup)
18206 *(.gnu.warning)
18207 - /* End of text section */
18208 - _etext = .;
18209 } :text = 0x9090
18210
18211 - NOTES :text :note
18212 + . += __KERNEL_TEXT_OFFSET;
18213 +
18214 +#ifdef CONFIG_X86_32
18215 + . = ALIGN(PAGE_SIZE);
18216 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18217 +
18218 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18219 + MODULES_EXEC_VADDR = .;
18220 + BYTE(0)
18221 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18222 + . = ALIGN(HPAGE_SIZE);
18223 + MODULES_EXEC_END = . - 1;
18224 +#endif
18225 +
18226 + } :module
18227 +#endif
18228 +
18229 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18230 + /* End of text section */
18231 + _etext = . - __KERNEL_TEXT_OFFSET;
18232 + }
18233
18234 - EXCEPTION_TABLE(16) :text = 0x9090
18235 +#ifdef CONFIG_X86_32
18236 + . = ALIGN(PAGE_SIZE);
18237 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18238 + *(.idt)
18239 + . = ALIGN(PAGE_SIZE);
18240 + *(.empty_zero_page)
18241 + *(.initial_pg_fixmap)
18242 + *(.initial_pg_pmd)
18243 + *(.initial_page_table)
18244 + *(.swapper_pg_dir)
18245 + } :rodata
18246 +#endif
18247 +
18248 + . = ALIGN(PAGE_SIZE);
18249 + NOTES :rodata :note
18250 +
18251 + EXCEPTION_TABLE(16) :rodata
18252
18253 #if defined(CONFIG_DEBUG_RODATA)
18254 /* .text should occupy whole number of pages */
18255 @@ -127,16 +181,20 @@ SECTIONS
18256
18257 /* Data */
18258 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18259 +
18260 +#ifdef CONFIG_PAX_KERNEXEC
18261 + . = ALIGN(HPAGE_SIZE);
18262 +#else
18263 + . = ALIGN(PAGE_SIZE);
18264 +#endif
18265 +
18266 /* Start of data section */
18267 _sdata = .;
18268
18269 /* init_task */
18270 INIT_TASK_DATA(THREAD_SIZE)
18271
18272 -#ifdef CONFIG_X86_32
18273 - /* 32 bit has nosave before _edata */
18274 NOSAVE_DATA
18275 -#endif
18276
18277 PAGE_ALIGNED_DATA(PAGE_SIZE)
18278
18279 @@ -145,6 +203,8 @@ SECTIONS
18280 DATA_DATA
18281 CONSTRUCTORS
18282
18283 + jiffies = jiffies_64;
18284 +
18285 /* rarely changed data like cpu maps */
18286 READ_MOSTLY_DATA(INTERNODE_CACHE_BYTES)
18287
18288 @@ -199,12 +259,6 @@ SECTIONS
18289 }
18290 vgetcpu_mode = VVIRT(.vgetcpu_mode);
18291
18292 - . = ALIGN(L1_CACHE_BYTES);
18293 - .jiffies : AT(VLOAD(.jiffies)) {
18294 - *(.jiffies)
18295 - }
18296 - jiffies = VVIRT(.jiffies);
18297 -
18298 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
18299 *(.vsyscall_3)
18300 }
18301 @@ -220,12 +274,19 @@ SECTIONS
18302 #endif /* CONFIG_X86_64 */
18303
18304 /* Init code and data - will be freed after init */
18305 - . = ALIGN(PAGE_SIZE);
18306 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18307 + BYTE(0)
18308 +
18309 +#ifdef CONFIG_PAX_KERNEXEC
18310 + . = ALIGN(HPAGE_SIZE);
18311 +#else
18312 + . = ALIGN(PAGE_SIZE);
18313 +#endif
18314 +
18315 __init_begin = .; /* paired with __init_end */
18316 - }
18317 + } :init.begin
18318
18319 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18320 +#ifdef CONFIG_SMP
18321 /*
18322 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18323 * output PHDR, so the next output section - .init.text - should
18324 @@ -234,12 +295,27 @@ SECTIONS
18325 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18326 #endif
18327
18328 - INIT_TEXT_SECTION(PAGE_SIZE)
18329 -#ifdef CONFIG_X86_64
18330 - :init
18331 -#endif
18332 + . = ALIGN(PAGE_SIZE);
18333 + init_begin = .;
18334 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18335 + VMLINUX_SYMBOL(_sinittext) = .;
18336 + INIT_TEXT
18337 + VMLINUX_SYMBOL(_einittext) = .;
18338 + . = ALIGN(PAGE_SIZE);
18339 + } :text.init
18340
18341 - INIT_DATA_SECTION(16)
18342 + /*
18343 + * .exit.text is discard at runtime, not link time, to deal with
18344 + * references from .altinstructions and .eh_frame
18345 + */
18346 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18347 + EXIT_TEXT
18348 + . = ALIGN(16);
18349 + } :text.exit
18350 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18351 +
18352 + . = ALIGN(PAGE_SIZE);
18353 + INIT_DATA_SECTION(16) :init
18354
18355 /*
18356 * Code and data for a variety of lowlevel trampolines, to be
18357 @@ -306,19 +382,12 @@ SECTIONS
18358 }
18359
18360 . = ALIGN(8);
18361 - /*
18362 - * .exit.text is discard at runtime, not link time, to deal with
18363 - * references from .altinstructions and .eh_frame
18364 - */
18365 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18366 - EXIT_TEXT
18367 - }
18368
18369 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18370 EXIT_DATA
18371 }
18372
18373 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18374 +#ifndef CONFIG_SMP
18375 PERCPU(INTERNODE_CACHE_BYTES, PAGE_SIZE)
18376 #endif
18377
18378 @@ -337,16 +406,10 @@ SECTIONS
18379 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18380 __smp_locks = .;
18381 *(.smp_locks)
18382 - . = ALIGN(PAGE_SIZE);
18383 __smp_locks_end = .;
18384 + . = ALIGN(PAGE_SIZE);
18385 }
18386
18387 -#ifdef CONFIG_X86_64
18388 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18389 - NOSAVE_DATA
18390 - }
18391 -#endif
18392 -
18393 /* BSS */
18394 . = ALIGN(PAGE_SIZE);
18395 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18396 @@ -362,6 +425,7 @@ SECTIONS
18397 __brk_base = .;
18398 . += 64 * 1024; /* 64k alignment slop space */
18399 *(.brk_reservation) /* areas brk users have reserved */
18400 + . = ALIGN(HPAGE_SIZE);
18401 __brk_limit = .;
18402 }
18403
18404 @@ -388,13 +452,12 @@ SECTIONS
18405 * for the boot processor.
18406 */
18407 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18408 -INIT_PER_CPU(gdt_page);
18409 INIT_PER_CPU(irq_stack_union);
18410
18411 /*
18412 * Build-time check on the image size:
18413 */
18414 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18415 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18416 "kernel image bigger than KERNEL_IMAGE_SIZE");
18417
18418 #ifdef CONFIG_SMP
18419 diff -urNp linux-2.6.39.2/arch/x86/kernel/vsyscall_64.c linux-2.6.39.2/arch/x86/kernel/vsyscall_64.c
18420 --- linux-2.6.39.2/arch/x86/kernel/vsyscall_64.c 2011-05-19 00:06:34.000000000 -0400
18421 +++ linux-2.6.39.2/arch/x86/kernel/vsyscall_64.c 2011-05-22 19:36:30.000000000 -0400
18422 @@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wa
18423
18424 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
18425 /* copy vsyscall data */
18426 + strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
18427 vsyscall_gtod_data.clock.vread = clock->vread;
18428 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
18429 vsyscall_gtod_data.clock.mask = clock->mask;
18430 @@ -208,7 +209,7 @@ vgetcpu(unsigned *cpu, unsigned *node, s
18431 We do this here because otherwise user space would do it on
18432 its own in a likely inferior way (no access to jiffies).
18433 If you don't like it pass NULL. */
18434 - if (tcache && tcache->blob[0] == (j = __jiffies)) {
18435 + if (tcache && tcache->blob[0] == (j = jiffies)) {
18436 p = tcache->blob[1];
18437 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
18438 /* Load per CPU data from RDTSCP */
18439 diff -urNp linux-2.6.39.2/arch/x86/kernel/x8664_ksyms_64.c linux-2.6.39.2/arch/x86/kernel/x8664_ksyms_64.c
18440 --- linux-2.6.39.2/arch/x86/kernel/x8664_ksyms_64.c 2011-05-19 00:06:34.000000000 -0400
18441 +++ linux-2.6.39.2/arch/x86/kernel/x8664_ksyms_64.c 2011-05-22 19:36:30.000000000 -0400
18442 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18443 EXPORT_SYMBOL(copy_user_generic_string);
18444 EXPORT_SYMBOL(copy_user_generic_unrolled);
18445 EXPORT_SYMBOL(__copy_user_nocache);
18446 -EXPORT_SYMBOL(_copy_from_user);
18447 -EXPORT_SYMBOL(_copy_to_user);
18448
18449 EXPORT_SYMBOL(copy_page);
18450 EXPORT_SYMBOL(clear_page);
18451 diff -urNp linux-2.6.39.2/arch/x86/kernel/xsave.c linux-2.6.39.2/arch/x86/kernel/xsave.c
18452 --- linux-2.6.39.2/arch/x86/kernel/xsave.c 2011-05-19 00:06:34.000000000 -0400
18453 +++ linux-2.6.39.2/arch/x86/kernel/xsave.c 2011-05-22 19:36:30.000000000 -0400
18454 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_
18455 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18456 return -EINVAL;
18457
18458 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18459 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18460 fx_sw_user->extended_size -
18461 FP_XSTATE_MAGIC2_SIZE));
18462 if (err)
18463 @@ -267,7 +267,7 @@ fx_only:
18464 * the other extended state.
18465 */
18466 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18467 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18468 + return fxrstor_checking((struct i387_fxsave_struct __user *)buf);
18469 }
18470
18471 /*
18472 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf
18473 if (use_xsave())
18474 err = restore_user_xstate(buf);
18475 else
18476 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18477 + err = fxrstor_checking((struct i387_fxsave_struct __user *)
18478 buf);
18479 if (unlikely(err)) {
18480 /*
18481 diff -urNp linux-2.6.39.2/arch/x86/kvm/emulate.c linux-2.6.39.2/arch/x86/kvm/emulate.c
18482 --- linux-2.6.39.2/arch/x86/kvm/emulate.c 2011-05-19 00:06:34.000000000 -0400
18483 +++ linux-2.6.39.2/arch/x86/kvm/emulate.c 2011-05-22 19:36:30.000000000 -0400
18484 @@ -89,7 +89,7 @@
18485 #define Src2ImmByte (2<<29)
18486 #define Src2One (3<<29)
18487 #define Src2Imm (4<<29)
18488 -#define Src2Mask (7<<29)
18489 +#define Src2Mask (7U<<29)
18490
18491 #define X2(x...) x, x
18492 #define X3(x...) X2(x), x
18493 @@ -190,6 +190,7 @@ struct group_dual {
18494
18495 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix, _dsttype) \
18496 do { \
18497 + unsigned long _tmp; \
18498 __asm__ __volatile__ ( \
18499 _PRE_EFLAGS("0", "4", "2") \
18500 _op _suffix " %"_x"3,%1; " \
18501 @@ -203,8 +204,6 @@ struct group_dual {
18502 /* Raw emulation: instruction has two explicit operands. */
18503 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
18504 do { \
18505 - unsigned long _tmp; \
18506 - \
18507 switch ((_dst).bytes) { \
18508 case 2: \
18509 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w",u16);\
18510 @@ -220,7 +219,6 @@ struct group_dual {
18511
18512 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18513 do { \
18514 - unsigned long _tmp; \
18515 switch ((_dst).bytes) { \
18516 case 1: \
18517 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b",u8); \
18518 diff -urNp linux-2.6.39.2/arch/x86/kvm/lapic.c linux-2.6.39.2/arch/x86/kvm/lapic.c
18519 --- linux-2.6.39.2/arch/x86/kvm/lapic.c 2011-05-19 00:06:34.000000000 -0400
18520 +++ linux-2.6.39.2/arch/x86/kvm/lapic.c 2011-05-22 19:36:30.000000000 -0400
18521 @@ -53,7 +53,7 @@
18522 #define APIC_BUS_CYCLE_NS 1
18523
18524 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18525 -#define apic_debug(fmt, arg...)
18526 +#define apic_debug(fmt, arg...) do {} while (0)
18527
18528 #define APIC_LVT_NUM 6
18529 /* 14 is the version for Xeon and Pentium 8.4.8*/
18530 diff -urNp linux-2.6.39.2/arch/x86/kvm/mmu.c linux-2.6.39.2/arch/x86/kvm/mmu.c
18531 --- linux-2.6.39.2/arch/x86/kvm/mmu.c 2011-05-19 00:06:34.000000000 -0400
18532 +++ linux-2.6.39.2/arch/x86/kvm/mmu.c 2011-05-22 19:36:30.000000000 -0400
18533 @@ -3240,7 +3240,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18534
18535 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18536
18537 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18538 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18539
18540 /*
18541 * Assume that the pte write on a page table of the same type
18542 @@ -3275,7 +3275,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *
18543 smp_rmb();
18544
18545 spin_lock(&vcpu->kvm->mmu_lock);
18546 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18547 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18548 gentry = 0;
18549 kvm_mmu_free_some_pages(vcpu);
18550 ++vcpu->kvm->stat.mmu_pte_write;
18551 diff -urNp linux-2.6.39.2/arch/x86/kvm/paging_tmpl.h linux-2.6.39.2/arch/x86/kvm/paging_tmpl.h
18552 --- linux-2.6.39.2/arch/x86/kvm/paging_tmpl.h 2011-05-19 00:06:34.000000000 -0400
18553 +++ linux-2.6.39.2/arch/x86/kvm/paging_tmpl.h 2011-05-22 19:36:30.000000000 -0400
18554 @@ -552,6 +552,8 @@ static int FNAME(page_fault)(struct kvm_
18555 unsigned long mmu_seq;
18556 bool map_writable;
18557
18558 + pax_track_stack();
18559 +
18560 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
18561
18562 r = mmu_topup_memory_caches(vcpu);
18563 @@ -672,7 +674,7 @@ static void FNAME(invlpg)(struct kvm_vcp
18564 if (need_flush)
18565 kvm_flush_remote_tlbs(vcpu->kvm);
18566
18567 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18568 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18569
18570 spin_unlock(&vcpu->kvm->mmu_lock);
18571
18572 diff -urNp linux-2.6.39.2/arch/x86/kvm/svm.c linux-2.6.39.2/arch/x86/kvm/svm.c
18573 --- linux-2.6.39.2/arch/x86/kvm/svm.c 2011-05-19 00:06:34.000000000 -0400
18574 +++ linux-2.6.39.2/arch/x86/kvm/svm.c 2011-05-22 19:36:30.000000000 -0400
18575 @@ -3278,7 +3278,11 @@ static void reload_tss(struct kvm_vcpu *
18576 int cpu = raw_smp_processor_id();
18577
18578 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18579 +
18580 + pax_open_kernel();
18581 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18582 + pax_close_kernel();
18583 +
18584 load_TR_desc();
18585 }
18586
18587 @@ -3656,6 +3660,10 @@ static void svm_vcpu_run(struct kvm_vcpu
18588 #endif
18589 #endif
18590
18591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18592 + __set_fs(current_thread_info()->addr_limit);
18593 +#endif
18594 +
18595 reload_tss(vcpu);
18596
18597 local_irq_disable();
18598 @@ -3871,7 +3879,7 @@ static void svm_fpu_deactivate(struct kv
18599 update_cr0_intercept(svm);
18600 }
18601
18602 -static struct kvm_x86_ops svm_x86_ops = {
18603 +static const struct kvm_x86_ops svm_x86_ops = {
18604 .cpu_has_kvm_support = has_svm,
18605 .disabled_by_bios = is_disabled,
18606 .hardware_setup = svm_hardware_setup,
18607 diff -urNp linux-2.6.39.2/arch/x86/kvm/vmx.c linux-2.6.39.2/arch/x86/kvm/vmx.c
18608 --- linux-2.6.39.2/arch/x86/kvm/vmx.c 2011-05-19 00:06:34.000000000 -0400
18609 +++ linux-2.6.39.2/arch/x86/kvm/vmx.c 2011-05-22 19:36:30.000000000 -0400
18610 @@ -725,7 +725,11 @@ static void reload_tss(void)
18611 struct desc_struct *descs;
18612
18613 descs = (void *)gdt->address;
18614 +
18615 + pax_open_kernel();
18616 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18617 + pax_close_kernel();
18618 +
18619 load_TR_desc();
18620 }
18621
18622 @@ -1648,8 +1652,11 @@ static __init int hardware_setup(void)
18623 if (!cpu_has_vmx_flexpriority())
18624 flexpriority_enabled = 0;
18625
18626 - if (!cpu_has_vmx_tpr_shadow())
18627 - kvm_x86_ops->update_cr8_intercept = NULL;
18628 + if (!cpu_has_vmx_tpr_shadow()) {
18629 + pax_open_kernel();
18630 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18631 + pax_close_kernel();
18632 + }
18633
18634 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18635 kvm_disable_largepages();
18636 @@ -2693,7 +2700,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
18637 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18638
18639 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
18640 - vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
18641 + vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
18642 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
18643 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
18644 vmcs_write64(VM_EXIT_MSR_LOAD_ADDR, __pa(vmx->msr_autoload.host));
18645 @@ -4068,6 +4075,12 @@ static void __noclone vmx_vcpu_run(struc
18646 "jmp .Lkvm_vmx_return \n\t"
18647 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18648 ".Lkvm_vmx_return: "
18649 +
18650 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18651 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18652 + ".Lkvm_vmx_return2: "
18653 +#endif
18654 +
18655 /* Save guest registers, load host registers, keep flags */
18656 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18657 "pop %0 \n\t"
18658 @@ -4116,6 +4129,11 @@ static void __noclone vmx_vcpu_run(struc
18659 #endif
18660 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18661 [wordsize]"i"(sizeof(ulong))
18662 +
18663 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18664 + ,[cs]"i"(__KERNEL_CS)
18665 +#endif
18666 +
18667 : "cc", "memory"
18668 , R"ax", R"bx", R"di", R"si"
18669 #ifdef CONFIG_X86_64
18670 @@ -4130,7 +4148,16 @@ static void __noclone vmx_vcpu_run(struc
18671
18672 vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
18673
18674 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18675 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18676 +
18677 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18678 + loadsegment(fs, __KERNEL_PERCPU);
18679 +#endif
18680 +
18681 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18682 + __set_fs(current_thread_info()->addr_limit);
18683 +#endif
18684 +
18685 vmx->launched = 1;
18686
18687 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18688 @@ -4368,7 +4395,7 @@ static void vmx_set_supported_cpuid(u32
18689 {
18690 }
18691
18692 -static struct kvm_x86_ops vmx_x86_ops = {
18693 +static const struct kvm_x86_ops vmx_x86_ops = {
18694 .cpu_has_kvm_support = cpu_has_kvm_support,
18695 .disabled_by_bios = vmx_disabled_by_bios,
18696 .hardware_setup = hardware_setup,
18697 diff -urNp linux-2.6.39.2/arch/x86/kvm/x86.c linux-2.6.39.2/arch/x86/kvm/x86.c
18698 --- linux-2.6.39.2/arch/x86/kvm/x86.c 2011-05-19 00:06:34.000000000 -0400
18699 +++ linux-2.6.39.2/arch/x86/kvm/x86.c 2011-05-22 19:36:30.000000000 -0400
18700 @@ -94,7 +94,7 @@ static void update_cr8_intercept(struct
18701 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
18702 struct kvm_cpuid_entry2 __user *entries);
18703
18704 -struct kvm_x86_ops *kvm_x86_ops;
18705 +const struct kvm_x86_ops *kvm_x86_ops;
18706 EXPORT_SYMBOL_GPL(kvm_x86_ops);
18707
18708 int ignore_msrs = 0;
18709 @@ -2050,6 +2050,8 @@ long kvm_arch_dev_ioctl(struct file *fil
18710 if (n < msr_list.nmsrs)
18711 goto out;
18712 r = -EFAULT;
18713 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18714 + goto out;
18715 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18716 num_msrs_to_save * sizeof(u32)))
18717 goto out;
18718 @@ -2217,15 +2219,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(str
18719 struct kvm_cpuid2 *cpuid,
18720 struct kvm_cpuid_entry2 __user *entries)
18721 {
18722 - int r;
18723 + int r, i;
18724
18725 r = -E2BIG;
18726 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18727 goto out;
18728 r = -EFAULT;
18729 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18730 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18731 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18732 goto out;
18733 + for (i = 0; i < cpuid->nent; ++i) {
18734 + struct kvm_cpuid_entry2 cpuid_entry;
18735 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18736 + goto out;
18737 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18738 + }
18739 vcpu->arch.cpuid_nent = cpuid->nent;
18740 kvm_apic_set_version(vcpu);
18741 kvm_x86_ops->cpuid_update(vcpu);
18742 @@ -2240,15 +2247,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(str
18743 struct kvm_cpuid2 *cpuid,
18744 struct kvm_cpuid_entry2 __user *entries)
18745 {
18746 - int r;
18747 + int r, i;
18748
18749 r = -E2BIG;
18750 if (cpuid->nent < vcpu->arch.cpuid_nent)
18751 goto out;
18752 r = -EFAULT;
18753 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18754 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18755 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18756 goto out;
18757 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18758 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18759 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18760 + goto out;
18761 + }
18762 return 0;
18763
18764 out:
18765 @@ -2526,7 +2537,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
18766 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18767 struct kvm_interrupt *irq)
18768 {
18769 - if (irq->irq < 0 || irq->irq >= 256)
18770 + if (irq->irq >= 256)
18771 return -EINVAL;
18772 if (irqchip_in_kernel(vcpu->kvm))
18773 return -ENXIO;
18774 @@ -4672,7 +4683,7 @@ static unsigned long kvm_get_guest_ip(vo
18775 return ip;
18776 }
18777
18778 -static struct perf_guest_info_callbacks kvm_guest_cbs = {
18779 +static const struct perf_guest_info_callbacks kvm_guest_cbs = {
18780 .is_in_guest = kvm_is_in_guest,
18781 .is_user_mode = kvm_is_user_mode,
18782 .get_guest_ip = kvm_get_guest_ip,
18783 @@ -4690,10 +4701,10 @@ void kvm_after_handle_nmi(struct kvm_vcp
18784 }
18785 EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
18786
18787 -int kvm_arch_init(void *opaque)
18788 +int kvm_arch_init(const void *opaque)
18789 {
18790 int r;
18791 - struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18792 + const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
18793
18794 if (kvm_x86_ops) {
18795 printk(KERN_ERR "kvm: already loaded the other module\n");
18796 diff -urNp linux-2.6.39.2/arch/x86/lib/atomic64_32.c linux-2.6.39.2/arch/x86/lib/atomic64_32.c
18797 --- linux-2.6.39.2/arch/x86/lib/atomic64_32.c 2011-05-19 00:06:34.000000000 -0400
18798 +++ linux-2.6.39.2/arch/x86/lib/atomic64_32.c 2011-05-22 19:36:30.000000000 -0400
18799 @@ -8,18 +8,30 @@
18800
18801 long long atomic64_read_cx8(long long, const atomic64_t *v);
18802 EXPORT_SYMBOL(atomic64_read_cx8);
18803 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18804 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18805 long long atomic64_set_cx8(long long, const atomic64_t *v);
18806 EXPORT_SYMBOL(atomic64_set_cx8);
18807 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18808 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18809 long long atomic64_xchg_cx8(long long, unsigned high);
18810 EXPORT_SYMBOL(atomic64_xchg_cx8);
18811 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18812 EXPORT_SYMBOL(atomic64_add_return_cx8);
18813 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18814 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18815 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18816 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18817 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18818 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18819 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18820 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18821 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18822 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18823 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18824 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18825 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18826 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18827 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18828 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18829 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18830 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18831 #ifndef CONFIG_X86_CMPXCHG64
18832 long long atomic64_read_386(long long, const atomic64_t *v);
18833 EXPORT_SYMBOL(atomic64_read_386);
18834 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18835 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18836 long long atomic64_set_386(long long, const atomic64_t *v);
18837 EXPORT_SYMBOL(atomic64_set_386);
18838 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18839 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18840 long long atomic64_xchg_386(long long, unsigned high);
18841 EXPORT_SYMBOL(atomic64_xchg_386);
18842 long long atomic64_add_return_386(long long a, atomic64_t *v);
18843 EXPORT_SYMBOL(atomic64_add_return_386);
18844 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18845 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18846 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18847 EXPORT_SYMBOL(atomic64_sub_return_386);
18848 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18849 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18850 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18851 EXPORT_SYMBOL(atomic64_inc_return_386);
18852 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18853 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18854 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18855 EXPORT_SYMBOL(atomic64_dec_return_386);
18856 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18857 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18858 long long atomic64_add_386(long long a, atomic64_t *v);
18859 EXPORT_SYMBOL(atomic64_add_386);
18860 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18861 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18862 long long atomic64_sub_386(long long a, atomic64_t *v);
18863 EXPORT_SYMBOL(atomic64_sub_386);
18864 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18865 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18866 long long atomic64_inc_386(long long a, atomic64_t *v);
18867 EXPORT_SYMBOL(atomic64_inc_386);
18868 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18869 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18870 long long atomic64_dec_386(long long a, atomic64_t *v);
18871 EXPORT_SYMBOL(atomic64_dec_386);
18872 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18873 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18874 long long atomic64_dec_if_positive_386(atomic64_t *v);
18875 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18876 int atomic64_inc_not_zero_386(atomic64_t *v);
18877 diff -urNp linux-2.6.39.2/arch/x86/lib/atomic64_386_32.S linux-2.6.39.2/arch/x86/lib/atomic64_386_32.S
18878 --- linux-2.6.39.2/arch/x86/lib/atomic64_386_32.S 2011-05-19 00:06:34.000000000 -0400
18879 +++ linux-2.6.39.2/arch/x86/lib/atomic64_386_32.S 2011-05-22 19:36:30.000000000 -0400
18880 @@ -48,6 +48,10 @@ BEGIN(read)
18881 movl (v), %eax
18882 movl 4(v), %edx
18883 RET_ENDP
18884 +BEGIN(read_unchecked)
18885 + movl (v), %eax
18886 + movl 4(v), %edx
18887 +RET_ENDP
18888 #undef v
18889
18890 #define v %esi
18891 @@ -55,6 +59,10 @@ BEGIN(set)
18892 movl %ebx, (v)
18893 movl %ecx, 4(v)
18894 RET_ENDP
18895 +BEGIN(set_unchecked)
18896 + movl %ebx, (v)
18897 + movl %ecx, 4(v)
18898 +RET_ENDP
18899 #undef v
18900
18901 #define v %esi
18902 @@ -70,6 +78,20 @@ RET_ENDP
18903 BEGIN(add)
18904 addl %eax, (v)
18905 adcl %edx, 4(v)
18906 +
18907 +#ifdef CONFIG_PAX_REFCOUNT
18908 + jno 0f
18909 + subl %eax, (v)
18910 + sbbl %edx, 4(v)
18911 + int $4
18912 +0:
18913 + _ASM_EXTABLE(0b, 0b)
18914 +#endif
18915 +
18916 +RET_ENDP
18917 +BEGIN(add_unchecked)
18918 + addl %eax, (v)
18919 + adcl %edx, 4(v)
18920 RET_ENDP
18921 #undef v
18922
18923 @@ -77,6 +99,24 @@ RET_ENDP
18924 BEGIN(add_return)
18925 addl (v), %eax
18926 adcl 4(v), %edx
18927 +
18928 +#ifdef CONFIG_PAX_REFCOUNT
18929 + into
18930 +1234:
18931 + _ASM_EXTABLE(1234b, 2f)
18932 +#endif
18933 +
18934 + movl %eax, (v)
18935 + movl %edx, 4(v)
18936 +
18937 +#ifdef CONFIG_PAX_REFCOUNT
18938 +2:
18939 +#endif
18940 +
18941 +RET_ENDP
18942 +BEGIN(add_return_unchecked)
18943 + addl (v), %eax
18944 + adcl 4(v), %edx
18945 movl %eax, (v)
18946 movl %edx, 4(v)
18947 RET_ENDP
18948 @@ -86,6 +126,20 @@ RET_ENDP
18949 BEGIN(sub)
18950 subl %eax, (v)
18951 sbbl %edx, 4(v)
18952 +
18953 +#ifdef CONFIG_PAX_REFCOUNT
18954 + jno 0f
18955 + addl %eax, (v)
18956 + adcl %edx, 4(v)
18957 + int $4
18958 +0:
18959 + _ASM_EXTABLE(0b, 0b)
18960 +#endif
18961 +
18962 +RET_ENDP
18963 +BEGIN(sub_unchecked)
18964 + subl %eax, (v)
18965 + sbbl %edx, 4(v)
18966 RET_ENDP
18967 #undef v
18968
18969 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18970 sbbl $0, %edx
18971 addl (v), %eax
18972 adcl 4(v), %edx
18973 +
18974 +#ifdef CONFIG_PAX_REFCOUNT
18975 + into
18976 +1234:
18977 + _ASM_EXTABLE(1234b, 2f)
18978 +#endif
18979 +
18980 + movl %eax, (v)
18981 + movl %edx, 4(v)
18982 +
18983 +#ifdef CONFIG_PAX_REFCOUNT
18984 +2:
18985 +#endif
18986 +
18987 +RET_ENDP
18988 +BEGIN(sub_return_unchecked)
18989 + negl %edx
18990 + negl %eax
18991 + sbbl $0, %edx
18992 + addl (v), %eax
18993 + adcl 4(v), %edx
18994 movl %eax, (v)
18995 movl %edx, 4(v)
18996 RET_ENDP
18997 @@ -105,6 +180,20 @@ RET_ENDP
18998 BEGIN(inc)
18999 addl $1, (v)
19000 adcl $0, 4(v)
19001 +
19002 +#ifdef CONFIG_PAX_REFCOUNT
19003 + jno 0f
19004 + subl $1, (v)
19005 + sbbl $0, 4(v)
19006 + int $4
19007 +0:
19008 + _ASM_EXTABLE(0b, 0b)
19009 +#endif
19010 +
19011 +RET_ENDP
19012 +BEGIN(inc_unchecked)
19013 + addl $1, (v)
19014 + adcl $0, 4(v)
19015 RET_ENDP
19016 #undef v
19017
19018 @@ -114,6 +203,26 @@ BEGIN(inc_return)
19019 movl 4(v), %edx
19020 addl $1, %eax
19021 adcl $0, %edx
19022 +
19023 +#ifdef CONFIG_PAX_REFCOUNT
19024 + into
19025 +1234:
19026 + _ASM_EXTABLE(1234b, 2f)
19027 +#endif
19028 +
19029 + movl %eax, (v)
19030 + movl %edx, 4(v)
19031 +
19032 +#ifdef CONFIG_PAX_REFCOUNT
19033 +2:
19034 +#endif
19035 +
19036 +RET_ENDP
19037 +BEGIN(inc_return_unchecked)
19038 + movl (v), %eax
19039 + movl 4(v), %edx
19040 + addl $1, %eax
19041 + adcl $0, %edx
19042 movl %eax, (v)
19043 movl %edx, 4(v)
19044 RET_ENDP
19045 @@ -123,6 +232,20 @@ RET_ENDP
19046 BEGIN(dec)
19047 subl $1, (v)
19048 sbbl $0, 4(v)
19049 +
19050 +#ifdef CONFIG_PAX_REFCOUNT
19051 + jno 0f
19052 + addl $1, (v)
19053 + adcl $0, 4(v)
19054 + int $4
19055 +0:
19056 + _ASM_EXTABLE(0b, 0b)
19057 +#endif
19058 +
19059 +RET_ENDP
19060 +BEGIN(dec_unchecked)
19061 + subl $1, (v)
19062 + sbbl $0, 4(v)
19063 RET_ENDP
19064 #undef v
19065
19066 @@ -132,6 +255,26 @@ BEGIN(dec_return)
19067 movl 4(v), %edx
19068 subl $1, %eax
19069 sbbl $0, %edx
19070 +
19071 +#ifdef CONFIG_PAX_REFCOUNT
19072 + into
19073 +1234:
19074 + _ASM_EXTABLE(1234b, 2f)
19075 +#endif
19076 +
19077 + movl %eax, (v)
19078 + movl %edx, 4(v)
19079 +
19080 +#ifdef CONFIG_PAX_REFCOUNT
19081 +2:
19082 +#endif
19083 +
19084 +RET_ENDP
19085 +BEGIN(dec_return_unchecked)
19086 + movl (v), %eax
19087 + movl 4(v), %edx
19088 + subl $1, %eax
19089 + sbbl $0, %edx
19090 movl %eax, (v)
19091 movl %edx, 4(v)
19092 RET_ENDP
19093 @@ -143,6 +286,13 @@ BEGIN(add_unless)
19094 adcl %edx, %edi
19095 addl (v), %eax
19096 adcl 4(v), %edx
19097 +
19098 +#ifdef CONFIG_PAX_REFCOUNT
19099 + into
19100 +1234:
19101 + _ASM_EXTABLE(1234b, 2f)
19102 +#endif
19103 +
19104 cmpl %eax, %esi
19105 je 3f
19106 1:
19107 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
19108 1:
19109 addl $1, %eax
19110 adcl $0, %edx
19111 +
19112 +#ifdef CONFIG_PAX_REFCOUNT
19113 + into
19114 +1234:
19115 + _ASM_EXTABLE(1234b, 2f)
19116 +#endif
19117 +
19118 movl %eax, (v)
19119 movl %edx, 4(v)
19120 movl $1, %eax
19121 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
19122 movl 4(v), %edx
19123 subl $1, %eax
19124 sbbl $0, %edx
19125 +
19126 +#ifdef CONFIG_PAX_REFCOUNT
19127 + into
19128 +1234:
19129 + _ASM_EXTABLE(1234b, 1f)
19130 +#endif
19131 +
19132 js 1f
19133 movl %eax, (v)
19134 movl %edx, 4(v)
19135 diff -urNp linux-2.6.39.2/arch/x86/lib/atomic64_cx8_32.S linux-2.6.39.2/arch/x86/lib/atomic64_cx8_32.S
19136 --- linux-2.6.39.2/arch/x86/lib/atomic64_cx8_32.S 2011-05-19 00:06:34.000000000 -0400
19137 +++ linux-2.6.39.2/arch/x86/lib/atomic64_cx8_32.S 2011-05-22 19:36:30.000000000 -0400
19138 @@ -39,6 +39,14 @@ ENTRY(atomic64_read_cx8)
19139 CFI_ENDPROC
19140 ENDPROC(atomic64_read_cx8)
19141
19142 +ENTRY(atomic64_read_unchecked_cx8)
19143 + CFI_STARTPROC
19144 +
19145 + read64 %ecx
19146 + ret
19147 + CFI_ENDPROC
19148 +ENDPROC(atomic64_read_unchecked_cx8)
19149 +
19150 ENTRY(atomic64_set_cx8)
19151 CFI_STARTPROC
19152
19153 @@ -52,6 +60,19 @@ ENTRY(atomic64_set_cx8)
19154 CFI_ENDPROC
19155 ENDPROC(atomic64_set_cx8)
19156
19157 +ENTRY(atomic64_set_unchecked_cx8)
19158 + CFI_STARTPROC
19159 +
19160 +1:
19161 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
19162 + * are atomic on 586 and newer */
19163 + cmpxchg8b (%esi)
19164 + jne 1b
19165 +
19166 + ret
19167 + CFI_ENDPROC
19168 +ENDPROC(atomic64_set_unchecked_cx8)
19169 +
19170 ENTRY(atomic64_xchg_cx8)
19171 CFI_STARTPROC
19172
19173 @@ -66,8 +87,8 @@ ENTRY(atomic64_xchg_cx8)
19174 CFI_ENDPROC
19175 ENDPROC(atomic64_xchg_cx8)
19176
19177 -.macro addsub_return func ins insc
19178 -ENTRY(atomic64_\func\()_return_cx8)
19179 +.macro addsub_return func ins insc unchecked=""
19180 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19181 CFI_STARTPROC
19182 SAVE ebp
19183 SAVE ebx
19184 @@ -84,27 +105,43 @@ ENTRY(atomic64_\func\()_return_cx8)
19185 movl %edx, %ecx
19186 \ins\()l %esi, %ebx
19187 \insc\()l %edi, %ecx
19188 +
19189 +.ifb \unchecked
19190 +#ifdef CONFIG_PAX_REFCOUNT
19191 + into
19192 +2:
19193 + _ASM_EXTABLE(2b, 3f)
19194 +#endif
19195 +.endif
19196 +
19197 LOCK_PREFIX
19198 cmpxchg8b (%ebp)
19199 jne 1b
19200 -
19201 -10:
19202 movl %ebx, %eax
19203 movl %ecx, %edx
19204 +
19205 +.ifb \unchecked
19206 +#ifdef CONFIG_PAX_REFCOUNT
19207 +3:
19208 +#endif
19209 +.endif
19210 +
19211 RESTORE edi
19212 RESTORE esi
19213 RESTORE ebx
19214 RESTORE ebp
19215 ret
19216 CFI_ENDPROC
19217 -ENDPROC(atomic64_\func\()_return_cx8)
19218 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19219 .endm
19220
19221 addsub_return add add adc
19222 addsub_return sub sub sbb
19223 +addsub_return add add adc _unchecked
19224 +addsub_return sub sub sbb _unchecked
19225
19226 -.macro incdec_return func ins insc
19227 -ENTRY(atomic64_\func\()_return_cx8)
19228 +.macro incdec_return func ins insc unchecked
19229 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19230 CFI_STARTPROC
19231 SAVE ebx
19232
19233 @@ -114,21 +151,38 @@ ENTRY(atomic64_\func\()_return_cx8)
19234 movl %edx, %ecx
19235 \ins\()l $1, %ebx
19236 \insc\()l $0, %ecx
19237 +
19238 +.ifb \unchecked
19239 +#ifdef CONFIG_PAX_REFCOUNT
19240 + into
19241 +2:
19242 + _ASM_EXTABLE(2b, 3f)
19243 +#endif
19244 +.endif
19245 +
19246 LOCK_PREFIX
19247 cmpxchg8b (%esi)
19248 jne 1b
19249
19250 -10:
19251 movl %ebx, %eax
19252 movl %ecx, %edx
19253 +
19254 +.ifb \unchecked
19255 +#ifdef CONFIG_PAX_REFCOUNT
19256 +3:
19257 +#endif
19258 +.endif
19259 +
19260 RESTORE ebx
19261 ret
19262 CFI_ENDPROC
19263 -ENDPROC(atomic64_\func\()_return_cx8)
19264 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19265 .endm
19266
19267 incdec_return inc add adc
19268 incdec_return dec sub sbb
19269 +incdec_return inc add adc _unchecked
19270 +incdec_return dec sub sbb _unchecked
19271
19272 ENTRY(atomic64_dec_if_positive_cx8)
19273 CFI_STARTPROC
19274 @@ -140,6 +194,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19275 movl %edx, %ecx
19276 subl $1, %ebx
19277 sbb $0, %ecx
19278 +
19279 +#ifdef CONFIG_PAX_REFCOUNT
19280 + into
19281 +1234:
19282 + _ASM_EXTABLE(1234b, 2f)
19283 +#endif
19284 +
19285 js 2f
19286 LOCK_PREFIX
19287 cmpxchg8b (%esi)
19288 @@ -174,6 +235,13 @@ ENTRY(atomic64_add_unless_cx8)
19289 movl %edx, %ecx
19290 addl %esi, %ebx
19291 adcl %edi, %ecx
19292 +
19293 +#ifdef CONFIG_PAX_REFCOUNT
19294 + into
19295 +1234:
19296 + _ASM_EXTABLE(1234b, 3f)
19297 +#endif
19298 +
19299 LOCK_PREFIX
19300 cmpxchg8b (%ebp)
19301 jne 1b
19302 @@ -206,6 +274,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19303 movl %edx, %ecx
19304 addl $1, %ebx
19305 adcl $0, %ecx
19306 +
19307 +#ifdef CONFIG_PAX_REFCOUNT
19308 + into
19309 +1234:
19310 + _ASM_EXTABLE(1234b, 3f)
19311 +#endif
19312 +
19313 LOCK_PREFIX
19314 cmpxchg8b (%esi)
19315 jne 1b
19316 diff -urNp linux-2.6.39.2/arch/x86/lib/checksum_32.S linux-2.6.39.2/arch/x86/lib/checksum_32.S
19317 --- linux-2.6.39.2/arch/x86/lib/checksum_32.S 2011-05-19 00:06:34.000000000 -0400
19318 +++ linux-2.6.39.2/arch/x86/lib/checksum_32.S 2011-05-22 19:36:30.000000000 -0400
19319 @@ -28,7 +28,8 @@
19320 #include <linux/linkage.h>
19321 #include <asm/dwarf2.h>
19322 #include <asm/errno.h>
19323 -
19324 +#include <asm/segment.h>
19325 +
19326 /*
19327 * computes a partial checksum, e.g. for TCP/UDP fragments
19328 */
19329 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (
19330
19331 #define ARGBASE 16
19332 #define FP 12
19333 -
19334 -ENTRY(csum_partial_copy_generic)
19335 +
19336 +ENTRY(csum_partial_copy_generic_to_user)
19337 CFI_STARTPROC
19338 +
19339 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19340 + pushl_cfi %gs
19341 + popl_cfi %es
19342 + jmp csum_partial_copy_generic
19343 +#endif
19344 +
19345 +ENTRY(csum_partial_copy_generic_from_user)
19346 +
19347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19348 + pushl_cfi %gs
19349 + popl_cfi %ds
19350 +#endif
19351 +
19352 +ENTRY(csum_partial_copy_generic)
19353 subl $4,%esp
19354 CFI_ADJUST_CFA_OFFSET 4
19355 pushl_cfi %edi
19356 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19357 jmp 4f
19358 SRC(1: movw (%esi), %bx )
19359 addl $2, %esi
19360 -DST( movw %bx, (%edi) )
19361 +DST( movw %bx, %es:(%edi) )
19362 addl $2, %edi
19363 addw %bx, %ax
19364 adcl $0, %eax
19365 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19366 SRC(1: movl (%esi), %ebx )
19367 SRC( movl 4(%esi), %edx )
19368 adcl %ebx, %eax
19369 -DST( movl %ebx, (%edi) )
19370 +DST( movl %ebx, %es:(%edi) )
19371 adcl %edx, %eax
19372 -DST( movl %edx, 4(%edi) )
19373 +DST( movl %edx, %es:4(%edi) )
19374
19375 SRC( movl 8(%esi), %ebx )
19376 SRC( movl 12(%esi), %edx )
19377 adcl %ebx, %eax
19378 -DST( movl %ebx, 8(%edi) )
19379 +DST( movl %ebx, %es:8(%edi) )
19380 adcl %edx, %eax
19381 -DST( movl %edx, 12(%edi) )
19382 +DST( movl %edx, %es:12(%edi) )
19383
19384 SRC( movl 16(%esi), %ebx )
19385 SRC( movl 20(%esi), %edx )
19386 adcl %ebx, %eax
19387 -DST( movl %ebx, 16(%edi) )
19388 +DST( movl %ebx, %es:16(%edi) )
19389 adcl %edx, %eax
19390 -DST( movl %edx, 20(%edi) )
19391 +DST( movl %edx, %es:20(%edi) )
19392
19393 SRC( movl 24(%esi), %ebx )
19394 SRC( movl 28(%esi), %edx )
19395 adcl %ebx, %eax
19396 -DST( movl %ebx, 24(%edi) )
19397 +DST( movl %ebx, %es:24(%edi) )
19398 adcl %edx, %eax
19399 -DST( movl %edx, 28(%edi) )
19400 +DST( movl %edx, %es:28(%edi) )
19401
19402 lea 32(%esi), %esi
19403 lea 32(%edi), %edi
19404 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19405 shrl $2, %edx # This clears CF
19406 SRC(3: movl (%esi), %ebx )
19407 adcl %ebx, %eax
19408 -DST( movl %ebx, (%edi) )
19409 +DST( movl %ebx, %es:(%edi) )
19410 lea 4(%esi), %esi
19411 lea 4(%edi), %edi
19412 dec %edx
19413 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19414 jb 5f
19415 SRC( movw (%esi), %cx )
19416 leal 2(%esi), %esi
19417 -DST( movw %cx, (%edi) )
19418 +DST( movw %cx, %es:(%edi) )
19419 leal 2(%edi), %edi
19420 je 6f
19421 shll $16,%ecx
19422 SRC(5: movb (%esi), %cl )
19423 -DST( movb %cl, (%edi) )
19424 +DST( movb %cl, %es:(%edi) )
19425 6: addl %ecx, %eax
19426 adcl $0, %eax
19427 7:
19428 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19429
19430 6001:
19431 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19432 - movl $-EFAULT, (%ebx)
19433 + movl $-EFAULT, %ss:(%ebx)
19434
19435 # zero the complete destination - computing the rest
19436 # is too much work
19437 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19438
19439 6002:
19440 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19441 - movl $-EFAULT,(%ebx)
19442 + movl $-EFAULT,%ss:(%ebx)
19443 jmp 5000b
19444
19445 .previous
19446
19447 + pushl_cfi %ss
19448 + popl_cfi %ds
19449 + pushl_cfi %ss
19450 + popl_cfi %es
19451 popl_cfi %ebx
19452 CFI_RESTORE ebx
19453 popl_cfi %esi
19454 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19455 popl_cfi %ecx # equivalent to addl $4,%esp
19456 ret
19457 CFI_ENDPROC
19458 -ENDPROC(csum_partial_copy_generic)
19459 +ENDPROC(csum_partial_copy_generic_to_user)
19460
19461 #else
19462
19463 /* Version for PentiumII/PPro */
19464
19465 #define ROUND1(x) \
19466 + nop; nop; nop; \
19467 SRC(movl x(%esi), %ebx ) ; \
19468 addl %ebx, %eax ; \
19469 - DST(movl %ebx, x(%edi) ) ;
19470 + DST(movl %ebx, %es:x(%edi)) ;
19471
19472 #define ROUND(x) \
19473 + nop; nop; nop; \
19474 SRC(movl x(%esi), %ebx ) ; \
19475 adcl %ebx, %eax ; \
19476 - DST(movl %ebx, x(%edi) ) ;
19477 + DST(movl %ebx, %es:x(%edi)) ;
19478
19479 #define ARGBASE 12
19480 -
19481 -ENTRY(csum_partial_copy_generic)
19482 +
19483 +ENTRY(csum_partial_copy_generic_to_user)
19484 CFI_STARTPROC
19485 +
19486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19487 + pushl_cfi %gs
19488 + popl_cfi %es
19489 + jmp csum_partial_copy_generic
19490 +#endif
19491 +
19492 +ENTRY(csum_partial_copy_generic_from_user)
19493 +
19494 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19495 + pushl_cfi %gs
19496 + popl_cfi %ds
19497 +#endif
19498 +
19499 +ENTRY(csum_partial_copy_generic)
19500 pushl_cfi %ebx
19501 CFI_REL_OFFSET ebx, 0
19502 pushl_cfi %edi
19503 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19504 subl %ebx, %edi
19505 lea -1(%esi),%edx
19506 andl $-32,%edx
19507 - lea 3f(%ebx,%ebx), %ebx
19508 + lea 3f(%ebx,%ebx,2), %ebx
19509 testl %esi, %esi
19510 jmp *%ebx
19511 1: addl $64,%esi
19512 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19513 jb 5f
19514 SRC( movw (%esi), %dx )
19515 leal 2(%esi), %esi
19516 -DST( movw %dx, (%edi) )
19517 +DST( movw %dx, %es:(%edi) )
19518 leal 2(%edi), %edi
19519 je 6f
19520 shll $16,%edx
19521 5:
19522 SRC( movb (%esi), %dl )
19523 -DST( movb %dl, (%edi) )
19524 +DST( movb %dl, %es:(%edi) )
19525 6: addl %edx, %eax
19526 adcl $0, %eax
19527 7:
19528 .section .fixup, "ax"
19529 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19530 - movl $-EFAULT, (%ebx)
19531 + movl $-EFAULT, %ss:(%ebx)
19532 # zero the complete destination (computing the rest is too much work)
19533 movl ARGBASE+8(%esp),%edi # dst
19534 movl ARGBASE+12(%esp),%ecx # len
19535 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19536 rep; stosb
19537 jmp 7b
19538 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19539 - movl $-EFAULT, (%ebx)
19540 + movl $-EFAULT, %ss:(%ebx)
19541 jmp 7b
19542 .previous
19543
19544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19545 + pushl_cfi %ss
19546 + popl_cfi %ds
19547 + pushl_cfi %ss
19548 + popl_cfi %es
19549 +#endif
19550 +
19551 popl_cfi %esi
19552 CFI_RESTORE esi
19553 popl_cfi %edi
19554 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19555 CFI_RESTORE ebx
19556 ret
19557 CFI_ENDPROC
19558 -ENDPROC(csum_partial_copy_generic)
19559 +ENDPROC(csum_partial_copy_generic_to_user)
19560
19561 #undef ROUND
19562 #undef ROUND1
19563 diff -urNp linux-2.6.39.2/arch/x86/lib/clear_page_64.S linux-2.6.39.2/arch/x86/lib/clear_page_64.S
19564 --- linux-2.6.39.2/arch/x86/lib/clear_page_64.S 2011-05-19 00:06:34.000000000 -0400
19565 +++ linux-2.6.39.2/arch/x86/lib/clear_page_64.S 2011-05-22 19:36:30.000000000 -0400
19566 @@ -43,7 +43,7 @@ ENDPROC(clear_page)
19567
19568 #include <asm/cpufeature.h>
19569
19570 - .section .altinstr_replacement,"ax"
19571 + .section .altinstr_replacement,"a"
19572 1: .byte 0xeb /* jmp <disp8> */
19573 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19574 2:
19575 diff -urNp linux-2.6.39.2/arch/x86/lib/copy_page_64.S linux-2.6.39.2/arch/x86/lib/copy_page_64.S
19576 --- linux-2.6.39.2/arch/x86/lib/copy_page_64.S 2011-05-19 00:06:34.000000000 -0400
19577 +++ linux-2.6.39.2/arch/x86/lib/copy_page_64.S 2011-05-22 19:36:30.000000000 -0400
19578 @@ -104,7 +104,7 @@ ENDPROC(copy_page)
19579
19580 #include <asm/cpufeature.h>
19581
19582 - .section .altinstr_replacement,"ax"
19583 + .section .altinstr_replacement,"a"
19584 1: .byte 0xeb /* jmp <disp8> */
19585 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19586 2:
19587 diff -urNp linux-2.6.39.2/arch/x86/lib/copy_user_64.S linux-2.6.39.2/arch/x86/lib/copy_user_64.S
19588 --- linux-2.6.39.2/arch/x86/lib/copy_user_64.S 2011-06-03 00:04:13.000000000 -0400
19589 +++ linux-2.6.39.2/arch/x86/lib/copy_user_64.S 2011-06-03 00:32:05.000000000 -0400
19590 @@ -15,13 +15,14 @@
19591 #include <asm/asm-offsets.h>
19592 #include <asm/thread_info.h>
19593 #include <asm/cpufeature.h>
19594 +#include <asm/pgtable.h>
19595
19596 .macro ALTERNATIVE_JUMP feature,orig,alt
19597 0:
19598 .byte 0xe9 /* 32bit jump */
19599 .long \orig-1f /* by default jump to orig */
19600 1:
19601 - .section .altinstr_replacement,"ax"
19602 + .section .altinstr_replacement,"a"
19603 2: .byte 0xe9 /* near jump with 32bit immediate */
19604 .long \alt-1b /* offset */ /* or alternatively to alt */
19605 .previous
19606 @@ -64,37 +65,13 @@
19607 #endif
19608 .endm
19609
19610 -/* Standard copy_to_user with segment limit checking */
19611 -ENTRY(_copy_to_user)
19612 - CFI_STARTPROC
19613 - GET_THREAD_INFO(%rax)
19614 - movq %rdi,%rcx
19615 - addq %rdx,%rcx
19616 - jc bad_to_user
19617 - cmpq TI_addr_limit(%rax),%rcx
19618 - ja bad_to_user
19619 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19620 - CFI_ENDPROC
19621 -ENDPROC(_copy_to_user)
19622 -
19623 -/* Standard copy_from_user with segment limit checking */
19624 -ENTRY(_copy_from_user)
19625 - CFI_STARTPROC
19626 - GET_THREAD_INFO(%rax)
19627 - movq %rsi,%rcx
19628 - addq %rdx,%rcx
19629 - jc bad_from_user
19630 - cmpq TI_addr_limit(%rax),%rcx
19631 - ja bad_from_user
19632 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
19633 - CFI_ENDPROC
19634 -ENDPROC(_copy_from_user)
19635 -
19636 .section .fixup,"ax"
19637 /* must zero dest */
19638 ENTRY(bad_from_user)
19639 bad_from_user:
19640 CFI_STARTPROC
19641 + testl %edx,%edx
19642 + js bad_to_user
19643 movl %edx,%ecx
19644 xorl %eax,%eax
19645 rep
19646 diff -urNp linux-2.6.39.2/arch/x86/lib/copy_user_nocache_64.S linux-2.6.39.2/arch/x86/lib/copy_user_nocache_64.S
19647 --- linux-2.6.39.2/arch/x86/lib/copy_user_nocache_64.S 2011-05-19 00:06:34.000000000 -0400
19648 +++ linux-2.6.39.2/arch/x86/lib/copy_user_nocache_64.S 2011-05-22 19:36:30.000000000 -0400
19649 @@ -14,6 +14,7 @@
19650 #include <asm/current.h>
19651 #include <asm/asm-offsets.h>
19652 #include <asm/thread_info.h>
19653 +#include <asm/pgtable.h>
19654
19655 .macro ALIGN_DESTINATION
19656 #ifdef FIX_ALIGNMENT
19657 @@ -50,6 +51,15 @@
19658 */
19659 ENTRY(__copy_user_nocache)
19660 CFI_STARTPROC
19661 +
19662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19663 + mov $PAX_USER_SHADOW_BASE,%rcx
19664 + cmp %rcx,%rsi
19665 + jae 1f
19666 + add %rcx,%rsi
19667 +1:
19668 +#endif
19669 +
19670 cmpl $8,%edx
19671 jb 20f /* less then 8 bytes, go to byte copy loop */
19672 ALIGN_DESTINATION
19673 diff -urNp linux-2.6.39.2/arch/x86/lib/csum-wrappers_64.c linux-2.6.39.2/arch/x86/lib/csum-wrappers_64.c
19674 --- linux-2.6.39.2/arch/x86/lib/csum-wrappers_64.c 2011-05-19 00:06:34.000000000 -0400
19675 +++ linux-2.6.39.2/arch/x86/lib/csum-wrappers_64.c 2011-05-22 19:36:30.000000000 -0400
19676 @@ -52,6 +52,12 @@ csum_partial_copy_from_user(const void _
19677 len -= 2;
19678 }
19679 }
19680 +
19681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19682 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19683 + src += PAX_USER_SHADOW_BASE;
19684 +#endif
19685 +
19686 isum = csum_partial_copy_generic((__force const void *)src,
19687 dst, len, isum, errp, NULL);
19688 if (unlikely(*errp))
19689 @@ -105,6 +111,12 @@ csum_partial_copy_to_user(const void *sr
19690 }
19691
19692 *errp = 0;
19693 +
19694 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19695 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19696 + dst += PAX_USER_SHADOW_BASE;
19697 +#endif
19698 +
19699 return csum_partial_copy_generic(src, (void __force *)dst,
19700 len, isum, NULL, errp);
19701 }
19702 diff -urNp linux-2.6.39.2/arch/x86/lib/getuser.S linux-2.6.39.2/arch/x86/lib/getuser.S
19703 --- linux-2.6.39.2/arch/x86/lib/getuser.S 2011-05-19 00:06:34.000000000 -0400
19704 +++ linux-2.6.39.2/arch/x86/lib/getuser.S 2011-05-22 19:36:30.000000000 -0400
19705 @@ -33,14 +33,35 @@
19706 #include <asm/asm-offsets.h>
19707 #include <asm/thread_info.h>
19708 #include <asm/asm.h>
19709 +#include <asm/segment.h>
19710 +#include <asm/pgtable.h>
19711 +
19712 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19713 +#define __copyuser_seg gs;
19714 +#else
19715 +#define __copyuser_seg
19716 +#endif
19717
19718 .text
19719 ENTRY(__get_user_1)
19720 CFI_STARTPROC
19721 +
19722 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19723 GET_THREAD_INFO(%_ASM_DX)
19724 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19725 jae bad_get_user
19726 -1: movzb (%_ASM_AX),%edx
19727 +
19728 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19729 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19730 + cmp %_ASM_DX,%_ASM_AX
19731 + jae 1234f
19732 + add %_ASM_DX,%_ASM_AX
19733 +1234:
19734 +#endif
19735 +
19736 +#endif
19737 +
19738 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19739 xor %eax,%eax
19740 ret
19741 CFI_ENDPROC
19742 @@ -49,11 +70,24 @@ ENDPROC(__get_user_1)
19743 ENTRY(__get_user_2)
19744 CFI_STARTPROC
19745 add $1,%_ASM_AX
19746 +
19747 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19748 jc bad_get_user
19749 GET_THREAD_INFO(%_ASM_DX)
19750 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19751 jae bad_get_user
19752 -2: movzwl -1(%_ASM_AX),%edx
19753 +
19754 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19755 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19756 + cmp %_ASM_DX,%_ASM_AX
19757 + jae 1234f
19758 + add %_ASM_DX,%_ASM_AX
19759 +1234:
19760 +#endif
19761 +
19762 +#endif
19763 +
19764 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19765 xor %eax,%eax
19766 ret
19767 CFI_ENDPROC
19768 @@ -62,11 +96,24 @@ ENDPROC(__get_user_2)
19769 ENTRY(__get_user_4)
19770 CFI_STARTPROC
19771 add $3,%_ASM_AX
19772 +
19773 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19774 jc bad_get_user
19775 GET_THREAD_INFO(%_ASM_DX)
19776 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19777 jae bad_get_user
19778 -3: mov -3(%_ASM_AX),%edx
19779 +
19780 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19781 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19782 + cmp %_ASM_DX,%_ASM_AX
19783 + jae 1234f
19784 + add %_ASM_DX,%_ASM_AX
19785 +1234:
19786 +#endif
19787 +
19788 +#endif
19789 +
19790 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19791 xor %eax,%eax
19792 ret
19793 CFI_ENDPROC
19794 @@ -80,6 +127,15 @@ ENTRY(__get_user_8)
19795 GET_THREAD_INFO(%_ASM_DX)
19796 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19797 jae bad_get_user
19798 +
19799 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19800 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19801 + cmp %_ASM_DX,%_ASM_AX
19802 + jae 1234f
19803 + add %_ASM_DX,%_ASM_AX
19804 +1234:
19805 +#endif
19806 +
19807 4: movq -7(%_ASM_AX),%_ASM_DX
19808 xor %eax,%eax
19809 ret
19810 diff -urNp linux-2.6.39.2/arch/x86/lib/insn.c linux-2.6.39.2/arch/x86/lib/insn.c
19811 --- linux-2.6.39.2/arch/x86/lib/insn.c 2011-05-19 00:06:34.000000000 -0400
19812 +++ linux-2.6.39.2/arch/x86/lib/insn.c 2011-05-22 19:36:30.000000000 -0400
19813 @@ -21,6 +21,11 @@
19814 #include <linux/string.h>
19815 #include <asm/inat.h>
19816 #include <asm/insn.h>
19817 +#ifdef __KERNEL__
19818 +#include <asm/pgtable_types.h>
19819 +#else
19820 +#define ktla_ktva(addr) addr
19821 +#endif
19822
19823 #define get_next(t, insn) \
19824 ({t r; r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
19825 @@ -40,8 +45,8 @@
19826 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19827 {
19828 memset(insn, 0, sizeof(*insn));
19829 - insn->kaddr = kaddr;
19830 - insn->next_byte = kaddr;
19831 + insn->kaddr = ktla_ktva(kaddr);
19832 + insn->next_byte = ktla_ktva(kaddr);
19833 insn->x86_64 = x86_64 ? 1 : 0;
19834 insn->opnd_bytes = 4;
19835 if (x86_64)
19836 diff -urNp linux-2.6.39.2/arch/x86/lib/mmx_32.c linux-2.6.39.2/arch/x86/lib/mmx_32.c
19837 --- linux-2.6.39.2/arch/x86/lib/mmx_32.c 2011-05-19 00:06:34.000000000 -0400
19838 +++ linux-2.6.39.2/arch/x86/lib/mmx_32.c 2011-05-22 19:36:30.000000000 -0400
19839 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
19840 {
19841 void *p;
19842 int i;
19843 + unsigned long cr0;
19844
19845 if (unlikely(in_interrupt()))
19846 return __memcpy(to, from, len);
19847 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
19848 kernel_fpu_begin();
19849
19850 __asm__ __volatile__ (
19851 - "1: prefetch (%0)\n" /* This set is 28 bytes */
19852 - " prefetch 64(%0)\n"
19853 - " prefetch 128(%0)\n"
19854 - " prefetch 192(%0)\n"
19855 - " prefetch 256(%0)\n"
19856 + "1: prefetch (%1)\n" /* This set is 28 bytes */
19857 + " prefetch 64(%1)\n"
19858 + " prefetch 128(%1)\n"
19859 + " prefetch 192(%1)\n"
19860 + " prefetch 256(%1)\n"
19861 "2: \n"
19862 ".section .fixup, \"ax\"\n"
19863 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19864 + "3: \n"
19865 +
19866 +#ifdef CONFIG_PAX_KERNEXEC
19867 + " movl %%cr0, %0\n"
19868 + " movl %0, %%eax\n"
19869 + " andl $0xFFFEFFFF, %%eax\n"
19870 + " movl %%eax, %%cr0\n"
19871 +#endif
19872 +
19873 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19874 +
19875 +#ifdef CONFIG_PAX_KERNEXEC
19876 + " movl %0, %%cr0\n"
19877 +#endif
19878 +
19879 " jmp 2b\n"
19880 ".previous\n"
19881 _ASM_EXTABLE(1b, 3b)
19882 - : : "r" (from));
19883 + : "=&r" (cr0) : "r" (from) : "ax");
19884
19885 for ( ; i > 5; i--) {
19886 __asm__ __volatile__ (
19887 - "1: prefetch 320(%0)\n"
19888 - "2: movq (%0), %%mm0\n"
19889 - " movq 8(%0), %%mm1\n"
19890 - " movq 16(%0), %%mm2\n"
19891 - " movq 24(%0), %%mm3\n"
19892 - " movq %%mm0, (%1)\n"
19893 - " movq %%mm1, 8(%1)\n"
19894 - " movq %%mm2, 16(%1)\n"
19895 - " movq %%mm3, 24(%1)\n"
19896 - " movq 32(%0), %%mm0\n"
19897 - " movq 40(%0), %%mm1\n"
19898 - " movq 48(%0), %%mm2\n"
19899 - " movq 56(%0), %%mm3\n"
19900 - " movq %%mm0, 32(%1)\n"
19901 - " movq %%mm1, 40(%1)\n"
19902 - " movq %%mm2, 48(%1)\n"
19903 - " movq %%mm3, 56(%1)\n"
19904 + "1: prefetch 320(%1)\n"
19905 + "2: movq (%1), %%mm0\n"
19906 + " movq 8(%1), %%mm1\n"
19907 + " movq 16(%1), %%mm2\n"
19908 + " movq 24(%1), %%mm3\n"
19909 + " movq %%mm0, (%2)\n"
19910 + " movq %%mm1, 8(%2)\n"
19911 + " movq %%mm2, 16(%2)\n"
19912 + " movq %%mm3, 24(%2)\n"
19913 + " movq 32(%1), %%mm0\n"
19914 + " movq 40(%1), %%mm1\n"
19915 + " movq 48(%1), %%mm2\n"
19916 + " movq 56(%1), %%mm3\n"
19917 + " movq %%mm0, 32(%2)\n"
19918 + " movq %%mm1, 40(%2)\n"
19919 + " movq %%mm2, 48(%2)\n"
19920 + " movq %%mm3, 56(%2)\n"
19921 ".section .fixup, \"ax\"\n"
19922 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19923 + "3:\n"
19924 +
19925 +#ifdef CONFIG_PAX_KERNEXEC
19926 + " movl %%cr0, %0\n"
19927 + " movl %0, %%eax\n"
19928 + " andl $0xFFFEFFFF, %%eax\n"
19929 + " movl %%eax, %%cr0\n"
19930 +#endif
19931 +
19932 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
19933 +
19934 +#ifdef CONFIG_PAX_KERNEXEC
19935 + " movl %0, %%cr0\n"
19936 +#endif
19937 +
19938 " jmp 2b\n"
19939 ".previous\n"
19940 _ASM_EXTABLE(1b, 3b)
19941 - : : "r" (from), "r" (to) : "memory");
19942 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
19943
19944 from += 64;
19945 to += 64;
19946 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
19947 static void fast_copy_page(void *to, void *from)
19948 {
19949 int i;
19950 + unsigned long cr0;
19951
19952 kernel_fpu_begin();
19953
19954 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
19955 * but that is for later. -AV
19956 */
19957 __asm__ __volatile__(
19958 - "1: prefetch (%0)\n"
19959 - " prefetch 64(%0)\n"
19960 - " prefetch 128(%0)\n"
19961 - " prefetch 192(%0)\n"
19962 - " prefetch 256(%0)\n"
19963 + "1: prefetch (%1)\n"
19964 + " prefetch 64(%1)\n"
19965 + " prefetch 128(%1)\n"
19966 + " prefetch 192(%1)\n"
19967 + " prefetch 256(%1)\n"
19968 "2: \n"
19969 ".section .fixup, \"ax\"\n"
19970 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19971 + "3: \n"
19972 +
19973 +#ifdef CONFIG_PAX_KERNEXEC
19974 + " movl %%cr0, %0\n"
19975 + " movl %0, %%eax\n"
19976 + " andl $0xFFFEFFFF, %%eax\n"
19977 + " movl %%eax, %%cr0\n"
19978 +#endif
19979 +
19980 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
19981 +
19982 +#ifdef CONFIG_PAX_KERNEXEC
19983 + " movl %0, %%cr0\n"
19984 +#endif
19985 +
19986 " jmp 2b\n"
19987 ".previous\n"
19988 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
19989 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
19990
19991 for (i = 0; i < (4096-320)/64; i++) {
19992 __asm__ __volatile__ (
19993 - "1: prefetch 320(%0)\n"
19994 - "2: movq (%0), %%mm0\n"
19995 - " movntq %%mm0, (%1)\n"
19996 - " movq 8(%0), %%mm1\n"
19997 - " movntq %%mm1, 8(%1)\n"
19998 - " movq 16(%0), %%mm2\n"
19999 - " movntq %%mm2, 16(%1)\n"
20000 - " movq 24(%0), %%mm3\n"
20001 - " movntq %%mm3, 24(%1)\n"
20002 - " movq 32(%0), %%mm4\n"
20003 - " movntq %%mm4, 32(%1)\n"
20004 - " movq 40(%0), %%mm5\n"
20005 - " movntq %%mm5, 40(%1)\n"
20006 - " movq 48(%0), %%mm6\n"
20007 - " movntq %%mm6, 48(%1)\n"
20008 - " movq 56(%0), %%mm7\n"
20009 - " movntq %%mm7, 56(%1)\n"
20010 + "1: prefetch 320(%1)\n"
20011 + "2: movq (%1), %%mm0\n"
20012 + " movntq %%mm0, (%2)\n"
20013 + " movq 8(%1), %%mm1\n"
20014 + " movntq %%mm1, 8(%2)\n"
20015 + " movq 16(%1), %%mm2\n"
20016 + " movntq %%mm2, 16(%2)\n"
20017 + " movq 24(%1), %%mm3\n"
20018 + " movntq %%mm3, 24(%2)\n"
20019 + " movq 32(%1), %%mm4\n"
20020 + " movntq %%mm4, 32(%2)\n"
20021 + " movq 40(%1), %%mm5\n"
20022 + " movntq %%mm5, 40(%2)\n"
20023 + " movq 48(%1), %%mm6\n"
20024 + " movntq %%mm6, 48(%2)\n"
20025 + " movq 56(%1), %%mm7\n"
20026 + " movntq %%mm7, 56(%2)\n"
20027 ".section .fixup, \"ax\"\n"
20028 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20029 + "3:\n"
20030 +
20031 +#ifdef CONFIG_PAX_KERNEXEC
20032 + " movl %%cr0, %0\n"
20033 + " movl %0, %%eax\n"
20034 + " andl $0xFFFEFFFF, %%eax\n"
20035 + " movl %%eax, %%cr0\n"
20036 +#endif
20037 +
20038 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20039 +
20040 +#ifdef CONFIG_PAX_KERNEXEC
20041 + " movl %0, %%cr0\n"
20042 +#endif
20043 +
20044 " jmp 2b\n"
20045 ".previous\n"
20046 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20047 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20048
20049 from += 64;
20050 to += 64;
20051 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20052 static void fast_copy_page(void *to, void *from)
20053 {
20054 int i;
20055 + unsigned long cr0;
20056
20057 kernel_fpu_begin();
20058
20059 __asm__ __volatile__ (
20060 - "1: prefetch (%0)\n"
20061 - " prefetch 64(%0)\n"
20062 - " prefetch 128(%0)\n"
20063 - " prefetch 192(%0)\n"
20064 - " prefetch 256(%0)\n"
20065 + "1: prefetch (%1)\n"
20066 + " prefetch 64(%1)\n"
20067 + " prefetch 128(%1)\n"
20068 + " prefetch 192(%1)\n"
20069 + " prefetch 256(%1)\n"
20070 "2: \n"
20071 ".section .fixup, \"ax\"\n"
20072 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20073 + "3: \n"
20074 +
20075 +#ifdef CONFIG_PAX_KERNEXEC
20076 + " movl %%cr0, %0\n"
20077 + " movl %0, %%eax\n"
20078 + " andl $0xFFFEFFFF, %%eax\n"
20079 + " movl %%eax, %%cr0\n"
20080 +#endif
20081 +
20082 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20083 +
20084 +#ifdef CONFIG_PAX_KERNEXEC
20085 + " movl %0, %%cr0\n"
20086 +#endif
20087 +
20088 " jmp 2b\n"
20089 ".previous\n"
20090 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20091 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20092
20093 for (i = 0; i < 4096/64; i++) {
20094 __asm__ __volatile__ (
20095 - "1: prefetch 320(%0)\n"
20096 - "2: movq (%0), %%mm0\n"
20097 - " movq 8(%0), %%mm1\n"
20098 - " movq 16(%0), %%mm2\n"
20099 - " movq 24(%0), %%mm3\n"
20100 - " movq %%mm0, (%1)\n"
20101 - " movq %%mm1, 8(%1)\n"
20102 - " movq %%mm2, 16(%1)\n"
20103 - " movq %%mm3, 24(%1)\n"
20104 - " movq 32(%0), %%mm0\n"
20105 - " movq 40(%0), %%mm1\n"
20106 - " movq 48(%0), %%mm2\n"
20107 - " movq 56(%0), %%mm3\n"
20108 - " movq %%mm0, 32(%1)\n"
20109 - " movq %%mm1, 40(%1)\n"
20110 - " movq %%mm2, 48(%1)\n"
20111 - " movq %%mm3, 56(%1)\n"
20112 + "1: prefetch 320(%1)\n"
20113 + "2: movq (%1), %%mm0\n"
20114 + " movq 8(%1), %%mm1\n"
20115 + " movq 16(%1), %%mm2\n"
20116 + " movq 24(%1), %%mm3\n"
20117 + " movq %%mm0, (%2)\n"
20118 + " movq %%mm1, 8(%2)\n"
20119 + " movq %%mm2, 16(%2)\n"
20120 + " movq %%mm3, 24(%2)\n"
20121 + " movq 32(%1), %%mm0\n"
20122 + " movq 40(%1), %%mm1\n"
20123 + " movq 48(%1), %%mm2\n"
20124 + " movq 56(%1), %%mm3\n"
20125 + " movq %%mm0, 32(%2)\n"
20126 + " movq %%mm1, 40(%2)\n"
20127 + " movq %%mm2, 48(%2)\n"
20128 + " movq %%mm3, 56(%2)\n"
20129 ".section .fixup, \"ax\"\n"
20130 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20131 + "3:\n"
20132 +
20133 +#ifdef CONFIG_PAX_KERNEXEC
20134 + " movl %%cr0, %0\n"
20135 + " movl %0, %%eax\n"
20136 + " andl $0xFFFEFFFF, %%eax\n"
20137 + " movl %%eax, %%cr0\n"
20138 +#endif
20139 +
20140 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20141 +
20142 +#ifdef CONFIG_PAX_KERNEXEC
20143 + " movl %0, %%cr0\n"
20144 +#endif
20145 +
20146 " jmp 2b\n"
20147 ".previous\n"
20148 _ASM_EXTABLE(1b, 3b)
20149 - : : "r" (from), "r" (to) : "memory");
20150 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20151
20152 from += 64;
20153 to += 64;
20154 diff -urNp linux-2.6.39.2/arch/x86/lib/putuser.S linux-2.6.39.2/arch/x86/lib/putuser.S
20155 --- linux-2.6.39.2/arch/x86/lib/putuser.S 2011-05-19 00:06:34.000000000 -0400
20156 +++ linux-2.6.39.2/arch/x86/lib/putuser.S 2011-05-22 19:36:30.000000000 -0400
20157 @@ -15,7 +15,8 @@
20158 #include <asm/thread_info.h>
20159 #include <asm/errno.h>
20160 #include <asm/asm.h>
20161 -
20162 +#include <asm/segment.h>
20163 +#include <asm/pgtable.h>
20164
20165 /*
20166 * __put_user_X
20167 @@ -29,52 +30,119 @@
20168 * as they get called from within inline assembly.
20169 */
20170
20171 -#define ENTER CFI_STARTPROC ; \
20172 - GET_THREAD_INFO(%_ASM_BX)
20173 +#define ENTER CFI_STARTPROC
20174 #define EXIT ret ; \
20175 CFI_ENDPROC
20176
20177 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20178 +#define _DEST %_ASM_CX,%_ASM_BX
20179 +#else
20180 +#define _DEST %_ASM_CX
20181 +#endif
20182 +
20183 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20184 +#define __copyuser_seg gs;
20185 +#else
20186 +#define __copyuser_seg
20187 +#endif
20188 +
20189 .text
20190 ENTRY(__put_user_1)
20191 ENTER
20192 +
20193 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20194 + GET_THREAD_INFO(%_ASM_BX)
20195 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20196 jae bad_put_user
20197 -1: movb %al,(%_ASM_CX)
20198 +
20199 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20200 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20201 + cmp %_ASM_BX,%_ASM_CX
20202 + jb 1234f
20203 + xor %ebx,%ebx
20204 +1234:
20205 +#endif
20206 +
20207 +#endif
20208 +
20209 +1: __copyuser_seg movb %al,(_DEST)
20210 xor %eax,%eax
20211 EXIT
20212 ENDPROC(__put_user_1)
20213
20214 ENTRY(__put_user_2)
20215 ENTER
20216 +
20217 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20218 + GET_THREAD_INFO(%_ASM_BX)
20219 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20220 sub $1,%_ASM_BX
20221 cmp %_ASM_BX,%_ASM_CX
20222 jae bad_put_user
20223 -2: movw %ax,(%_ASM_CX)
20224 +
20225 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20226 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20227 + cmp %_ASM_BX,%_ASM_CX
20228 + jb 1234f
20229 + xor %ebx,%ebx
20230 +1234:
20231 +#endif
20232 +
20233 +#endif
20234 +
20235 +2: __copyuser_seg movw %ax,(_DEST)
20236 xor %eax,%eax
20237 EXIT
20238 ENDPROC(__put_user_2)
20239
20240 ENTRY(__put_user_4)
20241 ENTER
20242 +
20243 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20244 + GET_THREAD_INFO(%_ASM_BX)
20245 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20246 sub $3,%_ASM_BX
20247 cmp %_ASM_BX,%_ASM_CX
20248 jae bad_put_user
20249 -3: movl %eax,(%_ASM_CX)
20250 +
20251 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20252 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20253 + cmp %_ASM_BX,%_ASM_CX
20254 + jb 1234f
20255 + xor %ebx,%ebx
20256 +1234:
20257 +#endif
20258 +
20259 +#endif
20260 +
20261 +3: __copyuser_seg movl %eax,(_DEST)
20262 xor %eax,%eax
20263 EXIT
20264 ENDPROC(__put_user_4)
20265
20266 ENTRY(__put_user_8)
20267 ENTER
20268 +
20269 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20270 + GET_THREAD_INFO(%_ASM_BX)
20271 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20272 sub $7,%_ASM_BX
20273 cmp %_ASM_BX,%_ASM_CX
20274 jae bad_put_user
20275 -4: mov %_ASM_AX,(%_ASM_CX)
20276 +
20277 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20278 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20279 + cmp %_ASM_BX,%_ASM_CX
20280 + jb 1234f
20281 + xor %ebx,%ebx
20282 +1234:
20283 +#endif
20284 +
20285 +#endif
20286 +
20287 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20288 #ifdef CONFIG_X86_32
20289 -5: movl %edx,4(%_ASM_CX)
20290 +5: __copyuser_seg movl %edx,4(_DEST)
20291 #endif
20292 xor %eax,%eax
20293 EXIT
20294 diff -urNp linux-2.6.39.2/arch/x86/lib/usercopy_32.c linux-2.6.39.2/arch/x86/lib/usercopy_32.c
20295 --- linux-2.6.39.2/arch/x86/lib/usercopy_32.c 2011-05-19 00:06:34.000000000 -0400
20296 +++ linux-2.6.39.2/arch/x86/lib/usercopy_32.c 2011-05-22 19:36:30.000000000 -0400
20297 @@ -43,7 +43,7 @@ do { \
20298 __asm__ __volatile__( \
20299 " testl %1,%1\n" \
20300 " jz 2f\n" \
20301 - "0: lodsb\n" \
20302 + "0: "__copyuser_seg"lodsb\n" \
20303 " stosb\n" \
20304 " testb %%al,%%al\n" \
20305 " jz 1f\n" \
20306 @@ -128,10 +128,12 @@ do { \
20307 int __d0; \
20308 might_fault(); \
20309 __asm__ __volatile__( \
20310 + __COPYUSER_SET_ES \
20311 "0: rep; stosl\n" \
20312 " movl %2,%0\n" \
20313 "1: rep; stosb\n" \
20314 "2:\n" \
20315 + __COPYUSER_RESTORE_ES \
20316 ".section .fixup,\"ax\"\n" \
20317 "3: lea 0(%2,%0,4),%0\n" \
20318 " jmp 2b\n" \
20319 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s,
20320 might_fault();
20321
20322 __asm__ __volatile__(
20323 + __COPYUSER_SET_ES
20324 " testl %0, %0\n"
20325 " jz 3f\n"
20326 " andl %0,%%ecx\n"
20327 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s,
20328 " subl %%ecx,%0\n"
20329 " addl %0,%%eax\n"
20330 "1:\n"
20331 + __COPYUSER_RESTORE_ES
20332 ".section .fixup,\"ax\"\n"
20333 "2: xorl %%eax,%%eax\n"
20334 " jmp 1b\n"
20335 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20336
20337 #ifdef CONFIG_X86_INTEL_USERCOPY
20338 static unsigned long
20339 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20340 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20341 {
20342 int d0, d1;
20343 __asm__ __volatile__(
20344 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const
20345 " .align 2,0x90\n"
20346 "3: movl 0(%4), %%eax\n"
20347 "4: movl 4(%4), %%edx\n"
20348 - "5: movl %%eax, 0(%3)\n"
20349 - "6: movl %%edx, 4(%3)\n"
20350 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20351 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20352 "7: movl 8(%4), %%eax\n"
20353 "8: movl 12(%4),%%edx\n"
20354 - "9: movl %%eax, 8(%3)\n"
20355 - "10: movl %%edx, 12(%3)\n"
20356 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20357 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20358 "11: movl 16(%4), %%eax\n"
20359 "12: movl 20(%4), %%edx\n"
20360 - "13: movl %%eax, 16(%3)\n"
20361 - "14: movl %%edx, 20(%3)\n"
20362 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20363 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20364 "15: movl 24(%4), %%eax\n"
20365 "16: movl 28(%4), %%edx\n"
20366 - "17: movl %%eax, 24(%3)\n"
20367 - "18: movl %%edx, 28(%3)\n"
20368 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20369 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20370 "19: movl 32(%4), %%eax\n"
20371 "20: movl 36(%4), %%edx\n"
20372 - "21: movl %%eax, 32(%3)\n"
20373 - "22: movl %%edx, 36(%3)\n"
20374 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
20375 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
20376 "23: movl 40(%4), %%eax\n"
20377 "24: movl 44(%4), %%edx\n"
20378 - "25: movl %%eax, 40(%3)\n"
20379 - "26: movl %%edx, 44(%3)\n"
20380 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
20381 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
20382 "27: movl 48(%4), %%eax\n"
20383 "28: movl 52(%4), %%edx\n"
20384 - "29: movl %%eax, 48(%3)\n"
20385 - "30: movl %%edx, 52(%3)\n"
20386 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
20387 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
20388 "31: movl 56(%4), %%eax\n"
20389 "32: movl 60(%4), %%edx\n"
20390 - "33: movl %%eax, 56(%3)\n"
20391 - "34: movl %%edx, 60(%3)\n"
20392 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
20393 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
20394 " addl $-64, %0\n"
20395 " addl $64, %4\n"
20396 " addl $64, %3\n"
20397 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const
20398 " shrl $2, %0\n"
20399 " andl $3, %%eax\n"
20400 " cld\n"
20401 + __COPYUSER_SET_ES
20402 "99: rep; movsl\n"
20403 "36: movl %%eax, %0\n"
20404 "37: rep; movsb\n"
20405 "100:\n"
20406 + __COPYUSER_RESTORE_ES
20407 + ".section .fixup,\"ax\"\n"
20408 + "101: lea 0(%%eax,%0,4),%0\n"
20409 + " jmp 100b\n"
20410 + ".previous\n"
20411 + ".section __ex_table,\"a\"\n"
20412 + " .align 4\n"
20413 + " .long 1b,100b\n"
20414 + " .long 2b,100b\n"
20415 + " .long 3b,100b\n"
20416 + " .long 4b,100b\n"
20417 + " .long 5b,100b\n"
20418 + " .long 6b,100b\n"
20419 + " .long 7b,100b\n"
20420 + " .long 8b,100b\n"
20421 + " .long 9b,100b\n"
20422 + " .long 10b,100b\n"
20423 + " .long 11b,100b\n"
20424 + " .long 12b,100b\n"
20425 + " .long 13b,100b\n"
20426 + " .long 14b,100b\n"
20427 + " .long 15b,100b\n"
20428 + " .long 16b,100b\n"
20429 + " .long 17b,100b\n"
20430 + " .long 18b,100b\n"
20431 + " .long 19b,100b\n"
20432 + " .long 20b,100b\n"
20433 + " .long 21b,100b\n"
20434 + " .long 22b,100b\n"
20435 + " .long 23b,100b\n"
20436 + " .long 24b,100b\n"
20437 + " .long 25b,100b\n"
20438 + " .long 26b,100b\n"
20439 + " .long 27b,100b\n"
20440 + " .long 28b,100b\n"
20441 + " .long 29b,100b\n"
20442 + " .long 30b,100b\n"
20443 + " .long 31b,100b\n"
20444 + " .long 32b,100b\n"
20445 + " .long 33b,100b\n"
20446 + " .long 34b,100b\n"
20447 + " .long 35b,100b\n"
20448 + " .long 36b,100b\n"
20449 + " .long 37b,100b\n"
20450 + " .long 99b,101b\n"
20451 + ".previous"
20452 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
20453 + : "1"(to), "2"(from), "0"(size)
20454 + : "eax", "edx", "memory");
20455 + return size;
20456 +}
20457 +
20458 +static unsigned long
20459 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
20460 +{
20461 + int d0, d1;
20462 + __asm__ __volatile__(
20463 + " .align 2,0x90\n"
20464 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
20465 + " cmpl $67, %0\n"
20466 + " jbe 3f\n"
20467 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
20468 + " .align 2,0x90\n"
20469 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
20470 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
20471 + "5: movl %%eax, 0(%3)\n"
20472 + "6: movl %%edx, 4(%3)\n"
20473 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
20474 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
20475 + "9: movl %%eax, 8(%3)\n"
20476 + "10: movl %%edx, 12(%3)\n"
20477 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
20478 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
20479 + "13: movl %%eax, 16(%3)\n"
20480 + "14: movl %%edx, 20(%3)\n"
20481 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
20482 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
20483 + "17: movl %%eax, 24(%3)\n"
20484 + "18: movl %%edx, 28(%3)\n"
20485 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
20486 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
20487 + "21: movl %%eax, 32(%3)\n"
20488 + "22: movl %%edx, 36(%3)\n"
20489 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
20490 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
20491 + "25: movl %%eax, 40(%3)\n"
20492 + "26: movl %%edx, 44(%3)\n"
20493 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
20494 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
20495 + "29: movl %%eax, 48(%3)\n"
20496 + "30: movl %%edx, 52(%3)\n"
20497 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
20498 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
20499 + "33: movl %%eax, 56(%3)\n"
20500 + "34: movl %%edx, 60(%3)\n"
20501 + " addl $-64, %0\n"
20502 + " addl $64, %4\n"
20503 + " addl $64, %3\n"
20504 + " cmpl $63, %0\n"
20505 + " ja 1b\n"
20506 + "35: movl %0, %%eax\n"
20507 + " shrl $2, %0\n"
20508 + " andl $3, %%eax\n"
20509 + " cld\n"
20510 + "99: rep; "__copyuser_seg" movsl\n"
20511 + "36: movl %%eax, %0\n"
20512 + "37: rep; "__copyuser_seg" movsb\n"
20513 + "100:\n"
20514 ".section .fixup,\"ax\"\n"
20515 "101: lea 0(%%eax,%0,4),%0\n"
20516 " jmp 100b\n"
20517 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, cons
20518 int d0, d1;
20519 __asm__ __volatile__(
20520 " .align 2,0x90\n"
20521 - "0: movl 32(%4), %%eax\n"
20522 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20523 " cmpl $67, %0\n"
20524 " jbe 2f\n"
20525 - "1: movl 64(%4), %%eax\n"
20526 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20527 " .align 2,0x90\n"
20528 - "2: movl 0(%4), %%eax\n"
20529 - "21: movl 4(%4), %%edx\n"
20530 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20531 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20532 " movl %%eax, 0(%3)\n"
20533 " movl %%edx, 4(%3)\n"
20534 - "3: movl 8(%4), %%eax\n"
20535 - "31: movl 12(%4),%%edx\n"
20536 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20537 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20538 " movl %%eax, 8(%3)\n"
20539 " movl %%edx, 12(%3)\n"
20540 - "4: movl 16(%4), %%eax\n"
20541 - "41: movl 20(%4), %%edx\n"
20542 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20543 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20544 " movl %%eax, 16(%3)\n"
20545 " movl %%edx, 20(%3)\n"
20546 - "10: movl 24(%4), %%eax\n"
20547 - "51: movl 28(%4), %%edx\n"
20548 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20549 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20550 " movl %%eax, 24(%3)\n"
20551 " movl %%edx, 28(%3)\n"
20552 - "11: movl 32(%4), %%eax\n"
20553 - "61: movl 36(%4), %%edx\n"
20554 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20555 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20556 " movl %%eax, 32(%3)\n"
20557 " movl %%edx, 36(%3)\n"
20558 - "12: movl 40(%4), %%eax\n"
20559 - "71: movl 44(%4), %%edx\n"
20560 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20561 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20562 " movl %%eax, 40(%3)\n"
20563 " movl %%edx, 44(%3)\n"
20564 - "13: movl 48(%4), %%eax\n"
20565 - "81: movl 52(%4), %%edx\n"
20566 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20567 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20568 " movl %%eax, 48(%3)\n"
20569 " movl %%edx, 52(%3)\n"
20570 - "14: movl 56(%4), %%eax\n"
20571 - "91: movl 60(%4), %%edx\n"
20572 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20573 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20574 " movl %%eax, 56(%3)\n"
20575 " movl %%edx, 60(%3)\n"
20576 " addl $-64, %0\n"
20577 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, cons
20578 " shrl $2, %0\n"
20579 " andl $3, %%eax\n"
20580 " cld\n"
20581 - "6: rep; movsl\n"
20582 + "6: rep; "__copyuser_seg" movsl\n"
20583 " movl %%eax,%0\n"
20584 - "7: rep; movsb\n"
20585 + "7: rep; "__copyuser_seg" movsb\n"
20586 "8:\n"
20587 ".section .fixup,\"ax\"\n"
20588 "9: lea 0(%%eax,%0,4),%0\n"
20589 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing
20590
20591 __asm__ __volatile__(
20592 " .align 2,0x90\n"
20593 - "0: movl 32(%4), %%eax\n"
20594 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20595 " cmpl $67, %0\n"
20596 " jbe 2f\n"
20597 - "1: movl 64(%4), %%eax\n"
20598 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20599 " .align 2,0x90\n"
20600 - "2: movl 0(%4), %%eax\n"
20601 - "21: movl 4(%4), %%edx\n"
20602 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20603 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20604 " movnti %%eax, 0(%3)\n"
20605 " movnti %%edx, 4(%3)\n"
20606 - "3: movl 8(%4), %%eax\n"
20607 - "31: movl 12(%4),%%edx\n"
20608 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20609 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20610 " movnti %%eax, 8(%3)\n"
20611 " movnti %%edx, 12(%3)\n"
20612 - "4: movl 16(%4), %%eax\n"
20613 - "41: movl 20(%4), %%edx\n"
20614 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20615 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20616 " movnti %%eax, 16(%3)\n"
20617 " movnti %%edx, 20(%3)\n"
20618 - "10: movl 24(%4), %%eax\n"
20619 - "51: movl 28(%4), %%edx\n"
20620 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20621 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20622 " movnti %%eax, 24(%3)\n"
20623 " movnti %%edx, 28(%3)\n"
20624 - "11: movl 32(%4), %%eax\n"
20625 - "61: movl 36(%4), %%edx\n"
20626 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20627 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20628 " movnti %%eax, 32(%3)\n"
20629 " movnti %%edx, 36(%3)\n"
20630 - "12: movl 40(%4), %%eax\n"
20631 - "71: movl 44(%4), %%edx\n"
20632 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20633 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20634 " movnti %%eax, 40(%3)\n"
20635 " movnti %%edx, 44(%3)\n"
20636 - "13: movl 48(%4), %%eax\n"
20637 - "81: movl 52(%4), %%edx\n"
20638 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20639 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20640 " movnti %%eax, 48(%3)\n"
20641 " movnti %%edx, 52(%3)\n"
20642 - "14: movl 56(%4), %%eax\n"
20643 - "91: movl 60(%4), %%edx\n"
20644 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20645 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20646 " movnti %%eax, 56(%3)\n"
20647 " movnti %%edx, 60(%3)\n"
20648 " addl $-64, %0\n"
20649 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing
20650 " shrl $2, %0\n"
20651 " andl $3, %%eax\n"
20652 " cld\n"
20653 - "6: rep; movsl\n"
20654 + "6: rep; "__copyuser_seg" movsl\n"
20655 " movl %%eax,%0\n"
20656 - "7: rep; movsb\n"
20657 + "7: rep; "__copyuser_seg" movsb\n"
20658 "8:\n"
20659 ".section .fixup,\"ax\"\n"
20660 "9: lea 0(%%eax,%0,4),%0\n"
20661 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_n
20662
20663 __asm__ __volatile__(
20664 " .align 2,0x90\n"
20665 - "0: movl 32(%4), %%eax\n"
20666 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
20667 " cmpl $67, %0\n"
20668 " jbe 2f\n"
20669 - "1: movl 64(%4), %%eax\n"
20670 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
20671 " .align 2,0x90\n"
20672 - "2: movl 0(%4), %%eax\n"
20673 - "21: movl 4(%4), %%edx\n"
20674 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
20675 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
20676 " movnti %%eax, 0(%3)\n"
20677 " movnti %%edx, 4(%3)\n"
20678 - "3: movl 8(%4), %%eax\n"
20679 - "31: movl 12(%4),%%edx\n"
20680 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
20681 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
20682 " movnti %%eax, 8(%3)\n"
20683 " movnti %%edx, 12(%3)\n"
20684 - "4: movl 16(%4), %%eax\n"
20685 - "41: movl 20(%4), %%edx\n"
20686 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
20687 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
20688 " movnti %%eax, 16(%3)\n"
20689 " movnti %%edx, 20(%3)\n"
20690 - "10: movl 24(%4), %%eax\n"
20691 - "51: movl 28(%4), %%edx\n"
20692 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
20693 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
20694 " movnti %%eax, 24(%3)\n"
20695 " movnti %%edx, 28(%3)\n"
20696 - "11: movl 32(%4), %%eax\n"
20697 - "61: movl 36(%4), %%edx\n"
20698 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
20699 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
20700 " movnti %%eax, 32(%3)\n"
20701 " movnti %%edx, 36(%3)\n"
20702 - "12: movl 40(%4), %%eax\n"
20703 - "71: movl 44(%4), %%edx\n"
20704 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
20705 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
20706 " movnti %%eax, 40(%3)\n"
20707 " movnti %%edx, 44(%3)\n"
20708 - "13: movl 48(%4), %%eax\n"
20709 - "81: movl 52(%4), %%edx\n"
20710 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
20711 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
20712 " movnti %%eax, 48(%3)\n"
20713 " movnti %%edx, 52(%3)\n"
20714 - "14: movl 56(%4), %%eax\n"
20715 - "91: movl 60(%4), %%edx\n"
20716 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
20717 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
20718 " movnti %%eax, 56(%3)\n"
20719 " movnti %%edx, 60(%3)\n"
20720 " addl $-64, %0\n"
20721 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_n
20722 " shrl $2, %0\n"
20723 " andl $3, %%eax\n"
20724 " cld\n"
20725 - "6: rep; movsl\n"
20726 + "6: rep; "__copyuser_seg" movsl\n"
20727 " movl %%eax,%0\n"
20728 - "7: rep; movsb\n"
20729 + "7: rep; "__copyuser_seg" movsb\n"
20730 "8:\n"
20731 ".section .fixup,\"ax\"\n"
20732 "9: lea 0(%%eax,%0,4),%0\n"
20733 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_n
20734 */
20735 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
20736 unsigned long size);
20737 -unsigned long __copy_user_intel(void __user *to, const void *from,
20738 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
20739 + unsigned long size);
20740 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
20741 unsigned long size);
20742 unsigned long __copy_user_zeroing_intel_nocache(void *to,
20743 const void __user *from, unsigned long size);
20744 #endif /* CONFIG_X86_INTEL_USERCOPY */
20745
20746 /* Generic arbitrary sized copy. */
20747 -#define __copy_user(to, from, size) \
20748 +#define __copy_user(to, from, size, prefix, set, restore) \
20749 do { \
20750 int __d0, __d1, __d2; \
20751 __asm__ __volatile__( \
20752 + set \
20753 " cmp $7,%0\n" \
20754 " jbe 1f\n" \
20755 " movl %1,%0\n" \
20756 " negl %0\n" \
20757 " andl $7,%0\n" \
20758 " subl %0,%3\n" \
20759 - "4: rep; movsb\n" \
20760 + "4: rep; "prefix"movsb\n" \
20761 " movl %3,%0\n" \
20762 " shrl $2,%0\n" \
20763 " andl $3,%3\n" \
20764 " .align 2,0x90\n" \
20765 - "0: rep; movsl\n" \
20766 + "0: rep; "prefix"movsl\n" \
20767 " movl %3,%0\n" \
20768 - "1: rep; movsb\n" \
20769 + "1: rep; "prefix"movsb\n" \
20770 "2:\n" \
20771 + restore \
20772 ".section .fixup,\"ax\"\n" \
20773 "5: addl %3,%0\n" \
20774 " jmp 2b\n" \
20775 @@ -682,14 +799,14 @@ do { \
20776 " negl %0\n" \
20777 " andl $7,%0\n" \
20778 " subl %0,%3\n" \
20779 - "4: rep; movsb\n" \
20780 + "4: rep; "__copyuser_seg"movsb\n" \
20781 " movl %3,%0\n" \
20782 " shrl $2,%0\n" \
20783 " andl $3,%3\n" \
20784 " .align 2,0x90\n" \
20785 - "0: rep; movsl\n" \
20786 + "0: rep; "__copyuser_seg"movsl\n" \
20787 " movl %3,%0\n" \
20788 - "1: rep; movsb\n" \
20789 + "1: rep; "__copyuser_seg"movsb\n" \
20790 "2:\n" \
20791 ".section .fixup,\"ax\"\n" \
20792 "5: addl %3,%0\n" \
20793 @@ -775,9 +892,9 @@ survive:
20794 }
20795 #endif
20796 if (movsl_is_ok(to, from, n))
20797 - __copy_user(to, from, n);
20798 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
20799 else
20800 - n = __copy_user_intel(to, from, n);
20801 + n = __generic_copy_to_user_intel(to, from, n);
20802 return n;
20803 }
20804 EXPORT_SYMBOL(__copy_to_user_ll);
20805 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero
20806 unsigned long n)
20807 {
20808 if (movsl_is_ok(to, from, n))
20809 - __copy_user(to, from, n);
20810 + __copy_user(to, from, n, __copyuser_seg, "", "");
20811 else
20812 - n = __copy_user_intel((void __user *)to,
20813 - (const void *)from, n);
20814 + n = __generic_copy_from_user_intel(to, from, n);
20815 return n;
20816 }
20817 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
20818 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocach
20819 if (n > 64 && cpu_has_xmm2)
20820 n = __copy_user_intel_nocache(to, from, n);
20821 else
20822 - __copy_user(to, from, n);
20823 + __copy_user(to, from, n, __copyuser_seg, "", "");
20824 #else
20825 - __copy_user(to, from, n);
20826 + __copy_user(to, from, n, __copyuser_seg, "", "");
20827 #endif
20828 return n;
20829 }
20830 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
20831
20832 -/**
20833 - * copy_to_user: - Copy a block of data into user space.
20834 - * @to: Destination address, in user space.
20835 - * @from: Source address, in kernel space.
20836 - * @n: Number of bytes to copy.
20837 - *
20838 - * Context: User context only. This function may sleep.
20839 - *
20840 - * Copy data from kernel space to user space.
20841 - *
20842 - * Returns number of bytes that could not be copied.
20843 - * On success, this will be zero.
20844 - */
20845 -unsigned long
20846 -copy_to_user(void __user *to, const void *from, unsigned long n)
20847 +void copy_from_user_overflow(void)
20848 {
20849 - if (access_ok(VERIFY_WRITE, to, n))
20850 - n = __copy_to_user(to, from, n);
20851 - return n;
20852 + WARN(1, "Buffer overflow detected!\n");
20853 }
20854 -EXPORT_SYMBOL(copy_to_user);
20855 +EXPORT_SYMBOL(copy_from_user_overflow);
20856
20857 -/**
20858 - * copy_from_user: - Copy a block of data from user space.
20859 - * @to: Destination address, in kernel space.
20860 - * @from: Source address, in user space.
20861 - * @n: Number of bytes to copy.
20862 - *
20863 - * Context: User context only. This function may sleep.
20864 - *
20865 - * Copy data from user space to kernel space.
20866 - *
20867 - * Returns number of bytes that could not be copied.
20868 - * On success, this will be zero.
20869 - *
20870 - * If some data could not be copied, this function will pad the copied
20871 - * data to the requested size using zero bytes.
20872 - */
20873 -unsigned long
20874 -_copy_from_user(void *to, const void __user *from, unsigned long n)
20875 +void copy_to_user_overflow(void)
20876 {
20877 - if (access_ok(VERIFY_READ, from, n))
20878 - n = __copy_from_user(to, from, n);
20879 - else
20880 - memset(to, 0, n);
20881 - return n;
20882 + WARN(1, "Buffer overflow detected!\n");
20883 }
20884 -EXPORT_SYMBOL(_copy_from_user);
20885 +EXPORT_SYMBOL(copy_to_user_overflow);
20886
20887 -void copy_from_user_overflow(void)
20888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20889 +void __set_fs(mm_segment_t x)
20890 {
20891 - WARN(1, "Buffer overflow detected!\n");
20892 + switch (x.seg) {
20893 + case 0:
20894 + loadsegment(gs, 0);
20895 + break;
20896 + case TASK_SIZE_MAX:
20897 + loadsegment(gs, __USER_DS);
20898 + break;
20899 + case -1UL:
20900 + loadsegment(gs, __KERNEL_DS);
20901 + break;
20902 + default:
20903 + BUG();
20904 + }
20905 + return;
20906 }
20907 -EXPORT_SYMBOL(copy_from_user_overflow);
20908 +EXPORT_SYMBOL(__set_fs);
20909 +
20910 +void set_fs(mm_segment_t x)
20911 +{
20912 + current_thread_info()->addr_limit = x;
20913 + __set_fs(x);
20914 +}
20915 +EXPORT_SYMBOL(set_fs);
20916 +#endif
20917 diff -urNp linux-2.6.39.2/arch/x86/lib/usercopy_64.c linux-2.6.39.2/arch/x86/lib/usercopy_64.c
20918 --- linux-2.6.39.2/arch/x86/lib/usercopy_64.c 2011-05-19 00:06:34.000000000 -0400
20919 +++ linux-2.6.39.2/arch/x86/lib/usercopy_64.c 2011-05-22 19:36:30.000000000 -0400
20920 @@ -42,6 +42,12 @@ long
20921 __strncpy_from_user(char *dst, const char __user *src, long count)
20922 {
20923 long res;
20924 +
20925 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20926 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
20927 + src += PAX_USER_SHADOW_BASE;
20928 +#endif
20929 +
20930 __do_strncpy_from_user(dst, src, count, res);
20931 return res;
20932 }
20933 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *
20934 {
20935 long __d0;
20936 might_fault();
20937 +
20938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20939 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
20940 + addr += PAX_USER_SHADOW_BASE;
20941 +#endif
20942 +
20943 /* no memory constraint because it doesn't change any memory gcc knows
20944 about */
20945 asm volatile(
20946 @@ -151,10 +163,18 @@ EXPORT_SYMBOL(strlen_user);
20947
20948 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
20949 {
20950 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20951 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
20952 +
20953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20954 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
20955 + to += PAX_USER_SHADOW_BASE;
20956 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
20957 + from += PAX_USER_SHADOW_BASE;
20958 +#endif
20959 +
20960 return copy_user_generic((__force void *)to, (__force void *)from, len);
20961 - }
20962 - return len;
20963 + }
20964 + return len;
20965 }
20966 EXPORT_SYMBOL(copy_in_user);
20967
20968 diff -urNp linux-2.6.39.2/arch/x86/Makefile linux-2.6.39.2/arch/x86/Makefile
20969 --- linux-2.6.39.2/arch/x86/Makefile 2011-05-19 00:06:34.000000000 -0400
20970 +++ linux-2.6.39.2/arch/x86/Makefile 2011-05-22 19:36:30.000000000 -0400
20971 @@ -195,3 +195,12 @@ define archhelp
20972 echo ' FDARGS="..." arguments for the booted kernel'
20973 echo ' FDINITRD=file initrd for the booted kernel'
20974 endef
20975 +
20976 +define OLD_LD
20977 +
20978 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
20979 +*** Please upgrade your binutils to 2.18 or newer
20980 +endef
20981 +
20982 +archprepare:
20983 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
20984 diff -urNp linux-2.6.39.2/arch/x86/mm/extable.c linux-2.6.39.2/arch/x86/mm/extable.c
20985 --- linux-2.6.39.2/arch/x86/mm/extable.c 2011-05-19 00:06:34.000000000 -0400
20986 +++ linux-2.6.39.2/arch/x86/mm/extable.c 2011-05-22 19:36:30.000000000 -0400
20987 @@ -1,14 +1,71 @@
20988 #include <linux/module.h>
20989 #include <linux/spinlock.h>
20990 +#include <linux/sort.h>
20991 #include <asm/uaccess.h>
20992 +#include <asm/pgtable.h>
20993
20994 +/*
20995 + * The exception table needs to be sorted so that the binary
20996 + * search that we use to find entries in it works properly.
20997 + * This is used both for the kernel exception table and for
20998 + * the exception tables of modules that get loaded.
20999 + */
21000 +static int cmp_ex(const void *a, const void *b)
21001 +{
21002 + const struct exception_table_entry *x = a, *y = b;
21003 +
21004 + /* avoid overflow */
21005 + if (x->insn > y->insn)
21006 + return 1;
21007 + if (x->insn < y->insn)
21008 + return -1;
21009 + return 0;
21010 +}
21011 +
21012 +static void swap_ex(void *a, void *b, int size)
21013 +{
21014 + struct exception_table_entry t, *x = a, *y = b;
21015 +
21016 + t = *x;
21017 +
21018 + pax_open_kernel();
21019 + *x = *y;
21020 + *y = t;
21021 + pax_close_kernel();
21022 +}
21023 +
21024 +void sort_extable(struct exception_table_entry *start,
21025 + struct exception_table_entry *finish)
21026 +{
21027 + sort(start, finish - start, sizeof(struct exception_table_entry),
21028 + cmp_ex, swap_ex);
21029 +}
21030 +
21031 +#ifdef CONFIG_MODULES
21032 +/*
21033 + * If the exception table is sorted, any referring to the module init
21034 + * will be at the beginning or the end.
21035 + */
21036 +void trim_init_extable(struct module *m)
21037 +{
21038 + /*trim the beginning*/
21039 + while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
21040 + m->extable++;
21041 + m->num_exentries--;
21042 + }
21043 + /*trim the end*/
21044 + while (m->num_exentries &&
21045 + within_module_init(m->extable[m->num_exentries-1].insn, m))
21046 + m->num_exentries--;
21047 +}
21048 +#endif /* CONFIG_MODULES */
21049
21050 int fixup_exception(struct pt_regs *regs)
21051 {
21052 const struct exception_table_entry *fixup;
21053
21054 #ifdef CONFIG_PNPBIOS
21055 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21056 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21057 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21058 extern u32 pnp_bios_is_utter_crap;
21059 pnp_bios_is_utter_crap = 1;
21060 diff -urNp linux-2.6.39.2/arch/x86/mm/fault.c linux-2.6.39.2/arch/x86/mm/fault.c
21061 --- linux-2.6.39.2/arch/x86/mm/fault.c 2011-05-19 00:06:34.000000000 -0400
21062 +++ linux-2.6.39.2/arch/x86/mm/fault.c 2011-06-06 17:34:04.000000000 -0400
21063 @@ -12,10 +12,18 @@
21064 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
21065 #include <linux/perf_event.h> /* perf_sw_event */
21066 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21067 +#include <linux/unistd.h>
21068 +#include <linux/compiler.h>
21069
21070 #include <asm/traps.h> /* dotraplinkage, ... */
21071 #include <asm/pgalloc.h> /* pgd_*(), ... */
21072 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21073 +#include <asm/vsyscall.h>
21074 +#include <asm/tlbflush.h>
21075 +
21076 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21077 +#include <asm/stacktrace.h>
21078 +#endif
21079
21080 /*
21081 * Page fault error code bits:
21082 @@ -53,7 +61,7 @@ static inline int __kprobes notify_page_
21083 int ret = 0;
21084
21085 /* kprobe_running() needs smp_processor_id() */
21086 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21087 + if (kprobes_built_in() && !user_mode(regs)) {
21088 preempt_disable();
21089 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21090 ret = 1;
21091 @@ -114,7 +122,10 @@ check_prefetch_opcode(struct pt_regs *re
21092 return !instr_lo || (instr_lo>>1) == 1;
21093 case 0x00:
21094 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21095 - if (probe_kernel_address(instr, opcode))
21096 + if (user_mode(regs)) {
21097 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
21098 + return 0;
21099 + } else if (probe_kernel_address(instr, opcode))
21100 return 0;
21101
21102 *prefetch = (instr_lo == 0xF) &&
21103 @@ -148,7 +159,10 @@ is_prefetch(struct pt_regs *regs, unsign
21104 while (instr < max_instr) {
21105 unsigned char opcode;
21106
21107 - if (probe_kernel_address(instr, opcode))
21108 + if (user_mode(regs)) {
21109 + if (__copy_from_user_inatomic(&opcode, (__force unsigned char __user *)(instr), 1))
21110 + break;
21111 + } else if (probe_kernel_address(instr, opcode))
21112 break;
21113
21114 instr++;
21115 @@ -179,6 +193,30 @@ force_sig_info_fault(int si_signo, int s
21116 force_sig_info(si_signo, &info, tsk);
21117 }
21118
21119 +#ifdef CONFIG_PAX_EMUTRAMP
21120 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21121 +#endif
21122 +
21123 +#ifdef CONFIG_PAX_PAGEEXEC
21124 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21125 +{
21126 + pgd_t *pgd;
21127 + pud_t *pud;
21128 + pmd_t *pmd;
21129 +
21130 + pgd = pgd_offset(mm, address);
21131 + if (!pgd_present(*pgd))
21132 + return NULL;
21133 + pud = pud_offset(pgd, address);
21134 + if (!pud_present(*pud))
21135 + return NULL;
21136 + pmd = pmd_offset(pud, address);
21137 + if (!pmd_present(*pmd))
21138 + return NULL;
21139 + return pmd;
21140 +}
21141 +#endif
21142 +
21143 DEFINE_SPINLOCK(pgd_lock);
21144 LIST_HEAD(pgd_list);
21145
21146 @@ -229,10 +267,22 @@ void vmalloc_sync_all(void)
21147 for (address = VMALLOC_START & PMD_MASK;
21148 address >= TASK_SIZE && address < FIXADDR_TOP;
21149 address += PMD_SIZE) {
21150 +
21151 +#ifdef CONFIG_PAX_PER_CPU_PGD
21152 + unsigned long cpu;
21153 +#else
21154 struct page *page;
21155 +#endif
21156
21157 spin_lock(&pgd_lock);
21158 +
21159 +#ifdef CONFIG_PAX_PER_CPU_PGD
21160 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
21161 + pgd_t *pgd = get_cpu_pgd(cpu);
21162 + pmd_t *ret;
21163 +#else
21164 list_for_each_entry(page, &pgd_list, lru) {
21165 + pgd_t *pgd = page_address(page);
21166 spinlock_t *pgt_lock;
21167 pmd_t *ret;
21168
21169 @@ -240,8 +290,13 @@ void vmalloc_sync_all(void)
21170 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21171
21172 spin_lock(pgt_lock);
21173 - ret = vmalloc_sync_one(page_address(page), address);
21174 +#endif
21175 +
21176 + ret = vmalloc_sync_one(pgd, address);
21177 +
21178 +#ifndef CONFIG_PAX_PER_CPU_PGD
21179 spin_unlock(pgt_lock);
21180 +#endif
21181
21182 if (!ret)
21183 break;
21184 @@ -275,6 +330,11 @@ static noinline __kprobes int vmalloc_fa
21185 * an interrupt in the middle of a task switch..
21186 */
21187 pgd_paddr = read_cr3();
21188 +
21189 +#ifdef CONFIG_PAX_PER_CPU_PGD
21190 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21191 +#endif
21192 +
21193 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21194 if (!pmd_k)
21195 return -1;
21196 @@ -370,7 +430,14 @@ static noinline __kprobes int vmalloc_fa
21197 * happen within a race in page table update. In the later
21198 * case just flush:
21199 */
21200 +
21201 +#ifdef CONFIG_PAX_PER_CPU_PGD
21202 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21203 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21204 +#else
21205 pgd = pgd_offset(current->active_mm, address);
21206 +#endif
21207 +
21208 pgd_ref = pgd_offset_k(address);
21209 if (pgd_none(*pgd_ref))
21210 return -1;
21211 @@ -532,7 +599,7 @@ static int is_errata93(struct pt_regs *r
21212 static int is_errata100(struct pt_regs *regs, unsigned long address)
21213 {
21214 #ifdef CONFIG_X86_64
21215 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21216 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21217 return 1;
21218 #endif
21219 return 0;
21220 @@ -559,7 +626,7 @@ static int is_f00f_bug(struct pt_regs *r
21221 }
21222
21223 static const char nx_warning[] = KERN_CRIT
21224 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21225 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21226
21227 static void
21228 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21229 @@ -568,15 +635,26 @@ show_fault_oops(struct pt_regs *regs, un
21230 if (!oops_may_print())
21231 return;
21232
21233 - if (error_code & PF_INSTR) {
21234 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21235 unsigned int level;
21236
21237 pte_t *pte = lookup_address(address, &level);
21238
21239 if (pte && pte_present(*pte) && !pte_exec(*pte))
21240 - printk(nx_warning, current_uid());
21241 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21242 }
21243
21244 +#ifdef CONFIG_PAX_KERNEXEC
21245 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21246 + if (current->signal->curr_ip)
21247 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21248 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21249 + else
21250 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21251 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21252 + }
21253 +#endif
21254 +
21255 printk(KERN_ALERT "BUG: unable to handle kernel ");
21256 if (address < PAGE_SIZE)
21257 printk(KERN_CONT "NULL pointer dereference");
21258 @@ -701,6 +779,68 @@ __bad_area_nosemaphore(struct pt_regs *r
21259 unsigned long address, int si_code)
21260 {
21261 struct task_struct *tsk = current;
21262 + struct mm_struct *mm = tsk->mm;
21263 +
21264 +#ifdef CONFIG_X86_64
21265 + if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
21266 + if (regs->ip == (unsigned long)vgettimeofday) {
21267 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
21268 + return;
21269 + } else if (regs->ip == (unsigned long)vtime) {
21270 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
21271 + return;
21272 + } else if (regs->ip == (unsigned long)vgetcpu) {
21273 + regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
21274 + return;
21275 + }
21276 + }
21277 +#endif
21278 +
21279 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21280 + if (mm && (error_code & PF_USER)) {
21281 + unsigned long ip = regs->ip;
21282 +
21283 + if (v8086_mode(regs))
21284 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
21285 +
21286 + /*
21287 + * It's possible to have interrupts off here:
21288 + */
21289 + local_irq_enable();
21290 +
21291 +#ifdef CONFIG_PAX_PAGEEXEC
21292 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
21293 + (((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && ip == address))) {
21294 +
21295 +#ifdef CONFIG_PAX_EMUTRAMP
21296 + switch (pax_handle_fetch_fault(regs)) {
21297 + case 2:
21298 + return;
21299 + }
21300 +#endif
21301 +
21302 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21303 + do_group_exit(SIGKILL);
21304 + }
21305 +#endif
21306 +
21307 +#ifdef CONFIG_PAX_SEGMEXEC
21308 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address)) {
21309 +
21310 +#ifdef CONFIG_PAX_EMUTRAMP
21311 + switch (pax_handle_fetch_fault(regs)) {
21312 + case 2:
21313 + return;
21314 + }
21315 +#endif
21316 +
21317 + pax_report_fault(regs, (void *)ip, (void *)regs->sp);
21318 + do_group_exit(SIGKILL);
21319 + }
21320 +#endif
21321 +
21322 + }
21323 +#endif
21324
21325 /* User mode accesses just cause a SIGSEGV */
21326 if (error_code & PF_USER) {
21327 @@ -855,6 +995,99 @@ static int spurious_fault_check(unsigned
21328 return 1;
21329 }
21330
21331 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21332 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21333 +{
21334 + pte_t *pte;
21335 + pmd_t *pmd;
21336 + spinlock_t *ptl;
21337 + unsigned char pte_mask;
21338 +
21339 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21340 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21341 + return 0;
21342 +
21343 + /* PaX: it's our fault, let's handle it if we can */
21344 +
21345 + /* PaX: take a look at read faults before acquiring any locks */
21346 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21347 + /* instruction fetch attempt from a protected page in user mode */
21348 + up_read(&mm->mmap_sem);
21349 +
21350 +#ifdef CONFIG_PAX_EMUTRAMP
21351 + switch (pax_handle_fetch_fault(regs)) {
21352 + case 2:
21353 + return 1;
21354 + }
21355 +#endif
21356 +
21357 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21358 + do_group_exit(SIGKILL);
21359 + }
21360 +
21361 + pmd = pax_get_pmd(mm, address);
21362 + if (unlikely(!pmd))
21363 + return 0;
21364 +
21365 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21366 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21367 + pte_unmap_unlock(pte, ptl);
21368 + return 0;
21369 + }
21370 +
21371 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21372 + /* write attempt to a protected page in user mode */
21373 + pte_unmap_unlock(pte, ptl);
21374 + return 0;
21375 + }
21376 +
21377 +#ifdef CONFIG_SMP
21378 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21379 +#else
21380 + if (likely(address > get_limit(regs->cs)))
21381 +#endif
21382 + {
21383 + set_pte(pte, pte_mkread(*pte));
21384 + __flush_tlb_one(address);
21385 + pte_unmap_unlock(pte, ptl);
21386 + up_read(&mm->mmap_sem);
21387 + return 1;
21388 + }
21389 +
21390 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21391 +
21392 + /*
21393 + * PaX: fill DTLB with user rights and retry
21394 + */
21395 + __asm__ __volatile__ (
21396 + "orb %2,(%1)\n"
21397 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21398 +/*
21399 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21400 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21401 + * page fault when examined during a TLB load attempt. this is true not only
21402 + * for PTEs holding a non-present entry but also present entries that will
21403 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21404 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21405 + * for our target pages since their PTEs are simply not in the TLBs at all.
21406 +
21407 + * the best thing in omitting it is that we gain around 15-20% speed in the
21408 + * fast path of the page fault handler and can get rid of tracing since we
21409 + * can no longer flush unintended entries.
21410 + */
21411 + "invlpg (%0)\n"
21412 +#endif
21413 + __copyuser_seg"testb $0,(%0)\n"
21414 + "xorb %3,(%1)\n"
21415 + :
21416 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21417 + : "memory", "cc");
21418 + pte_unmap_unlock(pte, ptl);
21419 + up_read(&mm->mmap_sem);
21420 + return 1;
21421 +}
21422 +#endif
21423 +
21424 /*
21425 * Handle a spurious fault caused by a stale TLB entry.
21426 *
21427 @@ -927,6 +1160,9 @@ int show_unhandled_signals = 1;
21428 static inline int
21429 access_error(unsigned long error_code, struct vm_area_struct *vma)
21430 {
21431 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21432 + return 1;
21433 +
21434 if (error_code & PF_WRITE) {
21435 /* write, present and write, not present: */
21436 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21437 @@ -960,19 +1196,33 @@ do_page_fault(struct pt_regs *regs, unsi
21438 {
21439 struct vm_area_struct *vma;
21440 struct task_struct *tsk;
21441 - unsigned long address;
21442 struct mm_struct *mm;
21443 int fault;
21444 int write = error_code & PF_WRITE;
21445 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
21446 (write ? FAULT_FLAG_WRITE : 0);
21447
21448 + /* Get the faulting address: */
21449 + unsigned long address = read_cr2();
21450 +
21451 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21452 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21453 + if (!search_exception_tables(regs->ip)) {
21454 + bad_area_nosemaphore(regs, error_code, address);
21455 + return;
21456 + }
21457 + if (address < PAX_USER_SHADOW_BASE) {
21458 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21459 + printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
21460 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21461 + } else
21462 + address -= PAX_USER_SHADOW_BASE;
21463 + }
21464 +#endif
21465 +
21466 tsk = current;
21467 mm = tsk->mm;
21468
21469 - /* Get the faulting address: */
21470 - address = read_cr2();
21471 -
21472 /*
21473 * Detect and handle instructions that would cause a page fault for
21474 * both a tracked kernel page and a userspace page.
21475 @@ -1032,7 +1282,7 @@ do_page_fault(struct pt_regs *regs, unsi
21476 * User-mode registers count as a user access even for any
21477 * potential system fault or CPU buglet:
21478 */
21479 - if (user_mode_vm(regs)) {
21480 + if (user_mode(regs)) {
21481 local_irq_enable();
21482 error_code |= PF_USER;
21483 } else {
21484 @@ -1087,6 +1337,11 @@ retry:
21485 might_sleep();
21486 }
21487
21488 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21489 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
21490 + return;
21491 +#endif
21492 +
21493 vma = find_vma(mm, address);
21494 if (unlikely(!vma)) {
21495 bad_area(regs, error_code, address);
21496 @@ -1098,18 +1353,24 @@ retry:
21497 bad_area(regs, error_code, address);
21498 return;
21499 }
21500 - if (error_code & PF_USER) {
21501 - /*
21502 - * Accessing the stack below %sp is always a bug.
21503 - * The large cushion allows instructions like enter
21504 - * and pusha to work. ("enter $65535, $31" pushes
21505 - * 32 pointers and then decrements %sp by 65535.)
21506 - */
21507 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
21508 - bad_area(regs, error_code, address);
21509 - return;
21510 - }
21511 + /*
21512 + * Accessing the stack below %sp is always a bug.
21513 + * The large cushion allows instructions like enter
21514 + * and pusha to work. ("enter $65535, $31" pushes
21515 + * 32 pointers and then decrements %sp by 65535.)
21516 + */
21517 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
21518 + bad_area(regs, error_code, address);
21519 + return;
21520 }
21521 +
21522 +#ifdef CONFIG_PAX_SEGMEXEC
21523 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
21524 + bad_area(regs, error_code, address);
21525 + return;
21526 + }
21527 +#endif
21528 +
21529 if (unlikely(expand_stack(vma, address))) {
21530 bad_area(regs, error_code, address);
21531 return;
21532 @@ -1164,3 +1425,199 @@ good_area:
21533
21534 up_read(&mm->mmap_sem);
21535 }
21536 +
21537 +#ifdef CONFIG_PAX_EMUTRAMP
21538 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
21539 +{
21540 + int err;
21541 +
21542 + do { /* PaX: gcc trampoline emulation #1 */
21543 + unsigned char mov1, mov2;
21544 + unsigned short jmp;
21545 + unsigned int addr1, addr2;
21546 +
21547 +#ifdef CONFIG_X86_64
21548 + if ((regs->ip + 11) >> 32)
21549 + break;
21550 +#endif
21551 +
21552 + err = get_user(mov1, (unsigned char __user *)regs->ip);
21553 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21554 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
21555 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21556 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
21557 +
21558 + if (err)
21559 + break;
21560 +
21561 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
21562 + regs->cx = addr1;
21563 + regs->ax = addr2;
21564 + regs->ip = addr2;
21565 + return 2;
21566 + }
21567 + } while (0);
21568 +
21569 + do { /* PaX: gcc trampoline emulation #2 */
21570 + unsigned char mov, jmp;
21571 + unsigned int addr1, addr2;
21572 +
21573 +#ifdef CONFIG_X86_64
21574 + if ((regs->ip + 9) >> 32)
21575 + break;
21576 +#endif
21577 +
21578 + err = get_user(mov, (unsigned char __user *)regs->ip);
21579 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
21580 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
21581 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
21582 +
21583 + if (err)
21584 + break;
21585 +
21586 + if (mov == 0xB9 && jmp == 0xE9) {
21587 + regs->cx = addr1;
21588 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
21589 + return 2;
21590 + }
21591 + } while (0);
21592 +
21593 + return 1; /* PaX in action */
21594 +}
21595 +
21596 +#ifdef CONFIG_X86_64
21597 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
21598 +{
21599 + int err;
21600 +
21601 + do { /* PaX: gcc trampoline emulation #1 */
21602 + unsigned short mov1, mov2, jmp1;
21603 + unsigned char jmp2;
21604 + unsigned int addr1;
21605 + unsigned long addr2;
21606 +
21607 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21608 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
21609 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
21610 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
21611 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
21612 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
21613 +
21614 + if (err)
21615 + break;
21616 +
21617 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21618 + regs->r11 = addr1;
21619 + regs->r10 = addr2;
21620 + regs->ip = addr1;
21621 + return 2;
21622 + }
21623 + } while (0);
21624 +
21625 + do { /* PaX: gcc trampoline emulation #2 */
21626 + unsigned short mov1, mov2, jmp1;
21627 + unsigned char jmp2;
21628 + unsigned long addr1, addr2;
21629 +
21630 + err = get_user(mov1, (unsigned short __user *)regs->ip);
21631 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
21632 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
21633 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
21634 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
21635 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
21636 +
21637 + if (err)
21638 + break;
21639 +
21640 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
21641 + regs->r11 = addr1;
21642 + regs->r10 = addr2;
21643 + regs->ip = addr1;
21644 + return 2;
21645 + }
21646 + } while (0);
21647 +
21648 + return 1; /* PaX in action */
21649 +}
21650 +#endif
21651 +
21652 +/*
21653 + * PaX: decide what to do with offenders (regs->ip = fault address)
21654 + *
21655 + * returns 1 when task should be killed
21656 + * 2 when gcc trampoline was detected
21657 + */
21658 +static int pax_handle_fetch_fault(struct pt_regs *regs)
21659 +{
21660 + if (v8086_mode(regs))
21661 + return 1;
21662 +
21663 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
21664 + return 1;
21665 +
21666 +#ifdef CONFIG_X86_32
21667 + return pax_handle_fetch_fault_32(regs);
21668 +#else
21669 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
21670 + return pax_handle_fetch_fault_32(regs);
21671 + else
21672 + return pax_handle_fetch_fault_64(regs);
21673 +#endif
21674 +}
21675 +#endif
21676 +
21677 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21678 +void pax_report_insns(void *pc, void *sp)
21679 +{
21680 + long i;
21681 +
21682 + printk(KERN_ERR "PAX: bytes at PC: ");
21683 + for (i = 0; i < 20; i++) {
21684 + unsigned char c;
21685 + if (get_user(c, (__force unsigned char __user *)pc+i))
21686 + printk(KERN_CONT "?? ");
21687 + else
21688 + printk(KERN_CONT "%02x ", c);
21689 + }
21690 + printk("\n");
21691 +
21692 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
21693 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
21694 + unsigned long c;
21695 + if (get_user(c, (__force unsigned long __user *)sp+i))
21696 +#ifdef CONFIG_X86_32
21697 + printk(KERN_CONT "???????? ");
21698 +#else
21699 + printk(KERN_CONT "???????????????? ");
21700 +#endif
21701 + else
21702 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
21703 + }
21704 + printk("\n");
21705 +}
21706 +#endif
21707 +
21708 +/**
21709 + * probe_kernel_write(): safely attempt to write to a location
21710 + * @dst: address to write to
21711 + * @src: pointer to the data that shall be written
21712 + * @size: size of the data chunk
21713 + *
21714 + * Safely write to address @dst from the buffer at @src. If a kernel fault
21715 + * happens, handle that and return -EFAULT.
21716 + */
21717 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
21718 +{
21719 + long ret;
21720 + mm_segment_t old_fs = get_fs();
21721 +
21722 + set_fs(KERNEL_DS);
21723 + pagefault_disable();
21724 + pax_open_kernel();
21725 + ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
21726 + pax_close_kernel();
21727 + pagefault_enable();
21728 + set_fs(old_fs);
21729 +
21730 + return ret ? -EFAULT : 0;
21731 +}
21732 diff -urNp linux-2.6.39.2/arch/x86/mm/gup.c linux-2.6.39.2/arch/x86/mm/gup.c
21733 --- linux-2.6.39.2/arch/x86/mm/gup.c 2011-05-19 00:06:34.000000000 -0400
21734 +++ linux-2.6.39.2/arch/x86/mm/gup.c 2011-05-22 19:36:30.000000000 -0400
21735 @@ -263,7 +263,7 @@ int __get_user_pages_fast(unsigned long
21736 addr = start;
21737 len = (unsigned long) nr_pages << PAGE_SHIFT;
21738 end = start + len;
21739 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21740 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
21741 (void __user *)start, len)))
21742 return 0;
21743
21744 diff -urNp linux-2.6.39.2/arch/x86/mm/highmem_32.c linux-2.6.39.2/arch/x86/mm/highmem_32.c
21745 --- linux-2.6.39.2/arch/x86/mm/highmem_32.c 2011-05-19 00:06:34.000000000 -0400
21746 +++ linux-2.6.39.2/arch/x86/mm/highmem_32.c 2011-05-22 19:36:30.000000000 -0400
21747 @@ -44,7 +44,10 @@ void *kmap_atomic_prot(struct page *page
21748 idx = type + KM_TYPE_NR*smp_processor_id();
21749 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
21750 BUG_ON(!pte_none(*(kmap_pte-idx)));
21751 +
21752 + pax_open_kernel();
21753 set_pte(kmap_pte-idx, mk_pte(page, prot));
21754 + pax_close_kernel();
21755
21756 return (void *)vaddr;
21757 }
21758 diff -urNp linux-2.6.39.2/arch/x86/mm/hugetlbpage.c linux-2.6.39.2/arch/x86/mm/hugetlbpage.c
21759 --- linux-2.6.39.2/arch/x86/mm/hugetlbpage.c 2011-05-19 00:06:34.000000000 -0400
21760 +++ linux-2.6.39.2/arch/x86/mm/hugetlbpage.c 2011-05-22 19:36:30.000000000 -0400
21761 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmappe
21762 struct hstate *h = hstate_file(file);
21763 struct mm_struct *mm = current->mm;
21764 struct vm_area_struct *vma;
21765 - unsigned long start_addr;
21766 + unsigned long start_addr, pax_task_size = TASK_SIZE;
21767 +
21768 +#ifdef CONFIG_PAX_SEGMEXEC
21769 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21770 + pax_task_size = SEGMEXEC_TASK_SIZE;
21771 +#endif
21772 +
21773 + pax_task_size -= PAGE_SIZE;
21774
21775 if (len > mm->cached_hole_size) {
21776 - start_addr = mm->free_area_cache;
21777 + start_addr = mm->free_area_cache;
21778 } else {
21779 - start_addr = TASK_UNMAPPED_BASE;
21780 - mm->cached_hole_size = 0;
21781 + start_addr = mm->mmap_base;
21782 + mm->cached_hole_size = 0;
21783 }
21784
21785 full_search:
21786 @@ -280,26 +287,27 @@ full_search:
21787
21788 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
21789 /* At this point: (!vma || addr < vma->vm_end). */
21790 - if (TASK_SIZE - len < addr) {
21791 + if (pax_task_size - len < addr) {
21792 /*
21793 * Start a new search - just in case we missed
21794 * some holes.
21795 */
21796 - if (start_addr != TASK_UNMAPPED_BASE) {
21797 - start_addr = TASK_UNMAPPED_BASE;
21798 + if (start_addr != mm->mmap_base) {
21799 + start_addr = mm->mmap_base;
21800 mm->cached_hole_size = 0;
21801 goto full_search;
21802 }
21803 return -ENOMEM;
21804 }
21805 - if (!vma || addr + len <= vma->vm_start) {
21806 - mm->free_area_cache = addr + len;
21807 - return addr;
21808 - }
21809 + if (check_heap_stack_gap(vma, addr, len))
21810 + break;
21811 if (addr + mm->cached_hole_size < vma->vm_start)
21812 mm->cached_hole_size = vma->vm_start - addr;
21813 addr = ALIGN(vma->vm_end, huge_page_size(h));
21814 }
21815 +
21816 + mm->free_area_cache = addr + len;
21817 + return addr;
21818 }
21819
21820 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
21821 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmappe
21822 {
21823 struct hstate *h = hstate_file(file);
21824 struct mm_struct *mm = current->mm;
21825 - struct vm_area_struct *vma, *prev_vma;
21826 - unsigned long base = mm->mmap_base, addr = addr0;
21827 + struct vm_area_struct *vma;
21828 + unsigned long base = mm->mmap_base, addr;
21829 unsigned long largest_hole = mm->cached_hole_size;
21830 - int first_time = 1;
21831
21832 /* don't allow allocations above current base */
21833 if (mm->free_area_cache > base)
21834 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmappe
21835 largest_hole = 0;
21836 mm->free_area_cache = base;
21837 }
21838 -try_again:
21839 +
21840 /* make sure it can fit in the remaining address space */
21841 if (mm->free_area_cache < len)
21842 goto fail;
21843
21844 /* either no address requested or can't fit in requested address hole */
21845 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
21846 + addr = (mm->free_area_cache - len);
21847 do {
21848 + addr &= huge_page_mask(h);
21849 + vma = find_vma(mm, addr);
21850 /*
21851 * Lookup failure means no vma is above this address,
21852 * i.e. return with success:
21853 - */
21854 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
21855 - return addr;
21856 -
21857 - /*
21858 * new region fits between prev_vma->vm_end and
21859 * vma->vm_start, use it:
21860 */
21861 - if (addr + len <= vma->vm_start &&
21862 - (!prev_vma || (addr >= prev_vma->vm_end))) {
21863 + if (check_heap_stack_gap(vma, addr, len)) {
21864 /* remember the address as a hint for next time */
21865 - mm->cached_hole_size = largest_hole;
21866 - return (mm->free_area_cache = addr);
21867 - } else {
21868 - /* pull free_area_cache down to the first hole */
21869 - if (mm->free_area_cache == vma->vm_end) {
21870 - mm->free_area_cache = vma->vm_start;
21871 - mm->cached_hole_size = largest_hole;
21872 - }
21873 + mm->cached_hole_size = largest_hole;
21874 + return (mm->free_area_cache = addr);
21875 + }
21876 + /* pull free_area_cache down to the first hole */
21877 + if (mm->free_area_cache == vma->vm_end) {
21878 + mm->free_area_cache = vma->vm_start;
21879 + mm->cached_hole_size = largest_hole;
21880 }
21881
21882 /* remember the largest hole we saw so far */
21883 if (addr + largest_hole < vma->vm_start)
21884 - largest_hole = vma->vm_start - addr;
21885 + largest_hole = vma->vm_start - addr;
21886
21887 /* try just below the current vma->vm_start */
21888 - addr = (vma->vm_start - len) & huge_page_mask(h);
21889 - } while (len <= vma->vm_start);
21890 + addr = skip_heap_stack_gap(vma, len);
21891 + } while (!IS_ERR_VALUE(addr));
21892
21893 fail:
21894 /*
21895 - * if hint left us with no space for the requested
21896 - * mapping then try again:
21897 - */
21898 - if (first_time) {
21899 - mm->free_area_cache = base;
21900 - largest_hole = 0;
21901 - first_time = 0;
21902 - goto try_again;
21903 - }
21904 - /*
21905 * A failed mmap() very likely causes application failure,
21906 * so fall back to the bottom-up function here. This scenario
21907 * can happen with large stack limits and large mmap()
21908 * allocations.
21909 */
21910 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21911 +
21912 +#ifdef CONFIG_PAX_SEGMEXEC
21913 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21914 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
21915 + else
21916 +#endif
21917 +
21918 + mm->mmap_base = TASK_UNMAPPED_BASE;
21919 +
21920 +#ifdef CONFIG_PAX_RANDMMAP
21921 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21922 + mm->mmap_base += mm->delta_mmap;
21923 +#endif
21924 +
21925 + mm->free_area_cache = mm->mmap_base;
21926 mm->cached_hole_size = ~0UL;
21927 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
21928 len, pgoff, flags);
21929 @@ -386,6 +392,7 @@ fail:
21930 /*
21931 * Restore the topdown base:
21932 */
21933 + mm->mmap_base = base;
21934 mm->free_area_cache = base;
21935 mm->cached_hole_size = ~0UL;
21936
21937 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *f
21938 struct hstate *h = hstate_file(file);
21939 struct mm_struct *mm = current->mm;
21940 struct vm_area_struct *vma;
21941 + unsigned long pax_task_size = TASK_SIZE;
21942
21943 if (len & ~huge_page_mask(h))
21944 return -EINVAL;
21945 - if (len > TASK_SIZE)
21946 +
21947 +#ifdef CONFIG_PAX_SEGMEXEC
21948 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
21949 + pax_task_size = SEGMEXEC_TASK_SIZE;
21950 +#endif
21951 +
21952 + pax_task_size -= PAGE_SIZE;
21953 +
21954 + if (len > pax_task_size)
21955 return -ENOMEM;
21956
21957 if (flags & MAP_FIXED) {
21958 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *f
21959 if (addr) {
21960 addr = ALIGN(addr, huge_page_size(h));
21961 vma = find_vma(mm, addr);
21962 - if (TASK_SIZE - len >= addr &&
21963 - (!vma || addr + len <= vma->vm_start))
21964 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
21965 return addr;
21966 }
21967 if (mm->get_unmapped_area == arch_get_unmapped_area)
21968 diff -urNp linux-2.6.39.2/arch/x86/mm/init_32.c linux-2.6.39.2/arch/x86/mm/init_32.c
21969 --- linux-2.6.39.2/arch/x86/mm/init_32.c 2011-05-19 00:06:34.000000000 -0400
21970 +++ linux-2.6.39.2/arch/x86/mm/init_32.c 2011-05-22 19:36:30.000000000 -0400
21971 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
21972 }
21973
21974 /*
21975 - * Creates a middle page table and puts a pointer to it in the
21976 - * given global directory entry. This only returns the gd entry
21977 - * in non-PAE compilation mode, since the middle layer is folded.
21978 - */
21979 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
21980 -{
21981 - pud_t *pud;
21982 - pmd_t *pmd_table;
21983 -
21984 -#ifdef CONFIG_X86_PAE
21985 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
21986 - if (after_bootmem)
21987 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
21988 - else
21989 - pmd_table = (pmd_t *)alloc_low_page();
21990 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
21991 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
21992 - pud = pud_offset(pgd, 0);
21993 - BUG_ON(pmd_table != pmd_offset(pud, 0));
21994 -
21995 - return pmd_table;
21996 - }
21997 -#endif
21998 - pud = pud_offset(pgd, 0);
21999 - pmd_table = pmd_offset(pud, 0);
22000 -
22001 - return pmd_table;
22002 -}
22003 -
22004 -/*
22005 * Create a page table and place a pointer to it in a middle page
22006 * directory entry:
22007 */
22008 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_ini
22009 page_table = (pte_t *)alloc_low_page();
22010
22011 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22012 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22013 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22014 +#else
22015 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22016 +#endif
22017 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22018 }
22019
22020 return pte_offset_kernel(pmd, 0);
22021 }
22022
22023 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22024 +{
22025 + pud_t *pud;
22026 + pmd_t *pmd_table;
22027 +
22028 + pud = pud_offset(pgd, 0);
22029 + pmd_table = pmd_offset(pud, 0);
22030 +
22031 + return pmd_table;
22032 +}
22033 +
22034 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22035 {
22036 int pgd_idx = pgd_index(vaddr);
22037 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long star
22038 int pgd_idx, pmd_idx;
22039 unsigned long vaddr;
22040 pgd_t *pgd;
22041 + pud_t *pud;
22042 pmd_t *pmd;
22043 pte_t *pte = NULL;
22044
22045 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long star
22046 pgd = pgd_base + pgd_idx;
22047
22048 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22049 - pmd = one_md_table_init(pgd);
22050 - pmd = pmd + pmd_index(vaddr);
22051 + pud = pud_offset(pgd, vaddr);
22052 + pmd = pmd_offset(pud, vaddr);
22053 +
22054 +#ifdef CONFIG_X86_PAE
22055 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22056 +#endif
22057 +
22058 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22059 pmd++, pmd_idx++) {
22060 pte = page_table_kmap_check(one_page_table_init(pmd),
22061 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long star
22062 }
22063 }
22064
22065 -static inline int is_kernel_text(unsigned long addr)
22066 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22067 {
22068 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22069 - return 1;
22070 - return 0;
22071 + if ((start > ktla_ktva((unsigned long)_etext) ||
22072 + end <= ktla_ktva((unsigned long)_stext)) &&
22073 + (start > ktla_ktva((unsigned long)_einittext) ||
22074 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22075 +
22076 +#ifdef CONFIG_ACPI_SLEEP
22077 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22078 +#endif
22079 +
22080 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22081 + return 0;
22082 + return 1;
22083 }
22084
22085 /*
22086 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned lo
22087 unsigned long last_map_addr = end;
22088 unsigned long start_pfn, end_pfn;
22089 pgd_t *pgd_base = swapper_pg_dir;
22090 - int pgd_idx, pmd_idx, pte_ofs;
22091 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22092 unsigned long pfn;
22093 pgd_t *pgd;
22094 + pud_t *pud;
22095 pmd_t *pmd;
22096 pte_t *pte;
22097 unsigned pages_2m, pages_4k;
22098 @@ -281,8 +282,13 @@ repeat:
22099 pfn = start_pfn;
22100 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22101 pgd = pgd_base + pgd_idx;
22102 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22103 - pmd = one_md_table_init(pgd);
22104 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22105 + pud = pud_offset(pgd, 0);
22106 + pmd = pmd_offset(pud, 0);
22107 +
22108 +#ifdef CONFIG_X86_PAE
22109 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22110 +#endif
22111
22112 if (pfn >= end_pfn)
22113 continue;
22114 @@ -294,14 +300,13 @@ repeat:
22115 #endif
22116 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22117 pmd++, pmd_idx++) {
22118 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22119 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22120
22121 /*
22122 * Map with big pages if possible, otherwise
22123 * create normal page tables:
22124 */
22125 if (use_pse) {
22126 - unsigned int addr2;
22127 pgprot_t prot = PAGE_KERNEL_LARGE;
22128 /*
22129 * first pass will use the same initial
22130 @@ -311,11 +316,7 @@ repeat:
22131 __pgprot(PTE_IDENT_ATTR |
22132 _PAGE_PSE);
22133
22134 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22135 - PAGE_OFFSET + PAGE_SIZE-1;
22136 -
22137 - if (is_kernel_text(addr) ||
22138 - is_kernel_text(addr2))
22139 + if (is_kernel_text(address, address + PMD_SIZE))
22140 prot = PAGE_KERNEL_LARGE_EXEC;
22141
22142 pages_2m++;
22143 @@ -332,7 +333,7 @@ repeat:
22144 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22145 pte += pte_ofs;
22146 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22147 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22148 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22149 pgprot_t prot = PAGE_KERNEL;
22150 /*
22151 * first pass will use the same initial
22152 @@ -340,7 +341,7 @@ repeat:
22153 */
22154 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22155
22156 - if (is_kernel_text(addr))
22157 + if (is_kernel_text(address, address + PAGE_SIZE))
22158 prot = PAGE_KERNEL_EXEC;
22159
22160 pages_4k++;
22161 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start
22162
22163 pud = pud_offset(pgd, va);
22164 pmd = pmd_offset(pud, va);
22165 - if (!pmd_present(*pmd))
22166 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22167 break;
22168
22169 pte = pte_offset_kernel(pmd, va);
22170 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_ran
22171
22172 static void __init pagetable_init(void)
22173 {
22174 - pgd_t *pgd_base = swapper_pg_dir;
22175 -
22176 - permanent_kmaps_init(pgd_base);
22177 + permanent_kmaps_init(swapper_pg_dir);
22178 }
22179
22180 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22181 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22182 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22183
22184 /* user-defined highmem size */
22185 @@ -754,6 +753,12 @@ void __init mem_init(void)
22186
22187 pci_iommu_alloc();
22188
22189 +#ifdef CONFIG_PAX_PER_CPU_PGD
22190 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22191 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22192 + KERNEL_PGD_PTRS);
22193 +#endif
22194 +
22195 #ifdef CONFIG_FLATMEM
22196 BUG_ON(!mem_map);
22197 #endif
22198 @@ -771,7 +776,7 @@ void __init mem_init(void)
22199 set_highmem_pages_init();
22200
22201 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22202 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22203 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22204 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22205
22206 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22207 @@ -812,10 +817,10 @@ void __init mem_init(void)
22208 ((unsigned long)&__init_end -
22209 (unsigned long)&__init_begin) >> 10,
22210
22211 - (unsigned long)&_etext, (unsigned long)&_edata,
22212 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22213 + (unsigned long)&_sdata, (unsigned long)&_edata,
22214 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22215
22216 - (unsigned long)&_text, (unsigned long)&_etext,
22217 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22218 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22219
22220 /*
22221 @@ -893,6 +898,7 @@ void set_kernel_text_rw(void)
22222 if (!kernel_set_to_readonly)
22223 return;
22224
22225 + start = ktla_ktva(start);
22226 pr_debug("Set kernel text: %lx - %lx for read write\n",
22227 start, start+size);
22228
22229 @@ -907,6 +913,7 @@ void set_kernel_text_ro(void)
22230 if (!kernel_set_to_readonly)
22231 return;
22232
22233 + start = ktla_ktva(start);
22234 pr_debug("Set kernel text: %lx - %lx for read only\n",
22235 start, start+size);
22236
22237 @@ -935,6 +942,7 @@ void mark_rodata_ro(void)
22238 unsigned long start = PFN_ALIGN(_text);
22239 unsigned long size = PFN_ALIGN(_etext) - start;
22240
22241 + start = ktla_ktva(start);
22242 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
22243 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
22244 size >> 10);
22245 diff -urNp linux-2.6.39.2/arch/x86/mm/init_64.c linux-2.6.39.2/arch/x86/mm/init_64.c
22246 --- linux-2.6.39.2/arch/x86/mm/init_64.c 2011-05-19 00:06:34.000000000 -0400
22247 +++ linux-2.6.39.2/arch/x86/mm/init_64.c 2011-05-22 19:36:30.000000000 -0400
22248 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpa
22249 * around without checking the pgd every time.
22250 */
22251
22252 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
22253 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
22254 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22255
22256 int force_personality32;
22257 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long star
22258
22259 for (address = start; address <= end; address += PGDIR_SIZE) {
22260 const pgd_t *pgd_ref = pgd_offset_k(address);
22261 +
22262 +#ifdef CONFIG_PAX_PER_CPU_PGD
22263 + unsigned long cpu;
22264 +#else
22265 struct page *page;
22266 +#endif
22267
22268 if (pgd_none(*pgd_ref))
22269 continue;
22270
22271 spin_lock(&pgd_lock);
22272 +
22273 +#ifdef CONFIG_PAX_PER_CPU_PGD
22274 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22275 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
22276 +#else
22277 list_for_each_entry(page, &pgd_list, lru) {
22278 pgd_t *pgd;
22279 spinlock_t *pgt_lock;
22280 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long star
22281 /* the pgt_lock only for Xen */
22282 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
22283 spin_lock(pgt_lock);
22284 +#endif
22285
22286 if (pgd_none(*pgd))
22287 set_pgd(pgd, *pgd_ref);
22288 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long star
22289 BUG_ON(pgd_page_vaddr(*pgd)
22290 != pgd_page_vaddr(*pgd_ref));
22291
22292 +#ifndef CONFIG_PAX_PER_CPU_PGD
22293 spin_unlock(pgt_lock);
22294 +#endif
22295 +
22296 }
22297 spin_unlock(&pgd_lock);
22298 }
22299 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page,
22300 pmd = fill_pmd(pud, vaddr);
22301 pte = fill_pte(pmd, vaddr);
22302
22303 + pax_open_kernel();
22304 set_pte(pte, new_pte);
22305 + pax_close_kernel();
22306
22307 /*
22308 * It's enough to flush this one mapping.
22309 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(
22310 pgd = pgd_offset_k((unsigned long)__va(phys));
22311 if (pgd_none(*pgd)) {
22312 pud = (pud_t *) spp_getpage();
22313 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
22314 - _PAGE_USER));
22315 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
22316 }
22317 pud = pud_offset(pgd, (unsigned long)__va(phys));
22318 if (pud_none(*pud)) {
22319 pmd = (pmd_t *) spp_getpage();
22320 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
22321 - _PAGE_USER));
22322 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
22323 }
22324 pmd = pmd_offset(pud, phys);
22325 BUG_ON(!pmd_none(*pmd));
22326 @@ -698,6 +712,12 @@ void __init mem_init(void)
22327
22328 pci_iommu_alloc();
22329
22330 +#ifdef CONFIG_PAX_PER_CPU_PGD
22331 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22332 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22333 + KERNEL_PGD_PTRS);
22334 +#endif
22335 +
22336 /* clear_bss() already clear the empty_zero_page */
22337
22338 reservedpages = 0;
22339 @@ -858,8 +878,8 @@ int kern_addr_valid(unsigned long addr)
22340 static struct vm_area_struct gate_vma = {
22341 .vm_start = VSYSCALL_START,
22342 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
22343 - .vm_page_prot = PAGE_READONLY_EXEC,
22344 - .vm_flags = VM_READ | VM_EXEC
22345 + .vm_page_prot = PAGE_READONLY,
22346 + .vm_flags = VM_READ
22347 };
22348
22349 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
22350 @@ -893,7 +913,7 @@ int in_gate_area_no_mm(unsigned long add
22351
22352 const char *arch_vma_name(struct vm_area_struct *vma)
22353 {
22354 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
22355 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
22356 return "[vdso]";
22357 if (vma == &gate_vma)
22358 return "[vsyscall]";
22359 diff -urNp linux-2.6.39.2/arch/x86/mm/init.c linux-2.6.39.2/arch/x86/mm/init.c
22360 --- linux-2.6.39.2/arch/x86/mm/init.c 2011-05-19 00:06:34.000000000 -0400
22361 +++ linux-2.6.39.2/arch/x86/mm/init.c 2011-06-07 19:41:11.000000000 -0400
22362 @@ -33,7 +33,7 @@ int direct_gbpages
22363 static void __init find_early_table_space(unsigned long end, int use_pse,
22364 int use_gbpages)
22365 {
22366 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22367 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22368 phys_addr_t base;
22369
22370 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22371 @@ -315,12 +315,34 @@ unsigned long __init_refok init_memory_m
22372 */
22373 int devmem_is_allowed(unsigned long pagenr)
22374 {
22375 - if (pagenr <= 256)
22376 +#ifdef CONFIG_GRKERNSEC_KMEM
22377 + /* allow BDA */
22378 + if (!pagenr)
22379 + return 1;
22380 + /* allow EBDA */
22381 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22382 + return 1;
22383 +#else
22384 + if (!pagenr)
22385 + return 1;
22386 +#ifdef CONFIG_VM86
22387 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22388 + return 1;
22389 +#endif
22390 +#endif
22391 +
22392 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22393 return 1;
22394 +#ifdef CONFIG_GRKERNSEC_KMEM
22395 + /* throw out everything else below 1MB */
22396 + if (pagenr <= 256)
22397 + return 0;
22398 +#endif
22399 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22400 return 0;
22401 if (!page_is_ram(pagenr))
22402 return 1;
22403 +
22404 return 0;
22405 }
22406
22407 @@ -375,6 +397,86 @@ void free_init_pages(char *what, unsigne
22408
22409 void free_initmem(void)
22410 {
22411 +
22412 +#ifdef CONFIG_PAX_KERNEXEC
22413 +#ifdef CONFIG_X86_32
22414 + /* PaX: limit KERNEL_CS to actual size */
22415 + unsigned long addr, limit;
22416 + struct desc_struct d;
22417 + int cpu;
22418 +
22419 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22420 + limit = (limit - 1UL) >> PAGE_SHIFT;
22421 +
22422 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22423 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
22424 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22425 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22426 + }
22427 +
22428 + /* PaX: make KERNEL_CS read-only */
22429 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22430 + if (!paravirt_enabled())
22431 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22432 +/*
22433 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22434 + pgd = pgd_offset_k(addr);
22435 + pud = pud_offset(pgd, addr);
22436 + pmd = pmd_offset(pud, addr);
22437 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22438 + }
22439 +*/
22440 +#ifdef CONFIG_X86_PAE
22441 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22442 +/*
22443 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22444 + pgd = pgd_offset_k(addr);
22445 + pud = pud_offset(pgd, addr);
22446 + pmd = pmd_offset(pud, addr);
22447 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22448 + }
22449 +*/
22450 +#endif
22451 +
22452 +#ifdef CONFIG_MODULES
22453 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22454 +#endif
22455 +
22456 +#else
22457 + pgd_t *pgd;
22458 + pud_t *pud;
22459 + pmd_t *pmd;
22460 + unsigned long addr, end;
22461 +
22462 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22463 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22464 + pgd = pgd_offset_k(addr);
22465 + pud = pud_offset(pgd, addr);
22466 + pmd = pmd_offset(pud, addr);
22467 + if (!pmd_present(*pmd))
22468 + continue;
22469 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22470 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22471 + else
22472 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22473 + }
22474 +
22475 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22476 + end = addr + KERNEL_IMAGE_SIZE;
22477 + for (; addr < end; addr += PMD_SIZE) {
22478 + pgd = pgd_offset_k(addr);
22479 + pud = pud_offset(pgd, addr);
22480 + pmd = pmd_offset(pud, addr);
22481 + if (!pmd_present(*pmd))
22482 + continue;
22483 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22484 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22485 + }
22486 +#endif
22487 +
22488 + flush_tlb_all();
22489 +#endif
22490 +
22491 free_init_pages("unused kernel memory",
22492 (unsigned long)(&__init_begin),
22493 (unsigned long)(&__init_end));
22494 diff -urNp linux-2.6.39.2/arch/x86/mm/iomap_32.c linux-2.6.39.2/arch/x86/mm/iomap_32.c
22495 --- linux-2.6.39.2/arch/x86/mm/iomap_32.c 2011-05-19 00:06:34.000000000 -0400
22496 +++ linux-2.6.39.2/arch/x86/mm/iomap_32.c 2011-05-22 19:36:30.000000000 -0400
22497 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long
22498 type = kmap_atomic_idx_push();
22499 idx = type + KM_TYPE_NR * smp_processor_id();
22500 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22501 +
22502 + pax_open_kernel();
22503 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
22504 + pax_close_kernel();
22505 +
22506 arch_flush_lazy_mmu_mode();
22507
22508 return (void *)vaddr;
22509 diff -urNp linux-2.6.39.2/arch/x86/mm/ioremap.c linux-2.6.39.2/arch/x86/mm/ioremap.c
22510 --- linux-2.6.39.2/arch/x86/mm/ioremap.c 2011-05-19 00:06:34.000000000 -0400
22511 +++ linux-2.6.39.2/arch/x86/mm/ioremap.c 2011-05-22 19:36:30.000000000 -0400
22512 @@ -104,7 +104,7 @@ static void __iomem *__ioremap_caller(re
22513 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
22514 int is_ram = page_is_ram(pfn);
22515
22516 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
22517 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
22518 return NULL;
22519 WARN_ON_ONCE(is_ram);
22520 }
22521 @@ -344,7 +344,7 @@ static int __init early_ioremap_debug_se
22522 early_param("early_ioremap_debug", early_ioremap_debug_setup);
22523
22524 static __initdata int after_paging_init;
22525 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
22526 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
22527
22528 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
22529 {
22530 @@ -381,8 +381,7 @@ void __init early_ioremap_init(void)
22531 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
22532
22533 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
22534 - memset(bm_pte, 0, sizeof(bm_pte));
22535 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
22536 + pmd_populate_user(&init_mm, pmd, bm_pte);
22537
22538 /*
22539 * The boot-ioremap range spans multiple pmds, for which
22540 diff -urNp linux-2.6.39.2/arch/x86/mm/kmemcheck/kmemcheck.c linux-2.6.39.2/arch/x86/mm/kmemcheck/kmemcheck.c
22541 --- linux-2.6.39.2/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-19 00:06:34.000000000 -0400
22542 +++ linux-2.6.39.2/arch/x86/mm/kmemcheck/kmemcheck.c 2011-05-22 19:36:30.000000000 -0400
22543 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *reg
22544 * memory (e.g. tracked pages)? For now, we need this to avoid
22545 * invoking kmemcheck for PnP BIOS calls.
22546 */
22547 - if (regs->flags & X86_VM_MASK)
22548 + if (v8086_mode(regs))
22549 return false;
22550 - if (regs->cs != __KERNEL_CS)
22551 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
22552 return false;
22553
22554 pte = kmemcheck_pte_lookup(address);
22555 diff -urNp linux-2.6.39.2/arch/x86/mm/mmap.c linux-2.6.39.2/arch/x86/mm/mmap.c
22556 --- linux-2.6.39.2/arch/x86/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
22557 +++ linux-2.6.39.2/arch/x86/mm/mmap.c 2011-05-22 19:36:30.000000000 -0400
22558 @@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size
22559 * Leave an at least ~128 MB hole with possible stack randomization.
22560 */
22561 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
22562 -#define MAX_GAP (TASK_SIZE/6*5)
22563 +#define MAX_GAP (pax_task_size/6*5)
22564
22565 /*
22566 * True on X86_32 or when emulating IA32 on X86_64
22567 @@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
22568 return rnd << PAGE_SHIFT;
22569 }
22570
22571 -static unsigned long mmap_base(void)
22572 +static unsigned long mmap_base(struct mm_struct *mm)
22573 {
22574 unsigned long gap = rlimit(RLIMIT_STACK);
22575 + unsigned long pax_task_size = TASK_SIZE;
22576 +
22577 +#ifdef CONFIG_PAX_SEGMEXEC
22578 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22579 + pax_task_size = SEGMEXEC_TASK_SIZE;
22580 +#endif
22581
22582 if (gap < MIN_GAP)
22583 gap = MIN_GAP;
22584 else if (gap > MAX_GAP)
22585 gap = MAX_GAP;
22586
22587 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
22588 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
22589 }
22590
22591 /*
22592 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
22593 * does, but not when emulating X86_32
22594 */
22595 -static unsigned long mmap_legacy_base(void)
22596 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
22597 {
22598 - if (mmap_is_ia32())
22599 + if (mmap_is_ia32()) {
22600 +
22601 +#ifdef CONFIG_PAX_SEGMEXEC
22602 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22603 + return SEGMEXEC_TASK_UNMAPPED_BASE;
22604 + else
22605 +#endif
22606 +
22607 return TASK_UNMAPPED_BASE;
22608 - else
22609 + } else
22610 return TASK_UNMAPPED_BASE + mmap_rnd();
22611 }
22612
22613 @@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(vo
22614 void arch_pick_mmap_layout(struct mm_struct *mm)
22615 {
22616 if (mmap_is_legacy()) {
22617 - mm->mmap_base = mmap_legacy_base();
22618 + mm->mmap_base = mmap_legacy_base(mm);
22619 +
22620 +#ifdef CONFIG_PAX_RANDMMAP
22621 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22622 + mm->mmap_base += mm->delta_mmap;
22623 +#endif
22624 +
22625 mm->get_unmapped_area = arch_get_unmapped_area;
22626 mm->unmap_area = arch_unmap_area;
22627 } else {
22628 - mm->mmap_base = mmap_base();
22629 + mm->mmap_base = mmap_base(mm);
22630 +
22631 +#ifdef CONFIG_PAX_RANDMMAP
22632 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22633 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
22634 +#endif
22635 +
22636 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
22637 mm->unmap_area = arch_unmap_area_topdown;
22638 }
22639 diff -urNp linux-2.6.39.2/arch/x86/mm/mmio-mod.c linux-2.6.39.2/arch/x86/mm/mmio-mod.c
22640 --- linux-2.6.39.2/arch/x86/mm/mmio-mod.c 2011-05-19 00:06:34.000000000 -0400
22641 +++ linux-2.6.39.2/arch/x86/mm/mmio-mod.c 2011-05-22 19:36:30.000000000 -0400
22642 @@ -235,7 +235,7 @@ static void post(struct kmmio_probe *p,
22643 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
22644 void __iomem *addr)
22645 {
22646 - static atomic_t next_id;
22647 + static atomic_unchecked_t next_id;
22648 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
22649 /* These are page-unaligned. */
22650 struct mmiotrace_map map = {
22651 @@ -259,7 +259,7 @@ static void ioremap_trace_core(resource_
22652 .private = trace
22653 },
22654 .phys = offset,
22655 - .id = atomic_inc_return(&next_id)
22656 + .id = atomic_inc_return_unchecked(&next_id)
22657 };
22658 map.map_id = trace->id;
22659
22660 diff -urNp linux-2.6.39.2/arch/x86/mm/numa_32.c linux-2.6.39.2/arch/x86/mm/numa_32.c
22661 --- linux-2.6.39.2/arch/x86/mm/numa_32.c 2011-05-19 00:06:34.000000000 -0400
22662 +++ linux-2.6.39.2/arch/x86/mm/numa_32.c 2011-05-22 19:36:30.000000000 -0400
22663 @@ -99,7 +99,6 @@ unsigned long node_memmap_size_bytes(int
22664 }
22665 #endif
22666
22667 -extern unsigned long find_max_low_pfn(void);
22668 extern unsigned long highend_pfn, highstart_pfn;
22669
22670 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
22671 diff -urNp linux-2.6.39.2/arch/x86/mm/pageattr.c linux-2.6.39.2/arch/x86/mm/pageattr.c
22672 --- linux-2.6.39.2/arch/x86/mm/pageattr.c 2011-05-19 00:06:34.000000000 -0400
22673 +++ linux-2.6.39.2/arch/x86/mm/pageattr.c 2011-05-22 19:36:30.000000000 -0400
22674 @@ -261,7 +261,7 @@ static inline pgprot_t static_protection
22675 */
22676 #ifdef CONFIG_PCI_BIOS
22677 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
22678 - pgprot_val(forbidden) |= _PAGE_NX;
22679 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22680 #endif
22681
22682 /*
22683 @@ -269,9 +269,10 @@ static inline pgprot_t static_protection
22684 * Does not cover __inittext since that is gone later on. On
22685 * 64bit we do not enforce !NX on the low mapping
22686 */
22687 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
22688 - pgprot_val(forbidden) |= _PAGE_NX;
22689 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
22690 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22691
22692 +#ifdef CONFIG_DEBUG_RODATA
22693 /*
22694 * The .rodata section needs to be read-only. Using the pfn
22695 * catches all aliases.
22696 @@ -279,6 +280,7 @@ static inline pgprot_t static_protection
22697 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
22698 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
22699 pgprot_val(forbidden) |= _PAGE_RW;
22700 +#endif
22701
22702 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
22703 /*
22704 @@ -317,6 +319,13 @@ static inline pgprot_t static_protection
22705 }
22706 #endif
22707
22708 +#ifdef CONFIG_PAX_KERNEXEC
22709 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
22710 + pgprot_val(forbidden) |= _PAGE_RW;
22711 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
22712 + }
22713 +#endif
22714 +
22715 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
22716
22717 return prot;
22718 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
22719 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
22720 {
22721 /* change init_mm */
22722 + pax_open_kernel();
22723 set_pte_atomic(kpte, pte);
22724 +
22725 #ifdef CONFIG_X86_32
22726 if (!SHARED_KERNEL_PMD) {
22727 +
22728 +#ifdef CONFIG_PAX_PER_CPU_PGD
22729 + unsigned long cpu;
22730 +#else
22731 struct page *page;
22732 +#endif
22733
22734 +#ifdef CONFIG_PAX_PER_CPU_PGD
22735 + for (cpu = 0; cpu < NR_CPUS; ++cpu) {
22736 + pgd_t *pgd = get_cpu_pgd(cpu);
22737 +#else
22738 list_for_each_entry(page, &pgd_list, lru) {
22739 - pgd_t *pgd;
22740 + pgd_t *pgd = (pgd_t *)page_address(page);
22741 +#endif
22742 +
22743 pud_t *pud;
22744 pmd_t *pmd;
22745
22746 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
22747 + pgd += pgd_index(address);
22748 pud = pud_offset(pgd, address);
22749 pmd = pmd_offset(pud, address);
22750 set_pte_atomic((pte_t *)pmd, pte);
22751 }
22752 }
22753 #endif
22754 + pax_close_kernel();
22755 }
22756
22757 static int
22758 diff -urNp linux-2.6.39.2/arch/x86/mm/pageattr-test.c linux-2.6.39.2/arch/x86/mm/pageattr-test.c
22759 --- linux-2.6.39.2/arch/x86/mm/pageattr-test.c 2011-05-19 00:06:34.000000000 -0400
22760 +++ linux-2.6.39.2/arch/x86/mm/pageattr-test.c 2011-05-22 19:36:30.000000000 -0400
22761 @@ -36,7 +36,7 @@ enum {
22762
22763 static int pte_testbit(pte_t pte)
22764 {
22765 - return pte_flags(pte) & _PAGE_UNUSED1;
22766 + return pte_flags(pte) & _PAGE_CPA_TEST;
22767 }
22768
22769 struct split_state {
22770 diff -urNp linux-2.6.39.2/arch/x86/mm/pat.c linux-2.6.39.2/arch/x86/mm/pat.c
22771 --- linux-2.6.39.2/arch/x86/mm/pat.c 2011-05-19 00:06:34.000000000 -0400
22772 +++ linux-2.6.39.2/arch/x86/mm/pat.c 2011-05-22 19:36:30.000000000 -0400
22773 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
22774
22775 if (!entry) {
22776 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
22777 - current->comm, current->pid, start, end);
22778 + current->comm, task_pid_nr(current), start, end);
22779 return -EINVAL;
22780 }
22781
22782 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsig
22783 while (cursor < to) {
22784 if (!devmem_is_allowed(pfn)) {
22785 printk(KERN_INFO
22786 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
22787 - current->comm, from, to);
22788 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
22789 + current->comm, from, to, cursor);
22790 return 0;
22791 }
22792 cursor += PAGE_SIZE;
22793 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, un
22794 printk(KERN_INFO
22795 "%s:%d ioremap_change_attr failed %s "
22796 "for %Lx-%Lx\n",
22797 - current->comm, current->pid,
22798 + current->comm, task_pid_nr(current),
22799 cattr_name(flags),
22800 base, (unsigned long long)(base + size));
22801 return -EINVAL;
22802 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr,
22803 if (want_flags != flags) {
22804 printk(KERN_WARNING
22805 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
22806 - current->comm, current->pid,
22807 + current->comm, task_pid_nr(current),
22808 cattr_name(want_flags),
22809 (unsigned long long)paddr,
22810 (unsigned long long)(paddr + size),
22811 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr,
22812 free_memtype(paddr, paddr + size);
22813 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
22814 " for %Lx-%Lx, got %s\n",
22815 - current->comm, current->pid,
22816 + current->comm, task_pid_nr(current),
22817 cattr_name(want_flags),
22818 (unsigned long long)paddr,
22819 (unsigned long long)(paddr + size),
22820 diff -urNp linux-2.6.39.2/arch/x86/mm/pgtable_32.c linux-2.6.39.2/arch/x86/mm/pgtable_32.c
22821 --- linux-2.6.39.2/arch/x86/mm/pgtable_32.c 2011-05-19 00:06:34.000000000 -0400
22822 +++ linux-2.6.39.2/arch/x86/mm/pgtable_32.c 2011-05-22 19:36:30.000000000 -0400
22823 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr,
22824 return;
22825 }
22826 pte = pte_offset_kernel(pmd, vaddr);
22827 +
22828 + pax_open_kernel();
22829 if (pte_val(pteval))
22830 set_pte_at(&init_mm, vaddr, pte, pteval);
22831 else
22832 pte_clear(&init_mm, vaddr, pte);
22833 + pax_close_kernel();
22834
22835 /*
22836 * It's enough to flush this one mapping.
22837 diff -urNp linux-2.6.39.2/arch/x86/mm/pgtable.c linux-2.6.39.2/arch/x86/mm/pgtable.c
22838 --- linux-2.6.39.2/arch/x86/mm/pgtable.c 2011-05-19 00:06:34.000000000 -0400
22839 +++ linux-2.6.39.2/arch/x86/mm/pgtable.c 2011-05-22 19:36:30.000000000 -0400
22840 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *p
22841 list_del(&page->lru);
22842 }
22843
22844 -#define UNSHARED_PTRS_PER_PGD \
22845 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22846 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22847 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
22848
22849 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22850 +{
22851 + while (count--)
22852 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
22853 +}
22854 +#endif
22855 +
22856 +#ifdef CONFIG_PAX_PER_CPU_PGD
22857 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
22858 +{
22859 + while (count--)
22860 +
22861 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22862 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
22863 +#else
22864 + *dst++ = *src++;
22865 +#endif
22866
22867 +}
22868 +#endif
22869 +
22870 +#ifdef CONFIG_X86_64
22871 +#define pxd_t pud_t
22872 +#define pyd_t pgd_t
22873 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
22874 +#define pxd_free(mm, pud) pud_free((mm), (pud))
22875 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
22876 +#define pyd_offset(mm ,address) pgd_offset((mm), (address))
22877 +#define PYD_SIZE PGDIR_SIZE
22878 +#else
22879 +#define pxd_t pmd_t
22880 +#define pyd_t pud_t
22881 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
22882 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
22883 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
22884 +#define pyd_offset(mm ,address) pud_offset((mm), (address))
22885 +#define PYD_SIZE PUD_SIZE
22886 +#endif
22887 +
22888 +#ifdef CONFIG_PAX_PER_CPU_PGD
22889 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
22890 +static inline void pgd_dtor(pgd_t *pgd) {}
22891 +#else
22892 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
22893 {
22894 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
22895 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
22896 pgd_list_del(pgd);
22897 spin_unlock(&pgd_lock);
22898 }
22899 +#endif
22900
22901 /*
22902 * List of all pgd's needed for non-PAE so it can invalidate entries
22903 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
22904 * -- wli
22905 */
22906
22907 -#ifdef CONFIG_X86_PAE
22908 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
22909 /*
22910 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
22911 * updating the top-level pagetable entries to guarantee the
22912 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
22913 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
22914 * and initialize the kernel pmds here.
22915 */
22916 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
22917 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
22918
22919 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
22920 {
22921 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm,
22922 */
22923 flush_tlb_mm(mm);
22924 }
22925 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
22926 +#define PREALLOCATED_PXDS USER_PGD_PTRS
22927 #else /* !CONFIG_X86_PAE */
22928
22929 /* No need to prepopulate any pagetable entries in non-PAE modes. */
22930 -#define PREALLOCATED_PMDS 0
22931 +#define PREALLOCATED_PXDS 0
22932
22933 #endif /* CONFIG_X86_PAE */
22934
22935 -static void free_pmds(pmd_t *pmds[])
22936 +static void free_pxds(pxd_t *pxds[])
22937 {
22938 int i;
22939
22940 - for(i = 0; i < PREALLOCATED_PMDS; i++)
22941 - if (pmds[i])
22942 - free_page((unsigned long)pmds[i]);
22943 + for(i = 0; i < PREALLOCATED_PXDS; i++)
22944 + if (pxds[i])
22945 + free_page((unsigned long)pxds[i]);
22946 }
22947
22948 -static int preallocate_pmds(pmd_t *pmds[])
22949 +static int preallocate_pxds(pxd_t *pxds[])
22950 {
22951 int i;
22952 bool failed = false;
22953
22954 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22955 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
22956 - if (pmd == NULL)
22957 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22958 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
22959 + if (pxd == NULL)
22960 failed = true;
22961 - pmds[i] = pmd;
22962 + pxds[i] = pxd;
22963 }
22964
22965 if (failed) {
22966 - free_pmds(pmds);
22967 + free_pxds(pxds);
22968 return -ENOMEM;
22969 }
22970
22971 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[
22972 * preallocate which never got a corresponding vma will need to be
22973 * freed manually.
22974 */
22975 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
22976 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
22977 {
22978 int i;
22979
22980 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
22981 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
22982 pgd_t pgd = pgdp[i];
22983
22984 if (pgd_val(pgd) != 0) {
22985 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
22986 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
22987
22988 - pgdp[i] = native_make_pgd(0);
22989 + set_pgd(pgdp + i, native_make_pgd(0));
22990
22991 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
22992 - pmd_free(mm, pmd);
22993 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
22994 + pxd_free(mm, pxd);
22995 }
22996 }
22997 }
22998
22999 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23000 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23001 {
23002 - pud_t *pud;
23003 + pyd_t *pyd;
23004 unsigned long addr;
23005 int i;
23006
23007 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23008 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23009 return;
23010
23011 - pud = pud_offset(pgd, 0);
23012 +#ifdef CONFIG_X86_64
23013 + pyd = pyd_offset(mm, 0L);
23014 +#else
23015 + pyd = pyd_offset(pgd, 0L);
23016 +#endif
23017
23018 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23019 - i++, pud++, addr += PUD_SIZE) {
23020 - pmd_t *pmd = pmds[i];
23021 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23022 + i++, pyd++, addr += PYD_SIZE) {
23023 + pxd_t *pxd = pxds[i];
23024
23025 if (i >= KERNEL_PGD_BOUNDARY)
23026 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23027 - sizeof(pmd_t) * PTRS_PER_PMD);
23028 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23029 + sizeof(pxd_t) * PTRS_PER_PMD);
23030
23031 - pud_populate(mm, pud, pmd);
23032 + pyd_populate(mm, pyd, pxd);
23033 }
23034 }
23035
23036 pgd_t *pgd_alloc(struct mm_struct *mm)
23037 {
23038 pgd_t *pgd;
23039 - pmd_t *pmds[PREALLOCATED_PMDS];
23040 + pxd_t *pxds[PREALLOCATED_PXDS];
23041
23042 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23043
23044 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23045
23046 mm->pgd = pgd;
23047
23048 - if (preallocate_pmds(pmds) != 0)
23049 + if (preallocate_pxds(pxds) != 0)
23050 goto out_free_pgd;
23051
23052 if (paravirt_pgd_alloc(mm) != 0)
23053 - goto out_free_pmds;
23054 + goto out_free_pxds;
23055
23056 /*
23057 * Make sure that pre-populating the pmds is atomic with
23058 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23059 spin_lock(&pgd_lock);
23060
23061 pgd_ctor(mm, pgd);
23062 - pgd_prepopulate_pmd(mm, pgd, pmds);
23063 + pgd_prepopulate_pxd(mm, pgd, pxds);
23064
23065 spin_unlock(&pgd_lock);
23066
23067 return pgd;
23068
23069 -out_free_pmds:
23070 - free_pmds(pmds);
23071 +out_free_pxds:
23072 + free_pxds(pxds);
23073 out_free_pgd:
23074 free_page((unsigned long)pgd);
23075 out:
23076 @@ -295,7 +344,7 @@ out:
23077
23078 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23079 {
23080 - pgd_mop_up_pmds(mm, pgd);
23081 + pgd_mop_up_pxds(mm, pgd);
23082 pgd_dtor(pgd);
23083 paravirt_pgd_free(mm, pgd);
23084 free_page((unsigned long)pgd);
23085 diff -urNp linux-2.6.39.2/arch/x86/mm/setup_nx.c linux-2.6.39.2/arch/x86/mm/setup_nx.c
23086 --- linux-2.6.39.2/arch/x86/mm/setup_nx.c 2011-05-19 00:06:34.000000000 -0400
23087 +++ linux-2.6.39.2/arch/x86/mm/setup_nx.c 2011-05-22 19:36:30.000000000 -0400
23088 @@ -5,8 +5,10 @@
23089 #include <asm/pgtable.h>
23090 #include <asm/proto.h>
23091
23092 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23093 static int disable_nx __cpuinitdata;
23094
23095 +#ifndef CONFIG_PAX_PAGEEXEC
23096 /*
23097 * noexec = on|off
23098 *
23099 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str
23100 return 0;
23101 }
23102 early_param("noexec", noexec_setup);
23103 +#endif
23104 +
23105 +#endif
23106
23107 void __cpuinit x86_configure_nx(void)
23108 {
23109 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23110 if (cpu_has_nx && !disable_nx)
23111 __supported_pte_mask |= _PAGE_NX;
23112 else
23113 +#endif
23114 __supported_pte_mask &= ~_PAGE_NX;
23115 }
23116
23117 diff -urNp linux-2.6.39.2/arch/x86/mm/tlb.c linux-2.6.39.2/arch/x86/mm/tlb.c
23118 --- linux-2.6.39.2/arch/x86/mm/tlb.c 2011-05-19 00:06:34.000000000 -0400
23119 +++ linux-2.6.39.2/arch/x86/mm/tlb.c 2011-05-22 19:36:30.000000000 -0400
23120 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23121 BUG();
23122 cpumask_clear_cpu(cpu,
23123 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23124 +
23125 +#ifndef CONFIG_PAX_PER_CPU_PGD
23126 load_cr3(swapper_pg_dir);
23127 +#endif
23128 +
23129 }
23130 EXPORT_SYMBOL_GPL(leave_mm);
23131
23132 diff -urNp linux-2.6.39.2/arch/x86/oprofile/backtrace.c linux-2.6.39.2/arch/x86/oprofile/backtrace.c
23133 --- linux-2.6.39.2/arch/x86/oprofile/backtrace.c 2011-05-19 00:06:34.000000000 -0400
23134 +++ linux-2.6.39.2/arch/x86/oprofile/backtrace.c 2011-05-22 19:36:30.000000000 -0400
23135 @@ -57,7 +57,7 @@ dump_user_backtrace_32(struct stack_fram
23136 struct stack_frame_ia32 *fp;
23137
23138 /* Also check accessibility of one struct frame_head beyond */
23139 - if (!access_ok(VERIFY_READ, head, sizeof(bufhead)))
23140 + if (!__access_ok(VERIFY_READ, head, sizeof(bufhead)))
23141 return NULL;
23142 if (__copy_from_user_inatomic(bufhead, head, sizeof(bufhead)))
23143 return NULL;
23144 @@ -123,7 +123,7 @@ x86_backtrace(struct pt_regs * const reg
23145 {
23146 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
23147
23148 - if (!user_mode_vm(regs)) {
23149 + if (!user_mode(regs)) {
23150 unsigned long stack = kernel_stack_pointer(regs);
23151 if (depth)
23152 dump_trace(NULL, regs, (unsigned long *)stack, 0,
23153 diff -urNp linux-2.6.39.2/arch/x86/pci/ce4100.c linux-2.6.39.2/arch/x86/pci/ce4100.c
23154 --- linux-2.6.39.2/arch/x86/pci/ce4100.c 2011-05-19 00:06:34.000000000 -0400
23155 +++ linux-2.6.39.2/arch/x86/pci/ce4100.c 2011-05-22 19:36:30.000000000 -0400
23156 @@ -302,7 +302,7 @@ static int ce4100_conf_write(unsigned in
23157 return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
23158 }
23159
23160 -struct pci_raw_ops ce4100_pci_conf = {
23161 +const struct pci_raw_ops ce4100_pci_conf = {
23162 .read = ce4100_conf_read,
23163 .write = ce4100_conf_write,
23164 };
23165 diff -urNp linux-2.6.39.2/arch/x86/pci/common.c linux-2.6.39.2/arch/x86/pci/common.c
23166 --- linux-2.6.39.2/arch/x86/pci/common.c 2011-05-19 00:06:34.000000000 -0400
23167 +++ linux-2.6.39.2/arch/x86/pci/common.c 2011-05-22 19:36:30.000000000 -0400
23168 @@ -33,8 +33,8 @@ int noioapicreroute = 1;
23169 int pcibios_last_bus = -1;
23170 unsigned long pirq_table_addr;
23171 struct pci_bus *pci_root_bus;
23172 -struct pci_raw_ops *raw_pci_ops;
23173 -struct pci_raw_ops *raw_pci_ext_ops;
23174 +const struct pci_raw_ops *raw_pci_ops;
23175 +const struct pci_raw_ops *raw_pci_ext_ops;
23176
23177 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
23178 int reg, int len, u32 *val)
23179 diff -urNp linux-2.6.39.2/arch/x86/pci/direct.c linux-2.6.39.2/arch/x86/pci/direct.c
23180 --- linux-2.6.39.2/arch/x86/pci/direct.c 2011-05-19 00:06:34.000000000 -0400
23181 +++ linux-2.6.39.2/arch/x86/pci/direct.c 2011-05-22 19:36:30.000000000 -0400
23182 @@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int
23183
23184 #undef PCI_CONF1_ADDRESS
23185
23186 -struct pci_raw_ops pci_direct_conf1 = {
23187 +const struct pci_raw_ops pci_direct_conf1 = {
23188 .read = pci_conf1_read,
23189 .write = pci_conf1_write,
23190 };
23191 @@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int
23192
23193 #undef PCI_CONF2_ADDRESS
23194
23195 -struct pci_raw_ops pci_direct_conf2 = {
23196 +const struct pci_raw_ops pci_direct_conf2 = {
23197 .read = pci_conf2_read,
23198 .write = pci_conf2_write,
23199 };
23200 @@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
23201 * This should be close to trivial, but it isn't, because there are buggy
23202 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
23203 */
23204 -static int __init pci_sanity_check(struct pci_raw_ops *o)
23205 +static int __init pci_sanity_check(const struct pci_raw_ops *o)
23206 {
23207 u32 x = 0;
23208 int year, devfn;
23209 diff -urNp linux-2.6.39.2/arch/x86/pci/fixup.c linux-2.6.39.2/arch/x86/pci/fixup.c
23210 --- linux-2.6.39.2/arch/x86/pci/fixup.c 2011-05-19 00:06:34.000000000 -0400
23211 +++ linux-2.6.39.2/arch/x86/pci/fixup.c 2011-05-22 19:36:30.000000000 -0400
23212 @@ -435,7 +435,7 @@ static const struct dmi_system_id __devi
23213 DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
23214 },
23215 },
23216 - { }
23217 + {}
23218 };
23219
23220 static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
23221 diff -urNp linux-2.6.39.2/arch/x86/pci/mmconfig_32.c linux-2.6.39.2/arch/x86/pci/mmconfig_32.c
23222 --- linux-2.6.39.2/arch/x86/pci/mmconfig_32.c 2011-05-19 00:06:34.000000000 -0400
23223 +++ linux-2.6.39.2/arch/x86/pci/mmconfig_32.c 2011-05-22 19:36:30.000000000 -0400
23224 @@ -117,7 +117,7 @@ static int pci_mmcfg_write(unsigned int
23225 return 0;
23226 }
23227
23228 -static struct pci_raw_ops pci_mmcfg = {
23229 +static const struct pci_raw_ops pci_mmcfg = {
23230 .read = pci_mmcfg_read,
23231 .write = pci_mmcfg_write,
23232 };
23233 diff -urNp linux-2.6.39.2/arch/x86/pci/mmconfig_64.c linux-2.6.39.2/arch/x86/pci/mmconfig_64.c
23234 --- linux-2.6.39.2/arch/x86/pci/mmconfig_64.c 2011-05-19 00:06:34.000000000 -0400
23235 +++ linux-2.6.39.2/arch/x86/pci/mmconfig_64.c 2011-05-22 19:36:30.000000000 -0400
23236 @@ -81,7 +81,7 @@ static int pci_mmcfg_write(unsigned int
23237 return 0;
23238 }
23239
23240 -static struct pci_raw_ops pci_mmcfg = {
23241 +static const struct pci_raw_ops pci_mmcfg = {
23242 .read = pci_mmcfg_read,
23243 .write = pci_mmcfg_write,
23244 };
23245 diff -urNp linux-2.6.39.2/arch/x86/pci/mrst.c linux-2.6.39.2/arch/x86/pci/mrst.c
23246 --- linux-2.6.39.2/arch/x86/pci/mrst.c 2011-05-19 00:06:34.000000000 -0400
23247 +++ linux-2.6.39.2/arch/x86/pci/mrst.c 2011-05-22 19:36:30.000000000 -0400
23248 @@ -218,7 +218,7 @@ static int mrst_pci_irq_enable(struct pc
23249 return 0;
23250 }
23251
23252 -struct pci_ops pci_mrst_ops = {
23253 +const struct pci_ops pci_mrst_ops = {
23254 .read = pci_read,
23255 .write = pci_write,
23256 };
23257 diff -urNp linux-2.6.39.2/arch/x86/pci/numaq_32.c linux-2.6.39.2/arch/x86/pci/numaq_32.c
23258 --- linux-2.6.39.2/arch/x86/pci/numaq_32.c 2011-05-19 00:06:34.000000000 -0400
23259 +++ linux-2.6.39.2/arch/x86/pci/numaq_32.c 2011-05-22 19:36:30.000000000 -0400
23260 @@ -108,7 +108,7 @@ static int pci_conf1_mq_write(unsigned i
23261
23262 #undef PCI_CONF1_MQ_ADDRESS
23263
23264 -static struct pci_raw_ops pci_direct_conf1_mq = {
23265 +static const struct pci_raw_ops pci_direct_conf1_mq = {
23266 .read = pci_conf1_mq_read,
23267 .write = pci_conf1_mq_write
23268 };
23269 diff -urNp linux-2.6.39.2/arch/x86/pci/olpc.c linux-2.6.39.2/arch/x86/pci/olpc.c
23270 --- linux-2.6.39.2/arch/x86/pci/olpc.c 2011-05-19 00:06:34.000000000 -0400
23271 +++ linux-2.6.39.2/arch/x86/pci/olpc.c 2011-05-22 19:36:30.000000000 -0400
23272 @@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int s
23273 return 0;
23274 }
23275
23276 -static struct pci_raw_ops pci_olpc_conf = {
23277 +static const struct pci_raw_ops pci_olpc_conf = {
23278 .read = pci_olpc_read,
23279 .write = pci_olpc_write,
23280 };
23281 diff -urNp linux-2.6.39.2/arch/x86/pci/pcbios.c linux-2.6.39.2/arch/x86/pci/pcbios.c
23282 --- linux-2.6.39.2/arch/x86/pci/pcbios.c 2011-05-19 00:06:34.000000000 -0400
23283 +++ linux-2.6.39.2/arch/x86/pci/pcbios.c 2011-05-22 19:36:30.000000000 -0400
23284 @@ -79,50 +79,93 @@ union bios32 {
23285 static struct {
23286 unsigned long address;
23287 unsigned short segment;
23288 -} bios32_indirect = { 0, __KERNEL_CS };
23289 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
23290
23291 /*
23292 * Returns the entry point for the given service, NULL on error
23293 */
23294
23295 -static unsigned long bios32_service(unsigned long service)
23296 +static unsigned long __devinit bios32_service(unsigned long service)
23297 {
23298 unsigned char return_code; /* %al */
23299 unsigned long address; /* %ebx */
23300 unsigned long length; /* %ecx */
23301 unsigned long entry; /* %edx */
23302 unsigned long flags;
23303 + struct desc_struct d, *gdt;
23304
23305 local_irq_save(flags);
23306 - __asm__("lcall *(%%edi); cld"
23307 +
23308 + gdt = get_cpu_gdt_table(smp_processor_id());
23309 +
23310 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
23311 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23312 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
23313 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23314 +
23315 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
23316 : "=a" (return_code),
23317 "=b" (address),
23318 "=c" (length),
23319 "=d" (entry)
23320 : "0" (service),
23321 "1" (0),
23322 - "D" (&bios32_indirect));
23323 + "D" (&bios32_indirect),
23324 + "r"(__PCIBIOS_DS)
23325 + : "memory");
23326 +
23327 + pax_open_kernel();
23328 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
23329 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
23330 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
23331 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
23332 + pax_close_kernel();
23333 +
23334 local_irq_restore(flags);
23335
23336 switch (return_code) {
23337 - case 0:
23338 - return address + entry;
23339 - case 0x80: /* Not present */
23340 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23341 - return 0;
23342 - default: /* Shouldn't happen */
23343 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23344 - service, return_code);
23345 + case 0: {
23346 + int cpu;
23347 + unsigned char flags;
23348 +
23349 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
23350 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
23351 + printk(KERN_WARNING "bios32_service: not valid\n");
23352 return 0;
23353 + }
23354 + address = address + PAGE_OFFSET;
23355 + length += 16UL; /* some BIOSs underreport this... */
23356 + flags = 4;
23357 + if (length >= 64*1024*1024) {
23358 + length >>= PAGE_SHIFT;
23359 + flags |= 8;
23360 + }
23361 +
23362 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
23363 + gdt = get_cpu_gdt_table(cpu);
23364 + pack_descriptor(&d, address, length, 0x9b, flags);
23365 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
23366 + pack_descriptor(&d, address, length, 0x93, flags);
23367 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
23368 + }
23369 + return entry;
23370 + }
23371 + case 0x80: /* Not present */
23372 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
23373 + return 0;
23374 + default: /* Shouldn't happen */
23375 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
23376 + service, return_code);
23377 + return 0;
23378 }
23379 }
23380
23381 static struct {
23382 unsigned long address;
23383 unsigned short segment;
23384 -} pci_indirect = { 0, __KERNEL_CS };
23385 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
23386
23387 -static int pci_bios_present;
23388 +static int pci_bios_present __read_only;
23389
23390 static int __devinit check_pcibios(void)
23391 {
23392 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
23393 unsigned long flags, pcibios_entry;
23394
23395 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
23396 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
23397 + pci_indirect.address = pcibios_entry;
23398
23399 local_irq_save(flags);
23400 - __asm__(
23401 - "lcall *(%%edi); cld\n\t"
23402 + __asm__("movw %w6, %%ds\n\t"
23403 + "lcall *%%ss:(%%edi); cld\n\t"
23404 + "push %%ss\n\t"
23405 + "pop %%ds\n\t"
23406 "jc 1f\n\t"
23407 "xor %%ah, %%ah\n"
23408 "1:"
23409 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
23410 "=b" (ebx),
23411 "=c" (ecx)
23412 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
23413 - "D" (&pci_indirect)
23414 + "D" (&pci_indirect),
23415 + "r" (__PCIBIOS_DS)
23416 : "memory");
23417 local_irq_restore(flags);
23418
23419 @@ -188,7 +234,10 @@ static int pci_bios_read(unsigned int se
23420
23421 switch (len) {
23422 case 1:
23423 - __asm__("lcall *(%%esi); cld\n\t"
23424 + __asm__("movw %w6, %%ds\n\t"
23425 + "lcall *%%ss:(%%esi); cld\n\t"
23426 + "push %%ss\n\t"
23427 + "pop %%ds\n\t"
23428 "jc 1f\n\t"
23429 "xor %%ah, %%ah\n"
23430 "1:"
23431 @@ -197,7 +246,8 @@ static int pci_bios_read(unsigned int se
23432 : "1" (PCIBIOS_READ_CONFIG_BYTE),
23433 "b" (bx),
23434 "D" ((long)reg),
23435 - "S" (&pci_indirect));
23436 + "S" (&pci_indirect),
23437 + "r" (__PCIBIOS_DS));
23438 /*
23439 * Zero-extend the result beyond 8 bits, do not trust the
23440 * BIOS having done it:
23441 @@ -205,7 +255,10 @@ static int pci_bios_read(unsigned int se
23442 *value &= 0xff;
23443 break;
23444 case 2:
23445 - __asm__("lcall *(%%esi); cld\n\t"
23446 + __asm__("movw %w6, %%ds\n\t"
23447 + "lcall *%%ss:(%%esi); cld\n\t"
23448 + "push %%ss\n\t"
23449 + "pop %%ds\n\t"
23450 "jc 1f\n\t"
23451 "xor %%ah, %%ah\n"
23452 "1:"
23453 @@ -214,7 +267,8 @@ static int pci_bios_read(unsigned int se
23454 : "1" (PCIBIOS_READ_CONFIG_WORD),
23455 "b" (bx),
23456 "D" ((long)reg),
23457 - "S" (&pci_indirect));
23458 + "S" (&pci_indirect),
23459 + "r" (__PCIBIOS_DS));
23460 /*
23461 * Zero-extend the result beyond 16 bits, do not trust the
23462 * BIOS having done it:
23463 @@ -222,7 +276,10 @@ static int pci_bios_read(unsigned int se
23464 *value &= 0xffff;
23465 break;
23466 case 4:
23467 - __asm__("lcall *(%%esi); cld\n\t"
23468 + __asm__("movw %w6, %%ds\n\t"
23469 + "lcall *%%ss:(%%esi); cld\n\t"
23470 + "push %%ss\n\t"
23471 + "pop %%ds\n\t"
23472 "jc 1f\n\t"
23473 "xor %%ah, %%ah\n"
23474 "1:"
23475 @@ -231,7 +288,8 @@ static int pci_bios_read(unsigned int se
23476 : "1" (PCIBIOS_READ_CONFIG_DWORD),
23477 "b" (bx),
23478 "D" ((long)reg),
23479 - "S" (&pci_indirect));
23480 + "S" (&pci_indirect),
23481 + "r" (__PCIBIOS_DS));
23482 break;
23483 }
23484
23485 @@ -254,7 +312,10 @@ static int pci_bios_write(unsigned int s
23486
23487 switch (len) {
23488 case 1:
23489 - __asm__("lcall *(%%esi); cld\n\t"
23490 + __asm__("movw %w6, %%ds\n\t"
23491 + "lcall *%%ss:(%%esi); cld\n\t"
23492 + "push %%ss\n\t"
23493 + "pop %%ds\n\t"
23494 "jc 1f\n\t"
23495 "xor %%ah, %%ah\n"
23496 "1:"
23497 @@ -263,10 +324,14 @@ static int pci_bios_write(unsigned int s
23498 "c" (value),
23499 "b" (bx),
23500 "D" ((long)reg),
23501 - "S" (&pci_indirect));
23502 + "S" (&pci_indirect),
23503 + "r" (__PCIBIOS_DS));
23504 break;
23505 case 2:
23506 - __asm__("lcall *(%%esi); cld\n\t"
23507 + __asm__("movw %w6, %%ds\n\t"
23508 + "lcall *%%ss:(%%esi); cld\n\t"
23509 + "push %%ss\n\t"
23510 + "pop %%ds\n\t"
23511 "jc 1f\n\t"
23512 "xor %%ah, %%ah\n"
23513 "1:"
23514 @@ -275,10 +340,14 @@ static int pci_bios_write(unsigned int s
23515 "c" (value),
23516 "b" (bx),
23517 "D" ((long)reg),
23518 - "S" (&pci_indirect));
23519 + "S" (&pci_indirect),
23520 + "r" (__PCIBIOS_DS));
23521 break;
23522 case 4:
23523 - __asm__("lcall *(%%esi); cld\n\t"
23524 + __asm__("movw %w6, %%ds\n\t"
23525 + "lcall *%%ss:(%%esi); cld\n\t"
23526 + "push %%ss\n\t"
23527 + "pop %%ds\n\t"
23528 "jc 1f\n\t"
23529 "xor %%ah, %%ah\n"
23530 "1:"
23531 @@ -287,7 +356,8 @@ static int pci_bios_write(unsigned int s
23532 "c" (value),
23533 "b" (bx),
23534 "D" ((long)reg),
23535 - "S" (&pci_indirect));
23536 + "S" (&pci_indirect),
23537 + "r" (__PCIBIOS_DS));
23538 break;
23539 }
23540
23541 @@ -301,7 +371,7 @@ static int pci_bios_write(unsigned int s
23542 * Function table for BIOS32 access
23543 */
23544
23545 -static struct pci_raw_ops pci_bios_access = {
23546 +static const struct pci_raw_ops pci_bios_access = {
23547 .read = pci_bios_read,
23548 .write = pci_bios_write
23549 };
23550 @@ -310,7 +380,7 @@ static struct pci_raw_ops pci_bios_acces
23551 * Try to find PCI BIOS.
23552 */
23553
23554 -static struct pci_raw_ops * __devinit pci_find_bios(void)
23555 +static const struct pci_raw_ops * __devinit pci_find_bios(void)
23556 {
23557 union bios32 *check;
23558 unsigned char sum;
23559 @@ -392,10 +462,13 @@ struct irq_routing_table * pcibios_get_i
23560
23561 DBG("PCI: Fetching IRQ routing table... ");
23562 __asm__("push %%es\n\t"
23563 + "movw %w8, %%ds\n\t"
23564 "push %%ds\n\t"
23565 "pop %%es\n\t"
23566 - "lcall *(%%esi); cld\n\t"
23567 + "lcall *%%ss:(%%esi); cld\n\t"
23568 "pop %%es\n\t"
23569 + "push %%ss\n\t"
23570 + "pop %%ds\n"
23571 "jc 1f\n\t"
23572 "xor %%ah, %%ah\n"
23573 "1:"
23574 @@ -406,7 +479,8 @@ struct irq_routing_table * pcibios_get_i
23575 "1" (0),
23576 "D" ((long) &opt),
23577 "S" (&pci_indirect),
23578 - "m" (opt)
23579 + "m" (opt),
23580 + "r" (__PCIBIOS_DS)
23581 : "memory");
23582 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
23583 if (ret & 0xff00)
23584 @@ -430,7 +504,10 @@ int pcibios_set_irq_routing(struct pci_d
23585 {
23586 int ret;
23587
23588 - __asm__("lcall *(%%esi); cld\n\t"
23589 + __asm__("movw %w5, %%ds\n\t"
23590 + "lcall *%%ss:(%%esi); cld\n\t"
23591 + "push %%ss\n\t"
23592 + "pop %%ds\n"
23593 "jc 1f\n\t"
23594 "xor %%ah, %%ah\n"
23595 "1:"
23596 @@ -438,7 +515,8 @@ int pcibios_set_irq_routing(struct pci_d
23597 : "0" (PCIBIOS_SET_PCI_HW_INT),
23598 "b" ((dev->bus->number << 8) | dev->devfn),
23599 "c" ((irq << 8) | (pin + 10)),
23600 - "S" (&pci_indirect));
23601 + "S" (&pci_indirect),
23602 + "r" (__PCIBIOS_DS));
23603 return !(ret & 0xff00);
23604 }
23605 EXPORT_SYMBOL(pcibios_set_irq_routing);
23606 diff -urNp linux-2.6.39.2/arch/x86/pci/xen.c linux-2.6.39.2/arch/x86/pci/xen.c
23607 --- linux-2.6.39.2/arch/x86/pci/xen.c 2011-05-19 00:06:34.000000000 -0400
23608 +++ linux-2.6.39.2/arch/x86/pci/xen.c 2011-05-22 19:36:30.000000000 -0400
23609 @@ -62,7 +62,7 @@ static int acpi_register_gsi_xen_hvm(str
23610 #include <linux/msi.h>
23611 #include <asm/msidef.h>
23612
23613 -struct xen_pci_frontend_ops *xen_pci_frontend;
23614 +const struct xen_pci_frontend_ops *xen_pci_frontend;
23615 EXPORT_SYMBOL_GPL(xen_pci_frontend);
23616
23617 #define XEN_PIRQ_MSI_DATA (MSI_DATA_TRIGGER_EDGE | \
23618 diff -urNp linux-2.6.39.2/arch/x86/platform/efi/efi_32.c linux-2.6.39.2/arch/x86/platform/efi/efi_32.c
23619 --- linux-2.6.39.2/arch/x86/platform/efi/efi_32.c 2011-05-19 00:06:34.000000000 -0400
23620 +++ linux-2.6.39.2/arch/x86/platform/efi/efi_32.c 2011-05-22 19:36:30.000000000 -0400
23621 @@ -38,70 +38,37 @@
23622 */
23623
23624 static unsigned long efi_rt_eflags;
23625 -static pgd_t efi_bak_pg_dir_pointer[2];
23626 +static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
23627
23628 -void efi_call_phys_prelog(void)
23629 +void __init efi_call_phys_prelog(void)
23630 {
23631 - unsigned long cr4;
23632 - unsigned long temp;
23633 struct desc_ptr gdt_descr;
23634
23635 local_irq_save(efi_rt_eflags);
23636
23637 - /*
23638 - * If I don't have PAE, I should just duplicate two entries in page
23639 - * directory. If I have PAE, I just need to duplicate one entry in
23640 - * page directory.
23641 - */
23642 - cr4 = read_cr4_safe();
23643 -
23644 - if (cr4 & X86_CR4_PAE) {
23645 - efi_bak_pg_dir_pointer[0].pgd =
23646 - swapper_pg_dir[pgd_index(0)].pgd;
23647 - swapper_pg_dir[0].pgd =
23648 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23649 - } else {
23650 - efi_bak_pg_dir_pointer[0].pgd =
23651 - swapper_pg_dir[pgd_index(0)].pgd;
23652 - efi_bak_pg_dir_pointer[1].pgd =
23653 - swapper_pg_dir[pgd_index(0x400000)].pgd;
23654 - swapper_pg_dir[pgd_index(0)].pgd =
23655 - swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
23656 - temp = PAGE_OFFSET + 0x400000;
23657 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23658 - swapper_pg_dir[pgd_index(temp)].pgd;
23659 - }
23660 + clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
23661 + clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23662 + min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
23663
23664 /*
23665 * After the lock is released, the original page table is restored.
23666 */
23667 __flush_tlb_all();
23668
23669 - gdt_descr.address = __pa(get_cpu_gdt_table(0));
23670 + gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
23671 gdt_descr.size = GDT_SIZE - 1;
23672 load_gdt(&gdt_descr);
23673 }
23674
23675 -void efi_call_phys_epilog(void)
23676 +void __init efi_call_phys_epilog(void)
23677 {
23678 - unsigned long cr4;
23679 struct desc_ptr gdt_descr;
23680
23681 - gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
23682 + gdt_descr.address = get_cpu_gdt_table(0);
23683 gdt_descr.size = GDT_SIZE - 1;
23684 load_gdt(&gdt_descr);
23685
23686 - cr4 = read_cr4_safe();
23687 -
23688 - if (cr4 & X86_CR4_PAE) {
23689 - swapper_pg_dir[pgd_index(0)].pgd =
23690 - efi_bak_pg_dir_pointer[0].pgd;
23691 - } else {
23692 - swapper_pg_dir[pgd_index(0)].pgd =
23693 - efi_bak_pg_dir_pointer[0].pgd;
23694 - swapper_pg_dir[pgd_index(0x400000)].pgd =
23695 - efi_bak_pg_dir_pointer[1].pgd;
23696 - }
23697 + clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
23698
23699 /*
23700 * After the lock is released, the original page table is restored.
23701 diff -urNp linux-2.6.39.2/arch/x86/platform/efi/efi_stub_32.S linux-2.6.39.2/arch/x86/platform/efi/efi_stub_32.S
23702 --- linux-2.6.39.2/arch/x86/platform/efi/efi_stub_32.S 2011-05-19 00:06:34.000000000 -0400
23703 +++ linux-2.6.39.2/arch/x86/platform/efi/efi_stub_32.S 2011-05-22 19:36:30.000000000 -0400
23704 @@ -6,6 +6,7 @@
23705 */
23706
23707 #include <linux/linkage.h>
23708 +#include <linux/init.h>
23709 #include <asm/page_types.h>
23710
23711 /*
23712 @@ -20,7 +21,7 @@
23713 * service functions will comply with gcc calling convention, too.
23714 */
23715
23716 -.text
23717 +__INIT
23718 ENTRY(efi_call_phys)
23719 /*
23720 * 0. The function can only be called in Linux kernel. So CS has been
23721 @@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
23722 * The mapping of lower virtual memory has been created in prelog and
23723 * epilog.
23724 */
23725 - movl $1f, %edx
23726 - subl $__PAGE_OFFSET, %edx
23727 - jmp *%edx
23728 + jmp 1f-__PAGE_OFFSET
23729 1:
23730
23731 /*
23732 @@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
23733 * parameter 2, ..., param n. To make things easy, we save the return
23734 * address of efi_call_phys in a global variable.
23735 */
23736 - popl %edx
23737 - movl %edx, saved_return_addr
23738 - /* get the function pointer into ECX*/
23739 - popl %ecx
23740 - movl %ecx, efi_rt_function_ptr
23741 - movl $2f, %edx
23742 - subl $__PAGE_OFFSET, %edx
23743 - pushl %edx
23744 + popl (saved_return_addr)
23745 + popl (efi_rt_function_ptr)
23746
23747 /*
23748 * 3. Clear PG bit in %CR0.
23749 @@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
23750 /*
23751 * 5. Call the physical function.
23752 */
23753 - jmp *%ecx
23754 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
23755
23756 -2:
23757 /*
23758 * 6. After EFI runtime service returns, control will return to
23759 * following instruction. We'd better readjust stack pointer first.
23760 @@ -88,35 +80,28 @@ ENTRY(efi_call_phys)
23761 movl %cr0, %edx
23762 orl $0x80000000, %edx
23763 movl %edx, %cr0
23764 - jmp 1f
23765 -1:
23766 +
23767 /*
23768 * 8. Now restore the virtual mode from flat mode by
23769 * adding EIP with PAGE_OFFSET.
23770 */
23771 - movl $1f, %edx
23772 - jmp *%edx
23773 + jmp 1f+__PAGE_OFFSET
23774 1:
23775
23776 /*
23777 * 9. Balance the stack. And because EAX contain the return value,
23778 * we'd better not clobber it.
23779 */
23780 - leal efi_rt_function_ptr, %edx
23781 - movl (%edx), %ecx
23782 - pushl %ecx
23783 + pushl (efi_rt_function_ptr)
23784
23785 /*
23786 - * 10. Push the saved return address onto the stack and return.
23787 + * 10. Return to the saved return address.
23788 */
23789 - leal saved_return_addr, %edx
23790 - movl (%edx), %ecx
23791 - pushl %ecx
23792 - ret
23793 + jmpl *(saved_return_addr)
23794 ENDPROC(efi_call_phys)
23795 .previous
23796
23797 -.data
23798 +__INITDATA
23799 saved_return_addr:
23800 .long 0
23801 efi_rt_function_ptr:
23802 diff -urNp linux-2.6.39.2/arch/x86/platform/olpc/olpc_dt.c linux-2.6.39.2/arch/x86/platform/olpc/olpc_dt.c
23803 --- linux-2.6.39.2/arch/x86/platform/olpc/olpc_dt.c 2011-05-19 00:06:34.000000000 -0400
23804 +++ linux-2.6.39.2/arch/x86/platform/olpc/olpc_dt.c 2011-05-22 19:36:30.000000000 -0400
23805 @@ -154,7 +154,7 @@ void * __init prom_early_alloc(unsigned
23806 return res;
23807 }
23808
23809 -static struct of_pdt_ops prom_olpc_ops __initdata = {
23810 +static const struct of_pdt_ops prom_olpc_ops = {
23811 .nextprop = olpc_dt_nextprop,
23812 .getproplen = olpc_dt_getproplen,
23813 .getproperty = olpc_dt_getproperty,
23814 diff -urNp linux-2.6.39.2/arch/x86/platform/uv/tlb_uv.c linux-2.6.39.2/arch/x86/platform/uv/tlb_uv.c
23815 --- linux-2.6.39.2/arch/x86/platform/uv/tlb_uv.c 2011-05-19 00:06:34.000000000 -0400
23816 +++ linux-2.6.39.2/arch/x86/platform/uv/tlb_uv.c 2011-05-22 19:36:30.000000000 -0400
23817 @@ -342,6 +342,8 @@ static void uv_reset_with_ipi(struct bau
23818 cpumask_t mask;
23819 struct reset_args reset_args;
23820
23821 + pax_track_stack();
23822 +
23823 reset_args.sender = sender;
23824
23825 cpus_clear(mask);
23826 diff -urNp linux-2.6.39.2/arch/x86/power/cpu.c linux-2.6.39.2/arch/x86/power/cpu.c
23827 --- linux-2.6.39.2/arch/x86/power/cpu.c 2011-05-19 00:06:34.000000000 -0400
23828 +++ linux-2.6.39.2/arch/x86/power/cpu.c 2011-05-22 19:36:30.000000000 -0400
23829 @@ -130,7 +130,7 @@ static void do_fpu_end(void)
23830 static void fix_processor_context(void)
23831 {
23832 int cpu = smp_processor_id();
23833 - struct tss_struct *t = &per_cpu(init_tss, cpu);
23834 + struct tss_struct *t = init_tss + cpu;
23835
23836 set_tss_desc(cpu, t); /*
23837 * This just modifies memory; should not be
23838 @@ -140,7 +140,9 @@ static void fix_processor_context(void)
23839 */
23840
23841 #ifdef CONFIG_X86_64
23842 + pax_open_kernel();
23843 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
23844 + pax_close_kernel();
23845
23846 syscall_init(); /* This sets MSR_*STAR and related */
23847 #endif
23848 diff -urNp linux-2.6.39.2/arch/x86/vdso/Makefile linux-2.6.39.2/arch/x86/vdso/Makefile
23849 --- linux-2.6.39.2/arch/x86/vdso/Makefile 2011-05-19 00:06:34.000000000 -0400
23850 +++ linux-2.6.39.2/arch/x86/vdso/Makefile 2011-05-22 19:36:30.000000000 -0400
23851 @@ -123,7 +123,7 @@ quiet_cmd_vdso = VDSO $@
23852 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
23853 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
23854
23855 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23856 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
23857 GCOV_PROFILE := n
23858
23859 #
23860 diff -urNp linux-2.6.39.2/arch/x86/vdso/vclock_gettime.c linux-2.6.39.2/arch/x86/vdso/vclock_gettime.c
23861 --- linux-2.6.39.2/arch/x86/vdso/vclock_gettime.c 2011-05-19 00:06:34.000000000 -0400
23862 +++ linux-2.6.39.2/arch/x86/vdso/vclock_gettime.c 2011-05-22 19:36:30.000000000 -0400
23863 @@ -22,24 +22,48 @@
23864 #include <asm/hpet.h>
23865 #include <asm/unistd.h>
23866 #include <asm/io.h>
23867 +#include <asm/fixmap.h>
23868 #include "vextern.h"
23869
23870 #define gtod vdso_vsyscall_gtod_data
23871
23872 +notrace noinline long __vdso_fallback_time(long *t)
23873 +{
23874 + long secs;
23875 + asm volatile("syscall"
23876 + : "=a" (secs)
23877 + : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
23878 + return secs;
23879 +}
23880 +
23881 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
23882 {
23883 long ret;
23884 asm("syscall" : "=a" (ret) :
23885 - "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
23886 + "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
23887 return ret;
23888 }
23889
23890 +notrace static inline cycle_t __vdso_vread_hpet(void)
23891 +{
23892 + return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
23893 +}
23894 +
23895 +notrace static inline cycle_t __vdso_vread_tsc(void)
23896 +{
23897 + cycle_t ret = (cycle_t)vget_cycles();
23898 +
23899 + return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
23900 +}
23901 +
23902 notrace static inline long vgetns(void)
23903 {
23904 long v;
23905 - cycles_t (*vread)(void);
23906 - vread = gtod->clock.vread;
23907 - v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
23908 + if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
23909 + v = __vdso_vread_tsc();
23910 + else
23911 + v = __vdso_vread_hpet();
23912 + v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
23913 return (v * gtod->clock.mult) >> gtod->clock.shift;
23914 }
23915
23916 @@ -113,7 +137,9 @@ notrace static noinline int do_monotonic
23917
23918 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
23919 {
23920 - if (likely(gtod->sysctl_enabled))
23921 + if (likely(gtod->sysctl_enabled &&
23922 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23923 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23924 switch (clock) {
23925 case CLOCK_REALTIME:
23926 if (likely(gtod->clock.vread))
23927 @@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid
23928 int clock_gettime(clockid_t, struct timespec *)
23929 __attribute__((weak, alias("__vdso_clock_gettime")));
23930
23931 -notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23932 +notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
23933 {
23934 long ret;
23935 - if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
23936 + asm("syscall" : "=a" (ret) :
23937 + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
23938 + return ret;
23939 +}
23940 +
23941 +notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
23942 +{
23943 + if (likely(gtod->sysctl_enabled &&
23944 + ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
23945 + (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
23946 + {
23947 if (likely(tv != NULL)) {
23948 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
23949 offsetof(struct timespec, tv_nsec) ||
23950 @@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct t
23951 }
23952 return 0;
23953 }
23954 - asm("syscall" : "=a" (ret) :
23955 - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
23956 - return ret;
23957 + return __vdso_fallback_gettimeofday(tv, tz);
23958 }
23959 int gettimeofday(struct timeval *, struct timezone *)
23960 __attribute__((weak, alias("__vdso_gettimeofday")));
23961 diff -urNp linux-2.6.39.2/arch/x86/vdso/vdso32-setup.c linux-2.6.39.2/arch/x86/vdso/vdso32-setup.c
23962 --- linux-2.6.39.2/arch/x86/vdso/vdso32-setup.c 2011-05-19 00:06:34.000000000 -0400
23963 +++ linux-2.6.39.2/arch/x86/vdso/vdso32-setup.c 2011-05-22 19:36:30.000000000 -0400
23964 @@ -25,6 +25,7 @@
23965 #include <asm/tlbflush.h>
23966 #include <asm/vdso.h>
23967 #include <asm/proto.h>
23968 +#include <asm/mman.h>
23969
23970 enum {
23971 VDSO_DISABLED = 0,
23972 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int m
23973 void enable_sep_cpu(void)
23974 {
23975 int cpu = get_cpu();
23976 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
23977 + struct tss_struct *tss = init_tss + cpu;
23978
23979 if (!boot_cpu_has(X86_FEATURE_SEP)) {
23980 put_cpu();
23981 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
23982 gate_vma.vm_start = FIXADDR_USER_START;
23983 gate_vma.vm_end = FIXADDR_USER_END;
23984 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
23985 - gate_vma.vm_page_prot = __P101;
23986 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
23987 /*
23988 * Make sure the vDSO gets into every core dump.
23989 * Dumping its contents makes post-mortem fully interpretable later
23990 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct l
23991 if (compat)
23992 addr = VDSO_HIGH_BASE;
23993 else {
23994 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
23995 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
23996 if (IS_ERR_VALUE(addr)) {
23997 ret = addr;
23998 goto up_fail;
23999 }
24000 }
24001
24002 - current->mm->context.vdso = (void *)addr;
24003 + current->mm->context.vdso = addr;
24004
24005 if (compat_uses_vma || !compat) {
24006 /*
24007 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct l
24008 }
24009
24010 current_thread_info()->sysenter_return =
24011 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24012 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24013
24014 up_fail:
24015 if (ret)
24016 - current->mm->context.vdso = NULL;
24017 + current->mm->context.vdso = 0;
24018
24019 up_write(&mm->mmap_sem);
24020
24021 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24022
24023 const char *arch_vma_name(struct vm_area_struct *vma)
24024 {
24025 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24026 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24027 return "[vdso]";
24028 +
24029 +#ifdef CONFIG_PAX_SEGMEXEC
24030 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24031 + return "[vdso]";
24032 +#endif
24033 +
24034 return NULL;
24035 }
24036
24037 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(stru
24038 * Check to see if the corresponding task was created in compat vdso
24039 * mode.
24040 */
24041 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24042 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24043 return &gate_vma;
24044 return NULL;
24045 }
24046 diff -urNp linux-2.6.39.2/arch/x86/vdso/vdso.lds.S linux-2.6.39.2/arch/x86/vdso/vdso.lds.S
24047 --- linux-2.6.39.2/arch/x86/vdso/vdso.lds.S 2011-05-19 00:06:34.000000000 -0400
24048 +++ linux-2.6.39.2/arch/x86/vdso/vdso.lds.S 2011-06-06 17:34:26.000000000 -0400
24049 @@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
24050 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
24051 #include "vextern.h"
24052 #undef VEXTERN
24053 +
24054 +#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
24055 +VEXTERN(fallback_gettimeofday)
24056 +VEXTERN(fallback_time)
24057 +VEXTERN(getcpu)
24058 +#undef VEXTERN
24059 diff -urNp linux-2.6.39.2/arch/x86/vdso/vextern.h linux-2.6.39.2/arch/x86/vdso/vextern.h
24060 --- linux-2.6.39.2/arch/x86/vdso/vextern.h 2011-05-19 00:06:34.000000000 -0400
24061 +++ linux-2.6.39.2/arch/x86/vdso/vextern.h 2011-05-22 19:36:30.000000000 -0400
24062 @@ -11,6 +11,5 @@
24063 put into vextern.h and be referenced as a pointer with vdso prefix.
24064 The main kernel later fills in the values. */
24065
24066 -VEXTERN(jiffies)
24067 VEXTERN(vgetcpu_mode)
24068 VEXTERN(vsyscall_gtod_data)
24069 diff -urNp linux-2.6.39.2/arch/x86/vdso/vma.c linux-2.6.39.2/arch/x86/vdso/vma.c
24070 --- linux-2.6.39.2/arch/x86/vdso/vma.c 2011-05-19 00:06:34.000000000 -0400
24071 +++ linux-2.6.39.2/arch/x86/vdso/vma.c 2011-05-22 19:36:30.000000000 -0400
24072 @@ -58,7 +58,7 @@ static int __init init_vdso_vars(void)
24073 if (!vbase)
24074 goto oom;
24075
24076 - if (memcmp(vbase, "\177ELF", 4)) {
24077 + if (memcmp(vbase, ELFMAG, SELFMAG)) {
24078 printk("VDSO: I'm broken; not ELF\n");
24079 vdso_enabled = 0;
24080 }
24081 @@ -118,7 +118,7 @@ int arch_setup_additional_pages(struct l
24082 goto up_fail;
24083 }
24084
24085 - current->mm->context.vdso = (void *)addr;
24086 + current->mm->context.vdso = addr;
24087
24088 ret = install_special_mapping(mm, addr, vdso_size,
24089 VM_READ|VM_EXEC|
24090 @@ -126,7 +126,7 @@ int arch_setup_additional_pages(struct l
24091 VM_ALWAYSDUMP,
24092 vdso_pages);
24093 if (ret) {
24094 - current->mm->context.vdso = NULL;
24095 + current->mm->context.vdso = 0;
24096 goto up_fail;
24097 }
24098
24099 @@ -134,10 +134,3 @@ up_fail:
24100 up_write(&mm->mmap_sem);
24101 return ret;
24102 }
24103 -
24104 -static __init int vdso_setup(char *s)
24105 -{
24106 - vdso_enabled = simple_strtoul(s, NULL, 0);
24107 - return 0;
24108 -}
24109 -__setup("vdso=", vdso_setup);
24110 diff -urNp linux-2.6.39.2/arch/x86/xen/enlighten.c linux-2.6.39.2/arch/x86/xen/enlighten.c
24111 --- linux-2.6.39.2/arch/x86/xen/enlighten.c 2011-05-19 00:06:34.000000000 -0400
24112 +++ linux-2.6.39.2/arch/x86/xen/enlighten.c 2011-05-22 19:36:30.000000000 -0400
24113 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24114
24115 struct shared_info xen_dummy_shared_info;
24116
24117 -void *xen_initial_gdt;
24118 -
24119 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24120 __read_mostly int xen_have_vector_callback;
24121 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24122 @@ -1010,7 +1008,7 @@ static const struct pv_apic_ops xen_apic
24123 #endif
24124 };
24125
24126 -static void xen_reboot(int reason)
24127 +static __noreturn void xen_reboot(int reason)
24128 {
24129 struct sched_shutdown r = { .reason = reason };
24130
24131 @@ -1018,17 +1016,17 @@ static void xen_reboot(int reason)
24132 BUG();
24133 }
24134
24135 -static void xen_restart(char *msg)
24136 +static __noreturn void xen_restart(char *msg)
24137 {
24138 xen_reboot(SHUTDOWN_reboot);
24139 }
24140
24141 -static void xen_emergency_restart(void)
24142 +static __noreturn void xen_emergency_restart(void)
24143 {
24144 xen_reboot(SHUTDOWN_reboot);
24145 }
24146
24147 -static void xen_machine_halt(void)
24148 +static __noreturn void xen_machine_halt(void)
24149 {
24150 xen_reboot(SHUTDOWN_poweroff);
24151 }
24152 @@ -1127,7 +1125,17 @@ asmlinkage void __init xen_start_kernel(
24153 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24154
24155 /* Work out if we support NX */
24156 - x86_configure_nx();
24157 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24158 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24159 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24160 + unsigned l, h;
24161 +
24162 + __supported_pte_mask |= _PAGE_NX;
24163 + rdmsr(MSR_EFER, l, h);
24164 + l |= EFER_NX;
24165 + wrmsr(MSR_EFER, l, h);
24166 + }
24167 +#endif
24168
24169 xen_setup_features();
24170
24171 @@ -1158,13 +1166,6 @@ asmlinkage void __init xen_start_kernel(
24172
24173 machine_ops = xen_machine_ops;
24174
24175 - /*
24176 - * The only reliable way to retain the initial address of the
24177 - * percpu gdt_page is to remember it here, so we can go and
24178 - * mark it RW later, when the initial percpu area is freed.
24179 - */
24180 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24181 -
24182 xen_smp_init();
24183
24184 #ifdef CONFIG_ACPI_NUMA
24185 diff -urNp linux-2.6.39.2/arch/x86/xen/mmu.c linux-2.6.39.2/arch/x86/xen/mmu.c
24186 --- linux-2.6.39.2/arch/x86/xen/mmu.c 2011-06-03 00:04:13.000000000 -0400
24187 +++ linux-2.6.39.2/arch/x86/xen/mmu.c 2011-06-03 00:32:05.000000000 -0400
24188 @@ -1791,6 +1791,8 @@ __init pgd_t *xen_setup_kernel_pagetable
24189 convert_pfn_mfn(init_level4_pgt);
24190 convert_pfn_mfn(level3_ident_pgt);
24191 convert_pfn_mfn(level3_kernel_pgt);
24192 + convert_pfn_mfn(level3_vmalloc_pgt);
24193 + convert_pfn_mfn(level3_vmemmap_pgt);
24194
24195 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24196 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24197 @@ -1809,7 +1811,10 @@ __init pgd_t *xen_setup_kernel_pagetable
24198 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24199 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24200 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24201 + set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
24202 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24203 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24204 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24205 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24206 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24207
24208 diff -urNp linux-2.6.39.2/arch/x86/xen/pci-swiotlb-xen.c linux-2.6.39.2/arch/x86/xen/pci-swiotlb-xen.c
24209 --- linux-2.6.39.2/arch/x86/xen/pci-swiotlb-xen.c 2011-05-19 00:06:34.000000000 -0400
24210 +++ linux-2.6.39.2/arch/x86/xen/pci-swiotlb-xen.c 2011-05-22 19:36:30.000000000 -0400
24211 @@ -10,7 +10,7 @@
24212
24213 int xen_swiotlb __read_mostly;
24214
24215 -static struct dma_map_ops xen_swiotlb_dma_ops = {
24216 +static const struct dma_map_ops xen_swiotlb_dma_ops = {
24217 .mapping_error = xen_swiotlb_dma_mapping_error,
24218 .alloc_coherent = xen_swiotlb_alloc_coherent,
24219 .free_coherent = xen_swiotlb_free_coherent,
24220 diff -urNp linux-2.6.39.2/arch/x86/xen/smp.c linux-2.6.39.2/arch/x86/xen/smp.c
24221 --- linux-2.6.39.2/arch/x86/xen/smp.c 2011-05-19 00:06:34.000000000 -0400
24222 +++ linux-2.6.39.2/arch/x86/xen/smp.c 2011-05-22 19:36:30.000000000 -0400
24223 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_
24224 {
24225 BUG_ON(smp_processor_id() != 0);
24226 native_smp_prepare_boot_cpu();
24227 -
24228 - /* We've switched to the "real" per-cpu gdt, so make sure the
24229 - old memory can be recycled */
24230 - make_lowmem_page_readwrite(xen_initial_gdt);
24231 -
24232 xen_filter_cpu_maps();
24233 xen_setup_vcpu_info_placement();
24234 }
24235 @@ -259,12 +254,12 @@ cpu_initialize_context(unsigned int cpu,
24236 gdt = get_cpu_gdt_table(cpu);
24237
24238 ctxt->flags = VGCF_IN_KERNEL;
24239 - ctxt->user_regs.ds = __USER_DS;
24240 - ctxt->user_regs.es = __USER_DS;
24241 + ctxt->user_regs.ds = __KERNEL_DS;
24242 + ctxt->user_regs.es = __KERNEL_DS;
24243 ctxt->user_regs.ss = __KERNEL_DS;
24244 #ifdef CONFIG_X86_32
24245 ctxt->user_regs.fs = __KERNEL_PERCPU;
24246 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24247 + savesegment(gs, ctxt->user_regs.gs);
24248 #else
24249 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24250 #endif
24251 @@ -315,13 +310,12 @@ static int __cpuinit xen_cpu_up(unsigned
24252 int rc;
24253
24254 per_cpu(current_task, cpu) = idle;
24255 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24256 #ifdef CONFIG_X86_32
24257 irq_ctx_init(cpu);
24258 #else
24259 clear_tsk_thread_flag(idle, TIF_FORK);
24260 - per_cpu(kernel_stack, cpu) =
24261 - (unsigned long)task_stack_page(idle) -
24262 - KERNEL_STACK_OFFSET + THREAD_SIZE;
24263 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
24264 #endif
24265 xen_setup_runstate_info(cpu);
24266 xen_setup_timer(cpu);
24267 diff -urNp linux-2.6.39.2/arch/x86/xen/xen-asm_32.S linux-2.6.39.2/arch/x86/xen/xen-asm_32.S
24268 --- linux-2.6.39.2/arch/x86/xen/xen-asm_32.S 2011-05-19 00:06:34.000000000 -0400
24269 +++ linux-2.6.39.2/arch/x86/xen/xen-asm_32.S 2011-05-22 19:36:30.000000000 -0400
24270 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
24271 ESP_OFFSET=4 # bytes pushed onto stack
24272
24273 /*
24274 - * Store vcpu_info pointer for easy access. Do it this way to
24275 - * avoid having to reload %fs
24276 + * Store vcpu_info pointer for easy access.
24277 */
24278 #ifdef CONFIG_SMP
24279 - GET_THREAD_INFO(%eax)
24280 - movl TI_cpu(%eax), %eax
24281 - movl __per_cpu_offset(,%eax,4), %eax
24282 - mov xen_vcpu(%eax), %eax
24283 + push %fs
24284 + mov $(__KERNEL_PERCPU), %eax
24285 + mov %eax, %fs
24286 + mov PER_CPU_VAR(xen_vcpu), %eax
24287 + pop %fs
24288 #else
24289 movl xen_vcpu, %eax
24290 #endif
24291 diff -urNp linux-2.6.39.2/arch/x86/xen/xen-head.S linux-2.6.39.2/arch/x86/xen/xen-head.S
24292 --- linux-2.6.39.2/arch/x86/xen/xen-head.S 2011-05-19 00:06:34.000000000 -0400
24293 +++ linux-2.6.39.2/arch/x86/xen/xen-head.S 2011-05-22 19:36:30.000000000 -0400
24294 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
24295 #ifdef CONFIG_X86_32
24296 mov %esi,xen_start_info
24297 mov $init_thread_union+THREAD_SIZE,%esp
24298 +#ifdef CONFIG_SMP
24299 + movl $cpu_gdt_table,%edi
24300 + movl $__per_cpu_load,%eax
24301 + movw %ax,__KERNEL_PERCPU + 2(%edi)
24302 + rorl $16,%eax
24303 + movb %al,__KERNEL_PERCPU + 4(%edi)
24304 + movb %ah,__KERNEL_PERCPU + 7(%edi)
24305 + movl $__per_cpu_end - 1,%eax
24306 + subl $__per_cpu_start,%eax
24307 + movw %ax,__KERNEL_PERCPU + 0(%edi)
24308 +#endif
24309 #else
24310 mov %rsi,xen_start_info
24311 mov $init_thread_union+THREAD_SIZE,%rsp
24312 diff -urNp linux-2.6.39.2/arch/x86/xen/xen-ops.h linux-2.6.39.2/arch/x86/xen/xen-ops.h
24313 --- linux-2.6.39.2/arch/x86/xen/xen-ops.h 2011-05-19 00:06:34.000000000 -0400
24314 +++ linux-2.6.39.2/arch/x86/xen/xen-ops.h 2011-05-22 19:36:30.000000000 -0400
24315 @@ -10,8 +10,6 @@
24316 extern const char xen_hypervisor_callback[];
24317 extern const char xen_failsafe_callback[];
24318
24319 -extern void *xen_initial_gdt;
24320 -
24321 struct trap_info;
24322 void xen_copy_trap_info(struct trap_info *traps);
24323
24324 diff -urNp linux-2.6.39.2/block/blk-iopoll.c linux-2.6.39.2/block/blk-iopoll.c
24325 --- linux-2.6.39.2/block/blk-iopoll.c 2011-05-19 00:06:34.000000000 -0400
24326 +++ linux-2.6.39.2/block/blk-iopoll.c 2011-05-22 19:36:30.000000000 -0400
24327 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopo
24328 }
24329 EXPORT_SYMBOL(blk_iopoll_complete);
24330
24331 -static void blk_iopoll_softirq(struct softirq_action *h)
24332 +static void blk_iopoll_softirq(void)
24333 {
24334 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
24335 int rearm = 0, budget = blk_iopoll_budget;
24336 diff -urNp linux-2.6.39.2/block/blk-map.c linux-2.6.39.2/block/blk-map.c
24337 --- linux-2.6.39.2/block/blk-map.c 2011-05-19 00:06:34.000000000 -0400
24338 +++ linux-2.6.39.2/block/blk-map.c 2011-05-22 19:36:30.000000000 -0400
24339 @@ -301,7 +301,7 @@ int blk_rq_map_kern(struct request_queue
24340 if (!len || !kbuf)
24341 return -EINVAL;
24342
24343 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
24344 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
24345 if (do_copy)
24346 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
24347 else
24348 diff -urNp linux-2.6.39.2/block/blk-softirq.c linux-2.6.39.2/block/blk-softirq.c
24349 --- linux-2.6.39.2/block/blk-softirq.c 2011-05-19 00:06:34.000000000 -0400
24350 +++ linux-2.6.39.2/block/blk-softirq.c 2011-05-22 19:36:30.000000000 -0400
24351 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head,
24352 * Softirq action handler - move entries to local list and loop over them
24353 * while passing them to the queue registered handler.
24354 */
24355 -static void blk_done_softirq(struct softirq_action *h)
24356 +static void blk_done_softirq(void)
24357 {
24358 struct list_head *cpu_list, local_list;
24359
24360 diff -urNp linux-2.6.39.2/block/bsg.c linux-2.6.39.2/block/bsg.c
24361 --- linux-2.6.39.2/block/bsg.c 2011-05-19 00:06:34.000000000 -0400
24362 +++ linux-2.6.39.2/block/bsg.c 2011-05-22 19:36:30.000000000 -0400
24363 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct r
24364 struct sg_io_v4 *hdr, struct bsg_device *bd,
24365 fmode_t has_write_perm)
24366 {
24367 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24368 + unsigned char *cmdptr;
24369 +
24370 if (hdr->request_len > BLK_MAX_CDB) {
24371 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
24372 if (!rq->cmd)
24373 return -ENOMEM;
24374 - }
24375 + cmdptr = rq->cmd;
24376 + } else
24377 + cmdptr = tmpcmd;
24378
24379 - if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
24380 + if (copy_from_user(cmdptr, (void *)(unsigned long)hdr->request,
24381 hdr->request_len))
24382 return -EFAULT;
24383
24384 + if (cmdptr != rq->cmd)
24385 + memcpy(rq->cmd, cmdptr, hdr->request_len);
24386 +
24387 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
24388 if (blk_verify_command(rq->cmd, has_write_perm))
24389 return -EPERM;
24390 diff -urNp linux-2.6.39.2/block/scsi_ioctl.c linux-2.6.39.2/block/scsi_ioctl.c
24391 --- linux-2.6.39.2/block/scsi_ioctl.c 2011-05-19 00:06:34.000000000 -0400
24392 +++ linux-2.6.39.2/block/scsi_ioctl.c 2011-05-22 19:36:30.000000000 -0400
24393 @@ -222,8 +222,20 @@ EXPORT_SYMBOL(blk_verify_command);
24394 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
24395 struct sg_io_hdr *hdr, fmode_t mode)
24396 {
24397 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
24398 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24399 + unsigned char *cmdptr;
24400 +
24401 + if (rq->cmd != rq->__cmd)
24402 + cmdptr = rq->cmd;
24403 + else
24404 + cmdptr = tmpcmd;
24405 +
24406 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
24407 return -EFAULT;
24408 +
24409 + if (cmdptr != rq->cmd)
24410 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
24411 +
24412 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
24413 return -EPERM;
24414
24415 @@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *
24416 int err;
24417 unsigned int in_len, out_len, bytes, opcode, cmdlen;
24418 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
24419 + unsigned char tmpcmd[sizeof(rq->__cmd)];
24420 + unsigned char *cmdptr;
24421
24422 if (!sic)
24423 return -EINVAL;
24424 @@ -465,9 +479,18 @@ int sg_scsi_ioctl(struct request_queue *
24425 */
24426 err = -EFAULT;
24427 rq->cmd_len = cmdlen;
24428 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
24429 +
24430 + if (rq->cmd != rq->__cmd)
24431 + cmdptr = rq->cmd;
24432 + else
24433 + cmdptr = tmpcmd;
24434 +
24435 + if (copy_from_user(cmdptr, sic->data, cmdlen))
24436 goto error;
24437
24438 + if (rq->cmd != cmdptr)
24439 + memcpy(rq->cmd, cmdptr, cmdlen);
24440 +
24441 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
24442 goto error;
24443
24444 diff -urNp linux-2.6.39.2/crypto/serpent.c linux-2.6.39.2/crypto/serpent.c
24445 --- linux-2.6.39.2/crypto/serpent.c 2011-05-19 00:06:34.000000000 -0400
24446 +++ linux-2.6.39.2/crypto/serpent.c 2011-05-22 19:36:30.000000000 -0400
24447 @@ -224,6 +224,8 @@ static int serpent_setkey(struct crypto_
24448 u32 r0,r1,r2,r3,r4;
24449 int i;
24450
24451 + pax_track_stack();
24452 +
24453 /* Copy key, add padding */
24454
24455 for (i = 0; i < keylen; ++i)
24456 diff -urNp linux-2.6.39.2/Documentation/dontdiff linux-2.6.39.2/Documentation/dontdiff
24457 --- linux-2.6.39.2/Documentation/dontdiff 2011-05-19 00:06:34.000000000 -0400
24458 +++ linux-2.6.39.2/Documentation/dontdiff 2011-05-22 19:36:30.000000000 -0400
24459 @@ -1,13 +1,16 @@
24460 *.a
24461 *.aux
24462 *.bin
24463 +*.cis
24464 *.cpio
24465 *.csp
24466 +*.dbg
24467 *.dsp
24468 *.dvi
24469 *.elf
24470 *.eps
24471 *.fw
24472 +*.gcno
24473 *.gen.S
24474 *.gif
24475 *.grep
24476 @@ -38,8 +41,10 @@
24477 *.tab.h
24478 *.tex
24479 *.ver
24480 +*.vim
24481 *.xml
24482 *_MODULES
24483 +*_reg_safe.h
24484 *_vga16.c
24485 *~
24486 *.9
24487 @@ -49,11 +54,16 @@
24488 53c700_d.h
24489 CVS
24490 ChangeSet
24491 +GPATH
24492 +GRTAGS
24493 +GSYMS
24494 +GTAGS
24495 Image
24496 Kerntypes
24497 Module.markers
24498 Module.symvers
24499 PENDING
24500 +PERF*
24501 SCCS
24502 System.map*
24503 TAGS
24504 @@ -80,8 +90,11 @@ btfixupprep
24505 build
24506 bvmlinux
24507 bzImage*
24508 +capability_names.h
24509 capflags.c
24510 classlist.h*
24511 +clut_vga16.c
24512 +common-cmds.h
24513 comp*.log
24514 compile.h*
24515 conf
24516 @@ -106,16 +119,19 @@ fore200e_mkfirm
24517 fore200e_pca_fw.c*
24518 gconf
24519 gen-devlist
24520 +gen-kdb_cmds.c
24521 gen_crc32table
24522 gen_init_cpio
24523 generated
24524 genheaders
24525 genksyms
24526 *_gray256.c
24527 +hash
24528 ihex2fw
24529 ikconfig.h*
24530 inat-tables.c
24531 initramfs_data.cpio
24532 +initramfs_data.cpio.bz2
24533 initramfs_data.cpio.gz
24534 initramfs_list
24535 int16.c
24536 @@ -125,7 +141,6 @@ int32.c
24537 int4.c
24538 int8.c
24539 kallsyms
24540 -kconfig
24541 keywords.c
24542 ksym.c*
24543 ksym.h*
24544 @@ -149,7 +164,9 @@ mkboot
24545 mkbugboot
24546 mkcpustr
24547 mkdep
24548 +mkpiggy
24549 mkprep
24550 +mkregtable
24551 mktables
24552 mktree
24553 modpost
24554 @@ -165,6 +182,7 @@ parse.h
24555 patches*
24556 pca200e.bin
24557 pca200e_ecd.bin2
24558 +perf-archive
24559 piggy.gz
24560 piggyback
24561 piggy.S
24562 @@ -180,7 +198,9 @@ r600_reg_safe.h
24563 raid6altivec*.c
24564 raid6int*.c
24565 raid6tables.c
24566 +regdb.c
24567 relocs
24568 +rlim_names.h
24569 rn50_reg_safe.h
24570 rs600_reg_safe.h
24571 rv515_reg_safe.h
24572 @@ -189,6 +209,7 @@ setup
24573 setup.bin
24574 setup.elf
24575 sImage
24576 +slabinfo
24577 sm_tbl*
24578 split-include
24579 syscalltab.h
24580 @@ -213,13 +234,17 @@ version.h*
24581 vmlinux
24582 vmlinux-*
24583 vmlinux.aout
24584 +vmlinux.bin.all
24585 +vmlinux.bin.bz2
24586 vmlinux.lds
24587 +vmlinux.relocs
24588 voffset.h
24589 vsyscall.lds
24590 vsyscall_32.lds
24591 wanxlfw.inc
24592 uImage
24593 unifdef
24594 +utsrelease.h
24595 wakeup.bin
24596 wakeup.elf
24597 wakeup.lds
24598 diff -urNp linux-2.6.39.2/Documentation/filesystems/configfs/configfs_example_macros.c linux-2.6.39.2/Documentation/filesystems/configfs/configfs_example_macros.c
24599 --- linux-2.6.39.2/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-19 00:06:34.000000000 -0400
24600 +++ linux-2.6.39.2/Documentation/filesystems/configfs/configfs_example_macros.c 2011-05-22 19:36:30.000000000 -0400
24601 @@ -368,7 +368,7 @@ static struct configfs_item_operations g
24602 * Note that, since no extra work is required on ->drop_item(),
24603 * no ->drop_item() is provided.
24604 */
24605 -static struct configfs_group_operations group_children_group_ops = {
24606 +static const struct configfs_group_operations group_children_group_ops = {
24607 .make_group = group_children_make_group,
24608 };
24609
24610 diff -urNp linux-2.6.39.2/Documentation/filesystems/sysfs.txt linux-2.6.39.2/Documentation/filesystems/sysfs.txt
24611 --- linux-2.6.39.2/Documentation/filesystems/sysfs.txt 2011-05-19 00:06:34.000000000 -0400
24612 +++ linux-2.6.39.2/Documentation/filesystems/sysfs.txt 2011-05-22 19:36:30.000000000 -0400
24613 @@ -125,8 +125,8 @@ set of sysfs operations for forwarding r
24614 show and store methods of the attribute owners.
24615
24616 struct sysfs_ops {
24617 - ssize_t (*show)(struct kobject *, struct attribute *, char *);
24618 - ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
24619 + ssize_t (* const show)(struct kobject *, struct attribute *, char *);
24620 + ssize_t (* const store)(struct kobject *, struct attribute *, const char *, size_t);
24621 };
24622
24623 [ Subsystems should have already defined a struct kobj_type as a
24624 diff -urNp linux-2.6.39.2/Documentation/kernel-parameters.txt linux-2.6.39.2/Documentation/kernel-parameters.txt
24625 --- linux-2.6.39.2/Documentation/kernel-parameters.txt 2011-06-25 12:55:22.000000000 -0400
24626 +++ linux-2.6.39.2/Documentation/kernel-parameters.txt 2011-06-25 13:00:25.000000000 -0400
24627 @@ -1879,6 +1879,13 @@ bytes respectively. Such letter suffixes
24628 the specified number of seconds. This is to be used if
24629 your oopses keep scrolling off the screen.
24630
24631 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
24632 + virtualization environments that don't cope well with the
24633 + expand down segment used by UDEREF on X86-32 or the frequent
24634 + page table updates on X86-64.
24635 +
24636 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
24637 +
24638 pcbit= [HW,ISDN]
24639
24640 pcd. [PARIDE]
24641 diff -urNp linux-2.6.39.2/drivers/acpi/acpi_ipmi.c linux-2.6.39.2/drivers/acpi/acpi_ipmi.c
24642 --- linux-2.6.39.2/drivers/acpi/acpi_ipmi.c 2011-05-19 00:06:34.000000000 -0400
24643 +++ linux-2.6.39.2/drivers/acpi/acpi_ipmi.c 2011-05-22 19:36:30.000000000 -0400
24644 @@ -70,7 +70,7 @@ struct acpi_ipmi_device {
24645 struct ipmi_driver_data {
24646 struct list_head ipmi_devices;
24647 struct ipmi_smi_watcher bmc_events;
24648 - struct ipmi_user_hndl ipmi_hndlrs;
24649 + const struct ipmi_user_hndl ipmi_hndlrs;
24650 struct mutex ipmi_lock;
24651 };
24652
24653 diff -urNp linux-2.6.39.2/drivers/acpi/apei/cper.c linux-2.6.39.2/drivers/acpi/apei/cper.c
24654 --- linux-2.6.39.2/drivers/acpi/apei/cper.c 2011-05-19 00:06:34.000000000 -0400
24655 +++ linux-2.6.39.2/drivers/acpi/apei/cper.c 2011-05-22 19:36:30.000000000 -0400
24656 @@ -38,12 +38,12 @@
24657 */
24658 u64 cper_next_record_id(void)
24659 {
24660 - static atomic64_t seq;
24661 + static atomic64_unchecked_t seq;
24662
24663 - if (!atomic64_read(&seq))
24664 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
24665 + if (!atomic64_read_unchecked(&seq))
24666 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
24667
24668 - return atomic64_inc_return(&seq);
24669 + return atomic64_inc_return_unchecked(&seq);
24670 }
24671 EXPORT_SYMBOL_GPL(cper_next_record_id);
24672
24673 diff -urNp linux-2.6.39.2/drivers/acpi/battery.c linux-2.6.39.2/drivers/acpi/battery.c
24674 --- linux-2.6.39.2/drivers/acpi/battery.c 2011-05-19 00:06:34.000000000 -0400
24675 +++ linux-2.6.39.2/drivers/acpi/battery.c 2011-05-22 19:36:30.000000000 -0400
24676 @@ -864,7 +864,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
24677 }
24678
24679 static struct battery_file {
24680 - struct file_operations ops;
24681 + const struct file_operations ops;
24682 mode_t mode;
24683 const char *name;
24684 } acpi_battery_file[] = {
24685 diff -urNp linux-2.6.39.2/drivers/acpi/dock.c linux-2.6.39.2/drivers/acpi/dock.c
24686 --- linux-2.6.39.2/drivers/acpi/dock.c 2011-05-19 00:06:34.000000000 -0400
24687 +++ linux-2.6.39.2/drivers/acpi/dock.c 2011-05-22 19:36:30.000000000 -0400
24688 @@ -77,7 +77,7 @@ struct dock_dependent_device {
24689 struct list_head list;
24690 struct list_head hotplug_list;
24691 acpi_handle handle;
24692 - struct acpi_dock_ops *ops;
24693 + const struct acpi_dock_ops *ops;
24694 void *context;
24695 };
24696
24697 @@ -589,7 +589,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifi
24698 * the dock driver after _DCK is executed.
24699 */
24700 int
24701 -register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
24702 +register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
24703 void *context)
24704 {
24705 struct dock_dependent_device *dd;
24706 diff -urNp linux-2.6.39.2/drivers/acpi/ec_sys.c linux-2.6.39.2/drivers/acpi/ec_sys.c
24707 --- linux-2.6.39.2/drivers/acpi/ec_sys.c 2011-05-19 00:06:34.000000000 -0400
24708 +++ linux-2.6.39.2/drivers/acpi/ec_sys.c 2011-05-22 19:36:30.000000000 -0400
24709 @@ -92,7 +92,7 @@ static ssize_t acpi_ec_write_io(struct f
24710 return count;
24711 }
24712
24713 -static struct file_operations acpi_ec_io_ops = {
24714 +static const struct file_operations acpi_ec_io_ops = {
24715 .owner = THIS_MODULE,
24716 .open = acpi_ec_open_io,
24717 .read = acpi_ec_read_io,
24718 diff -urNp linux-2.6.39.2/drivers/acpi/fan.c linux-2.6.39.2/drivers/acpi/fan.c
24719 --- linux-2.6.39.2/drivers/acpi/fan.c 2011-05-19 00:06:34.000000000 -0400
24720 +++ linux-2.6.39.2/drivers/acpi/fan.c 2011-05-22 19:36:30.000000000 -0400
24721 @@ -110,7 +110,7 @@ fan_set_cur_state(struct thermal_cooling
24722 return result;
24723 }
24724
24725 -static struct thermal_cooling_device_ops fan_cooling_ops = {
24726 +static const struct thermal_cooling_device_ops fan_cooling_ops = {
24727 .get_max_state = fan_get_max_state,
24728 .get_cur_state = fan_get_cur_state,
24729 .set_cur_state = fan_set_cur_state,
24730 diff -urNp linux-2.6.39.2/drivers/acpi/power_meter.c linux-2.6.39.2/drivers/acpi/power_meter.c
24731 --- linux-2.6.39.2/drivers/acpi/power_meter.c 2011-05-19 00:06:34.000000000 -0400
24732 +++ linux-2.6.39.2/drivers/acpi/power_meter.c 2011-05-22 19:36:30.000000000 -0400
24733 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *d
24734 return res;
24735
24736 temp /= 1000;
24737 - if (temp < 0)
24738 - return -EINVAL;
24739
24740 mutex_lock(&resource->lock);
24741 resource->trip[attr->index - 7] = temp;
24742 diff -urNp linux-2.6.39.2/drivers/acpi/proc.c linux-2.6.39.2/drivers/acpi/proc.c
24743 --- linux-2.6.39.2/drivers/acpi/proc.c 2011-05-19 00:06:34.000000000 -0400
24744 +++ linux-2.6.39.2/drivers/acpi/proc.c 2011-05-22 19:36:30.000000000 -0400
24745 @@ -342,19 +342,13 @@ acpi_system_write_wakeup_device(struct f
24746 size_t count, loff_t * ppos)
24747 {
24748 struct list_head *node, *next;
24749 - char strbuf[5];
24750 - char str[5] = "";
24751 - unsigned int len = count;
24752 -
24753 - if (len > 4)
24754 - len = 4;
24755 - if (len < 0)
24756 - return -EFAULT;
24757 + char strbuf[5] = {0};
24758
24759 - if (copy_from_user(strbuf, buffer, len))
24760 + if (count > 4)
24761 + count = 4;
24762 + if (copy_from_user(strbuf, buffer, count))
24763 return -EFAULT;
24764 - strbuf[len] = '\0';
24765 - sscanf(strbuf, "%s", str);
24766 + strbuf[count] = '\0';
24767
24768 mutex_lock(&acpi_device_lock);
24769 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
24770 @@ -363,7 +357,7 @@ acpi_system_write_wakeup_device(struct f
24771 if (!dev->wakeup.flags.valid)
24772 continue;
24773
24774 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
24775 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
24776 if (device_can_wakeup(&dev->dev)) {
24777 bool enable = !device_may_wakeup(&dev->dev);
24778 device_set_wakeup_enable(&dev->dev, enable);
24779 diff -urNp linux-2.6.39.2/drivers/acpi/processor_driver.c linux-2.6.39.2/drivers/acpi/processor_driver.c
24780 --- linux-2.6.39.2/drivers/acpi/processor_driver.c 2011-05-19 00:06:34.000000000 -0400
24781 +++ linux-2.6.39.2/drivers/acpi/processor_driver.c 2011-05-22 19:36:30.000000000 -0400
24782 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(
24783 return 0;
24784 #endif
24785
24786 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
24787 + BUG_ON(pr->id >= nr_cpu_ids);
24788
24789 /*
24790 * Buggy BIOS check
24791 diff -urNp linux-2.6.39.2/drivers/acpi/processor_idle.c linux-2.6.39.2/drivers/acpi/processor_idle.c
24792 --- linux-2.6.39.2/drivers/acpi/processor_idle.c 2011-05-19 00:06:34.000000000 -0400
24793 +++ linux-2.6.39.2/drivers/acpi/processor_idle.c 2011-05-22 19:36:30.000000000 -0400
24794 @@ -121,7 +121,7 @@ static struct dmi_system_id __cpuinitdat
24795 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
24796 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
24797 (void *)1},
24798 - {},
24799 + {}
24800 };
24801
24802
24803 diff -urNp linux-2.6.39.2/drivers/acpi/processor_thermal.c linux-2.6.39.2/drivers/acpi/processor_thermal.c
24804 --- linux-2.6.39.2/drivers/acpi/processor_thermal.c 2011-05-19 00:06:34.000000000 -0400
24805 +++ linux-2.6.39.2/drivers/acpi/processor_thermal.c 2011-05-22 19:36:30.000000000 -0400
24806 @@ -244,7 +244,7 @@ processor_set_cur_state(struct thermal_c
24807 return result;
24808 }
24809
24810 -struct thermal_cooling_device_ops processor_cooling_ops = {
24811 +const struct thermal_cooling_device_ops processor_cooling_ops = {
24812 .get_max_state = processor_get_max_state,
24813 .get_cur_state = processor_get_cur_state,
24814 .set_cur_state = processor_set_cur_state,
24815 diff -urNp linux-2.6.39.2/drivers/acpi/sysfs.c linux-2.6.39.2/drivers/acpi/sysfs.c
24816 --- linux-2.6.39.2/drivers/acpi/sysfs.c 2011-05-19 00:06:34.000000000 -0400
24817 +++ linux-2.6.39.2/drivers/acpi/sysfs.c 2011-05-22 19:36:30.000000000 -0400
24818 @@ -149,12 +149,12 @@ static int param_get_debug_level(char *b
24819 return result;
24820 }
24821
24822 -static struct kernel_param_ops param_ops_debug_layer = {
24823 +static const struct kernel_param_ops param_ops_debug_layer = {
24824 .set = param_set_uint,
24825 .get = param_get_debug_layer,
24826 };
24827
24828 -static struct kernel_param_ops param_ops_debug_level = {
24829 +static const struct kernel_param_ops param_ops_debug_level = {
24830 .set = param_set_uint,
24831 .get = param_get_debug_level,
24832 };
24833 diff -urNp linux-2.6.39.2/drivers/acpi/thermal.c linux-2.6.39.2/drivers/acpi/thermal.c
24834 --- linux-2.6.39.2/drivers/acpi/thermal.c 2011-05-19 00:06:34.000000000 -0400
24835 +++ linux-2.6.39.2/drivers/acpi/thermal.c 2011-05-22 19:36:30.000000000 -0400
24836 @@ -812,7 +812,7 @@ acpi_thermal_unbind_cooling_device(struc
24837 thermal_zone_unbind_cooling_device);
24838 }
24839
24840 -static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24841 +static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
24842 .bind = acpi_thermal_bind_cooling_device,
24843 .unbind = acpi_thermal_unbind_cooling_device,
24844 .get_temp = thermal_get_temp,
24845 diff -urNp linux-2.6.39.2/drivers/acpi/video.c linux-2.6.39.2/drivers/acpi/video.c
24846 --- linux-2.6.39.2/drivers/acpi/video.c 2011-05-19 00:06:34.000000000 -0400
24847 +++ linux-2.6.39.2/drivers/acpi/video.c 2011-05-22 19:36:30.000000000 -0400
24848 @@ -308,7 +308,7 @@ video_set_cur_state(struct thermal_cooli
24849 return acpi_video_device_lcd_set_level(video, level);
24850 }
24851
24852 -static struct thermal_cooling_device_ops video_cooling_ops = {
24853 +static const struct thermal_cooling_device_ops video_cooling_ops = {
24854 .get_max_state = video_get_max_state,
24855 .get_cur_state = video_get_cur_state,
24856 .set_cur_state = video_set_cur_state,
24857 diff -urNp linux-2.6.39.2/drivers/ata/acard-ahci.c linux-2.6.39.2/drivers/ata/acard-ahci.c
24858 --- linux-2.6.39.2/drivers/ata/acard-ahci.c 2011-05-19 00:06:34.000000000 -0400
24859 +++ linux-2.6.39.2/drivers/ata/acard-ahci.c 2011-05-22 19:36:30.000000000 -0400
24860 @@ -87,7 +87,7 @@ static struct scsi_host_template acard_a
24861 AHCI_SHT("acard-ahci"),
24862 };
24863
24864 -static struct ata_port_operations acard_ops = {
24865 +static const struct ata_port_operations acard_ops = {
24866 .inherits = &ahci_ops,
24867 .qc_prep = acard_ahci_qc_prep,
24868 .qc_fill_rtf = acard_ahci_qc_fill_rtf,
24869 diff -urNp linux-2.6.39.2/drivers/ata/ahci.c linux-2.6.39.2/drivers/ata/ahci.c
24870 --- linux-2.6.39.2/drivers/ata/ahci.c 2011-05-19 00:06:34.000000000 -0400
24871 +++ linux-2.6.39.2/drivers/ata/ahci.c 2011-05-22 19:36:30.000000000 -0400
24872 @@ -94,17 +94,17 @@ static struct scsi_host_template ahci_sh
24873 AHCI_SHT("ahci"),
24874 };
24875
24876 -static struct ata_port_operations ahci_vt8251_ops = {
24877 +static const struct ata_port_operations ahci_vt8251_ops = {
24878 .inherits = &ahci_ops,
24879 .hardreset = ahci_vt8251_hardreset,
24880 };
24881
24882 -static struct ata_port_operations ahci_p5wdh_ops = {
24883 +static const struct ata_port_operations ahci_p5wdh_ops = {
24884 .inherits = &ahci_ops,
24885 .hardreset = ahci_p5wdh_hardreset,
24886 };
24887
24888 -static struct ata_port_operations ahci_sb600_ops = {
24889 +static const struct ata_port_operations ahci_sb600_ops = {
24890 .inherits = &ahci_ops,
24891 .softreset = ahci_sb600_softreset,
24892 .pmp_softreset = ahci_sb600_softreset,
24893 diff -urNp linux-2.6.39.2/drivers/ata/ahci.h linux-2.6.39.2/drivers/ata/ahci.h
24894 --- linux-2.6.39.2/drivers/ata/ahci.h 2011-05-19 00:06:34.000000000 -0400
24895 +++ linux-2.6.39.2/drivers/ata/ahci.h 2011-05-22 19:36:30.000000000 -0400
24896 @@ -311,7 +311,7 @@ extern struct device_attribute *ahci_sde
24897 .shost_attrs = ahci_shost_attrs, \
24898 .sdev_attrs = ahci_sdev_attrs
24899
24900 -extern struct ata_port_operations ahci_ops;
24901 +extern const struct ata_port_operations ahci_ops;
24902
24903 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
24904 u32 opts);
24905 diff -urNp linux-2.6.39.2/drivers/ata/ata_generic.c linux-2.6.39.2/drivers/ata/ata_generic.c
24906 --- linux-2.6.39.2/drivers/ata/ata_generic.c 2011-05-19 00:06:34.000000000 -0400
24907 +++ linux-2.6.39.2/drivers/ata/ata_generic.c 2011-05-22 19:36:30.000000000 -0400
24908 @@ -101,7 +101,7 @@ static struct scsi_host_template generic
24909 ATA_BMDMA_SHT(DRV_NAME),
24910 };
24911
24912 -static struct ata_port_operations generic_port_ops = {
24913 +static const struct ata_port_operations generic_port_ops = {
24914 .inherits = &ata_bmdma_port_ops,
24915 .cable_detect = ata_cable_unknown,
24916 .set_mode = generic_set_mode,
24917 diff -urNp linux-2.6.39.2/drivers/ata/ata_piix.c linux-2.6.39.2/drivers/ata/ata_piix.c
24918 --- linux-2.6.39.2/drivers/ata/ata_piix.c 2011-05-19 00:06:34.000000000 -0400
24919 +++ linux-2.6.39.2/drivers/ata/ata_piix.c 2011-05-22 19:36:30.000000000 -0400
24920 @@ -335,12 +335,12 @@ static struct scsi_host_template piix_sh
24921 ATA_BMDMA_SHT(DRV_NAME),
24922 };
24923
24924 -static struct ata_port_operations piix_sata_ops = {
24925 +static const struct ata_port_operations piix_sata_ops = {
24926 .inherits = &ata_bmdma32_port_ops,
24927 .sff_irq_check = piix_irq_check,
24928 };
24929
24930 -static struct ata_port_operations piix_pata_ops = {
24931 +static const struct ata_port_operations piix_pata_ops = {
24932 .inherits = &piix_sata_ops,
24933 .cable_detect = ata_cable_40wire,
24934 .set_piomode = piix_set_piomode,
24935 @@ -348,12 +348,12 @@ static struct ata_port_operations piix_p
24936 .prereset = piix_pata_prereset,
24937 };
24938
24939 -static struct ata_port_operations piix_vmw_ops = {
24940 +static const struct ata_port_operations piix_vmw_ops = {
24941 .inherits = &piix_pata_ops,
24942 .bmdma_status = piix_vmw_bmdma_status,
24943 };
24944
24945 -static struct ata_port_operations ich_pata_ops = {
24946 +static const struct ata_port_operations ich_pata_ops = {
24947 .inherits = &piix_pata_ops,
24948 .cable_detect = ich_pata_cable_detect,
24949 .set_dmamode = ich_set_dmamode,
24950 @@ -369,7 +369,7 @@ static struct scsi_host_template piix_si
24951 .shost_attrs = piix_sidpr_shost_attrs,
24952 };
24953
24954 -static struct ata_port_operations piix_sidpr_sata_ops = {
24955 +static const struct ata_port_operations piix_sidpr_sata_ops = {
24956 .inherits = &piix_sata_ops,
24957 .hardreset = sata_std_hardreset,
24958 .scr_read = piix_sidpr_scr_read,
24959 diff -urNp linux-2.6.39.2/drivers/ata/libahci.c linux-2.6.39.2/drivers/ata/libahci.c
24960 --- linux-2.6.39.2/drivers/ata/libahci.c 2011-05-19 00:06:34.000000000 -0400
24961 +++ linux-2.6.39.2/drivers/ata/libahci.c 2011-05-22 19:36:30.000000000 -0400
24962 @@ -141,7 +141,7 @@ struct device_attribute *ahci_sdev_attrs
24963 };
24964 EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
24965
24966 -struct ata_port_operations ahci_ops = {
24967 +const struct ata_port_operations ahci_ops = {
24968 .inherits = &sata_pmp_port_ops,
24969
24970 .qc_defer = ahci_pmp_qc_defer,
24971 diff -urNp linux-2.6.39.2/drivers/ata/libata-acpi.c linux-2.6.39.2/drivers/ata/libata-acpi.c
24972 --- linux-2.6.39.2/drivers/ata/libata-acpi.c 2011-05-19 00:06:34.000000000 -0400
24973 +++ linux-2.6.39.2/drivers/ata/libata-acpi.c 2011-05-22 19:36:30.000000000 -0400
24974 @@ -218,12 +218,12 @@ static void ata_acpi_dev_uevent(acpi_han
24975 ata_acpi_uevent(dev->link->ap, dev, event);
24976 }
24977
24978 -static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24979 +static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
24980 .handler = ata_acpi_dev_notify_dock,
24981 .uevent = ata_acpi_dev_uevent,
24982 };
24983
24984 -static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24985 +static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
24986 .handler = ata_acpi_ap_notify_dock,
24987 .uevent = ata_acpi_ap_uevent,
24988 };
24989 diff -urNp linux-2.6.39.2/drivers/ata/libata-core.c linux-2.6.39.2/drivers/ata/libata-core.c
24990 --- linux-2.6.39.2/drivers/ata/libata-core.c 2011-05-19 00:06:34.000000000 -0400
24991 +++ linux-2.6.39.2/drivers/ata/libata-core.c 2011-05-22 19:36:30.000000000 -0400
24992 @@ -4747,7 +4747,7 @@ void ata_qc_free(struct ata_queued_cmd *
24993 struct ata_port *ap;
24994 unsigned int tag;
24995
24996 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24997 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
24998 ap = qc->ap;
24999
25000 qc->flags = 0;
25001 @@ -4763,7 +4763,7 @@ void __ata_qc_complete(struct ata_queued
25002 struct ata_port *ap;
25003 struct ata_link *link;
25004
25005 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25006 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25007 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25008 ap = qc->ap;
25009 link = qc->dev->link;
25010 @@ -5756,7 +5756,7 @@ static void ata_host_stop(struct device
25011 * LOCKING:
25012 * None.
25013 */
25014 -static void ata_finalize_port_ops(struct ata_port_operations *ops)
25015 +static void ata_finalize_port_ops(const struct ata_port_operations *ops)
25016 {
25017 static DEFINE_SPINLOCK(lock);
25018 const struct ata_port_operations *cur;
25019 @@ -5768,6 +5768,7 @@ static void ata_finalize_port_ops(struct
25020 return;
25021
25022 spin_lock(&lock);
25023 + pax_open_kernel();
25024
25025 for (cur = ops->inherits; cur; cur = cur->inherits) {
25026 void **inherit = (void **)cur;
25027 @@ -5781,8 +5782,9 @@ static void ata_finalize_port_ops(struct
25028 if (IS_ERR(*pp))
25029 *pp = NULL;
25030
25031 - ops->inherits = NULL;
25032 + ((struct ata_port_operations *)ops)->inherits = NULL;
25033
25034 + pax_close_kernel();
25035 spin_unlock(&lock);
25036 }
25037
25038 @@ -5879,7 +5881,7 @@ int ata_host_start(struct ata_host *host
25039 */
25040 /* KILLME - the only user left is ipr */
25041 void ata_host_init(struct ata_host *host, struct device *dev,
25042 - unsigned long flags, struct ata_port_operations *ops)
25043 + unsigned long flags, const struct ata_port_operations *ops)
25044 {
25045 spin_lock_init(&host->lock);
25046 mutex_init(&host->eh_mutex);
25047 @@ -6583,7 +6585,7 @@ static void ata_dummy_error_handler(stru
25048 /* truly dummy */
25049 }
25050
25051 -struct ata_port_operations ata_dummy_port_ops = {
25052 +const struct ata_port_operations ata_dummy_port_ops = {
25053 .qc_prep = ata_noop_qc_prep,
25054 .qc_issue = ata_dummy_qc_issue,
25055 .error_handler = ata_dummy_error_handler,
25056 diff -urNp linux-2.6.39.2/drivers/ata/libata-eh.c linux-2.6.39.2/drivers/ata/libata-eh.c
25057 --- linux-2.6.39.2/drivers/ata/libata-eh.c 2011-05-19 00:06:34.000000000 -0400
25058 +++ linux-2.6.39.2/drivers/ata/libata-eh.c 2011-05-22 19:36:30.000000000 -0400
25059 @@ -2518,6 +2518,8 @@ void ata_eh_report(struct ata_port *ap)
25060 {
25061 struct ata_link *link;
25062
25063 + pax_track_stack();
25064 +
25065 ata_for_each_link(link, ap, HOST_FIRST)
25066 ata_eh_link_report(link);
25067 }
25068 @@ -3922,7 +3924,7 @@ void ata_do_eh(struct ata_port *ap, ata_
25069 */
25070 void ata_std_error_handler(struct ata_port *ap)
25071 {
25072 - struct ata_port_operations *ops = ap->ops;
25073 + const struct ata_port_operations *ops = ap->ops;
25074 ata_reset_fn_t hardreset = ops->hardreset;
25075
25076 /* ignore built-in hardreset if SCR access is not available */
25077 diff -urNp linux-2.6.39.2/drivers/ata/libata-pmp.c linux-2.6.39.2/drivers/ata/libata-pmp.c
25078 --- linux-2.6.39.2/drivers/ata/libata-pmp.c 2011-05-19 00:06:34.000000000 -0400
25079 +++ linux-2.6.39.2/drivers/ata/libata-pmp.c 2011-05-22 19:36:30.000000000 -0400
25080 @@ -912,7 +912,7 @@ static int sata_pmp_handle_link_fail(str
25081 */
25082 static int sata_pmp_eh_recover(struct ata_port *ap)
25083 {
25084 - struct ata_port_operations *ops = ap->ops;
25085 + const struct ata_port_operations *ops = ap->ops;
25086 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
25087 struct ata_link *pmp_link = &ap->link;
25088 struct ata_device *pmp_dev = pmp_link->device;
25089 diff -urNp linux-2.6.39.2/drivers/ata/pata_acpi.c linux-2.6.39.2/drivers/ata/pata_acpi.c
25090 --- linux-2.6.39.2/drivers/ata/pata_acpi.c 2011-05-19 00:06:34.000000000 -0400
25091 +++ linux-2.6.39.2/drivers/ata/pata_acpi.c 2011-05-22 19:36:30.000000000 -0400
25092 @@ -216,7 +216,7 @@ static struct scsi_host_template pacpi_s
25093 ATA_BMDMA_SHT(DRV_NAME),
25094 };
25095
25096 -static struct ata_port_operations pacpi_ops = {
25097 +static const struct ata_port_operations pacpi_ops = {
25098 .inherits = &ata_bmdma_port_ops,
25099 .qc_issue = pacpi_qc_issue,
25100 .cable_detect = pacpi_cable_detect,
25101 diff -urNp linux-2.6.39.2/drivers/ata/pata_ali.c linux-2.6.39.2/drivers/ata/pata_ali.c
25102 --- linux-2.6.39.2/drivers/ata/pata_ali.c 2011-05-19 00:06:34.000000000 -0400
25103 +++ linux-2.6.39.2/drivers/ata/pata_ali.c 2011-05-22 19:36:30.000000000 -0400
25104 @@ -363,7 +363,7 @@ static struct scsi_host_template ali_sht
25105 * Port operations for PIO only ALi
25106 */
25107
25108 -static struct ata_port_operations ali_early_port_ops = {
25109 +static const struct ata_port_operations ali_early_port_ops = {
25110 .inherits = &ata_sff_port_ops,
25111 .cable_detect = ata_cable_40wire,
25112 .set_piomode = ali_set_piomode,
25113 @@ -380,7 +380,7 @@ static const struct ata_port_operations
25114 * Port operations for DMA capable ALi without cable
25115 * detect
25116 */
25117 -static struct ata_port_operations ali_20_port_ops = {
25118 +static const struct ata_port_operations ali_20_port_ops = {
25119 .inherits = &ali_dma_base_ops,
25120 .cable_detect = ata_cable_40wire,
25121 .mode_filter = ali_20_filter,
25122 @@ -391,7 +391,7 @@ static struct ata_port_operations ali_20
25123 /*
25124 * Port operations for DMA capable ALi with cable detect
25125 */
25126 -static struct ata_port_operations ali_c2_port_ops = {
25127 +static const struct ata_port_operations ali_c2_port_ops = {
25128 .inherits = &ali_dma_base_ops,
25129 .check_atapi_dma = ali_check_atapi_dma,
25130 .cable_detect = ali_c2_cable_detect,
25131 @@ -402,7 +402,7 @@ static struct ata_port_operations ali_c2
25132 /*
25133 * Port operations for DMA capable ALi with cable detect
25134 */
25135 -static struct ata_port_operations ali_c4_port_ops = {
25136 +static const struct ata_port_operations ali_c4_port_ops = {
25137 .inherits = &ali_dma_base_ops,
25138 .check_atapi_dma = ali_check_atapi_dma,
25139 .cable_detect = ali_c2_cable_detect,
25140 @@ -412,7 +412,7 @@ static struct ata_port_operations ali_c4
25141 /*
25142 * Port operations for DMA capable ALi with cable detect and LBA48
25143 */
25144 -static struct ata_port_operations ali_c5_port_ops = {
25145 +static const struct ata_port_operations ali_c5_port_ops = {
25146 .inherits = &ali_dma_base_ops,
25147 .check_atapi_dma = ali_check_atapi_dma,
25148 .dev_config = ali_warn_atapi_dma,
25149 diff -urNp linux-2.6.39.2/drivers/ata/pata_amd.c linux-2.6.39.2/drivers/ata/pata_amd.c
25150 --- linux-2.6.39.2/drivers/ata/pata_amd.c 2011-05-19 00:06:34.000000000 -0400
25151 +++ linux-2.6.39.2/drivers/ata/pata_amd.c 2011-05-22 19:36:31.000000000 -0400
25152 @@ -397,28 +397,28 @@ static const struct ata_port_operations
25153 .prereset = amd_pre_reset,
25154 };
25155
25156 -static struct ata_port_operations amd33_port_ops = {
25157 +static const struct ata_port_operations amd33_port_ops = {
25158 .inherits = &amd_base_port_ops,
25159 .cable_detect = ata_cable_40wire,
25160 .set_piomode = amd33_set_piomode,
25161 .set_dmamode = amd33_set_dmamode,
25162 };
25163
25164 -static struct ata_port_operations amd66_port_ops = {
25165 +static const struct ata_port_operations amd66_port_ops = {
25166 .inherits = &amd_base_port_ops,
25167 .cable_detect = ata_cable_unknown,
25168 .set_piomode = amd66_set_piomode,
25169 .set_dmamode = amd66_set_dmamode,
25170 };
25171
25172 -static struct ata_port_operations amd100_port_ops = {
25173 +static const struct ata_port_operations amd100_port_ops = {
25174 .inherits = &amd_base_port_ops,
25175 .cable_detect = ata_cable_unknown,
25176 .set_piomode = amd100_set_piomode,
25177 .set_dmamode = amd100_set_dmamode,
25178 };
25179
25180 -static struct ata_port_operations amd133_port_ops = {
25181 +static const struct ata_port_operations amd133_port_ops = {
25182 .inherits = &amd_base_port_ops,
25183 .cable_detect = amd_cable_detect,
25184 .set_piomode = amd133_set_piomode,
25185 @@ -433,13 +433,13 @@ static const struct ata_port_operations
25186 .host_stop = nv_host_stop,
25187 };
25188
25189 -static struct ata_port_operations nv100_port_ops = {
25190 +static const struct ata_port_operations nv100_port_ops = {
25191 .inherits = &nv_base_port_ops,
25192 .set_piomode = nv100_set_piomode,
25193 .set_dmamode = nv100_set_dmamode,
25194 };
25195
25196 -static struct ata_port_operations nv133_port_ops = {
25197 +static const struct ata_port_operations nv133_port_ops = {
25198 .inherits = &nv_base_port_ops,
25199 .set_piomode = nv133_set_piomode,
25200 .set_dmamode = nv133_set_dmamode,
25201 diff -urNp linux-2.6.39.2/drivers/ata/pata_arasan_cf.c linux-2.6.39.2/drivers/ata/pata_arasan_cf.c
25202 --- linux-2.6.39.2/drivers/ata/pata_arasan_cf.c 2011-05-19 00:06:34.000000000 -0400
25203 +++ linux-2.6.39.2/drivers/ata/pata_arasan_cf.c 2011-05-22 19:36:31.000000000 -0400
25204 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(str
25205 /* Handle platform specific quirks */
25206 if (pdata->quirk) {
25207 if (pdata->quirk & CF_BROKEN_PIO) {
25208 - ap->ops->set_piomode = NULL;
25209 + pax_open_kernel();
25210 + *(void**)&ap->ops->set_piomode = NULL;
25211 + pax_close_kernel();
25212 ap->pio_mask = 0;
25213 }
25214 if (pdata->quirk & CF_BROKEN_MWDMA)
25215 diff -urNp linux-2.6.39.2/drivers/ata/pata_artop.c linux-2.6.39.2/drivers/ata/pata_artop.c
25216 --- linux-2.6.39.2/drivers/ata/pata_artop.c 2011-05-19 00:06:34.000000000 -0400
25217 +++ linux-2.6.39.2/drivers/ata/pata_artop.c 2011-05-22 19:36:31.000000000 -0400
25218 @@ -312,7 +312,7 @@ static struct scsi_host_template artop_s
25219 ATA_BMDMA_SHT(DRV_NAME),
25220 };
25221
25222 -static struct ata_port_operations artop6210_ops = {
25223 +static const struct ata_port_operations artop6210_ops = {
25224 .inherits = &ata_bmdma_port_ops,
25225 .cable_detect = ata_cable_40wire,
25226 .set_piomode = artop6210_set_piomode,
25227 @@ -321,7 +321,7 @@ static struct ata_port_operations artop6
25228 .qc_defer = artop6210_qc_defer,
25229 };
25230
25231 -static struct ata_port_operations artop6260_ops = {
25232 +static const struct ata_port_operations artop6260_ops = {
25233 .inherits = &ata_bmdma_port_ops,
25234 .cable_detect = artop6260_cable_detect,
25235 .set_piomode = artop6260_set_piomode,
25236 diff -urNp linux-2.6.39.2/drivers/ata/pata_at32.c linux-2.6.39.2/drivers/ata/pata_at32.c
25237 --- linux-2.6.39.2/drivers/ata/pata_at32.c 2011-05-19 00:06:34.000000000 -0400
25238 +++ linux-2.6.39.2/drivers/ata/pata_at32.c 2011-05-22 19:36:31.000000000 -0400
25239 @@ -173,7 +173,7 @@ static struct scsi_host_template at32_sh
25240 ATA_PIO_SHT(DRV_NAME),
25241 };
25242
25243 -static struct ata_port_operations at32_port_ops = {
25244 +static const struct ata_port_operations at32_port_ops = {
25245 .inherits = &ata_sff_port_ops,
25246 .cable_detect = ata_cable_40wire,
25247 .set_piomode = pata_at32_set_piomode,
25248 diff -urNp linux-2.6.39.2/drivers/ata/pata_at91.c linux-2.6.39.2/drivers/ata/pata_at91.c
25249 --- linux-2.6.39.2/drivers/ata/pata_at91.c 2011-05-19 00:06:34.000000000 -0400
25250 +++ linux-2.6.39.2/drivers/ata/pata_at91.c 2011-05-22 19:36:31.000000000 -0400
25251 @@ -212,7 +212,7 @@ static struct scsi_host_template pata_at
25252 ATA_PIO_SHT(DRV_NAME),
25253 };
25254
25255 -static struct ata_port_operations pata_at91_port_ops = {
25256 +static const struct ata_port_operations pata_at91_port_ops = {
25257 .inherits = &ata_sff_port_ops,
25258
25259 .sff_data_xfer = pata_at91_data_xfer_noirq,
25260 diff -urNp linux-2.6.39.2/drivers/ata/pata_atiixp.c linux-2.6.39.2/drivers/ata/pata_atiixp.c
25261 --- linux-2.6.39.2/drivers/ata/pata_atiixp.c 2011-05-19 00:06:34.000000000 -0400
25262 +++ linux-2.6.39.2/drivers/ata/pata_atiixp.c 2011-05-22 19:36:31.000000000 -0400
25263 @@ -214,7 +214,7 @@ static struct scsi_host_template atiixp_
25264 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25265 };
25266
25267 -static struct ata_port_operations atiixp_port_ops = {
25268 +static const struct ata_port_operations atiixp_port_ops = {
25269 .inherits = &ata_bmdma_port_ops,
25270
25271 .qc_prep = ata_bmdma_dumb_qc_prep,
25272 diff -urNp linux-2.6.39.2/drivers/ata/pata_atp867x.c linux-2.6.39.2/drivers/ata/pata_atp867x.c
25273 --- linux-2.6.39.2/drivers/ata/pata_atp867x.c 2011-05-19 00:06:34.000000000 -0400
25274 +++ linux-2.6.39.2/drivers/ata/pata_atp867x.c 2011-05-22 19:36:31.000000000 -0400
25275 @@ -275,7 +275,7 @@ static struct scsi_host_template atp867x
25276 ATA_BMDMA_SHT(DRV_NAME),
25277 };
25278
25279 -static struct ata_port_operations atp867x_ops = {
25280 +static const struct ata_port_operations atp867x_ops = {
25281 .inherits = &ata_bmdma_port_ops,
25282 .cable_detect = atp867x_cable_detect,
25283 .set_piomode = atp867x_set_piomode,
25284 diff -urNp linux-2.6.39.2/drivers/ata/pata_bf54x.c linux-2.6.39.2/drivers/ata/pata_bf54x.c
25285 --- linux-2.6.39.2/drivers/ata/pata_bf54x.c 2011-05-19 00:06:34.000000000 -0400
25286 +++ linux-2.6.39.2/drivers/ata/pata_bf54x.c 2011-05-22 19:36:31.000000000 -0400
25287 @@ -1420,7 +1420,7 @@ static struct scsi_host_template bfin_sh
25288 .dma_boundary = ATA_DMA_BOUNDARY,
25289 };
25290
25291 -static struct ata_port_operations bfin_pata_ops = {
25292 +static const struct ata_port_operations bfin_pata_ops = {
25293 .inherits = &ata_bmdma_port_ops,
25294
25295 .set_piomode = bfin_set_piomode,
25296 diff -urNp linux-2.6.39.2/drivers/ata/pata_cmd640.c linux-2.6.39.2/drivers/ata/pata_cmd640.c
25297 --- linux-2.6.39.2/drivers/ata/pata_cmd640.c 2011-05-19 00:06:34.000000000 -0400
25298 +++ linux-2.6.39.2/drivers/ata/pata_cmd640.c 2011-05-22 19:36:31.000000000 -0400
25299 @@ -176,7 +176,7 @@ static struct scsi_host_template cmd640_
25300 ATA_PIO_SHT(DRV_NAME),
25301 };
25302
25303 -static struct ata_port_operations cmd640_port_ops = {
25304 +static const struct ata_port_operations cmd640_port_ops = {
25305 .inherits = &ata_sff_port_ops,
25306 /* In theory xfer_noirq is not needed once we kill the prefetcher */
25307 .sff_data_xfer = ata_sff_data_xfer_noirq,
25308 diff -urNp linux-2.6.39.2/drivers/ata/pata_cmd64x.c linux-2.6.39.2/drivers/ata/pata_cmd64x.c
25309 --- linux-2.6.39.2/drivers/ata/pata_cmd64x.c 2011-06-03 00:04:13.000000000 -0400
25310 +++ linux-2.6.39.2/drivers/ata/pata_cmd64x.c 2011-06-03 00:32:05.000000000 -0400
25311 @@ -271,18 +271,18 @@ static const struct ata_port_operations
25312 .set_dmamode = cmd64x_set_dmamode,
25313 };
25314
25315 -static struct ata_port_operations cmd64x_port_ops = {
25316 +static const struct ata_port_operations cmd64x_port_ops = {
25317 .inherits = &cmd64x_base_ops,
25318 .cable_detect = ata_cable_40wire,
25319 };
25320
25321 -static struct ata_port_operations cmd646r1_port_ops = {
25322 +static const struct ata_port_operations cmd646r1_port_ops = {
25323 .inherits = &cmd64x_base_ops,
25324 .bmdma_stop = cmd646r1_bmdma_stop,
25325 .cable_detect = ata_cable_40wire,
25326 };
25327
25328 -static struct ata_port_operations cmd648_port_ops = {
25329 +static const struct ata_port_operations cmd648_port_ops = {
25330 .inherits = &cmd64x_base_ops,
25331 .bmdma_stop = cmd648_bmdma_stop,
25332 .cable_detect = cmd648_cable_detect,
25333 diff -urNp linux-2.6.39.2/drivers/ata/pata_cs5520.c linux-2.6.39.2/drivers/ata/pata_cs5520.c
25334 --- linux-2.6.39.2/drivers/ata/pata_cs5520.c 2011-05-19 00:06:34.000000000 -0400
25335 +++ linux-2.6.39.2/drivers/ata/pata_cs5520.c 2011-05-22 19:36:31.000000000 -0400
25336 @@ -108,7 +108,7 @@ static struct scsi_host_template cs5520_
25337 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25338 };
25339
25340 -static struct ata_port_operations cs5520_port_ops = {
25341 +static const struct ata_port_operations cs5520_port_ops = {
25342 .inherits = &ata_bmdma_port_ops,
25343 .qc_prep = ata_bmdma_dumb_qc_prep,
25344 .cable_detect = ata_cable_40wire,
25345 diff -urNp linux-2.6.39.2/drivers/ata/pata_cs5530.c linux-2.6.39.2/drivers/ata/pata_cs5530.c
25346 --- linux-2.6.39.2/drivers/ata/pata_cs5530.c 2011-05-19 00:06:34.000000000 -0400
25347 +++ linux-2.6.39.2/drivers/ata/pata_cs5530.c 2011-05-22 19:36:31.000000000 -0400
25348 @@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_
25349 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
25350 };
25351
25352 -static struct ata_port_operations cs5530_port_ops = {
25353 +static const struct ata_port_operations cs5530_port_ops = {
25354 .inherits = &ata_bmdma_port_ops,
25355
25356 .qc_prep = ata_bmdma_dumb_qc_prep,
25357 diff -urNp linux-2.6.39.2/drivers/ata/pata_cs5535.c linux-2.6.39.2/drivers/ata/pata_cs5535.c
25358 --- linux-2.6.39.2/drivers/ata/pata_cs5535.c 2011-05-19 00:06:34.000000000 -0400
25359 +++ linux-2.6.39.2/drivers/ata/pata_cs5535.c 2011-05-22 19:36:31.000000000 -0400
25360 @@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_
25361 ATA_BMDMA_SHT(DRV_NAME),
25362 };
25363
25364 -static struct ata_port_operations cs5535_port_ops = {
25365 +static const struct ata_port_operations cs5535_port_ops = {
25366 .inherits = &ata_bmdma_port_ops,
25367 .cable_detect = cs5535_cable_detect,
25368 .set_piomode = cs5535_set_piomode,
25369 diff -urNp linux-2.6.39.2/drivers/ata/pata_cs5536.c linux-2.6.39.2/drivers/ata/pata_cs5536.c
25370 --- linux-2.6.39.2/drivers/ata/pata_cs5536.c 2011-05-19 00:06:34.000000000 -0400
25371 +++ linux-2.6.39.2/drivers/ata/pata_cs5536.c 2011-05-22 19:36:31.000000000 -0400
25372 @@ -233,7 +233,7 @@ static struct scsi_host_template cs5536_
25373 ATA_BMDMA_SHT(DRV_NAME),
25374 };
25375
25376 -static struct ata_port_operations cs5536_port_ops = {
25377 +static const struct ata_port_operations cs5536_port_ops = {
25378 .inherits = &ata_bmdma32_port_ops,
25379 .cable_detect = cs5536_cable_detect,
25380 .set_piomode = cs5536_set_piomode,
25381 diff -urNp linux-2.6.39.2/drivers/ata/pata_cypress.c linux-2.6.39.2/drivers/ata/pata_cypress.c
25382 --- linux-2.6.39.2/drivers/ata/pata_cypress.c 2011-05-19 00:06:34.000000000 -0400
25383 +++ linux-2.6.39.2/drivers/ata/pata_cypress.c 2011-05-22 19:36:31.000000000 -0400
25384 @@ -115,7 +115,7 @@ static struct scsi_host_template cy82c69
25385 ATA_BMDMA_SHT(DRV_NAME),
25386 };
25387
25388 -static struct ata_port_operations cy82c693_port_ops = {
25389 +static const struct ata_port_operations cy82c693_port_ops = {
25390 .inherits = &ata_bmdma_port_ops,
25391 .cable_detect = ata_cable_40wire,
25392 .set_piomode = cy82c693_set_piomode,
25393 diff -urNp linux-2.6.39.2/drivers/ata/pata_efar.c linux-2.6.39.2/drivers/ata/pata_efar.c
25394 --- linux-2.6.39.2/drivers/ata/pata_efar.c 2011-05-19 00:06:34.000000000 -0400
25395 +++ linux-2.6.39.2/drivers/ata/pata_efar.c 2011-05-22 19:36:31.000000000 -0400
25396 @@ -238,7 +238,7 @@ static struct scsi_host_template efar_sh
25397 ATA_BMDMA_SHT(DRV_NAME),
25398 };
25399
25400 -static struct ata_port_operations efar_ops = {
25401 +static const struct ata_port_operations efar_ops = {
25402 .inherits = &ata_bmdma_port_ops,
25403 .cable_detect = efar_cable_detect,
25404 .set_piomode = efar_set_piomode,
25405 diff -urNp linux-2.6.39.2/drivers/ata/pata_hpt366.c linux-2.6.39.2/drivers/ata/pata_hpt366.c
25406 --- linux-2.6.39.2/drivers/ata/pata_hpt366.c 2011-05-19 00:06:34.000000000 -0400
25407 +++ linux-2.6.39.2/drivers/ata/pata_hpt366.c 2011-05-22 19:36:31.000000000 -0400
25408 @@ -276,7 +276,7 @@ static struct scsi_host_template hpt36x_
25409 * Configuration for HPT366/68
25410 */
25411
25412 -static struct ata_port_operations hpt366_port_ops = {
25413 +static const struct ata_port_operations hpt366_port_ops = {
25414 .inherits = &ata_bmdma_port_ops,
25415 .cable_detect = hpt36x_cable_detect,
25416 .mode_filter = hpt366_filter,
25417 diff -urNp linux-2.6.39.2/drivers/ata/pata_hpt37x.c linux-2.6.39.2/drivers/ata/pata_hpt37x.c
25418 --- linux-2.6.39.2/drivers/ata/pata_hpt37x.c 2011-05-19 00:06:34.000000000 -0400
25419 +++ linux-2.6.39.2/drivers/ata/pata_hpt37x.c 2011-05-22 19:36:31.000000000 -0400
25420 @@ -589,7 +589,7 @@ static struct scsi_host_template hpt37x_
25421 * Configuration for HPT370
25422 */
25423
25424 -static struct ata_port_operations hpt370_port_ops = {
25425 +static const struct ata_port_operations hpt370_port_ops = {
25426 .inherits = &ata_bmdma_port_ops,
25427
25428 .bmdma_stop = hpt370_bmdma_stop,
25429 @@ -605,7 +605,7 @@ static struct ata_port_operations hpt370
25430 * Configuration for HPT370A. Close to 370 but less filters
25431 */
25432
25433 -static struct ata_port_operations hpt370a_port_ops = {
25434 +static const struct ata_port_operations hpt370a_port_ops = {
25435 .inherits = &hpt370_port_ops,
25436 .mode_filter = hpt370a_filter,
25437 };
25438 @@ -615,7 +615,7 @@ static struct ata_port_operations hpt370
25439 * mode setting functionality.
25440 */
25441
25442 -static struct ata_port_operations hpt302_port_ops = {
25443 +static const struct ata_port_operations hpt302_port_ops = {
25444 .inherits = &ata_bmdma_port_ops,
25445
25446 .bmdma_stop = hpt37x_bmdma_stop,
25447 @@ -631,7 +631,7 @@ static struct ata_port_operations hpt302
25448 * but we have a mode filter.
25449 */
25450
25451 -static struct ata_port_operations hpt372_port_ops = {
25452 +static const struct ata_port_operations hpt372_port_ops = {
25453 .inherits = &hpt302_port_ops,
25454 .mode_filter = hpt372_filter,
25455 };
25456 @@ -641,7 +641,7 @@ static struct ata_port_operations hpt372
25457 * but we have a different cable detection procedure for function 1.
25458 */
25459
25460 -static struct ata_port_operations hpt374_fn1_port_ops = {
25461 +static const struct ata_port_operations hpt374_fn1_port_ops = {
25462 .inherits = &hpt372_port_ops,
25463 .cable_detect = hpt374_fn1_cable_detect,
25464 };
25465 diff -urNp linux-2.6.39.2/drivers/ata/pata_hpt3x2n.c linux-2.6.39.2/drivers/ata/pata_hpt3x2n.c
25466 --- linux-2.6.39.2/drivers/ata/pata_hpt3x2n.c 2011-05-19 00:06:34.000000000 -0400
25467 +++ linux-2.6.39.2/drivers/ata/pata_hpt3x2n.c 2011-05-22 19:36:31.000000000 -0400
25468 @@ -350,7 +350,7 @@ static struct scsi_host_template hpt3x2n
25469 * Configuration for HPT302N/371N.
25470 */
25471
25472 -static struct ata_port_operations hpt3xxn_port_ops = {
25473 +static const struct ata_port_operations hpt3xxn_port_ops = {
25474 .inherits = &ata_bmdma_port_ops,
25475
25476 .bmdma_stop = hpt3x2n_bmdma_stop,
25477 @@ -368,7 +368,7 @@ static struct ata_port_operations hpt3xx
25478 * Configuration for HPT372N. Same as 302N/371N but we have a mode filter.
25479 */
25480
25481 -static struct ata_port_operations hpt372n_port_ops = {
25482 +static const struct ata_port_operations hpt372n_port_ops = {
25483 .inherits = &hpt3xxn_port_ops,
25484 .mode_filter = &hpt372n_filter,
25485 };
25486 diff -urNp linux-2.6.39.2/drivers/ata/pata_hpt3x3.c linux-2.6.39.2/drivers/ata/pata_hpt3x3.c
25487 --- linux-2.6.39.2/drivers/ata/pata_hpt3x3.c 2011-05-19 00:06:34.000000000 -0400
25488 +++ linux-2.6.39.2/drivers/ata/pata_hpt3x3.c 2011-05-22 19:36:31.000000000 -0400
25489 @@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_
25490 ATA_BMDMA_SHT(DRV_NAME),
25491 };
25492
25493 -static struct ata_port_operations hpt3x3_port_ops = {
25494 +static const struct ata_port_operations hpt3x3_port_ops = {
25495 .inherits = &ata_bmdma_port_ops,
25496 .cable_detect = ata_cable_40wire,
25497 .set_piomode = hpt3x3_set_piomode,
25498 diff -urNp linux-2.6.39.2/drivers/ata/pata_icside.c linux-2.6.39.2/drivers/ata/pata_icside.c
25499 --- linux-2.6.39.2/drivers/ata/pata_icside.c 2011-05-19 00:06:34.000000000 -0400
25500 +++ linux-2.6.39.2/drivers/ata/pata_icside.c 2011-05-22 19:36:31.000000000 -0400
25501 @@ -320,7 +320,7 @@ static void pata_icside_postreset(struct
25502 }
25503 }
25504
25505 -static struct ata_port_operations pata_icside_port_ops = {
25506 +static const struct ata_port_operations pata_icside_port_ops = {
25507 .inherits = &ata_bmdma_port_ops,
25508 /* no need to build any PRD tables for DMA */
25509 .qc_prep = ata_noop_qc_prep,
25510 diff -urNp linux-2.6.39.2/drivers/ata/pata_isapnp.c linux-2.6.39.2/drivers/ata/pata_isapnp.c
25511 --- linux-2.6.39.2/drivers/ata/pata_isapnp.c 2011-05-19 00:06:34.000000000 -0400
25512 +++ linux-2.6.39.2/drivers/ata/pata_isapnp.c 2011-05-22 19:36:31.000000000 -0400
25513 @@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_
25514 ATA_PIO_SHT(DRV_NAME),
25515 };
25516
25517 -static struct ata_port_operations isapnp_port_ops = {
25518 +static const struct ata_port_operations isapnp_port_ops = {
25519 .inherits = &ata_sff_port_ops,
25520 .cable_detect = ata_cable_40wire,
25521 };
25522
25523 -static struct ata_port_operations isapnp_noalt_port_ops = {
25524 +static const struct ata_port_operations isapnp_noalt_port_ops = {
25525 .inherits = &ata_sff_port_ops,
25526 .cable_detect = ata_cable_40wire,
25527 /* No altstatus so we don't want to use the lost interrupt poll */
25528 diff -urNp linux-2.6.39.2/drivers/ata/pata_it8213.c linux-2.6.39.2/drivers/ata/pata_it8213.c
25529 --- linux-2.6.39.2/drivers/ata/pata_it8213.c 2011-05-19 00:06:34.000000000 -0400
25530 +++ linux-2.6.39.2/drivers/ata/pata_it8213.c 2011-05-22 19:36:31.000000000 -0400
25531 @@ -233,7 +233,7 @@ static struct scsi_host_template it8213_
25532 };
25533
25534
25535 -static struct ata_port_operations it8213_ops = {
25536 +static const struct ata_port_operations it8213_ops = {
25537 .inherits = &ata_bmdma_port_ops,
25538 .cable_detect = it8213_cable_detect,
25539 .set_piomode = it8213_set_piomode,
25540 diff -urNp linux-2.6.39.2/drivers/ata/pata_it821x.c linux-2.6.39.2/drivers/ata/pata_it821x.c
25541 --- linux-2.6.39.2/drivers/ata/pata_it821x.c 2011-05-19 00:06:34.000000000 -0400
25542 +++ linux-2.6.39.2/drivers/ata/pata_it821x.c 2011-05-22 19:36:31.000000000 -0400
25543 @@ -801,7 +801,7 @@ static struct scsi_host_template it821x_
25544 ATA_BMDMA_SHT(DRV_NAME),
25545 };
25546
25547 -static struct ata_port_operations it821x_smart_port_ops = {
25548 +static const struct ata_port_operations it821x_smart_port_ops = {
25549 .inherits = &ata_bmdma_port_ops,
25550
25551 .check_atapi_dma= it821x_check_atapi_dma,
25552 @@ -815,7 +815,7 @@ static struct ata_port_operations it821x
25553 .port_start = it821x_port_start,
25554 };
25555
25556 -static struct ata_port_operations it821x_passthru_port_ops = {
25557 +static const struct ata_port_operations it821x_passthru_port_ops = {
25558 .inherits = &ata_bmdma_port_ops,
25559
25560 .check_atapi_dma= it821x_check_atapi_dma,
25561 @@ -831,7 +831,7 @@ static struct ata_port_operations it821x
25562 .port_start = it821x_port_start,
25563 };
25564
25565 -static struct ata_port_operations it821x_rdc_port_ops = {
25566 +static const struct ata_port_operations it821x_rdc_port_ops = {
25567 .inherits = &ata_bmdma_port_ops,
25568
25569 .check_atapi_dma= it821x_check_atapi_dma,
25570 diff -urNp linux-2.6.39.2/drivers/ata/pata_ixp4xx_cf.c linux-2.6.39.2/drivers/ata/pata_ixp4xx_cf.c
25571 --- linux-2.6.39.2/drivers/ata/pata_ixp4xx_cf.c 2011-05-19 00:06:34.000000000 -0400
25572 +++ linux-2.6.39.2/drivers/ata/pata_ixp4xx_cf.c 2011-05-22 19:36:31.000000000 -0400
25573 @@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_
25574 ATA_PIO_SHT(DRV_NAME),
25575 };
25576
25577 -static struct ata_port_operations ixp4xx_port_ops = {
25578 +static const struct ata_port_operations ixp4xx_port_ops = {
25579 .inherits = &ata_sff_port_ops,
25580 .sff_data_xfer = ixp4xx_mmio_data_xfer,
25581 .cable_detect = ata_cable_40wire,
25582 diff -urNp linux-2.6.39.2/drivers/ata/pata_jmicron.c linux-2.6.39.2/drivers/ata/pata_jmicron.c
25583 --- linux-2.6.39.2/drivers/ata/pata_jmicron.c 2011-05-19 00:06:34.000000000 -0400
25584 +++ linux-2.6.39.2/drivers/ata/pata_jmicron.c 2011-05-22 19:36:31.000000000 -0400
25585 @@ -111,7 +111,7 @@ static struct scsi_host_template jmicron
25586 ATA_BMDMA_SHT(DRV_NAME),
25587 };
25588
25589 -static struct ata_port_operations jmicron_ops = {
25590 +static const struct ata_port_operations jmicron_ops = {
25591 .inherits = &ata_bmdma_port_ops,
25592 .prereset = jmicron_pre_reset,
25593 };
25594 diff -urNp linux-2.6.39.2/drivers/ata/pata_legacy.c linux-2.6.39.2/drivers/ata/pata_legacy.c
25595 --- linux-2.6.39.2/drivers/ata/pata_legacy.c 2011-05-19 00:06:34.000000000 -0400
25596 +++ linux-2.6.39.2/drivers/ata/pata_legacy.c 2011-05-22 19:36:31.000000000 -0400
25597 @@ -116,7 +116,7 @@ struct legacy_probe {
25598
25599 struct legacy_controller {
25600 const char *name;
25601 - struct ata_port_operations *ops;
25602 + const struct ata_port_operations *ops;
25603 unsigned int pio_mask;
25604 unsigned int flags;
25605 unsigned int pflags;
25606 @@ -239,12 +239,12 @@ static const struct ata_port_operations
25607 * pio_mask as well.
25608 */
25609
25610 -static struct ata_port_operations simple_port_ops = {
25611 +static const struct ata_port_operations simple_port_ops = {
25612 .inherits = &legacy_base_port_ops,
25613 .sff_data_xfer = ata_sff_data_xfer_noirq,
25614 };
25615
25616 -static struct ata_port_operations legacy_port_ops = {
25617 +static const struct ata_port_operations legacy_port_ops = {
25618 .inherits = &legacy_base_port_ops,
25619 .sff_data_xfer = ata_sff_data_xfer_noirq,
25620 .set_mode = legacy_set_mode,
25621 @@ -340,7 +340,7 @@ static unsigned int pdc_data_xfer_vlb(st
25622 return buflen;
25623 }
25624
25625 -static struct ata_port_operations pdc20230_port_ops = {
25626 +static const struct ata_port_operations pdc20230_port_ops = {
25627 .inherits = &legacy_base_port_ops,
25628 .set_piomode = pdc20230_set_piomode,
25629 .sff_data_xfer = pdc_data_xfer_vlb,
25630 @@ -373,7 +373,7 @@ static void ht6560a_set_piomode(struct a
25631 ioread8(ap->ioaddr.status_addr);
25632 }
25633
25634 -static struct ata_port_operations ht6560a_port_ops = {
25635 +static const struct ata_port_operations ht6560a_port_ops = {
25636 .inherits = &legacy_base_port_ops,
25637 .set_piomode = ht6560a_set_piomode,
25638 };
25639 @@ -416,7 +416,7 @@ static void ht6560b_set_piomode(struct a
25640 ioread8(ap->ioaddr.status_addr);
25641 }
25642
25643 -static struct ata_port_operations ht6560b_port_ops = {
25644 +static const struct ata_port_operations ht6560b_port_ops = {
25645 .inherits = &legacy_base_port_ops,
25646 .set_piomode = ht6560b_set_piomode,
25647 };
25648 @@ -515,7 +515,7 @@ static void opti82c611a_set_piomode(stru
25649 }
25650
25651
25652 -static struct ata_port_operations opti82c611a_port_ops = {
25653 +static const struct ata_port_operations opti82c611a_port_ops = {
25654 .inherits = &legacy_base_port_ops,
25655 .set_piomode = opti82c611a_set_piomode,
25656 };
25657 @@ -625,7 +625,7 @@ static unsigned int opti82c46x_qc_issue(
25658 return ata_sff_qc_issue(qc);
25659 }
25660
25661 -static struct ata_port_operations opti82c46x_port_ops = {
25662 +static const struct ata_port_operations opti82c46x_port_ops = {
25663 .inherits = &legacy_base_port_ops,
25664 .set_piomode = opti82c46x_set_piomode,
25665 .qc_issue = opti82c46x_qc_issue,
25666 @@ -787,20 +787,20 @@ static int qdi_port(struct platform_devi
25667 return 0;
25668 }
25669
25670 -static struct ata_port_operations qdi6500_port_ops = {
25671 +static const struct ata_port_operations qdi6500_port_ops = {
25672 .inherits = &legacy_base_port_ops,
25673 .set_piomode = qdi6500_set_piomode,
25674 .qc_issue = qdi_qc_issue,
25675 .sff_data_xfer = vlb32_data_xfer,
25676 };
25677
25678 -static struct ata_port_operations qdi6580_port_ops = {
25679 +static const struct ata_port_operations qdi6580_port_ops = {
25680 .inherits = &legacy_base_port_ops,
25681 .set_piomode = qdi6580_set_piomode,
25682 .sff_data_xfer = vlb32_data_xfer,
25683 };
25684
25685 -static struct ata_port_operations qdi6580dp_port_ops = {
25686 +static const struct ata_port_operations qdi6580dp_port_ops = {
25687 .inherits = &legacy_base_port_ops,
25688 .set_piomode = qdi6580dp_set_piomode,
25689 .qc_issue = qdi_qc_issue,
25690 @@ -872,7 +872,7 @@ static int winbond_port(struct platform_
25691 return 0;
25692 }
25693
25694 -static struct ata_port_operations winbond_port_ops = {
25695 +static const struct ata_port_operations winbond_port_ops = {
25696 .inherits = &legacy_base_port_ops,
25697 .set_piomode = winbond_set_piomode,
25698 .sff_data_xfer = vlb32_data_xfer,
25699 @@ -995,7 +995,7 @@ static __init int legacy_init_one(struct
25700 int pio_modes = controller->pio_mask;
25701 unsigned long io = probe->port;
25702 u32 mask = (1 << probe->slot);
25703 - struct ata_port_operations *ops = controller->ops;
25704 + const struct ata_port_operations *ops = controller->ops;
25705 struct legacy_data *ld = &legacy_data[probe->slot];
25706 struct ata_host *host = NULL;
25707 struct ata_port *ap;
25708 diff -urNp linux-2.6.39.2/drivers/ata/pata_macio.c linux-2.6.39.2/drivers/ata/pata_macio.c
25709 --- linux-2.6.39.2/drivers/ata/pata_macio.c 2011-05-19 00:06:34.000000000 -0400
25710 +++ linux-2.6.39.2/drivers/ata/pata_macio.c 2011-05-22 19:36:31.000000000 -0400
25711 @@ -918,9 +918,8 @@ static struct scsi_host_template pata_ma
25712 .slave_configure = pata_macio_slave_config,
25713 };
25714
25715 -static struct ata_port_operations pata_macio_ops = {
25716 +static const struct ata_port_operations pata_macio_ops = {
25717 .inherits = &ata_bmdma_port_ops,
25718 -
25719 .freeze = pata_macio_freeze,
25720 .set_piomode = pata_macio_set_timings,
25721 .set_dmamode = pata_macio_set_timings,
25722 diff -urNp linux-2.6.39.2/drivers/ata/pata_marvell.c linux-2.6.39.2/drivers/ata/pata_marvell.c
25723 --- linux-2.6.39.2/drivers/ata/pata_marvell.c 2011-05-19 00:06:34.000000000 -0400
25724 +++ linux-2.6.39.2/drivers/ata/pata_marvell.c 2011-05-22 19:36:31.000000000 -0400
25725 @@ -100,7 +100,7 @@ static struct scsi_host_template marvell
25726 ATA_BMDMA_SHT(DRV_NAME),
25727 };
25728
25729 -static struct ata_port_operations marvell_ops = {
25730 +static const struct ata_port_operations marvell_ops = {
25731 .inherits = &ata_bmdma_port_ops,
25732 .cable_detect = marvell_cable_detect,
25733 .prereset = marvell_pre_reset,
25734 diff -urNp linux-2.6.39.2/drivers/ata/pata_mpc52xx.c linux-2.6.39.2/drivers/ata/pata_mpc52xx.c
25735 --- linux-2.6.39.2/drivers/ata/pata_mpc52xx.c 2011-05-19 00:06:34.000000000 -0400
25736 +++ linux-2.6.39.2/drivers/ata/pata_mpc52xx.c 2011-05-22 19:36:31.000000000 -0400
25737 @@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx
25738 ATA_PIO_SHT(DRV_NAME),
25739 };
25740
25741 -static struct ata_port_operations mpc52xx_ata_port_ops = {
25742 +static const struct ata_port_operations mpc52xx_ata_port_ops = {
25743 .inherits = &ata_bmdma_port_ops,
25744 .sff_dev_select = mpc52xx_ata_dev_select,
25745 .set_piomode = mpc52xx_ata_set_piomode,
25746 diff -urNp linux-2.6.39.2/drivers/ata/pata_mpiix.c linux-2.6.39.2/drivers/ata/pata_mpiix.c
25747 --- linux-2.6.39.2/drivers/ata/pata_mpiix.c 2011-05-19 00:06:34.000000000 -0400
25748 +++ linux-2.6.39.2/drivers/ata/pata_mpiix.c 2011-05-22 19:36:31.000000000 -0400
25749 @@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_s
25750 ATA_PIO_SHT(DRV_NAME),
25751 };
25752
25753 -static struct ata_port_operations mpiix_port_ops = {
25754 +static const struct ata_port_operations mpiix_port_ops = {
25755 .inherits = &ata_sff_port_ops,
25756 .qc_issue = mpiix_qc_issue,
25757 .cable_detect = ata_cable_40wire,
25758 diff -urNp linux-2.6.39.2/drivers/ata/pata_netcell.c linux-2.6.39.2/drivers/ata/pata_netcell.c
25759 --- linux-2.6.39.2/drivers/ata/pata_netcell.c 2011-05-19 00:06:34.000000000 -0400
25760 +++ linux-2.6.39.2/drivers/ata/pata_netcell.c 2011-05-22 19:36:31.000000000 -0400
25761 @@ -34,7 +34,7 @@ static struct scsi_host_template netcell
25762 ATA_BMDMA_SHT(DRV_NAME),
25763 };
25764
25765 -static struct ata_port_operations netcell_ops = {
25766 +static const struct ata_port_operations netcell_ops = {
25767 .inherits = &ata_bmdma_port_ops,
25768 .cable_detect = ata_cable_80wire,
25769 .read_id = netcell_read_id,
25770 diff -urNp linux-2.6.39.2/drivers/ata/pata_ninja32.c linux-2.6.39.2/drivers/ata/pata_ninja32.c
25771 --- linux-2.6.39.2/drivers/ata/pata_ninja32.c 2011-05-19 00:06:34.000000000 -0400
25772 +++ linux-2.6.39.2/drivers/ata/pata_ninja32.c 2011-05-22 19:36:31.000000000 -0400
25773 @@ -81,7 +81,7 @@ static struct scsi_host_template ninja32
25774 ATA_BMDMA_SHT(DRV_NAME),
25775 };
25776
25777 -static struct ata_port_operations ninja32_port_ops = {
25778 +static const struct ata_port_operations ninja32_port_ops = {
25779 .inherits = &ata_bmdma_port_ops,
25780 .sff_dev_select = ninja32_dev_select,
25781 .cable_detect = ata_cable_40wire,
25782 diff -urNp linux-2.6.39.2/drivers/ata/pata_ns87410.c linux-2.6.39.2/drivers/ata/pata_ns87410.c
25783 --- linux-2.6.39.2/drivers/ata/pata_ns87410.c 2011-05-19 00:06:34.000000000 -0400
25784 +++ linux-2.6.39.2/drivers/ata/pata_ns87410.c 2011-05-22 19:36:31.000000000 -0400
25785 @@ -132,7 +132,7 @@ static struct scsi_host_template ns87410
25786 ATA_PIO_SHT(DRV_NAME),
25787 };
25788
25789 -static struct ata_port_operations ns87410_port_ops = {
25790 +static const struct ata_port_operations ns87410_port_ops = {
25791 .inherits = &ata_sff_port_ops,
25792 .qc_issue = ns87410_qc_issue,
25793 .cable_detect = ata_cable_40wire,
25794 diff -urNp linux-2.6.39.2/drivers/ata/pata_ns87415.c linux-2.6.39.2/drivers/ata/pata_ns87415.c
25795 --- linux-2.6.39.2/drivers/ata/pata_ns87415.c 2011-05-19 00:06:34.000000000 -0400
25796 +++ linux-2.6.39.2/drivers/ata/pata_ns87415.c 2011-05-22 19:36:31.000000000 -0400
25797 @@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct at
25798 }
25799 #endif /* 87560 SuperIO Support */
25800
25801 -static struct ata_port_operations ns87415_pata_ops = {
25802 +static const struct ata_port_operations ns87415_pata_ops = {
25803 .inherits = &ata_bmdma_port_ops,
25804
25805 .check_atapi_dma = ns87415_check_atapi_dma,
25806 @@ -313,7 +313,7 @@ static struct ata_port_operations ns8741
25807 };
25808
25809 #if defined(CONFIG_SUPERIO)
25810 -static struct ata_port_operations ns87560_pata_ops = {
25811 +static const struct ata_port_operations ns87560_pata_ops = {
25812 .inherits = &ns87415_pata_ops,
25813 .sff_tf_read = ns87560_tf_read,
25814 .sff_check_status = ns87560_check_status,
25815 diff -urNp linux-2.6.39.2/drivers/ata/pata_octeon_cf.c linux-2.6.39.2/drivers/ata/pata_octeon_cf.c
25816 --- linux-2.6.39.2/drivers/ata/pata_octeon_cf.c 2011-05-19 00:06:34.000000000 -0400
25817 +++ linux-2.6.39.2/drivers/ata/pata_octeon_cf.c 2011-05-22 19:36:31.000000000 -0400
25818 @@ -780,7 +780,7 @@ static unsigned int octeon_cf_qc_issue(s
25819 return 0;
25820 }
25821
25822 -static struct ata_port_operations octeon_cf_ops = {
25823 +static struct ata_port_operations octeon_cf_ops = { /* cannot be const */
25824 .inherits = &ata_sff_port_ops,
25825 .check_atapi_dma = octeon_cf_check_atapi_dma,
25826 .qc_prep = ata_noop_qc_prep,
25827 diff -urNp linux-2.6.39.2/drivers/ata/pata_oldpiix.c linux-2.6.39.2/drivers/ata/pata_oldpiix.c
25828 --- linux-2.6.39.2/drivers/ata/pata_oldpiix.c 2011-05-19 00:06:34.000000000 -0400
25829 +++ linux-2.6.39.2/drivers/ata/pata_oldpiix.c 2011-05-22 19:36:31.000000000 -0400
25830 @@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix
25831 ATA_BMDMA_SHT(DRV_NAME),
25832 };
25833
25834 -static struct ata_port_operations oldpiix_pata_ops = {
25835 +static const struct ata_port_operations oldpiix_pata_ops = {
25836 .inherits = &ata_bmdma_port_ops,
25837 .qc_issue = oldpiix_qc_issue,
25838 .cable_detect = ata_cable_40wire,
25839 diff -urNp linux-2.6.39.2/drivers/ata/pata_opti.c linux-2.6.39.2/drivers/ata/pata_opti.c
25840 --- linux-2.6.39.2/drivers/ata/pata_opti.c 2011-05-19 00:06:34.000000000 -0400
25841 +++ linux-2.6.39.2/drivers/ata/pata_opti.c 2011-05-22 19:36:31.000000000 -0400
25842 @@ -152,7 +152,7 @@ static struct scsi_host_template opti_sh
25843 ATA_PIO_SHT(DRV_NAME),
25844 };
25845
25846 -static struct ata_port_operations opti_port_ops = {
25847 +static const struct ata_port_operations opti_port_ops = {
25848 .inherits = &ata_sff_port_ops,
25849 .cable_detect = ata_cable_40wire,
25850 .set_piomode = opti_set_piomode,
25851 diff -urNp linux-2.6.39.2/drivers/ata/pata_optidma.c linux-2.6.39.2/drivers/ata/pata_optidma.c
25852 --- linux-2.6.39.2/drivers/ata/pata_optidma.c 2011-05-19 00:06:34.000000000 -0400
25853 +++ linux-2.6.39.2/drivers/ata/pata_optidma.c 2011-05-22 19:36:31.000000000 -0400
25854 @@ -337,7 +337,7 @@ static struct scsi_host_template optidma
25855 ATA_BMDMA_SHT(DRV_NAME),
25856 };
25857
25858 -static struct ata_port_operations optidma_port_ops = {
25859 +static const struct ata_port_operations optidma_port_ops = {
25860 .inherits = &ata_bmdma_port_ops,
25861 .cable_detect = ata_cable_40wire,
25862 .set_piomode = optidma_set_pio_mode,
25863 @@ -346,7 +346,7 @@ static struct ata_port_operations optidm
25864 .prereset = optidma_pre_reset,
25865 };
25866
25867 -static struct ata_port_operations optiplus_port_ops = {
25868 +static const struct ata_port_operations optiplus_port_ops = {
25869 .inherits = &optidma_port_ops,
25870 .set_piomode = optiplus_set_pio_mode,
25871 .set_dmamode = optiplus_set_dma_mode,
25872 diff -urNp linux-2.6.39.2/drivers/ata/pata_palmld.c linux-2.6.39.2/drivers/ata/pata_palmld.c
25873 --- linux-2.6.39.2/drivers/ata/pata_palmld.c 2011-05-19 00:06:34.000000000 -0400
25874 +++ linux-2.6.39.2/drivers/ata/pata_palmld.c 2011-05-22 19:36:31.000000000 -0400
25875 @@ -42,7 +42,7 @@ static struct scsi_host_template palmld_
25876 ATA_PIO_SHT(DRV_NAME),
25877 };
25878
25879 -static struct ata_port_operations palmld_port_ops = {
25880 +static const struct ata_port_operations palmld_port_ops = {
25881 .inherits = &ata_sff_port_ops,
25882 .sff_data_xfer = ata_sff_data_xfer_noirq,
25883 .cable_detect = ata_cable_40wire,
25884 diff -urNp linux-2.6.39.2/drivers/ata/pata_pcmcia.c linux-2.6.39.2/drivers/ata/pata_pcmcia.c
25885 --- linux-2.6.39.2/drivers/ata/pata_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
25886 +++ linux-2.6.39.2/drivers/ata/pata_pcmcia.c 2011-05-22 19:36:31.000000000 -0400
25887 @@ -151,14 +151,14 @@ static struct scsi_host_template pcmcia_
25888 ATA_PIO_SHT(DRV_NAME),
25889 };
25890
25891 -static struct ata_port_operations pcmcia_port_ops = {
25892 +static const struct ata_port_operations pcmcia_port_ops = {
25893 .inherits = &ata_sff_port_ops,
25894 .sff_data_xfer = ata_sff_data_xfer_noirq,
25895 .cable_detect = ata_cable_40wire,
25896 .set_mode = pcmcia_set_mode,
25897 };
25898
25899 -static struct ata_port_operations pcmcia_8bit_port_ops = {
25900 +static const struct ata_port_operations pcmcia_8bit_port_ops = {
25901 .inherits = &ata_sff_port_ops,
25902 .sff_data_xfer = ata_data_xfer_8bit,
25903 .cable_detect = ata_cable_40wire,
25904 @@ -205,7 +205,7 @@ static int pcmcia_init_one(struct pcmcia
25905 unsigned long io_base, ctl_base;
25906 void __iomem *io_addr, *ctl_addr;
25907 int n_ports = 1;
25908 - struct ata_port_operations *ops = &pcmcia_port_ops;
25909 + const struct ata_port_operations *ops = &pcmcia_port_ops;
25910
25911 /* Set up attributes in order to probe card and get resources */
25912 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
25913 diff -urNp linux-2.6.39.2/drivers/ata/pata_pdc2027x.c linux-2.6.39.2/drivers/ata/pata_pdc2027x.c
25914 --- linux-2.6.39.2/drivers/ata/pata_pdc2027x.c 2011-05-19 00:06:34.000000000 -0400
25915 +++ linux-2.6.39.2/drivers/ata/pata_pdc2027x.c 2011-05-22 19:36:31.000000000 -0400
25916 @@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027
25917 ATA_BMDMA_SHT(DRV_NAME),
25918 };
25919
25920 -static struct ata_port_operations pdc2027x_pata100_ops = {
25921 +static const struct ata_port_operations pdc2027x_pata100_ops = {
25922 .inherits = &ata_bmdma_port_ops,
25923 .check_atapi_dma = pdc2027x_check_atapi_dma,
25924 .cable_detect = pdc2027x_cable_detect,
25925 .prereset = pdc2027x_prereset,
25926 };
25927
25928 -static struct ata_port_operations pdc2027x_pata133_ops = {
25929 +static const struct ata_port_operations pdc2027x_pata133_ops = {
25930 .inherits = &pdc2027x_pata100_ops,
25931 .mode_filter = pdc2027x_mode_filter,
25932 .set_piomode = pdc2027x_set_piomode,
25933 diff -urNp linux-2.6.39.2/drivers/ata/pata_pdc202xx_old.c linux-2.6.39.2/drivers/ata/pata_pdc202xx_old.c
25934 --- linux-2.6.39.2/drivers/ata/pata_pdc202xx_old.c 2011-05-19 00:06:34.000000000 -0400
25935 +++ linux-2.6.39.2/drivers/ata/pata_pdc202xx_old.c 2011-05-22 19:36:31.000000000 -0400
25936 @@ -295,7 +295,7 @@ static struct scsi_host_template pdc202x
25937 ATA_BMDMA_SHT(DRV_NAME),
25938 };
25939
25940 -static struct ata_port_operations pdc2024x_port_ops = {
25941 +static const struct ata_port_operations pdc2024x_port_ops = {
25942 .inherits = &ata_bmdma_port_ops,
25943
25944 .cable_detect = ata_cable_40wire,
25945 @@ -306,7 +306,7 @@ static struct ata_port_operations pdc202
25946 .sff_irq_check = pdc202xx_irq_check,
25947 };
25948
25949 -static struct ata_port_operations pdc2026x_port_ops = {
25950 +static const struct ata_port_operations pdc2026x_port_ops = {
25951 .inherits = &pdc2024x_port_ops,
25952
25953 .check_atapi_dma = pdc2026x_check_atapi_dma,
25954 diff -urNp linux-2.6.39.2/drivers/ata/pata_piccolo.c linux-2.6.39.2/drivers/ata/pata_piccolo.c
25955 --- linux-2.6.39.2/drivers/ata/pata_piccolo.c 2011-05-19 00:06:34.000000000 -0400
25956 +++ linux-2.6.39.2/drivers/ata/pata_piccolo.c 2011-05-22 19:36:31.000000000 -0400
25957 @@ -67,7 +67,7 @@ static struct scsi_host_template tosh_sh
25958 ATA_BMDMA_SHT(DRV_NAME),
25959 };
25960
25961 -static struct ata_port_operations tosh_port_ops = {
25962 +static const struct ata_port_operations tosh_port_ops = {
25963 .inherits = &ata_bmdma_port_ops,
25964 .cable_detect = ata_cable_unknown,
25965 .set_piomode = tosh_set_piomode,
25966 diff -urNp linux-2.6.39.2/drivers/ata/pata_platform.c linux-2.6.39.2/drivers/ata/pata_platform.c
25967 --- linux-2.6.39.2/drivers/ata/pata_platform.c 2011-05-19 00:06:34.000000000 -0400
25968 +++ linux-2.6.39.2/drivers/ata/pata_platform.c 2011-05-22 19:36:31.000000000 -0400
25969 @@ -48,7 +48,7 @@ static struct scsi_host_template pata_pl
25970 ATA_PIO_SHT(DRV_NAME),
25971 };
25972
25973 -static struct ata_port_operations pata_platform_port_ops = {
25974 +static const struct ata_port_operations pata_platform_port_ops = {
25975 .inherits = &ata_sff_port_ops,
25976 .sff_data_xfer = ata_sff_data_xfer_noirq,
25977 .cable_detect = ata_cable_unknown,
25978 diff -urNp linux-2.6.39.2/drivers/ata/pata_pxa.c linux-2.6.39.2/drivers/ata/pata_pxa.c
25979 --- linux-2.6.39.2/drivers/ata/pata_pxa.c 2011-05-19 00:06:34.000000000 -0400
25980 +++ linux-2.6.39.2/drivers/ata/pata_pxa.c 2011-05-22 19:36:31.000000000 -0400
25981 @@ -198,7 +198,7 @@ static struct scsi_host_template pxa_ata
25982 ATA_BMDMA_SHT(DRV_NAME),
25983 };
25984
25985 -static struct ata_port_operations pxa_ata_port_ops = {
25986 +static const struct ata_port_operations pxa_ata_port_ops = {
25987 .inherits = &ata_bmdma_port_ops,
25988 .cable_detect = ata_cable_40wire,
25989
25990 diff -urNp linux-2.6.39.2/drivers/ata/pata_qdi.c linux-2.6.39.2/drivers/ata/pata_qdi.c
25991 --- linux-2.6.39.2/drivers/ata/pata_qdi.c 2011-05-19 00:06:34.000000000 -0400
25992 +++ linux-2.6.39.2/drivers/ata/pata_qdi.c 2011-05-22 19:36:31.000000000 -0400
25993 @@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht
25994 ATA_PIO_SHT(DRV_NAME),
25995 };
25996
25997 -static struct ata_port_operations qdi6500_port_ops = {
25998 +static const struct ata_port_operations qdi6500_port_ops = {
25999 .inherits = &ata_sff_port_ops,
26000 .qc_issue = qdi_qc_issue,
26001 .sff_data_xfer = qdi_data_xfer,
26002 @@ -165,7 +165,7 @@ static struct ata_port_operations qdi650
26003 .set_piomode = qdi6500_set_piomode,
26004 };
26005
26006 -static struct ata_port_operations qdi6580_port_ops = {
26007 +static const struct ata_port_operations qdi6580_port_ops = {
26008 .inherits = &qdi6500_port_ops,
26009 .set_piomode = qdi6580_set_piomode,
26010 };
26011 diff -urNp linux-2.6.39.2/drivers/ata/pata_radisys.c linux-2.6.39.2/drivers/ata/pata_radisys.c
26012 --- linux-2.6.39.2/drivers/ata/pata_radisys.c 2011-05-19 00:06:34.000000000 -0400
26013 +++ linux-2.6.39.2/drivers/ata/pata_radisys.c 2011-05-22 19:36:31.000000000 -0400
26014 @@ -187,7 +187,7 @@ static struct scsi_host_template radisys
26015 ATA_BMDMA_SHT(DRV_NAME),
26016 };
26017
26018 -static struct ata_port_operations radisys_pata_ops = {
26019 +static const struct ata_port_operations radisys_pata_ops = {
26020 .inherits = &ata_bmdma_port_ops,
26021 .qc_issue = radisys_qc_issue,
26022 .cable_detect = ata_cable_unknown,
26023 diff -urNp linux-2.6.39.2/drivers/ata/pata_rb532_cf.c linux-2.6.39.2/drivers/ata/pata_rb532_cf.c
26024 --- linux-2.6.39.2/drivers/ata/pata_rb532_cf.c 2011-05-19 00:06:34.000000000 -0400
26025 +++ linux-2.6.39.2/drivers/ata/pata_rb532_cf.c 2011-05-22 19:36:31.000000000 -0400
26026 @@ -69,7 +69,7 @@ static irqreturn_t rb532_pata_irq_handle
26027 return IRQ_HANDLED;
26028 }
26029
26030 -static struct ata_port_operations rb532_pata_port_ops = {
26031 +static const struct ata_port_operations rb532_pata_port_ops = {
26032 .inherits = &ata_sff_port_ops,
26033 .sff_data_xfer = ata_sff_data_xfer32,
26034 };
26035 diff -urNp linux-2.6.39.2/drivers/ata/pata_rdc.c linux-2.6.39.2/drivers/ata/pata_rdc.c
26036 --- linux-2.6.39.2/drivers/ata/pata_rdc.c 2011-05-19 00:06:34.000000000 -0400
26037 +++ linux-2.6.39.2/drivers/ata/pata_rdc.c 2011-05-22 19:36:31.000000000 -0400
26038 @@ -273,7 +273,7 @@ static void rdc_set_dmamode(struct ata_p
26039 pci_write_config_byte(dev, 0x48, udma_enable);
26040 }
26041
26042 -static struct ata_port_operations rdc_pata_ops = {
26043 +static const struct ata_port_operations rdc_pata_ops = {
26044 .inherits = &ata_bmdma32_port_ops,
26045 .cable_detect = rdc_pata_cable_detect,
26046 .set_piomode = rdc_set_piomode,
26047 diff -urNp linux-2.6.39.2/drivers/ata/pata_rz1000.c linux-2.6.39.2/drivers/ata/pata_rz1000.c
26048 --- linux-2.6.39.2/drivers/ata/pata_rz1000.c 2011-05-19 00:06:34.000000000 -0400
26049 +++ linux-2.6.39.2/drivers/ata/pata_rz1000.c 2011-05-22 19:36:31.000000000 -0400
26050 @@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_
26051 ATA_PIO_SHT(DRV_NAME),
26052 };
26053
26054 -static struct ata_port_operations rz1000_port_ops = {
26055 +static const struct ata_port_operations rz1000_port_ops = {
26056 .inherits = &ata_sff_port_ops,
26057 .cable_detect = ata_cable_40wire,
26058 .set_mode = rz1000_set_mode,
26059 diff -urNp linux-2.6.39.2/drivers/ata/pata_samsung_cf.c linux-2.6.39.2/drivers/ata/pata_samsung_cf.c
26060 --- linux-2.6.39.2/drivers/ata/pata_samsung_cf.c 2011-05-19 00:06:34.000000000 -0400
26061 +++ linux-2.6.39.2/drivers/ata/pata_samsung_cf.c 2011-05-22 19:36:31.000000000 -0400
26062 @@ -399,7 +399,7 @@ static struct scsi_host_template pata_s3
26063 ATA_PIO_SHT(DRV_NAME),
26064 };
26065
26066 -static struct ata_port_operations pata_s3c_port_ops = {
26067 +static const struct ata_port_operations pata_s3c_port_ops = {
26068 .inherits = &ata_sff_port_ops,
26069 .sff_check_status = pata_s3c_check_status,
26070 .sff_check_altstatus = pata_s3c_check_altstatus,
26071 @@ -413,7 +413,7 @@ static struct ata_port_operations pata_s
26072 .set_piomode = pata_s3c_set_piomode,
26073 };
26074
26075 -static struct ata_port_operations pata_s5p_port_ops = {
26076 +static const struct ata_port_operations pata_s5p_port_ops = {
26077 .inherits = &ata_sff_port_ops,
26078 .set_piomode = pata_s3c_set_piomode,
26079 };
26080 diff -urNp linux-2.6.39.2/drivers/ata/pata_sc1200.c linux-2.6.39.2/drivers/ata/pata_sc1200.c
26081 --- linux-2.6.39.2/drivers/ata/pata_sc1200.c 2011-05-19 00:06:34.000000000 -0400
26082 +++ linux-2.6.39.2/drivers/ata/pata_sc1200.c 2011-05-22 19:36:31.000000000 -0400
26083 @@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_
26084 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
26085 };
26086
26087 -static struct ata_port_operations sc1200_port_ops = {
26088 +static const struct ata_port_operations sc1200_port_ops = {
26089 .inherits = &ata_bmdma_port_ops,
26090 .qc_prep = ata_bmdma_dumb_qc_prep,
26091 .qc_issue = sc1200_qc_issue,
26092 diff -urNp linux-2.6.39.2/drivers/ata/pata_scc.c linux-2.6.39.2/drivers/ata/pata_scc.c
26093 --- linux-2.6.39.2/drivers/ata/pata_scc.c 2011-05-19 00:06:34.000000000 -0400
26094 +++ linux-2.6.39.2/drivers/ata/pata_scc.c 2011-05-22 19:36:31.000000000 -0400
26095 @@ -926,7 +926,7 @@ static struct scsi_host_template scc_sht
26096 ATA_BMDMA_SHT(DRV_NAME),
26097 };
26098
26099 -static struct ata_port_operations scc_pata_ops = {
26100 +static const struct ata_port_operations scc_pata_ops = {
26101 .inherits = &ata_bmdma_port_ops,
26102
26103 .set_piomode = scc_set_piomode,
26104 diff -urNp linux-2.6.39.2/drivers/ata/pata_sch.c linux-2.6.39.2/drivers/ata/pata_sch.c
26105 --- linux-2.6.39.2/drivers/ata/pata_sch.c 2011-05-19 00:06:34.000000000 -0400
26106 +++ linux-2.6.39.2/drivers/ata/pata_sch.c 2011-05-22 19:36:31.000000000 -0400
26107 @@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht
26108 ATA_BMDMA_SHT(DRV_NAME),
26109 };
26110
26111 -static struct ata_port_operations sch_pata_ops = {
26112 +static const struct ata_port_operations sch_pata_ops = {
26113 .inherits = &ata_bmdma_port_ops,
26114 .cable_detect = ata_cable_unknown,
26115 .set_piomode = sch_set_piomode,
26116 diff -urNp linux-2.6.39.2/drivers/ata/pata_serverworks.c linux-2.6.39.2/drivers/ata/pata_serverworks.c
26117 --- linux-2.6.39.2/drivers/ata/pata_serverworks.c 2011-05-19 00:06:34.000000000 -0400
26118 +++ linux-2.6.39.2/drivers/ata/pata_serverworks.c 2011-05-22 19:36:31.000000000 -0400
26119 @@ -300,7 +300,7 @@ static struct scsi_host_template serverw
26120 ATA_BMDMA_SHT(DRV_NAME),
26121 };
26122
26123 -static struct ata_port_operations serverworks_osb4_port_ops = {
26124 +static const struct ata_port_operations serverworks_osb4_port_ops = {
26125 .inherits = &ata_bmdma_port_ops,
26126 .cable_detect = serverworks_cable_detect,
26127 .mode_filter = serverworks_osb4_filter,
26128 @@ -308,7 +308,7 @@ static struct ata_port_operations server
26129 .set_dmamode = serverworks_set_dmamode,
26130 };
26131
26132 -static struct ata_port_operations serverworks_csb_port_ops = {
26133 +static const struct ata_port_operations serverworks_csb_port_ops = {
26134 .inherits = &serverworks_osb4_port_ops,
26135 .mode_filter = serverworks_csb_filter,
26136 };
26137 diff -urNp linux-2.6.39.2/drivers/ata/pata_sil680.c linux-2.6.39.2/drivers/ata/pata_sil680.c
26138 --- linux-2.6.39.2/drivers/ata/pata_sil680.c 2011-05-19 00:06:34.000000000 -0400
26139 +++ linux-2.6.39.2/drivers/ata/pata_sil680.c 2011-05-22 19:36:31.000000000 -0400
26140 @@ -225,8 +225,7 @@ static struct scsi_host_template sil680_
26141 ATA_BMDMA_SHT(DRV_NAME),
26142 };
26143
26144 -
26145 -static struct ata_port_operations sil680_port_ops = {
26146 +static const struct ata_port_operations sil680_port_ops = {
26147 .inherits = &ata_bmdma32_port_ops,
26148 .sff_exec_command = sil680_sff_exec_command,
26149 .sff_irq_check = sil680_sff_irq_check,
26150 diff -urNp linux-2.6.39.2/drivers/ata/pata_sis.c linux-2.6.39.2/drivers/ata/pata_sis.c
26151 --- linux-2.6.39.2/drivers/ata/pata_sis.c 2011-05-19 00:06:34.000000000 -0400
26152 +++ linux-2.6.39.2/drivers/ata/pata_sis.c 2011-05-22 19:36:31.000000000 -0400
26153 @@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht
26154 ATA_BMDMA_SHT(DRV_NAME),
26155 };
26156
26157 -static struct ata_port_operations sis_133_for_sata_ops = {
26158 +static const struct ata_port_operations sis_133_for_sata_ops = {
26159 .inherits = &ata_bmdma_port_ops,
26160 .set_piomode = sis_133_set_piomode,
26161 .set_dmamode = sis_133_set_dmamode,
26162 .cable_detect = sis_133_cable_detect,
26163 };
26164
26165 -static struct ata_port_operations sis_base_ops = {
26166 +static const struct ata_port_operations sis_base_ops = {
26167 .inherits = &ata_bmdma_port_ops,
26168 .prereset = sis_pre_reset,
26169 };
26170
26171 -static struct ata_port_operations sis_133_ops = {
26172 +static const struct ata_port_operations sis_133_ops = {
26173 .inherits = &sis_base_ops,
26174 .set_piomode = sis_133_set_piomode,
26175 .set_dmamode = sis_133_set_dmamode,
26176 .cable_detect = sis_133_cable_detect,
26177 };
26178
26179 -static struct ata_port_operations sis_133_early_ops = {
26180 +static const struct ata_port_operations sis_133_early_ops = {
26181 .inherits = &sis_base_ops,
26182 .set_piomode = sis_100_set_piomode,
26183 .set_dmamode = sis_133_early_set_dmamode,
26184 .cable_detect = sis_66_cable_detect,
26185 };
26186
26187 -static struct ata_port_operations sis_100_ops = {
26188 +static const struct ata_port_operations sis_100_ops = {
26189 .inherits = &sis_base_ops,
26190 .set_piomode = sis_100_set_piomode,
26191 .set_dmamode = sis_100_set_dmamode,
26192 .cable_detect = sis_66_cable_detect,
26193 };
26194
26195 -static struct ata_port_operations sis_66_ops = {
26196 +static const struct ata_port_operations sis_66_ops = {
26197 .inherits = &sis_base_ops,
26198 .set_piomode = sis_old_set_piomode,
26199 .set_dmamode = sis_66_set_dmamode,
26200 .cable_detect = sis_66_cable_detect,
26201 };
26202
26203 -static struct ata_port_operations sis_old_ops = {
26204 +static const struct ata_port_operations sis_old_ops = {
26205 .inherits = &sis_base_ops,
26206 .set_piomode = sis_old_set_piomode,
26207 .set_dmamode = sis_old_set_dmamode,
26208 diff -urNp linux-2.6.39.2/drivers/ata/pata_sl82c105.c linux-2.6.39.2/drivers/ata/pata_sl82c105.c
26209 --- linux-2.6.39.2/drivers/ata/pata_sl82c105.c 2011-05-19 00:06:34.000000000 -0400
26210 +++ linux-2.6.39.2/drivers/ata/pata_sl82c105.c 2011-05-22 19:36:31.000000000 -0400
26211 @@ -241,7 +241,7 @@ static struct scsi_host_template sl82c10
26212 ATA_BMDMA_SHT(DRV_NAME),
26213 };
26214
26215 -static struct ata_port_operations sl82c105_port_ops = {
26216 +static const struct ata_port_operations sl82c105_port_ops = {
26217 .inherits = &ata_bmdma_port_ops,
26218 .qc_defer = sl82c105_qc_defer,
26219 .bmdma_start = sl82c105_bmdma_start,
26220 diff -urNp linux-2.6.39.2/drivers/ata/pata_triflex.c linux-2.6.39.2/drivers/ata/pata_triflex.c
26221 --- linux-2.6.39.2/drivers/ata/pata_triflex.c 2011-05-19 00:06:34.000000000 -0400
26222 +++ linux-2.6.39.2/drivers/ata/pata_triflex.c 2011-05-22 19:36:31.000000000 -0400
26223 @@ -178,7 +178,7 @@ static struct scsi_host_template triflex
26224 ATA_BMDMA_SHT(DRV_NAME),
26225 };
26226
26227 -static struct ata_port_operations triflex_port_ops = {
26228 +static const struct ata_port_operations triflex_port_ops = {
26229 .inherits = &ata_bmdma_port_ops,
26230 .bmdma_start = triflex_bmdma_start,
26231 .bmdma_stop = triflex_bmdma_stop,
26232 diff -urNp linux-2.6.39.2/drivers/ata/pata_via.c linux-2.6.39.2/drivers/ata/pata_via.c
26233 --- linux-2.6.39.2/drivers/ata/pata_via.c 2011-05-19 00:06:34.000000000 -0400
26234 +++ linux-2.6.39.2/drivers/ata/pata_via.c 2011-05-22 19:36:31.000000000 -0400
26235 @@ -441,7 +441,7 @@ static struct scsi_host_template via_sht
26236 ATA_BMDMA_SHT(DRV_NAME),
26237 };
26238
26239 -static struct ata_port_operations via_port_ops = {
26240 +static const struct ata_port_operations via_port_ops = {
26241 .inherits = &ata_bmdma_port_ops,
26242 .cable_detect = via_cable_detect,
26243 .set_piomode = via_set_piomode,
26244 @@ -452,7 +452,7 @@ static struct ata_port_operations via_po
26245 .mode_filter = via_mode_filter,
26246 };
26247
26248 -static struct ata_port_operations via_port_ops_noirq = {
26249 +static const struct ata_port_operations via_port_ops_noirq = {
26250 .inherits = &via_port_ops,
26251 .sff_data_xfer = ata_sff_data_xfer_noirq,
26252 };
26253 diff -urNp linux-2.6.39.2/drivers/ata/pdc_adma.c linux-2.6.39.2/drivers/ata/pdc_adma.c
26254 --- linux-2.6.39.2/drivers/ata/pdc_adma.c 2011-05-19 00:06:34.000000000 -0400
26255 +++ linux-2.6.39.2/drivers/ata/pdc_adma.c 2011-05-22 19:36:31.000000000 -0400
26256 @@ -146,7 +146,7 @@ static struct scsi_host_template adma_at
26257 .dma_boundary = ADMA_DMA_BOUNDARY,
26258 };
26259
26260 -static struct ata_port_operations adma_ata_ops = {
26261 +static const struct ata_port_operations adma_ata_ops = {
26262 .inherits = &ata_sff_port_ops,
26263
26264 .lost_interrupt = ATA_OP_NULL,
26265 diff -urNp linux-2.6.39.2/drivers/ata/sata_dwc_460ex.c linux-2.6.39.2/drivers/ata/sata_dwc_460ex.c
26266 --- linux-2.6.39.2/drivers/ata/sata_dwc_460ex.c 2011-05-19 00:06:34.000000000 -0400
26267 +++ linux-2.6.39.2/drivers/ata/sata_dwc_460ex.c 2011-05-22 19:36:31.000000000 -0400
26268 @@ -1598,7 +1598,7 @@ static struct scsi_host_template sata_dw
26269 .dma_boundary = ATA_DMA_BOUNDARY,
26270 };
26271
26272 -static struct ata_port_operations sata_dwc_ops = {
26273 +static const struct ata_port_operations sata_dwc_ops = {
26274 .inherits = &ata_sff_port_ops,
26275
26276 .error_handler = sata_dwc_error_handler,
26277 diff -urNp linux-2.6.39.2/drivers/ata/sata_fsl.c linux-2.6.39.2/drivers/ata/sata_fsl.c
26278 --- linux-2.6.39.2/drivers/ata/sata_fsl.c 2011-05-19 00:06:34.000000000 -0400
26279 +++ linux-2.6.39.2/drivers/ata/sata_fsl.c 2011-05-22 19:36:31.000000000 -0400
26280 @@ -1268,7 +1268,7 @@ static struct scsi_host_template sata_fs
26281 .dma_boundary = ATA_DMA_BOUNDARY,
26282 };
26283
26284 -static struct ata_port_operations sata_fsl_ops = {
26285 +static const struct ata_port_operations sata_fsl_ops = {
26286 .inherits = &sata_pmp_port_ops,
26287
26288 .qc_defer = ata_std_qc_defer,
26289 diff -urNp linux-2.6.39.2/drivers/ata/sata_inic162x.c linux-2.6.39.2/drivers/ata/sata_inic162x.c
26290 --- linux-2.6.39.2/drivers/ata/sata_inic162x.c 2011-05-19 00:06:34.000000000 -0400
26291 +++ linux-2.6.39.2/drivers/ata/sata_inic162x.c 2011-05-22 19:36:31.000000000 -0400
26292 @@ -705,7 +705,7 @@ static int inic_port_start(struct ata_po
26293 return 0;
26294 }
26295
26296 -static struct ata_port_operations inic_port_ops = {
26297 +static const struct ata_port_operations inic_port_ops = {
26298 .inherits = &sata_port_ops,
26299
26300 .check_atapi_dma = inic_check_atapi_dma,
26301 diff -urNp linux-2.6.39.2/drivers/ata/sata_mv.c linux-2.6.39.2/drivers/ata/sata_mv.c
26302 --- linux-2.6.39.2/drivers/ata/sata_mv.c 2011-05-19 00:06:34.000000000 -0400
26303 +++ linux-2.6.39.2/drivers/ata/sata_mv.c 2011-05-22 19:36:31.000000000 -0400
26304 @@ -662,7 +662,7 @@ static struct scsi_host_template mv6_sht
26305 .dma_boundary = MV_DMA_BOUNDARY,
26306 };
26307
26308 -static struct ata_port_operations mv5_ops = {
26309 +static const struct ata_port_operations mv5_ops = {
26310 .inherits = &ata_sff_port_ops,
26311
26312 .lost_interrupt = ATA_OP_NULL,
26313 @@ -682,7 +682,7 @@ static struct ata_port_operations mv5_op
26314 .port_stop = mv_port_stop,
26315 };
26316
26317 -static struct ata_port_operations mv6_ops = {
26318 +static const struct ata_port_operations mv6_ops = {
26319 .inherits = &ata_bmdma_port_ops,
26320
26321 .lost_interrupt = ATA_OP_NULL,
26322 @@ -716,7 +716,7 @@ static struct ata_port_operations mv6_op
26323 .port_stop = mv_port_stop,
26324 };
26325
26326 -static struct ata_port_operations mv_iie_ops = {
26327 +static const struct ata_port_operations mv_iie_ops = {
26328 .inherits = &mv6_ops,
26329 .dev_config = ATA_OP_NULL,
26330 .qc_prep = mv_qc_prep_iie,
26331 diff -urNp linux-2.6.39.2/drivers/ata/sata_nv.c linux-2.6.39.2/drivers/ata/sata_nv.c
26332 --- linux-2.6.39.2/drivers/ata/sata_nv.c 2011-05-19 00:06:34.000000000 -0400
26333 +++ linux-2.6.39.2/drivers/ata/sata_nv.c 2011-05-22 19:36:31.000000000 -0400
26334 @@ -465,7 +465,7 @@ static struct scsi_host_template nv_swnc
26335 * cases. Define nv_hardreset() which only kicks in for post-boot
26336 * probing and use it for all variants.
26337 */
26338 -static struct ata_port_operations nv_generic_ops = {
26339 +static const struct ata_port_operations nv_generic_ops = {
26340 .inherits = &ata_bmdma_port_ops,
26341 .lost_interrupt = ATA_OP_NULL,
26342 .scr_read = nv_scr_read,
26343 @@ -473,20 +473,20 @@ static struct ata_port_operations nv_gen
26344 .hardreset = nv_hardreset,
26345 };
26346
26347 -static struct ata_port_operations nv_nf2_ops = {
26348 +static const struct ata_port_operations nv_nf2_ops = {
26349 .inherits = &nv_generic_ops,
26350 .freeze = nv_nf2_freeze,
26351 .thaw = nv_nf2_thaw,
26352 };
26353
26354 -static struct ata_port_operations nv_ck804_ops = {
26355 +static const struct ata_port_operations nv_ck804_ops = {
26356 .inherits = &nv_generic_ops,
26357 .freeze = nv_ck804_freeze,
26358 .thaw = nv_ck804_thaw,
26359 .host_stop = nv_ck804_host_stop,
26360 };
26361
26362 -static struct ata_port_operations nv_adma_ops = {
26363 +static const struct ata_port_operations nv_adma_ops = {
26364 .inherits = &nv_ck804_ops,
26365
26366 .check_atapi_dma = nv_adma_check_atapi_dma,
26367 @@ -510,7 +510,7 @@ static struct ata_port_operations nv_adm
26368 .host_stop = nv_adma_host_stop,
26369 };
26370
26371 -static struct ata_port_operations nv_swncq_ops = {
26372 +static const struct ata_port_operations nv_swncq_ops = {
26373 .inherits = &nv_generic_ops,
26374
26375 .qc_defer = ata_std_qc_defer,
26376 diff -urNp linux-2.6.39.2/drivers/ata/sata_promise.c linux-2.6.39.2/drivers/ata/sata_promise.c
26377 --- linux-2.6.39.2/drivers/ata/sata_promise.c 2011-05-19 00:06:34.000000000 -0400
26378 +++ linux-2.6.39.2/drivers/ata/sata_promise.c 2011-05-22 19:36:31.000000000 -0400
26379 @@ -194,7 +194,7 @@ static const struct ata_port_operations
26380 .error_handler = pdc_error_handler,
26381 };
26382
26383 -static struct ata_port_operations pdc_sata_ops = {
26384 +static const struct ata_port_operations pdc_sata_ops = {
26385 .inherits = &pdc_common_ops,
26386 .cable_detect = pdc_sata_cable_detect,
26387 .freeze = pdc_sata_freeze,
26388 @@ -207,14 +207,14 @@ static struct ata_port_operations pdc_sa
26389
26390 /* First-generation chips need a more restrictive ->check_atapi_dma op,
26391 and ->freeze/thaw that ignore the hotplug controls. */
26392 -static struct ata_port_operations pdc_old_sata_ops = {
26393 +static const struct ata_port_operations pdc_old_sata_ops = {
26394 .inherits = &pdc_sata_ops,
26395 .freeze = pdc_freeze,
26396 .thaw = pdc_thaw,
26397 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
26398 };
26399
26400 -static struct ata_port_operations pdc_pata_ops = {
26401 +static const struct ata_port_operations pdc_pata_ops = {
26402 .inherits = &pdc_common_ops,
26403 .cable_detect = pdc_pata_cable_detect,
26404 .freeze = pdc_freeze,
26405 diff -urNp linux-2.6.39.2/drivers/ata/sata_qstor.c linux-2.6.39.2/drivers/ata/sata_qstor.c
26406 --- linux-2.6.39.2/drivers/ata/sata_qstor.c 2011-05-19 00:06:34.000000000 -0400
26407 +++ linux-2.6.39.2/drivers/ata/sata_qstor.c 2011-05-22 19:36:31.000000000 -0400
26408 @@ -131,7 +131,7 @@ static struct scsi_host_template qs_ata_
26409 .dma_boundary = QS_DMA_BOUNDARY,
26410 };
26411
26412 -static struct ata_port_operations qs_ata_ops = {
26413 +static const struct ata_port_operations qs_ata_ops = {
26414 .inherits = &ata_sff_port_ops,
26415
26416 .check_atapi_dma = qs_check_atapi_dma,
26417 diff -urNp linux-2.6.39.2/drivers/ata/sata_sil24.c linux-2.6.39.2/drivers/ata/sata_sil24.c
26418 --- linux-2.6.39.2/drivers/ata/sata_sil24.c 2011-05-19 00:06:34.000000000 -0400
26419 +++ linux-2.6.39.2/drivers/ata/sata_sil24.c 2011-05-22 19:36:31.000000000 -0400
26420 @@ -388,7 +388,7 @@ static struct scsi_host_template sil24_s
26421 .dma_boundary = ATA_DMA_BOUNDARY,
26422 };
26423
26424 -static struct ata_port_operations sil24_ops = {
26425 +static const struct ata_port_operations sil24_ops = {
26426 .inherits = &sata_pmp_port_ops,
26427
26428 .qc_defer = sil24_qc_defer,
26429 diff -urNp linux-2.6.39.2/drivers/ata/sata_sil.c linux-2.6.39.2/drivers/ata/sata_sil.c
26430 --- linux-2.6.39.2/drivers/ata/sata_sil.c 2011-05-19 00:06:34.000000000 -0400
26431 +++ linux-2.6.39.2/drivers/ata/sata_sil.c 2011-05-22 19:36:31.000000000 -0400
26432 @@ -181,7 +181,7 @@ static struct scsi_host_template sil_sht
26433 .sg_tablesize = ATA_MAX_PRD
26434 };
26435
26436 -static struct ata_port_operations sil_ops = {
26437 +static const struct ata_port_operations sil_ops = {
26438 .inherits = &ata_bmdma32_port_ops,
26439 .dev_config = sil_dev_config,
26440 .set_mode = sil_set_mode,
26441 diff -urNp linux-2.6.39.2/drivers/ata/sata_sis.c linux-2.6.39.2/drivers/ata/sata_sis.c
26442 --- linux-2.6.39.2/drivers/ata/sata_sis.c 2011-05-19 00:06:34.000000000 -0400
26443 +++ linux-2.6.39.2/drivers/ata/sata_sis.c 2011-05-22 19:36:31.000000000 -0400
26444 @@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht
26445 ATA_BMDMA_SHT(DRV_NAME),
26446 };
26447
26448 -static struct ata_port_operations sis_ops = {
26449 +static const struct ata_port_operations sis_ops = {
26450 .inherits = &ata_bmdma_port_ops,
26451 .scr_read = sis_scr_read,
26452 .scr_write = sis_scr_write,
26453 diff -urNp linux-2.6.39.2/drivers/ata/sata_svw.c linux-2.6.39.2/drivers/ata/sata_svw.c
26454 --- linux-2.6.39.2/drivers/ata/sata_svw.c 2011-05-19 00:06:34.000000000 -0400
26455 +++ linux-2.6.39.2/drivers/ata/sata_svw.c 2011-05-22 19:36:31.000000000 -0400
26456 @@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata
26457 };
26458
26459
26460 -static struct ata_port_operations k2_sata_ops = {
26461 +static const struct ata_port_operations k2_sata_ops = {
26462 .inherits = &ata_bmdma_port_ops,
26463 .sff_tf_load = k2_sata_tf_load,
26464 .sff_tf_read = k2_sata_tf_read,
26465 diff -urNp linux-2.6.39.2/drivers/ata/sata_sx4.c linux-2.6.39.2/drivers/ata/sata_sx4.c
26466 --- linux-2.6.39.2/drivers/ata/sata_sx4.c 2011-05-19 00:06:34.000000000 -0400
26467 +++ linux-2.6.39.2/drivers/ata/sata_sx4.c 2011-05-22 19:36:31.000000000 -0400
26468 @@ -249,7 +249,7 @@ static struct scsi_host_template pdc_sat
26469 };
26470
26471 /* TODO: inherit from base port_ops after converting to new EH */
26472 -static struct ata_port_operations pdc_20621_ops = {
26473 +static const struct ata_port_operations pdc_20621_ops = {
26474 .inherits = &ata_sff_port_ops,
26475
26476 .check_atapi_dma = pdc_check_atapi_dma,
26477 diff -urNp linux-2.6.39.2/drivers/ata/sata_uli.c linux-2.6.39.2/drivers/ata/sata_uli.c
26478 --- linux-2.6.39.2/drivers/ata/sata_uli.c 2011-05-19 00:06:34.000000000 -0400
26479 +++ linux-2.6.39.2/drivers/ata/sata_uli.c 2011-05-22 19:36:31.000000000 -0400
26480 @@ -80,7 +80,7 @@ static struct scsi_host_template uli_sht
26481 ATA_BMDMA_SHT(DRV_NAME),
26482 };
26483
26484 -static struct ata_port_operations uli_ops = {
26485 +static const struct ata_port_operations uli_ops = {
26486 .inherits = &ata_bmdma_port_ops,
26487 .scr_read = uli_scr_read,
26488 .scr_write = uli_scr_write,
26489 diff -urNp linux-2.6.39.2/drivers/ata/sata_via.c linux-2.6.39.2/drivers/ata/sata_via.c
26490 --- linux-2.6.39.2/drivers/ata/sata_via.c 2011-05-19 00:06:34.000000000 -0400
26491 +++ linux-2.6.39.2/drivers/ata/sata_via.c 2011-05-22 19:36:31.000000000 -0400
26492 @@ -115,32 +115,32 @@ static struct scsi_host_template svia_sh
26493 ATA_BMDMA_SHT(DRV_NAME),
26494 };
26495
26496 -static struct ata_port_operations svia_base_ops = {
26497 +static const struct ata_port_operations svia_base_ops = {
26498 .inherits = &ata_bmdma_port_ops,
26499 .sff_tf_load = svia_tf_load,
26500 };
26501
26502 -static struct ata_port_operations vt6420_sata_ops = {
26503 +static const struct ata_port_operations vt6420_sata_ops = {
26504 .inherits = &svia_base_ops,
26505 .freeze = svia_noop_freeze,
26506 .prereset = vt6420_prereset,
26507 .bmdma_start = vt6420_bmdma_start,
26508 };
26509
26510 -static struct ata_port_operations vt6421_pata_ops = {
26511 +static const struct ata_port_operations vt6421_pata_ops = {
26512 .inherits = &svia_base_ops,
26513 .cable_detect = vt6421_pata_cable_detect,
26514 .set_piomode = vt6421_set_pio_mode,
26515 .set_dmamode = vt6421_set_dma_mode,
26516 };
26517
26518 -static struct ata_port_operations vt6421_sata_ops = {
26519 +static const struct ata_port_operations vt6421_sata_ops = {
26520 .inherits = &svia_base_ops,
26521 .scr_read = svia_scr_read,
26522 .scr_write = svia_scr_write,
26523 };
26524
26525 -static struct ata_port_operations vt8251_ops = {
26526 +static const struct ata_port_operations vt8251_ops = {
26527 .inherits = &svia_base_ops,
26528 .hardreset = sata_std_hardreset,
26529 .scr_read = vt8251_scr_read,
26530 diff -urNp linux-2.6.39.2/drivers/ata/sata_vsc.c linux-2.6.39.2/drivers/ata/sata_vsc.c
26531 --- linux-2.6.39.2/drivers/ata/sata_vsc.c 2011-05-19 00:06:34.000000000 -0400
26532 +++ linux-2.6.39.2/drivers/ata/sata_vsc.c 2011-05-22 19:36:31.000000000 -0400
26533 @@ -300,7 +300,7 @@ static struct scsi_host_template vsc_sat
26534 };
26535
26536
26537 -static struct ata_port_operations vsc_sata_ops = {
26538 +static const struct ata_port_operations vsc_sata_ops = {
26539 .inherits = &ata_bmdma_port_ops,
26540 /* The IRQ handling is not quite standard SFF behaviour so we
26541 cannot use the default lost interrupt handler */
26542 diff -urNp linux-2.6.39.2/drivers/atm/adummy.c linux-2.6.39.2/drivers/atm/adummy.c
26543 --- linux-2.6.39.2/drivers/atm/adummy.c 2011-05-19 00:06:34.000000000 -0400
26544 +++ linux-2.6.39.2/drivers/atm/adummy.c 2011-05-22 19:36:31.000000000 -0400
26545 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct
26546 vcc->pop(vcc, skb);
26547 else
26548 dev_kfree_skb_any(skb);
26549 - atomic_inc(&vcc->stats->tx);
26550 + atomic_inc_unchecked(&vcc->stats->tx);
26551
26552 return 0;
26553 }
26554 diff -urNp linux-2.6.39.2/drivers/atm/ambassador.c linux-2.6.39.2/drivers/atm/ambassador.c
26555 --- linux-2.6.39.2/drivers/atm/ambassador.c 2011-05-19 00:06:34.000000000 -0400
26556 +++ linux-2.6.39.2/drivers/atm/ambassador.c 2011-05-22 19:36:31.000000000 -0400
26557 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev,
26558 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
26559
26560 // VC layer stats
26561 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26562 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26563
26564 // free the descriptor
26565 kfree (tx_descr);
26566 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev,
26567 dump_skb ("<<<", vc, skb);
26568
26569 // VC layer stats
26570 - atomic_inc(&atm_vcc->stats->rx);
26571 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26572 __net_timestamp(skb);
26573 // end of our responsibility
26574 atm_vcc->push (atm_vcc, skb);
26575 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev,
26576 } else {
26577 PRINTK (KERN_INFO, "dropped over-size frame");
26578 // should we count this?
26579 - atomic_inc(&atm_vcc->stats->rx_drop);
26580 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26581 }
26582
26583 } else {
26584 @@ -1342,7 +1342,7 @@ static int amb_send (struct atm_vcc * at
26585 }
26586
26587 if (check_area (skb->data, skb->len)) {
26588 - atomic_inc(&atm_vcc->stats->tx_err);
26589 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
26590 return -ENOMEM; // ?
26591 }
26592
26593 diff -urNp linux-2.6.39.2/drivers/atm/atmtcp.c linux-2.6.39.2/drivers/atm/atmtcp.c
26594 --- linux-2.6.39.2/drivers/atm/atmtcp.c 2011-05-19 00:06:34.000000000 -0400
26595 +++ linux-2.6.39.2/drivers/atm/atmtcp.c 2011-05-22 19:36:31.000000000 -0400
26596 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc
26597 if (vcc->pop) vcc->pop(vcc,skb);
26598 else dev_kfree_skb(skb);
26599 if (dev_data) return 0;
26600 - atomic_inc(&vcc->stats->tx_err);
26601 + atomic_inc_unchecked(&vcc->stats->tx_err);
26602 return -ENOLINK;
26603 }
26604 size = skb->len+sizeof(struct atmtcp_hdr);
26605 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc
26606 if (!new_skb) {
26607 if (vcc->pop) vcc->pop(vcc,skb);
26608 else dev_kfree_skb(skb);
26609 - atomic_inc(&vcc->stats->tx_err);
26610 + atomic_inc_unchecked(&vcc->stats->tx_err);
26611 return -ENOBUFS;
26612 }
26613 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
26614 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc
26615 if (vcc->pop) vcc->pop(vcc,skb);
26616 else dev_kfree_skb(skb);
26617 out_vcc->push(out_vcc,new_skb);
26618 - atomic_inc(&vcc->stats->tx);
26619 - atomic_inc(&out_vcc->stats->rx);
26620 + atomic_inc_unchecked(&vcc->stats->tx);
26621 + atomic_inc_unchecked(&out_vcc->stats->rx);
26622 return 0;
26623 }
26624
26625 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc
26626 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
26627 read_unlock(&vcc_sklist_lock);
26628 if (!out_vcc) {
26629 - atomic_inc(&vcc->stats->tx_err);
26630 + atomic_inc_unchecked(&vcc->stats->tx_err);
26631 goto done;
26632 }
26633 skb_pull(skb,sizeof(struct atmtcp_hdr));
26634 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc
26635 __net_timestamp(new_skb);
26636 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
26637 out_vcc->push(out_vcc,new_skb);
26638 - atomic_inc(&vcc->stats->tx);
26639 - atomic_inc(&out_vcc->stats->rx);
26640 + atomic_inc_unchecked(&vcc->stats->tx);
26641 + atomic_inc_unchecked(&out_vcc->stats->rx);
26642 done:
26643 if (vcc->pop) vcc->pop(vcc,skb);
26644 else dev_kfree_skb(skb);
26645 diff -urNp linux-2.6.39.2/drivers/atm/eni.c linux-2.6.39.2/drivers/atm/eni.c
26646 --- linux-2.6.39.2/drivers/atm/eni.c 2011-05-19 00:06:34.000000000 -0400
26647 +++ linux-2.6.39.2/drivers/atm/eni.c 2011-05-22 19:36:31.000000000 -0400
26648 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
26649 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
26650 vcc->dev->number);
26651 length = 0;
26652 - atomic_inc(&vcc->stats->rx_err);
26653 + atomic_inc_unchecked(&vcc->stats->rx_err);
26654 }
26655 else {
26656 length = ATM_CELL_SIZE-1; /* no HEC */
26657 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26658 size);
26659 }
26660 eff = length = 0;
26661 - atomic_inc(&vcc->stats->rx_err);
26662 + atomic_inc_unchecked(&vcc->stats->rx_err);
26663 }
26664 else {
26665 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
26666 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
26667 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
26668 vcc->dev->number,vcc->vci,length,size << 2,descr);
26669 length = eff = 0;
26670 - atomic_inc(&vcc->stats->rx_err);
26671 + atomic_inc_unchecked(&vcc->stats->rx_err);
26672 }
26673 }
26674 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
26675 @@ -771,7 +771,7 @@ rx_dequeued++;
26676 vcc->push(vcc,skb);
26677 pushed++;
26678 }
26679 - atomic_inc(&vcc->stats->rx);
26680 + atomic_inc_unchecked(&vcc->stats->rx);
26681 }
26682 wake_up(&eni_dev->rx_wait);
26683 }
26684 @@ -1228,7 +1228,7 @@ static void dequeue_tx(struct atm_dev *d
26685 PCI_DMA_TODEVICE);
26686 if (vcc->pop) vcc->pop(vcc,skb);
26687 else dev_kfree_skb_irq(skb);
26688 - atomic_inc(&vcc->stats->tx);
26689 + atomic_inc_unchecked(&vcc->stats->tx);
26690 wake_up(&eni_dev->tx_wait);
26691 dma_complete++;
26692 }
26693 diff -urNp linux-2.6.39.2/drivers/atm/firestream.c linux-2.6.39.2/drivers/atm/firestream.c
26694 --- linux-2.6.39.2/drivers/atm/firestream.c 2011-05-19 00:06:34.000000000 -0400
26695 +++ linux-2.6.39.2/drivers/atm/firestream.c 2011-05-22 19:36:31.000000000 -0400
26696 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct
26697 }
26698 }
26699
26700 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26701 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26702
26703 fs_dprintk (FS_DEBUG_TXMEM, "i");
26704 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
26705 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_
26706 #endif
26707 skb_put (skb, qe->p1 & 0xffff);
26708 ATM_SKB(skb)->vcc = atm_vcc;
26709 - atomic_inc(&atm_vcc->stats->rx);
26710 + atomic_inc_unchecked(&atm_vcc->stats->rx);
26711 __net_timestamp(skb);
26712 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
26713 atm_vcc->push (atm_vcc, skb);
26714 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_
26715 kfree (pe);
26716 }
26717 if (atm_vcc)
26718 - atomic_inc(&atm_vcc->stats->rx_drop);
26719 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26720 break;
26721 case 0x1f: /* Reassembly abort: no buffers. */
26722 /* Silently increment error counter. */
26723 if (atm_vcc)
26724 - atomic_inc(&atm_vcc->stats->rx_drop);
26725 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
26726 break;
26727 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
26728 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
26729 diff -urNp linux-2.6.39.2/drivers/atm/fore200e.c linux-2.6.39.2/drivers/atm/fore200e.c
26730 --- linux-2.6.39.2/drivers/atm/fore200e.c 2011-05-19 00:06:34.000000000 -0400
26731 +++ linux-2.6.39.2/drivers/atm/fore200e.c 2011-05-22 19:36:31.000000000 -0400
26732 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200
26733 #endif
26734 /* check error condition */
26735 if (*entry->status & STATUS_ERROR)
26736 - atomic_inc(&vcc->stats->tx_err);
26737 + atomic_inc_unchecked(&vcc->stats->tx_err);
26738 else
26739 - atomic_inc(&vcc->stats->tx);
26740 + atomic_inc_unchecked(&vcc->stats->tx);
26741 }
26742 }
26743
26744 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore2
26745 if (skb == NULL) {
26746 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
26747
26748 - atomic_inc(&vcc->stats->rx_drop);
26749 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26750 return -ENOMEM;
26751 }
26752
26753 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore2
26754
26755 dev_kfree_skb_any(skb);
26756
26757 - atomic_inc(&vcc->stats->rx_drop);
26758 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26759 return -ENOMEM;
26760 }
26761
26762 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26763
26764 vcc->push(vcc, skb);
26765 - atomic_inc(&vcc->stats->rx);
26766 + atomic_inc_unchecked(&vcc->stats->rx);
26767
26768 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
26769
26770 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200
26771 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
26772 fore200e->atm_dev->number,
26773 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
26774 - atomic_inc(&vcc->stats->rx_err);
26775 + atomic_inc_unchecked(&vcc->stats->rx_err);
26776 }
26777 }
26778
26779 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struc
26780 goto retry_here;
26781 }
26782
26783 - atomic_inc(&vcc->stats->tx_err);
26784 + atomic_inc_unchecked(&vcc->stats->tx_err);
26785
26786 fore200e->tx_sat++;
26787 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
26788 diff -urNp linux-2.6.39.2/drivers/atm/he.c linux-2.6.39.2/drivers/atm/he.c
26789 --- linux-2.6.39.2/drivers/atm/he.c 2011-05-19 00:06:34.000000000 -0400
26790 +++ linux-2.6.39.2/drivers/atm/he.c 2011-05-22 19:36:31.000000000 -0400
26791 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26792
26793 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
26794 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
26795 - atomic_inc(&vcc->stats->rx_drop);
26796 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26797 goto return_host_buffers;
26798 }
26799
26800 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26801 RBRQ_LEN_ERR(he_dev->rbrq_head)
26802 ? "LEN_ERR" : "",
26803 vcc->vpi, vcc->vci);
26804 - atomic_inc(&vcc->stats->rx_err);
26805 + atomic_inc_unchecked(&vcc->stats->rx_err);
26806 goto return_host_buffers;
26807 }
26808
26809 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, i
26810 vcc->push(vcc, skb);
26811 spin_lock(&he_dev->global_lock);
26812
26813 - atomic_inc(&vcc->stats->rx);
26814 + atomic_inc_unchecked(&vcc->stats->rx);
26815
26816 return_host_buffers:
26817 ++pdus_assembled;
26818 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, str
26819 tpd->vcc->pop(tpd->vcc, tpd->skb);
26820 else
26821 dev_kfree_skb_any(tpd->skb);
26822 - atomic_inc(&tpd->vcc->stats->tx_err);
26823 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
26824 }
26825 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
26826 return;
26827 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26828 vcc->pop(vcc, skb);
26829 else
26830 dev_kfree_skb_any(skb);
26831 - atomic_inc(&vcc->stats->tx_err);
26832 + atomic_inc_unchecked(&vcc->stats->tx_err);
26833 return -EINVAL;
26834 }
26835
26836 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26837 vcc->pop(vcc, skb);
26838 else
26839 dev_kfree_skb_any(skb);
26840 - atomic_inc(&vcc->stats->tx_err);
26841 + atomic_inc_unchecked(&vcc->stats->tx_err);
26842 return -EINVAL;
26843 }
26844 #endif
26845 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26846 vcc->pop(vcc, skb);
26847 else
26848 dev_kfree_skb_any(skb);
26849 - atomic_inc(&vcc->stats->tx_err);
26850 + atomic_inc_unchecked(&vcc->stats->tx_err);
26851 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26852 return -ENOMEM;
26853 }
26854 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26855 vcc->pop(vcc, skb);
26856 else
26857 dev_kfree_skb_any(skb);
26858 - atomic_inc(&vcc->stats->tx_err);
26859 + atomic_inc_unchecked(&vcc->stats->tx_err);
26860 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26861 return -ENOMEM;
26862 }
26863 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_b
26864 __enqueue_tpd(he_dev, tpd, cid);
26865 spin_unlock_irqrestore(&he_dev->global_lock, flags);
26866
26867 - atomic_inc(&vcc->stats->tx);
26868 + atomic_inc_unchecked(&vcc->stats->tx);
26869
26870 return 0;
26871 }
26872 diff -urNp linux-2.6.39.2/drivers/atm/horizon.c linux-2.6.39.2/drivers/atm/horizon.c
26873 --- linux-2.6.39.2/drivers/atm/horizon.c 2011-05-19 00:06:34.000000000 -0400
26874 +++ linux-2.6.39.2/drivers/atm/horizon.c 2011-05-22 19:36:31.000000000 -0400
26875 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev,
26876 {
26877 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
26878 // VC layer stats
26879 - atomic_inc(&vcc->stats->rx);
26880 + atomic_inc_unchecked(&vcc->stats->rx);
26881 __net_timestamp(skb);
26882 // end of our responsibility
26883 vcc->push (vcc, skb);
26884 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const
26885 dev->tx_iovec = NULL;
26886
26887 // VC layer stats
26888 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
26889 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
26890
26891 // free the skb
26892 hrz_kfree_skb (skb);
26893 diff -urNp linux-2.6.39.2/drivers/atm/idt77252.c linux-2.6.39.2/drivers/atm/idt77252.c
26894 --- linux-2.6.39.2/drivers/atm/idt77252.c 2011-05-19 00:06:34.000000000 -0400
26895 +++ linux-2.6.39.2/drivers/atm/idt77252.c 2011-05-22 19:36:31.000000000 -0400
26896 @@ -811,7 +811,7 @@ drain_scq(struct idt77252_dev *card, str
26897 else
26898 dev_kfree_skb(skb);
26899
26900 - atomic_inc(&vcc->stats->tx);
26901 + atomic_inc_unchecked(&vcc->stats->tx);
26902 }
26903
26904 atomic_dec(&scq->used);
26905 @@ -1074,13 +1074,13 @@ dequeue_rx(struct idt77252_dev *card, st
26906 if ((sb = dev_alloc_skb(64)) == NULL) {
26907 printk("%s: Can't allocate buffers for aal0.\n",
26908 card->name);
26909 - atomic_add(i, &vcc->stats->rx_drop);
26910 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26911 break;
26912 }
26913 if (!atm_charge(vcc, sb->truesize)) {
26914 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
26915 card->name);
26916 - atomic_add(i - 1, &vcc->stats->rx_drop);
26917 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
26918 dev_kfree_skb(sb);
26919 break;
26920 }
26921 @@ -1097,7 +1097,7 @@ dequeue_rx(struct idt77252_dev *card, st
26922 ATM_SKB(sb)->vcc = vcc;
26923 __net_timestamp(sb);
26924 vcc->push(vcc, sb);
26925 - atomic_inc(&vcc->stats->rx);
26926 + atomic_inc_unchecked(&vcc->stats->rx);
26927
26928 cell += ATM_CELL_PAYLOAD;
26929 }
26930 @@ -1134,13 +1134,13 @@ dequeue_rx(struct idt77252_dev *card, st
26931 "(CDC: %08x)\n",
26932 card->name, len, rpp->len, readl(SAR_REG_CDC));
26933 recycle_rx_pool_skb(card, rpp);
26934 - atomic_inc(&vcc->stats->rx_err);
26935 + atomic_inc_unchecked(&vcc->stats->rx_err);
26936 return;
26937 }
26938 if (stat & SAR_RSQE_CRC) {
26939 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
26940 recycle_rx_pool_skb(card, rpp);
26941 - atomic_inc(&vcc->stats->rx_err);
26942 + atomic_inc_unchecked(&vcc->stats->rx_err);
26943 return;
26944 }
26945 if (skb_queue_len(&rpp->queue) > 1) {
26946 @@ -1151,7 +1151,7 @@ dequeue_rx(struct idt77252_dev *card, st
26947 RXPRINTK("%s: Can't alloc RX skb.\n",
26948 card->name);
26949 recycle_rx_pool_skb(card, rpp);
26950 - atomic_inc(&vcc->stats->rx_err);
26951 + atomic_inc_unchecked(&vcc->stats->rx_err);
26952 return;
26953 }
26954 if (!atm_charge(vcc, skb->truesize)) {
26955 @@ -1170,7 +1170,7 @@ dequeue_rx(struct idt77252_dev *card, st
26956 __net_timestamp(skb);
26957
26958 vcc->push(vcc, skb);
26959 - atomic_inc(&vcc->stats->rx);
26960 + atomic_inc_unchecked(&vcc->stats->rx);
26961
26962 return;
26963 }
26964 @@ -1192,7 +1192,7 @@ dequeue_rx(struct idt77252_dev *card, st
26965 __net_timestamp(skb);
26966
26967 vcc->push(vcc, skb);
26968 - atomic_inc(&vcc->stats->rx);
26969 + atomic_inc_unchecked(&vcc->stats->rx);
26970
26971 if (skb->truesize > SAR_FB_SIZE_3)
26972 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
26973 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *car
26974 if (vcc->qos.aal != ATM_AAL0) {
26975 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
26976 card->name, vpi, vci);
26977 - atomic_inc(&vcc->stats->rx_drop);
26978 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26979 goto drop;
26980 }
26981
26982 if ((sb = dev_alloc_skb(64)) == NULL) {
26983 printk("%s: Can't allocate buffers for AAL0.\n",
26984 card->name);
26985 - atomic_inc(&vcc->stats->rx_err);
26986 + atomic_inc_unchecked(&vcc->stats->rx_err);
26987 goto drop;
26988 }
26989
26990 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *car
26991 ATM_SKB(sb)->vcc = vcc;
26992 __net_timestamp(sb);
26993 vcc->push(vcc, sb);
26994 - atomic_inc(&vcc->stats->rx);
26995 + atomic_inc_unchecked(&vcc->stats->rx);
26996
26997 drop:
26998 skb_pull(queue, 64);
26999 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27000
27001 if (vc == NULL) {
27002 printk("%s: NULL connection in send().\n", card->name);
27003 - atomic_inc(&vcc->stats->tx_err);
27004 + atomic_inc_unchecked(&vcc->stats->tx_err);
27005 dev_kfree_skb(skb);
27006 return -EINVAL;
27007 }
27008 if (!test_bit(VCF_TX, &vc->flags)) {
27009 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
27010 - atomic_inc(&vcc->stats->tx_err);
27011 + atomic_inc_unchecked(&vcc->stats->tx_err);
27012 dev_kfree_skb(skb);
27013 return -EINVAL;
27014 }
27015 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27016 break;
27017 default:
27018 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
27019 - atomic_inc(&vcc->stats->tx_err);
27020 + atomic_inc_unchecked(&vcc->stats->tx_err);
27021 dev_kfree_skb(skb);
27022 return -EINVAL;
27023 }
27024
27025 if (skb_shinfo(skb)->nr_frags != 0) {
27026 printk("%s: No scatter-gather yet.\n", card->name);
27027 - atomic_inc(&vcc->stats->tx_err);
27028 + atomic_inc_unchecked(&vcc->stats->tx_err);
27029 dev_kfree_skb(skb);
27030 return -EINVAL;
27031 }
27032 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, s
27033
27034 err = queue_skb(card, vc, skb, oam);
27035 if (err) {
27036 - atomic_inc(&vcc->stats->tx_err);
27037 + atomic_inc_unchecked(&vcc->stats->tx_err);
27038 dev_kfree_skb(skb);
27039 return err;
27040 }
27041 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, v
27042 skb = dev_alloc_skb(64);
27043 if (!skb) {
27044 printk("%s: Out of memory in send_oam().\n", card->name);
27045 - atomic_inc(&vcc->stats->tx_err);
27046 + atomic_inc_unchecked(&vcc->stats->tx_err);
27047 return -ENOMEM;
27048 }
27049 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
27050 diff -urNp linux-2.6.39.2/drivers/atm/iphase.c linux-2.6.39.2/drivers/atm/iphase.c
27051 --- linux-2.6.39.2/drivers/atm/iphase.c 2011-05-19 00:06:34.000000000 -0400
27052 +++ linux-2.6.39.2/drivers/atm/iphase.c 2011-05-22 19:36:31.000000000 -0400
27053 @@ -1124,7 +1124,7 @@ static int rx_pkt(struct atm_dev *dev)
27054 status = (u_short) (buf_desc_ptr->desc_mode);
27055 if (status & (RX_CER | RX_PTE | RX_OFL))
27056 {
27057 - atomic_inc(&vcc->stats->rx_err);
27058 + atomic_inc_unchecked(&vcc->stats->rx_err);
27059 IF_ERR(printk("IA: bad packet, dropping it");)
27060 if (status & RX_CER) {
27061 IF_ERR(printk(" cause: packet CRC error\n");)
27062 @@ -1147,7 +1147,7 @@ static int rx_pkt(struct atm_dev *dev)
27063 len = dma_addr - buf_addr;
27064 if (len > iadev->rx_buf_sz) {
27065 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
27066 - atomic_inc(&vcc->stats->rx_err);
27067 + atomic_inc_unchecked(&vcc->stats->rx_err);
27068 goto out_free_desc;
27069 }
27070
27071 @@ -1297,7 +1297,7 @@ static void rx_dle_intr(struct atm_dev *
27072 ia_vcc = INPH_IA_VCC(vcc);
27073 if (ia_vcc == NULL)
27074 {
27075 - atomic_inc(&vcc->stats->rx_err);
27076 + atomic_inc_unchecked(&vcc->stats->rx_err);
27077 dev_kfree_skb_any(skb);
27078 atm_return(vcc, atm_guess_pdu2truesize(len));
27079 goto INCR_DLE;
27080 @@ -1309,7 +1309,7 @@ static void rx_dle_intr(struct atm_dev *
27081 if ((length > iadev->rx_buf_sz) || (length >
27082 (skb->len - sizeof(struct cpcs_trailer))))
27083 {
27084 - atomic_inc(&vcc->stats->rx_err);
27085 + atomic_inc_unchecked(&vcc->stats->rx_err);
27086 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
27087 length, skb->len);)
27088 dev_kfree_skb_any(skb);
27089 @@ -1325,7 +1325,7 @@ static void rx_dle_intr(struct atm_dev *
27090
27091 IF_RX(printk("rx_dle_intr: skb push");)
27092 vcc->push(vcc,skb);
27093 - atomic_inc(&vcc->stats->rx);
27094 + atomic_inc_unchecked(&vcc->stats->rx);
27095 iadev->rx_pkt_cnt++;
27096 }
27097 INCR_DLE:
27098 @@ -2807,15 +2807,15 @@ static int ia_ioctl(struct atm_dev *dev,
27099 {
27100 struct k_sonet_stats *stats;
27101 stats = &PRIV(_ia_dev[board])->sonet_stats;
27102 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
27103 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
27104 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
27105 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
27106 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
27107 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
27108 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
27109 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
27110 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
27111 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
27112 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
27113 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
27114 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
27115 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
27116 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
27117 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
27118 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
27119 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
27120 }
27121 ia_cmds.status = 0;
27122 break;
27123 @@ -2920,7 +2920,7 @@ static int ia_pkt_tx (struct atm_vcc *vc
27124 if ((desc == 0) || (desc > iadev->num_tx_desc))
27125 {
27126 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
27127 - atomic_inc(&vcc->stats->tx);
27128 + atomic_inc_unchecked(&vcc->stats->tx);
27129 if (vcc->pop)
27130 vcc->pop(vcc, skb);
27131 else
27132 @@ -3025,14 +3025,14 @@ static int ia_pkt_tx (struct atm_vcc *vc
27133 ATM_DESC(skb) = vcc->vci;
27134 skb_queue_tail(&iadev->tx_dma_q, skb);
27135
27136 - atomic_inc(&vcc->stats->tx);
27137 + atomic_inc_unchecked(&vcc->stats->tx);
27138 iadev->tx_pkt_cnt++;
27139 /* Increment transaction counter */
27140 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
27141
27142 #if 0
27143 /* add flow control logic */
27144 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
27145 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
27146 if (iavcc->vc_desc_cnt > 10) {
27147 vcc->tx_quota = vcc->tx_quota * 3 / 4;
27148 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
27149 diff -urNp linux-2.6.39.2/drivers/atm/lanai.c linux-2.6.39.2/drivers/atm/lanai.c
27150 --- linux-2.6.39.2/drivers/atm/lanai.c 2011-05-19 00:06:34.000000000 -0400
27151 +++ linux-2.6.39.2/drivers/atm/lanai.c 2011-05-22 19:36:31.000000000 -0400
27152 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct l
27153 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
27154 lanai_endtx(lanai, lvcc);
27155 lanai_free_skb(lvcc->tx.atmvcc, skb);
27156 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
27157 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
27158 }
27159
27160 /* Try to fill the buffer - don't call unless there is backlog */
27161 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc
27162 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
27163 __net_timestamp(skb);
27164 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
27165 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
27166 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
27167 out:
27168 lvcc->rx.buf.ptr = end;
27169 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
27170 @@ -1668,7 +1668,7 @@ static int handle_service(struct lanai_d
27171 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
27172 "vcc %d\n", lanai->number, (unsigned int) s, vci);
27173 lanai->stats.service_rxnotaal5++;
27174 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27175 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27176 return 0;
27177 }
27178 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
27179 @@ -1680,7 +1680,7 @@ static int handle_service(struct lanai_d
27180 int bytes;
27181 read_unlock(&vcc_sklist_lock);
27182 DPRINTK("got trashed rx pdu on vci %d\n", vci);
27183 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27184 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27185 lvcc->stats.x.aal5.service_trash++;
27186 bytes = (SERVICE_GET_END(s) * 16) -
27187 (((unsigned long) lvcc->rx.buf.ptr) -
27188 @@ -1692,7 +1692,7 @@ static int handle_service(struct lanai_d
27189 }
27190 if (s & SERVICE_STREAM) {
27191 read_unlock(&vcc_sklist_lock);
27192 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27193 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27194 lvcc->stats.x.aal5.service_stream++;
27195 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
27196 "PDU on VCI %d!\n", lanai->number, vci);
27197 @@ -1700,7 +1700,7 @@ static int handle_service(struct lanai_d
27198 return 0;
27199 }
27200 DPRINTK("got rx crc error on vci %d\n", vci);
27201 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
27202 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
27203 lvcc->stats.x.aal5.service_rxcrc++;
27204 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
27205 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
27206 diff -urNp linux-2.6.39.2/drivers/atm/nicstar.c linux-2.6.39.2/drivers/atm/nicstar.c
27207 --- linux-2.6.39.2/drivers/atm/nicstar.c 2011-05-19 00:06:34.000000000 -0400
27208 +++ linux-2.6.39.2/drivers/atm/nicstar.c 2011-05-22 19:36:31.000000000 -0400
27209 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc,
27210 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
27211 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
27212 card->index);
27213 - atomic_inc(&vcc->stats->tx_err);
27214 + atomic_inc_unchecked(&vcc->stats->tx_err);
27215 dev_kfree_skb_any(skb);
27216 return -EINVAL;
27217 }
27218 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc,
27219 if (!vc->tx) {
27220 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
27221 card->index);
27222 - atomic_inc(&vcc->stats->tx_err);
27223 + atomic_inc_unchecked(&vcc->stats->tx_err);
27224 dev_kfree_skb_any(skb);
27225 return -EINVAL;
27226 }
27227 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc,
27228 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
27229 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
27230 card->index);
27231 - atomic_inc(&vcc->stats->tx_err);
27232 + atomic_inc_unchecked(&vcc->stats->tx_err);
27233 dev_kfree_skb_any(skb);
27234 return -EINVAL;
27235 }
27236
27237 if (skb_shinfo(skb)->nr_frags != 0) {
27238 printk("nicstar%d: No scatter-gather yet.\n", card->index);
27239 - atomic_inc(&vcc->stats->tx_err);
27240 + atomic_inc_unchecked(&vcc->stats->tx_err);
27241 dev_kfree_skb_any(skb);
27242 return -EINVAL;
27243 }
27244 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc,
27245 }
27246
27247 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
27248 - atomic_inc(&vcc->stats->tx_err);
27249 + atomic_inc_unchecked(&vcc->stats->tx_err);
27250 dev_kfree_skb_any(skb);
27251 return -EIO;
27252 }
27253 - atomic_inc(&vcc->stats->tx);
27254 + atomic_inc_unchecked(&vcc->stats->tx);
27255
27256 return 0;
27257 }
27258 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns
27259 printk
27260 ("nicstar%d: Can't allocate buffers for aal0.\n",
27261 card->index);
27262 - atomic_add(i, &vcc->stats->rx_drop);
27263 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
27264 break;
27265 }
27266 if (!atm_charge(vcc, sb->truesize)) {
27267 RXPRINTK
27268 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
27269 card->index);
27270 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27271 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
27272 dev_kfree_skb_any(sb);
27273 break;
27274 }
27275 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns
27276 ATM_SKB(sb)->vcc = vcc;
27277 __net_timestamp(sb);
27278 vcc->push(vcc, sb);
27279 - atomic_inc(&vcc->stats->rx);
27280 + atomic_inc_unchecked(&vcc->stats->rx);
27281 cell += ATM_CELL_PAYLOAD;
27282 }
27283
27284 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns
27285 if (iovb == NULL) {
27286 printk("nicstar%d: Out of iovec buffers.\n",
27287 card->index);
27288 - atomic_inc(&vcc->stats->rx_drop);
27289 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27290 recycle_rx_buf(card, skb);
27291 return;
27292 }
27293 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns
27294 small or large buffer itself. */
27295 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
27296 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
27297 - atomic_inc(&vcc->stats->rx_err);
27298 + atomic_inc_unchecked(&vcc->stats->rx_err);
27299 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27300 NS_MAX_IOVECS);
27301 NS_PRV_IOVCNT(iovb) = 0;
27302 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns
27303 ("nicstar%d: Expected a small buffer, and this is not one.\n",
27304 card->index);
27305 which_list(card, skb);
27306 - atomic_inc(&vcc->stats->rx_err);
27307 + atomic_inc_unchecked(&vcc->stats->rx_err);
27308 recycle_rx_buf(card, skb);
27309 vc->rx_iov = NULL;
27310 recycle_iov_buf(card, iovb);
27311 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns
27312 ("nicstar%d: Expected a large buffer, and this is not one.\n",
27313 card->index);
27314 which_list(card, skb);
27315 - atomic_inc(&vcc->stats->rx_err);
27316 + atomic_inc_unchecked(&vcc->stats->rx_err);
27317 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27318 NS_PRV_IOVCNT(iovb));
27319 vc->rx_iov = NULL;
27320 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns
27321 printk(" - PDU size mismatch.\n");
27322 else
27323 printk(".\n");
27324 - atomic_inc(&vcc->stats->rx_err);
27325 + atomic_inc_unchecked(&vcc->stats->rx_err);
27326 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
27327 NS_PRV_IOVCNT(iovb));
27328 vc->rx_iov = NULL;
27329 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns
27330 /* skb points to a small buffer */
27331 if (!atm_charge(vcc, skb->truesize)) {
27332 push_rxbufs(card, skb);
27333 - atomic_inc(&vcc->stats->rx_drop);
27334 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27335 } else {
27336 skb_put(skb, len);
27337 dequeue_sm_buf(card, skb);
27338 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns
27339 ATM_SKB(skb)->vcc = vcc;
27340 __net_timestamp(skb);
27341 vcc->push(vcc, skb);
27342 - atomic_inc(&vcc->stats->rx);
27343 + atomic_inc_unchecked(&vcc->stats->rx);
27344 }
27345 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
27346 struct sk_buff *sb;
27347 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns
27348 if (len <= NS_SMBUFSIZE) {
27349 if (!atm_charge(vcc, sb->truesize)) {
27350 push_rxbufs(card, sb);
27351 - atomic_inc(&vcc->stats->rx_drop);
27352 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27353 } else {
27354 skb_put(sb, len);
27355 dequeue_sm_buf(card, sb);
27356 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns
27357 ATM_SKB(sb)->vcc = vcc;
27358 __net_timestamp(sb);
27359 vcc->push(vcc, sb);
27360 - atomic_inc(&vcc->stats->rx);
27361 + atomic_inc_unchecked(&vcc->stats->rx);
27362 }
27363
27364 push_rxbufs(card, skb);
27365 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns
27366
27367 if (!atm_charge(vcc, skb->truesize)) {
27368 push_rxbufs(card, skb);
27369 - atomic_inc(&vcc->stats->rx_drop);
27370 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27371 } else {
27372 dequeue_lg_buf(card, skb);
27373 #ifdef NS_USE_DESTRUCTORS
27374 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns
27375 ATM_SKB(skb)->vcc = vcc;
27376 __net_timestamp(skb);
27377 vcc->push(vcc, skb);
27378 - atomic_inc(&vcc->stats->rx);
27379 + atomic_inc_unchecked(&vcc->stats->rx);
27380 }
27381
27382 push_rxbufs(card, sb);
27383 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns
27384 printk
27385 ("nicstar%d: Out of huge buffers.\n",
27386 card->index);
27387 - atomic_inc(&vcc->stats->rx_drop);
27388 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27389 recycle_iovec_rx_bufs(card,
27390 (struct iovec *)
27391 iovb->data,
27392 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns
27393 card->hbpool.count++;
27394 } else
27395 dev_kfree_skb_any(hb);
27396 - atomic_inc(&vcc->stats->rx_drop);
27397 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27398 } else {
27399 /* Copy the small buffer to the huge buffer */
27400 sb = (struct sk_buff *)iov->iov_base;
27401 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns
27402 #endif /* NS_USE_DESTRUCTORS */
27403 __net_timestamp(hb);
27404 vcc->push(vcc, hb);
27405 - atomic_inc(&vcc->stats->rx);
27406 + atomic_inc_unchecked(&vcc->stats->rx);
27407 }
27408 }
27409
27410 diff -urNp linux-2.6.39.2/drivers/atm/solos-pci.c linux-2.6.39.2/drivers/atm/solos-pci.c
27411 --- linux-2.6.39.2/drivers/atm/solos-pci.c 2011-05-19 00:06:34.000000000 -0400
27412 +++ linux-2.6.39.2/drivers/atm/solos-pci.c 2011-05-22 19:36:31.000000000 -0400
27413 @@ -715,7 +715,7 @@ void solos_bh(unsigned long card_arg)
27414 }
27415 atm_charge(vcc, skb->truesize);
27416 vcc->push(vcc, skb);
27417 - atomic_inc(&vcc->stats->rx);
27418 + atomic_inc_unchecked(&vcc->stats->rx);
27419 break;
27420
27421 case PKT_STATUS:
27422 @@ -900,6 +900,8 @@ static int print_buffer(struct sk_buff *
27423 char msg[500];
27424 char item[10];
27425
27426 + pax_track_stack();
27427 +
27428 len = buf->len;
27429 for (i = 0; i < len; i++){
27430 if(i % 8 == 0)
27431 @@ -1009,7 +1011,7 @@ static uint32_t fpga_tx(struct solos_car
27432 vcc = SKB_CB(oldskb)->vcc;
27433
27434 if (vcc) {
27435 - atomic_inc(&vcc->stats->tx);
27436 + atomic_inc_unchecked(&vcc->stats->tx);
27437 solos_pop(vcc, oldskb);
27438 } else
27439 dev_kfree_skb_irq(oldskb);
27440 diff -urNp linux-2.6.39.2/drivers/atm/suni.c linux-2.6.39.2/drivers/atm/suni.c
27441 --- linux-2.6.39.2/drivers/atm/suni.c 2011-05-19 00:06:34.000000000 -0400
27442 +++ linux-2.6.39.2/drivers/atm/suni.c 2011-05-22 19:36:31.000000000 -0400
27443 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
27444
27445
27446 #define ADD_LIMITED(s,v) \
27447 - atomic_add((v),&stats->s); \
27448 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
27449 + atomic_add_unchecked((v),&stats->s); \
27450 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
27451
27452
27453 static void suni_hz(unsigned long from_timer)
27454 diff -urNp linux-2.6.39.2/drivers/atm/uPD98402.c linux-2.6.39.2/drivers/atm/uPD98402.c
27455 --- linux-2.6.39.2/drivers/atm/uPD98402.c 2011-05-19 00:06:34.000000000 -0400
27456 +++ linux-2.6.39.2/drivers/atm/uPD98402.c 2011-05-22 19:36:31.000000000 -0400
27457 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *d
27458 struct sonet_stats tmp;
27459 int error = 0;
27460
27461 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27462 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
27463 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
27464 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
27465 if (zero && !error) {
27466 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev
27467
27468
27469 #define ADD_LIMITED(s,v) \
27470 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
27471 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
27472 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27473 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
27474 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
27475 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
27476
27477
27478 static void stat_event(struct atm_dev *dev)
27479 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev
27480 if (reason & uPD98402_INT_PFM) stat_event(dev);
27481 if (reason & uPD98402_INT_PCO) {
27482 (void) GET(PCOCR); /* clear interrupt cause */
27483 - atomic_add(GET(HECCT),
27484 + atomic_add_unchecked(GET(HECCT),
27485 &PRIV(dev)->sonet_stats.uncorr_hcs);
27486 }
27487 if ((reason & uPD98402_INT_RFO) &&
27488 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev
27489 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
27490 uPD98402_INT_LOS),PIMR); /* enable them */
27491 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
27492 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27493 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
27494 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
27495 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
27496 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
27497 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
27498 return 0;
27499 }
27500
27501 diff -urNp linux-2.6.39.2/drivers/atm/zatm.c linux-2.6.39.2/drivers/atm/zatm.c
27502 --- linux-2.6.39.2/drivers/atm/zatm.c 2011-05-19 00:06:34.000000000 -0400
27503 +++ linux-2.6.39.2/drivers/atm/zatm.c 2011-05-22 19:36:31.000000000 -0400
27504 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27505 }
27506 if (!size) {
27507 dev_kfree_skb_irq(skb);
27508 - if (vcc) atomic_inc(&vcc->stats->rx_err);
27509 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
27510 continue;
27511 }
27512 if (!atm_charge(vcc,skb->truesize)) {
27513 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy
27514 skb->len = size;
27515 ATM_SKB(skb)->vcc = vcc;
27516 vcc->push(vcc,skb);
27517 - atomic_inc(&vcc->stats->rx);
27518 + atomic_inc_unchecked(&vcc->stats->rx);
27519 }
27520 zout(pos & 0xffff,MTA(mbx));
27521 #if 0 /* probably a stupid idea */
27522 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD
27523 skb_queue_head(&zatm_vcc->backlog,skb);
27524 break;
27525 }
27526 - atomic_inc(&vcc->stats->tx);
27527 + atomic_inc_unchecked(&vcc->stats->tx);
27528 wake_up(&zatm_vcc->tx_wait);
27529 }
27530
27531 diff -urNp linux-2.6.39.2/drivers/base/iommu.c linux-2.6.39.2/drivers/base/iommu.c
27532 --- linux-2.6.39.2/drivers/base/iommu.c 2011-05-19 00:06:34.000000000 -0400
27533 +++ linux-2.6.39.2/drivers/base/iommu.c 2011-05-22 19:36:31.000000000 -0400
27534 @@ -23,9 +23,8 @@
27535 #include <linux/errno.h>
27536 #include <linux/iommu.h>
27537
27538 -static struct iommu_ops *iommu_ops;
27539 -
27540 -void register_iommu(struct iommu_ops *ops)
27541 +static const struct iommu_ops *iommu_ops;
27542 +void register_iommu(const struct iommu_ops *ops)
27543 {
27544 if (iommu_ops)
27545 BUG();
27546 diff -urNp linux-2.6.39.2/drivers/base/power/generic_ops.c linux-2.6.39.2/drivers/base/power/generic_ops.c
27547 --- linux-2.6.39.2/drivers/base/power/generic_ops.c 2011-05-19 00:06:34.000000000 -0400
27548 +++ linux-2.6.39.2/drivers/base/power/generic_ops.c 2011-05-22 19:36:31.000000000 -0400
27549 @@ -215,7 +215,7 @@ int pm_generic_restore(struct device *de
27550 EXPORT_SYMBOL_GPL(pm_generic_restore);
27551 #endif /* CONFIG_PM_SLEEP */
27552
27553 -struct dev_pm_ops generic_subsys_pm_ops = {
27554 +const struct dev_pm_ops generic_subsys_pm_ops = {
27555 #ifdef CONFIG_PM_SLEEP
27556 .suspend = pm_generic_suspend,
27557 .resume = pm_generic_resume,
27558 diff -urNp linux-2.6.39.2/drivers/base/power/wakeup.c linux-2.6.39.2/drivers/base/power/wakeup.c
27559 --- linux-2.6.39.2/drivers/base/power/wakeup.c 2011-05-19 00:06:34.000000000 -0400
27560 +++ linux-2.6.39.2/drivers/base/power/wakeup.c 2011-05-22 19:36:31.000000000 -0400
27561 @@ -29,14 +29,14 @@ bool events_check_enabled;
27562 * They need to be modified together atomically, so it's better to use one
27563 * atomic variable to hold them both.
27564 */
27565 -static atomic_t combined_event_count = ATOMIC_INIT(0);
27566 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
27567
27568 #define IN_PROGRESS_BITS (sizeof(int) * 4)
27569 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
27570
27571 static void split_counters(unsigned int *cnt, unsigned int *inpr)
27572 {
27573 - unsigned int comb = atomic_read(&combined_event_count);
27574 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
27575
27576 *cnt = (comb >> IN_PROGRESS_BITS);
27577 *inpr = comb & MAX_IN_PROGRESS;
27578 @@ -351,7 +351,7 @@ static void wakeup_source_activate(struc
27579 ws->last_time = ktime_get();
27580
27581 /* Increment the counter of events in progress. */
27582 - atomic_inc(&combined_event_count);
27583 + atomic_inc_unchecked(&combined_event_count);
27584 }
27585
27586 /**
27587 @@ -441,7 +441,7 @@ static void wakeup_source_deactivate(str
27588 * Increment the counter of registered wakeup events and decrement the
27589 * couter of wakeup events in progress simultaneously.
27590 */
27591 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
27592 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
27593 }
27594
27595 /**
27596 diff -urNp linux-2.6.39.2/drivers/block/cciss.c linux-2.6.39.2/drivers/block/cciss.c
27597 --- linux-2.6.39.2/drivers/block/cciss.c 2011-05-19 00:06:34.000000000 -0400
27598 +++ linux-2.6.39.2/drivers/block/cciss.c 2011-05-22 19:41:32.000000000 -0400
27599 @@ -103,7 +103,7 @@ MODULE_DEVICE_TABLE(pci, cciss_pci_devic
27600 * product = Marketing Name for the board
27601 * access = Address of the struct of function pointers
27602 */
27603 -static struct board_type products[] = {
27604 +static const struct board_type products[] = {
27605 {0x40700E11, "Smart Array 5300", &SA5_access},
27606 {0x40800E11, "Smart Array 5i", &SA5B_access},
27607 {0x40820E11, "Smart Array 532", &SA5B_access},
27608 @@ -1151,6 +1151,8 @@ static int cciss_ioctl32_passthru(struct
27609 int err;
27610 u32 cp;
27611
27612 + memset(&arg64, 0, sizeof(arg64));
27613 +
27614 err = 0;
27615 err |=
27616 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
27617 diff -urNp linux-2.6.39.2/drivers/block/cciss.h linux-2.6.39.2/drivers/block/cciss.h
27618 --- linux-2.6.39.2/drivers/block/cciss.h 2011-05-19 00:06:34.000000000 -0400
27619 +++ linux-2.6.39.2/drivers/block/cciss.h 2011-05-22 19:36:31.000000000 -0400
27620 @@ -393,7 +393,7 @@ static bool SA5_performant_intr_pending(
27621 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
27622 }
27623
27624 -static struct access_method SA5_access = {
27625 +static const struct access_method SA5_access = {
27626 SA5_submit_command,
27627 SA5_intr_mask,
27628 SA5_fifo_full,
27629 @@ -401,7 +401,7 @@ static struct access_method SA5_access =
27630 SA5_completed,
27631 };
27632
27633 -static struct access_method SA5B_access = {
27634 +static const struct access_method SA5B_access = {
27635 SA5_submit_command,
27636 SA5B_intr_mask,
27637 SA5_fifo_full,
27638 @@ -409,7 +409,7 @@ static struct access_method SA5B_access
27639 SA5_completed,
27640 };
27641
27642 -static struct access_method SA5_performant_access = {
27643 +static const struct access_method SA5_performant_access = {
27644 SA5_submit_command,
27645 SA5_performant_intr_mask,
27646 SA5_fifo_full,
27647 @@ -420,7 +420,7 @@ static struct access_method SA5_performa
27648 struct board_type {
27649 __u32 board_id;
27650 char *product_name;
27651 - struct access_method *access;
27652 + const struct access_method *access;
27653 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
27654 };
27655
27656 diff -urNp linux-2.6.39.2/drivers/block/cpqarray.c linux-2.6.39.2/drivers/block/cpqarray.c
27657 --- linux-2.6.39.2/drivers/block/cpqarray.c 2011-05-19 00:06:34.000000000 -0400
27658 +++ linux-2.6.39.2/drivers/block/cpqarray.c 2011-05-22 19:36:31.000000000 -0400
27659 @@ -80,7 +80,7 @@ static int eisa[8];
27660 * product = Marketing Name for the board
27661 * access = Address of the struct of function pointers
27662 */
27663 -static struct board_type products[] = {
27664 +static const struct board_type products[] = {
27665 { 0x0040110E, "IDA", &smart1_access },
27666 { 0x0140110E, "IDA-2", &smart1_access },
27667 { 0x1040110E, "IAES", &smart1_access },
27668 @@ -911,6 +911,8 @@ static void do_ida_request(struct reques
27669 struct scatterlist tmp_sg[SG_MAX];
27670 int i, dir, seg;
27671
27672 + pax_track_stack();
27673 +
27674 queue_next:
27675 creq = blk_peek_request(q);
27676 if (!creq)
27677 diff -urNp linux-2.6.39.2/drivers/block/cpqarray.h linux-2.6.39.2/drivers/block/cpqarray.h
27678 --- linux-2.6.39.2/drivers/block/cpqarray.h 2011-05-19 00:06:34.000000000 -0400
27679 +++ linux-2.6.39.2/drivers/block/cpqarray.h 2011-05-22 19:36:31.000000000 -0400
27680 @@ -69,7 +69,7 @@ struct access_method {
27681 struct board_type {
27682 __u32 board_id;
27683 char *product_name;
27684 - struct access_method *access;
27685 + const struct access_method *access;
27686 };
27687
27688 struct ctlr_info {
27689 diff -urNp linux-2.6.39.2/drivers/block/DAC960.c linux-2.6.39.2/drivers/block/DAC960.c
27690 --- linux-2.6.39.2/drivers/block/DAC960.c 2011-05-19 00:06:34.000000000 -0400
27691 +++ linux-2.6.39.2/drivers/block/DAC960.c 2011-05-22 19:36:31.000000000 -0400
27692 @@ -1980,6 +1980,8 @@ static bool DAC960_V1_ReadDeviceConfigur
27693 unsigned long flags;
27694 int Channel, TargetID;
27695
27696 + pax_track_stack();
27697 +
27698 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
27699 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
27700 sizeof(DAC960_SCSI_Inquiry_T) +
27701 diff -urNp linux-2.6.39.2/drivers/block/drbd/drbd_int.h linux-2.6.39.2/drivers/block/drbd/drbd_int.h
27702 --- linux-2.6.39.2/drivers/block/drbd/drbd_int.h 2011-05-19 00:06:34.000000000 -0400
27703 +++ linux-2.6.39.2/drivers/block/drbd/drbd_int.h 2011-05-22 19:36:31.000000000 -0400
27704 @@ -736,7 +736,7 @@ struct drbd_request;
27705 struct drbd_epoch {
27706 struct list_head list;
27707 unsigned int barrier_nr;
27708 - atomic_t epoch_size; /* increased on every request added. */
27709 + atomic_unchecked_t epoch_size; /* increased on every request added. */
27710 atomic_t active; /* increased on every req. added, and dec on every finished. */
27711 unsigned long flags;
27712 };
27713 @@ -1108,7 +1108,7 @@ struct drbd_conf {
27714 void *int_dig_in;
27715 void *int_dig_vv;
27716 wait_queue_head_t seq_wait;
27717 - atomic_t packet_seq;
27718 + atomic_unchecked_t packet_seq;
27719 unsigned int peer_seq;
27720 spinlock_t peer_seq_lock;
27721 unsigned int minor;
27722 diff -urNp linux-2.6.39.2/drivers/block/drbd/drbd_main.c linux-2.6.39.2/drivers/block/drbd/drbd_main.c
27723 --- linux-2.6.39.2/drivers/block/drbd/drbd_main.c 2011-05-19 00:06:34.000000000 -0400
27724 +++ linux-2.6.39.2/drivers/block/drbd/drbd_main.c 2011-05-22 19:36:31.000000000 -0400
27725 @@ -2387,7 +2387,7 @@ static int _drbd_send_ack(struct drbd_co
27726 p.sector = sector;
27727 p.block_id = block_id;
27728 p.blksize = blksize;
27729 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
27730 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
27731
27732 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
27733 return false;
27734 @@ -2686,7 +2686,7 @@ int drbd_send_dblock(struct drbd_conf *m
27735 p.sector = cpu_to_be64(req->sector);
27736 p.block_id = (unsigned long)req;
27737 p.seq_num = cpu_to_be32(req->seq_num =
27738 - atomic_add_return(1, &mdev->packet_seq));
27739 + atomic_add_return_unchecked(1, &mdev->packet_seq));
27740
27741 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
27742
27743 @@ -2971,7 +2971,7 @@ void drbd_init_set_defaults(struct drbd_
27744 atomic_set(&mdev->unacked_cnt, 0);
27745 atomic_set(&mdev->local_cnt, 0);
27746 atomic_set(&mdev->net_cnt, 0);
27747 - atomic_set(&mdev->packet_seq, 0);
27748 + atomic_set_unchecked(&mdev->packet_seq, 0);
27749 atomic_set(&mdev->pp_in_use, 0);
27750 atomic_set(&mdev->pp_in_use_by_net, 0);
27751 atomic_set(&mdev->rs_sect_in, 0);
27752 @@ -3051,8 +3051,8 @@ void drbd_mdev_cleanup(struct drbd_conf
27753 mdev->receiver.t_state);
27754
27755 /* no need to lock it, I'm the only thread alive */
27756 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
27757 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
27758 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
27759 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
27760 mdev->al_writ_cnt =
27761 mdev->bm_writ_cnt =
27762 mdev->read_cnt =
27763 diff -urNp linux-2.6.39.2/drivers/block/drbd/drbd_nl.c linux-2.6.39.2/drivers/block/drbd/drbd_nl.c
27764 --- linux-2.6.39.2/drivers/block/drbd/drbd_nl.c 2011-05-19 00:06:34.000000000 -0400
27765 +++ linux-2.6.39.2/drivers/block/drbd/drbd_nl.c 2011-05-22 19:36:31.000000000 -0400
27766 @@ -2298,7 +2298,7 @@ static void drbd_connector_callback(stru
27767 module_put(THIS_MODULE);
27768 }
27769
27770 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27771 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
27772
27773 static unsigned short *
27774 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
27775 @@ -2369,7 +2369,7 @@ void drbd_bcast_state(struct drbd_conf *
27776 cn_reply->id.idx = CN_IDX_DRBD;
27777 cn_reply->id.val = CN_VAL_DRBD;
27778
27779 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27780 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27781 cn_reply->ack = 0; /* not used here. */
27782 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27783 (int)((char *)tl - (char *)reply->tag_list);
27784 @@ -2401,7 +2401,7 @@ void drbd_bcast_ev_helper(struct drbd_co
27785 cn_reply->id.idx = CN_IDX_DRBD;
27786 cn_reply->id.val = CN_VAL_DRBD;
27787
27788 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27789 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27790 cn_reply->ack = 0; /* not used here. */
27791 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27792 (int)((char *)tl - (char *)reply->tag_list);
27793 @@ -2479,7 +2479,7 @@ void drbd_bcast_ee(struct drbd_conf *mde
27794 cn_reply->id.idx = CN_IDX_DRBD;
27795 cn_reply->id.val = CN_VAL_DRBD;
27796
27797 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
27798 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
27799 cn_reply->ack = 0; // not used here.
27800 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27801 (int)((char*)tl - (char*)reply->tag_list);
27802 @@ -2518,7 +2518,7 @@ void drbd_bcast_sync_progress(struct drb
27803 cn_reply->id.idx = CN_IDX_DRBD;
27804 cn_reply->id.val = CN_VAL_DRBD;
27805
27806 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
27807 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
27808 cn_reply->ack = 0; /* not used here. */
27809 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
27810 (int)((char *)tl - (char *)reply->tag_list);
27811 diff -urNp linux-2.6.39.2/drivers/block/drbd/drbd_receiver.c linux-2.6.39.2/drivers/block/drbd/drbd_receiver.c
27812 --- linux-2.6.39.2/drivers/block/drbd/drbd_receiver.c 2011-05-19 00:06:34.000000000 -0400
27813 +++ linux-2.6.39.2/drivers/block/drbd/drbd_receiver.c 2011-05-22 19:36:31.000000000 -0400
27814 @@ -894,7 +894,7 @@ retry:
27815 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
27816 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
27817
27818 - atomic_set(&mdev->packet_seq, 0);
27819 + atomic_set_unchecked(&mdev->packet_seq, 0);
27820 mdev->peer_seq = 0;
27821
27822 drbd_thread_start(&mdev->asender);
27823 @@ -990,7 +990,7 @@ static enum finish_epoch drbd_may_finish
27824 do {
27825 next_epoch = NULL;
27826
27827 - epoch_size = atomic_read(&epoch->epoch_size);
27828 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
27829
27830 switch (ev & ~EV_CLEANUP) {
27831 case EV_PUT:
27832 @@ -1025,7 +1025,7 @@ static enum finish_epoch drbd_may_finish
27833 rv = FE_DESTROYED;
27834 } else {
27835 epoch->flags = 0;
27836 - atomic_set(&epoch->epoch_size, 0);
27837 + atomic_set_unchecked(&epoch->epoch_size, 0);
27838 /* atomic_set(&epoch->active, 0); is already zero */
27839 if (rv == FE_STILL_LIVE)
27840 rv = FE_RECYCLED;
27841 @@ -1196,14 +1196,14 @@ static int receive_Barrier(struct drbd_c
27842 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
27843 drbd_flush(mdev);
27844
27845 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27846 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27847 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27848 if (epoch)
27849 break;
27850 }
27851
27852 epoch = mdev->current_epoch;
27853 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27854 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27855
27856 D_ASSERT(atomic_read(&epoch->active) == 0);
27857 D_ASSERT(epoch->flags == 0);
27858 @@ -1215,11 +1215,11 @@ static int receive_Barrier(struct drbd_c
27859 }
27860
27861 epoch->flags = 0;
27862 - atomic_set(&epoch->epoch_size, 0);
27863 + atomic_set_unchecked(&epoch->epoch_size, 0);
27864 atomic_set(&epoch->active, 0);
27865
27866 spin_lock(&mdev->epoch_lock);
27867 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27868 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27869 list_add(&epoch->list, &mdev->current_epoch->list);
27870 mdev->current_epoch = epoch;
27871 mdev->epochs++;
27872 @@ -1668,7 +1668,7 @@ static int receive_Data(struct drbd_conf
27873 spin_unlock(&mdev->peer_seq_lock);
27874
27875 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27876 - atomic_inc(&mdev->current_epoch->epoch_size);
27877 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27878 return drbd_drain_block(mdev, data_size);
27879 }
27880
27881 @@ -1694,7 +1694,7 @@ static int receive_Data(struct drbd_conf
27882
27883 spin_lock(&mdev->epoch_lock);
27884 e->epoch = mdev->current_epoch;
27885 - atomic_inc(&e->epoch->epoch_size);
27886 + atomic_inc_unchecked(&e->epoch->epoch_size);
27887 atomic_inc(&e->epoch->active);
27888 spin_unlock(&mdev->epoch_lock);
27889
27890 @@ -3905,7 +3905,7 @@ static void drbd_disconnect(struct drbd_
27891 D_ASSERT(list_empty(&mdev->done_ee));
27892
27893 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27894 - atomic_set(&mdev->current_epoch->epoch_size, 0);
27895 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27896 D_ASSERT(list_empty(&mdev->current_epoch->list));
27897 }
27898
27899 diff -urNp linux-2.6.39.2/drivers/block/nbd.c linux-2.6.39.2/drivers/block/nbd.c
27900 --- linux-2.6.39.2/drivers/block/nbd.c 2011-06-25 12:55:22.000000000 -0400
27901 +++ linux-2.6.39.2/drivers/block/nbd.c 2011-06-25 13:00:25.000000000 -0400
27902 @@ -157,6 +157,8 @@ static int sock_xmit(struct nbd_device *
27903 struct kvec iov;
27904 sigset_t blocked, oldset;
27905
27906 + pax_track_stack();
27907 +
27908 if (unlikely(!sock)) {
27909 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
27910 lo->disk->disk_name, (send ? "send" : "recv"));
27911 @@ -571,6 +573,8 @@ static void do_nbd_request(struct reques
27912 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
27913 unsigned int cmd, unsigned long arg)
27914 {
27915 + pax_track_stack();
27916 +
27917 switch (cmd) {
27918 case NBD_DISCONNECT: {
27919 struct request sreq;
27920 diff -urNp linux-2.6.39.2/drivers/block/smart1,2.h linux-2.6.39.2/drivers/block/smart1,2.h
27921 --- linux-2.6.39.2/drivers/block/smart1,2.h 2011-05-19 00:06:34.000000000 -0400
27922 +++ linux-2.6.39.2/drivers/block/smart1,2.h 2011-05-22 19:36:31.000000000 -0400
27923 @@ -107,7 +107,7 @@ static unsigned long smart4_intr_pending
27924 return 0 ;
27925 }
27926
27927 -static struct access_method smart4_access = {
27928 +static const struct access_method smart4_access = {
27929 smart4_submit_command,
27930 smart4_intr_mask,
27931 smart4_fifo_full,
27932 @@ -143,7 +143,7 @@ static unsigned long smart2_intr_pending
27933 return readl(h->vaddr + INTR_PENDING);
27934 }
27935
27936 -static struct access_method smart2_access = {
27937 +static const struct access_method smart2_access = {
27938 smart2_submit_command,
27939 smart2_intr_mask,
27940 smart2_fifo_full,
27941 @@ -179,7 +179,7 @@ static unsigned long smart2e_intr_pendin
27942 return inl(h->io_mem_addr + INTR_PENDING);
27943 }
27944
27945 -static struct access_method smart2e_access = {
27946 +static const struct access_method smart2e_access = {
27947 smart2e_submit_command,
27948 smart2e_intr_mask,
27949 smart2e_fifo_full,
27950 @@ -269,7 +269,7 @@ static unsigned long smart1_intr_pending
27951 return chan;
27952 }
27953
27954 -static struct access_method smart1_access = {
27955 +static const struct access_method smart1_access = {
27956 smart1_submit_command,
27957 smart1_intr_mask,
27958 smart1_fifo_full,
27959 diff -urNp linux-2.6.39.2/drivers/block/xsysace.c linux-2.6.39.2/drivers/block/xsysace.c
27960 --- linux-2.6.39.2/drivers/block/xsysace.c 2011-05-19 00:06:34.000000000 -0400
27961 +++ linux-2.6.39.2/drivers/block/xsysace.c 2011-05-22 19:36:31.000000000 -0400
27962 @@ -262,7 +262,7 @@ static void ace_dataout_8(struct ace_dev
27963 ace->data_ptr = src;
27964 }
27965
27966 -static struct ace_reg_ops ace_reg_8_ops = {
27967 +static const struct ace_reg_ops ace_reg_8_ops = {
27968 .in = ace_in_8,
27969 .out = ace_out_8,
27970 .datain = ace_datain_8,
27971 @@ -327,14 +327,14 @@ static void ace_dataout_le16(struct ace_
27972 ace->data_ptr = src;
27973 }
27974
27975 -static struct ace_reg_ops ace_reg_be16_ops = {
27976 +static const struct ace_reg_ops ace_reg_be16_ops = {
27977 .in = ace_in_be16,
27978 .out = ace_out_be16,
27979 .datain = ace_datain_be16,
27980 .dataout = ace_dataout_be16,
27981 };
27982
27983 -static struct ace_reg_ops ace_reg_le16_ops = {
27984 +static const struct ace_reg_ops ace_reg_le16_ops = {
27985 .in = ace_in_le16,
27986 .out = ace_out_le16,
27987 .datain = ace_datain_le16,
27988 diff -urNp linux-2.6.39.2/drivers/char/agp/frontend.c linux-2.6.39.2/drivers/char/agp/frontend.c
27989 --- linux-2.6.39.2/drivers/char/agp/frontend.c 2011-05-19 00:06:34.000000000 -0400
27990 +++ linux-2.6.39.2/drivers/char/agp/frontend.c 2011-05-22 19:36:31.000000000 -0400
27991 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct ag
27992 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27993 return -EFAULT;
27994
27995 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27996 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27997 return -EFAULT;
27998
27999 client = agp_find_client_by_pid(reserve.pid);
28000 diff -urNp linux-2.6.39.2/drivers/char/briq_panel.c linux-2.6.39.2/drivers/char/briq_panel.c
28001 --- linux-2.6.39.2/drivers/char/briq_panel.c 2011-05-19 00:06:34.000000000 -0400
28002 +++ linux-2.6.39.2/drivers/char/briq_panel.c 2011-05-22 19:41:32.000000000 -0400
28003 @@ -9,6 +9,7 @@
28004 #include <linux/types.h>
28005 #include <linux/errno.h>
28006 #include <linux/tty.h>
28007 +#include <linux/mutex.h>
28008 #include <linux/timer.h>
28009 #include <linux/kernel.h>
28010 #include <linux/wait.h>
28011 @@ -34,6 +35,7 @@ static int vfd_is_open;
28012 static unsigned char vfd[40];
28013 static int vfd_cursor;
28014 static unsigned char ledpb, led;
28015 +static DEFINE_MUTEX(vfd_mutex);
28016
28017 static void update_vfd(void)
28018 {
28019 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct f
28020 if (!vfd_is_open)
28021 return -EBUSY;
28022
28023 + mutex_lock(&vfd_mutex);
28024 for (;;) {
28025 char c;
28026 if (!indx)
28027 break;
28028 - if (get_user(c, buf))
28029 + if (get_user(c, buf)) {
28030 + mutex_unlock(&vfd_mutex);
28031 return -EFAULT;
28032 + }
28033 if (esc) {
28034 set_led(c);
28035 esc = 0;
28036 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct f
28037 buf++;
28038 }
28039 update_vfd();
28040 + mutex_unlock(&vfd_mutex);
28041
28042 return len;
28043 }
28044 diff -urNp linux-2.6.39.2/drivers/char/genrtc.c linux-2.6.39.2/drivers/char/genrtc.c
28045 --- linux-2.6.39.2/drivers/char/genrtc.c 2011-05-19 00:06:34.000000000 -0400
28046 +++ linux-2.6.39.2/drivers/char/genrtc.c 2011-05-22 19:41:32.000000000 -0400
28047 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *fi
28048 switch (cmd) {
28049
28050 case RTC_PLL_GET:
28051 + memset(&pll, 0, sizeof(pll));
28052 if (get_rtc_pll(&pll))
28053 return -EINVAL;
28054 else
28055 diff -urNp linux-2.6.39.2/drivers/char/hpet.c linux-2.6.39.2/drivers/char/hpet.c
28056 --- linux-2.6.39.2/drivers/char/hpet.c 2011-05-19 00:06:34.000000000 -0400
28057 +++ linux-2.6.39.2/drivers/char/hpet.c 2011-05-22 19:36:31.000000000 -0400
28058 @@ -553,7 +553,7 @@ static inline unsigned long hpet_time_di
28059 }
28060
28061 static int
28062 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
28063 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
28064 struct hpet_info *info)
28065 {
28066 struct hpet_timer __iomem *timer;
28067 diff -urNp linux-2.6.39.2/drivers/char/ipmi/ipmi_devintf.c linux-2.6.39.2/drivers/char/ipmi/ipmi_devintf.c
28068 --- linux-2.6.39.2/drivers/char/ipmi/ipmi_devintf.c 2011-05-19 00:06:34.000000000 -0400
28069 +++ linux-2.6.39.2/drivers/char/ipmi/ipmi_devintf.c 2011-05-22 19:36:31.000000000 -0400
28070 @@ -109,8 +109,7 @@ static int ipmi_fasync(int fd, struct fi
28071 return (result);
28072 }
28073
28074 -static struct ipmi_user_hndl ipmi_hndlrs =
28075 -{
28076 +static const struct ipmi_user_hndl ipmi_hndlrs = {
28077 .ipmi_recv_hndl = file_receive_handler,
28078 };
28079
28080 diff -urNp linux-2.6.39.2/drivers/char/ipmi/ipmi_msghandler.c linux-2.6.39.2/drivers/char/ipmi/ipmi_msghandler.c
28081 --- linux-2.6.39.2/drivers/char/ipmi/ipmi_msghandler.c 2011-05-19 00:06:34.000000000 -0400
28082 +++ linux-2.6.39.2/drivers/char/ipmi/ipmi_msghandler.c 2011-05-22 19:36:31.000000000 -0400
28083 @@ -82,7 +82,7 @@ struct ipmi_user {
28084 struct kref refcount;
28085
28086 /* The upper layer that handles receive messages. */
28087 - struct ipmi_user_hndl *handler;
28088 + const struct ipmi_user_hndl *handler;
28089 void *handler_data;
28090
28091 /* The interface this user is bound to. */
28092 @@ -414,7 +414,7 @@ struct ipmi_smi {
28093 struct proc_dir_entry *proc_dir;
28094 char proc_dir_name[10];
28095
28096 - atomic_t stats[IPMI_NUM_STATS];
28097 + atomic_unchecked_t stats[IPMI_NUM_STATS];
28098
28099 /*
28100 * run_to_completion duplicate of smb_info, smi_info
28101 @@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
28102
28103
28104 #define ipmi_inc_stat(intf, stat) \
28105 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
28106 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
28107 #define ipmi_get_stat(intf, stat) \
28108 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
28109 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
28110
28111 static int is_lan_addr(struct ipmi_addr *addr)
28112 {
28113 @@ -875,7 +875,7 @@ static int intf_err_seq(ipmi_smi_t int
28114
28115
28116 int ipmi_create_user(unsigned int if_num,
28117 - struct ipmi_user_hndl *handler,
28118 + const struct ipmi_user_hndl *handler,
28119 void *handler_data,
28120 ipmi_user_t *user)
28121 {
28122 @@ -2844,7 +2844,7 @@ int ipmi_register_smi(struct ipmi_smi_ha
28123 INIT_LIST_HEAD(&intf->cmd_rcvrs);
28124 init_waitqueue_head(&intf->waitq);
28125 for (i = 0; i < IPMI_NUM_STATS; i++)
28126 - atomic_set(&intf->stats[i], 0);
28127 + atomic_set_unchecked(&intf->stats[i], 0);
28128
28129 intf->proc_dir = NULL;
28130
28131 @@ -4196,6 +4196,8 @@ static void send_panic_events(char *str)
28132 struct ipmi_smi_msg smi_msg;
28133 struct ipmi_recv_msg recv_msg;
28134
28135 + pax_track_stack();
28136 +
28137 si = (struct ipmi_system_interface_addr *) &addr;
28138 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
28139 si->channel = IPMI_BMC_CHANNEL;
28140 diff -urNp linux-2.6.39.2/drivers/char/ipmi/ipmi_poweroff.c linux-2.6.39.2/drivers/char/ipmi/ipmi_poweroff.c
28141 --- linux-2.6.39.2/drivers/char/ipmi/ipmi_poweroff.c 2011-05-19 00:06:34.000000000 -0400
28142 +++ linux-2.6.39.2/drivers/char/ipmi/ipmi_poweroff.c 2011-05-22 19:36:31.000000000 -0400
28143 @@ -133,7 +133,7 @@ static void receive_handler(struct ipmi_
28144 complete(comp);
28145 }
28146
28147 -static struct ipmi_user_hndl ipmi_poweroff_handler = {
28148 +static const struct ipmi_user_hndl ipmi_poweroff_handler = {
28149 .ipmi_recv_hndl = receive_handler
28150 };
28151
28152 diff -urNp linux-2.6.39.2/drivers/char/ipmi/ipmi_si_intf.c linux-2.6.39.2/drivers/char/ipmi/ipmi_si_intf.c
28153 --- linux-2.6.39.2/drivers/char/ipmi/ipmi_si_intf.c 2011-05-19 00:06:34.000000000 -0400
28154 +++ linux-2.6.39.2/drivers/char/ipmi/ipmi_si_intf.c 2011-05-22 19:36:31.000000000 -0400
28155 @@ -276,7 +276,7 @@ struct smi_info {
28156 unsigned char slave_addr;
28157
28158 /* Counters and things for the proc filesystem. */
28159 - atomic_t stats[SI_NUM_STATS];
28160 + atomic_unchecked_t stats[SI_NUM_STATS];
28161
28162 struct task_struct *thread;
28163
28164 @@ -285,9 +285,9 @@ struct smi_info {
28165 };
28166
28167 #define smi_inc_stat(smi, stat) \
28168 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
28169 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
28170 #define smi_get_stat(smi, stat) \
28171 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
28172 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
28173
28174 #define SI_MAX_PARMS 4
28175
28176 @@ -3198,7 +3198,7 @@ static int try_smi_init(struct smi_info
28177 atomic_set(&new_smi->req_events, 0);
28178 new_smi->run_to_completion = 0;
28179 for (i = 0; i < SI_NUM_STATS; i++)
28180 - atomic_set(&new_smi->stats[i], 0);
28181 + atomic_set_unchecked(&new_smi->stats[i], 0);
28182
28183 new_smi->interrupt_disabled = 1;
28184 atomic_set(&new_smi->stop_operation, 0);
28185 diff -urNp linux-2.6.39.2/drivers/char/ipmi/ipmi_watchdog.c linux-2.6.39.2/drivers/char/ipmi/ipmi_watchdog.c
28186 --- linux-2.6.39.2/drivers/char/ipmi/ipmi_watchdog.c 2011-05-19 00:06:34.000000000 -0400
28187 +++ linux-2.6.39.2/drivers/char/ipmi/ipmi_watchdog.c 2011-05-22 19:36:31.000000000 -0400
28188 @@ -216,7 +216,7 @@ static int set_param_timeout(const char
28189 return rv;
28190 }
28191
28192 -static struct kernel_param_ops param_ops_timeout = {
28193 +static const struct kernel_param_ops param_ops_timeout = {
28194 .set = set_param_timeout,
28195 .get = param_get_int,
28196 };
28197 @@ -278,14 +278,14 @@ static int set_param_wdog_ifnum(const ch
28198 return 0;
28199 }
28200
28201 -static struct kernel_param_ops param_ops_wdog_ifnum = {
28202 +static const struct kernel_param_ops param_ops_wdog_ifnum = {
28203 .set = set_param_wdog_ifnum,
28204 .get = param_get_int,
28205 };
28206
28207 #define param_check_wdog_ifnum param_check_int
28208
28209 -static struct kernel_param_ops param_ops_str = {
28210 +static const struct kernel_param_ops param_ops_str = {
28211 .set = set_param_str,
28212 .get = get_param_str,
28213 };
28214 @@ -953,7 +953,7 @@ static void ipmi_wdog_pretimeout_handler
28215 pretimeout_since_last_heartbeat = 1;
28216 }
28217
28218 -static struct ipmi_user_hndl ipmi_hndlrs = {
28219 +static const struct ipmi_user_hndl ipmi_hndlrs = {
28220 .ipmi_recv_hndl = ipmi_wdog_msg_handler,
28221 .ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler
28222 };
28223 diff -urNp linux-2.6.39.2/drivers/char/Kconfig linux-2.6.39.2/drivers/char/Kconfig
28224 --- linux-2.6.39.2/drivers/char/Kconfig 2011-05-19 00:06:34.000000000 -0400
28225 +++ linux-2.6.39.2/drivers/char/Kconfig 2011-05-22 19:41:37.000000000 -0400
28226 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
28227
28228 config DEVKMEM
28229 bool "/dev/kmem virtual device support"
28230 - default y
28231 + default n
28232 + depends on !GRKERNSEC_KMEM
28233 help
28234 Say Y here if you want to support the /dev/kmem device. The
28235 /dev/kmem device is rarely used, but can be used for certain
28236 @@ -596,6 +597,7 @@ config DEVPORT
28237 bool
28238 depends on !M68K
28239 depends on ISA || PCI
28240 + depends on !GRKERNSEC_KMEM
28241 default y
28242
28243 source "drivers/s390/char/Kconfig"
28244 diff -urNp linux-2.6.39.2/drivers/char/mem.c linux-2.6.39.2/drivers/char/mem.c
28245 --- linux-2.6.39.2/drivers/char/mem.c 2011-05-19 00:06:34.000000000 -0400
28246 +++ linux-2.6.39.2/drivers/char/mem.c 2011-05-22 19:41:37.000000000 -0400
28247 @@ -18,6 +18,7 @@
28248 #include <linux/raw.h>
28249 #include <linux/tty.h>
28250 #include <linux/capability.h>
28251 +#include <linux/security.h>
28252 #include <linux/ptrace.h>
28253 #include <linux/device.h>
28254 #include <linux/highmem.h>
28255 @@ -34,6 +35,10 @@
28256 # include <linux/efi.h>
28257 #endif
28258
28259 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28260 +extern struct file_operations grsec_fops;
28261 +#endif
28262 +
28263 static inline unsigned long size_inside_page(unsigned long start,
28264 unsigned long size)
28265 {
28266 @@ -65,9 +70,13 @@ static inline int range_is_allowed(unsig
28267
28268 while (cursor < to) {
28269 if (!devmem_is_allowed(pfn)) {
28270 +#ifdef CONFIG_GRKERNSEC_KMEM
28271 + gr_handle_mem_readwrite(from, to);
28272 +#else
28273 printk(KERN_INFO
28274 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
28275 current->comm, from, to);
28276 +#endif
28277 return 0;
28278 }
28279 cursor += PAGE_SIZE;
28280 @@ -75,6 +84,11 @@ static inline int range_is_allowed(unsig
28281 }
28282 return 1;
28283 }
28284 +#elif defined(CONFIG_GRKERNSEC_KMEM)
28285 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28286 +{
28287 + return 0;
28288 +}
28289 #else
28290 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28291 {
28292 @@ -117,6 +131,7 @@ static ssize_t read_mem(struct file *fil
28293
28294 while (count > 0) {
28295 unsigned long remaining;
28296 + char *temp;
28297
28298 sz = size_inside_page(p, count);
28299
28300 @@ -132,7 +147,23 @@ static ssize_t read_mem(struct file *fil
28301 if (!ptr)
28302 return -EFAULT;
28303
28304 - remaining = copy_to_user(buf, ptr, sz);
28305 +#ifdef CONFIG_PAX_USERCOPY
28306 + temp = kmalloc(sz, GFP_KERNEL);
28307 + if (!temp) {
28308 + unxlate_dev_mem_ptr(p, ptr);
28309 + return -ENOMEM;
28310 + }
28311 + memcpy(temp, ptr, sz);
28312 +#else
28313 + temp = ptr;
28314 +#endif
28315 +
28316 + remaining = copy_to_user(buf, temp, sz);
28317 +
28318 +#ifdef CONFIG_PAX_USERCOPY
28319 + kfree(temp);
28320 +#endif
28321 +
28322 unxlate_dev_mem_ptr(p, ptr);
28323 if (remaining)
28324 return -EFAULT;
28325 @@ -395,9 +426,8 @@ static ssize_t read_kmem(struct file *fi
28326 size_t count, loff_t *ppos)
28327 {
28328 unsigned long p = *ppos;
28329 - ssize_t low_count, read, sz;
28330 + ssize_t low_count, read, sz, err = 0;
28331 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
28332 - int err = 0;
28333
28334 read = 0;
28335 if (p < (unsigned long) high_memory) {
28336 @@ -419,6 +449,8 @@ static ssize_t read_kmem(struct file *fi
28337 }
28338 #endif
28339 while (low_count > 0) {
28340 + char *temp;
28341 +
28342 sz = size_inside_page(p, low_count);
28343
28344 /*
28345 @@ -428,7 +460,22 @@ static ssize_t read_kmem(struct file *fi
28346 */
28347 kbuf = xlate_dev_kmem_ptr((char *)p);
28348
28349 - if (copy_to_user(buf, kbuf, sz))
28350 +#ifdef CONFIG_PAX_USERCOPY
28351 + temp = kmalloc(sz, GFP_KERNEL);
28352 + if (!temp)
28353 + return -ENOMEM;
28354 + memcpy(temp, kbuf, sz);
28355 +#else
28356 + temp = kbuf;
28357 +#endif
28358 +
28359 + err = copy_to_user(buf, temp, sz);
28360 +
28361 +#ifdef CONFIG_PAX_USERCOPY
28362 + kfree(temp);
28363 +#endif
28364 +
28365 + if (err)
28366 return -EFAULT;
28367 buf += sz;
28368 p += sz;
28369 @@ -854,6 +901,9 @@ static const struct memdev {
28370 #ifdef CONFIG_CRASH_DUMP
28371 [12] = { "oldmem", 0, &oldmem_fops, NULL },
28372 #endif
28373 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
28374 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
28375 +#endif
28376 };
28377
28378 static int memory_open(struct inode *inode, struct file *filp)
28379 diff -urNp linux-2.6.39.2/drivers/char/mmtimer.c linux-2.6.39.2/drivers/char/mmtimer.c
28380 --- linux-2.6.39.2/drivers/char/mmtimer.c 2011-05-19 00:06:34.000000000 -0400
28381 +++ linux-2.6.39.2/drivers/char/mmtimer.c 2011-05-22 19:36:31.000000000 -0400
28382 @@ -53,7 +53,7 @@ MODULE_LICENSE("GPL");
28383
28384 #define RTC_BITS 55 /* 55 bits for this implementation */
28385
28386 -static struct k_clock sgi_clock;
28387 +static const struct k_clock sgi_clock;
28388
28389 extern unsigned long sn_rtc_cycles_per_second;
28390
28391 @@ -772,7 +772,7 @@ static int sgi_clock_getres(const clocki
28392 return 0;
28393 }
28394
28395 -static struct k_clock sgi_clock = {
28396 +static const struct k_clock sgi_clock = {
28397 .clock_set = sgi_clock_set,
28398 .clock_get = sgi_clock_get,
28399 .clock_getres = sgi_clock_getres,
28400 diff -urNp linux-2.6.39.2/drivers/char/nvram.c linux-2.6.39.2/drivers/char/nvram.c
28401 --- linux-2.6.39.2/drivers/char/nvram.c 2011-05-19 00:06:34.000000000 -0400
28402 +++ linux-2.6.39.2/drivers/char/nvram.c 2011-05-22 19:36:31.000000000 -0400
28403 @@ -246,7 +246,7 @@ static ssize_t nvram_read(struct file *f
28404
28405 spin_unlock_irq(&rtc_lock);
28406
28407 - if (copy_to_user(buf, contents, tmp - contents))
28408 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
28409 return -EFAULT;
28410
28411 *ppos = i;
28412 diff -urNp linux-2.6.39.2/drivers/char/random.c linux-2.6.39.2/drivers/char/random.c
28413 --- linux-2.6.39.2/drivers/char/random.c 2011-05-19 00:06:34.000000000 -0400
28414 +++ linux-2.6.39.2/drivers/char/random.c 2011-05-22 19:41:37.000000000 -0400
28415 @@ -261,8 +261,13 @@
28416 /*
28417 * Configuration information
28418 */
28419 +#ifdef CONFIG_GRKERNSEC_RANDNET
28420 +#define INPUT_POOL_WORDS 512
28421 +#define OUTPUT_POOL_WORDS 128
28422 +#else
28423 #define INPUT_POOL_WORDS 128
28424 #define OUTPUT_POOL_WORDS 32
28425 +#endif
28426 #define SEC_XFER_SIZE 512
28427 #define EXTRACT_SIZE 10
28428
28429 @@ -300,10 +305,17 @@ static struct poolinfo {
28430 int poolwords;
28431 int tap1, tap2, tap3, tap4, tap5;
28432 } poolinfo_table[] = {
28433 +#ifdef CONFIG_GRKERNSEC_RANDNET
28434 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
28435 + { 512, 411, 308, 208, 104, 1 },
28436 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
28437 + { 128, 103, 76, 51, 25, 1 },
28438 +#else
28439 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
28440 { 128, 103, 76, 51, 25, 1 },
28441 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
28442 { 32, 26, 20, 14, 7, 1 },
28443 +#endif
28444 #if 0
28445 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
28446 { 2048, 1638, 1231, 819, 411, 1 },
28447 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(stru
28448
28449 extract_buf(r, tmp);
28450 i = min_t(int, nbytes, EXTRACT_SIZE);
28451 - if (copy_to_user(buf, tmp, i)) {
28452 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
28453 ret = -EFAULT;
28454 break;
28455 }
28456 @@ -1214,7 +1226,7 @@ EXPORT_SYMBOL(generate_random_uuid);
28457 #include <linux/sysctl.h>
28458
28459 static int min_read_thresh = 8, min_write_thresh;
28460 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
28461 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
28462 static int max_write_thresh = INPUT_POOL_WORDS * 32;
28463 static char sysctl_bootid[16];
28464
28465 diff -urNp linux-2.6.39.2/drivers/char/sonypi.c linux-2.6.39.2/drivers/char/sonypi.c
28466 --- linux-2.6.39.2/drivers/char/sonypi.c 2011-05-19 00:06:34.000000000 -0400
28467 +++ linux-2.6.39.2/drivers/char/sonypi.c 2011-05-22 19:36:31.000000000 -0400
28468 @@ -55,6 +55,7 @@
28469 #include <asm/uaccess.h>
28470 #include <asm/io.h>
28471 #include <asm/system.h>
28472 +#include <asm/local.h>
28473
28474 #include <linux/sonypi.h>
28475
28476 @@ -491,7 +492,7 @@ static struct sonypi_device {
28477 spinlock_t fifo_lock;
28478 wait_queue_head_t fifo_proc_list;
28479 struct fasync_struct *fifo_async;
28480 - int open_count;
28481 + local_t open_count;
28482 int model;
28483 struct input_dev *input_jog_dev;
28484 struct input_dev *input_key_dev;
28485 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, st
28486 static int sonypi_misc_release(struct inode *inode, struct file *file)
28487 {
28488 mutex_lock(&sonypi_device.lock);
28489 - sonypi_device.open_count--;
28490 + local_dec(&sonypi_device.open_count);
28491 mutex_unlock(&sonypi_device.lock);
28492 return 0;
28493 }
28494 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode
28495 {
28496 mutex_lock(&sonypi_device.lock);
28497 /* Flush input queue on first open */
28498 - if (!sonypi_device.open_count)
28499 + if (!local_read(&sonypi_device.open_count))
28500 kfifo_reset(&sonypi_device.fifo);
28501 - sonypi_device.open_count++;
28502 + local_inc(&sonypi_device.open_count);
28503 mutex_unlock(&sonypi_device.lock);
28504
28505 return 0;
28506 diff -urNp linux-2.6.39.2/drivers/char/tpm/tpm_bios.c linux-2.6.39.2/drivers/char/tpm/tpm_bios.c
28507 --- linux-2.6.39.2/drivers/char/tpm/tpm_bios.c 2011-05-19 00:06:34.000000000 -0400
28508 +++ linux-2.6.39.2/drivers/char/tpm/tpm_bios.c 2011-05-22 19:36:31.000000000 -0400
28509 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start
28510 event = addr;
28511
28512 if ((event->event_type == 0 && event->event_size == 0) ||
28513 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
28514 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
28515 return NULL;
28516
28517 return addr;
28518 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(
28519 return NULL;
28520
28521 if ((event->event_type == 0 && event->event_size == 0) ||
28522 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
28523 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
28524 return NULL;
28525
28526 (*pos)++;
28527 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_
28528 int i;
28529
28530 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
28531 - seq_putc(m, data[i]);
28532 + if (!seq_putc(m, data[i]))
28533 + return -EFAULT;
28534
28535 return 0;
28536 }
28537 @@ -410,6 +411,11 @@ static int read_log(struct tpm_bios_log
28538 log->bios_event_log_end = log->bios_event_log + len;
28539
28540 virt = acpi_os_map_memory(start, len);
28541 + if (!virt) {
28542 + kfree(log->bios_event_log);
28543 + log->bios_event_log = NULL;
28544 + return -EFAULT;
28545 + }
28546
28547 memcpy(log->bios_event_log, virt, len);
28548
28549 diff -urNp linux-2.6.39.2/drivers/char/tpm/tpm.c linux-2.6.39.2/drivers/char/tpm/tpm.c
28550 --- linux-2.6.39.2/drivers/char/tpm/tpm.c 2011-05-19 00:06:34.000000000 -0400
28551 +++ linux-2.6.39.2/drivers/char/tpm/tpm.c 2011-05-22 19:36:31.000000000 -0400
28552 @@ -411,7 +411,7 @@ static ssize_t tpm_transmit(struct tpm_c
28553 chip->vendor.req_complete_val)
28554 goto out_recv;
28555
28556 - if ((status == chip->vendor.req_canceled)) {
28557 + if (status == chip->vendor.req_canceled) {
28558 dev_err(chip->dev, "Operation Canceled\n");
28559 rc = -ECANCELED;
28560 goto out;
28561 @@ -844,6 +844,8 @@ ssize_t tpm_show_pubek(struct device *de
28562
28563 struct tpm_chip *chip = dev_get_drvdata(dev);
28564
28565 + pax_track_stack();
28566 +
28567 tpm_cmd.header.in = tpm_readpubek_header;
28568 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
28569 "attempting to read the PUBEK");
28570 diff -urNp linux-2.6.39.2/drivers/char/ttyprintk.c linux-2.6.39.2/drivers/char/ttyprintk.c
28571 --- linux-2.6.39.2/drivers/char/ttyprintk.c 2011-05-19 00:06:34.000000000 -0400
28572 +++ linux-2.6.39.2/drivers/char/ttyprintk.c 2011-05-22 19:36:31.000000000 -0400
28573 @@ -170,7 +170,7 @@ static const struct tty_operations ttypr
28574 .ioctl = tpk_ioctl,
28575 };
28576
28577 -struct tty_port_operations null_ops = { };
28578 +const struct tty_port_operations null_ops = { };
28579
28580 static struct tty_driver *ttyprintk_driver;
28581
28582 diff -urNp linux-2.6.39.2/drivers/char/xilinx_hwicap/xilinx_hwicap.c linux-2.6.39.2/drivers/char/xilinx_hwicap/xilinx_hwicap.c
28583 --- linux-2.6.39.2/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-19 00:06:34.000000000 -0400
28584 +++ linux-2.6.39.2/drivers/char/xilinx_hwicap/xilinx_hwicap.c 2011-05-22 19:36:31.000000000 -0400
28585 @@ -678,14 +678,14 @@ static int __devinit hwicap_setup(struct
28586 return retval;
28587 }
28588
28589 -static struct hwicap_driver_config buffer_icap_config = {
28590 +static const struct hwicap_driver_config buffer_icap_config = {
28591 .get_configuration = buffer_icap_get_configuration,
28592 .set_configuration = buffer_icap_set_configuration,
28593 .get_status = buffer_icap_get_status,
28594 .reset = buffer_icap_reset,
28595 };
28596
28597 -static struct hwicap_driver_config fifo_icap_config = {
28598 +static const struct hwicap_driver_config fifo_icap_config = {
28599 .get_configuration = fifo_icap_get_configuration,
28600 .set_configuration = fifo_icap_set_configuration,
28601 .get_status = fifo_icap_get_status,
28602 diff -urNp linux-2.6.39.2/drivers/crypto/hifn_795x.c linux-2.6.39.2/drivers/crypto/hifn_795x.c
28603 --- linux-2.6.39.2/drivers/crypto/hifn_795x.c 2011-05-19 00:06:34.000000000 -0400
28604 +++ linux-2.6.39.2/drivers/crypto/hifn_795x.c 2011-05-22 19:36:31.000000000 -0400
28605 @@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device
28606 0xCA, 0x34, 0x2B, 0x2E};
28607 struct scatterlist sg;
28608
28609 + pax_track_stack();
28610 +
28611 memset(src, 0, sizeof(src));
28612 memset(ctx.key, 0, sizeof(ctx.key));
28613
28614 diff -urNp linux-2.6.39.2/drivers/crypto/padlock-aes.c linux-2.6.39.2/drivers/crypto/padlock-aes.c
28615 --- linux-2.6.39.2/drivers/crypto/padlock-aes.c 2011-05-19 00:06:34.000000000 -0400
28616 +++ linux-2.6.39.2/drivers/crypto/padlock-aes.c 2011-05-22 19:36:31.000000000 -0400
28617 @@ -109,6 +109,8 @@ static int aes_set_key(struct crypto_tfm
28618 struct crypto_aes_ctx gen_aes;
28619 int cpu;
28620
28621 + pax_track_stack();
28622 +
28623 if (key_len % 8) {
28624 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
28625 return -EINVAL;
28626 diff -urNp linux-2.6.39.2/drivers/dca/dca-core.c linux-2.6.39.2/drivers/dca/dca-core.c
28627 --- linux-2.6.39.2/drivers/dca/dca-core.c 2011-05-19 00:06:34.000000000 -0400
28628 +++ linux-2.6.39.2/drivers/dca/dca-core.c 2011-05-22 19:36:31.000000000 -0400
28629 @@ -325,7 +325,7 @@ EXPORT_SYMBOL_GPL(dca_get_tag);
28630 * @ops - pointer to struct of dca operation function pointers
28631 * @priv_size - size of extra mem to be added for provider's needs
28632 */
28633 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
28634 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size)
28635 {
28636 struct dca_provider *dca;
28637 int alloc_size;
28638 diff -urNp linux-2.6.39.2/drivers/dma/ioat/dca.c linux-2.6.39.2/drivers/dma/ioat/dca.c
28639 --- linux-2.6.39.2/drivers/dma/ioat/dca.c 2011-05-19 00:06:34.000000000 -0400
28640 +++ linux-2.6.39.2/drivers/dma/ioat/dca.c 2011-05-22 19:36:31.000000000 -0400
28641 @@ -234,7 +234,7 @@ static int ioat_dca_dev_managed(struct d
28642 return 0;
28643 }
28644
28645 -static struct dca_ops ioat_dca_ops = {
28646 +static const struct dca_ops ioat_dca_ops = {
28647 .add_requester = ioat_dca_add_requester,
28648 .remove_requester = ioat_dca_remove_requester,
28649 .get_tag = ioat_dca_get_tag,
28650 @@ -384,7 +384,7 @@ static u8 ioat2_dca_get_tag(struct dca_p
28651 return tag;
28652 }
28653
28654 -static struct dca_ops ioat2_dca_ops = {
28655 +static const struct dca_ops ioat2_dca_ops = {
28656 .add_requester = ioat2_dca_add_requester,
28657 .remove_requester = ioat2_dca_remove_requester,
28658 .get_tag = ioat2_dca_get_tag,
28659 @@ -579,7 +579,7 @@ static u8 ioat3_dca_get_tag(struct dca_p
28660 return tag;
28661 }
28662
28663 -static struct dca_ops ioat3_dca_ops = {
28664 +static const struct dca_ops ioat3_dca_ops = {
28665 .add_requester = ioat3_dca_add_requester,
28666 .remove_requester = ioat3_dca_remove_requester,
28667 .get_tag = ioat3_dca_get_tag,
28668 diff -urNp linux-2.6.39.2/drivers/edac/amd64_edac.h linux-2.6.39.2/drivers/edac/amd64_edac.h
28669 --- linux-2.6.39.2/drivers/edac/amd64_edac.h 2011-05-19 00:06:34.000000000 -0400
28670 +++ linux-2.6.39.2/drivers/edac/amd64_edac.h 2011-05-22 19:36:31.000000000 -0400
28671 @@ -333,7 +333,7 @@ struct chip_select {
28672 };
28673
28674 struct amd64_pvt {
28675 - struct low_ops *ops;
28676 + const struct low_ops *ops;
28677
28678 /* pci_device handles which we utilize */
28679 struct pci_dev *F1, *F2, *F3;
28680 @@ -443,7 +443,7 @@ struct low_ops {
28681 struct amd64_family_type {
28682 const char *ctl_name;
28683 u16 f1_id, f3_id;
28684 - struct low_ops ops;
28685 + const struct low_ops ops;
28686 };
28687
28688 int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset,
28689 diff -urNp linux-2.6.39.2/drivers/edac/edac_mc_sysfs.c linux-2.6.39.2/drivers/edac/edac_mc_sysfs.c
28690 --- linux-2.6.39.2/drivers/edac/edac_mc_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28691 +++ linux-2.6.39.2/drivers/edac/edac_mc_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28692 @@ -760,7 +760,7 @@ static void edac_inst_grp_release(struct
28693 }
28694
28695 /* Intermediate show/store table */
28696 -static struct sysfs_ops inst_grp_ops = {
28697 +static const struct sysfs_ops inst_grp_ops = {
28698 .show = inst_grp_show,
28699 .store = inst_grp_store
28700 };
28701 diff -urNp linux-2.6.39.2/drivers/edac/edac_pci_sysfs.c linux-2.6.39.2/drivers/edac/edac_pci_sysfs.c
28702 --- linux-2.6.39.2/drivers/edac/edac_pci_sysfs.c 2011-05-19 00:06:34.000000000 -0400
28703 +++ linux-2.6.39.2/drivers/edac/edac_pci_sysfs.c 2011-05-22 19:36:31.000000000 -0400
28704 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log
28705 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
28706 static int edac_pci_poll_msec = 1000; /* one second workq period */
28707
28708 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
28709 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
28710 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
28711 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
28712
28713 static struct kobject *edac_pci_top_main_kobj;
28714 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
28715 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(str
28716 edac_printk(KERN_CRIT, EDAC_PCI,
28717 "Signaled System Error on %s\n",
28718 pci_name(dev));
28719 - atomic_inc(&pci_nonparity_count);
28720 + atomic_inc_unchecked(&pci_nonparity_count);
28721 }
28722
28723 if (status & (PCI_STATUS_PARITY)) {
28724 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(str
28725 "Master Data Parity Error on %s\n",
28726 pci_name(dev));
28727
28728 - atomic_inc(&pci_parity_count);
28729 + atomic_inc_unchecked(&pci_parity_count);
28730 }
28731
28732 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28733 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(str
28734 "Detected Parity Error on %s\n",
28735 pci_name(dev));
28736
28737 - atomic_inc(&pci_parity_count);
28738 + atomic_inc_unchecked(&pci_parity_count);
28739 }
28740 }
28741
28742 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(str
28743 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
28744 "Signaled System Error on %s\n",
28745 pci_name(dev));
28746 - atomic_inc(&pci_nonparity_count);
28747 + atomic_inc_unchecked(&pci_nonparity_count);
28748 }
28749
28750 if (status & (PCI_STATUS_PARITY)) {
28751 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(str
28752 "Master Data Parity Error on "
28753 "%s\n", pci_name(dev));
28754
28755 - atomic_inc(&pci_parity_count);
28756 + atomic_inc_unchecked(&pci_parity_count);
28757 }
28758
28759 if (status & (PCI_STATUS_DETECTED_PARITY)) {
28760 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(str
28761 "Detected Parity Error on %s\n",
28762 pci_name(dev));
28763
28764 - atomic_inc(&pci_parity_count);
28765 + atomic_inc_unchecked(&pci_parity_count);
28766 }
28767 }
28768 }
28769 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
28770 if (!check_pci_errors)
28771 return;
28772
28773 - before_count = atomic_read(&pci_parity_count);
28774 + before_count = atomic_read_unchecked(&pci_parity_count);
28775
28776 /* scan all PCI devices looking for a Parity Error on devices and
28777 * bridges.
28778 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
28779 /* Only if operator has selected panic on PCI Error */
28780 if (edac_pci_get_panic_on_pe()) {
28781 /* If the count is different 'after' from 'before' */
28782 - if (before_count != atomic_read(&pci_parity_count))
28783 + if (before_count != atomic_read_unchecked(&pci_parity_count))
28784 panic("EDAC: PCI Parity Error");
28785 }
28786 }
28787 diff -urNp linux-2.6.39.2/drivers/firewire/core-cdev.c linux-2.6.39.2/drivers/firewire/core-cdev.c
28788 --- linux-2.6.39.2/drivers/firewire/core-cdev.c 2011-05-19 00:06:34.000000000 -0400
28789 +++ linux-2.6.39.2/drivers/firewire/core-cdev.c 2011-05-22 19:36:31.000000000 -0400
28790 @@ -1312,8 +1312,7 @@ static int init_iso_resource(struct clie
28791 int ret;
28792
28793 if ((request->channels == 0 && request->bandwidth == 0) ||
28794 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
28795 - request->bandwidth < 0)
28796 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
28797 return -EINVAL;
28798
28799 r = kmalloc(sizeof(*r), GFP_KERNEL);
28800 diff -urNp linux-2.6.39.2/drivers/firewire/core-transaction.c linux-2.6.39.2/drivers/firewire/core-transaction.c
28801 --- linux-2.6.39.2/drivers/firewire/core-transaction.c 2011-05-19 00:06:34.000000000 -0400
28802 +++ linux-2.6.39.2/drivers/firewire/core-transaction.c 2011-05-22 19:36:31.000000000 -0400
28803 @@ -36,6 +36,7 @@
28804 #include <linux/string.h>
28805 #include <linux/timer.h>
28806 #include <linux/types.h>
28807 +#include <linux/sched.h>
28808
28809 #include <asm/byteorder.h>
28810
28811 @@ -420,6 +421,8 @@ int fw_run_transaction(struct fw_card *c
28812 struct transaction_callback_data d;
28813 struct fw_transaction t;
28814
28815 + pax_track_stack();
28816 +
28817 init_timer_on_stack(&t.split_timeout_timer);
28818 init_completion(&d.done);
28819 d.payload = payload;
28820 diff -urNp linux-2.6.39.2/drivers/firmware/dmi_scan.c linux-2.6.39.2/drivers/firmware/dmi_scan.c
28821 --- linux-2.6.39.2/drivers/firmware/dmi_scan.c 2011-05-19 00:06:34.000000000 -0400
28822 +++ linux-2.6.39.2/drivers/firmware/dmi_scan.c 2011-05-22 19:36:31.000000000 -0400
28823 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
28824 }
28825 }
28826 else {
28827 - /*
28828 - * no iounmap() for that ioremap(); it would be a no-op, but
28829 - * it's so early in setup that sucker gets confused into doing
28830 - * what it shouldn't if we actually call it.
28831 - */
28832 p = dmi_ioremap(0xF0000, 0x10000);
28833 if (p == NULL)
28834 goto error;
28835 diff -urNp linux-2.6.39.2/drivers/gpio/vr41xx_giu.c linux-2.6.39.2/drivers/gpio/vr41xx_giu.c
28836 --- linux-2.6.39.2/drivers/gpio/vr41xx_giu.c 2011-05-19 00:06:34.000000000 -0400
28837 +++ linux-2.6.39.2/drivers/gpio/vr41xx_giu.c 2011-05-22 19:36:31.000000000 -0400
28838 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28839 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28840 maskl, pendl, maskh, pendh);
28841
28842 - atomic_inc(&irq_err_count);
28843 + atomic_inc_unchecked(&irq_err_count);
28844
28845 return -EINVAL;
28846 }
28847 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_crtc_helper.c linux-2.6.39.2/drivers/gpu/drm/drm_crtc_helper.c
28848 --- linux-2.6.39.2/drivers/gpu/drm/drm_crtc_helper.c 2011-05-19 00:06:34.000000000 -0400
28849 +++ linux-2.6.39.2/drivers/gpu/drm/drm_crtc_helper.c 2011-05-22 19:36:31.000000000 -0400
28850 @@ -276,7 +276,7 @@ static bool drm_encoder_crtc_ok(struct d
28851 struct drm_crtc *tmp;
28852 int crtc_mask = 1;
28853
28854 - WARN(!crtc, "checking null crtc?\n");
28855 + BUG_ON(!crtc);
28856
28857 dev = crtc->dev;
28858
28859 @@ -343,6 +343,8 @@ bool drm_crtc_helper_set_mode(struct drm
28860 struct drm_encoder *encoder;
28861 bool ret = true;
28862
28863 + pax_track_stack();
28864 +
28865 crtc->enabled = drm_helper_crtc_in_use(crtc);
28866 if (!crtc->enabled)
28867 return true;
28868 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_drv.c linux-2.6.39.2/drivers/gpu/drm/drm_drv.c
28869 --- linux-2.6.39.2/drivers/gpu/drm/drm_drv.c 2011-05-19 00:06:34.000000000 -0400
28870 +++ linux-2.6.39.2/drivers/gpu/drm/drm_drv.c 2011-05-22 19:36:31.000000000 -0400
28871 @@ -386,7 +386,7 @@ long drm_ioctl(struct file *filp,
28872
28873 dev = file_priv->minor->dev;
28874 atomic_inc(&dev->ioctl_count);
28875 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28876 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28877 ++file_priv->ioctl_count;
28878
28879 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28880 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_fops.c linux-2.6.39.2/drivers/gpu/drm/drm_fops.c
28881 --- linux-2.6.39.2/drivers/gpu/drm/drm_fops.c 2011-05-19 00:06:34.000000000 -0400
28882 +++ linux-2.6.39.2/drivers/gpu/drm/drm_fops.c 2011-05-22 19:36:31.000000000 -0400
28883 @@ -70,7 +70,7 @@ static int drm_setup(struct drm_device *
28884 }
28885
28886 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28887 - atomic_set(&dev->counts[i], 0);
28888 + atomic_set_unchecked(&dev->counts[i], 0);
28889
28890 dev->sigdata.lock = NULL;
28891
28892 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct
28893
28894 retcode = drm_open_helper(inode, filp, dev);
28895 if (!retcode) {
28896 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28897 - if (!dev->open_count++)
28898 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28899 + if (local_inc_return(&dev->open_count) == 1)
28900 retcode = drm_setup(dev);
28901 }
28902 if (!retcode) {
28903 @@ -472,7 +472,7 @@ int drm_release(struct inode *inode, str
28904
28905 mutex_lock(&drm_global_mutex);
28906
28907 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28908 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28909
28910 if (dev->driver->preclose)
28911 dev->driver->preclose(dev, file_priv);
28912 @@ -484,7 +484,7 @@ int drm_release(struct inode *inode, str
28913 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28914 task_pid_nr(current),
28915 (long)old_encode_dev(file_priv->minor->device),
28916 - dev->open_count);
28917 + local_read(&dev->open_count));
28918
28919 /* if the master has gone away we can't do anything with the lock */
28920 if (file_priv->minor->master)
28921 @@ -565,8 +565,8 @@ int drm_release(struct inode *inode, str
28922 * End inline drm_release
28923 */
28924
28925 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28926 - if (!--dev->open_count) {
28927 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28928 + if (local_dec_and_test(&dev->open_count)) {
28929 if (atomic_read(&dev->ioctl_count)) {
28930 DRM_ERROR("Device busy: %d\n",
28931 atomic_read(&dev->ioctl_count));
28932 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_global.c linux-2.6.39.2/drivers/gpu/drm/drm_global.c
28933 --- linux-2.6.39.2/drivers/gpu/drm/drm_global.c 2011-05-19 00:06:34.000000000 -0400
28934 +++ linux-2.6.39.2/drivers/gpu/drm/drm_global.c 2011-05-22 19:36:31.000000000 -0400
28935 @@ -36,7 +36,7 @@
28936 struct drm_global_item {
28937 struct mutex mutex;
28938 void *object;
28939 - int refcount;
28940 + atomic_t refcount;
28941 };
28942
28943 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28944 @@ -49,7 +49,7 @@ void drm_global_init(void)
28945 struct drm_global_item *item = &glob[i];
28946 mutex_init(&item->mutex);
28947 item->object = NULL;
28948 - item->refcount = 0;
28949 + atomic_set(&item->refcount, 0);
28950 }
28951 }
28952
28953 @@ -59,7 +59,7 @@ void drm_global_release(void)
28954 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28955 struct drm_global_item *item = &glob[i];
28956 BUG_ON(item->object != NULL);
28957 - BUG_ON(item->refcount != 0);
28958 + BUG_ON(atomic_read(&item->refcount) != 0);
28959 }
28960 }
28961
28962 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_globa
28963 void *object;
28964
28965 mutex_lock(&item->mutex);
28966 - if (item->refcount == 0) {
28967 + if (atomic_read(&item->refcount) == 0) {
28968 item->object = kzalloc(ref->size, GFP_KERNEL);
28969 if (unlikely(item->object == NULL)) {
28970 ret = -ENOMEM;
28971 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_globa
28972 goto out_err;
28973
28974 }
28975 - ++item->refcount;
28976 + atomic_inc(&item->refcount);
28977 ref->object = item->object;
28978 object = item->object;
28979 mutex_unlock(&item->mutex);
28980 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_gl
28981 struct drm_global_item *item = &glob[ref->global_type];
28982
28983 mutex_lock(&item->mutex);
28984 - BUG_ON(item->refcount == 0);
28985 + BUG_ON(atomic_read(&item->refcount) == 0);
28986 BUG_ON(ref->object != item->object);
28987 - if (--item->refcount == 0) {
28988 + if (atomic_dec_and_test(&item->refcount)) {
28989 ref->release(ref);
28990 item->object = NULL;
28991 }
28992 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_info.c linux-2.6.39.2/drivers/gpu/drm/drm_info.c
28993 --- linux-2.6.39.2/drivers/gpu/drm/drm_info.c 2011-05-19 00:06:34.000000000 -0400
28994 +++ linux-2.6.39.2/drivers/gpu/drm/drm_info.c 2011-05-22 19:41:37.000000000 -0400
28995 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void
28996 struct drm_local_map *map;
28997 struct drm_map_list *r_list;
28998
28999 - /* Hardcoded from _DRM_FRAME_BUFFER,
29000 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
29001 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
29002 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
29003 + static const char * const types[] = {
29004 + [_DRM_FRAME_BUFFER] = "FB",
29005 + [_DRM_REGISTERS] = "REG",
29006 + [_DRM_SHM] = "SHM",
29007 + [_DRM_AGP] = "AGP",
29008 + [_DRM_SCATTER_GATHER] = "SG",
29009 + [_DRM_CONSISTENT] = "PCI",
29010 + [_DRM_GEM] = "GEM" };
29011 const char *type;
29012 int i;
29013
29014 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void
29015 map = r_list->map;
29016 if (!map)
29017 continue;
29018 - if (map->type < 0 || map->type > 5)
29019 + if (map->type >= ARRAY_SIZE(types))
29020 type = "??";
29021 else
29022 type = types[map->type];
29023 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, voi
29024 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
29025 vma->vm_flags & VM_LOCKED ? 'l' : '-',
29026 vma->vm_flags & VM_IO ? 'i' : '-',
29027 +#ifdef CONFIG_GRKERNSEC_HIDESYM
29028 + 0);
29029 +#else
29030 vma->vm_pgoff);
29031 +#endif
29032
29033 #if defined(__i386__)
29034 pgprot = pgprot_val(vma->vm_page_prot);
29035 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_ioctl.c linux-2.6.39.2/drivers/gpu/drm/drm_ioctl.c
29036 --- linux-2.6.39.2/drivers/gpu/drm/drm_ioctl.c 2011-05-19 00:06:34.000000000 -0400
29037 +++ linux-2.6.39.2/drivers/gpu/drm/drm_ioctl.c 2011-05-22 19:36:31.000000000 -0400
29038 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev,
29039 stats->data[i].value =
29040 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
29041 else
29042 - stats->data[i].value = atomic_read(&dev->counts[i]);
29043 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
29044 stats->data[i].type = dev->types[i];
29045 }
29046
29047 diff -urNp linux-2.6.39.2/drivers/gpu/drm/drm_lock.c linux-2.6.39.2/drivers/gpu/drm/drm_lock.c
29048 --- linux-2.6.39.2/drivers/gpu/drm/drm_lock.c 2011-05-19 00:06:34.000000000 -0400
29049 +++ linux-2.6.39.2/drivers/gpu/drm/drm_lock.c 2011-05-22 19:36:31.000000000 -0400
29050 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, voi
29051 if (drm_lock_take(&master->lock, lock->context)) {
29052 master->lock.file_priv = file_priv;
29053 master->lock.lock_time = jiffies;
29054 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
29055 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
29056 break; /* Got lock */
29057 }
29058
29059 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, v
29060 return -EINVAL;
29061 }
29062
29063 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
29064 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
29065
29066 if (drm_lock_free(&master->lock, lock->context)) {
29067 /* FIXME: Should really bail out here. */
29068 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i810/i810_dma.c linux-2.6.39.2/drivers/gpu/drm/i810/i810_dma.c
29069 --- linux-2.6.39.2/drivers/gpu/drm/i810/i810_dma.c 2011-05-19 00:06:34.000000000 -0400
29070 +++ linux-2.6.39.2/drivers/gpu/drm/i810/i810_dma.c 2011-05-22 19:36:31.000000000 -0400
29071 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_de
29072 dma->buflist[vertex->idx],
29073 vertex->discard, vertex->used);
29074
29075 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29076 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29077 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
29078 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29079 sarea_priv->last_enqueue = dev_priv->counter - 1;
29080 sarea_priv->last_dispatch = (int)hw_status[5];
29081
29082 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device
29083 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
29084 mc->last_render);
29085
29086 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29087 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
29088 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
29089 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
29090 sarea_priv->last_enqueue = dev_priv->counter - 1;
29091 sarea_priv->last_dispatch = (int)hw_status[5];
29092
29093 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i810/i810_drv.h linux-2.6.39.2/drivers/gpu/drm/i810/i810_drv.h
29094 --- linux-2.6.39.2/drivers/gpu/drm/i810/i810_drv.h 2011-05-19 00:06:34.000000000 -0400
29095 +++ linux-2.6.39.2/drivers/gpu/drm/i810/i810_drv.h 2011-05-22 19:36:31.000000000 -0400
29096 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
29097 int page_flipping;
29098
29099 wait_queue_head_t irq_queue;
29100 - atomic_t irq_received;
29101 - atomic_t irq_emitted;
29102 + atomic_unchecked_t irq_received;
29103 + atomic_unchecked_t irq_emitted;
29104
29105 int front_offset;
29106 } drm_i810_private_t;
29107 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7017.c linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7017.c
29108 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-19 00:06:34.000000000 -0400
29109 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7017.c 2011-05-22 19:36:31.000000000 -0400
29110 @@ -390,7 +390,7 @@ static void ch7017_destroy(struct intel_
29111 }
29112 }
29113
29114 -struct intel_dvo_dev_ops ch7017_ops = {
29115 +const struct intel_dvo_dev_ops ch7017_ops = {
29116 .init = ch7017_init,
29117 .detect = ch7017_detect,
29118 .mode_valid = ch7017_mode_valid,
29119 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7xxx.c linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7xxx.c
29120 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-19 00:06:34.000000000 -0400
29121 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ch7xxx.c 2011-05-22 19:36:31.000000000 -0400
29122 @@ -320,7 +320,7 @@ static void ch7xxx_destroy(struct intel_
29123 }
29124 }
29125
29126 -struct intel_dvo_dev_ops ch7xxx_ops = {
29127 +const struct intel_dvo_dev_ops ch7xxx_ops = {
29128 .init = ch7xxx_init,
29129 .detect = ch7xxx_detect,
29130 .mode_valid = ch7xxx_mode_valid,
29131 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo.h linux-2.6.39.2/drivers/gpu/drm/i915/dvo.h
29132 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo.h 2011-05-19 00:06:34.000000000 -0400
29133 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo.h 2011-05-22 19:36:31.000000000 -0400
29134 @@ -122,23 +122,23 @@ struct intel_dvo_dev_ops {
29135 *
29136 * \return singly-linked list of modes or NULL if no modes found.
29137 */
29138 - struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
29139 + struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
29140
29141 /**
29142 * Clean up driver-specific bits of the output
29143 */
29144 - void (*destroy) (struct intel_dvo_device *dvo);
29145 + void (* const destroy) (struct intel_dvo_device *dvo);
29146
29147 /**
29148 * Debugging hook to dump device registers to log file
29149 */
29150 - void (*dump_regs)(struct intel_dvo_device *dvo);
29151 + void (* const dump_regs)(struct intel_dvo_device *dvo);
29152 };
29153
29154 -extern struct intel_dvo_dev_ops sil164_ops;
29155 -extern struct intel_dvo_dev_ops ch7xxx_ops;
29156 -extern struct intel_dvo_dev_ops ivch_ops;
29157 -extern struct intel_dvo_dev_ops tfp410_ops;
29158 -extern struct intel_dvo_dev_ops ch7017_ops;
29159 +extern const struct intel_dvo_dev_ops sil164_ops;
29160 +extern const struct intel_dvo_dev_ops ch7xxx_ops;
29161 +extern const struct intel_dvo_dev_ops ivch_ops;
29162 +extern const struct intel_dvo_dev_ops tfp410_ops;
29163 +extern const struct intel_dvo_dev_ops ch7017_ops;
29164
29165 #endif /* _INTEL_DVO_H */
29166 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ivch.c linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ivch.c
29167 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-19 00:06:34.000000000 -0400
29168 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo_ivch.c 2011-05-22 19:36:31.000000000 -0400
29169 @@ -410,7 +410,7 @@ static void ivch_destroy(struct intel_dv
29170 }
29171 }
29172
29173 -struct intel_dvo_dev_ops ivch_ops= {
29174 +const struct intel_dvo_dev_ops ivch_ops= {
29175 .init = ivch_init,
29176 .dpms = ivch_dpms,
29177 .mode_valid = ivch_mode_valid,
29178 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo_sil164.c linux-2.6.39.2/drivers/gpu/drm/i915/dvo_sil164.c
29179 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-19 00:06:34.000000000 -0400
29180 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo_sil164.c 2011-05-22 19:36:31.000000000 -0400
29181 @@ -252,7 +252,7 @@ static void sil164_destroy(struct intel_
29182 }
29183 }
29184
29185 -struct intel_dvo_dev_ops sil164_ops = {
29186 +const struct intel_dvo_dev_ops sil164_ops = {
29187 .init = sil164_init,
29188 .detect = sil164_detect,
29189 .mode_valid = sil164_mode_valid,
29190 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/dvo_tfp410.c linux-2.6.39.2/drivers/gpu/drm/i915/dvo_tfp410.c
29191 --- linux-2.6.39.2/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-19 00:06:34.000000000 -0400
29192 +++ linux-2.6.39.2/drivers/gpu/drm/i915/dvo_tfp410.c 2011-05-22 19:36:31.000000000 -0400
29193 @@ -293,7 +293,7 @@ static void tfp410_destroy(struct intel_
29194 }
29195 }
29196
29197 -struct intel_dvo_dev_ops tfp410_ops = {
29198 +const struct intel_dvo_dev_ops tfp410_ops = {
29199 .init = tfp410_init,
29200 .detect = tfp410_detect,
29201 .mode_valid = tfp410_mode_valid,
29202 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_debugfs.c linux-2.6.39.2/drivers/gpu/drm/i915/i915_debugfs.c
29203 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-19 00:06:34.000000000 -0400
29204 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_debugfs.c 2011-05-22 19:36:31.000000000 -0400
29205 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct se
29206 I915_READ(GTIMR));
29207 }
29208 seq_printf(m, "Interrupts received: %d\n",
29209 - atomic_read(&dev_priv->irq_received));
29210 + atomic_read_unchecked(&dev_priv->irq_received));
29211 for (i = 0; i < I915_NUM_RINGS; i++) {
29212 if (IS_GEN6(dev)) {
29213 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
29214 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_dma.c linux-2.6.39.2/drivers/gpu/drm/i915/i915_dma.c
29215 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_dma.c 2011-05-19 00:06:34.000000000 -0400
29216 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_dma.c 2011-05-22 19:36:31.000000000 -0400
29217 @@ -1171,7 +1171,7 @@ static bool i915_switcheroo_can_switch(s
29218 bool can_switch;
29219
29220 spin_lock(&dev->count_lock);
29221 - can_switch = (dev->open_count == 0);
29222 + can_switch = (local_read(&dev->open_count) == 0);
29223 spin_unlock(&dev->count_lock);
29224 return can_switch;
29225 }
29226 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.c linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.c
29227 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.c 2011-05-19 00:06:34.000000000 -0400
29228 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.c 2011-05-22 19:36:31.000000000 -0400
29229 @@ -679,7 +679,7 @@ static const struct dev_pm_ops i915_pm_o
29230 .restore = i915_pm_resume,
29231 };
29232
29233 -static struct vm_operations_struct i915_gem_vm_ops = {
29234 +static const struct vm_operations_struct i915_gem_vm_ops = {
29235 .fault = i915_gem_fault,
29236 .open = drm_gem_vm_open,
29237 .close = drm_gem_vm_close,
29238 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.h linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.h
29239 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.h 2011-05-19 00:06:34.000000000 -0400
29240 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_drv.h 2011-05-22 19:36:31.000000000 -0400
29241 @@ -287,7 +287,7 @@ typedef struct drm_i915_private {
29242 int current_page;
29243 int page_flipping;
29244
29245 - atomic_t irq_received;
29246 + atomic_unchecked_t irq_received;
29247
29248 /* protects the irq masks */
29249 spinlock_t irq_lock;
29250 @@ -848,7 +848,7 @@ struct drm_i915_gem_object {
29251 * will be page flipped away on the next vblank. When it
29252 * reaches 0, dev_priv->pending_flip_queue will be woken up.
29253 */
29254 - atomic_t pending_flip;
29255 + atomic_unchecked_t pending_flip;
29256 };
29257
29258 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
29259 @@ -1232,7 +1232,7 @@ extern int intel_setup_gmbus(struct drm_
29260 extern void intel_teardown_gmbus(struct drm_device *dev);
29261 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
29262 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
29263 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29264 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
29265 {
29266 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
29267 }
29268 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-2.6.39.2/drivers/gpu/drm/i915/i915_gem_execbuffer.c
29269 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-19 00:06:34.000000000 -0400
29270 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2011-05-22 19:36:31.000000000 -0400
29271 @@ -192,7 +192,7 @@ i915_gem_object_set_to_gpu_domain(struct
29272 i915_gem_release_mmap(obj);
29273
29274 if (obj->base.pending_write_domain)
29275 - cd->flips |= atomic_read(&obj->pending_flip);
29276 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
29277
29278 /* The actual obj->write_domain will be updated with
29279 * pending_write_domain after we emit the accumulated flush for all
29280 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/i915_irq.c linux-2.6.39.2/drivers/gpu/drm/i915/i915_irq.c
29281 --- linux-2.6.39.2/drivers/gpu/drm/i915/i915_irq.c 2011-05-19 00:06:34.000000000 -0400
29282 +++ linux-2.6.39.2/drivers/gpu/drm/i915/i915_irq.c 2011-05-22 19:36:31.000000000 -0400
29283 @@ -1101,7 +1101,7 @@ irqreturn_t i915_driver_irq_handler(DRM_
29284 int ret = IRQ_NONE, pipe;
29285 bool blc_event = false;
29286
29287 - atomic_inc(&dev_priv->irq_received);
29288 + atomic_inc_unchecked(&dev_priv->irq_received);
29289
29290 if (HAS_PCH_SPLIT(dev))
29291 return ironlake_irq_handler(dev);
29292 @@ -1655,7 +1655,7 @@ void i915_driver_irq_preinstall(struct d
29293 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
29294 int pipe;
29295
29296 - atomic_set(&dev_priv->irq_received, 0);
29297 + atomic_set_unchecked(&dev_priv->irq_received, 0);
29298
29299 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
29300 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
29301 diff -urNp linux-2.6.39.2/drivers/gpu/drm/i915/intel_display.c linux-2.6.39.2/drivers/gpu/drm/i915/intel_display.c
29302 --- linux-2.6.39.2/drivers/gpu/drm/i915/intel_display.c 2011-05-19 00:06:34.000000000 -0400
29303 +++ linux-2.6.39.2/drivers/gpu/drm/i915/intel_display.c 2011-05-22 19:36:31.000000000 -0400
29304 @@ -2244,7 +2244,7 @@ intel_pipe_set_base(struct drm_crtc *crt
29305
29306 wait_event(dev_priv->pending_flip_queue,
29307 atomic_read(&dev_priv->mm.wedged) ||
29308 - atomic_read(&obj->pending_flip) == 0);
29309 + atomic_read_unchecked(&obj->pending_flip) == 0);
29310
29311 /* Big Hammer, we also need to ensure that any pending
29312 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
29313 @@ -2712,7 +2712,7 @@ static void intel_crtc_wait_for_pending_
29314 obj = to_intel_framebuffer(crtc->fb)->obj;
29315 dev_priv = crtc->dev->dev_private;
29316 wait_event(dev_priv->pending_flip_queue,
29317 - atomic_read(&obj->pending_flip) == 0);
29318 + atomic_read_unchecked(&obj->pending_flip) == 0);
29319 }
29320
29321 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
29322 @@ -6016,7 +6016,7 @@ static void do_intel_finish_page_flip(st
29323
29324 atomic_clear_mask(1 << intel_crtc->plane,
29325 &obj->pending_flip.counter);
29326 - if (atomic_read(&obj->pending_flip) == 0)
29327 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
29328 wake_up(&dev_priv->pending_flip_queue);
29329
29330 schedule_work(&work->work);
29331 @@ -6145,7 +6145,7 @@ static int intel_crtc_page_flip(struct d
29332 /* Block clients from rendering to the new back buffer until
29333 * the flip occurs and the object is no longer visible.
29334 */
29335 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29336 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
29337
29338 switch (INTEL_INFO(dev)->gen) {
29339 case 2:
29340 diff -urNp linux-2.6.39.2/drivers/gpu/drm/mga/mga_drv.h linux-2.6.39.2/drivers/gpu/drm/mga/mga_drv.h
29341 --- linux-2.6.39.2/drivers/gpu/drm/mga/mga_drv.h 2011-05-19 00:06:34.000000000 -0400
29342 +++ linux-2.6.39.2/drivers/gpu/drm/mga/mga_drv.h 2011-05-22 19:36:31.000000000 -0400
29343 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
29344 u32 clear_cmd;
29345 u32 maccess;
29346
29347 - atomic_t vbl_received; /**< Number of vblanks received. */
29348 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
29349 wait_queue_head_t fence_queue;
29350 - atomic_t last_fence_retired;
29351 + atomic_unchecked_t last_fence_retired;
29352 u32 next_fence_to_post;
29353
29354 unsigned int fb_cpp;
29355 diff -urNp linux-2.6.39.2/drivers/gpu/drm/mga/mga_irq.c linux-2.6.39.2/drivers/gpu/drm/mga/mga_irq.c
29356 --- linux-2.6.39.2/drivers/gpu/drm/mga/mga_irq.c 2011-05-19 00:06:34.000000000 -0400
29357 +++ linux-2.6.39.2/drivers/gpu/drm/mga/mga_irq.c 2011-05-22 19:36:31.000000000 -0400
29358 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_de
29359 if (crtc != 0)
29360 return 0;
29361
29362 - return atomic_read(&dev_priv->vbl_received);
29363 + return atomic_read_unchecked(&dev_priv->vbl_received);
29364 }
29365
29366
29367 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29368 /* VBLANK interrupt */
29369 if (status & MGA_VLINEPEN) {
29370 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
29371 - atomic_inc(&dev_priv->vbl_received);
29372 + atomic_inc_unchecked(&dev_priv->vbl_received);
29373 drm_handle_vblank(dev, 0);
29374 handled = 1;
29375 }
29376 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_I
29377 if ((prim_start & ~0x03) != (prim_end & ~0x03))
29378 MGA_WRITE(MGA_PRIMEND, prim_end);
29379
29380 - atomic_inc(&dev_priv->last_fence_retired);
29381 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
29382 DRM_WAKEUP(&dev_priv->fence_queue);
29383 handled = 1;
29384 }
29385 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_dev
29386 * using fences.
29387 */
29388 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
29389 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
29390 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
29391 - *sequence) <= (1 << 23)));
29392
29393 *sequence = cur_fence;
29394 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_acpi.c linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_acpi.c
29395 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-19 00:06:34.000000000 -0400
29396 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_acpi.c 2011-05-22 19:36:31.000000000 -0400
29397 @@ -141,7 +141,7 @@ static int nouveau_dsm_get_client_id(str
29398 return VGA_SWITCHEROO_DIS;
29399 }
29400
29401 -static struct vga_switcheroo_handler nouveau_dsm_handler = {
29402 +static const struct vga_switcheroo_handler nouveau_dsm_handler = {
29403 .switchto = nouveau_dsm_switchto,
29404 .power_state = nouveau_dsm_power_state,
29405 .init = nouveau_dsm_init,
29406 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_drv.h linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_drv.h
29407 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-05-19 00:06:34.000000000 -0400
29408 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_drv.h 2011-06-07 18:07:24.000000000 -0400
29409 @@ -228,7 +228,7 @@ struct nouveau_channel {
29410 struct list_head pending;
29411 uint32_t sequence;
29412 uint32_t sequence_ack;
29413 - atomic_t last_sequence_irq;
29414 + atomic_unchecked_t last_sequence_irq;
29415 } fence;
29416
29417 /* DMA push buffer */
29418 @@ -662,7 +662,7 @@ struct drm_nouveau_private {
29419 struct drm_global_reference mem_global_ref;
29420 struct ttm_bo_global_ref bo_global_ref;
29421 struct ttm_bo_device bdev;
29422 - atomic_t validate_sequence;
29423 + atomic_unchecked_t validate_sequence;
29424 } ttm;
29425
29426 struct {
29427 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_fence.c linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_fence.c
29428 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-19 00:06:34.000000000 -0400
29429 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_fence.c 2011-05-22 19:36:31.000000000 -0400
29430 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_chan
29431 if (USE_REFCNT(dev))
29432 sequence = nvchan_rd32(chan, 0x48);
29433 else
29434 - sequence = atomic_read(&chan->fence.last_sequence_irq);
29435 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
29436
29437 if (chan->fence.sequence_ack == sequence)
29438 goto out;
29439 @@ -553,7 +553,7 @@ nouveau_fence_channel_init(struct nouvea
29440 out_initialised:
29441 INIT_LIST_HEAD(&chan->fence.pending);
29442 spin_lock_init(&chan->fence.lock);
29443 - atomic_set(&chan->fence.last_sequence_irq, 0);
29444 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
29445 return 0;
29446 }
29447
29448 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_gem.c linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_gem.c
29449 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-19 00:06:34.000000000 -0400
29450 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_gem.c 2011-05-22 19:36:31.000000000 -0400
29451 @@ -249,7 +249,7 @@ validate_init(struct nouveau_channel *ch
29452 int trycnt = 0;
29453 int ret, i;
29454
29455 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
29456 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
29457 retry:
29458 if (++trycnt > 100000) {
29459 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
29460 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_state.c linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_state.c
29461 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-19 00:06:34.000000000 -0400
29462 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nouveau_state.c 2011-05-22 19:36:31.000000000 -0400
29463 @@ -583,7 +583,7 @@ static bool nouveau_switcheroo_can_switc
29464 bool can_switch;
29465
29466 spin_lock(&dev->count_lock);
29467 - can_switch = (dev->open_count == 0);
29468 + can_switch = (local_read(&dev->open_count) == 0);
29469 spin_unlock(&dev->count_lock);
29470 return can_switch;
29471 }
29472 diff -urNp linux-2.6.39.2/drivers/gpu/drm/nouveau/nv04_graph.c linux-2.6.39.2/drivers/gpu/drm/nouveau/nv04_graph.c
29473 --- linux-2.6.39.2/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-19 00:06:34.000000000 -0400
29474 +++ linux-2.6.39.2/drivers/gpu/drm/nouveau/nv04_graph.c 2011-05-22 19:36:31.000000000 -0400
29475 @@ -552,7 +552,7 @@ static int
29476 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
29477 u32 class, u32 mthd, u32 data)
29478 {
29479 - atomic_set(&chan->fence.last_sequence_irq, data);
29480 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
29481 return 0;
29482 }
29483
29484 diff -urNp linux-2.6.39.2/drivers/gpu/drm/r128/r128_cce.c linux-2.6.39.2/drivers/gpu/drm/r128/r128_cce.c
29485 --- linux-2.6.39.2/drivers/gpu/drm/r128/r128_cce.c 2011-05-19 00:06:34.000000000 -0400
29486 +++ linux-2.6.39.2/drivers/gpu/drm/r128/r128_cce.c 2011-05-22 19:36:31.000000000 -0400
29487 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_d
29488
29489 /* GH: Simple idle check.
29490 */
29491 - atomic_set(&dev_priv->idle_count, 0);
29492 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29493
29494 /* We don't support anything other than bus-mastering ring mode,
29495 * but the ring can be in either AGP or PCI space for the ring
29496 diff -urNp linux-2.6.39.2/drivers/gpu/drm/r128/r128_drv.h linux-2.6.39.2/drivers/gpu/drm/r128/r128_drv.h
29497 --- linux-2.6.39.2/drivers/gpu/drm/r128/r128_drv.h 2011-05-19 00:06:34.000000000 -0400
29498 +++ linux-2.6.39.2/drivers/gpu/drm/r128/r128_drv.h 2011-05-22 19:36:31.000000000 -0400
29499 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
29500 int is_pci;
29501 unsigned long cce_buffers_offset;
29502
29503 - atomic_t idle_count;
29504 + atomic_unchecked_t idle_count;
29505
29506 int page_flipping;
29507 int current_page;
29508 u32 crtc_offset;
29509 u32 crtc_offset_cntl;
29510
29511 - atomic_t vbl_received;
29512 + atomic_unchecked_t vbl_received;
29513
29514 u32 color_fmt;
29515 unsigned int front_offset;
29516 diff -urNp linux-2.6.39.2/drivers/gpu/drm/r128/r128_irq.c linux-2.6.39.2/drivers/gpu/drm/r128/r128_irq.c
29517 --- linux-2.6.39.2/drivers/gpu/drm/r128/r128_irq.c 2011-05-19 00:06:34.000000000 -0400
29518 +++ linux-2.6.39.2/drivers/gpu/drm/r128/r128_irq.c 2011-05-22 19:36:31.000000000 -0400
29519 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_d
29520 if (crtc != 0)
29521 return 0;
29522
29523 - return atomic_read(&dev_priv->vbl_received);
29524 + return atomic_read_unchecked(&dev_priv->vbl_received);
29525 }
29526
29527 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
29528 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_
29529 /* VBLANK interrupt */
29530 if (status & R128_CRTC_VBLANK_INT) {
29531 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
29532 - atomic_inc(&dev_priv->vbl_received);
29533 + atomic_inc_unchecked(&dev_priv->vbl_received);
29534 drm_handle_vblank(dev, 0);
29535 return IRQ_HANDLED;
29536 }
29537 diff -urNp linux-2.6.39.2/drivers/gpu/drm/r128/r128_state.c linux-2.6.39.2/drivers/gpu/drm/r128/r128_state.c
29538 --- linux-2.6.39.2/drivers/gpu/drm/r128/r128_state.c 2011-05-19 00:06:34.000000000 -0400
29539 +++ linux-2.6.39.2/drivers/gpu/drm/r128/r128_state.c 2011-05-22 19:36:31.000000000 -0400
29540 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_priv
29541
29542 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
29543 {
29544 - if (atomic_read(&dev_priv->idle_count) == 0)
29545 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
29546 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
29547 else
29548 - atomic_set(&dev_priv->idle_count, 0);
29549 + atomic_set_unchecked(&dev_priv->idle_count, 0);
29550 }
29551
29552 #endif
29553 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/atom.c linux-2.6.39.2/drivers/gpu/drm/radeon/atom.c
29554 --- linux-2.6.39.2/drivers/gpu/drm/radeon/atom.c 2011-05-19 00:06:34.000000000 -0400
29555 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/atom.c 2011-05-22 19:36:31.000000000 -0400
29556 @@ -1245,6 +1245,8 @@ struct atom_context *atom_parse(struct c
29557 char name[512];
29558 int i;
29559
29560 + pax_track_stack();
29561 +
29562 ctx->card = card;
29563 ctx->bios = bios;
29564
29565 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/mkregtable.c linux-2.6.39.2/drivers/gpu/drm/radeon/mkregtable.c
29566 --- linux-2.6.39.2/drivers/gpu/drm/radeon/mkregtable.c 2011-05-19 00:06:34.000000000 -0400
29567 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/mkregtable.c 2011-05-22 19:36:31.000000000 -0400
29568 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t,
29569 regex_t mask_rex;
29570 regmatch_t match[4];
29571 char buf[1024];
29572 - size_t end;
29573 + long end;
29574 int len;
29575 int done = 0;
29576 int r;
29577 unsigned o;
29578 struct offset *offset;
29579 char last_reg_s[10];
29580 - int last_reg;
29581 + unsigned long last_reg;
29582
29583 if (regcomp
29584 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
29585 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atombios.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atombios.c
29586 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-19 00:06:34.000000000 -0400
29587 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atombios.c 2011-05-22 19:36:31.000000000 -0400
29588 @@ -545,6 +545,8 @@ bool radeon_get_atom_connector_info_from
29589 struct radeon_gpio_rec gpio;
29590 struct radeon_hpd hpd;
29591
29592 + pax_track_stack();
29593 +
29594 if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
29595 return false;
29596
29597 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atpx_handler.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atpx_handler.c
29598 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-19 00:06:34.000000000 -0400
29599 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_atpx_handler.c 2011-05-22 19:36:31.000000000 -0400
29600 @@ -234,7 +234,7 @@ static int radeon_atpx_get_client_id(str
29601 return VGA_SWITCHEROO_DIS;
29602 }
29603
29604 -static struct vga_switcheroo_handler radeon_atpx_handler = {
29605 +static const struct vga_switcheroo_handler radeon_atpx_handler = {
29606 .switchto = radeon_atpx_switchto,
29607 .power_state = radeon_atpx_power_state,
29608 .init = radeon_atpx_init,
29609 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_device.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_device.c
29610 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_device.c 2011-06-25 12:55:22.000000000 -0400
29611 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_device.c 2011-06-25 13:00:25.000000000 -0400
29612 @@ -674,7 +674,7 @@ static bool radeon_switcheroo_can_switch
29613 bool can_switch;
29614
29615 spin_lock(&dev->count_lock);
29616 - can_switch = (dev->open_count == 0);
29617 + can_switch = (local_read(&dev->open_count) == 0);
29618 spin_unlock(&dev->count_lock);
29619 return can_switch;
29620 }
29621 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_display.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_display.c
29622 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_display.c 2011-05-19 00:06:34.000000000 -0400
29623 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_display.c 2011-05-22 19:36:31.000000000 -0400
29624 @@ -934,6 +934,8 @@ void radeon_compute_pll_legacy(struct ra
29625 uint32_t post_div;
29626 u32 pll_out_min, pll_out_max;
29627
29628 + pax_track_stack();
29629 +
29630 DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
29631 freq = freq * 1000;
29632
29633 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_drv.h linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_drv.h
29634 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-19 00:06:34.000000000 -0400
29635 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_drv.h 2011-05-22 19:36:31.000000000 -0400
29636 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
29637
29638 /* SW interrupt */
29639 wait_queue_head_t swi_queue;
29640 - atomic_t swi_emitted;
29641 + atomic_unchecked_t swi_emitted;
29642 int vblank_crtc;
29643 uint32_t irq_enable_reg;
29644 uint32_t r500_disp_irq_reg;
29645 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_fence.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_fence.c
29646 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-19 00:06:34.000000000 -0400
29647 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_fence.c 2011-05-22 19:36:31.000000000 -0400
29648 @@ -49,7 +49,7 @@ int radeon_fence_emit(struct radeon_devi
29649 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
29650 return 0;
29651 }
29652 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
29653 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
29654 if (!rdev->cp.ready) {
29655 /* FIXME: cp is not running assume everythings is done right
29656 * away
29657 @@ -352,7 +352,7 @@ int radeon_fence_driver_init(struct rade
29658 return r;
29659 }
29660 WREG32(rdev->fence_drv.scratch_reg, 0);
29661 - atomic_set(&rdev->fence_drv.seq, 0);
29662 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
29663 INIT_LIST_HEAD(&rdev->fence_drv.created);
29664 INIT_LIST_HEAD(&rdev->fence_drv.emited);
29665 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
29666 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon.h linux-2.6.39.2/drivers/gpu/drm/radeon/radeon.h
29667 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon.h 2011-05-19 00:06:34.000000000 -0400
29668 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon.h 2011-05-22 19:36:31.000000000 -0400
29669 @@ -189,7 +189,7 @@ extern int sumo_get_temp(struct radeon_d
29670 */
29671 struct radeon_fence_driver {
29672 uint32_t scratch_reg;
29673 - atomic_t seq;
29674 + atomic_unchecked_t seq;
29675 uint32_t last_seq;
29676 unsigned long last_jiffies;
29677 unsigned long last_timeout;
29678 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ioc32.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ioc32.c
29679 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-19 00:06:34.000000000 -0400
29680 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ioc32.c 2011-05-22 19:36:31.000000000 -0400
29681 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(str
29682 request = compat_alloc_user_space(sizeof(*request));
29683 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
29684 || __put_user(req32.param, &request->param)
29685 - || __put_user((void __user *)(unsigned long)req32.value,
29686 + || __put_user((unsigned long)req32.value,
29687 &request->value))
29688 return -EFAULT;
29689
29690 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_irq.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_irq.c
29691 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-19 00:06:34.000000000 -0400
29692 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_irq.c 2011-05-22 19:36:31.000000000 -0400
29693 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_de
29694 unsigned int ret;
29695 RING_LOCALS;
29696
29697 - atomic_inc(&dev_priv->swi_emitted);
29698 - ret = atomic_read(&dev_priv->swi_emitted);
29699 + atomic_inc_unchecked(&dev_priv->swi_emitted);
29700 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29701
29702 BEGIN_RING(4);
29703 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29704 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct
29705 drm_radeon_private_t *dev_priv =
29706 (drm_radeon_private_t *) dev->dev_private;
29707
29708 - atomic_set(&dev_priv->swi_emitted, 0);
29709 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29710 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29711
29712 dev->max_vblank_count = 0x001fffff;
29713 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_state.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_state.c
29714 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_state.c 2011-05-19 00:06:34.000000000 -0400
29715 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_state.c 2011-05-22 19:36:31.000000000 -0400
29716 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_de
29717 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29718 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29719
29720 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29721 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29722 sarea_priv->nbox * sizeof(depth_boxes[0])))
29723 return -EFAULT;
29724
29725 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm
29726 {
29727 drm_radeon_private_t *dev_priv = dev->dev_private;
29728 drm_radeon_getparam_t *param = data;
29729 - int value;
29730 + int value = 0;
29731
29732 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29733
29734 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ttm.c linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ttm.c
29735 --- linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-19 00:06:34.000000000 -0400
29736 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/radeon_ttm.c 2011-05-22 19:36:31.000000000 -0400
29737 @@ -603,8 +603,9 @@ void radeon_ttm_set_active_vram_size(str
29738 man->size = size >> PAGE_SHIFT;
29739 }
29740
29741 -static struct vm_operations_struct radeon_ttm_vm_ops;
29742 -static const struct vm_operations_struct *ttm_vm_ops = NULL;
29743 +extern int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
29744 +extern void ttm_bo_vm_open(struct vm_area_struct *vma);
29745 +extern void ttm_bo_vm_close(struct vm_area_struct *vma);
29746
29747 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29748 {
29749 @@ -612,17 +613,22 @@ static int radeon_ttm_fault(struct vm_ar
29750 struct radeon_device *rdev;
29751 int r;
29752
29753 - bo = (struct ttm_buffer_object *)vma->vm_private_data;
29754 - if (bo == NULL) {
29755 + bo = (struct ttm_buffer_object *)vma->vm_private_data;
29756 + if (!bo)
29757 return VM_FAULT_NOPAGE;
29758 - }
29759 rdev = radeon_get_rdev(bo->bdev);
29760 mutex_lock(&rdev->vram_mutex);
29761 - r = ttm_vm_ops->fault(vma, vmf);
29762 + r = ttm_bo_vm_fault(vma, vmf);
29763 mutex_unlock(&rdev->vram_mutex);
29764 return r;
29765 }
29766
29767 +static const struct vm_operations_struct radeon_ttm_vm_ops = {
29768 + .fault = radeon_ttm_fault,
29769 + .open = ttm_bo_vm_open,
29770 + .close = ttm_bo_vm_close
29771 +};
29772 +
29773 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29774 {
29775 struct drm_file *file_priv;
29776 @@ -635,18 +641,11 @@ int radeon_mmap(struct file *filp, struc
29777
29778 file_priv = filp->private_data;
29779 rdev = file_priv->minor->dev->dev_private;
29780 - if (rdev == NULL) {
29781 + if (!rdev)
29782 return -EINVAL;
29783 - }
29784 r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
29785 - if (unlikely(r != 0)) {
29786 + if (r)
29787 return r;
29788 - }
29789 - if (unlikely(ttm_vm_ops == NULL)) {
29790 - ttm_vm_ops = vma->vm_ops;
29791 - radeon_ttm_vm_ops = *ttm_vm_ops;
29792 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29793 - }
29794 vma->vm_ops = &radeon_ttm_vm_ops;
29795 return 0;
29796 }
29797 diff -urNp linux-2.6.39.2/drivers/gpu/drm/radeon/rs690.c linux-2.6.39.2/drivers/gpu/drm/radeon/rs690.c
29798 --- linux-2.6.39.2/drivers/gpu/drm/radeon/rs690.c 2011-05-19 00:06:34.000000000 -0400
29799 +++ linux-2.6.39.2/drivers/gpu/drm/radeon/rs690.c 2011-05-22 19:36:31.000000000 -0400
29800 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct
29801 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29802 rdev->pm.sideport_bandwidth.full)
29803 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29804 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29805 + read_delay_latency.full = dfixed_const(800 * 1000);
29806 read_delay_latency.full = dfixed_div(read_delay_latency,
29807 rdev->pm.igp_sideport_mclk);
29808 + a.full = dfixed_const(370);
29809 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29810 } else {
29811 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29812 rdev->pm.k8_bandwidth.full)
29813 diff -urNp linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_bo_vm.c linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_bo_vm.c
29814 --- linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-19 00:06:34.000000000 -0400
29815 +++ linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_bo_vm.c 2011-05-22 19:36:31.000000000 -0400
29816 @@ -69,11 +69,11 @@ static struct ttm_buffer_object *ttm_bo_
29817 return best_bo;
29818 }
29819
29820 -static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29821 +int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
29822 {
29823 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
29824 vma->vm_private_data;
29825 - struct ttm_bo_device *bdev = bo->bdev;
29826 + struct ttm_bo_device *bdev;
29827 unsigned long page_offset;
29828 unsigned long page_last;
29829 unsigned long pfn;
29830 @@ -83,8 +83,12 @@ static int ttm_bo_vm_fault(struct vm_are
29831 int i;
29832 unsigned long address = (unsigned long)vmf->virtual_address;
29833 int retval = VM_FAULT_NOPAGE;
29834 - struct ttm_mem_type_manager *man =
29835 - &bdev->man[bo->mem.mem_type];
29836 + struct ttm_mem_type_manager *man;
29837 +
29838 + if (!bo)
29839 + return VM_FAULT_NOPAGE;
29840 + bdev = bo->bdev;
29841 + man = &bdev->man[bo->mem.mem_type];
29842
29843 /*
29844 * Work around locking order reversal in fault / nopfn
29845 @@ -219,22 +223,25 @@ out_unlock:
29846 ttm_bo_unreserve(bo);
29847 return retval;
29848 }
29849 +EXPORT_SYMBOL(ttm_bo_vm_fault);
29850
29851 -static void ttm_bo_vm_open(struct vm_area_struct *vma)
29852 +void ttm_bo_vm_open(struct vm_area_struct *vma)
29853 {
29854 struct ttm_buffer_object *bo =
29855 (struct ttm_buffer_object *)vma->vm_private_data;
29856
29857 (void)ttm_bo_reference(bo);
29858 }
29859 +EXPORT_SYMBOL(ttm_bo_vm_open);
29860
29861 -static void ttm_bo_vm_close(struct vm_area_struct *vma)
29862 +void ttm_bo_vm_close(struct vm_area_struct *vma)
29863 {
29864 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)vma->vm_private_data;
29865
29866 ttm_bo_unref(&bo);
29867 vma->vm_private_data = NULL;
29868 }
29869 +EXPORT_SYMBOL(ttm_bo_vm_close);
29870
29871 static const struct vm_operations_struct ttm_bo_vm_ops = {
29872 .fault = ttm_bo_vm_fault,
29873 diff -urNp linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_page_alloc.c linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_page_alloc.c
29874 --- linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-19 00:06:34.000000000 -0400
29875 +++ linux-2.6.39.2/drivers/gpu/drm/ttm/ttm_page_alloc.c 2011-05-22 19:36:31.000000000 -0400
29876 @@ -397,9 +397,9 @@ static int ttm_pool_get_num_unused_pages
29877 */
29878 static int ttm_pool_mm_shrink(struct shrinker *shrink, int shrink_pages, gfp_t gfp_mask)
29879 {
29880 - static atomic_t start_pool = ATOMIC_INIT(0);
29881 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29882 unsigned i;
29883 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29884 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29885 struct ttm_page_pool *pool;
29886
29887 pool_offset = pool_offset % NUM_POOLS;
29888 diff -urNp linux-2.6.39.2/drivers/gpu/drm/via/via_drv.h linux-2.6.39.2/drivers/gpu/drm/via/via_drv.h
29889 --- linux-2.6.39.2/drivers/gpu/drm/via/via_drv.h 2011-05-19 00:06:34.000000000 -0400
29890 +++ linux-2.6.39.2/drivers/gpu/drm/via/via_drv.h 2011-05-22 19:36:31.000000000 -0400
29891 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29892 typedef uint32_t maskarray_t[5];
29893
29894 typedef struct drm_via_irq {
29895 - atomic_t irq_received;
29896 + atomic_unchecked_t irq_received;
29897 uint32_t pending_mask;
29898 uint32_t enable_mask;
29899 wait_queue_head_t irq_queue;
29900 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29901 struct timeval last_vblank;
29902 int last_vblank_valid;
29903 unsigned usec_per_vblank;
29904 - atomic_t vbl_received;
29905 + atomic_unchecked_t vbl_received;
29906 drm_via_state_t hc_state;
29907 char pci_buf[VIA_PCI_BUF_SIZE];
29908 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29909 diff -urNp linux-2.6.39.2/drivers/gpu/drm/via/via_irq.c linux-2.6.39.2/drivers/gpu/drm/via/via_irq.c
29910 --- linux-2.6.39.2/drivers/gpu/drm/via/via_irq.c 2011-05-19 00:06:34.000000000 -0400
29911 +++ linux-2.6.39.2/drivers/gpu/drm/via/via_irq.c 2011-05-22 19:36:31.000000000 -0400
29912 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_de
29913 if (crtc != 0)
29914 return 0;
29915
29916 - return atomic_read(&dev_priv->vbl_received);
29917 + return atomic_read_unchecked(&dev_priv->vbl_received);
29918 }
29919
29920 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29921 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_I
29922
29923 status = VIA_READ(VIA_REG_INTERRUPT);
29924 if (status & VIA_IRQ_VBLANK_PENDING) {
29925 - atomic_inc(&dev_priv->vbl_received);
29926 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29927 + atomic_inc_unchecked(&dev_priv->vbl_received);
29928 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29929 do_gettimeofday(&cur_vblank);
29930 if (dev_priv->last_vblank_valid) {
29931 dev_priv->usec_per_vblank =
29932 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29933 dev_priv->last_vblank = cur_vblank;
29934 dev_priv->last_vblank_valid = 1;
29935 }
29936 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29937 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29938 DRM_DEBUG("US per vblank is: %u\n",
29939 dev_priv->usec_per_vblank);
29940 }
29941 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_I
29942
29943 for (i = 0; i < dev_priv->num_irqs; ++i) {
29944 if (status & cur_irq->pending_mask) {
29945 - atomic_inc(&cur_irq->irq_received);
29946 + atomic_inc_unchecked(&cur_irq->irq_received);
29947 DRM_WAKEUP(&cur_irq->irq_queue);
29948 handled = 1;
29949 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29950 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *d
29951 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29952 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29953 masks[irq][4]));
29954 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29955 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29956 } else {
29957 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29958 (((cur_irq_sequence =
29959 - atomic_read(&cur_irq->irq_received)) -
29960 + atomic_read_unchecked(&cur_irq->irq_received)) -
29961 *sequence) <= (1 << 23)));
29962 }
29963 *sequence = cur_irq_sequence;
29964 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct dr
29965 }
29966
29967 for (i = 0; i < dev_priv->num_irqs; ++i) {
29968 - atomic_set(&cur_irq->irq_received, 0);
29969 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29970 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29971 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29972 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29973 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev,
29974 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29975 case VIA_IRQ_RELATIVE:
29976 irqwait->request.sequence +=
29977 - atomic_read(&cur_irq->irq_received);
29978 + atomic_read_unchecked(&cur_irq->irq_received);
29979 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29980 case VIA_IRQ_ABSOLUTE:
29981 break;
29982 diff -urNp linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29983 --- linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-19 00:06:34.000000000 -0400
29984 +++ linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 2011-05-22 19:36:31.000000000 -0400
29985 @@ -240,7 +240,7 @@ struct vmw_private {
29986 * Fencing and IRQs.
29987 */
29988
29989 - atomic_t fence_seq;
29990 + atomic_unchecked_t fence_seq;
29991 wait_queue_head_t fence_queue;
29992 wait_queue_head_t fifo_queue;
29993 atomic_t fence_queue_waiters;
29994 diff -urNp linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
29995 --- linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-19 00:06:34.000000000 -0400
29996 +++ linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c 2011-05-22 19:36:31.000000000 -0400
29997 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev
29998 while (!vmw_lag_lt(queue, us)) {
29999 spin_lock(&queue->lock);
30000 if (list_empty(&queue->head))
30001 - sequence = atomic_read(&dev_priv->fence_seq);
30002 + sequence = atomic_read_unchecked(&dev_priv->fence_seq);
30003 else {
30004 fence = list_first_entry(&queue->head,
30005 struct vmw_fence, head);
30006 diff -urNp linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
30007 --- linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-19 00:06:34.000000000 -0400
30008 +++ linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c 2011-05-22 19:36:31.000000000 -0400
30009 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *de
30010 (unsigned int) min,
30011 (unsigned int) fifo->capabilities);
30012
30013 - atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence);
30014 + atomic_set_unchecked(&dev_priv->fence_seq, dev_priv->last_read_sequence);
30015 iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE);
30016 vmw_fence_queue_init(&fifo->fence_queue);
30017 return vmw_fifo_send_fence(dev_priv, &dummy);
30018 @@ -476,7 +476,7 @@ int vmw_fifo_send_fence(struct vmw_priva
30019
30020 fm = vmw_fifo_reserve(dev_priv, bytes);
30021 if (unlikely(fm == NULL)) {
30022 - *sequence = atomic_read(&dev_priv->fence_seq);
30023 + *sequence = atomic_read_unchecked(&dev_priv->fence_seq);
30024 ret = -ENOMEM;
30025 (void)vmw_fallback_wait(dev_priv, false, true, *sequence,
30026 false, 3*HZ);
30027 @@ -484,7 +484,7 @@ int vmw_fifo_send_fence(struct vmw_priva
30028 }
30029
30030 do {
30031 - *sequence = atomic_add_return(1, &dev_priv->fence_seq);
30032 + *sequence = atomic_add_return_unchecked(1, &dev_priv->fence_seq);
30033 } while (*sequence == 0);
30034
30035 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
30036 @@ -534,7 +534,7 @@ static int vmw_fifo_vm_fault(struct vm_a
30037 return VM_FAULT_SIGBUS;
30038 }
30039
30040 -static struct vm_operations_struct vmw_fifo_vm_ops = {
30041 +static const struct vm_operations_struct vmw_fifo_vm_ops = {
30042 .fault = vmw_fifo_vm_fault,
30043 .open = NULL,
30044 .close = NULL
30045 diff -urNp linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
30046 --- linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-19 00:06:34.000000000 -0400
30047 +++ linux-2.6.39.2/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c 2011-05-22 19:36:31.000000000 -0400
30048 @@ -100,7 +100,7 @@ bool vmw_fence_signaled(struct vmw_priva
30049 * emitted. Then the fence is stale and signaled.
30050 */
30051
30052 - ret = ((atomic_read(&dev_priv->fence_seq) - sequence)
30053 + ret = ((atomic_read_unchecked(&dev_priv->fence_seq) - sequence)
30054 > VMW_FENCE_WRAP);
30055
30056 return ret;
30057 @@ -131,7 +131,7 @@ int vmw_fallback_wait(struct vmw_private
30058
30059 if (fifo_idle)
30060 down_read(&fifo_state->rwsem);
30061 - signal_seq = atomic_read(&dev_priv->fence_seq);
30062 + signal_seq = atomic_read_unchecked(&dev_priv->fence_seq);
30063 ret = 0;
30064
30065 for (;;) {
30066 diff -urNp linux-2.6.39.2/drivers/gpu/vga/vga_switcheroo.c linux-2.6.39.2/drivers/gpu/vga/vga_switcheroo.c
30067 --- linux-2.6.39.2/drivers/gpu/vga/vga_switcheroo.c 2011-05-19 00:06:34.000000000 -0400
30068 +++ linux-2.6.39.2/drivers/gpu/vga/vga_switcheroo.c 2011-05-22 19:36:31.000000000 -0400
30069 @@ -53,7 +53,7 @@ struct vgasr_priv {
30070 int registered_clients;
30071 struct vga_switcheroo_client clients[VGA_SWITCHEROO_MAX_CLIENTS];
30072
30073 - struct vga_switcheroo_handler *handler;
30074 + const struct vga_switcheroo_handler *handler;
30075 };
30076
30077 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
30078 @@ -62,7 +62,7 @@ static void vga_switcheroo_debugfs_fini(
30079 /* only one switcheroo per system */
30080 static struct vgasr_priv vgasr_priv;
30081
30082 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
30083 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler)
30084 {
30085 mutex_lock(&vgasr_mutex);
30086 if (vgasr_priv.handler) {
30087 diff -urNp linux-2.6.39.2/drivers/hid/hid-core.c linux-2.6.39.2/drivers/hid/hid-core.c
30088 --- linux-2.6.39.2/drivers/hid/hid-core.c 2011-05-19 00:06:34.000000000 -0400
30089 +++ linux-2.6.39.2/drivers/hid/hid-core.c 2011-05-22 19:36:31.000000000 -0400
30090 @@ -1888,7 +1888,7 @@ static bool hid_ignore(struct hid_device
30091
30092 int hid_add_device(struct hid_device *hdev)
30093 {
30094 - static atomic_t id = ATOMIC_INIT(0);
30095 + static atomic_unchecked_t id = ATOMIC_INIT(0);
30096 int ret;
30097
30098 if (WARN_ON(hdev->status & HID_STAT_ADDED))
30099 @@ -1903,7 +1903,7 @@ int hid_add_device(struct hid_device *hd
30100 /* XXX hack, any other cleaner solution after the driver core
30101 * is converted to allow more than 20 bytes as the device name? */
30102 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
30103 - hdev->vendor, hdev->product, atomic_inc_return(&id));
30104 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
30105
30106 hid_debug_register(hdev, dev_name(&hdev->dev));
30107 ret = device_add(&hdev->dev);
30108 diff -urNp linux-2.6.39.2/drivers/hid/hid-picolcd.c linux-2.6.39.2/drivers/hid/hid-picolcd.c
30109 --- linux-2.6.39.2/drivers/hid/hid-picolcd.c 2011-05-19 00:06:34.000000000 -0400
30110 +++ linux-2.6.39.2/drivers/hid/hid-picolcd.c 2011-05-22 19:36:31.000000000 -0400
30111 @@ -1037,7 +1037,7 @@ static int picolcd_check_lcd_fb(struct l
30112 return fb && fb == picolcd_fbinfo((struct picolcd_data *)lcd_get_data(ldev));
30113 }
30114
30115 -static struct lcd_ops picolcd_lcdops = {
30116 +static const struct lcd_ops picolcd_lcdops = {
30117 .get_contrast = picolcd_get_contrast,
30118 .set_contrast = picolcd_set_contrast,
30119 .check_fb = picolcd_check_lcd_fb,
30120 diff -urNp linux-2.6.39.2/drivers/hid/usbhid/hiddev.c linux-2.6.39.2/drivers/hid/usbhid/hiddev.c
30121 --- linux-2.6.39.2/drivers/hid/usbhid/hiddev.c 2011-05-19 00:06:34.000000000 -0400
30122 +++ linux-2.6.39.2/drivers/hid/usbhid/hiddev.c 2011-05-22 19:36:31.000000000 -0400
30123 @@ -613,7 +613,7 @@ static long hiddev_ioctl(struct file *fi
30124 break;
30125
30126 case HIDIOCAPPLICATION:
30127 - if (arg < 0 || arg >= hid->maxapplication)
30128 + if (arg >= hid->maxapplication)
30129 break;
30130
30131 for (i = 0; i < hid->maxcollection; i++)
30132 diff -urNp linux-2.6.39.2/drivers/hwmon/ibmaem.c linux-2.6.39.2/drivers/hwmon/ibmaem.c
30133 --- linux-2.6.39.2/drivers/hwmon/ibmaem.c 2011-05-19 00:06:34.000000000 -0400
30134 +++ linux-2.6.39.2/drivers/hwmon/ibmaem.c 2011-05-22 19:36:31.000000000 -0400
30135 @@ -238,7 +238,7 @@ struct aem_read_sensor_resp {
30136 struct aem_driver_data {
30137 struct list_head aem_devices;
30138 struct ipmi_smi_watcher bmc_events;
30139 - struct ipmi_user_hndl ipmi_hndlrs;
30140 + const struct ipmi_user_hndl ipmi_hndlrs;
30141 };
30142
30143 static void aem_register_bmc(int iface, struct device *dev);
30144 diff -urNp linux-2.6.39.2/drivers/hwmon/ibmpex.c linux-2.6.39.2/drivers/hwmon/ibmpex.c
30145 --- linux-2.6.39.2/drivers/hwmon/ibmpex.c 2011-05-19 00:06:34.000000000 -0400
30146 +++ linux-2.6.39.2/drivers/hwmon/ibmpex.c 2011-05-22 19:36:31.000000000 -0400
30147 @@ -110,7 +110,7 @@ struct ibmpex_bmc_data {
30148 struct ibmpex_driver_data {
30149 struct list_head bmc_data;
30150 struct ipmi_smi_watcher bmc_events;
30151 - struct ipmi_user_hndl ipmi_hndlrs;
30152 + const struct ipmi_user_hndl ipmi_hndlrs;
30153 };
30154
30155 static struct ibmpex_driver_data driver_data = {
30156 diff -urNp linux-2.6.39.2/drivers/hwmon/sht15.c linux-2.6.39.2/drivers/hwmon/sht15.c
30157 --- linux-2.6.39.2/drivers/hwmon/sht15.c 2011-05-19 00:06:34.000000000 -0400
30158 +++ linux-2.6.39.2/drivers/hwmon/sht15.c 2011-05-22 19:36:31.000000000 -0400
30159 @@ -113,7 +113,7 @@ struct sht15_data {
30160 int supply_uV;
30161 int supply_uV_valid;
30162 struct work_struct update_supply_work;
30163 - atomic_t interrupt_handled;
30164 + atomic_unchecked_t interrupt_handled;
30165 };
30166
30167 /**
30168 @@ -246,13 +246,13 @@ static inline int sht15_update_single_va
30169 return ret;
30170
30171 gpio_direction_input(data->pdata->gpio_data);
30172 - atomic_set(&data->interrupt_handled, 0);
30173 + atomic_set_unchecked(&data->interrupt_handled, 0);
30174
30175 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30176 if (gpio_get_value(data->pdata->gpio_data) == 0) {
30177 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
30178 /* Only relevant if the interrupt hasn't occurred. */
30179 - if (!atomic_read(&data->interrupt_handled))
30180 + if (!atomic_read_unchecked(&data->interrupt_handled))
30181 schedule_work(&data->read_work);
30182 }
30183 ret = wait_event_timeout(data->wait_queue,
30184 @@ -399,7 +399,7 @@ static irqreturn_t sht15_interrupt_fired
30185 struct sht15_data *data = d;
30186 /* First disable the interrupt */
30187 disable_irq_nosync(irq);
30188 - atomic_inc(&data->interrupt_handled);
30189 + atomic_inc_unchecked(&data->interrupt_handled);
30190 /* Then schedule a reading work struct */
30191 if (data->flag != SHT15_READING_NOTHING)
30192 schedule_work(&data->read_work);
30193 @@ -450,11 +450,11 @@ static void sht15_bh_read_data(struct wo
30194 here as could have gone low in meantime so verify
30195 it hasn't!
30196 */
30197 - atomic_set(&data->interrupt_handled, 0);
30198 + atomic_set_unchecked(&data->interrupt_handled, 0);
30199 enable_irq(gpio_to_irq(data->pdata->gpio_data));
30200 /* If still not occurred or another handler has been scheduled */
30201 if (gpio_get_value(data->pdata->gpio_data)
30202 - || atomic_read(&data->interrupt_handled))
30203 + || atomic_read_unchecked(&data->interrupt_handled))
30204 return;
30205 }
30206 /* Read the data back from the device */
30207 diff -urNp linux-2.6.39.2/drivers/hwmon/w83791d.c linux-2.6.39.2/drivers/hwmon/w83791d.c
30208 --- linux-2.6.39.2/drivers/hwmon/w83791d.c 2011-05-19 00:06:34.000000000 -0400
30209 +++ linux-2.6.39.2/drivers/hwmon/w83791d.c 2011-05-22 19:36:31.000000000 -0400
30210 @@ -329,8 +329,8 @@ static int w83791d_detect(struct i2c_cli
30211 struct i2c_board_info *info);
30212 static int w83791d_remove(struct i2c_client *client);
30213
30214 -static int w83791d_read(struct i2c_client *client, u8 register);
30215 -static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
30216 +static int w83791d_read(struct i2c_client *client, u8 reg);
30217 +static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
30218 static struct w83791d_data *w83791d_update_device(struct device *dev);
30219
30220 #ifdef DEBUG
30221 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-at91.c linux-2.6.39.2/drivers/i2c/busses/i2c-at91.c
30222 --- linux-2.6.39.2/drivers/i2c/busses/i2c-at91.c 2011-05-19 00:06:34.000000000 -0400
30223 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-at91.c 2011-05-22 19:36:31.000000000 -0400
30224 @@ -181,7 +181,7 @@ static u32 at91_func(struct i2c_adapter
30225 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30226 }
30227
30228 -static struct i2c_algorithm at91_algorithm = {
30229 +static const struct i2c_algorithm at91_algorithm = {
30230 .master_xfer = at91_xfer,
30231 .functionality = at91_func,
30232 };
30233 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-bfin-twi.c linux-2.6.39.2/drivers/i2c/busses/i2c-bfin-twi.c
30234 --- linux-2.6.39.2/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-19 00:06:34.000000000 -0400
30235 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-bfin-twi.c 2011-05-22 19:36:31.000000000 -0400
30236 @@ -599,7 +599,7 @@ static u32 bfin_twi_functionality(struct
30237 I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK;
30238 }
30239
30240 -static struct i2c_algorithm bfin_twi_algorithm = {
30241 +static const struct i2c_algorithm bfin_twi_algorithm = {
30242 .master_xfer = bfin_twi_master_xfer,
30243 .smbus_xfer = bfin_twi_smbus_xfer,
30244 .functionality = bfin_twi_functionality,
30245 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-davinci.c linux-2.6.39.2/drivers/i2c/busses/i2c-davinci.c
30246 --- linux-2.6.39.2/drivers/i2c/busses/i2c-davinci.c 2011-05-19 00:06:34.000000000 -0400
30247 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-davinci.c 2011-05-22 19:36:31.000000000 -0400
30248 @@ -630,7 +630,7 @@ static inline void i2c_davinci_cpufreq_d
30249 }
30250 #endif
30251
30252 -static struct i2c_algorithm i2c_davinci_algo = {
30253 +static const struct i2c_algorithm i2c_davinci_algo = {
30254 .master_xfer = i2c_davinci_xfer,
30255 .functionality = i2c_davinci_func,
30256 };
30257 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-designware.c linux-2.6.39.2/drivers/i2c/busses/i2c-designware.c
30258 --- linux-2.6.39.2/drivers/i2c/busses/i2c-designware.c 2011-05-19 00:06:34.000000000 -0400
30259 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-designware.c 2011-05-22 19:36:31.000000000 -0400
30260 @@ -689,7 +689,7 @@ tx_aborted:
30261 return IRQ_HANDLED;
30262 }
30263
30264 -static struct i2c_algorithm i2c_dw_algo = {
30265 +static const struct i2c_algorithm i2c_dw_algo = {
30266 .master_xfer = i2c_dw_xfer,
30267 .functionality = i2c_dw_func,
30268 };
30269 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-eg20t.c linux-2.6.39.2/drivers/i2c/busses/i2c-eg20t.c
30270 --- linux-2.6.39.2/drivers/i2c/busses/i2c-eg20t.c 2011-05-19 00:06:34.000000000 -0400
30271 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-eg20t.c 2011-05-22 19:36:31.000000000 -0400
30272 @@ -708,7 +708,7 @@ static u32 pch_i2c_func(struct i2c_adapt
30273 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
30274 }
30275
30276 -static struct i2c_algorithm pch_algorithm = {
30277 +static const struct i2c_algorithm pch_algorithm = {
30278 .master_xfer = pch_i2c_xfer,
30279 .functionality = pch_i2c_func
30280 };
30281 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-imx.c linux-2.6.39.2/drivers/i2c/busses/i2c-imx.c
30282 --- linux-2.6.39.2/drivers/i2c/busses/i2c-imx.c 2011-05-19 00:06:34.000000000 -0400
30283 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-imx.c 2011-05-22 19:36:31.000000000 -0400
30284 @@ -457,7 +457,7 @@ static u32 i2c_imx_func(struct i2c_adapt
30285 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30286 }
30287
30288 -static struct i2c_algorithm i2c_imx_algo = {
30289 +static const struct i2c_algorithm i2c_imx_algo = {
30290 .master_xfer = i2c_imx_xfer,
30291 .functionality = i2c_imx_func,
30292 };
30293 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-intel-mid.c linux-2.6.39.2/drivers/i2c/busses/i2c-intel-mid.c
30294 --- linux-2.6.39.2/drivers/i2c/busses/i2c-intel-mid.c 2011-05-19 00:06:34.000000000 -0400
30295 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-intel-mid.c 2011-05-22 19:36:31.000000000 -0400
30296 @@ -917,7 +917,7 @@ err:
30297 return IRQ_HANDLED;
30298 }
30299
30300 -static struct i2c_algorithm intel_mid_i2c_algorithm = {
30301 +static const struct i2c_algorithm intel_mid_i2c_algorithm = {
30302 .master_xfer = intel_mid_i2c_xfer,
30303 .functionality = intel_mid_i2c_func,
30304 };
30305 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-nforce2.c linux-2.6.39.2/drivers/i2c/busses/i2c-nforce2.c
30306 --- linux-2.6.39.2/drivers/i2c/busses/i2c-nforce2.c 2011-05-19 00:06:34.000000000 -0400
30307 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-nforce2.c 2011-05-22 19:36:31.000000000 -0400
30308 @@ -303,7 +303,7 @@ static u32 nforce2_func(struct i2c_adapt
30309 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
30310 }
30311
30312 -static struct i2c_algorithm smbus_algorithm = {
30313 +static const struct i2c_algorithm smbus_algorithm = {
30314 .smbus_xfer = nforce2_access,
30315 .functionality = nforce2_func,
30316 };
30317 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-pmcmsp.c linux-2.6.39.2/drivers/i2c/busses/i2c-pmcmsp.c
30318 --- linux-2.6.39.2/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-19 00:06:34.000000000 -0400
30319 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-pmcmsp.c 2011-05-22 19:36:31.000000000 -0400
30320 @@ -615,7 +615,7 @@ static u32 pmcmsptwi_i2c_func(struct i2c
30321
30322 /* -- Initialization -- */
30323
30324 -static struct i2c_algorithm pmcmsptwi_algo = {
30325 +static const struct i2c_algorithm pmcmsptwi_algo = {
30326 .master_xfer = pmcmsptwi_master_xfer,
30327 .functionality = pmcmsptwi_i2c_func,
30328 };
30329 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-pnx.c linux-2.6.39.2/drivers/i2c/busses/i2c-pnx.c
30330 --- linux-2.6.39.2/drivers/i2c/busses/i2c-pnx.c 2011-05-19 00:06:34.000000000 -0400
30331 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-pnx.c 2011-05-22 19:36:31.000000000 -0400
30332 @@ -535,7 +535,7 @@ static u32 i2c_pnx_func(struct i2c_adapt
30333 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30334 }
30335
30336 -static struct i2c_algorithm pnx_algorithm = {
30337 +static const struct i2c_algorithm pnx_algorithm = {
30338 .master_xfer = i2c_pnx_xfer,
30339 .functionality = i2c_pnx_func,
30340 };
30341 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-puv3.c linux-2.6.39.2/drivers/i2c/busses/i2c-puv3.c
30342 --- linux-2.6.39.2/drivers/i2c/busses/i2c-puv3.c 2011-05-19 00:06:34.000000000 -0400
30343 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-puv3.c 2011-05-22 19:36:31.000000000 -0400
30344 @@ -176,7 +176,7 @@ static u32 puv3_i2c_func(struct i2c_adap
30345 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30346 }
30347
30348 -static struct i2c_algorithm puv3_i2c_algorithm = {
30349 +static const struct i2c_algorithm puv3_i2c_algorithm = {
30350 .master_xfer = puv3_i2c_xfer,
30351 .functionality = puv3_i2c_func,
30352 };
30353 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-s6000.c linux-2.6.39.2/drivers/i2c/busses/i2c-s6000.c
30354 --- linux-2.6.39.2/drivers/i2c/busses/i2c-s6000.c 2011-05-19 00:06:34.000000000 -0400
30355 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-s6000.c 2011-05-22 19:36:31.000000000 -0400
30356 @@ -243,7 +243,7 @@ static u32 s6i2c_functionality(struct i2
30357 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30358 }
30359
30360 -static struct i2c_algorithm s6i2c_algorithm = {
30361 +static const struct i2c_algorithm s6i2c_algorithm = {
30362 .master_xfer = s6i2c_master_xfer,
30363 .functionality = s6i2c_functionality,
30364 };
30365 diff -urNp linux-2.6.39.2/drivers/i2c/busses/i2c-sh_mobile.c linux-2.6.39.2/drivers/i2c/busses/i2c-sh_mobile.c
30366 --- linux-2.6.39.2/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-19 00:06:34.000000000 -0400
30367 +++ linux-2.6.39.2/drivers/i2c/busses/i2c-sh_mobile.c 2011-05-22 19:36:31.000000000 -0400
30368 @@ -529,7 +529,7 @@ static u32 sh_mobile_i2c_func(struct i2c
30369 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
30370 }
30371
30372 -static struct i2c_algorithm sh_mobile_i2c_algorithm = {
30373 +static const struct i2c_algorithm sh_mobile_i2c_algorithm = {
30374 .functionality = sh_mobile_i2c_func,
30375 .master_xfer = sh_mobile_i2c_xfer,
30376 };
30377 diff -urNp linux-2.6.39.2/drivers/ide/ide-cd.c linux-2.6.39.2/drivers/ide/ide-cd.c
30378 --- linux-2.6.39.2/drivers/ide/ide-cd.c 2011-06-03 00:04:14.000000000 -0400
30379 +++ linux-2.6.39.2/drivers/ide/ide-cd.c 2011-06-03 00:32:05.000000000 -0400
30380 @@ -769,7 +769,7 @@ static void cdrom_do_block_pc(ide_drive_
30381 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
30382 if ((unsigned long)buf & alignment
30383 || blk_rq_bytes(rq) & q->dma_pad_mask
30384 - || object_is_on_stack(buf))
30385 + || object_starts_on_stack(buf))
30386 drive->dma = 0;
30387 }
30388 }
30389 diff -urNp linux-2.6.39.2/drivers/ide/ide-floppy.c linux-2.6.39.2/drivers/ide/ide-floppy.c
30390 --- linux-2.6.39.2/drivers/ide/ide-floppy.c 2011-05-19 00:06:34.000000000 -0400
30391 +++ linux-2.6.39.2/drivers/ide/ide-floppy.c 2011-05-22 19:36:31.000000000 -0400
30392 @@ -379,6 +379,8 @@ static int ide_floppy_get_capacity(ide_d
30393 u8 pc_buf[256], header_len, desc_cnt;
30394 int i, rc = 1, blocks, length;
30395
30396 + pax_track_stack();
30397 +
30398 ide_debug_log(IDE_DBG_FUNC, "enter");
30399
30400 drive->bios_cyl = 0;
30401 diff -urNp linux-2.6.39.2/drivers/ide/it821x.c linux-2.6.39.2/drivers/ide/it821x.c
30402 --- linux-2.6.39.2/drivers/ide/it821x.c 2011-05-19 00:06:34.000000000 -0400
30403 +++ linux-2.6.39.2/drivers/ide/it821x.c 2011-05-22 19:36:31.000000000 -0400
30404 @@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t
30405
30406 }
30407
30408 -static struct ide_dma_ops it821x_pass_through_dma_ops = {
30409 +static const struct ide_dma_ops it821x_pass_through_dma_ops = {
30410 .dma_host_set = ide_dma_host_set,
30411 .dma_setup = ide_dma_setup,
30412 .dma_start = it821x_dma_start,
30413 diff -urNp linux-2.6.39.2/drivers/ide/setup-pci.c linux-2.6.39.2/drivers/ide/setup-pci.c
30414 --- linux-2.6.39.2/drivers/ide/setup-pci.c 2011-05-19 00:06:34.000000000 -0400
30415 +++ linux-2.6.39.2/drivers/ide/setup-pci.c 2011-05-22 19:36:31.000000000 -0400
30416 @@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev
30417 int ret, i, n_ports = dev2 ? 4 : 2;
30418 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
30419
30420 + pax_track_stack();
30421 +
30422 for (i = 0; i < n_ports / 2; i++) {
30423 ret = ide_setup_pci_controller(pdev[i], d, !i);
30424 if (ret < 0)
30425 diff -urNp linux-2.6.39.2/drivers/ide/trm290.c linux-2.6.39.2/drivers/ide/trm290.c
30426 --- linux-2.6.39.2/drivers/ide/trm290.c 2011-05-19 00:06:34.000000000 -0400
30427 +++ linux-2.6.39.2/drivers/ide/trm290.c 2011-05-22 19:36:31.000000000 -0400
30428 @@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp
30429 .output_data = ide_output_data,
30430 };
30431
30432 -static struct ide_dma_ops trm290_dma_ops = {
30433 +static const struct ide_dma_ops trm290_dma_ops = {
30434 .dma_host_set = trm290_dma_host_set,
30435 .dma_setup = trm290_dma_setup,
30436 .dma_start = trm290_dma_start,
30437 diff -urNp linux-2.6.39.2/drivers/infiniband/core/cm.c linux-2.6.39.2/drivers/infiniband/core/cm.c
30438 --- linux-2.6.39.2/drivers/infiniband/core/cm.c 2011-05-19 00:06:34.000000000 -0400
30439 +++ linux-2.6.39.2/drivers/infiniband/core/cm.c 2011-05-22 19:36:31.000000000 -0400
30440 @@ -113,7 +113,7 @@ static char const counter_group_names[CM
30441
30442 struct cm_counter_group {
30443 struct kobject obj;
30444 - atomic_long_t counter[CM_ATTR_COUNT];
30445 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30446 };
30447
30448 struct cm_counter_attribute {
30449 @@ -1387,7 +1387,7 @@ static void cm_dup_req_handler(struct cm
30450 struct ib_mad_send_buf *msg = NULL;
30451 int ret;
30452
30453 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30454 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30455 counter[CM_REQ_COUNTER]);
30456
30457 /* Quick state check to discard duplicate REQs. */
30458 @@ -1765,7 +1765,7 @@ static void cm_dup_rep_handler(struct cm
30459 if (!cm_id_priv)
30460 return;
30461
30462 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30463 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30464 counter[CM_REP_COUNTER]);
30465 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30466 if (ret)
30467 @@ -1932,7 +1932,7 @@ static int cm_rtu_handler(struct cm_work
30468 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30469 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30470 spin_unlock_irq(&cm_id_priv->lock);
30471 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30472 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30473 counter[CM_RTU_COUNTER]);
30474 goto out;
30475 }
30476 @@ -2115,7 +2115,7 @@ static int cm_dreq_handler(struct cm_wor
30477 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30478 dreq_msg->local_comm_id);
30479 if (!cm_id_priv) {
30480 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30481 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30482 counter[CM_DREQ_COUNTER]);
30483 cm_issue_drep(work->port, work->mad_recv_wc);
30484 return -EINVAL;
30485 @@ -2140,7 +2140,7 @@ static int cm_dreq_handler(struct cm_wor
30486 case IB_CM_MRA_REP_RCVD:
30487 break;
30488 case IB_CM_TIMEWAIT:
30489 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30490 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30491 counter[CM_DREQ_COUNTER]);
30492 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30493 goto unlock;
30494 @@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_wor
30495 cm_free_msg(msg);
30496 goto deref;
30497 case IB_CM_DREQ_RCVD:
30498 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30499 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30500 counter[CM_DREQ_COUNTER]);
30501 goto unlock;
30502 default:
30503 @@ -2521,7 +2521,7 @@ static int cm_mra_handler(struct cm_work
30504 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30505 cm_id_priv->msg, timeout)) {
30506 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30507 - atomic_long_inc(&work->port->
30508 + atomic_long_inc_unchecked(&work->port->
30509 counter_group[CM_RECV_DUPLICATES].
30510 counter[CM_MRA_COUNTER]);
30511 goto out;
30512 @@ -2530,7 +2530,7 @@ static int cm_mra_handler(struct cm_work
30513 break;
30514 case IB_CM_MRA_REQ_RCVD:
30515 case IB_CM_MRA_REP_RCVD:
30516 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30517 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30518 counter[CM_MRA_COUNTER]);
30519 /* fall through */
30520 default:
30521 @@ -2692,7 +2692,7 @@ static int cm_lap_handler(struct cm_work
30522 case IB_CM_LAP_IDLE:
30523 break;
30524 case IB_CM_MRA_LAP_SENT:
30525 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30526 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30527 counter[CM_LAP_COUNTER]);
30528 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30529 goto unlock;
30530 @@ -2708,7 +2708,7 @@ static int cm_lap_handler(struct cm_work
30531 cm_free_msg(msg);
30532 goto deref;
30533 case IB_CM_LAP_RCVD:
30534 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30535 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30536 counter[CM_LAP_COUNTER]);
30537 goto unlock;
30538 default:
30539 @@ -2992,7 +2992,7 @@ static int cm_sidr_req_handler(struct cm
30540 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30541 if (cur_cm_id_priv) {
30542 spin_unlock_irq(&cm.lock);
30543 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30544 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30545 counter[CM_SIDR_REQ_COUNTER]);
30546 goto out; /* Duplicate message. */
30547 }
30548 @@ -3204,10 +3204,10 @@ static void cm_send_handler(struct ib_ma
30549 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30550 msg->retries = 1;
30551
30552 - atomic_long_add(1 + msg->retries,
30553 + atomic_long_add_unchecked(1 + msg->retries,
30554 &port->counter_group[CM_XMIT].counter[attr_index]);
30555 if (msg->retries)
30556 - atomic_long_add(msg->retries,
30557 + atomic_long_add_unchecked(msg->retries,
30558 &port->counter_group[CM_XMIT_RETRIES].
30559 counter[attr_index]);
30560
30561 @@ -3417,7 +3417,7 @@ static void cm_recv_handler(struct ib_ma
30562 }
30563
30564 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30565 - atomic_long_inc(&port->counter_group[CM_RECV].
30566 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30567 counter[attr_id - CM_ATTR_ID_OFFSET]);
30568
30569 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30570 @@ -3615,7 +3615,7 @@ static ssize_t cm_show_counter(struct ko
30571 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30572
30573 return sprintf(buf, "%ld\n",
30574 - atomic_long_read(&group->counter[cm_attr->index]));
30575 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30576 }
30577
30578 static const struct sysfs_ops cm_counter_ops = {
30579 diff -urNp linux-2.6.39.2/drivers/infiniband/core/fmr_pool.c linux-2.6.39.2/drivers/infiniband/core/fmr_pool.c
30580 --- linux-2.6.39.2/drivers/infiniband/core/fmr_pool.c 2011-05-19 00:06:34.000000000 -0400
30581 +++ linux-2.6.39.2/drivers/infiniband/core/fmr_pool.c 2011-05-22 19:36:31.000000000 -0400
30582 @@ -97,8 +97,8 @@ struct ib_fmr_pool {
30583
30584 struct task_struct *thread;
30585
30586 - atomic_t req_ser;
30587 - atomic_t flush_ser;
30588 + atomic_unchecked_t req_ser;
30589 + atomic_unchecked_t flush_ser;
30590
30591 wait_queue_head_t force_wait;
30592 };
30593 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *p
30594 struct ib_fmr_pool *pool = pool_ptr;
30595
30596 do {
30597 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30598 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30599 ib_fmr_batch_release(pool);
30600
30601 - atomic_inc(&pool->flush_ser);
30602 + atomic_inc_unchecked(&pool->flush_ser);
30603 wake_up_interruptible(&pool->force_wait);
30604
30605 if (pool->flush_function)
30606 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *p
30607 }
30608
30609 set_current_state(TASK_INTERRUPTIBLE);
30610 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30611 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30612 !kthread_should_stop())
30613 schedule();
30614 __set_current_state(TASK_RUNNING);
30615 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(s
30616 pool->dirty_watermark = params->dirty_watermark;
30617 pool->dirty_len = 0;
30618 spin_lock_init(&pool->pool_lock);
30619 - atomic_set(&pool->req_ser, 0);
30620 - atomic_set(&pool->flush_ser, 0);
30621 + atomic_set_unchecked(&pool->req_ser, 0);
30622 + atomic_set_unchecked(&pool->flush_ser, 0);
30623 init_waitqueue_head(&pool->force_wait);
30624
30625 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30626 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool
30627 }
30628 spin_unlock_irq(&pool->pool_lock);
30629
30630 - serial = atomic_inc_return(&pool->req_ser);
30631 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30632 wake_up_process(pool->thread);
30633
30634 if (wait_event_interruptible(pool->force_wait,
30635 - atomic_read(&pool->flush_ser) - serial >= 0))
30636 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30637 return -EINTR;
30638
30639 return 0;
30640 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr
30641 } else {
30642 list_add_tail(&fmr->list, &pool->dirty_list);
30643 if (++pool->dirty_len >= pool->dirty_watermark) {
30644 - atomic_inc(&pool->req_ser);
30645 + atomic_inc_unchecked(&pool->req_ser);
30646 wake_up_process(pool->thread);
30647 }
30648 }
30649 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/cxgb4/mem.c linux-2.6.39.2/drivers/infiniband/hw/cxgb4/mem.c
30650 --- linux-2.6.39.2/drivers/infiniband/hw/cxgb4/mem.c 2011-05-19 00:06:34.000000000 -0400
30651 +++ linux-2.6.39.2/drivers/infiniband/hw/cxgb4/mem.c 2011-05-22 19:36:31.000000000 -0400
30652 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_r
30653 int err;
30654 struct fw_ri_tpte tpt;
30655 u32 stag_idx;
30656 - static atomic_t key;
30657 + static atomic_unchecked_t key;
30658
30659 if (c4iw_fatal_error(rdev))
30660 return -EIO;
30661 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_r
30662 &rdev->resource.tpt_fifo_lock);
30663 if (!stag_idx)
30664 return -ENOMEM;
30665 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30666 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30667 }
30668 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30669 __func__, stag_state, type, pdid, stag_idx);
30670 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_dma.c linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_dma.c
30671 --- linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-19 00:06:34.000000000 -0400
30672 +++ linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_dma.c 2011-05-22 19:36:31.000000000 -0400
30673 @@ -175,7 +175,7 @@ static void ipath_dma_free_coherent(stru
30674 free_pages((unsigned long) cpu_addr, get_order(size));
30675 }
30676
30677 -struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30678 +const struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
30679 ipath_mapping_error,
30680 ipath_dma_map_single,
30681 ipath_dma_unmap_single,
30682 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_fs.c linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_fs.c
30683 --- linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-19 00:06:34.000000000 -0400
30684 +++ linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_fs.c 2011-05-22 19:36:31.000000000 -0400
30685 @@ -113,6 +113,8 @@ static ssize_t atomic_counters_read(stru
30686 struct infinipath_counters counters;
30687 struct ipath_devdata *dd;
30688
30689 + pax_track_stack();
30690 +
30691 dd = file->f_path.dentry->d_inode->i_private;
30692 dd->ipath_f_read_counters(dd, &counters);
30693
30694 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_rc.c linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_rc.c
30695 --- linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-19 00:06:34.000000000 -0400
30696 +++ linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_rc.c 2011-05-22 19:36:31.000000000 -0400
30697 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30698 struct ib_atomic_eth *ateth;
30699 struct ipath_ack_entry *e;
30700 u64 vaddr;
30701 - atomic64_t *maddr;
30702 + atomic64_unchecked_t *maddr;
30703 u64 sdata;
30704 u32 rkey;
30705 u8 next;
30706 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *de
30707 IB_ACCESS_REMOTE_ATOMIC)))
30708 goto nack_acc_unlck;
30709 /* Perform atomic OP and save result. */
30710 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30711 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30712 sdata = be64_to_cpu(ateth->swap_data);
30713 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30714 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30715 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30716 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30717 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30718 be64_to_cpu(ateth->compare_data),
30719 sdata);
30720 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_ruc.c linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_ruc.c
30721 --- linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-19 00:06:34.000000000 -0400
30722 +++ linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_ruc.c 2011-05-22 19:36:31.000000000 -0400
30723 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ip
30724 unsigned long flags;
30725 struct ib_wc wc;
30726 u64 sdata;
30727 - atomic64_t *maddr;
30728 + atomic64_unchecked_t *maddr;
30729 enum ib_wc_status send_status;
30730
30731 /*
30732 @@ -382,11 +382,11 @@ again:
30733 IB_ACCESS_REMOTE_ATOMIC)))
30734 goto acc_err;
30735 /* Perform atomic OP and save result. */
30736 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30737 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30738 sdata = wqe->wr.wr.atomic.compare_add;
30739 *(u64 *) sqp->s_sge.sge.vaddr =
30740 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30741 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30742 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30743 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30744 sdata, wqe->wr.wr.atomic.swap);
30745 goto send_comp;
30746 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_verbs.h linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_verbs.h
30747 --- linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-19 00:06:34.000000000 -0400
30748 +++ linux-2.6.39.2/drivers/infiniband/hw/ipath/ipath_verbs.h 2011-05-22 19:36:31.000000000 -0400
30749 @@ -931,6 +931,6 @@ extern unsigned int ib_ipath_max_srq_wrs
30750
30751 extern const u32 ib_ipath_rnr_table[];
30752
30753 -extern struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30754 +extern const struct ib_dma_mapping_ops ipath_dma_mapping_ops;
30755
30756 #endif /* IPATH_VERBS_H */
30757 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/nes/nes.c linux-2.6.39.2/drivers/infiniband/hw/nes/nes.c
30758 --- linux-2.6.39.2/drivers/infiniband/hw/nes/nes.c 2011-05-19 00:06:34.000000000 -0400
30759 +++ linux-2.6.39.2/drivers/infiniband/hw/nes/nes.c 2011-05-22 19:36:31.000000000 -0400
30760 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limi
30761 LIST_HEAD(nes_adapter_list);
30762 static LIST_HEAD(nes_dev_list);
30763
30764 -atomic_t qps_destroyed;
30765 +atomic_unchecked_t qps_destroyed;
30766
30767 static unsigned int ee_flsh_adapter;
30768 static unsigned int sysfs_nonidx_addr;
30769 @@ -275,7 +275,7 @@ static void nes_cqp_rem_ref_callback(str
30770 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30771 struct nes_adapter *nesadapter = nesdev->nesadapter;
30772
30773 - atomic_inc(&qps_destroyed);
30774 + atomic_inc_unchecked(&qps_destroyed);
30775
30776 /* Free the control structures */
30777
30778 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/nes/nes_cm.c linux-2.6.39.2/drivers/infiniband/hw/nes/nes_cm.c
30779 --- linux-2.6.39.2/drivers/infiniband/hw/nes/nes_cm.c 2011-05-19 00:06:34.000000000 -0400
30780 +++ linux-2.6.39.2/drivers/infiniband/hw/nes/nes_cm.c 2011-05-22 19:36:31.000000000 -0400
30781 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30782 u32 cm_packets_retrans;
30783 u32 cm_packets_created;
30784 u32 cm_packets_received;
30785 -atomic_t cm_listens_created;
30786 -atomic_t cm_listens_destroyed;
30787 +atomic_unchecked_t cm_listens_created;
30788 +atomic_unchecked_t cm_listens_destroyed;
30789 u32 cm_backlog_drops;
30790 -atomic_t cm_loopbacks;
30791 -atomic_t cm_nodes_created;
30792 -atomic_t cm_nodes_destroyed;
30793 -atomic_t cm_accel_dropped_pkts;
30794 -atomic_t cm_resets_recvd;
30795 +atomic_unchecked_t cm_loopbacks;
30796 +atomic_unchecked_t cm_nodes_created;
30797 +atomic_unchecked_t cm_nodes_destroyed;
30798 +atomic_unchecked_t cm_accel_dropped_pkts;
30799 +atomic_unchecked_t cm_resets_recvd;
30800
30801 static inline int mini_cm_accelerated(struct nes_cm_core *,
30802 struct nes_cm_node *);
30803 @@ -151,13 +151,13 @@ static struct nes_cm_ops nes_cm_api = {
30804
30805 static struct nes_cm_core *g_cm_core;
30806
30807 -atomic_t cm_connects;
30808 -atomic_t cm_accepts;
30809 -atomic_t cm_disconnects;
30810 -atomic_t cm_closes;
30811 -atomic_t cm_connecteds;
30812 -atomic_t cm_connect_reqs;
30813 -atomic_t cm_rejects;
30814 +atomic_unchecked_t cm_connects;
30815 +atomic_unchecked_t cm_accepts;
30816 +atomic_unchecked_t cm_disconnects;
30817 +atomic_unchecked_t cm_closes;
30818 +atomic_unchecked_t cm_connecteds;
30819 +atomic_unchecked_t cm_connect_reqs;
30820 +atomic_unchecked_t cm_rejects;
30821
30822
30823 /**
30824 @@ -1045,7 +1045,7 @@ static int mini_cm_dec_refcnt_listen(str
30825 kfree(listener);
30826 listener = NULL;
30827 ret = 0;
30828 - atomic_inc(&cm_listens_destroyed);
30829 + atomic_inc_unchecked(&cm_listens_destroyed);
30830 } else {
30831 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30832 }
30833 @@ -1240,7 +1240,7 @@ static struct nes_cm_node *make_cm_node(
30834 cm_node->rem_mac);
30835
30836 add_hte_node(cm_core, cm_node);
30837 - atomic_inc(&cm_nodes_created);
30838 + atomic_inc_unchecked(&cm_nodes_created);
30839
30840 return cm_node;
30841 }
30842 @@ -1298,7 +1298,7 @@ static int rem_ref_cm_node(struct nes_cm
30843 }
30844
30845 atomic_dec(&cm_core->node_cnt);
30846 - atomic_inc(&cm_nodes_destroyed);
30847 + atomic_inc_unchecked(&cm_nodes_destroyed);
30848 nesqp = cm_node->nesqp;
30849 if (nesqp) {
30850 nesqp->cm_node = NULL;
30851 @@ -1365,7 +1365,7 @@ static int process_options(struct nes_cm
30852
30853 static void drop_packet(struct sk_buff *skb)
30854 {
30855 - atomic_inc(&cm_accel_dropped_pkts);
30856 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30857 dev_kfree_skb_any(skb);
30858 }
30859
30860 @@ -1428,7 +1428,7 @@ static void handle_rst_pkt(struct nes_cm
30861 {
30862
30863 int reset = 0; /* whether to send reset in case of err.. */
30864 - atomic_inc(&cm_resets_recvd);
30865 + atomic_inc_unchecked(&cm_resets_recvd);
30866 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30867 " refcnt=%d\n", cm_node, cm_node->state,
30868 atomic_read(&cm_node->ref_count));
30869 @@ -2057,7 +2057,7 @@ static struct nes_cm_node *mini_cm_conne
30870 rem_ref_cm_node(cm_node->cm_core, cm_node);
30871 return NULL;
30872 }
30873 - atomic_inc(&cm_loopbacks);
30874 + atomic_inc_unchecked(&cm_loopbacks);
30875 loopbackremotenode->loopbackpartner = cm_node;
30876 loopbackremotenode->tcp_cntxt.rcv_wscale =
30877 NES_CM_DEFAULT_RCV_WND_SCALE;
30878 @@ -2332,7 +2332,7 @@ static int mini_cm_recv_pkt(struct nes_c
30879 add_ref_cm_node(cm_node);
30880 } else if (cm_node->state == NES_CM_STATE_TSA) {
30881 rem_ref_cm_node(cm_core, cm_node);
30882 - atomic_inc(&cm_accel_dropped_pkts);
30883 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30884 dev_kfree_skb_any(skb);
30885 break;
30886 }
30887 @@ -2638,7 +2638,7 @@ static int nes_cm_disconn_true(struct ne
30888
30889 if ((cm_id) && (cm_id->event_handler)) {
30890 if (issue_disconn) {
30891 - atomic_inc(&cm_disconnects);
30892 + atomic_inc_unchecked(&cm_disconnects);
30893 cm_event.event = IW_CM_EVENT_DISCONNECT;
30894 cm_event.status = disconn_status;
30895 cm_event.local_addr = cm_id->local_addr;
30896 @@ -2660,7 +2660,7 @@ static int nes_cm_disconn_true(struct ne
30897 }
30898
30899 if (issue_close) {
30900 - atomic_inc(&cm_closes);
30901 + atomic_inc_unchecked(&cm_closes);
30902 nes_disconnect(nesqp, 1);
30903
30904 cm_id->provider_data = nesqp;
30905 @@ -2791,7 +2791,7 @@ int nes_accept(struct iw_cm_id *cm_id, s
30906
30907 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30908 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30909 - atomic_inc(&cm_accepts);
30910 + atomic_inc_unchecked(&cm_accepts);
30911
30912 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30913 netdev_refcnt_read(nesvnic->netdev));
30914 @@ -3001,7 +3001,7 @@ int nes_reject(struct iw_cm_id *cm_id, c
30915
30916 struct nes_cm_core *cm_core;
30917
30918 - atomic_inc(&cm_rejects);
30919 + atomic_inc_unchecked(&cm_rejects);
30920 cm_node = (struct nes_cm_node *) cm_id->provider_data;
30921 loopback = cm_node->loopbackpartner;
30922 cm_core = cm_node->cm_core;
30923 @@ -3067,7 +3067,7 @@ int nes_connect(struct iw_cm_id *cm_id,
30924 ntohl(cm_id->local_addr.sin_addr.s_addr),
30925 ntohs(cm_id->local_addr.sin_port));
30926
30927 - atomic_inc(&cm_connects);
30928 + atomic_inc_unchecked(&cm_connects);
30929 nesqp->active_conn = 1;
30930
30931 /* cache the cm_id in the qp */
30932 @@ -3173,7 +3173,7 @@ int nes_create_listen(struct iw_cm_id *c
30933 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30934 return err;
30935 }
30936 - atomic_inc(&cm_listens_created);
30937 + atomic_inc_unchecked(&cm_listens_created);
30938 }
30939
30940 cm_id->add_ref(cm_id);
30941 @@ -3278,7 +3278,7 @@ static void cm_event_connected(struct ne
30942 if (nesqp->destroyed) {
30943 return;
30944 }
30945 - atomic_inc(&cm_connecteds);
30946 + atomic_inc_unchecked(&cm_connecteds);
30947 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30948 " local port 0x%04X. jiffies = %lu.\n",
30949 nesqp->hwqp.qp_id,
30950 @@ -3493,7 +3493,7 @@ static void cm_event_reset(struct nes_cm
30951
30952 cm_id->add_ref(cm_id);
30953 ret = cm_id->event_handler(cm_id, &cm_event);
30954 - atomic_inc(&cm_closes);
30955 + atomic_inc_unchecked(&cm_closes);
30956 cm_event.event = IW_CM_EVENT_CLOSE;
30957 cm_event.status = IW_CM_EVENT_STATUS_OK;
30958 cm_event.provider_data = cm_id->provider_data;
30959 @@ -3529,7 +3529,7 @@ static void cm_event_mpa_req(struct nes_
30960 return;
30961 cm_id = cm_node->cm_id;
30962
30963 - atomic_inc(&cm_connect_reqs);
30964 + atomic_inc_unchecked(&cm_connect_reqs);
30965 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30966 cm_node, cm_id, jiffies);
30967
30968 @@ -3567,7 +3567,7 @@ static void cm_event_mpa_reject(struct n
30969 return;
30970 cm_id = cm_node->cm_id;
30971
30972 - atomic_inc(&cm_connect_reqs);
30973 + atomic_inc_unchecked(&cm_connect_reqs);
30974 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30975 cm_node, cm_id, jiffies);
30976
30977 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/nes/nes.h linux-2.6.39.2/drivers/infiniband/hw/nes/nes.h
30978 --- linux-2.6.39.2/drivers/infiniband/hw/nes/nes.h 2011-05-19 00:06:34.000000000 -0400
30979 +++ linux-2.6.39.2/drivers/infiniband/hw/nes/nes.h 2011-05-22 19:36:31.000000000 -0400
30980 @@ -175,17 +175,17 @@ extern unsigned int nes_debug_level;
30981 extern unsigned int wqm_quanta;
30982 extern struct list_head nes_adapter_list;
30983
30984 -extern atomic_t cm_connects;
30985 -extern atomic_t cm_accepts;
30986 -extern atomic_t cm_disconnects;
30987 -extern atomic_t cm_closes;
30988 -extern atomic_t cm_connecteds;
30989 -extern atomic_t cm_connect_reqs;
30990 -extern atomic_t cm_rejects;
30991 -extern atomic_t mod_qp_timouts;
30992 -extern atomic_t qps_created;
30993 -extern atomic_t qps_destroyed;
30994 -extern atomic_t sw_qps_destroyed;
30995 +extern atomic_unchecked_t cm_connects;
30996 +extern atomic_unchecked_t cm_accepts;
30997 +extern atomic_unchecked_t cm_disconnects;
30998 +extern atomic_unchecked_t cm_closes;
30999 +extern atomic_unchecked_t cm_connecteds;
31000 +extern atomic_unchecked_t cm_connect_reqs;
31001 +extern atomic_unchecked_t cm_rejects;
31002 +extern atomic_unchecked_t mod_qp_timouts;
31003 +extern atomic_unchecked_t qps_created;
31004 +extern atomic_unchecked_t qps_destroyed;
31005 +extern atomic_unchecked_t sw_qps_destroyed;
31006 extern u32 mh_detected;
31007 extern u32 mh_pauses_sent;
31008 extern u32 cm_packets_sent;
31009 @@ -194,14 +194,14 @@ extern u32 cm_packets_created;
31010 extern u32 cm_packets_received;
31011 extern u32 cm_packets_dropped;
31012 extern u32 cm_packets_retrans;
31013 -extern atomic_t cm_listens_created;
31014 -extern atomic_t cm_listens_destroyed;
31015 +extern atomic_unchecked_t cm_listens_created;
31016 +extern atomic_unchecked_t cm_listens_destroyed;
31017 extern u32 cm_backlog_drops;
31018 -extern atomic_t cm_loopbacks;
31019 -extern atomic_t cm_nodes_created;
31020 -extern atomic_t cm_nodes_destroyed;
31021 -extern atomic_t cm_accel_dropped_pkts;
31022 -extern atomic_t cm_resets_recvd;
31023 +extern atomic_unchecked_t cm_loopbacks;
31024 +extern atomic_unchecked_t cm_nodes_created;
31025 +extern atomic_unchecked_t cm_nodes_destroyed;
31026 +extern atomic_unchecked_t cm_accel_dropped_pkts;
31027 +extern atomic_unchecked_t cm_resets_recvd;
31028
31029 extern u32 int_mod_timer_init;
31030 extern u32 int_mod_cq_depth_256;
31031 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/nes/nes_nic.c linux-2.6.39.2/drivers/infiniband/hw/nes/nes_nic.c
31032 --- linux-2.6.39.2/drivers/infiniband/hw/nes/nes_nic.c 2011-05-19 00:06:34.000000000 -0400
31033 +++ linux-2.6.39.2/drivers/infiniband/hw/nes/nes_nic.c 2011-05-22 19:36:31.000000000 -0400
31034 @@ -1302,31 +1302,31 @@ static void nes_netdev_get_ethtool_stats
31035 target_stat_values[++index] = mh_detected;
31036 target_stat_values[++index] = mh_pauses_sent;
31037 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
31038 - target_stat_values[++index] = atomic_read(&cm_connects);
31039 - target_stat_values[++index] = atomic_read(&cm_accepts);
31040 - target_stat_values[++index] = atomic_read(&cm_disconnects);
31041 - target_stat_values[++index] = atomic_read(&cm_connecteds);
31042 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
31043 - target_stat_values[++index] = atomic_read(&cm_rejects);
31044 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
31045 - target_stat_values[++index] = atomic_read(&qps_created);
31046 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
31047 - target_stat_values[++index] = atomic_read(&qps_destroyed);
31048 - target_stat_values[++index] = atomic_read(&cm_closes);
31049 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
31050 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
31051 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
31052 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
31053 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
31054 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
31055 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
31056 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
31057 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
31058 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
31059 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
31060 target_stat_values[++index] = cm_packets_sent;
31061 target_stat_values[++index] = cm_packets_bounced;
31062 target_stat_values[++index] = cm_packets_created;
31063 target_stat_values[++index] = cm_packets_received;
31064 target_stat_values[++index] = cm_packets_dropped;
31065 target_stat_values[++index] = cm_packets_retrans;
31066 - target_stat_values[++index] = atomic_read(&cm_listens_created);
31067 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
31068 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
31069 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
31070 target_stat_values[++index] = cm_backlog_drops;
31071 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
31072 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
31073 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
31074 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
31075 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
31076 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
31077 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
31078 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
31079 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
31080 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
31081 target_stat_values[++index] = nesadapter->free_4kpbl;
31082 target_stat_values[++index] = nesadapter->free_256pbl;
31083 target_stat_values[++index] = int_mod_timer_init;
31084 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/nes/nes_verbs.c linux-2.6.39.2/drivers/infiniband/hw/nes/nes_verbs.c
31085 --- linux-2.6.39.2/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-19 00:06:34.000000000 -0400
31086 +++ linux-2.6.39.2/drivers/infiniband/hw/nes/nes_verbs.c 2011-05-22 19:36:31.000000000 -0400
31087 @@ -46,9 +46,9 @@
31088
31089 #include <rdma/ib_umem.h>
31090
31091 -atomic_t mod_qp_timouts;
31092 -atomic_t qps_created;
31093 -atomic_t sw_qps_destroyed;
31094 +atomic_unchecked_t mod_qp_timouts;
31095 +atomic_unchecked_t qps_created;
31096 +atomic_unchecked_t sw_qps_destroyed;
31097
31098 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
31099
31100 @@ -1141,7 +1141,7 @@ static struct ib_qp *nes_create_qp(struc
31101 if (init_attr->create_flags)
31102 return ERR_PTR(-EINVAL);
31103
31104 - atomic_inc(&qps_created);
31105 + atomic_inc_unchecked(&qps_created);
31106 switch (init_attr->qp_type) {
31107 case IB_QPT_RC:
31108 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
31109 @@ -1470,7 +1470,7 @@ static int nes_destroy_qp(struct ib_qp *
31110 struct iw_cm_event cm_event;
31111 int ret;
31112
31113 - atomic_inc(&sw_qps_destroyed);
31114 + atomic_inc_unchecked(&sw_qps_destroyed);
31115 nesqp->destroyed = 1;
31116
31117 /* Blow away the connection if it exists. */
31118 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/qib/qib.h linux-2.6.39.2/drivers/infiniband/hw/qib/qib.h
31119 --- linux-2.6.39.2/drivers/infiniband/hw/qib/qib.h 2011-05-19 00:06:34.000000000 -0400
31120 +++ linux-2.6.39.2/drivers/infiniband/hw/qib/qib.h 2011-05-22 19:36:31.000000000 -0400
31121 @@ -51,6 +51,7 @@
31122 #include <linux/completion.h>
31123 #include <linux/kref.h>
31124 #include <linux/sched.h>
31125 +#include <linux/slab.h>
31126
31127 #include "qib_common.h"
31128 #include "qib_verbs.h"
31129 @@ -87,7 +88,7 @@ struct qlogic_ib_stats {
31130 };
31131
31132 extern struct qlogic_ib_stats qib_stats;
31133 -extern struct pci_error_handlers qib_pci_err_handler;
31134 +extern const struct pci_error_handlers qib_pci_err_handler;
31135 extern struct pci_driver qib_driver;
31136
31137 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
31138 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/qib/qib_mmap.c linux-2.6.39.2/drivers/infiniband/hw/qib/qib_mmap.c
31139 --- linux-2.6.39.2/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-19 00:06:34.000000000 -0400
31140 +++ linux-2.6.39.2/drivers/infiniband/hw/qib/qib_mmap.c 2011-05-22 19:36:31.000000000 -0400
31141 @@ -75,7 +75,7 @@ static void qib_vma_close(struct vm_area
31142 kref_put(&ip->ref, qib_release_mmap_info);
31143 }
31144
31145 -static struct vm_operations_struct qib_vm_ops = {
31146 +static const struct vm_operations_struct qib_vm_ops = {
31147 .open = qib_vma_open,
31148 .close = qib_vma_close,
31149 };
31150 diff -urNp linux-2.6.39.2/drivers/infiniband/hw/qib/qib_pcie.c linux-2.6.39.2/drivers/infiniband/hw/qib/qib_pcie.c
31151 --- linux-2.6.39.2/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-19 00:06:34.000000000 -0400
31152 +++ linux-2.6.39.2/drivers/infiniband/hw/qib/qib_pcie.c 2011-05-22 19:36:31.000000000 -0400
31153 @@ -735,7 +735,7 @@ qib_pci_resume(struct pci_dev *pdev)
31154 qib_init(dd, 1); /* same as re-init after reset */
31155 }
31156
31157 -struct pci_error_handlers qib_pci_err_handler = {
31158 +const struct pci_error_handlers qib_pci_err_handler = {
31159 .error_detected = qib_pci_error_detected,
31160 .mmio_enabled = qib_pci_mmio_enabled,
31161 .link_reset = qib_pci_link_reset,
31162 diff -urNp linux-2.6.39.2/drivers/input/gameport/gameport.c linux-2.6.39.2/drivers/input/gameport/gameport.c
31163 --- linux-2.6.39.2/drivers/input/gameport/gameport.c 2011-05-19 00:06:34.000000000 -0400
31164 +++ linux-2.6.39.2/drivers/input/gameport/gameport.c 2011-05-22 19:36:31.000000000 -0400
31165 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
31166 */
31167 static void gameport_init_port(struct gameport *gameport)
31168 {
31169 - static atomic_t gameport_no = ATOMIC_INIT(0);
31170 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
31171
31172 __module_get(THIS_MODULE);
31173
31174 mutex_init(&gameport->drv_mutex);
31175 device_initialize(&gameport->dev);
31176 dev_set_name(&gameport->dev, "gameport%lu",
31177 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
31178 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
31179 gameport->dev.bus = &gameport_bus;
31180 gameport->dev.release = gameport_release_port;
31181 if (gameport->parent)
31182 diff -urNp linux-2.6.39.2/drivers/input/input.c linux-2.6.39.2/drivers/input/input.c
31183 --- linux-2.6.39.2/drivers/input/input.c 2011-05-19 00:06:34.000000000 -0400
31184 +++ linux-2.6.39.2/drivers/input/input.c 2011-05-22 19:36:31.000000000 -0400
31185 @@ -1815,7 +1815,7 @@ static void input_cleanse_bitmasks(struc
31186 */
31187 int input_register_device(struct input_dev *dev)
31188 {
31189 - static atomic_t input_no = ATOMIC_INIT(0);
31190 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
31191 struct input_handler *handler;
31192 const char *path;
31193 int error;
31194 @@ -1852,7 +1852,7 @@ int input_register_device(struct input_d
31195 dev->setkeycode = input_default_setkeycode;
31196
31197 dev_set_name(&dev->dev, "input%ld",
31198 - (unsigned long) atomic_inc_return(&input_no) - 1);
31199 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
31200
31201 error = device_add(&dev->dev);
31202 if (error)
31203 diff -urNp linux-2.6.39.2/drivers/input/joystick/sidewinder.c linux-2.6.39.2/drivers/input/joystick/sidewinder.c
31204 --- linux-2.6.39.2/drivers/input/joystick/sidewinder.c 2011-05-19 00:06:34.000000000 -0400
31205 +++ linux-2.6.39.2/drivers/input/joystick/sidewinder.c 2011-05-22 19:36:31.000000000 -0400
31206 @@ -30,6 +30,7 @@
31207 #include <linux/kernel.h>
31208 #include <linux/module.h>
31209 #include <linux/slab.h>
31210 +#include <linux/sched.h>
31211 #include <linux/init.h>
31212 #include <linux/input.h>
31213 #include <linux/gameport.h>
31214 @@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
31215 unsigned char buf[SW_LENGTH];
31216 int i;
31217
31218 + pax_track_stack();
31219 +
31220 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
31221
31222 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
31223 diff -urNp linux-2.6.39.2/drivers/input/joystick/xpad.c linux-2.6.39.2/drivers/input/joystick/xpad.c
31224 --- linux-2.6.39.2/drivers/input/joystick/xpad.c 2011-05-19 00:06:34.000000000 -0400
31225 +++ linux-2.6.39.2/drivers/input/joystick/xpad.c 2011-05-22 19:36:31.000000000 -0400
31226 @@ -689,7 +689,7 @@ static void xpad_led_set(struct led_clas
31227
31228 static int xpad_led_probe(struct usb_xpad *xpad)
31229 {
31230 - static atomic_t led_seq = ATOMIC_INIT(0);
31231 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
31232 long led_no;
31233 struct xpad_led *led;
31234 struct led_classdev *led_cdev;
31235 @@ -702,7 +702,7 @@ static int xpad_led_probe(struct usb_xpa
31236 if (!led)
31237 return -ENOMEM;
31238
31239 - led_no = (long)atomic_inc_return(&led_seq) - 1;
31240 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
31241
31242 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
31243 led->xpad = xpad;
31244 diff -urNp linux-2.6.39.2/drivers/input/mousedev.c linux-2.6.39.2/drivers/input/mousedev.c
31245 --- linux-2.6.39.2/drivers/input/mousedev.c 2011-05-19 00:06:34.000000000 -0400
31246 +++ linux-2.6.39.2/drivers/input/mousedev.c 2011-05-22 19:36:31.000000000 -0400
31247 @@ -764,7 +764,7 @@ static ssize_t mousedev_read(struct file
31248
31249 spin_unlock_irq(&client->packet_lock);
31250
31251 - if (copy_to_user(buffer, data, count))
31252 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
31253 return -EFAULT;
31254
31255 return count;
31256 diff -urNp linux-2.6.39.2/drivers/input/serio/serio.c linux-2.6.39.2/drivers/input/serio/serio.c
31257 --- linux-2.6.39.2/drivers/input/serio/serio.c 2011-05-19 00:06:34.000000000 -0400
31258 +++ linux-2.6.39.2/drivers/input/serio/serio.c 2011-05-22 19:36:31.000000000 -0400
31259 @@ -497,7 +497,7 @@ static void serio_release_port(struct de
31260 */
31261 static void serio_init_port(struct serio *serio)
31262 {
31263 - static atomic_t serio_no = ATOMIC_INIT(0);
31264 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
31265
31266 __module_get(THIS_MODULE);
31267
31268 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio
31269 mutex_init(&serio->drv_mutex);
31270 device_initialize(&serio->dev);
31271 dev_set_name(&serio->dev, "serio%ld",
31272 - (long)atomic_inc_return(&serio_no) - 1);
31273 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
31274 serio->dev.bus = &serio_bus;
31275 serio->dev.release = serio_release_port;
31276 serio->dev.groups = serio_device_attr_groups;
31277 diff -urNp linux-2.6.39.2/drivers/isdn/capi/capi.c linux-2.6.39.2/drivers/isdn/capi/capi.c
31278 --- linux-2.6.39.2/drivers/isdn/capi/capi.c 2011-05-19 00:06:34.000000000 -0400
31279 +++ linux-2.6.39.2/drivers/isdn/capi/capi.c 2011-05-22 19:36:31.000000000 -0400
31280 @@ -89,8 +89,8 @@ struct capiminor {
31281
31282 struct capi20_appl *ap;
31283 u32 ncci;
31284 - atomic_t datahandle;
31285 - atomic_t msgid;
31286 + atomic_unchecked_t datahandle;
31287 + atomic_unchecked_t msgid;
31288
31289 struct tty_port port;
31290 int ttyinstop;
31291 @@ -414,7 +414,7 @@ gen_data_b3_resp_for(struct capiminor *m
31292 capimsg_setu16(s, 2, mp->ap->applid);
31293 capimsg_setu8 (s, 4, CAPI_DATA_B3);
31294 capimsg_setu8 (s, 5, CAPI_RESP);
31295 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
31296 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
31297 capimsg_setu32(s, 8, mp->ncci);
31298 capimsg_setu16(s, 12, datahandle);
31299 }
31300 @@ -547,14 +547,14 @@ static void handle_minor_send(struct cap
31301 mp->outbytes -= len;
31302 spin_unlock_bh(&mp->outlock);
31303
31304 - datahandle = atomic_inc_return(&mp->datahandle);
31305 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
31306 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
31307 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31308 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
31309 capimsg_setu16(skb->data, 2, mp->ap->applid);
31310 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
31311 capimsg_setu8 (skb->data, 5, CAPI_REQ);
31312 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
31313 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
31314 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
31315 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
31316 capimsg_setu16(skb->data, 16, len); /* Data length */
31317 diff -urNp linux-2.6.39.2/drivers/isdn/gigaset/common.c linux-2.6.39.2/drivers/isdn/gigaset/common.c
31318 --- linux-2.6.39.2/drivers/isdn/gigaset/common.c 2011-05-19 00:06:34.000000000 -0400
31319 +++ linux-2.6.39.2/drivers/isdn/gigaset/common.c 2011-05-22 19:36:31.000000000 -0400
31320 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct
31321 cs->commands_pending = 0;
31322 cs->cur_at_seq = 0;
31323 cs->gotfwver = -1;
31324 - cs->open_count = 0;
31325 + local_set(&cs->open_count, 0);
31326 cs->dev = NULL;
31327 cs->tty = NULL;
31328 cs->tty_dev = NULL;
31329 diff -urNp linux-2.6.39.2/drivers/isdn/gigaset/gigaset.h linux-2.6.39.2/drivers/isdn/gigaset/gigaset.h
31330 --- linux-2.6.39.2/drivers/isdn/gigaset/gigaset.h 2011-05-19 00:06:34.000000000 -0400
31331 +++ linux-2.6.39.2/drivers/isdn/gigaset/gigaset.h 2011-05-22 19:36:31.000000000 -0400
31332 @@ -35,6 +35,7 @@
31333 #include <linux/tty_driver.h>
31334 #include <linux/list.h>
31335 #include <asm/atomic.h>
31336 +#include <asm/local.h>
31337
31338 #define GIG_VERSION {0, 5, 0, 0}
31339 #define GIG_COMPAT {0, 4, 0, 0}
31340 @@ -433,7 +434,7 @@ struct cardstate {
31341 spinlock_t cmdlock;
31342 unsigned curlen, cmdbytes;
31343
31344 - unsigned open_count;
31345 + local_t open_count;
31346 struct tty_struct *tty;
31347 struct tasklet_struct if_wake_tasklet;
31348 unsigned control_state;
31349 diff -urNp linux-2.6.39.2/drivers/isdn/gigaset/interface.c linux-2.6.39.2/drivers/isdn/gigaset/interface.c
31350 --- linux-2.6.39.2/drivers/isdn/gigaset/interface.c 2011-05-19 00:06:34.000000000 -0400
31351 +++ linux-2.6.39.2/drivers/isdn/gigaset/interface.c 2011-05-22 19:36:31.000000000 -0400
31352 @@ -160,9 +160,7 @@ static int if_open(struct tty_struct *tt
31353 return -ERESTARTSYS;
31354 tty->driver_data = cs;
31355
31356 - ++cs->open_count;
31357 -
31358 - if (cs->open_count == 1) {
31359 + if (local_inc_return(&cs->open_count) == 1) {
31360 spin_lock_irqsave(&cs->lock, flags);
31361 cs->tty = tty;
31362 spin_unlock_irqrestore(&cs->lock, flags);
31363 @@ -190,10 +188,10 @@ static void if_close(struct tty_struct *
31364
31365 if (!cs->connected)
31366 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31367 - else if (!cs->open_count)
31368 + else if (!local_read(&cs->open_count))
31369 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31370 else {
31371 - if (!--cs->open_count) {
31372 + if (!local_dec_return(&cs->open_count)) {
31373 spin_lock_irqsave(&cs->lock, flags);
31374 cs->tty = NULL;
31375 spin_unlock_irqrestore(&cs->lock, flags);
31376 @@ -228,7 +226,7 @@ static int if_ioctl(struct tty_struct *t
31377 if (!cs->connected) {
31378 gig_dbg(DEBUG_IF, "not connected");
31379 retval = -ENODEV;
31380 - } else if (!cs->open_count)
31381 + } else if (!local_read(&cs->open_count))
31382 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31383 else {
31384 retval = 0;
31385 @@ -358,7 +356,7 @@ static int if_write(struct tty_struct *t
31386 retval = -ENODEV;
31387 goto done;
31388 }
31389 - if (!cs->open_count) {
31390 + if (!local_read(&cs->open_count)) {
31391 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31392 retval = -ENODEV;
31393 goto done;
31394 @@ -411,7 +409,7 @@ static int if_write_room(struct tty_stru
31395 if (!cs->connected) {
31396 gig_dbg(DEBUG_IF, "not connected");
31397 retval = -ENODEV;
31398 - } else if (!cs->open_count)
31399 + } else if (!local_read(&cs->open_count))
31400 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31401 else if (cs->mstate != MS_LOCKED) {
31402 dev_warn(cs->dev, "can't write to unlocked device\n");
31403 @@ -441,7 +439,7 @@ static int if_chars_in_buffer(struct tty
31404
31405 if (!cs->connected)
31406 gig_dbg(DEBUG_IF, "not connected");
31407 - else if (!cs->open_count)
31408 + else if (!local_read(&cs->open_count))
31409 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31410 else if (cs->mstate != MS_LOCKED)
31411 dev_warn(cs->dev, "can't write to unlocked device\n");
31412 @@ -469,7 +467,7 @@ static void if_throttle(struct tty_struc
31413
31414 if (!cs->connected)
31415 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31416 - else if (!cs->open_count)
31417 + else if (!local_read(&cs->open_count))
31418 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31419 else
31420 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31421 @@ -493,7 +491,7 @@ static void if_unthrottle(struct tty_str
31422
31423 if (!cs->connected)
31424 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
31425 - else if (!cs->open_count)
31426 + else if (!local_read(&cs->open_count))
31427 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31428 else
31429 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
31430 @@ -524,7 +522,7 @@ static void if_set_termios(struct tty_st
31431 goto out;
31432 }
31433
31434 - if (!cs->open_count) {
31435 + if (!local_read(&cs->open_count)) {
31436 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31437 goto out;
31438 }
31439 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/avm/b1.c linux-2.6.39.2/drivers/isdn/hardware/avm/b1.c
31440 --- linux-2.6.39.2/drivers/isdn/hardware/avm/b1.c 2011-05-19 00:06:34.000000000 -0400
31441 +++ linux-2.6.39.2/drivers/isdn/hardware/avm/b1.c 2011-05-22 19:36:31.000000000 -0400
31442 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capilo
31443 }
31444 if (left) {
31445 if (t4file->user) {
31446 - if (copy_from_user(buf, dp, left))
31447 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31448 return -EFAULT;
31449 } else {
31450 memcpy(buf, dp, left);
31451 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capilo
31452 }
31453 if (left) {
31454 if (config->user) {
31455 - if (copy_from_user(buf, dp, left))
31456 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31457 return -EFAULT;
31458 } else {
31459 memcpy(buf, dp, left);
31460 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/capidtmf.c linux-2.6.39.2/drivers/isdn/hardware/eicon/capidtmf.c
31461 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-19 00:06:34.000000000 -0400
31462 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/capidtmf.c 2011-05-22 19:36:31.000000000 -0400
31463 @@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_sta
31464 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
31465 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
31466
31467 + pax_track_stack();
31468
31469 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
31470 {
31471 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/capifunc.c linux-2.6.39.2/drivers/isdn/hardware/eicon/capifunc.c
31472 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/capifunc.c 2011-05-19 00:06:34.000000000 -0400
31473 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/capifunc.c 2011-05-22 19:36:31.000000000 -0400
31474 @@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
31475 IDI_SYNC_REQ req;
31476 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31477
31478 + pax_track_stack();
31479 +
31480 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31481
31482 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31483 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/diddfunc.c linux-2.6.39.2/drivers/isdn/hardware/eicon/diddfunc.c
31484 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-19 00:06:34.000000000 -0400
31485 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/diddfunc.c 2011-05-22 19:36:31.000000000 -0400
31486 @@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_di
31487 IDI_SYNC_REQ req;
31488 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31489
31490 + pax_track_stack();
31491 +
31492 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31493
31494 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31495 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/divasfunc.c linux-2.6.39.2/drivers/isdn/hardware/eicon/divasfunc.c
31496 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-19 00:06:34.000000000 -0400
31497 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/divasfunc.c 2011-05-22 19:36:31.000000000 -0400
31498 @@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_di
31499 IDI_SYNC_REQ req;
31500 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31501
31502 + pax_track_stack();
31503 +
31504 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31505
31506 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31507 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/idifunc.c linux-2.6.39.2/drivers/isdn/hardware/eicon/idifunc.c
31508 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/idifunc.c 2011-05-19 00:06:34.000000000 -0400
31509 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/idifunc.c 2011-05-22 19:36:31.000000000 -0400
31510 @@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_di
31511 IDI_SYNC_REQ req;
31512 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31513
31514 + pax_track_stack();
31515 +
31516 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31517
31518 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31519 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/message.c linux-2.6.39.2/drivers/isdn/hardware/eicon/message.c
31520 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/message.c 2011-05-19 00:06:34.000000000 -0400
31521 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/message.c 2011-05-22 19:36:31.000000000 -0400
31522 @@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
31523 dword d;
31524 word w;
31525
31526 + pax_track_stack();
31527 +
31528 a = plci->adapter;
31529 Id = ((word)plci->Id<<8)|a->Id;
31530 PUT_WORD(&SS_Ind[4],0x0000);
31531 @@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE
31532 word j, n, w;
31533 dword d;
31534
31535 + pax_track_stack();
31536 +
31537
31538 for(i=0;i<8;i++) bp_parms[i].length = 0;
31539 for(i=0;i<2;i++) global_config[i].length = 0;
31540 @@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARS
31541 const byte llc3[] = {4,3,2,2,6,6,0};
31542 const byte header[] = {0,2,3,3,0,0,0};
31543
31544 + pax_track_stack();
31545 +
31546 for(i=0;i<8;i++) bp_parms[i].length = 0;
31547 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
31548 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
31549 @@ -14760,6 +14766,8 @@ static void group_optimization(DIVA_CAPI
31550 word appl_number_group_type[MAX_APPL];
31551 PLCI *auxplci;
31552
31553 + pax_track_stack();
31554 +
31555 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
31556
31557 if(!a->group_optimization_enabled)
31558 diff -urNp linux-2.6.39.2/drivers/isdn/hardware/eicon/mntfunc.c linux-2.6.39.2/drivers/isdn/hardware/eicon/mntfunc.c
31559 --- linux-2.6.39.2/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-19 00:06:34.000000000 -0400
31560 +++ linux-2.6.39.2/drivers/isdn/hardware/eicon/mntfunc.c 2011-05-22 19:36:31.000000000 -0400
31561 @@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_di
31562 IDI_SYNC_REQ req;
31563 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
31564
31565 + pax_track_stack();
31566 +
31567 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
31568
31569 for (x = 0; x < MAX_DESCRIPTORS; x++) {
31570 diff -urNp linux-2.6.39.2/drivers/isdn/i4l/isdn_common.c linux-2.6.39.2/drivers/isdn/i4l/isdn_common.c
31571 --- linux-2.6.39.2/drivers/isdn/i4l/isdn_common.c 2011-05-19 00:06:34.000000000 -0400
31572 +++ linux-2.6.39.2/drivers/isdn/i4l/isdn_common.c 2011-05-22 19:36:31.000000000 -0400
31573 @@ -1292,6 +1292,8 @@ isdn_ioctl(struct file *file, uint cmd,
31574 } iocpar;
31575 void __user *argp = (void __user *)arg;
31576
31577 + pax_track_stack();
31578 +
31579 #define name iocpar.name
31580 #define bname iocpar.bname
31581 #define iocts iocpar.iocts
31582 diff -urNp linux-2.6.39.2/drivers/isdn/i4l/isdn_net.c linux-2.6.39.2/drivers/isdn/i4l/isdn_net.c
31583 --- linux-2.6.39.2/drivers/isdn/i4l/isdn_net.c 2011-05-19 00:06:34.000000000 -0400
31584 +++ linux-2.6.39.2/drivers/isdn/i4l/isdn_net.c 2011-05-22 19:36:31.000000000 -0400
31585 @@ -400,7 +400,7 @@ isdn_net_stat_callback(int idx, isdn_ctr
31586 isdn_net_local *lp = p->local;
31587 #ifdef CONFIG_ISDN_X25
31588 struct concap_proto *cprot = lp->netdev->cprot;
31589 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31590 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31591 #endif
31592 switch (cmd) {
31593 case ISDN_STAT_BSENT:
31594 @@ -831,7 +831,7 @@ isdn_net_hangup(struct net_device *d)
31595 isdn_ctrl cmd;
31596 #ifdef CONFIG_ISDN_X25
31597 struct concap_proto *cprot = lp->netdev->cprot;
31598 - struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31599 + const struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
31600 #endif
31601
31602 if (lp->flags & ISDN_NET_CONNECTED) {
31603 diff -urNp linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.c linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.c
31604 --- linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.c 2011-05-19 00:06:34.000000000 -0400
31605 +++ linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.c 2011-05-22 19:36:31.000000000 -0400
31606 @@ -52,7 +52,7 @@ static int isdn_x25iface_connect_ind( st
31607 static int isdn_x25iface_disconn_ind( struct concap_proto * );
31608
31609
31610 -static struct concap_proto_ops ix25_pops = {
31611 +static const struct concap_proto_ops ix25_pops = {
31612 &isdn_x25iface_proto_new,
31613 &isdn_x25iface_proto_del,
31614 &isdn_x25iface_proto_restart,
31615 diff -urNp linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.h linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.h
31616 --- linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.h 2011-05-19 00:06:34.000000000 -0400
31617 +++ linux-2.6.39.2/drivers/isdn/i4l/isdn_x25iface.h 2011-05-22 19:36:31.000000000 -0400
31618 @@ -23,7 +23,7 @@
31619 #include <linux/isdn.h>
31620 #include <linux/concap.h>
31621
31622 -extern struct concap_proto_ops * isdn_x25iface_concap_proto_ops_pt;
31623 +extern const struct concap_proto_ops *isdn_x25iface_concap_proto_ops_pt;
31624 extern struct concap_proto * isdn_x25iface_proto_new(void);
31625
31626
31627 diff -urNp linux-2.6.39.2/drivers/isdn/icn/icn.c linux-2.6.39.2/drivers/isdn/icn/icn.c
31628 --- linux-2.6.39.2/drivers/isdn/icn/icn.c 2011-05-19 00:06:34.000000000 -0400
31629 +++ linux-2.6.39.2/drivers/isdn/icn/icn.c 2011-05-22 19:36:31.000000000 -0400
31630 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len
31631 if (count > len)
31632 count = len;
31633 if (user) {
31634 - if (copy_from_user(msg, buf, count))
31635 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31636 return -EFAULT;
31637 } else
31638 memcpy(msg, buf, count);
31639 diff -urNp linux-2.6.39.2/drivers/lguest/core.c linux-2.6.39.2/drivers/lguest/core.c
31640 --- linux-2.6.39.2/drivers/lguest/core.c 2011-05-19 00:06:34.000000000 -0400
31641 +++ linux-2.6.39.2/drivers/lguest/core.c 2011-05-22 19:36:31.000000000 -0400
31642 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31643 * it's worked so far. The end address needs +1 because __get_vm_area
31644 * allocates an extra guard page, so we need space for that.
31645 */
31646 +
31647 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31648 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31649 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31650 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31651 +#else
31652 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31653 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31654 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31655 +#endif
31656 +
31657 if (!switcher_vma) {
31658 err = -ENOMEM;
31659 printk("lguest: could not map switcher pages high\n");
31660 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31661 * Now the Switcher is mapped at the right address, we can't fail!
31662 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
31663 */
31664 - memcpy(switcher_vma->addr, start_switcher_text,
31665 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31666 end_switcher_text - start_switcher_text);
31667
31668 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31669 diff -urNp linux-2.6.39.2/drivers/lguest/lguest_device.c linux-2.6.39.2/drivers/lguest/lguest_device.c
31670 --- linux-2.6.39.2/drivers/lguest/lguest_device.c 2011-05-19 00:06:34.000000000 -0400
31671 +++ linux-2.6.39.2/drivers/lguest/lguest_device.c 2011-05-22 19:36:31.000000000 -0400
31672 @@ -374,7 +374,7 @@ error:
31673 }
31674
31675 /* The ops structure which hooks everything together. */
31676 -static struct virtio_config_ops lguest_config_ops = {
31677 +static const struct virtio_config_ops lguest_config_ops = {
31678 .get_features = lg_get_features,
31679 .finalize_features = lg_finalize_features,
31680 .get = lg_get,
31681 diff -urNp linux-2.6.39.2/drivers/lguest/x86/core.c linux-2.6.39.2/drivers/lguest/x86/core.c
31682 --- linux-2.6.39.2/drivers/lguest/x86/core.c 2011-05-19 00:06:34.000000000 -0400
31683 +++ linux-2.6.39.2/drivers/lguest/x86/core.c 2011-05-22 19:36:31.000000000 -0400
31684 @@ -59,7 +59,7 @@ static struct {
31685 /* Offset from where switcher.S was compiled to where we've copied it */
31686 static unsigned long switcher_offset(void)
31687 {
31688 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31689 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31690 }
31691
31692 /* This cpu's struct lguest_pages. */
31693 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg
31694 * These copies are pretty cheap, so we do them unconditionally: */
31695 /* Save the current Host top-level page directory.
31696 */
31697 +
31698 +#ifdef CONFIG_PAX_PER_CPU_PGD
31699 + pages->state.host_cr3 = read_cr3();
31700 +#else
31701 pages->state.host_cr3 = __pa(current->mm->pgd);
31702 +#endif
31703 +
31704 /*
31705 * Set up the Guest's page tables to see this CPU's pages (and no
31706 * other CPU's pages).
31707 @@ -547,7 +553,7 @@ void __init lguest_arch_host_init(void)
31708 * compiled-in switcher code and the high-mapped copy we just made.
31709 */
31710 for (i = 0; i < IDT_ENTRIES; i++)
31711 - default_idt_entries[i] += switcher_offset();
31712 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31713
31714 /*
31715 * Set up the Switcher's per-cpu areas.
31716 @@ -630,7 +636,7 @@ void __init lguest_arch_host_init(void)
31717 * it will be undisturbed when we switch. To change %cs and jump we
31718 * need this structure to feed to Intel's "lcall" instruction.
31719 */
31720 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31721 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31722 lguest_entry.segment = LGUEST_CS;
31723
31724 /*
31725 diff -urNp linux-2.6.39.2/drivers/lguest/x86/switcher_32.S linux-2.6.39.2/drivers/lguest/x86/switcher_32.S
31726 --- linux-2.6.39.2/drivers/lguest/x86/switcher_32.S 2011-05-19 00:06:34.000000000 -0400
31727 +++ linux-2.6.39.2/drivers/lguest/x86/switcher_32.S 2011-05-22 19:36:31.000000000 -0400
31728 @@ -87,6 +87,7 @@
31729 #include <asm/page.h>
31730 #include <asm/segment.h>
31731 #include <asm/lguest.h>
31732 +#include <asm/processor-flags.h>
31733
31734 // We mark the start of the code to copy
31735 // It's placed in .text tho it's never run here
31736 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31737 // Changes type when we load it: damn Intel!
31738 // For after we switch over our page tables
31739 // That entry will be read-only: we'd crash.
31740 +
31741 +#ifdef CONFIG_PAX_KERNEXEC
31742 + mov %cr0, %edx
31743 + xor $X86_CR0_WP, %edx
31744 + mov %edx, %cr0
31745 +#endif
31746 +
31747 movl $(GDT_ENTRY_TSS*8), %edx
31748 ltr %dx
31749
31750 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31751 // Let's clear it again for our return.
31752 // The GDT descriptor of the Host
31753 // Points to the table after two "size" bytes
31754 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31755 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31756 // Clear "used" from type field (byte 5, bit 2)
31757 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31758 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31759 +
31760 +#ifdef CONFIG_PAX_KERNEXEC
31761 + mov %cr0, %eax
31762 + xor $X86_CR0_WP, %eax
31763 + mov %eax, %cr0
31764 +#endif
31765
31766 // Once our page table's switched, the Guest is live!
31767 // The Host fades as we run this final step.
31768 @@ -295,13 +309,12 @@ deliver_to_host:
31769 // I consulted gcc, and it gave
31770 // These instructions, which I gladly credit:
31771 leal (%edx,%ebx,8), %eax
31772 - movzwl (%eax),%edx
31773 - movl 4(%eax), %eax
31774 - xorw %ax, %ax
31775 - orl %eax, %edx
31776 + movl 4(%eax), %edx
31777 + movw (%eax), %dx
31778 // Now the address of the handler's in %edx
31779 // We call it now: its "iret" drops us home.
31780 - jmp *%edx
31781 + ljmp $__KERNEL_CS, $1f
31782 +1: jmp *%edx
31783
31784 // Every interrupt can come to us here
31785 // But we must truly tell each apart.
31786 diff -urNp linux-2.6.39.2/drivers/md/dm.c linux-2.6.39.2/drivers/md/dm.c
31787 --- linux-2.6.39.2/drivers/md/dm.c 2011-05-19 00:06:34.000000000 -0400
31788 +++ linux-2.6.39.2/drivers/md/dm.c 2011-05-22 19:36:31.000000000 -0400
31789 @@ -162,9 +162,9 @@ struct mapped_device {
31790 /*
31791 * Event handling.
31792 */
31793 - atomic_t event_nr;
31794 + atomic_unchecked_t event_nr;
31795 wait_queue_head_t eventq;
31796 - atomic_t uevent_seq;
31797 + atomic_unchecked_t uevent_seq;
31798 struct list_head uevent_list;
31799 spinlock_t uevent_lock; /* Protect access to uevent_list */
31800
31801 @@ -1836,8 +1836,8 @@ static struct mapped_device *alloc_dev(i
31802 rwlock_init(&md->map_lock);
31803 atomic_set(&md->holders, 1);
31804 atomic_set(&md->open_count, 0);
31805 - atomic_set(&md->event_nr, 0);
31806 - atomic_set(&md->uevent_seq, 0);
31807 + atomic_set_unchecked(&md->event_nr, 0);
31808 + atomic_set_unchecked(&md->uevent_seq, 0);
31809 INIT_LIST_HEAD(&md->uevent_list);
31810 spin_lock_init(&md->uevent_lock);
31811
31812 @@ -1971,7 +1971,7 @@ static void event_callback(void *context
31813
31814 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31815
31816 - atomic_inc(&md->event_nr);
31817 + atomic_inc_unchecked(&md->event_nr);
31818 wake_up(&md->eventq);
31819 }
31820
31821 @@ -2547,18 +2547,18 @@ int dm_kobject_uevent(struct mapped_devi
31822
31823 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31824 {
31825 - return atomic_add_return(1, &md->uevent_seq);
31826 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31827 }
31828
31829 uint32_t dm_get_event_nr(struct mapped_device *md)
31830 {
31831 - return atomic_read(&md->event_nr);
31832 + return atomic_read_unchecked(&md->event_nr);
31833 }
31834
31835 int dm_wait_event(struct mapped_device *md, int event_nr)
31836 {
31837 return wait_event_interruptible(md->eventq,
31838 - (event_nr != atomic_read(&md->event_nr)));
31839 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31840 }
31841
31842 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31843 diff -urNp linux-2.6.39.2/drivers/md/dm-crypt.c linux-2.6.39.2/drivers/md/dm-crypt.c
31844 --- linux-2.6.39.2/drivers/md/dm-crypt.c 2011-05-19 00:06:34.000000000 -0400
31845 +++ linux-2.6.39.2/drivers/md/dm-crypt.c 2011-05-22 19:36:31.000000000 -0400
31846 @@ -138,7 +138,7 @@ struct crypt_config {
31847 char *cipher;
31848 char *cipher_string;
31849
31850 - struct crypt_iv_operations *iv_gen_ops;
31851 + const struct crypt_iv_operations *iv_gen_ops;
31852 union {
31853 struct iv_essiv_private essiv;
31854 struct iv_benbi_private benbi;
31855 @@ -620,15 +620,15 @@ static int crypt_iv_lmk_post(struct cryp
31856 return r;
31857 }
31858
31859 -static struct crypt_iv_operations crypt_iv_plain_ops = {
31860 +static const struct crypt_iv_operations crypt_iv_plain_ops = {
31861 .generator = crypt_iv_plain_gen
31862 };
31863
31864 -static struct crypt_iv_operations crypt_iv_plain64_ops = {
31865 +static const struct crypt_iv_operations crypt_iv_plain64_ops = {
31866 .generator = crypt_iv_plain64_gen
31867 };
31868
31869 -static struct crypt_iv_operations crypt_iv_essiv_ops = {
31870 +static const struct crypt_iv_operations crypt_iv_essiv_ops = {
31871 .ctr = crypt_iv_essiv_ctr,
31872 .dtr = crypt_iv_essiv_dtr,
31873 .init = crypt_iv_essiv_init,
31874 @@ -636,17 +636,17 @@ static struct crypt_iv_operations crypt_
31875 .generator = crypt_iv_essiv_gen
31876 };
31877
31878 -static struct crypt_iv_operations crypt_iv_benbi_ops = {
31879 +static const struct crypt_iv_operations crypt_iv_benbi_ops = {
31880 .ctr = crypt_iv_benbi_ctr,
31881 .dtr = crypt_iv_benbi_dtr,
31882 .generator = crypt_iv_benbi_gen
31883 };
31884
31885 -static struct crypt_iv_operations crypt_iv_null_ops = {
31886 +static const struct crypt_iv_operations crypt_iv_null_ops = {
31887 .generator = crypt_iv_null_gen
31888 };
31889
31890 -static struct crypt_iv_operations crypt_iv_lmk_ops = {
31891 +static const struct crypt_iv_operations crypt_iv_lmk_ops = {
31892 .ctr = crypt_iv_lmk_ctr,
31893 .dtr = crypt_iv_lmk_dtr,
31894 .init = crypt_iv_lmk_init,
31895 diff -urNp linux-2.6.39.2/drivers/md/dm-ioctl.c linux-2.6.39.2/drivers/md/dm-ioctl.c
31896 --- linux-2.6.39.2/drivers/md/dm-ioctl.c 2011-05-19 00:06:34.000000000 -0400
31897 +++ linux-2.6.39.2/drivers/md/dm-ioctl.c 2011-05-22 19:36:31.000000000 -0400
31898 @@ -1551,7 +1551,7 @@ static int validate_params(uint cmd, str
31899 cmd == DM_LIST_VERSIONS_CMD)
31900 return 0;
31901
31902 - if ((cmd == DM_DEV_CREATE_CMD)) {
31903 + if (cmd == DM_DEV_CREATE_CMD) {
31904 if (!*param->name) {
31905 DMWARN("name not supplied when creating device");
31906 return -EINVAL;
31907 diff -urNp linux-2.6.39.2/drivers/md/dm-raid1.c linux-2.6.39.2/drivers/md/dm-raid1.c
31908 --- linux-2.6.39.2/drivers/md/dm-raid1.c 2011-05-19 00:06:34.000000000 -0400
31909 +++ linux-2.6.39.2/drivers/md/dm-raid1.c 2011-05-22 19:36:31.000000000 -0400
31910 @@ -42,7 +42,7 @@ enum dm_raid1_error {
31911
31912 struct mirror {
31913 struct mirror_set *ms;
31914 - atomic_t error_count;
31915 + atomic_unchecked_t error_count;
31916 unsigned long error_type;
31917 struct dm_dev *dev;
31918 sector_t offset;
31919 @@ -187,7 +187,7 @@ static struct mirror *get_valid_mirror(s
31920 struct mirror *m;
31921
31922 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31923 - if (!atomic_read(&m->error_count))
31924 + if (!atomic_read_unchecked(&m->error_count))
31925 return m;
31926
31927 return NULL;
31928 @@ -219,7 +219,7 @@ static void fail_mirror(struct mirror *m
31929 * simple way to tell if a device has encountered
31930 * errors.
31931 */
31932 - atomic_inc(&m->error_count);
31933 + atomic_inc_unchecked(&m->error_count);
31934
31935 if (test_and_set_bit(error_type, &m->error_type))
31936 return;
31937 @@ -410,7 +410,7 @@ static struct mirror *choose_mirror(stru
31938 struct mirror *m = get_default_mirror(ms);
31939
31940 do {
31941 - if (likely(!atomic_read(&m->error_count)))
31942 + if (likely(!atomic_read_unchecked(&m->error_count)))
31943 return m;
31944
31945 if (m-- == ms->mirror)
31946 @@ -424,7 +424,7 @@ static int default_ok(struct mirror *m)
31947 {
31948 struct mirror *default_mirror = get_default_mirror(m->ms);
31949
31950 - return !atomic_read(&default_mirror->error_count);
31951 + return !atomic_read_unchecked(&default_mirror->error_count);
31952 }
31953
31954 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31955 @@ -561,7 +561,7 @@ static void do_reads(struct mirror_set *
31956 */
31957 if (likely(region_in_sync(ms, region, 1)))
31958 m = choose_mirror(ms, bio->bi_sector);
31959 - else if (m && atomic_read(&m->error_count))
31960 + else if (m && atomic_read_unchecked(&m->error_count))
31961 m = NULL;
31962
31963 if (likely(m))
31964 @@ -939,7 +939,7 @@ static int get_mirror(struct mirror_set
31965 }
31966
31967 ms->mirror[mirror].ms = ms;
31968 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31969 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31970 ms->mirror[mirror].error_type = 0;
31971 ms->mirror[mirror].offset = offset;
31972
31973 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_targ
31974 */
31975 static char device_status_char(struct mirror *m)
31976 {
31977 - if (!atomic_read(&(m->error_count)))
31978 + if (!atomic_read_unchecked(&(m->error_count)))
31979 return 'A';
31980
31981 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31982 diff -urNp linux-2.6.39.2/drivers/md/dm-stripe.c linux-2.6.39.2/drivers/md/dm-stripe.c
31983 --- linux-2.6.39.2/drivers/md/dm-stripe.c 2011-05-19 00:06:34.000000000 -0400
31984 +++ linux-2.6.39.2/drivers/md/dm-stripe.c 2011-05-22 19:36:31.000000000 -0400
31985 @@ -20,7 +20,7 @@ struct stripe {
31986 struct dm_dev *dev;
31987 sector_t physical_start;
31988
31989 - atomic_t error_count;
31990 + atomic_unchecked_t error_count;
31991 };
31992
31993 struct stripe_c {
31994 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *
31995 kfree(sc);
31996 return r;
31997 }
31998 - atomic_set(&(sc->stripe[i].error_count), 0);
31999 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
32000 }
32001
32002 ti->private = sc;
32003 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_targe
32004 DMEMIT("%d ", sc->stripes);
32005 for (i = 0; i < sc->stripes; i++) {
32006 DMEMIT("%s ", sc->stripe[i].dev->name);
32007 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
32008 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
32009 'D' : 'A';
32010 }
32011 buffer[i] = '\0';
32012 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_targe
32013 */
32014 for (i = 0; i < sc->stripes; i++)
32015 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
32016 - atomic_inc(&(sc->stripe[i].error_count));
32017 - if (atomic_read(&(sc->stripe[i].error_count)) <
32018 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
32019 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
32020 DM_IO_ERROR_THRESHOLD)
32021 schedule_work(&sc->trigger_event);
32022 }
32023 diff -urNp linux-2.6.39.2/drivers/md/dm-table.c linux-2.6.39.2/drivers/md/dm-table.c
32024 --- linux-2.6.39.2/drivers/md/dm-table.c 2011-06-03 00:04:14.000000000 -0400
32025 +++ linux-2.6.39.2/drivers/md/dm-table.c 2011-06-03 00:32:05.000000000 -0400
32026 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct
32027 if (!dev_size)
32028 return 0;
32029
32030 - if ((start >= dev_size) || (start + len > dev_size)) {
32031 + if ((start >= dev_size) || (len > dev_size - start)) {
32032 DMWARN("%s: %s too small for target: "
32033 "start=%llu, len=%llu, dev_size=%llu",
32034 dm_device_name(ti->table->md), bdevname(bdev, b),
32035 diff -urNp linux-2.6.39.2/drivers/md/md.c linux-2.6.39.2/drivers/md/md.c
32036 --- linux-2.6.39.2/drivers/md/md.c 2011-06-25 12:55:22.000000000 -0400
32037 +++ linux-2.6.39.2/drivers/md/md.c 2011-06-25 13:00:25.000000000 -0400
32038 @@ -226,10 +226,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
32039 * start build, activate spare
32040 */
32041 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
32042 -static atomic_t md_event_count;
32043 +static atomic_unchecked_t md_event_count;
32044 void md_new_event(mddev_t *mddev)
32045 {
32046 - atomic_inc(&md_event_count);
32047 + atomic_inc_unchecked(&md_event_count);
32048 wake_up(&md_event_waiters);
32049 }
32050 EXPORT_SYMBOL_GPL(md_new_event);
32051 @@ -239,7 +239,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
32052 */
32053 static void md_new_event_inintr(mddev_t *mddev)
32054 {
32055 - atomic_inc(&md_event_count);
32056 + atomic_inc_unchecked(&md_event_count);
32057 wake_up(&md_event_waiters);
32058 }
32059
32060 @@ -1454,7 +1454,7 @@ static int super_1_load(mdk_rdev_t *rdev
32061
32062 rdev->preferred_minor = 0xffff;
32063 rdev->data_offset = le64_to_cpu(sb->data_offset);
32064 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32065 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
32066
32067 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
32068 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
32069 @@ -1632,7 +1632,7 @@ static void super_1_sync(mddev_t *mddev,
32070 else
32071 sb->resync_offset = cpu_to_le64(0);
32072
32073 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
32074 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
32075
32076 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
32077 sb->size = cpu_to_le64(mddev->dev_sectors);
32078 @@ -2414,7 +2414,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_sho
32079 static ssize_t
32080 errors_show(mdk_rdev_t *rdev, char *page)
32081 {
32082 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
32083 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
32084 }
32085
32086 static ssize_t
32087 @@ -2423,7 +2423,7 @@ errors_store(mdk_rdev_t *rdev, const cha
32088 char *e;
32089 unsigned long n = simple_strtoul(buf, &e, 10);
32090 if (*buf && (*e == 0 || *e == '\n')) {
32091 - atomic_set(&rdev->corrected_errors, n);
32092 + atomic_set_unchecked(&rdev->corrected_errors, n);
32093 return len;
32094 }
32095 return -EINVAL;
32096 @@ -2779,8 +2779,8 @@ void md_rdev_init(mdk_rdev_t *rdev)
32097 rdev->last_read_error.tv_sec = 0;
32098 rdev->last_read_error.tv_nsec = 0;
32099 atomic_set(&rdev->nr_pending, 0);
32100 - atomic_set(&rdev->read_errors, 0);
32101 - atomic_set(&rdev->corrected_errors, 0);
32102 + atomic_set_unchecked(&rdev->read_errors, 0);
32103 + atomic_set_unchecked(&rdev->corrected_errors, 0);
32104
32105 INIT_LIST_HEAD(&rdev->same_set);
32106 init_waitqueue_head(&rdev->blocked_wait);
32107 @@ -6388,7 +6388,7 @@ static int md_seq_show(struct seq_file *
32108
32109 spin_unlock(&pers_lock);
32110 seq_printf(seq, "\n");
32111 - mi->event = atomic_read(&md_event_count);
32112 + mi->event = atomic_read_unchecked(&md_event_count);
32113 return 0;
32114 }
32115 if (v == (void*)2) {
32116 @@ -6477,7 +6477,7 @@ static int md_seq_show(struct seq_file *
32117 chunk_kb ? "KB" : "B");
32118 if (bitmap->file) {
32119 seq_printf(seq, ", file: ");
32120 - seq_path(seq, &bitmap->file->f_path, " \t\n");
32121 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
32122 }
32123
32124 seq_printf(seq, "\n");
32125 @@ -6511,7 +6511,7 @@ static int md_seq_open(struct inode *ino
32126 else {
32127 struct seq_file *p = file->private_data;
32128 p->private = mi;
32129 - mi->event = atomic_read(&md_event_count);
32130 + mi->event = atomic_read_unchecked(&md_event_count);
32131 }
32132 return error;
32133 }
32134 @@ -6527,7 +6527,7 @@ static unsigned int mdstat_poll(struct f
32135 /* always allow read */
32136 mask = POLLIN | POLLRDNORM;
32137
32138 - if (mi->event != atomic_read(&md_event_count))
32139 + if (mi->event != atomic_read_unchecked(&md_event_count))
32140 mask |= POLLERR | POLLPRI;
32141 return mask;
32142 }
32143 @@ -6571,7 +6571,7 @@ static int is_mddev_idle(mddev_t *mddev,
32144 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
32145 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
32146 (int)part_stat_read(&disk->part0, sectors[1]) -
32147 - atomic_read(&disk->sync_io);
32148 + atomic_read_unchecked(&disk->sync_io);
32149 /* sync IO will cause sync_io to increase before the disk_stats
32150 * as sync_io is counted when a request starts, and
32151 * disk_stats is counted when it completes.
32152 diff -urNp linux-2.6.39.2/drivers/md/md.h linux-2.6.39.2/drivers/md/md.h
32153 --- linux-2.6.39.2/drivers/md/md.h 2011-05-19 00:06:34.000000000 -0400
32154 +++ linux-2.6.39.2/drivers/md/md.h 2011-05-22 19:36:31.000000000 -0400
32155 @@ -97,13 +97,13 @@ struct mdk_rdev_s
32156 * only maintained for arrays that
32157 * support hot removal
32158 */
32159 - atomic_t read_errors; /* number of consecutive read errors that
32160 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
32161 * we have tried to ignore.
32162 */
32163 struct timespec last_read_error; /* monotonic time since our
32164 * last read error
32165 */
32166 - atomic_t corrected_errors; /* number of corrected read errors,
32167 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
32168 * for reporting to userspace and storing
32169 * in superblock.
32170 */
32171 @@ -342,7 +342,7 @@ static inline void rdev_dec_pending(mdk_
32172
32173 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
32174 {
32175 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32176 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
32177 }
32178
32179 struct mdk_personality
32180 diff -urNp linux-2.6.39.2/drivers/md/raid10.c linux-2.6.39.2/drivers/md/raid10.c
32181 --- linux-2.6.39.2/drivers/md/raid10.c 2011-05-19 00:06:34.000000000 -0400
32182 +++ linux-2.6.39.2/drivers/md/raid10.c 2011-05-22 19:36:31.000000000 -0400
32183 @@ -1209,7 +1209,7 @@ static void end_sync_read(struct bio *bi
32184 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
32185 set_bit(R10BIO_Uptodate, &r10_bio->state);
32186 else {
32187 - atomic_add(r10_bio->sectors,
32188 + atomic_add_unchecked(r10_bio->sectors,
32189 &conf->mirrors[d].rdev->corrected_errors);
32190 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
32191 md_error(r10_bio->mddev,
32192 @@ -1417,7 +1417,7 @@ static void check_decay_read_errors(mdde
32193 {
32194 struct timespec cur_time_mon;
32195 unsigned long hours_since_last;
32196 - unsigned int read_errors = atomic_read(&rdev->read_errors);
32197 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
32198
32199 ktime_get_ts(&cur_time_mon);
32200
32201 @@ -1439,9 +1439,9 @@ static void check_decay_read_errors(mdde
32202 * overflowing the shift of read_errors by hours_since_last.
32203 */
32204 if (hours_since_last >= 8 * sizeof(read_errors))
32205 - atomic_set(&rdev->read_errors, 0);
32206 + atomic_set_unchecked(&rdev->read_errors, 0);
32207 else
32208 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
32209 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
32210 }
32211
32212 /*
32213 @@ -1476,8 +1476,8 @@ static void fix_read_error(conf_t *conf,
32214 }
32215
32216 check_decay_read_errors(mddev, rdev);
32217 - atomic_inc(&rdev->read_errors);
32218 - cur_read_error_count = atomic_read(&rdev->read_errors);
32219 + atomic_inc_unchecked(&rdev->read_errors);
32220 + cur_read_error_count = atomic_read_unchecked(&rdev->read_errors);
32221 if (cur_read_error_count > max_read_errors) {
32222 rcu_read_unlock();
32223 printk(KERN_NOTICE
32224 @@ -1550,7 +1550,7 @@ static void fix_read_error(conf_t *conf,
32225 test_bit(In_sync, &rdev->flags)) {
32226 atomic_inc(&rdev->nr_pending);
32227 rcu_read_unlock();
32228 - atomic_add(s, &rdev->corrected_errors);
32229 + atomic_add_unchecked(s, &rdev->corrected_errors);
32230 if (sync_page_io(rdev,
32231 r10_bio->devs[sl].addr +
32232 sect,
32233 diff -urNp linux-2.6.39.2/drivers/md/raid1.c linux-2.6.39.2/drivers/md/raid1.c
32234 --- linux-2.6.39.2/drivers/md/raid1.c 2011-05-19 00:06:34.000000000 -0400
32235 +++ linux-2.6.39.2/drivers/md/raid1.c 2011-05-22 19:36:31.000000000 -0400
32236 @@ -1342,7 +1342,7 @@ static void sync_request_write(mddev_t *
32237 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
32238 continue;
32239 rdev = conf->mirrors[d].rdev;
32240 - atomic_add(s, &rdev->corrected_errors);
32241 + atomic_add_unchecked(s, &rdev->corrected_errors);
32242 if (sync_page_io(rdev,
32243 sect,
32244 s<<9,
32245 @@ -1488,7 +1488,7 @@ static void fix_read_error(conf_t *conf,
32246 /* Well, this device is dead */
32247 md_error(mddev, rdev);
32248 else {
32249 - atomic_add(s, &rdev->corrected_errors);
32250 + atomic_add_unchecked(s, &rdev->corrected_errors);
32251 printk(KERN_INFO
32252 "md/raid1:%s: read error corrected "
32253 "(%d sectors at %llu on %s)\n",
32254 diff -urNp linux-2.6.39.2/drivers/md/raid5.c linux-2.6.39.2/drivers/md/raid5.c
32255 --- linux-2.6.39.2/drivers/md/raid5.c 2011-06-25 12:55:22.000000000 -0400
32256 +++ linux-2.6.39.2/drivers/md/raid5.c 2011-06-25 13:01:13.000000000 -0400
32257 @@ -550,7 +550,7 @@ static void ops_run_io(struct stripe_hea
32258 bi->bi_next = NULL;
32259 if ((rw & WRITE) &&
32260 test_bit(R5_ReWrite, &sh->dev[i].flags))
32261 - atomic_add(STRIPE_SECTORS,
32262 + atomic_add_unchecked(STRIPE_SECTORS,
32263 &rdev->corrected_errors);
32264 generic_make_request(bi);
32265 } else {
32266 @@ -1596,15 +1596,15 @@ static void raid5_end_read_request(struc
32267 clear_bit(R5_ReadError, &sh->dev[i].flags);
32268 clear_bit(R5_ReWrite, &sh->dev[i].flags);
32269 }
32270 - if (atomic_read(&conf->disks[i].rdev->read_errors))
32271 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
32272 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
32273 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
32274 } else {
32275 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
32276 int retry = 0;
32277 rdev = conf->disks[i].rdev;
32278
32279 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
32280 - atomic_inc(&rdev->read_errors);
32281 + atomic_inc_unchecked(&rdev->read_errors);
32282 if (conf->mddev->degraded >= conf->max_degraded)
32283 printk_rl(KERN_WARNING
32284 "md/raid:%s: read error not correctable "
32285 @@ -1622,7 +1622,7 @@ static void raid5_end_read_request(struc
32286 (unsigned long long)(sh->sector
32287 + rdev->data_offset),
32288 bdn);
32289 - else if (atomic_read(&rdev->read_errors)
32290 + else if (atomic_read_unchecked(&rdev->read_errors)
32291 > conf->max_nr_stripes)
32292 printk(KERN_WARNING
32293 "md/raid:%s: Too many read errors, failing device %s.\n",
32294 @@ -1947,6 +1947,7 @@ static sector_t compute_blocknr(struct s
32295 sector_t r_sector;
32296 struct stripe_head sh2;
32297
32298 + pax_track_stack();
32299
32300 chunk_offset = sector_div(new_sector, sectors_per_chunk);
32301 stripe = new_sector;
32302 diff -urNp linux-2.6.39.2/drivers/media/common/saa7146_hlp.c linux-2.6.39.2/drivers/media/common/saa7146_hlp.c
32303 --- linux-2.6.39.2/drivers/media/common/saa7146_hlp.c 2011-05-19 00:06:34.000000000 -0400
32304 +++ linux-2.6.39.2/drivers/media/common/saa7146_hlp.c 2011-05-22 19:36:31.000000000 -0400
32305 @@ -353,6 +353,8 @@ static void calculate_clipping_registers
32306
32307 int x[32], y[32], w[32], h[32];
32308
32309 + pax_track_stack();
32310 +
32311 /* clear out memory */
32312 memset(&line_list[0], 0x00, sizeof(u32)*32);
32313 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
32314 diff -urNp linux-2.6.39.2/drivers/media/common/saa7146_vbi.c linux-2.6.39.2/drivers/media/common/saa7146_vbi.c
32315 --- linux-2.6.39.2/drivers/media/common/saa7146_vbi.c 2011-05-19 00:06:34.000000000 -0400
32316 +++ linux-2.6.39.2/drivers/media/common/saa7146_vbi.c 2011-05-22 19:36:31.000000000 -0400
32317 @@ -501,7 +501,7 @@ static ssize_t vbi_read(struct file *fil
32318 return ret;
32319 }
32320
32321 -struct saa7146_use_ops saa7146_vbi_uops = {
32322 +const struct saa7146_use_ops saa7146_vbi_uops = {
32323 .init = vbi_init,
32324 .open = vbi_open,
32325 .release = vbi_close,
32326 diff -urNp linux-2.6.39.2/drivers/media/common/saa7146_video.c linux-2.6.39.2/drivers/media/common/saa7146_video.c
32327 --- linux-2.6.39.2/drivers/media/common/saa7146_video.c 2011-05-19 00:06:34.000000000 -0400
32328 +++ linux-2.6.39.2/drivers/media/common/saa7146_video.c 2011-05-22 19:36:31.000000000 -0400
32329 @@ -1420,7 +1420,7 @@ out:
32330 return ret;
32331 }
32332
32333 -struct saa7146_use_ops saa7146_video_uops = {
32334 +const struct saa7146_use_ops saa7146_video_uops = {
32335 .init = video_init,
32336 .open = video_open,
32337 .release = video_close,
32338 diff -urNp linux-2.6.39.2/drivers/media/dvb/dm1105/dm1105.c linux-2.6.39.2/drivers/media/dvb/dm1105/dm1105.c
32339 --- linux-2.6.39.2/drivers/media/dvb/dm1105/dm1105.c 2011-05-19 00:06:34.000000000 -0400
32340 +++ linux-2.6.39.2/drivers/media/dvb/dm1105/dm1105.c 2011-05-22 19:36:31.000000000 -0400
32341 @@ -418,7 +418,7 @@ static u32 functionality(struct i2c_adap
32342 return I2C_FUNC_I2C;
32343 }
32344
32345 -static struct i2c_algorithm dm1105_algo = {
32346 +static const struct i2c_algorithm dm1105_algo = {
32347 .master_xfer = dm1105_i2c_xfer,
32348 .functionality = functionality,
32349 };
32350 diff -urNp linux-2.6.39.2/drivers/media/dvb/dvb-core/dvb_ca_en50221.c linux-2.6.39.2/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
32351 --- linux-2.6.39.2/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-19 00:06:34.000000000 -0400
32352 +++ linux-2.6.39.2/drivers/media/dvb/dvb-core/dvb_ca_en50221.c 2011-05-22 19:36:31.000000000 -0400
32353 @@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(stru
32354 u8 buf[HOST_LINK_BUF_SIZE];
32355 int i;
32356
32357 + pax_track_stack();
32358 +
32359 dprintk("%s\n", __func__);
32360
32361 /* check if we have space for a link buf in the rx_buffer */
32362 @@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(s
32363 unsigned long timeout;
32364 int written;
32365
32366 + pax_track_stack();
32367 +
32368 dprintk("%s\n", __func__);
32369
32370 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
32371 diff -urNp linux-2.6.39.2/drivers/media/dvb/dvb-core/dvbdev.c linux-2.6.39.2/drivers/media/dvb/dvb-core/dvbdev.c
32372 --- linux-2.6.39.2/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-19 00:06:34.000000000 -0400
32373 +++ linux-2.6.39.2/drivers/media/dvb/dvb-core/dvbdev.c 2011-05-22 19:36:31.000000000 -0400
32374 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapt
32375 const struct dvb_device *template, void *priv, int type)
32376 {
32377 struct dvb_device *dvbdev;
32378 - struct file_operations *dvbdevfops;
32379 + struct file_operations *dvbdevfops; /* cannot be const, see this function */
32380 struct device *clsdev;
32381 int minor;
32382 int id;
32383 diff -urNp linux-2.6.39.2/drivers/media/dvb/dvb-usb/dib0700_core.c linux-2.6.39.2/drivers/media/dvb/dvb-usb/dib0700_core.c
32384 --- linux-2.6.39.2/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-19 00:06:34.000000000 -0400
32385 +++ linux-2.6.39.2/drivers/media/dvb/dvb-usb/dib0700_core.c 2011-05-22 19:36:31.000000000 -0400
32386 @@ -391,6 +391,8 @@ int dib0700_download_firmware(struct usb
32387
32388 u8 buf[260];
32389
32390 + pax_track_stack();
32391 +
32392 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
32393 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
32394 hx.addr, hx.len, hx.chk);
32395 diff -urNp linux-2.6.39.2/drivers/media/dvb/dvb-usb/lmedm04.c linux-2.6.39.2/drivers/media/dvb/dvb-usb/lmedm04.c
32396 --- linux-2.6.39.2/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-19 00:06:34.000000000 -0400
32397 +++ linux-2.6.39.2/drivers/media/dvb/dvb-usb/lmedm04.c 2011-05-22 19:36:31.000000000 -0400
32398 @@ -663,6 +663,7 @@ static int lme2510_download_firmware(str
32399 packet_size = 0x31;
32400 len_in = 1;
32401
32402 + pax_track_stack();
32403
32404 info("FRM Starting Firmware Download");
32405
32406 @@ -715,6 +716,8 @@ static void lme_coldreset(struct usb_dev
32407 int ret = 0, len_in;
32408 u8 data[512] = {0};
32409
32410 + pax_track_stack();
32411 +
32412 data[0] = 0x0a;
32413 len_in = 1;
32414 info("FRM Firmware Cold Reset");
32415 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/dib7000p.c linux-2.6.39.2/drivers/media/dvb/frontends/dib7000p.c
32416 --- linux-2.6.39.2/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:04:14.000000000 -0400
32417 +++ linux-2.6.39.2/drivers/media/dvb/frontends/dib7000p.c 2011-06-03 00:32:05.000000000 -0400
32418 @@ -1945,7 +1945,7 @@ static u32 dib7000p_i2c_func(struct i2c_
32419 return I2C_FUNC_I2C;
32420 }
32421
32422 -static struct i2c_algorithm dib7090_tuner_xfer_algo = {
32423 +static const struct i2c_algorithm dib7090_tuner_xfer_algo = {
32424 .master_xfer = dib7090_tuner_xfer,
32425 .functionality = dib7000p_i2c_func,
32426 };
32427 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/dib9000.c linux-2.6.39.2/drivers/media/dvb/frontends/dib9000.c
32428 --- linux-2.6.39.2/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:04:14.000000000 -0400
32429 +++ linux-2.6.39.2/drivers/media/dvb/frontends/dib9000.c 2011-06-03 00:32:05.000000000 -0400
32430 @@ -1676,12 +1676,12 @@ static u32 dib9000_i2c_func(struct i2c_a
32431 return I2C_FUNC_I2C;
32432 }
32433
32434 -static struct i2c_algorithm dib9000_tuner_algo = {
32435 +static const struct i2c_algorithm dib9000_tuner_algo = {
32436 .master_xfer = dib9000_tuner_xfer,
32437 .functionality = dib9000_i2c_func,
32438 };
32439
32440 -static struct i2c_algorithm dib9000_component_bus_algo = {
32441 +static const struct i2c_algorithm dib9000_component_bus_algo = {
32442 .master_xfer = dib9000_fw_component_bus_xfer,
32443 .functionality = dib9000_i2c_func,
32444 };
32445 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/dibx000_common.c linux-2.6.39.2/drivers/media/dvb/frontends/dibx000_common.c
32446 --- linux-2.6.39.2/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:04:14.000000000 -0400
32447 +++ linux-2.6.39.2/drivers/media/dvb/frontends/dibx000_common.c 2011-06-03 00:37:36.000000000 -0400
32448 @@ -221,12 +221,12 @@ static int dibx000_i2c_master_xfer_gpio3
32449 return num;
32450 }
32451
32452 -static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32453 +static const struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
32454 .master_xfer = dibx000_i2c_master_xfer_gpio12,
32455 .functionality = dibx000_i2c_func,
32456 };
32457
32458 -static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32459 +static const struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
32460 .master_xfer = dibx000_i2c_master_xfer_gpio34,
32461 .functionality = dibx000_i2c_func,
32462 };
32463 @@ -285,7 +285,7 @@ static int dibx000_i2c_gated_gpio67_xfer
32464 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32465 }
32466
32467 -static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32468 +static const struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
32469 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
32470 .functionality = dibx000_i2c_func,
32471 };
32472 @@ -322,7 +322,7 @@ static int dibx000_i2c_gated_tuner_xfer(
32473 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
32474 }
32475
32476 -static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32477 +static const struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
32478 .master_xfer = dibx000_i2c_gated_tuner_xfer,
32479 .functionality = dibx000_i2c_func,
32480 };
32481 @@ -375,7 +375,7 @@ void dibx000_reset_i2c_master(struct dib
32482 EXPORT_SYMBOL(dibx000_reset_i2c_master);
32483
32484 static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
32485 - struct i2c_algorithm *algo, const char *name,
32486 + const struct i2c_algorithm *algo, const char *name,
32487 struct dibx000_i2c_master *mst)
32488 {
32489 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
32490 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/mb86a16.c linux-2.6.39.2/drivers/media/dvb/frontends/mb86a16.c
32491 --- linux-2.6.39.2/drivers/media/dvb/frontends/mb86a16.c 2011-05-19 00:06:34.000000000 -0400
32492 +++ linux-2.6.39.2/drivers/media/dvb/frontends/mb86a16.c 2011-05-22 19:36:31.000000000 -0400
32493 @@ -1060,6 +1060,8 @@ static int mb86a16_set_fe(struct mb86a16
32494 int ret = -1;
32495 int sync;
32496
32497 + pax_track_stack();
32498 +
32499 dprintk(verbose, MB86A16_INFO, 1, "freq=%d Mhz, symbrt=%d Ksps", state->frequency, state->srate);
32500
32501 fcp = 3000;
32502 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/or51211.c linux-2.6.39.2/drivers/media/dvb/frontends/or51211.c
32503 --- linux-2.6.39.2/drivers/media/dvb/frontends/or51211.c 2011-05-19 00:06:34.000000000 -0400
32504 +++ linux-2.6.39.2/drivers/media/dvb/frontends/or51211.c 2011-05-22 19:36:31.000000000 -0400
32505 @@ -113,6 +113,8 @@ static int or51211_load_firmware (struct
32506 u8 tudata[585];
32507 int i;
32508
32509 + pax_track_stack();
32510 +
32511 dprintk("Firmware is %zd bytes\n",fw->size);
32512
32513 /* Get eprom data */
32514 diff -urNp linux-2.6.39.2/drivers/media/dvb/frontends/s5h1420.c linux-2.6.39.2/drivers/media/dvb/frontends/s5h1420.c
32515 --- linux-2.6.39.2/drivers/media/dvb/frontends/s5h1420.c 2011-05-19 00:06:34.000000000 -0400
32516 +++ linux-2.6.39.2/drivers/media/dvb/frontends/s5h1420.c 2011-05-22 19:36:31.000000000 -0400
32517 @@ -870,7 +870,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(
32518 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
32519 }
32520
32521 -static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32522 +static const struct i2c_algorithm s5h1420_tuner_i2c_algo = {
32523 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
32524 .functionality = s5h1420_tuner_i2c_func,
32525 };
32526 diff -urNp linux-2.6.39.2/drivers/media/dvb/mantis/mantis_i2c.c linux-2.6.39.2/drivers/media/dvb/mantis/mantis_i2c.c
32527 --- linux-2.6.39.2/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-19 00:06:34.000000000 -0400
32528 +++ linux-2.6.39.2/drivers/media/dvb/mantis/mantis_i2c.c 2011-05-22 19:36:31.000000000 -0400
32529 @@ -212,7 +212,7 @@ static u32 mantis_i2c_func(struct i2c_ad
32530 return I2C_FUNC_SMBUS_EMUL;
32531 }
32532
32533 -static struct i2c_algorithm mantis_algo = {
32534 +static const struct i2c_algorithm mantis_algo = {
32535 .master_xfer = mantis_i2c_xfer,
32536 .functionality = mantis_i2c_func,
32537 };
32538 diff -urNp linux-2.6.39.2/drivers/media/dvb/ttusb-dec/ttusb_dec.c linux-2.6.39.2/drivers/media/dvb/ttusb-dec/ttusb_dec.c
32539 --- linux-2.6.39.2/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-19 00:06:34.000000000 -0400
32540 +++ linux-2.6.39.2/drivers/media/dvb/ttusb-dec/ttusb_dec.c 2011-05-22 19:36:31.000000000 -0400
32541 @@ -1614,7 +1614,7 @@ static int fe_send_command(struct dvb_fr
32542 return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
32543 }
32544
32545 -static struct ttusbdecfe_config fe_config = {
32546 +static const struct ttusbdecfe_config fe_config = {
32547 .send_command = fe_send_command
32548 };
32549
32550 diff -urNp linux-2.6.39.2/drivers/media/radio/radio-cadet.c linux-2.6.39.2/drivers/media/radio/radio-cadet.c
32551 --- linux-2.6.39.2/drivers/media/radio/radio-cadet.c 2011-05-19 00:06:34.000000000 -0400
32552 +++ linux-2.6.39.2/drivers/media/radio/radio-cadet.c 2011-05-22 19:36:31.000000000 -0400
32553 @@ -349,7 +349,7 @@ static ssize_t cadet_read(struct file *f
32554 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
32555 mutex_unlock(&dev->lock);
32556
32557 - if (copy_to_user(data, readbuf, i))
32558 + if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
32559 return -EFAULT;
32560 return i;
32561 }
32562 diff -urNp linux-2.6.39.2/drivers/media/radio/radio-si4713.c linux-2.6.39.2/drivers/media/radio/radio-si4713.c
32563 --- linux-2.6.39.2/drivers/media/radio/radio-si4713.c 2011-05-19 00:06:34.000000000 -0400
32564 +++ linux-2.6.39.2/drivers/media/radio/radio-si4713.c 2011-05-22 19:36:31.000000000 -0400
32565 @@ -231,7 +231,7 @@ static long radio_si4713_default(struct
32566 ioctl, cmd, arg);
32567 }
32568
32569 -static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32570 +static const struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
32571 .vidioc_enumaudout = radio_si4713_enumaudout,
32572 .vidioc_g_audout = radio_si4713_g_audout,
32573 .vidioc_s_audout = radio_si4713_s_audout,
32574 diff -urNp linux-2.6.39.2/drivers/media/rc/ir-lirc-codec.c linux-2.6.39.2/drivers/media/rc/ir-lirc-codec.c
32575 --- linux-2.6.39.2/drivers/media/rc/ir-lirc-codec.c 2011-05-19 00:06:34.000000000 -0400
32576 +++ linux-2.6.39.2/drivers/media/rc/ir-lirc-codec.c 2011-05-22 19:36:31.000000000 -0400
32577 @@ -277,7 +277,7 @@ static void ir_lirc_close(void *data)
32578 return;
32579 }
32580
32581 -static struct file_operations lirc_fops = {
32582 +static const struct file_operations lirc_fops = {
32583 .owner = THIS_MODULE,
32584 .write = ir_lirc_transmit_ir,
32585 .unlocked_ioctl = ir_lirc_ioctl,
32586 diff -urNp linux-2.6.39.2/drivers/media/rc/lirc_dev.c linux-2.6.39.2/drivers/media/rc/lirc_dev.c
32587 --- linux-2.6.39.2/drivers/media/rc/lirc_dev.c 2011-05-19 00:06:34.000000000 -0400
32588 +++ linux-2.6.39.2/drivers/media/rc/lirc_dev.c 2011-05-22 19:36:31.000000000 -0400
32589 @@ -151,7 +151,7 @@ static int lirc_thread(void *irctl)
32590 }
32591
32592
32593 -static struct file_operations lirc_dev_fops = {
32594 +static const struct file_operations lirc_dev_fops = {
32595 .owner = THIS_MODULE,
32596 .read = lirc_dev_fop_read,
32597 .write = lirc_dev_fop_write,
32598 diff -urNp linux-2.6.39.2/drivers/media/rc/rc-main.c linux-2.6.39.2/drivers/media/rc/rc-main.c
32599 --- linux-2.6.39.2/drivers/media/rc/rc-main.c 2011-05-19 00:06:34.000000000 -0400
32600 +++ linux-2.6.39.2/drivers/media/rc/rc-main.c 2011-05-22 19:36:31.000000000 -0400
32601 @@ -996,7 +996,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
32602
32603 int rc_register_device(struct rc_dev *dev)
32604 {
32605 - static atomic_t devno = ATOMIC_INIT(0);
32606 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
32607 struct rc_map *rc_map;
32608 const char *path;
32609 int rc;
32610 @@ -1019,7 +1019,7 @@ int rc_register_device(struct rc_dev *de
32611 if (dev->close)
32612 dev->input_dev->close = ir_close;
32613
32614 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
32615 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
32616 dev_set_name(&dev->dev, "rc%ld", dev->devno);
32617 dev_set_drvdata(&dev->dev, dev);
32618 rc = device_add(&dev->dev);
32619 diff -urNp linux-2.6.39.2/drivers/media/video/cafe_ccic.c linux-2.6.39.2/drivers/media/video/cafe_ccic.c
32620 --- linux-2.6.39.2/drivers/media/video/cafe_ccic.c 2011-05-19 00:06:34.000000000 -0400
32621 +++ linux-2.6.39.2/drivers/media/video/cafe_ccic.c 2011-05-22 19:36:31.000000000 -0400
32622 @@ -520,7 +520,7 @@ static u32 cafe_smbus_func(struct i2c_ad
32623 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
32624 }
32625
32626 -static struct i2c_algorithm cafe_smbus_algo = {
32627 +static const struct i2c_algorithm cafe_smbus_algo = {
32628 .smbus_xfer = cafe_smbus_xfer,
32629 .functionality = cafe_smbus_func
32630 };
32631 diff -urNp linux-2.6.39.2/drivers/media/video/cx18/cx18-alsa-pcm.c linux-2.6.39.2/drivers/media/video/cx18/cx18-alsa-pcm.c
32632 --- linux-2.6.39.2/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-19 00:06:34.000000000 -0400
32633 +++ linux-2.6.39.2/drivers/media/video/cx18/cx18-alsa-pcm.c 2011-05-22 19:36:31.000000000 -0400
32634 @@ -314,7 +314,7 @@ static struct page *snd_pcm_get_vmalloc_
32635 return vmalloc_to_page(pageptr);
32636 }
32637
32638 -static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32639 +static const struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
32640 .open = snd_cx18_pcm_capture_open,
32641 .close = snd_cx18_pcm_capture_close,
32642 .ioctl = snd_cx18_pcm_ioctl,
32643 diff -urNp linux-2.6.39.2/drivers/media/video/cx18/cx18-driver.c linux-2.6.39.2/drivers/media/video/cx18/cx18-driver.c
32644 --- linux-2.6.39.2/drivers/media/video/cx18/cx18-driver.c 2011-05-19 00:06:34.000000000 -0400
32645 +++ linux-2.6.39.2/drivers/media/video/cx18/cx18-driver.c 2011-05-22 19:36:31.000000000 -0400
32646 @@ -61,7 +61,7 @@ static struct pci_device_id cx18_pci_tbl
32647
32648 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
32649
32650 -static atomic_t cx18_instance = ATOMIC_INIT(0);
32651 +static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
32652
32653 /* Parameter declarations */
32654 static int cardtype[CX18_MAX_CARDS];
32655 @@ -327,6 +327,8 @@ void cx18_read_eeprom(struct cx18 *cx, s
32656 struct i2c_client c;
32657 u8 eedata[256];
32658
32659 + pax_track_stack();
32660 +
32661 memset(&c, 0, sizeof(c));
32662 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
32663 c.adapter = &cx->i2c_adap[0];
32664 @@ -892,7 +894,7 @@ static int __devinit cx18_probe(struct p
32665 struct cx18 *cx;
32666
32667 /* FIXME - module parameter arrays constrain max instances */
32668 - i = atomic_inc_return(&cx18_instance) - 1;
32669 + i = atomic_inc_return_unchecked(&cx18_instance) - 1;
32670 if (i >= CX18_MAX_CARDS) {
32671 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
32672 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
32673 diff -urNp linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-audio.c linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-audio.c
32674 --- linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32675 +++ linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32676 @@ -613,7 +613,7 @@ static struct page *snd_pcm_get_vmalloc_
32677 return vmalloc_to_page(pageptr);
32678 }
32679
32680 -static struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32681 +static const struct snd_pcm_ops snd_cx231xx_pcm_capture = {
32682 .open = snd_cx231xx_capture_open,
32683 .close = snd_cx231xx_pcm_close,
32684 .ioctl = snd_pcm_lib_ioctl,
32685 diff -urNp linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-i2c.c linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-i2c.c
32686 --- linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32687 +++ linux-2.6.39.2/drivers/media/video/cx231xx/cx231xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32688 @@ -435,7 +435,7 @@ static u32 functionality(struct i2c_adap
32689 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
32690 }
32691
32692 -static struct i2c_algorithm cx231xx_algo = {
32693 +static const struct i2c_algorithm cx231xx_algo = {
32694 .master_xfer = cx231xx_i2c_xfer,
32695 .functionality = functionality,
32696 };
32697 diff -urNp linux-2.6.39.2/drivers/media/video/cx23885/cx23885-input.c linux-2.6.39.2/drivers/media/video/cx23885/cx23885-input.c
32698 --- linux-2.6.39.2/drivers/media/video/cx23885/cx23885-input.c 2011-05-19 00:06:34.000000000 -0400
32699 +++ linux-2.6.39.2/drivers/media/video/cx23885/cx23885-input.c 2011-05-22 19:36:31.000000000 -0400
32700 @@ -53,6 +53,8 @@ static void cx23885_input_process_measur
32701 bool handle = false;
32702 struct ir_raw_event ir_core_event[64];
32703
32704 + pax_track_stack();
32705 +
32706 do {
32707 num = 0;
32708 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
32709 diff -urNp linux-2.6.39.2/drivers/media/video/cx88/cx88-alsa.c linux-2.6.39.2/drivers/media/video/cx88/cx88-alsa.c
32710 --- linux-2.6.39.2/drivers/media/video/cx88/cx88-alsa.c 2011-05-19 00:06:34.000000000 -0400
32711 +++ linux-2.6.39.2/drivers/media/video/cx88/cx88-alsa.c 2011-05-22 19:36:31.000000000 -0400
32712 @@ -519,7 +519,7 @@ static struct page *snd_cx88_page(struct
32713 /*
32714 * operators
32715 */
32716 -static struct snd_pcm_ops snd_cx88_pcm_ops = {
32717 +static const struct snd_pcm_ops snd_cx88_pcm_ops = {
32718 .open = snd_cx88_pcm_open,
32719 .close = snd_cx88_close,
32720 .ioctl = snd_pcm_lib_ioctl,
32721 diff -urNp linux-2.6.39.2/drivers/media/video/davinci/ccdc_hw_device.h linux-2.6.39.2/drivers/media/video/davinci/ccdc_hw_device.h
32722 --- linux-2.6.39.2/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-19 00:06:34.000000000 -0400
32723 +++ linux-2.6.39.2/drivers/media/video/davinci/ccdc_hw_device.h 2011-05-22 19:36:31.000000000 -0400
32724 @@ -99,7 +99,7 @@ struct ccdc_hw_device {
32725 /* module owner */
32726 struct module *owner;
32727 /* hw ops */
32728 - struct ccdc_hw_ops hw_ops;
32729 + const struct ccdc_hw_ops hw_ops;
32730 };
32731
32732 /* Used by CCDC module to register & unregister with vpfe capture driver */
32733 diff -urNp linux-2.6.39.2/drivers/media/video/davinci/vpss.c linux-2.6.39.2/drivers/media/video/davinci/vpss.c
32734 --- linux-2.6.39.2/drivers/media/video/davinci/vpss.c 2011-05-19 00:06:34.000000000 -0400
32735 +++ linux-2.6.39.2/drivers/media/video/davinci/vpss.c 2011-05-22 19:36:31.000000000 -0400
32736 @@ -103,7 +103,7 @@ struct vpss_oper_config {
32737 __iomem void *vpss_regs_base1;
32738 enum vpss_platform_type platform;
32739 spinlock_t vpss_lock;
32740 - struct vpss_hw_ops hw_ops;
32741 + const struct vpss_hw_ops hw_ops;
32742 };
32743
32744 static struct vpss_oper_config oper_cfg;
32745 diff -urNp linux-2.6.39.2/drivers/media/video/em28xx/em28xx-audio.c linux-2.6.39.2/drivers/media/video/em28xx/em28xx-audio.c
32746 --- linux-2.6.39.2/drivers/media/video/em28xx/em28xx-audio.c 2011-05-19 00:06:34.000000000 -0400
32747 +++ linux-2.6.39.2/drivers/media/video/em28xx/em28xx-audio.c 2011-05-22 19:36:31.000000000 -0400
32748 @@ -432,7 +432,7 @@ static struct page *snd_pcm_get_vmalloc_
32749 return vmalloc_to_page(pageptr);
32750 }
32751
32752 -static struct snd_pcm_ops snd_em28xx_pcm_capture = {
32753 +static const struct snd_pcm_ops snd_em28xx_pcm_capture = {
32754 .open = snd_em28xx_capture_open,
32755 .close = snd_em28xx_pcm_close,
32756 .ioctl = snd_pcm_lib_ioctl,
32757 diff -urNp linux-2.6.39.2/drivers/media/video/em28xx/em28xx-i2c.c linux-2.6.39.2/drivers/media/video/em28xx/em28xx-i2c.c
32758 --- linux-2.6.39.2/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-19 00:06:34.000000000 -0400
32759 +++ linux-2.6.39.2/drivers/media/video/em28xx/em28xx-i2c.c 2011-05-22 19:36:31.000000000 -0400
32760 @@ -451,7 +451,7 @@ static u32 functionality(struct i2c_adap
32761 return I2C_FUNC_SMBUS_EMUL;
32762 }
32763
32764 -static struct i2c_algorithm em28xx_algo = {
32765 +static const struct i2c_algorithm em28xx_algo = {
32766 .master_xfer = em28xx_i2c_xfer,
32767 .functionality = functionality,
32768 };
32769 diff -urNp linux-2.6.39.2/drivers/media/video/hdpvr/hdpvr-i2c.c linux-2.6.39.2/drivers/media/video/hdpvr/hdpvr-i2c.c
32770 --- linux-2.6.39.2/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-19 00:06:34.000000000 -0400
32771 +++ linux-2.6.39.2/drivers/media/video/hdpvr/hdpvr-i2c.c 2011-05-22 19:36:31.000000000 -0400
32772 @@ -179,7 +179,7 @@ static u32 hdpvr_functionality(struct i2
32773 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
32774 }
32775
32776 -static struct i2c_algorithm hdpvr_algo = {
32777 +static const struct i2c_algorithm hdpvr_algo = {
32778 .master_xfer = hdpvr_transfer,
32779 .functionality = hdpvr_functionality,
32780 };
32781 diff -urNp linux-2.6.39.2/drivers/media/video/imx074.c linux-2.6.39.2/drivers/media/video/imx074.c
32782 --- linux-2.6.39.2/drivers/media/video/imx074.c 2011-05-19 00:06:34.000000000 -0400
32783 +++ linux-2.6.39.2/drivers/media/video/imx074.c 2011-05-22 19:36:31.000000000 -0400
32784 @@ -267,7 +267,7 @@ static int imx074_g_chip_ident(struct v4
32785 return 0;
32786 }
32787
32788 -static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32789 +static const struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
32790 .s_stream = imx074_s_stream,
32791 .s_mbus_fmt = imx074_s_fmt,
32792 .g_mbus_fmt = imx074_g_fmt,
32793 @@ -277,7 +277,7 @@ static struct v4l2_subdev_video_ops imx0
32794 .cropcap = imx074_cropcap,
32795 };
32796
32797 -static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32798 +static const struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
32799 .g_chip_ident = imx074_g_chip_ident,
32800 };
32801
32802 diff -urNp linux-2.6.39.2/drivers/media/video/ivtv/ivtv-driver.c linux-2.6.39.2/drivers/media/video/ivtv/ivtv-driver.c
32803 --- linux-2.6.39.2/drivers/media/video/ivtv/ivtv-driver.c 2011-05-19 00:06:34.000000000 -0400
32804 +++ linux-2.6.39.2/drivers/media/video/ivtv/ivtv-driver.c 2011-05-22 19:36:31.000000000 -0400
32805 @@ -80,7 +80,7 @@ static struct pci_device_id ivtv_pci_tbl
32806 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
32807
32808 /* ivtv instance counter */
32809 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
32810 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
32811
32812 /* Parameter declarations */
32813 static int cardtype[IVTV_MAX_CARDS];
32814 diff -urNp linux-2.6.39.2/drivers/media/video/mt9m001.c linux-2.6.39.2/drivers/media/video/mt9m001.c
32815 --- linux-2.6.39.2/drivers/media/video/mt9m001.c 2011-05-19 00:06:34.000000000 -0400
32816 +++ linux-2.6.39.2/drivers/media/video/mt9m001.c 2011-05-22 19:36:31.000000000 -0400
32817 @@ -691,7 +691,7 @@ static int mt9m001_g_skip_top_lines(stru
32818 return 0;
32819 }
32820
32821 -static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32822 +static const struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
32823 .g_ctrl = mt9m001_g_ctrl,
32824 .s_ctrl = mt9m001_s_ctrl,
32825 .g_chip_ident = mt9m001_g_chip_ident,
32826 @@ -714,7 +714,7 @@ static int mt9m001_enum_fmt(struct v4l2_
32827 return 0;
32828 }
32829
32830 -static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32831 +static const struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
32832 .s_stream = mt9m001_s_stream,
32833 .s_mbus_fmt = mt9m001_s_fmt,
32834 .g_mbus_fmt = mt9m001_g_fmt,
32835 @@ -725,7 +725,7 @@ static struct v4l2_subdev_video_ops mt9m
32836 .enum_mbus_fmt = mt9m001_enum_fmt,
32837 };
32838
32839 -static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32840 +static const struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
32841 .g_skip_top_lines = mt9m001_g_skip_top_lines,
32842 };
32843
32844 diff -urNp linux-2.6.39.2/drivers/media/video/mt9t031.c linux-2.6.39.2/drivers/media/video/mt9t031.c
32845 --- linux-2.6.39.2/drivers/media/video/mt9t031.c 2011-05-19 00:06:34.000000000 -0400
32846 +++ linux-2.6.39.2/drivers/media/video/mt9t031.c 2011-05-22 19:36:31.000000000 -0400
32847 @@ -725,7 +725,7 @@ static int mt9t031_runtime_resume(struct
32848 return 0;
32849 }
32850
32851 -static struct dev_pm_ops mt9t031_dev_pm_ops = {
32852 +static const struct dev_pm_ops mt9t031_dev_pm_ops = {
32853 .runtime_suspend = mt9t031_runtime_suspend,
32854 .runtime_resume = mt9t031_runtime_resume,
32855 };
32856 @@ -788,7 +788,7 @@ static int mt9t031_g_skip_top_lines(stru
32857 return 0;
32858 }
32859
32860 -static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32861 +static const struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
32862 .g_ctrl = mt9t031_g_ctrl,
32863 .s_ctrl = mt9t031_s_ctrl,
32864 .g_chip_ident = mt9t031_g_chip_ident,
32865 @@ -808,7 +808,7 @@ static int mt9t031_enum_fmt(struct v4l2_
32866 return 0;
32867 }
32868
32869 -static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32870 +static const struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
32871 .s_stream = mt9t031_s_stream,
32872 .s_mbus_fmt = mt9t031_s_fmt,
32873 .g_mbus_fmt = mt9t031_g_fmt,
32874 @@ -819,7 +819,7 @@ static struct v4l2_subdev_video_ops mt9t
32875 .enum_mbus_fmt = mt9t031_enum_fmt,
32876 };
32877
32878 -static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32879 +static const struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
32880 .g_skip_top_lines = mt9t031_g_skip_top_lines,
32881 };
32882
32883 diff -urNp linux-2.6.39.2/drivers/media/video/mt9v022.c linux-2.6.39.2/drivers/media/video/mt9v022.c
32884 --- linux-2.6.39.2/drivers/media/video/mt9v022.c 2011-05-19 00:06:34.000000000 -0400
32885 +++ linux-2.6.39.2/drivers/media/video/mt9v022.c 2011-05-22 19:36:31.000000000 -0400
32886 @@ -825,7 +825,7 @@ static int mt9v022_g_skip_top_lines(stru
32887 return 0;
32888 }
32889
32890 -static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32891 +static const struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
32892 .g_ctrl = mt9v022_g_ctrl,
32893 .s_ctrl = mt9v022_s_ctrl,
32894 .g_chip_ident = mt9v022_g_chip_ident,
32895 @@ -848,7 +848,7 @@ static int mt9v022_enum_fmt(struct v4l2_
32896 return 0;
32897 }
32898
32899 -static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32900 +static const struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
32901 .s_stream = mt9v022_s_stream,
32902 .s_mbus_fmt = mt9v022_s_fmt,
32903 .g_mbus_fmt = mt9v022_g_fmt,
32904 @@ -859,7 +859,7 @@ static struct v4l2_subdev_video_ops mt9v
32905 .enum_mbus_fmt = mt9v022_enum_fmt,
32906 };
32907
32908 -static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32909 +static const struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
32910 .g_skip_top_lines = mt9v022_g_skip_top_lines,
32911 };
32912
32913 diff -urNp linux-2.6.39.2/drivers/media/video/mx2_camera.c linux-2.6.39.2/drivers/media/video/mx2_camera.c
32914 --- linux-2.6.39.2/drivers/media/video/mx2_camera.c 2011-05-19 00:06:34.000000000 -0400
32915 +++ linux-2.6.39.2/drivers/media/video/mx2_camera.c 2011-05-22 19:36:31.000000000 -0400
32916 @@ -668,7 +668,7 @@ static void mx2_videobuf_release(struct
32917 free_buffer(vq, buf);
32918 }
32919
32920 -static struct videobuf_queue_ops mx2_videobuf_ops = {
32921 +static const struct videobuf_queue_ops mx2_videobuf_ops = {
32922 .buf_setup = mx2_videobuf_setup,
32923 .buf_prepare = mx2_videobuf_prepare,
32924 .buf_queue = mx2_videobuf_queue,
32925 diff -urNp linux-2.6.39.2/drivers/media/video/omap24xxcam.c linux-2.6.39.2/drivers/media/video/omap24xxcam.c
32926 --- linux-2.6.39.2/drivers/media/video/omap24xxcam.c 2011-05-19 00:06:34.000000000 -0400
32927 +++ linux-2.6.39.2/drivers/media/video/omap24xxcam.c 2011-05-22 19:36:31.000000000 -0400
32928 @@ -403,7 +403,7 @@ static void omap24xxcam_vbq_complete(str
32929 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
32930
32931 do_gettimeofday(&vb->ts);
32932 - vb->field_count = atomic_add_return(2, &fh->field_count);
32933 + vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
32934 if (csr & csr_error) {
32935 vb->state = VIDEOBUF_ERROR;
32936 if (!atomic_read(&fh->cam->in_reset)) {
32937 diff -urNp linux-2.6.39.2/drivers/media/video/omap24xxcam.h linux-2.6.39.2/drivers/media/video/omap24xxcam.h
32938 --- linux-2.6.39.2/drivers/media/video/omap24xxcam.h 2011-05-19 00:06:34.000000000 -0400
32939 +++ linux-2.6.39.2/drivers/media/video/omap24xxcam.h 2011-05-22 19:36:31.000000000 -0400
32940 @@ -533,7 +533,7 @@ struct omap24xxcam_fh {
32941 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
32942 struct videobuf_queue vbq;
32943 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
32944 - atomic_t field_count; /* field counter for videobuf_buffer */
32945 + atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
32946 /* accessing cam here doesn't need serialisation: it's constant */
32947 struct omap24xxcam_device *cam;
32948 };
32949 diff -urNp linux-2.6.39.2/drivers/media/video/omap3isp/isp.h linux-2.6.39.2/drivers/media/video/omap3isp/isp.h
32950 --- linux-2.6.39.2/drivers/media/video/omap3isp/isp.h 2011-05-19 00:06:34.000000000 -0400
32951 +++ linux-2.6.39.2/drivers/media/video/omap3isp/isp.h 2011-05-22 19:36:31.000000000 -0400
32952 @@ -290,7 +290,7 @@ struct isp_device {
32953
32954 struct iommu *iommu;
32955
32956 - struct isp_platform_callback platform_cb;
32957 + const struct isp_platform_callback platform_cb;
32958 };
32959
32960 #define v4l2_dev_to_isp_device(dev) \
32961 diff -urNp linux-2.6.39.2/drivers/media/video/ov2640.c linux-2.6.39.2/drivers/media/video/ov2640.c
32962 --- linux-2.6.39.2/drivers/media/video/ov2640.c 2011-05-19 00:06:34.000000000 -0400
32963 +++ linux-2.6.39.2/drivers/media/video/ov2640.c 2011-05-22 19:36:31.000000000 -0400
32964 @@ -1080,7 +1080,7 @@ static struct soc_camera_ops ov2640_ops
32965 .num_controls = ARRAY_SIZE(ov2640_controls),
32966 };
32967
32968 -static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32969 +static const struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
32970 .g_ctrl = ov2640_g_ctrl,
32971 .s_ctrl = ov2640_s_ctrl,
32972 .g_chip_ident = ov2640_g_chip_ident,
32973 @@ -1090,7 +1090,7 @@ static struct v4l2_subdev_core_ops ov264
32974 #endif
32975 };
32976
32977 -static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32978 +static const struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
32979 .s_stream = ov2640_s_stream,
32980 .g_mbus_fmt = ov2640_g_fmt,
32981 .s_mbus_fmt = ov2640_s_fmt,
32982 diff -urNp linux-2.6.39.2/drivers/media/video/ov772x.c linux-2.6.39.2/drivers/media/video/ov772x.c
32983 --- linux-2.6.39.2/drivers/media/video/ov772x.c 2011-05-19 00:06:34.000000000 -0400
32984 +++ linux-2.6.39.2/drivers/media/video/ov772x.c 2011-05-22 19:36:31.000000000 -0400
32985 @@ -1079,7 +1079,7 @@ static struct soc_camera_ops ov772x_ops
32986 .num_controls = ARRAY_SIZE(ov772x_controls),
32987 };
32988
32989 -static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32990 +static const struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
32991 .g_ctrl = ov772x_g_ctrl,
32992 .s_ctrl = ov772x_s_ctrl,
32993 .g_chip_ident = ov772x_g_chip_ident,
32994 @@ -1099,7 +1099,7 @@ static int ov772x_enum_fmt(struct v4l2_s
32995 return 0;
32996 }
32997
32998 -static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
32999 +static const struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
33000 .s_stream = ov772x_s_stream,
33001 .g_mbus_fmt = ov772x_g_fmt,
33002 .s_mbus_fmt = ov772x_s_fmt,
33003 diff -urNp linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-eeprom.c linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
33004 --- linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-19 00:06:34.000000000 -0400
33005 +++ linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-eeprom.c 2011-05-22 19:36:31.000000000 -0400
33006 @@ -120,6 +120,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw
33007 u8 *eeprom;
33008 struct tveeprom tvdata;
33009
33010 + pax_track_stack();
33011 +
33012 memset(&tvdata,0,sizeof(tvdata));
33013
33014 eeprom = pvr2_eeprom_fetch(hdw);
33015 diff -urNp linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
33016 --- linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-19 00:06:34.000000000 -0400
33017 +++ linux-2.6.39.2/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c 2011-05-22 19:36:31.000000000 -0400
33018 @@ -527,7 +527,7 @@ static u32 pvr2_i2c_functionality(struct
33019 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
33020 }
33021
33022 -static struct i2c_algorithm pvr2_i2c_algo_template = {
33023 +static const struct i2c_algorithm pvr2_i2c_algo_template = {
33024 .master_xfer = pvr2_i2c_xfer,
33025 .functionality = pvr2_i2c_functionality,
33026 };
33027 diff -urNp linux-2.6.39.2/drivers/media/video/rj54n1cb0c.c linux-2.6.39.2/drivers/media/video/rj54n1cb0c.c
33028 --- linux-2.6.39.2/drivers/media/video/rj54n1cb0c.c 2011-05-19 00:06:34.000000000 -0400
33029 +++ linux-2.6.39.2/drivers/media/video/rj54n1cb0c.c 2011-05-22 19:36:31.000000000 -0400
33030 @@ -1327,7 +1327,7 @@ static int rj54n1_s_ctrl(struct v4l2_sub
33031 return 0;
33032 }
33033
33034 -static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
33035 +static const struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
33036 .g_ctrl = rj54n1_g_ctrl,
33037 .s_ctrl = rj54n1_s_ctrl,
33038 .g_chip_ident = rj54n1_g_chip_ident,
33039 @@ -1337,7 +1337,7 @@ static struct v4l2_subdev_core_ops rj54n
33040 #endif
33041 };
33042
33043 -static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
33044 +static const struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
33045 .s_stream = rj54n1_s_stream,
33046 .s_mbus_fmt = rj54n1_s_fmt,
33047 .g_mbus_fmt = rj54n1_g_fmt,
33048 diff -urNp linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-capture.c linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-capture.c
33049 --- linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-19 00:06:34.000000000 -0400
33050 +++ linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-capture.c 2011-05-22 19:36:31.000000000 -0400
33051 @@ -376,7 +376,7 @@ static void fimc_unlock(struct vb2_queue
33052 mutex_unlock(&ctx->fimc_dev->lock);
33053 }
33054
33055 -static struct vb2_ops fimc_capture_qops = {
33056 +static const struct vb2_ops fimc_capture_qops = {
33057 .queue_setup = queue_setup,
33058 .buf_prepare = buffer_prepare,
33059 .buf_queue = buffer_queue,
33060 diff -urNp linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-core.c linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-core.c
33061 --- linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-19 00:06:34.000000000 -0400
33062 +++ linux-2.6.39.2/drivers/media/video/s5p-fimc/fimc-core.c 2011-05-22 19:36:31.000000000 -0400
33063 @@ -768,7 +768,7 @@ static void fimc_unlock(struct vb2_queue
33064 mutex_unlock(&ctx->fimc_dev->lock);
33065 }
33066
33067 -static struct vb2_ops fimc_qops = {
33068 +static const struct vb2_ops fimc_qops = {
33069 .queue_setup = fimc_queue_setup,
33070 .buf_prepare = fimc_buf_prepare,
33071 .buf_queue = fimc_buf_queue,
33072 diff -urNp linux-2.6.39.2/drivers/media/video/saa7134/saa6752hs.c linux-2.6.39.2/drivers/media/video/saa7134/saa6752hs.c
33073 --- linux-2.6.39.2/drivers/media/video/saa7134/saa6752hs.c 2011-05-19 00:06:34.000000000 -0400
33074 +++ linux-2.6.39.2/drivers/media/video/saa7134/saa6752hs.c 2011-05-22 19:36:31.000000000 -0400
33075 @@ -682,6 +682,8 @@ static int saa6752hs_init(struct v4l2_su
33076 unsigned char localPAT[256];
33077 unsigned char localPMT[256];
33078
33079 + pax_track_stack();
33080 +
33081 /* Set video format - must be done first as it resets other settings */
33082 set_reg8(client, 0x41, h->video_format);
33083
33084 diff -urNp linux-2.6.39.2/drivers/media/video/saa7134/saa7134-alsa.c linux-2.6.39.2/drivers/media/video/saa7134/saa7134-alsa.c
33085 --- linux-2.6.39.2/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-19 00:06:34.000000000 -0400
33086 +++ linux-2.6.39.2/drivers/media/video/saa7134/saa7134-alsa.c 2011-05-22 19:36:31.000000000 -0400
33087 @@ -808,7 +808,7 @@ static struct page *snd_card_saa7134_pag
33088 * ALSA capture callbacks definition
33089 */
33090
33091 -static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
33092 +static const struct snd_pcm_ops snd_card_saa7134_capture_ops = {
33093 .open = snd_card_saa7134_capture_open,
33094 .close = snd_card_saa7134_capture_close,
33095 .ioctl = snd_pcm_lib_ioctl,
33096 diff -urNp linux-2.6.39.2/drivers/media/video/saa7164/saa7164-cmd.c linux-2.6.39.2/drivers/media/video/saa7164/saa7164-cmd.c
33097 --- linux-2.6.39.2/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-19 00:06:34.000000000 -0400
33098 +++ linux-2.6.39.2/drivers/media/video/saa7164/saa7164-cmd.c 2011-05-22 19:36:31.000000000 -0400
33099 @@ -88,6 +88,8 @@ int saa7164_irq_dequeue(struct saa7164_d
33100 u8 tmp[512];
33101 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33102
33103 + pax_track_stack();
33104 +
33105 /* While any outstand message on the bus exists... */
33106 do {
33107
33108 @@ -141,6 +143,8 @@ int saa7164_cmd_dequeue(struct saa7164_d
33109 u8 tmp[512];
33110 dprintk(DBGLVL_CMD, "%s()\n", __func__);
33111
33112 + pax_track_stack();
33113 +
33114 while (loop) {
33115
33116 struct tmComResInfo tRsp = { 0, 0, 0, 0, 0, 0 };
33117 diff -urNp linux-2.6.39.2/drivers/media/video/sh_mobile_csi2.c linux-2.6.39.2/drivers/media/video/sh_mobile_csi2.c
33118 --- linux-2.6.39.2/drivers/media/video/sh_mobile_csi2.c 2011-05-19 00:06:34.000000000 -0400
33119 +++ linux-2.6.39.2/drivers/media/video/sh_mobile_csi2.c 2011-05-22 19:36:31.000000000 -0400
33120 @@ -127,12 +127,12 @@ static int sh_csi2_s_fmt(struct v4l2_sub
33121 return 0;
33122 }
33123
33124 -static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33125 +static const struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
33126 .s_mbus_fmt = sh_csi2_s_fmt,
33127 .try_mbus_fmt = sh_csi2_try_fmt,
33128 };
33129
33130 -static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33131 +static const struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
33132
33133 static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
33134 .core = &sh_csi2_subdev_core_ops,
33135 diff -urNp linux-2.6.39.2/drivers/media/video/soc_camera_platform.c linux-2.6.39.2/drivers/media/video/soc_camera_platform.c
33136 --- linux-2.6.39.2/drivers/media/video/soc_camera_platform.c 2011-05-19 00:06:34.000000000 -0400
33137 +++ linux-2.6.39.2/drivers/media/video/soc_camera_platform.c 2011-05-22 19:36:31.000000000 -0400
33138 @@ -70,7 +70,7 @@ static int soc_camera_platform_fill_fmt(
33139 return 0;
33140 }
33141
33142 -static struct v4l2_subdev_core_ops platform_subdev_core_ops;
33143 +static const struct v4l2_subdev_core_ops platform_subdev_core_ops;
33144
33145 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
33146 enum v4l2_mbus_pixelcode *code)
33147 @@ -115,7 +115,7 @@ static int soc_camera_platform_cropcap(s
33148 return 0;
33149 }
33150
33151 -static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33152 +static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
33153 .s_stream = soc_camera_platform_s_stream,
33154 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
33155 .cropcap = soc_camera_platform_cropcap,
33156 diff -urNp linux-2.6.39.2/drivers/media/video/tlg2300/pd-alsa.c linux-2.6.39.2/drivers/media/video/tlg2300/pd-alsa.c
33157 --- linux-2.6.39.2/drivers/media/video/tlg2300/pd-alsa.c 2011-05-19 00:06:34.000000000 -0400
33158 +++ linux-2.6.39.2/drivers/media/video/tlg2300/pd-alsa.c 2011-05-22 19:36:31.000000000 -0400
33159 @@ -265,7 +265,7 @@ static struct page *snd_pcm_pd_get_page(
33160 return vmalloc_to_page(pageptr);
33161 }
33162
33163 -static struct snd_pcm_ops pcm_capture_ops = {
33164 +static const struct snd_pcm_ops pcm_capture_ops = {
33165 .open = snd_pd_capture_open,
33166 .close = snd_pd_pcm_close,
33167 .ioctl = snd_pcm_lib_ioctl,
33168 diff -urNp linux-2.6.39.2/drivers/media/video/tw9910.c linux-2.6.39.2/drivers/media/video/tw9910.c
33169 --- linux-2.6.39.2/drivers/media/video/tw9910.c 2011-05-19 00:06:34.000000000 -0400
33170 +++ linux-2.6.39.2/drivers/media/video/tw9910.c 2011-05-22 19:36:31.000000000 -0400
33171 @@ -894,7 +894,7 @@ static struct soc_camera_ops tw9910_ops
33172 .enum_input = tw9910_enum_input,
33173 };
33174
33175 -static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33176 +static const struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
33177 .g_chip_ident = tw9910_g_chip_ident,
33178 .s_std = tw9910_s_std,
33179 #ifdef CONFIG_VIDEO_ADV_DEBUG
33180 @@ -913,7 +913,7 @@ static int tw9910_enum_fmt(struct v4l2_s
33181 return 0;
33182 }
33183
33184 -static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33185 +static const struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
33186 .s_stream = tw9910_s_stream,
33187 .g_mbus_fmt = tw9910_g_fmt,
33188 .s_mbus_fmt = tw9910_s_fmt,
33189 diff -urNp linux-2.6.39.2/drivers/media/video/usbvision/usbvision-core.c linux-2.6.39.2/drivers/media/video/usbvision/usbvision-core.c
33190 --- linux-2.6.39.2/drivers/media/video/usbvision/usbvision-core.c 2011-05-19 00:06:34.000000000 -0400
33191 +++ linux-2.6.39.2/drivers/media/video/usbvision/usbvision-core.c 2011-05-22 19:36:31.000000000 -0400
33192 @@ -799,6 +799,8 @@ static enum parse_state usbvision_parse_
33193 unsigned char rv, gv, bv;
33194 static unsigned char *Y, *U, *V;
33195
33196 + pax_track_stack();
33197 +
33198 frame = usbvision->cur_frame;
33199 image_size = frame->frmwidth * frame->frmheight;
33200 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
33201 diff -urNp linux-2.6.39.2/drivers/media/video/usbvision/usbvision-i2c.c linux-2.6.39.2/drivers/media/video/usbvision/usbvision-i2c.c
33202 --- linux-2.6.39.2/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-19 00:06:34.000000000 -0400
33203 +++ linux-2.6.39.2/drivers/media/video/usbvision/usbvision-i2c.c 2011-05-22 19:36:31.000000000 -0400
33204 @@ -189,7 +189,7 @@ static u32 functionality(struct i2c_adap
33205
33206 /* -----exported algorithm data: ------------------------------------- */
33207
33208 -static struct i2c_algorithm usbvision_algo = {
33209 +static const struct i2c_algorithm usbvision_algo = {
33210 .master_xfer = usbvision_i2c_xfer,
33211 .smbus_xfer = NULL,
33212 .functionality = functionality,
33213 diff -urNp linux-2.6.39.2/drivers/media/video/v4l2-device.c linux-2.6.39.2/drivers/media/video/v4l2-device.c
33214 --- linux-2.6.39.2/drivers/media/video/v4l2-device.c 2011-05-19 00:06:34.000000000 -0400
33215 +++ linux-2.6.39.2/drivers/media/video/v4l2-device.c 2011-05-22 19:36:31.000000000 -0400
33216 @@ -71,9 +71,9 @@ int v4l2_device_put(struct v4l2_device *
33217 EXPORT_SYMBOL_GPL(v4l2_device_put);
33218
33219 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
33220 - atomic_t *instance)
33221 + atomic_unchecked_t *instance)
33222 {
33223 - int num = atomic_inc_return(instance) - 1;
33224 + int num = atomic_inc_return_unchecked(instance) - 1;
33225 int len = strlen(basename);
33226
33227 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
33228 diff -urNp linux-2.6.39.2/drivers/media/video/videobuf-dma-sg.c linux-2.6.39.2/drivers/media/video/videobuf-dma-sg.c
33229 --- linux-2.6.39.2/drivers/media/video/videobuf-dma-sg.c 2011-05-19 00:06:34.000000000 -0400
33230 +++ linux-2.6.39.2/drivers/media/video/videobuf-dma-sg.c 2011-05-22 19:36:31.000000000 -0400
33231 @@ -606,6 +606,8 @@ void *videobuf_sg_alloc(size_t size)
33232 {
33233 struct videobuf_queue q;
33234
33235 + pax_track_stack();
33236 +
33237 /* Required to make generic handler to call __videobuf_alloc */
33238 q.int_ops = &sg_ops;
33239
33240 diff -urNp linux-2.6.39.2/drivers/message/fusion/mptbase.c linux-2.6.39.2/drivers/message/fusion/mptbase.c
33241 --- linux-2.6.39.2/drivers/message/fusion/mptbase.c 2011-05-19 00:06:34.000000000 -0400
33242 +++ linux-2.6.39.2/drivers/message/fusion/mptbase.c 2011-05-22 19:41:37.000000000 -0400
33243 @@ -143,7 +143,7 @@ static int MptDriverClass[MPT_MAX_PRO
33244 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33245 /* Reset handler lookup table */
33246 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33247 -static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33248 +static const struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
33249
33250 #ifdef CONFIG_PROC_FS
33251 static struct proc_dir_entry *mpt_proc_root_dir;
33252 @@ -772,7 +772,7 @@ mpt_reset_deregister(u8 cb_idx)
33253 * @cb_idx: MPT protocol driver index
33254 */
33255 int
33256 -mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33257 +mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
33258 {
33259 MPT_ADAPTER *ioc;
33260 const struct pci_device_id *id;
33261 @@ -801,7 +801,7 @@ mpt_device_driver_register(struct mpt_pc
33262 void
33263 mpt_device_driver_deregister(u8 cb_idx)
33264 {
33265 - struct mpt_pci_driver *dd_cbfunc;
33266 + const struct mpt_pci_driver *dd_cbfunc;
33267 MPT_ADAPTER *ioc;
33268
33269 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
33270 @@ -6683,8 +6683,13 @@ static int mpt_iocinfo_proc_show(struct
33271 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33272 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33273
33274 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33275 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33276 +#else
33277 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33278 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33279 +#endif
33280 +
33281 /*
33282 * Rounding UP to nearest 4-kB boundary here...
33283 */
33284 diff -urNp linux-2.6.39.2/drivers/message/fusion/mptbase.h linux-2.6.39.2/drivers/message/fusion/mptbase.h
33285 --- linux-2.6.39.2/drivers/message/fusion/mptbase.h 2011-05-19 00:06:34.000000000 -0400
33286 +++ linux-2.6.39.2/drivers/message/fusion/mptbase.h 2011-05-22 19:36:31.000000000 -0400
33287 @@ -908,7 +908,7 @@ extern int mpt_event_register(u8 cb_idx
33288 extern void mpt_event_deregister(u8 cb_idx);
33289 extern int mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func);
33290 extern void mpt_reset_deregister(u8 cb_idx);
33291 -extern int mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33292 +extern int mpt_device_driver_register(const struct mpt_pci_driver * dd_cbfunc, u8 cb_idx);
33293 extern void mpt_device_driver_deregister(u8 cb_idx);
33294 extern MPT_FRAME_HDR *mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc);
33295 extern void mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf);
33296 diff -urNp linux-2.6.39.2/drivers/message/fusion/mptctl.c linux-2.6.39.2/drivers/message/fusion/mptctl.c
33297 --- linux-2.6.39.2/drivers/message/fusion/mptctl.c 2011-05-19 00:06:34.000000000 -0400
33298 +++ linux-2.6.39.2/drivers/message/fusion/mptctl.c 2011-05-22 19:36:31.000000000 -0400
33299 @@ -3000,7 +3000,7 @@ mptctl_remove(struct pci_dev *pdev)
33300 {
33301 }
33302
33303 -static struct mpt_pci_driver mptctl_driver = {
33304 +static const struct mpt_pci_driver mptctl_driver = {
33305 .probe = mptctl_probe,
33306 .remove = mptctl_remove,
33307 };
33308 diff -urNp linux-2.6.39.2/drivers/message/fusion/mptsas.c linux-2.6.39.2/drivers/message/fusion/mptsas.c
33309 --- linux-2.6.39.2/drivers/message/fusion/mptsas.c 2011-05-19 00:06:34.000000000 -0400
33310 +++ linux-2.6.39.2/drivers/message/fusion/mptsas.c 2011-05-22 19:36:31.000000000 -0400
33311 @@ -439,6 +439,23 @@ mptsas_is_end_device(struct mptsas_devin
33312 return 0;
33313 }
33314
33315 +static inline void
33316 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33317 +{
33318 + if (phy_info->port_details) {
33319 + phy_info->port_details->rphy = rphy;
33320 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33321 + ioc->name, rphy));
33322 + }
33323 +
33324 + if (rphy) {
33325 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33326 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33327 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33328 + ioc->name, rphy, rphy->dev.release));
33329 + }
33330 +}
33331 +
33332 /* no mutex */
33333 static void
33334 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33335 @@ -477,23 +494,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *p
33336 return NULL;
33337 }
33338
33339 -static inline void
33340 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33341 -{
33342 - if (phy_info->port_details) {
33343 - phy_info->port_details->rphy = rphy;
33344 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33345 - ioc->name, rphy));
33346 - }
33347 -
33348 - if (rphy) {
33349 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33350 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33351 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33352 - ioc->name, rphy, rphy->dev.release));
33353 - }
33354 -}
33355 -
33356 static inline struct sas_port *
33357 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33358 {
33359 diff -urNp linux-2.6.39.2/drivers/message/fusion/mptscsih.c linux-2.6.39.2/drivers/message/fusion/mptscsih.c
33360 --- linux-2.6.39.2/drivers/message/fusion/mptscsih.c 2011-05-19 00:06:34.000000000 -0400
33361 +++ linux-2.6.39.2/drivers/message/fusion/mptscsih.c 2011-05-22 19:36:31.000000000 -0400
33362 @@ -1268,15 +1268,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33363
33364 h = shost_priv(SChost);
33365
33366 - if (h) {
33367 - if (h->info_kbuf == NULL)
33368 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33369 - return h->info_kbuf;
33370 - h->info_kbuf[0] = '\0';
33371 + if (!h)
33372 + return NULL;
33373
33374 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33375 - h->info_kbuf[size-1] = '\0';
33376 - }
33377 + if (h->info_kbuf == NULL)
33378 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33379 + return h->info_kbuf;
33380 + h->info_kbuf[0] = '\0';
33381 +
33382 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33383 + h->info_kbuf[size-1] = '\0';
33384
33385 return h->info_kbuf;
33386 }
33387 diff -urNp linux-2.6.39.2/drivers/message/i2o/i2o_config.c linux-2.6.39.2/drivers/message/i2o/i2o_config.c
33388 --- linux-2.6.39.2/drivers/message/i2o/i2o_config.c 2011-05-19 00:06:34.000000000 -0400
33389 +++ linux-2.6.39.2/drivers/message/i2o/i2o_config.c 2011-05-22 19:36:31.000000000 -0400
33390 @@ -781,6 +781,8 @@ static int i2o_cfg_passthru(unsigned lon
33391 struct i2o_message *msg;
33392 unsigned int iop;
33393
33394 + pax_track_stack();
33395 +
33396 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
33397 return -EFAULT;
33398
33399 diff -urNp linux-2.6.39.2/drivers/message/i2o/i2o_proc.c linux-2.6.39.2/drivers/message/i2o/i2o_proc.c
33400 --- linux-2.6.39.2/drivers/message/i2o/i2o_proc.c 2011-05-19 00:06:34.000000000 -0400
33401 +++ linux-2.6.39.2/drivers/message/i2o/i2o_proc.c 2011-05-22 19:36:31.000000000 -0400
33402 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33403 "Array Controller Device"
33404 };
33405
33406 -static char *chtostr(u8 * chars, int n)
33407 -{
33408 - char tmp[256];
33409 - tmp[0] = 0;
33410 - return strncat(tmp, (char *)chars, n);
33411 -}
33412 -
33413 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33414 char *group)
33415 {
33416 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct
33417
33418 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33419 seq_printf(seq, "%-#8x", ddm_table.module_id);
33420 - seq_printf(seq, "%-29s",
33421 - chtostr(ddm_table.module_name_version, 28));
33422 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33423 seq_printf(seq, "%9d ", ddm_table.data_size);
33424 seq_printf(seq, "%8d", ddm_table.code_size);
33425
33426 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(s
33427
33428 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33429 seq_printf(seq, "%-#8x", dst->module_id);
33430 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33431 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33432 + seq_printf(seq, "%-.28s", dst->module_name_version);
33433 + seq_printf(seq, "%-.8s", dst->date);
33434 seq_printf(seq, "%8d ", dst->module_size);
33435 seq_printf(seq, "%8d ", dst->mpb_size);
33436 seq_printf(seq, "0x%04x", dst->module_flags);
33437 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(str
33438 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33439 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33440 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33441 - seq_printf(seq, "Vendor info : %s\n",
33442 - chtostr((u8 *) (work32 + 2), 16));
33443 - seq_printf(seq, "Product info : %s\n",
33444 - chtostr((u8 *) (work32 + 6), 16));
33445 - seq_printf(seq, "Description : %s\n",
33446 - chtostr((u8 *) (work32 + 10), 16));
33447 - seq_printf(seq, "Product rev. : %s\n",
33448 - chtostr((u8 *) (work32 + 14), 8));
33449 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33450 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33451 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33452 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33453
33454 seq_printf(seq, "Serial number : ");
33455 print_serial_number(seq, (u8 *) (work32 + 16),
33456 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(str
33457 }
33458
33459 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33460 - seq_printf(seq, "Module name : %s\n",
33461 - chtostr(result.module_name, 24));
33462 - seq_printf(seq, "Module revision : %s\n",
33463 - chtostr(result.module_rev, 8));
33464 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
33465 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33466
33467 seq_printf(seq, "Serial number : ");
33468 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33469 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq
33470 return 0;
33471 }
33472
33473 - seq_printf(seq, "Device name : %s\n",
33474 - chtostr(result.device_name, 64));
33475 - seq_printf(seq, "Service name : %s\n",
33476 - chtostr(result.service_name, 64));
33477 - seq_printf(seq, "Physical name : %s\n",
33478 - chtostr(result.physical_location, 64));
33479 - seq_printf(seq, "Instance number : %s\n",
33480 - chtostr(result.instance_number, 4));
33481 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
33482 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
33483 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
33484 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
33485
33486 return 0;
33487 }
33488 diff -urNp linux-2.6.39.2/drivers/message/i2o/iop.c linux-2.6.39.2/drivers/message/i2o/iop.c
33489 --- linux-2.6.39.2/drivers/message/i2o/iop.c 2011-05-19 00:06:34.000000000 -0400
33490 +++ linux-2.6.39.2/drivers/message/i2o/iop.c 2011-05-22 19:36:31.000000000 -0400
33491 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_contro
33492
33493 spin_lock_irqsave(&c->context_list_lock, flags);
33494
33495 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
33496 - atomic_inc(&c->context_list_counter);
33497 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
33498 + atomic_inc_unchecked(&c->context_list_counter);
33499
33500 - entry->context = atomic_read(&c->context_list_counter);
33501 + entry->context = atomic_read_unchecked(&c->context_list_counter);
33502
33503 list_add(&entry->list, &c->context_list);
33504
33505 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(voi
33506
33507 #if BITS_PER_LONG == 64
33508 spin_lock_init(&c->context_list_lock);
33509 - atomic_set(&c->context_list_counter, 0);
33510 + atomic_set_unchecked(&c->context_list_counter, 0);
33511 INIT_LIST_HEAD(&c->context_list);
33512 #endif
33513
33514 diff -urNp linux-2.6.39.2/drivers/mfd/ab3100-core.c linux-2.6.39.2/drivers/mfd/ab3100-core.c
33515 --- linux-2.6.39.2/drivers/mfd/ab3100-core.c 2011-05-19 00:06:34.000000000 -0400
33516 +++ linux-2.6.39.2/drivers/mfd/ab3100-core.c 2011-05-22 19:36:31.000000000 -0400
33517 @@ -385,7 +385,7 @@ static int ab3100_event_registers_startu
33518 return 0;
33519 }
33520
33521 -static struct abx500_ops ab3100_ops = {
33522 +static const struct abx500_ops ab3100_ops = {
33523 .get_chip_id = ab3100_get_chip_id,
33524 .set_register = set_register_interruptible,
33525 .get_register = get_register_interruptible,
33526 diff -urNp linux-2.6.39.2/drivers/mfd/ab3550-core.c linux-2.6.39.2/drivers/mfd/ab3550-core.c
33527 --- linux-2.6.39.2/drivers/mfd/ab3550-core.c 2011-05-19 00:06:34.000000000 -0400
33528 +++ linux-2.6.39.2/drivers/mfd/ab3550-core.c 2011-05-22 19:36:31.000000000 -0400
33529 @@ -676,7 +676,7 @@ static int ab3550_startup_irq_enabled(st
33530 return val;
33531 }
33532
33533 -static struct abx500_ops ab3550_ops = {
33534 +static const struct abx500_ops ab3550_ops = {
33535 .get_chip_id = ab3550_get_chip_id,
33536 .get_register = ab3550_get_register_interruptible,
33537 .set_register = ab3550_set_register_interruptible,
33538 diff -urNp linux-2.6.39.2/drivers/mfd/ab8500-core.c linux-2.6.39.2/drivers/mfd/ab8500-core.c
33539 --- linux-2.6.39.2/drivers/mfd/ab8500-core.c 2011-05-19 00:06:34.000000000 -0400
33540 +++ linux-2.6.39.2/drivers/mfd/ab8500-core.c 2011-05-22 19:36:31.000000000 -0400
33541 @@ -223,7 +223,7 @@ static int ab8500_mask_and_set_register(
33542
33543 }
33544
33545 -static struct abx500_ops ab8500_ops = {
33546 +static const struct abx500_ops ab8500_ops = {
33547 .get_chip_id = ab8500_get_chip_id,
33548 .get_register = ab8500_get_register,
33549 .set_register = ab8500_set_register,
33550 diff -urNp linux-2.6.39.2/drivers/mfd/abx500-core.c linux-2.6.39.2/drivers/mfd/abx500-core.c
33551 --- linux-2.6.39.2/drivers/mfd/abx500-core.c 2011-05-19 00:06:34.000000000 -0400
33552 +++ linux-2.6.39.2/drivers/mfd/abx500-core.c 2011-05-22 19:36:31.000000000 -0400
33553 @@ -18,7 +18,7 @@ struct abx500_device_entry {
33554 struct device *dev;
33555 };
33556
33557 -static void lookup_ops(struct device *dev, struct abx500_ops **ops)
33558 +static void lookup_ops(struct device *dev, const struct abx500_ops **ops)
33559 {
33560 struct abx500_device_entry *dev_entry;
33561
33562 @@ -31,7 +31,7 @@ static void lookup_ops(struct device *de
33563 }
33564 }
33565
33566 -int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
33567 +int abx500_register_ops(struct device *dev, const struct abx500_ops *ops)
33568 {
33569 struct abx500_device_entry *dev_entry;
33570
33571 @@ -65,7 +65,7 @@ EXPORT_SYMBOL(abx500_remove_ops);
33572 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
33573 u8 value)
33574 {
33575 - struct abx500_ops *ops;
33576 + const struct abx500_ops *ops;
33577
33578 lookup_ops(dev->parent, &ops);
33579 if ((ops != NULL) && (ops->set_register != NULL))
33580 @@ -78,7 +78,7 @@ EXPORT_SYMBOL(abx500_set_register_interr
33581 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
33582 u8 *value)
33583 {
33584 - struct abx500_ops *ops;
33585 + const struct abx500_ops *ops;
33586
33587 lookup_ops(dev->parent, &ops);
33588 if ((ops != NULL) && (ops->get_register != NULL))
33589 @@ -91,7 +91,7 @@ EXPORT_SYMBOL(abx500_get_register_interr
33590 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
33591 u8 first_reg, u8 *regvals, u8 numregs)
33592 {
33593 - struct abx500_ops *ops;
33594 + const struct abx500_ops *ops;
33595
33596 lookup_ops(dev->parent, &ops);
33597 if ((ops != NULL) && (ops->get_register_page != NULL))
33598 @@ -105,7 +105,7 @@ EXPORT_SYMBOL(abx500_get_register_page_i
33599 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
33600 u8 reg, u8 bitmask, u8 bitvalues)
33601 {
33602 - struct abx500_ops *ops;
33603 + const struct abx500_ops *ops;
33604
33605 lookup_ops(dev->parent, &ops);
33606 if ((ops != NULL) && (ops->mask_and_set_register != NULL))
33607 @@ -118,7 +118,7 @@ EXPORT_SYMBOL(abx500_mask_and_set_regist
33608
33609 int abx500_get_chip_id(struct device *dev)
33610 {
33611 - struct abx500_ops *ops;
33612 + const struct abx500_ops *ops;
33613
33614 lookup_ops(dev->parent, &ops);
33615 if ((ops != NULL) && (ops->get_chip_id != NULL))
33616 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(abx500_get_chip_id);
33617
33618 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event)
33619 {
33620 - struct abx500_ops *ops;
33621 + const struct abx500_ops *ops;
33622
33623 lookup_ops(dev->parent, &ops);
33624 if ((ops != NULL) && (ops->event_registers_startup_state_get != NULL))
33625 @@ -142,7 +142,7 @@ EXPORT_SYMBOL(abx500_event_registers_sta
33626
33627 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq)
33628 {
33629 - struct abx500_ops *ops;
33630 + const struct abx500_ops *ops;
33631
33632 lookup_ops(dev->parent, &ops);
33633 if ((ops != NULL) && (ops->startup_irq_enabled != NULL))
33634 diff -urNp linux-2.6.39.2/drivers/mfd/janz-cmodio.c linux-2.6.39.2/drivers/mfd/janz-cmodio.c
33635 --- linux-2.6.39.2/drivers/mfd/janz-cmodio.c 2011-05-19 00:06:34.000000000 -0400
33636 +++ linux-2.6.39.2/drivers/mfd/janz-cmodio.c 2011-05-22 19:36:31.000000000 -0400
33637 @@ -13,6 +13,7 @@
33638
33639 #include <linux/kernel.h>
33640 #include <linux/module.h>
33641 +#include <linux/slab.h>
33642 #include <linux/init.h>
33643 #include <linux/pci.h>
33644 #include <linux/interrupt.h>
33645 diff -urNp linux-2.6.39.2/drivers/mfd/mcp-sa11x0.c linux-2.6.39.2/drivers/mfd/mcp-sa11x0.c
33646 --- linux-2.6.39.2/drivers/mfd/mcp-sa11x0.c 2011-05-19 00:06:34.000000000 -0400
33647 +++ linux-2.6.39.2/drivers/mfd/mcp-sa11x0.c 2011-05-22 19:36:31.000000000 -0400
33648 @@ -128,7 +128,7 @@ static void mcp_sa11x0_disable(struct mc
33649 /*
33650 * Our methods.
33651 */
33652 -static struct mcp_ops mcp_sa11x0 = {
33653 +static const struct mcp_ops mcp_sa11x0 = {
33654 .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
33655 .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
33656 .reg_write = mcp_sa11x0_write,
33657 diff -urNp linux-2.6.39.2/drivers/mfd/wm8350-i2c.c linux-2.6.39.2/drivers/mfd/wm8350-i2c.c
33658 --- linux-2.6.39.2/drivers/mfd/wm8350-i2c.c 2011-05-19 00:06:34.000000000 -0400
33659 +++ linux-2.6.39.2/drivers/mfd/wm8350-i2c.c 2011-05-22 19:36:31.000000000 -0400
33660 @@ -44,6 +44,8 @@ static int wm8350_i2c_write_device(struc
33661 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
33662 int ret;
33663
33664 + pax_track_stack();
33665 +
33666 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
33667 return -EINVAL;
33668
33669 diff -urNp linux-2.6.39.2/drivers/misc/enclosure.c linux-2.6.39.2/drivers/misc/enclosure.c
33670 --- linux-2.6.39.2/drivers/misc/enclosure.c 2011-05-19 00:06:34.000000000 -0400
33671 +++ linux-2.6.39.2/drivers/misc/enclosure.c 2011-05-22 19:36:31.000000000 -0400
33672 @@ -161,7 +161,7 @@ enclosure_register(struct device *dev, c
33673 }
33674 EXPORT_SYMBOL_GPL(enclosure_register);
33675
33676 -static struct enclosure_component_callbacks enclosure_null_callbacks;
33677 +static const struct enclosure_component_callbacks enclosure_null_callbacks;
33678
33679 /**
33680 * enclosure_unregister - remove an enclosure
33681 diff -urNp linux-2.6.39.2/drivers/misc/kgdbts.c linux-2.6.39.2/drivers/misc/kgdbts.c
33682 --- linux-2.6.39.2/drivers/misc/kgdbts.c 2011-05-19 00:06:34.000000000 -0400
33683 +++ linux-2.6.39.2/drivers/misc/kgdbts.c 2011-05-22 19:36:31.000000000 -0400
33684 @@ -118,7 +118,7 @@
33685 } while (0)
33686 #define MAX_CONFIG_LEN 40
33687
33688 -static struct kgdb_io kgdbts_io_ops;
33689 +static const struct kgdb_io kgdbts_io_ops;
33690 static char get_buf[BUFMAX];
33691 static int get_buf_cnt;
33692 static char put_buf[BUFMAX];
33693 @@ -1103,7 +1103,7 @@ static void kgdbts_post_exp_handler(void
33694 module_put(THIS_MODULE);
33695 }
33696
33697 -static struct kgdb_io kgdbts_io_ops = {
33698 +static const struct kgdb_io kgdbts_io_ops = {
33699 .name = "kgdbts",
33700 .read_char = kgdbts_get_char,
33701 .write_char = kgdbts_put_char,
33702 diff -urNp linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.c linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.c
33703 --- linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-19 00:06:34.000000000 -0400
33704 +++ linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.c 2011-05-22 19:36:31.000000000 -0400
33705 @@ -435,7 +435,7 @@ static irqreturn_t lis302dl_interrupt(in
33706 * the lid is closed. This leads to interrupts as soon as a little move
33707 * is done.
33708 */
33709 - atomic_inc(&lis3_dev.count);
33710 + atomic_inc_unchecked(&lis3_dev.count);
33711
33712 wake_up_interruptible(&lis3_dev.misc_wait);
33713 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33714 @@ -518,7 +518,7 @@ static int lis3lv02d_misc_open(struct in
33715 if (lis3_dev.pm_dev)
33716 pm_runtime_get_sync(lis3_dev.pm_dev);
33717
33718 - atomic_set(&lis3_dev.count, 0);
33719 + atomic_set_unchecked(&lis3_dev.count, 0);
33720 return 0;
33721 }
33722
33723 @@ -545,7 +545,7 @@ static ssize_t lis3lv02d_misc_read(struc
33724 add_wait_queue(&lis3_dev.misc_wait, &wait);
33725 while (true) {
33726 set_current_state(TASK_INTERRUPTIBLE);
33727 - data = atomic_xchg(&lis3_dev.count, 0);
33728 + data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33729 if (data)
33730 break;
33731
33732 @@ -583,7 +583,7 @@ out:
33733 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33734 {
33735 poll_wait(file, &lis3_dev.misc_wait, wait);
33736 - if (atomic_read(&lis3_dev.count))
33737 + if (atomic_read_unchecked(&lis3_dev.count))
33738 return POLLIN | POLLRDNORM;
33739 return 0;
33740 }
33741 diff -urNp linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.h linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.h
33742 --- linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-19 00:06:34.000000000 -0400
33743 +++ linux-2.6.39.2/drivers/misc/lis3lv02d/lis3lv02d.h 2011-05-22 19:36:31.000000000 -0400
33744 @@ -265,7 +265,7 @@ struct lis3lv02d {
33745 struct input_polled_dev *idev; /* input device */
33746 struct platform_device *pdev; /* platform device */
33747 struct regulator_bulk_data regulators[2];
33748 - atomic_t count; /* interrupt count after last read */
33749 + atomic_unchecked_t count; /* interrupt count after last read */
33750 union axis_conversion ac; /* hw -> logical axis */
33751 int mapped_btns[3];
33752
33753 diff -urNp linux-2.6.39.2/drivers/misc/sgi-gru/gruhandles.c linux-2.6.39.2/drivers/misc/sgi-gru/gruhandles.c
33754 --- linux-2.6.39.2/drivers/misc/sgi-gru/gruhandles.c 2011-05-19 00:06:34.000000000 -0400
33755 +++ linux-2.6.39.2/drivers/misc/sgi-gru/gruhandles.c 2011-05-22 19:36:31.000000000 -0400
33756 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op
33757 unsigned long nsec;
33758
33759 nsec = CLKS2NSEC(clks);
33760 - atomic_long_inc(&mcs_op_statistics[op].count);
33761 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
33762 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
33763 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
33764 if (mcs_op_statistics[op].max < nsec)
33765 mcs_op_statistics[op].max = nsec;
33766 }
33767 diff -urNp linux-2.6.39.2/drivers/misc/sgi-gru/gruprocfs.c linux-2.6.39.2/drivers/misc/sgi-gru/gruprocfs.c
33768 --- linux-2.6.39.2/drivers/misc/sgi-gru/gruprocfs.c 2011-05-19 00:06:34.000000000 -0400
33769 +++ linux-2.6.39.2/drivers/misc/sgi-gru/gruprocfs.c 2011-05-22 19:36:31.000000000 -0400
33770 @@ -32,9 +32,9 @@
33771
33772 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
33773
33774 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
33775 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
33776 {
33777 - unsigned long val = atomic_long_read(v);
33778 + unsigned long val = atomic_long_read_unchecked(v);
33779
33780 seq_printf(s, "%16lu %s\n", val, id);
33781 }
33782 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct se
33783
33784 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
33785 for (op = 0; op < mcsop_last; op++) {
33786 - count = atomic_long_read(&mcs_op_statistics[op].count);
33787 - total = atomic_long_read(&mcs_op_statistics[op].total);
33788 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
33789 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
33790 max = mcs_op_statistics[op].max;
33791 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
33792 count ? total / count : 0, max);
33793 diff -urNp linux-2.6.39.2/drivers/misc/sgi-gru/grutables.h linux-2.6.39.2/drivers/misc/sgi-gru/grutables.h
33794 --- linux-2.6.39.2/drivers/misc/sgi-gru/grutables.h 2011-05-19 00:06:34.000000000 -0400
33795 +++ linux-2.6.39.2/drivers/misc/sgi-gru/grutables.h 2011-05-22 19:36:31.000000000 -0400
33796 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
33797 * GRU statistics.
33798 */
33799 struct gru_stats_s {
33800 - atomic_long_t vdata_alloc;
33801 - atomic_long_t vdata_free;
33802 - atomic_long_t gts_alloc;
33803 - atomic_long_t gts_free;
33804 - atomic_long_t gms_alloc;
33805 - atomic_long_t gms_free;
33806 - atomic_long_t gts_double_allocate;
33807 - atomic_long_t assign_context;
33808 - atomic_long_t assign_context_failed;
33809 - atomic_long_t free_context;
33810 - atomic_long_t load_user_context;
33811 - atomic_long_t load_kernel_context;
33812 - atomic_long_t lock_kernel_context;
33813 - atomic_long_t unlock_kernel_context;
33814 - atomic_long_t steal_user_context;
33815 - atomic_long_t steal_kernel_context;
33816 - atomic_long_t steal_context_failed;
33817 - atomic_long_t nopfn;
33818 - atomic_long_t asid_new;
33819 - atomic_long_t asid_next;
33820 - atomic_long_t asid_wrap;
33821 - atomic_long_t asid_reuse;
33822 - atomic_long_t intr;
33823 - atomic_long_t intr_cbr;
33824 - atomic_long_t intr_tfh;
33825 - atomic_long_t intr_spurious;
33826 - atomic_long_t intr_mm_lock_failed;
33827 - atomic_long_t call_os;
33828 - atomic_long_t call_os_wait_queue;
33829 - atomic_long_t user_flush_tlb;
33830 - atomic_long_t user_unload_context;
33831 - atomic_long_t user_exception;
33832 - atomic_long_t set_context_option;
33833 - atomic_long_t check_context_retarget_intr;
33834 - atomic_long_t check_context_unload;
33835 - atomic_long_t tlb_dropin;
33836 - atomic_long_t tlb_preload_page;
33837 - atomic_long_t tlb_dropin_fail_no_asid;
33838 - atomic_long_t tlb_dropin_fail_upm;
33839 - atomic_long_t tlb_dropin_fail_invalid;
33840 - atomic_long_t tlb_dropin_fail_range_active;
33841 - atomic_long_t tlb_dropin_fail_idle;
33842 - atomic_long_t tlb_dropin_fail_fmm;
33843 - atomic_long_t tlb_dropin_fail_no_exception;
33844 - atomic_long_t tfh_stale_on_fault;
33845 - atomic_long_t mmu_invalidate_range;
33846 - atomic_long_t mmu_invalidate_page;
33847 - atomic_long_t flush_tlb;
33848 - atomic_long_t flush_tlb_gru;
33849 - atomic_long_t flush_tlb_gru_tgh;
33850 - atomic_long_t flush_tlb_gru_zero_asid;
33851 -
33852 - atomic_long_t copy_gpa;
33853 - atomic_long_t read_gpa;
33854 -
33855 - atomic_long_t mesq_receive;
33856 - atomic_long_t mesq_receive_none;
33857 - atomic_long_t mesq_send;
33858 - atomic_long_t mesq_send_failed;
33859 - atomic_long_t mesq_noop;
33860 - atomic_long_t mesq_send_unexpected_error;
33861 - atomic_long_t mesq_send_lb_overflow;
33862 - atomic_long_t mesq_send_qlimit_reached;
33863 - atomic_long_t mesq_send_amo_nacked;
33864 - atomic_long_t mesq_send_put_nacked;
33865 - atomic_long_t mesq_page_overflow;
33866 - atomic_long_t mesq_qf_locked;
33867 - atomic_long_t mesq_qf_noop_not_full;
33868 - atomic_long_t mesq_qf_switch_head_failed;
33869 - atomic_long_t mesq_qf_unexpected_error;
33870 - atomic_long_t mesq_noop_unexpected_error;
33871 - atomic_long_t mesq_noop_lb_overflow;
33872 - atomic_long_t mesq_noop_qlimit_reached;
33873 - atomic_long_t mesq_noop_amo_nacked;
33874 - atomic_long_t mesq_noop_put_nacked;
33875 - atomic_long_t mesq_noop_page_overflow;
33876 + atomic_long_unchecked_t vdata_alloc;
33877 + atomic_long_unchecked_t vdata_free;
33878 + atomic_long_unchecked_t gts_alloc;
33879 + atomic_long_unchecked_t gts_free;
33880 + atomic_long_unchecked_t gms_alloc;
33881 + atomic_long_unchecked_t gms_free;
33882 + atomic_long_unchecked_t gts_double_allocate;
33883 + atomic_long_unchecked_t assign_context;
33884 + atomic_long_unchecked_t assign_context_failed;
33885 + atomic_long_unchecked_t free_context;
33886 + atomic_long_unchecked_t load_user_context;
33887 + atomic_long_unchecked_t load_kernel_context;
33888 + atomic_long_unchecked_t lock_kernel_context;
33889 + atomic_long_unchecked_t unlock_kernel_context;
33890 + atomic_long_unchecked_t steal_user_context;
33891 + atomic_long_unchecked_t steal_kernel_context;
33892 + atomic_long_unchecked_t steal_context_failed;
33893 + atomic_long_unchecked_t nopfn;
33894 + atomic_long_unchecked_t asid_new;
33895 + atomic_long_unchecked_t asid_next;
33896 + atomic_long_unchecked_t asid_wrap;
33897 + atomic_long_unchecked_t asid_reuse;
33898 + atomic_long_unchecked_t intr;
33899 + atomic_long_unchecked_t intr_cbr;
33900 + atomic_long_unchecked_t intr_tfh;
33901 + atomic_long_unchecked_t intr_spurious;
33902 + atomic_long_unchecked_t intr_mm_lock_failed;
33903 + atomic_long_unchecked_t call_os;
33904 + atomic_long_unchecked_t call_os_wait_queue;
33905 + atomic_long_unchecked_t user_flush_tlb;
33906 + atomic_long_unchecked_t user_unload_context;
33907 + atomic_long_unchecked_t user_exception;
33908 + atomic_long_unchecked_t set_context_option;
33909 + atomic_long_unchecked_t check_context_retarget_intr;
33910 + atomic_long_unchecked_t check_context_unload;
33911 + atomic_long_unchecked_t tlb_dropin;
33912 + atomic_long_unchecked_t tlb_preload_page;
33913 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
33914 + atomic_long_unchecked_t tlb_dropin_fail_upm;
33915 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
33916 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
33917 + atomic_long_unchecked_t tlb_dropin_fail_idle;
33918 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
33919 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
33920 + atomic_long_unchecked_t tfh_stale_on_fault;
33921 + atomic_long_unchecked_t mmu_invalidate_range;
33922 + atomic_long_unchecked_t mmu_invalidate_page;
33923 + atomic_long_unchecked_t flush_tlb;
33924 + atomic_long_unchecked_t flush_tlb_gru;
33925 + atomic_long_unchecked_t flush_tlb_gru_tgh;
33926 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
33927 +
33928 + atomic_long_unchecked_t copy_gpa;
33929 + atomic_long_unchecked_t read_gpa;
33930 +
33931 + atomic_long_unchecked_t mesq_receive;
33932 + atomic_long_unchecked_t mesq_receive_none;
33933 + atomic_long_unchecked_t mesq_send;
33934 + atomic_long_unchecked_t mesq_send_failed;
33935 + atomic_long_unchecked_t mesq_noop;
33936 + atomic_long_unchecked_t mesq_send_unexpected_error;
33937 + atomic_long_unchecked_t mesq_send_lb_overflow;
33938 + atomic_long_unchecked_t mesq_send_qlimit_reached;
33939 + atomic_long_unchecked_t mesq_send_amo_nacked;
33940 + atomic_long_unchecked_t mesq_send_put_nacked;
33941 + atomic_long_unchecked_t mesq_page_overflow;
33942 + atomic_long_unchecked_t mesq_qf_locked;
33943 + atomic_long_unchecked_t mesq_qf_noop_not_full;
33944 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
33945 + atomic_long_unchecked_t mesq_qf_unexpected_error;
33946 + atomic_long_unchecked_t mesq_noop_unexpected_error;
33947 + atomic_long_unchecked_t mesq_noop_lb_overflow;
33948 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
33949 + atomic_long_unchecked_t mesq_noop_amo_nacked;
33950 + atomic_long_unchecked_t mesq_noop_put_nacked;
33951 + atomic_long_unchecked_t mesq_noop_page_overflow;
33952
33953 };
33954
33955 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start
33956 tghop_invalidate, mcsop_last};
33957
33958 struct mcs_op_statistic {
33959 - atomic_long_t count;
33960 - atomic_long_t total;
33961 + atomic_long_unchecked_t count;
33962 + atomic_long_unchecked_t total;
33963 unsigned long max;
33964 };
33965
33966 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_st
33967
33968 #define STAT(id) do { \
33969 if (gru_options & OPT_STATS) \
33970 - atomic_long_inc(&gru_stats.id); \
33971 + atomic_long_inc_unchecked(&gru_stats.id); \
33972 } while (0)
33973
33974 #ifdef CONFIG_SGI_GRU_DEBUG
33975 diff -urNp linux-2.6.39.2/drivers/misc/sgi-xp/xpc_sn2.c linux-2.6.39.2/drivers/misc/sgi-xp/xpc_sn2.c
33976 --- linux-2.6.39.2/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-19 00:06:34.000000000 -0400
33977 +++ linux-2.6.39.2/drivers/misc/sgi-xp/xpc_sn2.c 2011-05-22 19:36:31.000000000 -0400
33978 @@ -2351,7 +2351,7 @@ xpc_received_payload_sn2(struct xpc_chan
33979 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
33980 }
33981
33982 -static struct xpc_arch_operations xpc_arch_ops_sn2 = {
33983 +static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
33984 .setup_partitions = xpc_setup_partitions_sn2,
33985 .teardown_partitions = xpc_teardown_partitions_sn2,
33986 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
33987 diff -urNp linux-2.6.39.2/drivers/misc/sgi-xp/xpc_uv.c linux-2.6.39.2/drivers/misc/sgi-xp/xpc_uv.c
33988 --- linux-2.6.39.2/drivers/misc/sgi-xp/xpc_uv.c 2011-05-19 00:06:34.000000000 -0400
33989 +++ linux-2.6.39.2/drivers/misc/sgi-xp/xpc_uv.c 2011-05-22 19:36:31.000000000 -0400
33990 @@ -1674,7 +1674,7 @@ xpc_received_payload_uv(struct xpc_chann
33991 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
33992 }
33993
33994 -static struct xpc_arch_operations xpc_arch_ops_uv = {
33995 +static const struct xpc_arch_operations xpc_arch_ops_uv = {
33996 .setup_partitions = xpc_setup_partitions_uv,
33997 .teardown_partitions = xpc_teardown_partitions_uv,
33998 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
33999 diff -urNp linux-2.6.39.2/drivers/misc/spear13xx_pcie_gadget.c linux-2.6.39.2/drivers/misc/spear13xx_pcie_gadget.c
34000 --- linux-2.6.39.2/drivers/misc/spear13xx_pcie_gadget.c 2011-05-19 00:06:34.000000000 -0400
34001 +++ linux-2.6.39.2/drivers/misc/spear13xx_pcie_gadget.c 2011-05-22 19:36:31.000000000 -0400
34002 @@ -644,7 +644,7 @@ static ssize_t pcie_gadget_target_attr_s
34003 return ret;
34004 }
34005
34006 -static struct configfs_item_operations pcie_gadget_target_item_ops = {
34007 +static const struct configfs_item_operations pcie_gadget_target_item_ops = {
34008 .show_attribute = pcie_gadget_target_attr_show,
34009 .store_attribute = pcie_gadget_target_attr_store,
34010 };
34011 diff -urNp linux-2.6.39.2/drivers/mmc/host/davinci_mmc.c linux-2.6.39.2/drivers/mmc/host/davinci_mmc.c
34012 --- linux-2.6.39.2/drivers/mmc/host/davinci_mmc.c 2011-05-19 00:06:34.000000000 -0400
34013 +++ linux-2.6.39.2/drivers/mmc/host/davinci_mmc.c 2011-05-22 19:36:31.000000000 -0400
34014 @@ -1133,7 +1133,7 @@ static void mmc_davinci_enable_sdio_irq(
34015 }
34016 }
34017
34018 -static struct mmc_host_ops mmc_davinci_ops = {
34019 +static const struct mmc_host_ops mmc_davinci_ops = {
34020 .request = mmc_davinci_request,
34021 .set_ios = mmc_davinci_set_ios,
34022 .get_cd = mmc_davinci_get_cd,
34023 diff -urNp linux-2.6.39.2/drivers/mmc/host/dw_mmc.c linux-2.6.39.2/drivers/mmc/host/dw_mmc.c
34024 --- linux-2.6.39.2/drivers/mmc/host/dw_mmc.c 2011-05-19 00:06:34.000000000 -0400
34025 +++ linux-2.6.39.2/drivers/mmc/host/dw_mmc.c 2011-05-22 19:36:31.000000000 -0400
34026 @@ -417,7 +417,7 @@ static int dw_mci_idmac_init(struct dw_m
34027 return 0;
34028 }
34029
34030 -static struct dw_mci_dma_ops dw_mci_idmac_ops = {
34031 +static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
34032 .init = dw_mci_idmac_init,
34033 .start = dw_mci_idmac_start_dma,
34034 .stop = dw_mci_idmac_stop_dma,
34035 diff -urNp linux-2.6.39.2/drivers/mmc/host/s3cmci.c linux-2.6.39.2/drivers/mmc/host/s3cmci.c
34036 --- linux-2.6.39.2/drivers/mmc/host/s3cmci.c 2011-05-19 00:06:34.000000000 -0400
34037 +++ linux-2.6.39.2/drivers/mmc/host/s3cmci.c 2011-05-22 19:36:31.000000000 -0400
34038 @@ -1349,7 +1349,7 @@ static void s3cmci_enable_sdio_irq(struc
34039 s3cmci_check_sdio_irq(host);
34040 }
34041
34042 -static struct mmc_host_ops s3cmci_ops = {
34043 +static const struct mmc_host_ops s3cmci_ops = {
34044 .request = s3cmci_request,
34045 .set_ios = s3cmci_set_ios,
34046 .get_ro = s3cmci_get_ro,
34047 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-cns3xxx.c linux-2.6.39.2/drivers/mmc/host/sdhci-cns3xxx.c
34048 --- linux-2.6.39.2/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-19 00:06:34.000000000 -0400
34049 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-cns3xxx.c 2011-05-22 19:36:31.000000000 -0400
34050 @@ -81,7 +81,7 @@ out:
34051 host->clock = clock;
34052 }
34053
34054 -static struct sdhci_ops sdhci_cns3xxx_ops = {
34055 +static const struct sdhci_ops sdhci_cns3xxx_ops = {
34056 .get_max_clock = sdhci_cns3xxx_get_max_clk,
34057 .set_clock = sdhci_cns3xxx_set_clock,
34058 };
34059 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-dove.c linux-2.6.39.2/drivers/mmc/host/sdhci-dove.c
34060 --- linux-2.6.39.2/drivers/mmc/host/sdhci-dove.c 2011-05-19 00:06:34.000000000 -0400
34061 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-dove.c 2011-05-22 19:36:31.000000000 -0400
34062 @@ -56,7 +56,7 @@ static u32 sdhci_dove_readl(struct sdhci
34063 return ret;
34064 }
34065
34066 -static struct sdhci_ops sdhci_dove_ops = {
34067 +static const struct sdhci_ops sdhci_dove_ops = {
34068 .read_w = sdhci_dove_readw,
34069 .read_l = sdhci_dove_readl,
34070 };
34071 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-esdhc-imx.c linux-2.6.39.2/drivers/mmc/host/sdhci-esdhc-imx.c
34072 --- linux-2.6.39.2/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-19 00:06:34.000000000 -0400
34073 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-esdhc-imx.c 2011-05-22 19:36:31.000000000 -0400
34074 @@ -201,7 +201,7 @@ static unsigned int esdhc_pltfm_get_ro(s
34075 return -ENOSYS;
34076 }
34077
34078 -static struct sdhci_ops sdhci_esdhc_ops = {
34079 +static const struct sdhci_ops sdhci_esdhc_ops = {
34080 .read_l = esdhc_readl_le,
34081 .read_w = esdhc_readw_le,
34082 .write_l = esdhc_writel_le,
34083 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-of.h linux-2.6.39.2/drivers/mmc/host/sdhci-of.h
34084 --- linux-2.6.39.2/drivers/mmc/host/sdhci-of.h 2011-05-19 00:06:34.000000000 -0400
34085 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-of.h 2011-05-22 19:36:31.000000000 -0400
34086 @@ -21,7 +21,7 @@
34087
34088 struct sdhci_of_data {
34089 unsigned int quirks;
34090 - struct sdhci_ops ops;
34091 + const struct sdhci_ops ops;
34092 };
34093
34094 struct sdhci_of_host {
34095 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-pci.c linux-2.6.39.2/drivers/mmc/host/sdhci-pci.c
34096 --- linux-2.6.39.2/drivers/mmc/host/sdhci-pci.c 2011-05-19 00:06:34.000000000 -0400
34097 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-pci.c 2011-05-22 19:36:31.000000000 -0400
34098 @@ -786,7 +786,7 @@ static int sdhci_pci_enable_dma(struct s
34099 return 0;
34100 }
34101
34102 -static struct sdhci_ops sdhci_pci_ops = {
34103 +static const struct sdhci_ops sdhci_pci_ops = {
34104 .enable_dma = sdhci_pci_enable_dma,
34105 };
34106
34107 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-pltfm.c linux-2.6.39.2/drivers/mmc/host/sdhci-pltfm.c
34108 --- linux-2.6.39.2/drivers/mmc/host/sdhci-pltfm.c 2011-05-19 00:06:34.000000000 -0400
34109 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-pltfm.c 2011-05-22 19:36:31.000000000 -0400
34110 @@ -41,7 +41,7 @@
34111 * *
34112 \*****************************************************************************/
34113
34114 -static struct sdhci_ops sdhci_pltfm_ops = {
34115 +static const struct sdhci_ops sdhci_pltfm_ops = {
34116 };
34117
34118 /*****************************************************************************\
34119 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-pxa.c linux-2.6.39.2/drivers/mmc/host/sdhci-pxa.c
34120 --- linux-2.6.39.2/drivers/mmc/host/sdhci-pxa.c 2011-05-19 00:06:34.000000000 -0400
34121 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-pxa.c 2011-05-22 19:36:31.000000000 -0400
34122 @@ -69,7 +69,7 @@ static void set_clock(struct sdhci_host
34123 }
34124 }
34125
34126 -static struct sdhci_ops sdhci_pxa_ops = {
34127 +static const struct sdhci_ops sdhci_pxa_ops = {
34128 .set_clock = set_clock,
34129 };
34130
34131 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-s3c.c linux-2.6.39.2/drivers/mmc/host/sdhci-s3c.c
34132 --- linux-2.6.39.2/drivers/mmc/host/sdhci-s3c.c 2011-05-19 00:06:34.000000000 -0400
34133 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-s3c.c 2011-05-22 19:36:31.000000000 -0400
34134 @@ -309,7 +309,7 @@ static int sdhci_s3c_platform_8bit_width
34135 return 0;
34136 }
34137
34138 -static struct sdhci_ops sdhci_s3c_ops = {
34139 +static const struct sdhci_ops sdhci_s3c_ops = {
34140 .get_max_clock = sdhci_s3c_get_max_clk,
34141 .set_clock = sdhci_s3c_set_clock,
34142 .get_min_clock = sdhci_s3c_get_min_clock,
34143 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-spear.c linux-2.6.39.2/drivers/mmc/host/sdhci-spear.c
34144 --- linux-2.6.39.2/drivers/mmc/host/sdhci-spear.c 2011-05-19 00:06:34.000000000 -0400
34145 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-spear.c 2011-05-22 19:36:31.000000000 -0400
34146 @@ -32,7 +32,7 @@ struct spear_sdhci {
34147 };
34148
34149 /* sdhci ops */
34150 -static struct sdhci_ops sdhci_pltfm_ops = {
34151 +static const struct sdhci_ops sdhci_pltfm_ops = {
34152 /* Nothing to do for now. */
34153 };
34154
34155 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdhci-tegra.c linux-2.6.39.2/drivers/mmc/host/sdhci-tegra.c
34156 --- linux-2.6.39.2/drivers/mmc/host/sdhci-tegra.c 2011-05-19 00:06:34.000000000 -0400
34157 +++ linux-2.6.39.2/drivers/mmc/host/sdhci-tegra.c 2011-05-22 19:36:31.000000000 -0400
34158 @@ -242,7 +242,7 @@ static void tegra_sdhci_pltfm_exit(struc
34159 clk_put(pltfm_host->clk);
34160 }
34161
34162 -static struct sdhci_ops tegra_sdhci_ops = {
34163 +static const struct sdhci_ops tegra_sdhci_ops = {
34164 .get_ro = tegra_sdhci_get_ro,
34165 .read_l = tegra_sdhci_readl,
34166 .read_w = tegra_sdhci_readw,
34167 diff -urNp linux-2.6.39.2/drivers/mmc/host/sdricoh_cs.c linux-2.6.39.2/drivers/mmc/host/sdricoh_cs.c
34168 --- linux-2.6.39.2/drivers/mmc/host/sdricoh_cs.c 2011-05-19 00:06:34.000000000 -0400
34169 +++ linux-2.6.39.2/drivers/mmc/host/sdricoh_cs.c 2011-05-22 19:36:31.000000000 -0400
34170 @@ -387,7 +387,7 @@ static int sdricoh_get_ro(struct mmc_hos
34171 return (status & STATUS_CARD_LOCKED);
34172 }
34173
34174 -static struct mmc_host_ops sdricoh_ops = {
34175 +static const struct mmc_host_ops sdricoh_ops = {
34176 .request = sdricoh_request,
34177 .set_ios = sdricoh_set_ios,
34178 .get_ro = sdricoh_get_ro,
34179 diff -urNp linux-2.6.39.2/drivers/mmc/host/sh_mmcif.c linux-2.6.39.2/drivers/mmc/host/sh_mmcif.c
34180 --- linux-2.6.39.2/drivers/mmc/host/sh_mmcif.c 2011-05-19 00:06:34.000000000 -0400
34181 +++ linux-2.6.39.2/drivers/mmc/host/sh_mmcif.c 2011-05-22 19:36:31.000000000 -0400
34182 @@ -872,7 +872,7 @@ static int sh_mmcif_get_cd(struct mmc_ho
34183 return p->get_cd(host->pd);
34184 }
34185
34186 -static struct mmc_host_ops sh_mmcif_ops = {
34187 +static const struct mmc_host_ops sh_mmcif_ops = {
34188 .request = sh_mmcif_request,
34189 .set_ios = sh_mmcif_set_ios,
34190 .get_cd = sh_mmcif_get_cd,
34191 diff -urNp linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0001.c linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0001.c
34192 --- linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-19 00:06:34.000000000 -0400
34193 +++ linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0001.c 2011-05-22 19:36:31.000000000 -0400
34194 @@ -757,6 +757,8 @@ static int chip_ready (struct map_info *
34195 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
34196 unsigned long timeo = jiffies + HZ;
34197
34198 + pax_track_stack();
34199 +
34200 /* Prevent setting state FL_SYNCING for chip in suspended state. */
34201 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
34202 goto sleep;
34203 @@ -1657,6 +1659,8 @@ static int __xipram do_write_buffer(stru
34204 unsigned long initial_adr;
34205 int initial_len = len;
34206
34207 + pax_track_stack();
34208 +
34209 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
34210 adr += chip->start;
34211 initial_adr = adr;
34212 @@ -1875,6 +1879,8 @@ static int __xipram do_erase_oneblock(st
34213 int retries = 3;
34214 int ret;
34215
34216 + pax_track_stack();
34217 +
34218 adr += chip->start;
34219
34220 retry:
34221 diff -urNp linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0020.c linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0020.c
34222 --- linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-19 00:06:34.000000000 -0400
34223 +++ linux-2.6.39.2/drivers/mtd/chips/cfi_cmdset_0020.c 2011-05-22 19:36:31.000000000 -0400
34224 @@ -255,6 +255,8 @@ static inline int do_read_onechip(struct
34225 unsigned long cmd_addr;
34226 struct cfi_private *cfi = map->fldrv_priv;
34227
34228 + pax_track_stack();
34229 +
34230 adr += chip->start;
34231
34232 /* Ensure cmd read/writes are aligned. */
34233 @@ -428,6 +430,8 @@ static inline int do_write_buffer(struct
34234 DECLARE_WAITQUEUE(wait, current);
34235 int wbufsize, z;
34236
34237 + pax_track_stack();
34238 +
34239 /* M58LW064A requires bus alignment for buffer wriets -- saw */
34240 if (adr & (map_bankwidth(map)-1))
34241 return -EINVAL;
34242 @@ -742,6 +746,8 @@ static inline int do_erase_oneblock(stru
34243 DECLARE_WAITQUEUE(wait, current);
34244 int ret = 0;
34245
34246 + pax_track_stack();
34247 +
34248 adr += chip->start;
34249
34250 /* Let's determine this according to the interleave only once */
34251 @@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struc
34252 unsigned long timeo = jiffies + HZ;
34253 DECLARE_WAITQUEUE(wait, current);
34254
34255 + pax_track_stack();
34256 +
34257 adr += chip->start;
34258
34259 /* Let's determine this according to the interleave only once */
34260 @@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(str
34261 unsigned long timeo = jiffies + HZ;
34262 DECLARE_WAITQUEUE(wait, current);
34263
34264 + pax_track_stack();
34265 +
34266 adr += chip->start;
34267
34268 /* Let's determine this according to the interleave only once */
34269 diff -urNp linux-2.6.39.2/drivers/mtd/devices/doc2000.c linux-2.6.39.2/drivers/mtd/devices/doc2000.c
34270 --- linux-2.6.39.2/drivers/mtd/devices/doc2000.c 2011-05-19 00:06:34.000000000 -0400
34271 +++ linux-2.6.39.2/drivers/mtd/devices/doc2000.c 2011-05-22 19:36:31.000000000 -0400
34272 @@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mt
34273
34274 /* The ECC will not be calculated correctly if less than 512 is written */
34275 /* DBB-
34276 - if (len != 0x200 && eccbuf)
34277 + if (len != 0x200)
34278 printk(KERN_WARNING
34279 "ECC needs a full sector write (adr: %lx size %lx)\n",
34280 (long) to, (long) len);
34281 diff -urNp linux-2.6.39.2/drivers/mtd/devices/doc2001.c linux-2.6.39.2/drivers/mtd/devices/doc2001.c
34282 --- linux-2.6.39.2/drivers/mtd/devices/doc2001.c 2011-05-19 00:06:34.000000000 -0400
34283 +++ linux-2.6.39.2/drivers/mtd/devices/doc2001.c 2011-05-22 19:36:31.000000000 -0400
34284 @@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mt
34285 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34286
34287 /* Don't allow read past end of device */
34288 - if (from >= this->totlen)
34289 + if (from >= this->totlen || !len)
34290 return -EINVAL;
34291
34292 /* Don't allow a single read to cross a 512-byte block boundary */
34293 diff -urNp linux-2.6.39.2/drivers/mtd/ftl.c linux-2.6.39.2/drivers/mtd/ftl.c
34294 --- linux-2.6.39.2/drivers/mtd/ftl.c 2011-05-19 00:06:34.000000000 -0400
34295 +++ linux-2.6.39.2/drivers/mtd/ftl.c 2011-05-22 19:36:31.000000000 -0400
34296 @@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *
34297 loff_t offset;
34298 uint16_t srcunitswap = cpu_to_le16(srcunit);
34299
34300 + pax_track_stack();
34301 +
34302 eun = &part->EUNInfo[srcunit];
34303 xfer = &part->XferInfo[xferunit];
34304 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
34305 diff -urNp linux-2.6.39.2/drivers/mtd/inftlcore.c linux-2.6.39.2/drivers/mtd/inftlcore.c
34306 --- linux-2.6.39.2/drivers/mtd/inftlcore.c 2011-05-19 00:06:34.000000000 -0400
34307 +++ linux-2.6.39.2/drivers/mtd/inftlcore.c 2011-05-22 19:36:31.000000000 -0400
34308 @@ -259,6 +259,8 @@ static u16 INFTL_foldchain(struct INFTLr
34309 struct inftl_oob oob;
34310 size_t retlen;
34311
34312 + pax_track_stack();
34313 +
34314 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
34315 "pending=%d)\n", inftl, thisVUC, pendingblock);
34316
34317 diff -urNp linux-2.6.39.2/drivers/mtd/inftlmount.c linux-2.6.39.2/drivers/mtd/inftlmount.c
34318 --- linux-2.6.39.2/drivers/mtd/inftlmount.c 2011-05-19 00:06:34.000000000 -0400
34319 +++ linux-2.6.39.2/drivers/mtd/inftlmount.c 2011-05-22 19:36:31.000000000 -0400
34320 @@ -53,6 +53,8 @@ static int find_boot_record(struct INFTL
34321 struct INFTLPartition *ip;
34322 size_t retlen;
34323
34324 + pax_track_stack();
34325 +
34326 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
34327
34328 /*
34329 diff -urNp linux-2.6.39.2/drivers/mtd/lpddr/qinfo_probe.c linux-2.6.39.2/drivers/mtd/lpddr/qinfo_probe.c
34330 --- linux-2.6.39.2/drivers/mtd/lpddr/qinfo_probe.c 2011-05-19 00:06:34.000000000 -0400
34331 +++ linux-2.6.39.2/drivers/mtd/lpddr/qinfo_probe.c 2011-05-22 19:36:31.000000000 -0400
34332 @@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map
34333 {
34334 map_word pfow_val[4];
34335
34336 + pax_track_stack();
34337 +
34338 /* Check identification string */
34339 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
34340 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
34341 diff -urNp linux-2.6.39.2/drivers/mtd/mtdchar.c linux-2.6.39.2/drivers/mtd/mtdchar.c
34342 --- linux-2.6.39.2/drivers/mtd/mtdchar.c 2011-05-19 00:06:34.000000000 -0400
34343 +++ linux-2.6.39.2/drivers/mtd/mtdchar.c 2011-05-22 19:36:31.000000000 -0400
34344 @@ -560,6 +560,8 @@ static int mtd_ioctl(struct file *file,
34345 u_long size;
34346 struct mtd_info_user info;
34347
34348 + pax_track_stack();
34349 +
34350 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
34351
34352 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
34353 diff -urNp linux-2.6.39.2/drivers/mtd/nand/denali.c linux-2.6.39.2/drivers/mtd/nand/denali.c
34354 --- linux-2.6.39.2/drivers/mtd/nand/denali.c 2011-05-19 00:06:34.000000000 -0400
34355 +++ linux-2.6.39.2/drivers/mtd/nand/denali.c 2011-05-22 19:36:31.000000000 -0400
34356 @@ -25,6 +25,7 @@
34357 #include <linux/pci.h>
34358 #include <linux/mtd/mtd.h>
34359 #include <linux/module.h>
34360 +#include <linux/slab.h>
34361
34362 #include "denali.h"
34363
34364 diff -urNp linux-2.6.39.2/drivers/mtd/nftlcore.c linux-2.6.39.2/drivers/mtd/nftlcore.c
34365 --- linux-2.6.39.2/drivers/mtd/nftlcore.c 2011-05-19 00:06:34.000000000 -0400
34366 +++ linux-2.6.39.2/drivers/mtd/nftlcore.c 2011-05-22 19:36:31.000000000 -0400
34367 @@ -264,6 +264,8 @@ static u16 NFTL_foldchain (struct NFTLre
34368 int inplace = 1;
34369 size_t retlen;
34370
34371 + pax_track_stack();
34372 +
34373 memset(BlockMap, 0xff, sizeof(BlockMap));
34374 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
34375
34376 diff -urNp linux-2.6.39.2/drivers/mtd/nftlmount.c linux-2.6.39.2/drivers/mtd/nftlmount.c
34377 --- linux-2.6.39.2/drivers/mtd/nftlmount.c 2011-05-19 00:06:34.000000000 -0400
34378 +++ linux-2.6.39.2/drivers/mtd/nftlmount.c 2011-05-22 19:36:31.000000000 -0400
34379 @@ -24,6 +24,7 @@
34380 #include <asm/errno.h>
34381 #include <linux/delay.h>
34382 #include <linux/slab.h>
34383 +#include <linux/sched.h>
34384 #include <linux/mtd/mtd.h>
34385 #include <linux/mtd/nand.h>
34386 #include <linux/mtd/nftl.h>
34387 @@ -45,6 +46,8 @@ static int find_boot_record(struct NFTLr
34388 struct mtd_info *mtd = nftl->mbd.mtd;
34389 unsigned int i;
34390
34391 + pax_track_stack();
34392 +
34393 /* Assume logical EraseSize == physical erasesize for starting the scan.
34394 We'll sort it out later if we find a MediaHeader which says otherwise */
34395 /* Actually, we won't. The new DiskOnChip driver has already scanned
34396 diff -urNp linux-2.6.39.2/drivers/mtd/ubi/build.c linux-2.6.39.2/drivers/mtd/ubi/build.c
34397 --- linux-2.6.39.2/drivers/mtd/ubi/build.c 2011-05-19 00:06:34.000000000 -0400
34398 +++ linux-2.6.39.2/drivers/mtd/ubi/build.c 2011-05-22 19:36:31.000000000 -0400
34399 @@ -1287,7 +1287,7 @@ module_exit(ubi_exit);
34400 static int __init bytes_str_to_int(const char *str)
34401 {
34402 char *endp;
34403 - unsigned long result;
34404 + unsigned long result, scale = 1;
34405
34406 result = simple_strtoul(str, &endp, 0);
34407 if (str == endp || result >= INT_MAX) {
34408 @@ -1298,11 +1298,11 @@ static int __init bytes_str_to_int(const
34409
34410 switch (*endp) {
34411 case 'G':
34412 - result *= 1024;
34413 + scale *= 1024;
34414 case 'M':
34415 - result *= 1024;
34416 + scale *= 1024;
34417 case 'K':
34418 - result *= 1024;
34419 + scale *= 1024;
34420 if (endp[1] == 'i' && endp[2] == 'B')
34421 endp += 2;
34422 case '\0':
34423 @@ -1313,7 +1313,13 @@ static int __init bytes_str_to_int(const
34424 return -EINVAL;
34425 }
34426
34427 - return result;
34428 + if ((intoverflow_t)result*scale >= INT_MAX) {
34429 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
34430 + str);
34431 + return -EINVAL;
34432 + }
34433 +
34434 + return result*scale;
34435 }
34436
34437 /**
34438 diff -urNp linux-2.6.39.2/drivers/net/bcm63xx_enet.c linux-2.6.39.2/drivers/net/bcm63xx_enet.c
34439 --- linux-2.6.39.2/drivers/net/bcm63xx_enet.c 2011-05-19 00:06:34.000000000 -0400
34440 +++ linux-2.6.39.2/drivers/net/bcm63xx_enet.c 2011-05-22 19:36:31.000000000 -0400
34441 @@ -1469,7 +1469,7 @@ static int bcm_enet_set_pauseparam(struc
34442 return 0;
34443 }
34444
34445 -static struct ethtool_ops bcm_enet_ethtool_ops = {
34446 +static const struct ethtool_ops bcm_enet_ethtool_ops = {
34447 .get_strings = bcm_enet_get_strings,
34448 .get_sset_count = bcm_enet_get_sset_count,
34449 .get_ethtool_stats = bcm_enet_get_ethtool_stats,
34450 diff -urNp linux-2.6.39.2/drivers/net/bna/bnad_ethtool.c linux-2.6.39.2/drivers/net/bna/bnad_ethtool.c
34451 --- linux-2.6.39.2/drivers/net/bna/bnad_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34452 +++ linux-2.6.39.2/drivers/net/bna/bnad_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34453 @@ -1242,7 +1242,7 @@ bnad_get_sset_count(struct net_device *n
34454 }
34455 }
34456
34457 -static struct ethtool_ops bnad_ethtool_ops = {
34458 +static const struct ethtool_ops bnad_ethtool_ops = {
34459 .get_settings = bnad_get_settings,
34460 .set_settings = bnad_set_settings,
34461 .get_drvinfo = bnad_get_drvinfo,
34462 diff -urNp linux-2.6.39.2/drivers/net/bnx2.c linux-2.6.39.2/drivers/net/bnx2.c
34463 --- linux-2.6.39.2/drivers/net/bnx2.c 2011-05-19 00:06:34.000000000 -0400
34464 +++ linux-2.6.39.2/drivers/net/bnx2.c 2011-05-22 19:36:31.000000000 -0400
34465 @@ -5828,6 +5828,8 @@ bnx2_test_nvram(struct bnx2 *bp)
34466 int rc = 0;
34467 u32 magic, csum;
34468
34469 + pax_track_stack();
34470 +
34471 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
34472 goto test_nvram_done;
34473
34474 diff -urNp linux-2.6.39.2/drivers/net/bnx2x/bnx2x_ethtool.c linux-2.6.39.2/drivers/net/bnx2x/bnx2x_ethtool.c
34475 --- linux-2.6.39.2/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-19 00:06:34.000000000 -0400
34476 +++ linux-2.6.39.2/drivers/net/bnx2x/bnx2x_ethtool.c 2011-05-22 19:36:31.000000000 -0400
34477 @@ -1788,6 +1788,8 @@ static int bnx2x_test_nvram(struct bnx2x
34478 int i, rc;
34479 u32 magic, crc;
34480
34481 + pax_track_stack();
34482 +
34483 if (BP_NOMCP(bp))
34484 return 0;
34485
34486 diff -urNp linux-2.6.39.2/drivers/net/chelsio/pm3393.c linux-2.6.39.2/drivers/net/chelsio/pm3393.c
34487 --- linux-2.6.39.2/drivers/net/chelsio/pm3393.c 2011-05-19 00:06:34.000000000 -0400
34488 +++ linux-2.6.39.2/drivers/net/chelsio/pm3393.c 2011-05-22 19:36:31.000000000 -0400
34489 @@ -571,7 +571,7 @@ static void pm3393_destroy(struct cmac *
34490 kfree(cmac);
34491 }
34492
34493 -static struct cmac_ops pm3393_ops = {
34494 +static const struct cmac_ops pm3393_ops = {
34495 .destroy = pm3393_destroy,
34496 .reset = pm3393_reset,
34497 .interrupt_enable = pm3393_interrupt_enable,
34498 diff -urNp linux-2.6.39.2/drivers/net/chelsio/vsc7326.c linux-2.6.39.2/drivers/net/chelsio/vsc7326.c
34499 --- linux-2.6.39.2/drivers/net/chelsio/vsc7326.c 2011-05-19 00:06:34.000000000 -0400
34500 +++ linux-2.6.39.2/drivers/net/chelsio/vsc7326.c 2011-05-22 19:36:31.000000000 -0400
34501 @@ -666,7 +666,7 @@ static void mac_destroy(struct cmac *mac
34502 kfree(mac);
34503 }
34504
34505 -static struct cmac_ops vsc7326_ops = {
34506 +static const struct cmac_ops vsc7326_ops = {
34507 .destroy = mac_destroy,
34508 .reset = mac_reset,
34509 .interrupt_handler = mac_intr_handler,
34510 diff -urNp linux-2.6.39.2/drivers/net/cxgb4/cxgb4_main.c linux-2.6.39.2/drivers/net/cxgb4/cxgb4_main.c
34511 --- linux-2.6.39.2/drivers/net/cxgb4/cxgb4_main.c 2011-05-19 00:06:34.000000000 -0400
34512 +++ linux-2.6.39.2/drivers/net/cxgb4/cxgb4_main.c 2011-05-22 19:36:31.000000000 -0400
34513 @@ -3428,6 +3428,8 @@ static int __devinit enable_msix(struct
34514 unsigned int nchan = adap->params.nports;
34515 struct msix_entry entries[MAX_INGQ + 1];
34516
34517 + pax_track_stack();
34518 +
34519 for (i = 0; i < ARRAY_SIZE(entries); ++i)
34520 entries[i].entry = i;
34521
34522 diff -urNp linux-2.6.39.2/drivers/net/cxgb4/t4_hw.c linux-2.6.39.2/drivers/net/cxgb4/t4_hw.c
34523 --- linux-2.6.39.2/drivers/net/cxgb4/t4_hw.c 2011-05-19 00:06:34.000000000 -0400
34524 +++ linux-2.6.39.2/drivers/net/cxgb4/t4_hw.c 2011-05-22 19:36:31.000000000 -0400
34525 @@ -362,6 +362,8 @@ static int get_vpd_params(struct adapter
34526 u8 vpd[VPD_LEN], csum;
34527 unsigned int vpdr_len, kw_offset, id_len;
34528
34529 + pax_track_stack();
34530 +
34531 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(vpd), vpd);
34532 if (ret < 0)
34533 return ret;
34534 diff -urNp linux-2.6.39.2/drivers/net/cxgb4vf/cxgb4vf_main.c linux-2.6.39.2/drivers/net/cxgb4vf/cxgb4vf_main.c
34535 --- linux-2.6.39.2/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-19 00:06:34.000000000 -0400
34536 +++ linux-2.6.39.2/drivers/net/cxgb4vf/cxgb4vf_main.c 2011-05-22 19:36:31.000000000 -0400
34537 @@ -1572,7 +1572,7 @@ static int cxgb4vf_set_tso(struct net_de
34538 return 0;
34539 }
34540
34541 -static struct ethtool_ops cxgb4vf_ethtool_ops = {
34542 +static const struct ethtool_ops cxgb4vf_ethtool_ops = {
34543 .get_settings = cxgb4vf_get_settings,
34544 .get_drvinfo = cxgb4vf_get_drvinfo,
34545 .get_msglevel = cxgb4vf_get_msglevel,
34546 diff -urNp linux-2.6.39.2/drivers/net/e1000e/82571.c linux-2.6.39.2/drivers/net/e1000e/82571.c
34547 --- linux-2.6.39.2/drivers/net/e1000e/82571.c 2011-05-19 00:06:34.000000000 -0400
34548 +++ linux-2.6.39.2/drivers/net/e1000e/82571.c 2011-05-22 19:36:31.000000000 -0400
34549 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(s
34550 {
34551 struct e1000_hw *hw = &adapter->hw;
34552 struct e1000_mac_info *mac = &hw->mac;
34553 - struct e1000_mac_operations *func = &mac->ops;
34554 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34555 u32 swsm = 0;
34556 u32 swsm2 = 0;
34557 bool force_clear_smbi = false;
34558 @@ -1930,7 +1930,7 @@ static void e1000_clear_hw_cntrs_82571(s
34559 er32(ICRXDMTC);
34560 }
34561
34562 -static struct e1000_mac_operations e82571_mac_ops = {
34563 +static const struct e1000_mac_operations e82571_mac_ops = {
34564 /* .check_mng_mode: mac type dependent */
34565 /* .check_for_link: media type dependent */
34566 .id_led_init = e1000e_id_led_init,
34567 @@ -1952,7 +1952,7 @@ static struct e1000_mac_operations e8257
34568 .read_mac_addr = e1000_read_mac_addr_82571,
34569 };
34570
34571 -static struct e1000_phy_operations e82_phy_ops_igp = {
34572 +static const struct e1000_phy_operations e82_phy_ops_igp = {
34573 .acquire = e1000_get_hw_semaphore_82571,
34574 .check_polarity = e1000_check_polarity_igp,
34575 .check_reset_block = e1000e_check_reset_block_generic,
34576 @@ -1970,7 +1970,7 @@ static struct e1000_phy_operations e82_p
34577 .cfg_on_link_up = NULL,
34578 };
34579
34580 -static struct e1000_phy_operations e82_phy_ops_m88 = {
34581 +static const struct e1000_phy_operations e82_phy_ops_m88 = {
34582 .acquire = e1000_get_hw_semaphore_82571,
34583 .check_polarity = e1000_check_polarity_m88,
34584 .check_reset_block = e1000e_check_reset_block_generic,
34585 @@ -1988,7 +1988,7 @@ static struct e1000_phy_operations e82_p
34586 .cfg_on_link_up = NULL,
34587 };
34588
34589 -static struct e1000_phy_operations e82_phy_ops_bm = {
34590 +static const struct e1000_phy_operations e82_phy_ops_bm = {
34591 .acquire = e1000_get_hw_semaphore_82571,
34592 .check_polarity = e1000_check_polarity_m88,
34593 .check_reset_block = e1000e_check_reset_block_generic,
34594 @@ -2006,7 +2006,7 @@ static struct e1000_phy_operations e82_p
34595 .cfg_on_link_up = NULL,
34596 };
34597
34598 -static struct e1000_nvm_operations e82571_nvm_ops = {
34599 +static const struct e1000_nvm_operations e82571_nvm_ops = {
34600 .acquire = e1000_acquire_nvm_82571,
34601 .read = e1000e_read_nvm_eerd,
34602 .release = e1000_release_nvm_82571,
34603 diff -urNp linux-2.6.39.2/drivers/net/e1000e/e1000.h linux-2.6.39.2/drivers/net/e1000e/e1000.h
34604 --- linux-2.6.39.2/drivers/net/e1000e/e1000.h 2011-05-19 00:06:34.000000000 -0400
34605 +++ linux-2.6.39.2/drivers/net/e1000e/e1000.h 2011-05-22 19:36:31.000000000 -0400
34606 @@ -409,9 +409,9 @@ struct e1000_info {
34607 u32 pba;
34608 u32 max_hw_frame_size;
34609 s32 (*get_variants)(struct e1000_adapter *);
34610 - struct e1000_mac_operations *mac_ops;
34611 - struct e1000_phy_operations *phy_ops;
34612 - struct e1000_nvm_operations *nvm_ops;
34613 + const struct e1000_mac_operations *mac_ops;
34614 + const struct e1000_phy_operations *phy_ops;
34615 + const struct e1000_nvm_operations *nvm_ops;
34616 };
34617
34618 /* hardware capability, feature, and workaround flags */
34619 diff -urNp linux-2.6.39.2/drivers/net/e1000e/es2lan.c linux-2.6.39.2/drivers/net/e1000e/es2lan.c
34620 --- linux-2.6.39.2/drivers/net/e1000e/es2lan.c 2011-05-19 00:06:34.000000000 -0400
34621 +++ linux-2.6.39.2/drivers/net/e1000e/es2lan.c 2011-05-22 19:36:31.000000000 -0400
34622 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es
34623 {
34624 struct e1000_hw *hw = &adapter->hw;
34625 struct e1000_mac_info *mac = &hw->mac;
34626 - struct e1000_mac_operations *func = &mac->ops;
34627 + struct e1000_mac_operations *func = &mac->ops; /* cannot be const */
34628
34629 /* Set media type */
34630 switch (adapter->pdev->device) {
34631 @@ -1431,7 +1431,7 @@ static void e1000_clear_hw_cntrs_80003es
34632 er32(ICRXDMTC);
34633 }
34634
34635 -static struct e1000_mac_operations es2_mac_ops = {
34636 +static const struct e1000_mac_operations es2_mac_ops = {
34637 .read_mac_addr = e1000_read_mac_addr_80003es2lan,
34638 .id_led_init = e1000e_id_led_init,
34639 .check_mng_mode = e1000e_check_mng_mode_generic,
34640 @@ -1453,7 +1453,7 @@ static struct e1000_mac_operations es2_m
34641 .setup_led = e1000e_setup_led_generic,
34642 };
34643
34644 -static struct e1000_phy_operations es2_phy_ops = {
34645 +static const struct e1000_phy_operations es2_phy_ops = {
34646 .acquire = e1000_acquire_phy_80003es2lan,
34647 .check_polarity = e1000_check_polarity_m88,
34648 .check_reset_block = e1000e_check_reset_block_generic,
34649 @@ -1471,7 +1471,7 @@ static struct e1000_phy_operations es2_p
34650 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
34651 };
34652
34653 -static struct e1000_nvm_operations es2_nvm_ops = {
34654 +static const struct e1000_nvm_operations es2_nvm_ops = {
34655 .acquire = e1000_acquire_nvm_80003es2lan,
34656 .read = e1000e_read_nvm_eerd,
34657 .release = e1000_release_nvm_80003es2lan,
34658 diff -urNp linux-2.6.39.2/drivers/net/e1000e/hw.h linux-2.6.39.2/drivers/net/e1000e/hw.h
34659 --- linux-2.6.39.2/drivers/net/e1000e/hw.h 2011-05-19 00:06:34.000000000 -0400
34660 +++ linux-2.6.39.2/drivers/net/e1000e/hw.h 2011-05-22 19:36:31.000000000 -0400
34661 @@ -811,6 +811,7 @@ struct e1000_nvm_operations {
34662 };
34663
34664 struct e1000_mac_info {
34665 + /* cannot be const see e1000_init_mac_params_ich8lan */
34666 struct e1000_mac_operations ops;
34667 u8 addr[ETH_ALEN];
34668 u8 perm_addr[ETH_ALEN];
34669 @@ -852,6 +853,7 @@ struct e1000_mac_info {
34670 };
34671
34672 struct e1000_phy_info {
34673 + /* Cannot be const see e1000_init_phy_params_82571() */
34674 struct e1000_phy_operations ops;
34675
34676 enum e1000_phy_type type;
34677 @@ -886,6 +888,7 @@ struct e1000_phy_info {
34678 };
34679
34680 struct e1000_nvm_info {
34681 + /* cannot be const */
34682 struct e1000_nvm_operations ops;
34683
34684 enum e1000_nvm_type type;
34685 diff -urNp linux-2.6.39.2/drivers/net/e1000e/ich8lan.c linux-2.6.39.2/drivers/net/e1000e/ich8lan.c
34686 --- linux-2.6.39.2/drivers/net/e1000e/ich8lan.c 2011-05-19 00:06:34.000000000 -0400
34687 +++ linux-2.6.39.2/drivers/net/e1000e/ich8lan.c 2011-05-22 19:36:31.000000000 -0400
34688 @@ -3866,7 +3866,7 @@ static void e1000_clear_hw_cntrs_ich8lan
34689 }
34690 }
34691
34692 -static struct e1000_mac_operations ich8_mac_ops = {
34693 +static const struct e1000_mac_operations ich8_mac_ops = {
34694 .id_led_init = e1000e_id_led_init,
34695 /* check_mng_mode dependent on mac type */
34696 .check_for_link = e1000_check_for_copper_link_ich8lan,
34697 @@ -3885,7 +3885,7 @@ static struct e1000_mac_operations ich8_
34698 /* id_led_init dependent on mac type */
34699 };
34700
34701 -static struct e1000_phy_operations ich8_phy_ops = {
34702 +static const struct e1000_phy_operations ich8_phy_ops = {
34703 .acquire = e1000_acquire_swflag_ich8lan,
34704 .check_reset_block = e1000_check_reset_block_ich8lan,
34705 .commit = NULL,
34706 @@ -3899,7 +3899,7 @@ static struct e1000_phy_operations ich8_
34707 .write_reg = e1000e_write_phy_reg_igp,
34708 };
34709
34710 -static struct e1000_nvm_operations ich8_nvm_ops = {
34711 +static const struct e1000_nvm_operations ich8_nvm_ops = {
34712 .acquire = e1000_acquire_nvm_ich8lan,
34713 .read = e1000_read_nvm_ich8lan,
34714 .release = e1000_release_nvm_ich8lan,
34715 diff -urNp linux-2.6.39.2/drivers/net/greth.c linux-2.6.39.2/drivers/net/greth.c
34716 --- linux-2.6.39.2/drivers/net/greth.c 2011-05-19 00:06:34.000000000 -0400
34717 +++ linux-2.6.39.2/drivers/net/greth.c 2011-05-22 19:36:31.000000000 -0400
34718 @@ -1192,7 +1192,7 @@ static const struct ethtool_ops greth_et
34719 .get_link = ethtool_op_get_link,
34720 };
34721
34722 -static struct net_device_ops greth_netdev_ops = {
34723 +static const struct net_device_ops greth_netdev_ops = {
34724 .ndo_open = greth_open,
34725 .ndo_stop = greth_close,
34726 .ndo_start_xmit = greth_start_xmit,
34727 diff -urNp linux-2.6.39.2/drivers/net/hamradio/6pack.c linux-2.6.39.2/drivers/net/hamradio/6pack.c
34728 --- linux-2.6.39.2/drivers/net/hamradio/6pack.c 2011-05-19 00:06:34.000000000 -0400
34729 +++ linux-2.6.39.2/drivers/net/hamradio/6pack.c 2011-05-22 19:36:31.000000000 -0400
34730 @@ -463,6 +463,8 @@ static void sixpack_receive_buf(struct t
34731 unsigned char buf[512];
34732 int count1;
34733
34734 + pax_track_stack();
34735 +
34736 if (!count)
34737 return;
34738
34739 diff -urNp linux-2.6.39.2/drivers/net/ibm_newemac/phy.c linux-2.6.39.2/drivers/net/ibm_newemac/phy.c
34740 --- linux-2.6.39.2/drivers/net/ibm_newemac/phy.c 2011-05-19 00:06:34.000000000 -0400
34741 +++ linux-2.6.39.2/drivers/net/ibm_newemac/phy.c 2011-05-22 19:36:31.000000000 -0400
34742 @@ -273,7 +273,7 @@ static int genmii_read_link(struct mii_p
34743 }
34744
34745 /* Generic implementation for most 10/100/1000 PHYs */
34746 -static struct mii_phy_ops generic_phy_ops = {
34747 +static const struct mii_phy_ops generic_phy_ops = {
34748 .setup_aneg = genmii_setup_aneg,
34749 .setup_forced = genmii_setup_forced,
34750 .poll_link = genmii_poll_link,
34751 @@ -337,7 +337,7 @@ static int cis8201_init(struct mii_phy *
34752 return 0;
34753 }
34754
34755 -static struct mii_phy_ops cis8201_phy_ops = {
34756 +static const struct mii_phy_ops cis8201_phy_ops = {
34757 .init = cis8201_init,
34758 .setup_aneg = genmii_setup_aneg,
34759 .setup_forced = genmii_setup_forced,
34760 @@ -417,7 +417,7 @@ static int et1011c_init(struct mii_phy *
34761 return 0;
34762 }
34763
34764 -static struct mii_phy_ops et1011c_phy_ops = {
34765 +static const struct mii_phy_ops et1011c_phy_ops = {
34766 .init = et1011c_init,
34767 .setup_aneg = genmii_setup_aneg,
34768 .setup_forced = genmii_setup_forced,
34769 @@ -436,7 +436,7 @@ static struct mii_phy_def et1011c_phy_de
34770
34771
34772
34773 -static struct mii_phy_ops m88e1111_phy_ops = {
34774 +static const struct mii_phy_ops m88e1111_phy_ops = {
34775 .init = m88e1111_init,
34776 .setup_aneg = genmii_setup_aneg,
34777 .setup_forced = genmii_setup_forced,
34778 @@ -452,7 +452,7 @@ static struct mii_phy_def m88e1111_phy_d
34779 .ops = &m88e1111_phy_ops,
34780 };
34781
34782 -static struct mii_phy_ops m88e1112_phy_ops = {
34783 +static const struct mii_phy_ops m88e1112_phy_ops = {
34784 .init = m88e1112_init,
34785 .setup_aneg = genmii_setup_aneg,
34786 .setup_forced = genmii_setup_forced,
34787 diff -urNp linux-2.6.39.2/drivers/net/ibmveth.c linux-2.6.39.2/drivers/net/ibmveth.c
34788 --- linux-2.6.39.2/drivers/net/ibmveth.c 2011-05-19 00:06:34.000000000 -0400
34789 +++ linux-2.6.39.2/drivers/net/ibmveth.c 2011-05-22 19:36:31.000000000 -0400
34790 @@ -1625,7 +1625,7 @@ static struct vio_device_id ibmveth_devi
34791 };
34792 MODULE_DEVICE_TABLE(vio, ibmveth_device_table);
34793
34794 -static struct dev_pm_ops ibmveth_pm_ops = {
34795 +static const struct dev_pm_ops ibmveth_pm_ops = {
34796 .resume = ibmveth_resume
34797 };
34798
34799 diff -urNp linux-2.6.39.2/drivers/net/igb/e1000_82575.c linux-2.6.39.2/drivers/net/igb/e1000_82575.c
34800 --- linux-2.6.39.2/drivers/net/igb/e1000_82575.c 2011-05-19 00:06:34.000000000 -0400
34801 +++ linux-2.6.39.2/drivers/net/igb/e1000_82575.c 2011-05-22 19:36:31.000000000 -0400
34802 @@ -2029,7 +2029,7 @@ out:
34803 return ret_val;
34804 }
34805
34806 -static struct e1000_mac_operations e1000_mac_ops_82575 = {
34807 +static const struct e1000_mac_operations e1000_mac_ops_82575 = {
34808 .init_hw = igb_init_hw_82575,
34809 .check_for_link = igb_check_for_link_82575,
34810 .rar_set = igb_rar_set,
34811 @@ -2037,13 +2037,13 @@ static struct e1000_mac_operations e1000
34812 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
34813 };
34814
34815 -static struct e1000_phy_operations e1000_phy_ops_82575 = {
34816 +static const struct e1000_phy_operations e1000_phy_ops_82575 = {
34817 .acquire = igb_acquire_phy_82575,
34818 .get_cfg_done = igb_get_cfg_done_82575,
34819 .release = igb_release_phy_82575,
34820 };
34821
34822 -static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34823 +static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
34824 .acquire = igb_acquire_nvm_82575,
34825 .read = igb_read_nvm_eerd,
34826 .release = igb_release_nvm_82575,
34827 diff -urNp linux-2.6.39.2/drivers/net/igb/e1000_hw.h linux-2.6.39.2/drivers/net/igb/e1000_hw.h
34828 --- linux-2.6.39.2/drivers/net/igb/e1000_hw.h 2011-05-19 00:06:34.000000000 -0400
34829 +++ linux-2.6.39.2/drivers/net/igb/e1000_hw.h 2011-05-22 19:36:31.000000000 -0400
34830 @@ -342,14 +342,15 @@ struct e1000_nvm_operations {
34831
34832 struct e1000_info {
34833 s32 (*get_invariants)(struct e1000_hw *);
34834 - struct e1000_mac_operations *mac_ops;
34835 - struct e1000_phy_operations *phy_ops;
34836 - struct e1000_nvm_operations *nvm_ops;
34837 + const struct e1000_mac_operations *mac_ops;
34838 + const struct e1000_phy_operations *phy_ops;
34839 + const struct e1000_nvm_operations *nvm_ops;
34840 };
34841
34842 extern const struct e1000_info e1000_82575_info;
34843
34844 struct e1000_mac_info {
34845 + /* cannot be const see igb_get_invariants_82575() */
34846 struct e1000_mac_operations ops;
34847
34848 u8 addr[6];
34849 @@ -388,6 +389,7 @@ struct e1000_mac_info {
34850 };
34851
34852 struct e1000_phy_info {
34853 + /* cannot be const see igb_get_invariants_82575() */
34854 struct e1000_phy_operations ops;
34855
34856 enum e1000_phy_type type;
34857 @@ -423,6 +425,7 @@ struct e1000_phy_info {
34858 };
34859
34860 struct e1000_nvm_info {
34861 + /* cannot be const */
34862 struct e1000_nvm_operations ops;
34863 enum e1000_nvm_type type;
34864 enum e1000_nvm_override override;
34865 diff -urNp linux-2.6.39.2/drivers/net/igbvf/vf.h linux-2.6.39.2/drivers/net/igbvf/vf.h
34866 --- linux-2.6.39.2/drivers/net/igbvf/vf.h 2011-05-19 00:06:34.000000000 -0400
34867 +++ linux-2.6.39.2/drivers/net/igbvf/vf.h 2011-05-22 19:36:31.000000000 -0400
34868 @@ -191,6 +191,7 @@ struct e1000_mac_operations {
34869 };
34870
34871 struct e1000_mac_info {
34872 + /* cannot be const see e1000_init_mac_params_vf() */
34873 struct e1000_mac_operations ops;
34874 u8 addr[6];
34875 u8 perm_addr[6];
34876 diff -urNp linux-2.6.39.2/drivers/net/irda/sh_irda.c linux-2.6.39.2/drivers/net/irda/sh_irda.c
34877 --- linux-2.6.39.2/drivers/net/irda/sh_irda.c 2011-05-19 00:06:34.000000000 -0400
34878 +++ linux-2.6.39.2/drivers/net/irda/sh_irda.c 2011-05-22 19:36:31.000000000 -0400
34879 @@ -307,7 +307,7 @@ static int xir_fte(struct sh_irda_self *
34880 return 0;
34881 }
34882
34883 -static struct sh_irda_xir_func xir_func = {
34884 +static const struct sh_irda_xir_func xir_func = {
34885 .xir_fre = xir_fre,
34886 .xir_trov = xir_trov,
34887 .xir_9 = xir_9,
34888 @@ -321,7 +321,7 @@ static struct sh_irda_xir_func xir_func
34889 *
34890 * MIR/FIR are not supported now
34891 *=====================================*/
34892 -static struct sh_irda_xir_func mfir_func = {
34893 +static const struct sh_irda_xir_func mfir_func = {
34894 .xir_fre = xir_fre,
34895 .xir_trov = xir_trov,
34896 .xir_9 = xir_9,
34897 @@ -400,7 +400,7 @@ static int sir_fte(struct sh_irda_self *
34898 return 0;
34899 }
34900
34901 -static struct sh_irda_xir_func sir_func = {
34902 +static const struct sh_irda_xir_func sir_func = {
34903 .xir_fre = sir_fre,
34904 .xir_trov = sir_trov,
34905 .xir_9 = sir_tot,
34906 @@ -411,7 +411,7 @@ static struct sh_irda_xir_func sir_func
34907 static void sh_irda_set_mode(struct sh_irda_self *self, enum sh_irda_mode mode)
34908 {
34909 struct device *dev = &self->ndev->dev;
34910 - struct sh_irda_xir_func *func;
34911 + const struct sh_irda_xir_func *func;
34912 const char *name;
34913 u16 data;
34914
34915 diff -urNp linux-2.6.39.2/drivers/net/ixgb/ixgb_main.c linux-2.6.39.2/drivers/net/ixgb/ixgb_main.c
34916 --- linux-2.6.39.2/drivers/net/ixgb/ixgb_main.c 2011-05-19 00:06:34.000000000 -0400
34917 +++ linux-2.6.39.2/drivers/net/ixgb/ixgb_main.c 2011-05-22 19:36:31.000000000 -0400
34918 @@ -1069,6 +1069,8 @@ ixgb_set_multi(struct net_device *netdev
34919 u32 rctl;
34920 int i;
34921
34922 + pax_track_stack();
34923 +
34924 /* Check for Promiscuous and All Multicast modes */
34925
34926 rctl = IXGB_READ_REG(hw, RCTL);
34927 diff -urNp linux-2.6.39.2/drivers/net/ixgb/ixgb_param.c linux-2.6.39.2/drivers/net/ixgb/ixgb_param.c
34928 --- linux-2.6.39.2/drivers/net/ixgb/ixgb_param.c 2011-05-19 00:06:34.000000000 -0400
34929 +++ linux-2.6.39.2/drivers/net/ixgb/ixgb_param.c 2011-05-22 19:36:31.000000000 -0400
34930 @@ -261,6 +261,9 @@ void __devinit
34931 ixgb_check_options(struct ixgb_adapter *adapter)
34932 {
34933 int bd = adapter->bd_number;
34934 +
34935 + pax_track_stack();
34936 +
34937 if (bd >= IXGB_MAX_NIC) {
34938 pr_notice("Warning: no configuration for board #%i\n", bd);
34939 pr_notice("Using defaults for all values\n");
34940 diff -urNp linux-2.6.39.2/drivers/net/ixgbe/ixgbe_82599.c linux-2.6.39.2/drivers/net/ixgbe/ixgbe_82599.c
34941 --- linux-2.6.39.2/drivers/net/ixgbe/ixgbe_82599.c 2011-05-19 00:06:34.000000000 -0400
34942 +++ linux-2.6.39.2/drivers/net/ixgbe/ixgbe_82599.c 2011-05-22 19:36:31.000000000 -0400
34943 @@ -2099,7 +2099,7 @@ static struct ixgbe_phy_operations phy_o
34944 .check_overtemp = &ixgbe_tn_check_overtemp,
34945 };
34946
34947 -struct ixgbe_info ixgbe_82599_info = {
34948 +const struct ixgbe_info ixgbe_82599_info = {
34949 .mac = ixgbe_mac_82599EB,
34950 .get_invariants = &ixgbe_get_invariants_82599,
34951 .mac_ops = &mac_ops_82599,
34952 diff -urNp linux-2.6.39.2/drivers/net/ixgbe/ixgbe.h linux-2.6.39.2/drivers/net/ixgbe/ixgbe.h
34953 --- linux-2.6.39.2/drivers/net/ixgbe/ixgbe.h 2011-05-19 00:06:34.000000000 -0400
34954 +++ linux-2.6.39.2/drivers/net/ixgbe/ixgbe.h 2011-05-22 19:36:31.000000000 -0400
34955 @@ -493,8 +493,8 @@ enum ixgbe_boards {
34956 };
34957
34958 extern struct ixgbe_info ixgbe_82598_info;
34959 -extern struct ixgbe_info ixgbe_82599_info;
34960 -extern struct ixgbe_info ixgbe_X540_info;
34961 +extern const struct ixgbe_info ixgbe_82599_info;
34962 +extern const struct ixgbe_info ixgbe_X540_info;
34963 #ifdef CONFIG_IXGBE_DCB
34964 extern const struct dcbnl_rtnl_ops dcbnl_ops;
34965 extern int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
34966 diff -urNp linux-2.6.39.2/drivers/net/ixgbe/ixgbe_x540.c linux-2.6.39.2/drivers/net/ixgbe/ixgbe_x540.c
34967 --- linux-2.6.39.2/drivers/net/ixgbe/ixgbe_x540.c 2011-05-19 00:06:34.000000000 -0400
34968 +++ linux-2.6.39.2/drivers/net/ixgbe/ixgbe_x540.c 2011-05-22 19:36:31.000000000 -0400
34969 @@ -727,7 +727,7 @@ static struct ixgbe_phy_operations phy_o
34970 .check_overtemp = &ixgbe_tn_check_overtemp,
34971 };
34972
34973 -struct ixgbe_info ixgbe_X540_info = {
34974 +const struct ixgbe_info ixgbe_X540_info = {
34975 .mac = ixgbe_mac_X540,
34976 .get_invariants = &ixgbe_get_invariants_X540,
34977 .mac_ops = &mac_ops_X540,
34978 diff -urNp linux-2.6.39.2/drivers/net/ixgbevf/ethtool.c linux-2.6.39.2/drivers/net/ixgbevf/ethtool.c
34979 --- linux-2.6.39.2/drivers/net/ixgbevf/ethtool.c 2011-05-19 00:06:34.000000000 -0400
34980 +++ linux-2.6.39.2/drivers/net/ixgbevf/ethtool.c 2011-05-22 19:36:31.000000000 -0400
34981 @@ -709,7 +709,7 @@ static int ixgbevf_nway_reset(struct net
34982 return 0;
34983 }
34984
34985 -static struct ethtool_ops ixgbevf_ethtool_ops = {
34986 +static const struct ethtool_ops ixgbevf_ethtool_ops = {
34987 .get_settings = ixgbevf_get_settings,
34988 .get_drvinfo = ixgbevf_get_drvinfo,
34989 .get_regs_len = ixgbevf_get_regs_len,
34990 diff -urNp linux-2.6.39.2/drivers/net/ixgbevf/ixgbevf.h linux-2.6.39.2/drivers/net/ixgbevf/ixgbevf.h
34991 --- linux-2.6.39.2/drivers/net/ixgbevf/ixgbevf.h 2011-05-19 00:06:34.000000000 -0400
34992 +++ linux-2.6.39.2/drivers/net/ixgbevf/ixgbevf.h 2011-05-22 19:36:31.000000000 -0400
34993 @@ -279,7 +279,7 @@ enum ixgbevf_boards {
34994
34995 extern struct ixgbevf_info ixgbevf_82599_vf_info;
34996 extern struct ixgbevf_info ixgbevf_X540_vf_info;
34997 -extern struct ixgbe_mac_operations ixgbevf_mbx_ops;
34998 +extern const struct ixgbe_mac_operations ixgbevf_mbx_ops;
34999
35000 /* needed by ethtool.c */
35001 extern char ixgbevf_driver_name[];
35002 diff -urNp linux-2.6.39.2/drivers/net/ixgbevf/vf.c linux-2.6.39.2/drivers/net/ixgbevf/vf.c
35003 --- linux-2.6.39.2/drivers/net/ixgbevf/vf.c 2011-05-19 00:06:34.000000000 -0400
35004 +++ linux-2.6.39.2/drivers/net/ixgbevf/vf.c 2011-05-22 19:36:31.000000000 -0400
35005 @@ -368,7 +368,7 @@ static s32 ixgbevf_check_mac_link_vf(str
35006 return 0;
35007 }
35008
35009 -static struct ixgbe_mac_operations ixgbevf_mac_ops = {
35010 +static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
35011 .init_hw = ixgbevf_init_hw_vf,
35012 .reset_hw = ixgbevf_reset_hw_vf,
35013 .start_hw = ixgbevf_start_hw_vf,
35014 @@ -381,12 +381,12 @@ static struct ixgbe_mac_operations ixgbe
35015 .set_vfta = ixgbevf_set_vfta_vf,
35016 };
35017
35018 -struct ixgbevf_info ixgbevf_82599_vf_info = {
35019 +const struct ixgbevf_info ixgbevf_82599_vf_info = {
35020 .mac = ixgbe_mac_82599_vf,
35021 .mac_ops = &ixgbevf_mac_ops,
35022 };
35023
35024 -struct ixgbevf_info ixgbevf_X540_vf_info = {
35025 +const struct ixgbevf_info ixgbevf_X540_vf_info = {
35026 .mac = ixgbe_mac_X540_vf,
35027 .mac_ops = &ixgbevf_mac_ops,
35028 };
35029 diff -urNp linux-2.6.39.2/drivers/net/ixgbevf/vf.h linux-2.6.39.2/drivers/net/ixgbevf/vf.h
35030 --- linux-2.6.39.2/drivers/net/ixgbevf/vf.h 2011-05-19 00:06:34.000000000 -0400
35031 +++ linux-2.6.39.2/drivers/net/ixgbevf/vf.h 2011-05-22 19:36:31.000000000 -0400
35032 @@ -166,7 +166,7 @@ struct ixgbevf_hw_stats {
35033
35034 struct ixgbevf_info {
35035 enum ixgbe_mac_type mac;
35036 - struct ixgbe_mac_operations *mac_ops;
35037 + const struct ixgbe_mac_operations *mac_ops;
35038 };
35039
35040 #endif /* __IXGBE_VF_H__ */
35041 diff -urNp linux-2.6.39.2/drivers/net/ksz884x.c linux-2.6.39.2/drivers/net/ksz884x.c
35042 --- linux-2.6.39.2/drivers/net/ksz884x.c 2011-05-19 00:06:34.000000000 -0400
35043 +++ linux-2.6.39.2/drivers/net/ksz884x.c 2011-05-22 19:36:31.000000000 -0400
35044 @@ -6536,6 +6536,8 @@ static void netdev_get_ethtool_stats(str
35045 int rc;
35046 u64 counter[TOTAL_PORT_COUNTER_NUM];
35047
35048 + pax_track_stack();
35049 +
35050 mutex_lock(&hw_priv->lock);
35051 n = SWITCH_PORT_NUM;
35052 for (i = 0, p = port->first_port; i < port->mib_port_cnt; i++, p++) {
35053 @@ -6637,7 +6639,7 @@ static int netdev_set_rx_csum(struct net
35054 return 0;
35055 }
35056
35057 -static struct ethtool_ops netdev_ethtool_ops = {
35058 +static const struct ethtool_ops netdev_ethtool_ops = {
35059 .get_settings = netdev_get_settings,
35060 .set_settings = netdev_set_settings,
35061 .nway_reset = netdev_nway_reset,
35062 diff -urNp linux-2.6.39.2/drivers/net/mlx4/main.c linux-2.6.39.2/drivers/net/mlx4/main.c
35063 --- linux-2.6.39.2/drivers/net/mlx4/main.c 2011-05-19 00:06:34.000000000 -0400
35064 +++ linux-2.6.39.2/drivers/net/mlx4/main.c 2011-05-22 19:36:31.000000000 -0400
35065 @@ -40,6 +40,7 @@
35066 #include <linux/dma-mapping.h>
35067 #include <linux/slab.h>
35068 #include <linux/io-mapping.h>
35069 +#include <linux/sched.h>
35070
35071 #include <linux/mlx4/device.h>
35072 #include <linux/mlx4/doorbell.h>
35073 @@ -764,6 +765,8 @@ static int mlx4_init_hca(struct mlx4_dev
35074 u64 icm_size;
35075 int err;
35076
35077 + pax_track_stack();
35078 +
35079 err = mlx4_QUERY_FW(dev);
35080 if (err) {
35081 if (err == -EACCES)
35082 diff -urNp linux-2.6.39.2/drivers/net/netconsole.c linux-2.6.39.2/drivers/net/netconsole.c
35083 --- linux-2.6.39.2/drivers/net/netconsole.c 2011-05-19 00:06:34.000000000 -0400
35084 +++ linux-2.6.39.2/drivers/net/netconsole.c 2011-05-22 19:36:31.000000000 -0400
35085 @@ -634,7 +634,7 @@ static void drop_netconsole_target(struc
35086 config_item_put(&nt->item);
35087 }
35088
35089 -static struct configfs_group_operations netconsole_subsys_group_ops = {
35090 +static const struct configfs_group_operations netconsole_subsys_group_ops = {
35091 .make_item = make_netconsole_target,
35092 .drop_item = drop_netconsole_target,
35093 };
35094 diff -urNp linux-2.6.39.2/drivers/net/niu.c linux-2.6.39.2/drivers/net/niu.c
35095 --- linux-2.6.39.2/drivers/net/niu.c 2011-05-19 00:06:34.000000000 -0400
35096 +++ linux-2.6.39.2/drivers/net/niu.c 2011-05-22 19:36:31.000000000 -0400
35097 @@ -9067,6 +9067,8 @@ static void __devinit niu_try_msix(struc
35098 int i, num_irqs, err;
35099 u8 first_ldg;
35100
35101 + pax_track_stack();
35102 +
35103 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
35104 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
35105 ldg_num_map[i] = first_ldg + i;
35106 diff -urNp linux-2.6.39.2/drivers/net/pcnet32.c linux-2.6.39.2/drivers/net/pcnet32.c
35107 --- linux-2.6.39.2/drivers/net/pcnet32.c 2011-05-19 00:06:34.000000000 -0400
35108 +++ linux-2.6.39.2/drivers/net/pcnet32.c 2011-05-22 19:36:31.000000000 -0400
35109 @@ -82,7 +82,7 @@ static int cards_found;
35110 /*
35111 * VLB I/O addresses
35112 */
35113 -static unsigned int pcnet32_portlist[] __initdata =
35114 +static unsigned int pcnet32_portlist[] __devinitdata =
35115 { 0x300, 0x320, 0x340, 0x360, 0 };
35116
35117 static int pcnet32_debug;
35118 @@ -379,7 +379,7 @@ static int pcnet32_wio_check(unsigned lo
35119 return inw(addr + PCNET32_WIO_RAP) == 88;
35120 }
35121
35122 -static struct pcnet32_access pcnet32_wio = {
35123 +static const struct pcnet32_access pcnet32_wio = {
35124 .read_csr = pcnet32_wio_read_csr,
35125 .write_csr = pcnet32_wio_write_csr,
35126 .read_bcr = pcnet32_wio_read_bcr,
35127 @@ -434,7 +434,7 @@ static int pcnet32_dwio_check(unsigned l
35128 return (inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88;
35129 }
35130
35131 -static struct pcnet32_access pcnet32_dwio = {
35132 +static const struct pcnet32_access pcnet32_dwio = {
35133 .read_csr = pcnet32_dwio_read_csr,
35134 .write_csr = pcnet32_dwio_write_csr,
35135 .read_bcr = pcnet32_dwio_read_bcr,
35136 @@ -1546,7 +1546,7 @@ pcnet32_probe1(unsigned long ioaddr, int
35137 int chip_version;
35138 char *chipname;
35139 struct net_device *dev;
35140 - struct pcnet32_access *a = NULL;
35141 + const struct pcnet32_access *a = NULL;
35142 u8 promaddr[6];
35143 int ret = -ENODEV;
35144
35145 diff -urNp linux-2.6.39.2/drivers/net/ppp_generic.c linux-2.6.39.2/drivers/net/ppp_generic.c
35146 --- linux-2.6.39.2/drivers/net/ppp_generic.c 2011-05-19 00:06:34.000000000 -0400
35147 +++ linux-2.6.39.2/drivers/net/ppp_generic.c 2011-05-22 19:36:31.000000000 -0400
35148 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, st
35149 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35150 struct ppp_stats stats;
35151 struct ppp_comp_stats cstats;
35152 - char *vers;
35153
35154 switch (cmd) {
35155 case SIOCGPPPSTATS:
35156 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, st
35157 break;
35158
35159 case SIOCGPPPVER:
35160 - vers = PPP_VERSION;
35161 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35162 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35163 break;
35164 err = 0;
35165 break;
35166 diff -urNp linux-2.6.39.2/drivers/net/qlcnic/qlcnic.h linux-2.6.39.2/drivers/net/qlcnic/qlcnic.h
35167 --- linux-2.6.39.2/drivers/net/qlcnic/qlcnic.h 2011-05-19 00:06:34.000000000 -0400
35168 +++ linux-2.6.39.2/drivers/net/qlcnic/qlcnic.h 2011-05-22 19:36:31.000000000 -0400
35169 @@ -1037,7 +1037,7 @@ struct qlcnic_adapter {
35170 struct vlan_group *vlgrp;
35171 struct qlcnic_npar_info *npars;
35172 struct qlcnic_eswitch *eswitch;
35173 - struct qlcnic_nic_template *nic_ops;
35174 + const struct qlcnic_nic_template *nic_ops;
35175
35176 struct qlcnic_adapter_stats stats;
35177
35178 diff -urNp linux-2.6.39.2/drivers/net/qlcnic/qlcnic_main.c linux-2.6.39.2/drivers/net/qlcnic/qlcnic_main.c
35179 --- linux-2.6.39.2/drivers/net/qlcnic/qlcnic_main.c 2011-05-19 00:06:34.000000000 -0400
35180 +++ linux-2.6.39.2/drivers/net/qlcnic/qlcnic_main.c 2011-05-22 19:36:31.000000000 -0400
35181 @@ -340,13 +340,13 @@ static const struct net_device_ops qlcni
35182 #endif
35183 };
35184
35185 -static struct qlcnic_nic_template qlcnic_ops = {
35186 +static const struct qlcnic_nic_template qlcnic_ops = {
35187 .config_bridged_mode = qlcnic_config_bridged_mode,
35188 .config_led = qlcnic_config_led,
35189 .start_firmware = qlcnic_start_firmware
35190 };
35191
35192 -static struct qlcnic_nic_template qlcnic_vf_ops = {
35193 +static const struct qlcnic_nic_template qlcnic_vf_ops = {
35194 .config_bridged_mode = qlcnicvf_config_bridged_mode,
35195 .config_led = qlcnicvf_config_led,
35196 .start_firmware = qlcnicvf_start_firmware
35197 diff -urNp linux-2.6.39.2/drivers/net/qlge/qlge.h linux-2.6.39.2/drivers/net/qlge/qlge.h
35198 --- linux-2.6.39.2/drivers/net/qlge/qlge.h 2011-05-19 00:06:34.000000000 -0400
35199 +++ linux-2.6.39.2/drivers/net/qlge/qlge.h 2011-05-22 19:36:31.000000000 -0400
35200 @@ -2134,7 +2134,7 @@ struct ql_adapter {
35201 struct delayed_work mpi_idc_work;
35202 struct delayed_work mpi_core_to_log;
35203 struct completion ide_completion;
35204 - struct nic_operations *nic_ops;
35205 + const struct nic_operations *nic_ops;
35206 u16 device_id;
35207 struct timer_list timer;
35208 atomic_t lb_count;
35209 diff -urNp linux-2.6.39.2/drivers/net/qlge/qlge_main.c linux-2.6.39.2/drivers/net/qlge/qlge_main.c
35210 --- linux-2.6.39.2/drivers/net/qlge/qlge_main.c 2011-05-19 00:06:34.000000000 -0400
35211 +++ linux-2.6.39.2/drivers/net/qlge/qlge_main.c 2011-05-22 19:36:31.000000000 -0400
35212 @@ -4412,12 +4412,12 @@ error:
35213 rtnl_unlock();
35214 }
35215
35216 -static struct nic_operations qla8012_nic_ops = {
35217 +static const struct nic_operations qla8012_nic_ops = {
35218 .get_flash = ql_get_8012_flash_params,
35219 .port_initialize = ql_8012_port_initialize,
35220 };
35221
35222 -static struct nic_operations qla8000_nic_ops = {
35223 +static const struct nic_operations qla8000_nic_ops = {
35224 .get_flash = ql_get_8000_flash_params,
35225 .port_initialize = ql_8000_port_initialize,
35226 };
35227 diff -urNp linux-2.6.39.2/drivers/net/sfc/falcon.c linux-2.6.39.2/drivers/net/sfc/falcon.c
35228 --- linux-2.6.39.2/drivers/net/sfc/falcon.c 2011-05-19 00:06:34.000000000 -0400
35229 +++ linux-2.6.39.2/drivers/net/sfc/falcon.c 2011-05-22 19:36:31.000000000 -0400
35230 @@ -1703,7 +1703,7 @@ static int falcon_set_wol(struct efx_nic
35231 **************************************************************************
35232 */
35233
35234 -struct efx_nic_type falcon_a1_nic_type = {
35235 +const struct efx_nic_type falcon_a1_nic_type = {
35236 .probe = falcon_probe_nic,
35237 .remove = falcon_remove_nic,
35238 .init = falcon_init_nic,
35239 @@ -1744,7 +1744,7 @@ struct efx_nic_type falcon_a1_nic_type =
35240 .reset_world_flags = ETH_RESET_IRQ,
35241 };
35242
35243 -struct efx_nic_type falcon_b0_nic_type = {
35244 +const struct efx_nic_type falcon_b0_nic_type = {
35245 .probe = falcon_probe_nic,
35246 .remove = falcon_remove_nic,
35247 .init = falcon_init_nic,
35248 diff -urNp linux-2.6.39.2/drivers/net/sfc/mtd.c linux-2.6.39.2/drivers/net/sfc/mtd.c
35249 --- linux-2.6.39.2/drivers/net/sfc/mtd.c 2011-05-19 00:06:34.000000000 -0400
35250 +++ linux-2.6.39.2/drivers/net/sfc/mtd.c 2011-05-22 19:36:31.000000000 -0400
35251 @@ -382,7 +382,7 @@ static int falcon_mtd_sync(struct mtd_in
35252 return rc;
35253 }
35254
35255 -static struct efx_mtd_ops falcon_mtd_ops = {
35256 +static const struct efx_mtd_ops falcon_mtd_ops = {
35257 .read = falcon_mtd_read,
35258 .erase = falcon_mtd_erase,
35259 .write = falcon_mtd_write,
35260 @@ -560,7 +560,7 @@ static int siena_mtd_sync(struct mtd_inf
35261 return rc;
35262 }
35263
35264 -static struct efx_mtd_ops siena_mtd_ops = {
35265 +static const struct efx_mtd_ops siena_mtd_ops = {
35266 .read = siena_mtd_read,
35267 .erase = siena_mtd_erase,
35268 .write = siena_mtd_write,
35269 diff -urNp linux-2.6.39.2/drivers/net/sfc/nic.h linux-2.6.39.2/drivers/net/sfc/nic.h
35270 --- linux-2.6.39.2/drivers/net/sfc/nic.h 2011-05-19 00:06:34.000000000 -0400
35271 +++ linux-2.6.39.2/drivers/net/sfc/nic.h 2011-05-22 19:36:31.000000000 -0400
35272 @@ -152,9 +152,9 @@ struct siena_nic_data {
35273 int wol_filter_id;
35274 };
35275
35276 -extern struct efx_nic_type falcon_a1_nic_type;
35277 -extern struct efx_nic_type falcon_b0_nic_type;
35278 -extern struct efx_nic_type siena_a0_nic_type;
35279 +extern const struct efx_nic_type falcon_a1_nic_type;
35280 +extern const struct efx_nic_type falcon_b0_nic_type;
35281 +extern const struct efx_nic_type siena_a0_nic_type;
35282
35283 /**************************************************************************
35284 *
35285 diff -urNp linux-2.6.39.2/drivers/net/sfc/siena.c linux-2.6.39.2/drivers/net/sfc/siena.c
35286 --- linux-2.6.39.2/drivers/net/sfc/siena.c 2011-05-19 00:06:34.000000000 -0400
35287 +++ linux-2.6.39.2/drivers/net/sfc/siena.c 2011-05-22 19:36:31.000000000 -0400
35288 @@ -599,7 +599,7 @@ static void siena_init_wol(struct efx_ni
35289 **************************************************************************
35290 */
35291
35292 -struct efx_nic_type siena_a0_nic_type = {
35293 +const struct efx_nic_type siena_a0_nic_type = {
35294 .probe = siena_probe_nic,
35295 .remove = siena_remove_nic,
35296 .init = siena_init_nic,
35297 diff -urNp linux-2.6.39.2/drivers/net/sh_eth.c linux-2.6.39.2/drivers/net/sh_eth.c
35298 --- linux-2.6.39.2/drivers/net/sh_eth.c 2011-05-19 00:06:34.000000000 -0400
35299 +++ linux-2.6.39.2/drivers/net/sh_eth.c 2011-05-22 19:36:31.000000000 -0400
35300 @@ -1360,7 +1360,7 @@ static void sh_eth_get_strings(struct ne
35301 }
35302 }
35303
35304 -static struct ethtool_ops sh_eth_ethtool_ops = {
35305 +static const struct ethtool_ops sh_eth_ethtool_ops = {
35306 .get_settings = sh_eth_get_settings,
35307 .set_settings = sh_eth_set_settings,
35308 .nway_reset = sh_eth_nway_reset,
35309 diff -urNp linux-2.6.39.2/drivers/net/stmmac/stmmac_ethtool.c linux-2.6.39.2/drivers/net/stmmac/stmmac_ethtool.c
35310 --- linux-2.6.39.2/drivers/net/stmmac/stmmac_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35311 +++ linux-2.6.39.2/drivers/net/stmmac/stmmac_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35312 @@ -348,7 +348,7 @@ static int stmmac_set_wol(struct net_dev
35313 return 0;
35314 }
35315
35316 -static struct ethtool_ops stmmac_ethtool_ops = {
35317 +static const struct ethtool_ops stmmac_ethtool_ops = {
35318 .begin = stmmac_check_if_running,
35319 .get_drvinfo = stmmac_ethtool_getdrvinfo,
35320 .get_settings = stmmac_ethtool_getsettings,
35321 diff -urNp linux-2.6.39.2/drivers/net/sungem_phy.c linux-2.6.39.2/drivers/net/sungem_phy.c
35322 --- linux-2.6.39.2/drivers/net/sungem_phy.c 2011-05-19 00:06:34.000000000 -0400
35323 +++ linux-2.6.39.2/drivers/net/sungem_phy.c 2011-05-22 19:36:31.000000000 -0400
35324 @@ -886,7 +886,7 @@ static int marvell_read_link(struct mii_
35325 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
35326
35327 /* Broadcom BCM 5201 */
35328 -static struct mii_phy_ops bcm5201_phy_ops = {
35329 +static const struct mii_phy_ops bcm5201_phy_ops = {
35330 .init = bcm5201_init,
35331 .suspend = bcm5201_suspend,
35332 .setup_aneg = genmii_setup_aneg,
35333 @@ -905,7 +905,7 @@ static struct mii_phy_def bcm5201_phy_de
35334 };
35335
35336 /* Broadcom BCM 5221 */
35337 -static struct mii_phy_ops bcm5221_phy_ops = {
35338 +static const struct mii_phy_ops bcm5221_phy_ops = {
35339 .suspend = bcm5221_suspend,
35340 .init = bcm5221_init,
35341 .setup_aneg = genmii_setup_aneg,
35342 @@ -924,7 +924,7 @@ static struct mii_phy_def bcm5221_phy_de
35343 };
35344
35345 /* Broadcom BCM 5241 */
35346 -static struct mii_phy_ops bcm5241_phy_ops = {
35347 +static const struct mii_phy_ops bcm5241_phy_ops = {
35348 .suspend = bcm5241_suspend,
35349 .init = bcm5241_init,
35350 .setup_aneg = genmii_setup_aneg,
35351 @@ -942,7 +942,7 @@ static struct mii_phy_def bcm5241_phy_de
35352 };
35353
35354 /* Broadcom BCM 5400 */
35355 -static struct mii_phy_ops bcm5400_phy_ops = {
35356 +static const struct mii_phy_ops bcm5400_phy_ops = {
35357 .init = bcm5400_init,
35358 .suspend = bcm5400_suspend,
35359 .setup_aneg = bcm54xx_setup_aneg,
35360 @@ -961,7 +961,7 @@ static struct mii_phy_def bcm5400_phy_de
35361 };
35362
35363 /* Broadcom BCM 5401 */
35364 -static struct mii_phy_ops bcm5401_phy_ops = {
35365 +static const struct mii_phy_ops bcm5401_phy_ops = {
35366 .init = bcm5401_init,
35367 .suspend = bcm5401_suspend,
35368 .setup_aneg = bcm54xx_setup_aneg,
35369 @@ -980,7 +980,7 @@ static struct mii_phy_def bcm5401_phy_de
35370 };
35371
35372 /* Broadcom BCM 5411 */
35373 -static struct mii_phy_ops bcm5411_phy_ops = {
35374 +static const struct mii_phy_ops bcm5411_phy_ops = {
35375 .init = bcm5411_init,
35376 .suspend = generic_suspend,
35377 .setup_aneg = bcm54xx_setup_aneg,
35378 @@ -999,7 +999,7 @@ static struct mii_phy_def bcm5411_phy_de
35379 };
35380
35381 /* Broadcom BCM 5421 */
35382 -static struct mii_phy_ops bcm5421_phy_ops = {
35383 +static const struct mii_phy_ops bcm5421_phy_ops = {
35384 .init = bcm5421_init,
35385 .suspend = generic_suspend,
35386 .setup_aneg = bcm54xx_setup_aneg,
35387 @@ -1019,7 +1019,7 @@ static struct mii_phy_def bcm5421_phy_de
35388 };
35389
35390 /* Broadcom BCM 5421 built-in K2 */
35391 -static struct mii_phy_ops bcm5421k2_phy_ops = {
35392 +static const struct mii_phy_ops bcm5421k2_phy_ops = {
35393 .init = bcm5421_init,
35394 .suspend = generic_suspend,
35395 .setup_aneg = bcm54xx_setup_aneg,
35396 @@ -1037,7 +1037,7 @@ static struct mii_phy_def bcm5421k2_phy_
35397 .ops = &bcm5421k2_phy_ops
35398 };
35399
35400 -static struct mii_phy_ops bcm5461_phy_ops = {
35401 +static const struct mii_phy_ops bcm5461_phy_ops = {
35402 .init = bcm5421_init,
35403 .suspend = generic_suspend,
35404 .setup_aneg = bcm54xx_setup_aneg,
35405 @@ -1057,7 +1057,7 @@ static struct mii_phy_def bcm5461_phy_de
35406 };
35407
35408 /* Broadcom BCM 5462 built-in Vesta */
35409 -static struct mii_phy_ops bcm5462V_phy_ops = {
35410 +static const struct mii_phy_ops bcm5462V_phy_ops = {
35411 .init = bcm5421_init,
35412 .suspend = generic_suspend,
35413 .setup_aneg = bcm54xx_setup_aneg,
35414 @@ -1076,7 +1076,7 @@ static struct mii_phy_def bcm5462V_phy_d
35415 };
35416
35417 /* Marvell 88E1101 amd 88E1111 */
35418 -static struct mii_phy_ops marvell88e1101_phy_ops = {
35419 +static const struct mii_phy_ops marvell88e1101_phy_ops = {
35420 .suspend = generic_suspend,
35421 .setup_aneg = marvell_setup_aneg,
35422 .setup_forced = marvell_setup_forced,
35423 @@ -1084,7 +1084,7 @@ static struct mii_phy_ops marvell88e1101
35424 .read_link = marvell_read_link
35425 };
35426
35427 -static struct mii_phy_ops marvell88e1111_phy_ops = {
35428 +static const struct mii_phy_ops marvell88e1111_phy_ops = {
35429 .init = marvell88e1111_init,
35430 .suspend = generic_suspend,
35431 .setup_aneg = marvell_setup_aneg,
35432 @@ -1122,7 +1122,7 @@ static struct mii_phy_def marvell88e1111
35433 };
35434
35435 /* Generic implementation for most 10/100 PHYs */
35436 -static struct mii_phy_ops generic_phy_ops = {
35437 +static const struct mii_phy_ops generic_phy_ops = {
35438 .setup_aneg = genmii_setup_aneg,
35439 .setup_forced = genmii_setup_forced,
35440 .poll_link = genmii_poll_link,
35441 diff -urNp linux-2.6.39.2/drivers/net/tg3.h linux-2.6.39.2/drivers/net/tg3.h
35442 --- linux-2.6.39.2/drivers/net/tg3.h 2011-05-19 00:06:34.000000000 -0400
35443 +++ linux-2.6.39.2/drivers/net/tg3.h 2011-05-22 19:36:31.000000000 -0400
35444 @@ -131,6 +131,7 @@
35445 #define CHIPREV_ID_5750_A0 0x4000
35446 #define CHIPREV_ID_5750_A1 0x4001
35447 #define CHIPREV_ID_5750_A3 0x4003
35448 +#define CHIPREV_ID_5750_C1 0x4201
35449 #define CHIPREV_ID_5750_C2 0x4202
35450 #define CHIPREV_ID_5752_A0_HW 0x5000
35451 #define CHIPREV_ID_5752_A0 0x6000
35452 diff -urNp linux-2.6.39.2/drivers/net/tile/tilepro.c linux-2.6.39.2/drivers/net/tile/tilepro.c
35453 --- linux-2.6.39.2/drivers/net/tile/tilepro.c 2011-05-19 00:06:34.000000000 -0400
35454 +++ linux-2.6.39.2/drivers/net/tile/tilepro.c 2011-05-22 19:36:31.000000000 -0400
35455 @@ -2263,7 +2263,7 @@ static int tile_net_get_mac(struct net_d
35456 }
35457
35458
35459 -static struct net_device_ops tile_net_ops = {
35460 +static const struct net_device_ops tile_net_ops = {
35461 .ndo_open = tile_net_open,
35462 .ndo_stop = tile_net_stop,
35463 .ndo_start_xmit = tile_net_tx,
35464 diff -urNp linux-2.6.39.2/drivers/net/tulip/de2104x.c linux-2.6.39.2/drivers/net/tulip/de2104x.c
35465 --- linux-2.6.39.2/drivers/net/tulip/de2104x.c 2011-05-19 00:06:34.000000000 -0400
35466 +++ linux-2.6.39.2/drivers/net/tulip/de2104x.c 2011-05-22 19:36:31.000000000 -0400
35467 @@ -1817,6 +1817,8 @@ static void __devinit de21041_get_srom_i
35468 struct de_srom_info_leaf *il;
35469 void *bufp;
35470
35471 + pax_track_stack();
35472 +
35473 /* download entire eeprom */
35474 for (i = 0; i < DE_EEPROM_WORDS; i++)
35475 ((__le16 *)ee_data)[i] =
35476 diff -urNp linux-2.6.39.2/drivers/net/tulip/de4x5.c linux-2.6.39.2/drivers/net/tulip/de4x5.c
35477 --- linux-2.6.39.2/drivers/net/tulip/de4x5.c 2011-05-19 00:06:34.000000000 -0400
35478 +++ linux-2.6.39.2/drivers/net/tulip/de4x5.c 2011-05-22 19:36:31.000000000 -0400
35479 @@ -5401,7 +5401,7 @@ de4x5_ioctl(struct net_device *dev, stru
35480 for (i=0; i<ETH_ALEN; i++) {
35481 tmp.addr[i] = dev->dev_addr[i];
35482 }
35483 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35484 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35485 break;
35486
35487 case DE4X5_SET_HWADDR: /* Set the hardware address */
35488 @@ -5441,7 +5441,7 @@ de4x5_ioctl(struct net_device *dev, stru
35489 spin_lock_irqsave(&lp->lock, flags);
35490 memcpy(&statbuf, &lp->pktStats, ioc->len);
35491 spin_unlock_irqrestore(&lp->lock, flags);
35492 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35493 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35494 return -EFAULT;
35495 break;
35496 }
35497 diff -urNp linux-2.6.39.2/drivers/net/usb/asix.c linux-2.6.39.2/drivers/net/usb/asix.c
35498 --- linux-2.6.39.2/drivers/net/usb/asix.c 2011-05-19 00:06:34.000000000 -0400
35499 +++ linux-2.6.39.2/drivers/net/usb/asix.c 2011-05-22 19:36:31.000000000 -0400
35500 @@ -1098,7 +1098,7 @@ out:
35501 return ret;
35502 }
35503
35504 -static struct ethtool_ops ax88178_ethtool_ops = {
35505 +static const struct ethtool_ops ax88178_ethtool_ops = {
35506 .get_drvinfo = asix_get_drvinfo,
35507 .get_link = asix_get_link,
35508 .get_msglevel = usbnet_get_msglevel,
35509 diff -urNp linux-2.6.39.2/drivers/net/usb/cdc_ncm.c linux-2.6.39.2/drivers/net/usb/cdc_ncm.c
35510 --- linux-2.6.39.2/drivers/net/usb/cdc_ncm.c 2011-06-25 12:55:22.000000000 -0400
35511 +++ linux-2.6.39.2/drivers/net/usb/cdc_ncm.c 2011-06-25 13:00:26.000000000 -0400
35512 @@ -141,7 +141,7 @@ struct cdc_ncm_ctx {
35513 static void cdc_ncm_tx_timeout(unsigned long arg);
35514 static const struct driver_info cdc_ncm_info;
35515 static struct usb_driver cdc_ncm_driver;
35516 -static struct ethtool_ops cdc_ncm_ethtool_ops;
35517 +static const struct ethtool_ops cdc_ncm_ethtool_ops;
35518
35519 static const struct usb_device_id cdc_devs[] = {
35520 { USB_INTERFACE_INFO(USB_CLASS_COMM,
35521 @@ -1258,7 +1258,7 @@ static struct usb_driver cdc_ncm_driver
35522 .supports_autosuspend = 1,
35523 };
35524
35525 -static struct ethtool_ops cdc_ncm_ethtool_ops = {
35526 +static const struct ethtool_ops cdc_ncm_ethtool_ops = {
35527 .get_drvinfo = cdc_ncm_get_drvinfo,
35528 .get_link = usbnet_get_link,
35529 .get_msglevel = usbnet_get_msglevel,
35530 diff -urNp linux-2.6.39.2/drivers/net/usb/hso.c linux-2.6.39.2/drivers/net/usb/hso.c
35531 --- linux-2.6.39.2/drivers/net/usb/hso.c 2011-05-19 00:06:34.000000000 -0400
35532 +++ linux-2.6.39.2/drivers/net/usb/hso.c 2011-05-22 19:36:31.000000000 -0400
35533 @@ -71,7 +71,7 @@
35534 #include <asm/byteorder.h>
35535 #include <linux/serial_core.h>
35536 #include <linux/serial.h>
35537 -
35538 +#include <asm/local.h>
35539
35540 #define MOD_AUTHOR "Option Wireless"
35541 #define MOD_DESCRIPTION "USB High Speed Option driver"
35542 @@ -257,7 +257,7 @@ struct hso_serial {
35543
35544 /* from usb_serial_port */
35545 struct tty_struct *tty;
35546 - int open_count;
35547 + local_t open_count;
35548 spinlock_t serial_lock;
35549
35550 int (*write_data) (struct hso_serial *serial);
35551 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_
35552 struct urb *urb;
35553
35554 urb = serial->rx_urb[0];
35555 - if (serial->open_count > 0) {
35556 + if (local_read(&serial->open_count) > 0) {
35557 count = put_rxbuf_data(urb, serial);
35558 if (count == -1)
35559 return;
35560 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_cal
35561 DUMP1(urb->transfer_buffer, urb->actual_length);
35562
35563 /* Anyone listening? */
35564 - if (serial->open_count == 0)
35565 + if (local_read(&serial->open_count) == 0)
35566 return;
35567
35568 if (status == 0) {
35569 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_st
35570 spin_unlock_irq(&serial->serial_lock);
35571
35572 /* check for port already opened, if not set the termios */
35573 - serial->open_count++;
35574 - if (serial->open_count == 1) {
35575 + if (local_inc_return(&serial->open_count) == 1) {
35576 serial->rx_state = RX_IDLE;
35577 /* Force default termio settings */
35578 _hso_serial_set_termios(tty, NULL);
35579 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_st
35580 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35581 if (result) {
35582 hso_stop_serial_device(serial->parent);
35583 - serial->open_count--;
35584 + local_dec(&serial->open_count);
35585 kref_put(&serial->parent->ref, hso_serial_ref_free);
35586 }
35587 } else {
35588 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_
35589
35590 /* reset the rts and dtr */
35591 /* do the actual close */
35592 - serial->open_count--;
35593 + local_dec(&serial->open_count);
35594
35595 - if (serial->open_count <= 0) {
35596 - serial->open_count = 0;
35597 + if (local_read(&serial->open_count) <= 0) {
35598 + local_set(&serial->open_count, 0);
35599 spin_lock_irq(&serial->serial_lock);
35600 if (serial->tty == tty) {
35601 serial->tty->driver_data = NULL;
35602 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struc
35603
35604 /* the actual setup */
35605 spin_lock_irqsave(&serial->serial_lock, flags);
35606 - if (serial->open_count)
35607 + if (local_read(&serial->open_count))
35608 _hso_serial_set_termios(tty, old);
35609 else
35610 tty->termios = old;
35611 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *ur
35612 D1("Pending read interrupt on port %d\n", i);
35613 spin_lock(&serial->serial_lock);
35614 if (serial->rx_state == RX_IDLE &&
35615 - serial->open_count > 0) {
35616 + local_read(&serial->open_count) > 0) {
35617 /* Setup and send a ctrl req read on
35618 * port i */
35619 if (!serial->rx_urb_filled[0]) {
35620 @@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interfa
35621 /* Start all serial ports */
35622 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35623 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35624 - if (dev2ser(serial_table[i])->open_count) {
35625 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35626 result =
35627 hso_start_serial_device(serial_table[i], GFP_NOIO);
35628 hso_kick_transmit(dev2ser(serial_table[i]));
35629 diff -urNp linux-2.6.39.2/drivers/net/usb/ipheth.c linux-2.6.39.2/drivers/net/usb/ipheth.c
35630 --- linux-2.6.39.2/drivers/net/usb/ipheth.c 2011-05-19 00:06:34.000000000 -0400
35631 +++ linux-2.6.39.2/drivers/net/usb/ipheth.c 2011-05-22 19:36:31.000000000 -0400
35632 @@ -421,7 +421,7 @@ static u32 ipheth_ethtool_op_get_link(st
35633 return netif_carrier_ok(dev->net);
35634 }
35635
35636 -static struct ethtool_ops ops = {
35637 +static const struct ethtool_ops ops = {
35638 .get_link = ipheth_ethtool_op_get_link
35639 };
35640
35641 diff -urNp linux-2.6.39.2/drivers/net/usb/sierra_net.c linux-2.6.39.2/drivers/net/usb/sierra_net.c
35642 --- linux-2.6.39.2/drivers/net/usb/sierra_net.c 2011-05-19 00:06:34.000000000 -0400
35643 +++ linux-2.6.39.2/drivers/net/usb/sierra_net.c 2011-05-22 19:36:31.000000000 -0400
35644 @@ -618,7 +618,7 @@ static u32 sierra_net_get_link(struct ne
35645 return sierra_net_get_private(dev)->link_up && netif_running(net);
35646 }
35647
35648 -static struct ethtool_ops sierra_net_ethtool_ops = {
35649 +static const struct ethtool_ops sierra_net_ethtool_ops = {
35650 .get_drvinfo = sierra_net_get_drvinfo,
35651 .get_link = sierra_net_get_link,
35652 .get_msglevel = usbnet_get_msglevel,
35653 diff -urNp linux-2.6.39.2/drivers/net/vmxnet3/vmxnet3_ethtool.c linux-2.6.39.2/drivers/net/vmxnet3/vmxnet3_ethtool.c
35654 --- linux-2.6.39.2/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-19 00:06:34.000000000 -0400
35655 +++ linux-2.6.39.2/drivers/net/vmxnet3/vmxnet3_ethtool.c 2011-05-22 19:36:31.000000000 -0400
35656 @@ -631,8 +631,7 @@ vmxnet3_set_rss_indir(struct net_device
35657 * Return with error code if any of the queue indices
35658 * is out of range
35659 */
35660 - if (p->ring_index[i] < 0 ||
35661 - p->ring_index[i] >= adapter->num_rx_queues)
35662 + if (p->ring_index[i] >= adapter->num_rx_queues)
35663 return -EINVAL;
35664 }
35665
35666 diff -urNp linux-2.6.39.2/drivers/net/vxge/vxge-main.c linux-2.6.39.2/drivers/net/vxge/vxge-main.c
35667 --- linux-2.6.39.2/drivers/net/vxge/vxge-main.c 2011-05-19 00:06:34.000000000 -0400
35668 +++ linux-2.6.39.2/drivers/net/vxge/vxge-main.c 2011-05-22 19:36:31.000000000 -0400
35669 @@ -97,6 +97,8 @@ static inline void VXGE_COMPLETE_VPATH_T
35670 struct sk_buff *completed[NR_SKB_COMPLETED];
35671 int more;
35672
35673 + pax_track_stack();
35674 +
35675 do {
35676 more = 0;
35677 skb_ptr = completed;
35678 @@ -1927,6 +1929,8 @@ static enum vxge_hw_status vxge_rth_conf
35679 u8 mtable[256] = {0}; /* CPU to vpath mapping */
35680 int index;
35681
35682 + pax_track_stack();
35683 +
35684 /*
35685 * Filling
35686 * - itable with bucket numbers
35687 diff -urNp linux-2.6.39.2/drivers/net/wan/cycx_x25.c linux-2.6.39.2/drivers/net/wan/cycx_x25.c
35688 --- linux-2.6.39.2/drivers/net/wan/cycx_x25.c 2011-05-19 00:06:34.000000000 -0400
35689 +++ linux-2.6.39.2/drivers/net/wan/cycx_x25.c 2011-05-22 19:36:31.000000000 -0400
35690 @@ -1018,6 +1018,8 @@ static void hex_dump(char *msg, unsigned
35691 unsigned char hex[1024],
35692 * phex = hex;
35693
35694 + pax_track_stack();
35695 +
35696 if (len >= (sizeof(hex) / 2))
35697 len = (sizeof(hex) / 2) - 1;
35698
35699 diff -urNp linux-2.6.39.2/drivers/net/wan/lapbether.c linux-2.6.39.2/drivers/net/wan/lapbether.c
35700 --- linux-2.6.39.2/drivers/net/wan/lapbether.c 2011-05-19 00:06:34.000000000 -0400
35701 +++ linux-2.6.39.2/drivers/net/wan/lapbether.c 2011-05-22 19:36:31.000000000 -0400
35702 @@ -259,7 +259,7 @@ static int lapbeth_set_mac_address(struc
35703 }
35704
35705
35706 -static struct lapb_register_struct lapbeth_callbacks = {
35707 +static const struct lapb_register_struct lapbeth_callbacks = {
35708 .connect_confirmation = lapbeth_connected,
35709 .connect_indication = lapbeth_connected,
35710 .disconnect_confirmation = lapbeth_disconnected,
35711 diff -urNp linux-2.6.39.2/drivers/net/wan/x25_asy.c linux-2.6.39.2/drivers/net/wan/x25_asy.c
35712 --- linux-2.6.39.2/drivers/net/wan/x25_asy.c 2011-05-19 00:06:34.000000000 -0400
35713 +++ linux-2.6.39.2/drivers/net/wan/x25_asy.c 2011-05-22 19:36:31.000000000 -0400
35714 @@ -434,7 +434,7 @@ static void x25_asy_disconnected(struct
35715 netif_rx(skb);
35716 }
35717
35718 -static struct lapb_register_struct x25_asy_callbacks = {
35719 +static const struct lapb_register_struct x25_asy_callbacks = {
35720 .connect_confirmation = x25_asy_connected,
35721 .connect_indication = x25_asy_connected,
35722 .disconnect_confirmation = x25_asy_disconnected,
35723 diff -urNp linux-2.6.39.2/drivers/net/wimax/i2400m/usb-fw.c linux-2.6.39.2/drivers/net/wimax/i2400m/usb-fw.c
35724 --- linux-2.6.39.2/drivers/net/wimax/i2400m/usb-fw.c 2011-05-19 00:06:34.000000000 -0400
35725 +++ linux-2.6.39.2/drivers/net/wimax/i2400m/usb-fw.c 2011-05-22 19:36:31.000000000 -0400
35726 @@ -287,6 +287,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(stru
35727 int do_autopm = 1;
35728 DECLARE_COMPLETION_ONSTACK(notif_completion);
35729
35730 + pax_track_stack();
35731 +
35732 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
35733 i2400m, ack, ack_size);
35734 BUG_ON(_ack == i2400m->bm_ack_buf);
35735 diff -urNp linux-2.6.39.2/drivers/net/wireless/airo.c linux-2.6.39.2/drivers/net/wireless/airo.c
35736 --- linux-2.6.39.2/drivers/net/wireless/airo.c 2011-05-19 00:06:34.000000000 -0400
35737 +++ linux-2.6.39.2/drivers/net/wireless/airo.c 2011-05-22 19:36:31.000000000 -0400
35738 @@ -3001,6 +3001,8 @@ static void airo_process_scan_results (s
35739 BSSListElement * loop_net;
35740 BSSListElement * tmp_net;
35741
35742 + pax_track_stack();
35743 +
35744 /* Blow away current list of scan results */
35745 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
35746 list_move_tail (&loop_net->list, &ai->network_free_list);
35747 @@ -3792,6 +3794,8 @@ static u16 setup_card(struct airo_info *
35748 WepKeyRid wkr;
35749 int rc;
35750
35751 + pax_track_stack();
35752 +
35753 memset( &mySsid, 0, sizeof( mySsid ) );
35754 kfree (ai->flash);
35755 ai->flash = NULL;
35756 @@ -4760,6 +4764,8 @@ static int proc_stats_rid_open( struct i
35757 __le32 *vals = stats.vals;
35758 int len;
35759
35760 + pax_track_stack();
35761 +
35762 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35763 return -ENOMEM;
35764 data = file->private_data;
35765 @@ -5483,6 +5489,8 @@ static int proc_BSSList_open( struct ino
35766 /* If doLoseSync is not 1, we won't do a Lose Sync */
35767 int doLoseSync = -1;
35768
35769 + pax_track_stack();
35770 +
35771 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
35772 return -ENOMEM;
35773 data = file->private_data;
35774 @@ -7190,6 +7198,8 @@ static int airo_get_aplist(struct net_de
35775 int i;
35776 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
35777
35778 + pax_track_stack();
35779 +
35780 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
35781 if (!qual)
35782 return -ENOMEM;
35783 @@ -7750,6 +7760,8 @@ static void airo_read_wireless_stats(str
35784 CapabilityRid cap_rid;
35785 __le32 *vals = stats_rid.vals;
35786
35787 + pax_track_stack();
35788 +
35789 /* Get stats out of the card */
35790 clear_bit(JOB_WSTATS, &local->jobs);
35791 if (local->power.event) {
35792 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath5k/debug.c linux-2.6.39.2/drivers/net/wireless/ath/ath5k/debug.c
35793 --- linux-2.6.39.2/drivers/net/wireless/ath/ath5k/debug.c 2011-05-19 00:06:34.000000000 -0400
35794 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath5k/debug.c 2011-05-22 19:36:31.000000000 -0400
35795 @@ -204,6 +204,8 @@ static ssize_t read_file_beacon(struct f
35796 unsigned int v;
35797 u64 tsf;
35798
35799 + pax_track_stack();
35800 +
35801 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
35802 len += snprintf(buf+len, sizeof(buf)-len,
35803 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
35804 @@ -323,6 +325,8 @@ static ssize_t read_file_debug(struct fi
35805 unsigned int len = 0;
35806 unsigned int i;
35807
35808 + pax_track_stack();
35809 +
35810 len += snprintf(buf+len, sizeof(buf)-len,
35811 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
35812
35813 @@ -384,6 +388,8 @@ static ssize_t read_file_antenna(struct
35814 unsigned int i;
35815 unsigned int v;
35816
35817 + pax_track_stack();
35818 +
35819 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
35820 sc->ah->ah_ant_mode);
35821 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
35822 @@ -494,6 +500,8 @@ static ssize_t read_file_misc(struct fil
35823 unsigned int len = 0;
35824 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
35825
35826 + pax_track_stack();
35827 +
35828 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
35829 sc->bssidmask);
35830 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
35831 @@ -550,6 +558,8 @@ static ssize_t read_file_frameerrors(str
35832 unsigned int len = 0;
35833 int i;
35834
35835 + pax_track_stack();
35836 +
35837 len += snprintf(buf+len, sizeof(buf)-len,
35838 "RX\n---------------------\n");
35839 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
35840 @@ -667,6 +677,8 @@ static ssize_t read_file_ani(struct file
35841 char buf[700];
35842 unsigned int len = 0;
35843
35844 + pax_track_stack();
35845 +
35846 len += snprintf(buf+len, sizeof(buf)-len,
35847 "HW has PHY error counters:\t%s\n",
35848 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
35849 @@ -827,6 +839,8 @@ static ssize_t read_file_queue(struct fi
35850 struct ath5k_buf *bf, *bf0;
35851 int i, n;
35852
35853 + pax_track_stack();
35854 +
35855 len += snprintf(buf+len, sizeof(buf)-len,
35856 "available txbuffers: %d\n", sc->txbuf_len);
35857
35858 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_calib.c linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_calib.c
35859 --- linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-19 00:06:34.000000000 -0400
35860 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_calib.c 2011-05-22 19:36:31.000000000 -0400
35861 @@ -734,6 +734,8 @@ static void ar9003_hw_tx_iq_cal(struct a
35862 s32 i, j, ip, im, nmeasurement;
35863 u8 nchains = get_streams(common->tx_chainmask);
35864
35865 + pax_track_stack();
35866 +
35867 for (ip = 0; ip < MPASS; ip++) {
35868 REG_RMW_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_1,
35869 AR_PHY_TX_IQCAQL_CONTROL_1_IQCORR_I_Q_COFF_DELPT,
35870 @@ -856,6 +858,8 @@ static void ar9003_hw_tx_iq_cal_post_pro
35871 int i, ip, im, j;
35872 int nmeasurement;
35873
35874 + pax_track_stack();
35875 +
35876 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
35877 if (ah->txchainmask & (1 << i))
35878 num_chains++;
35879 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_paprd.c linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
35880 --- linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-19 00:06:34.000000000 -0400
35881 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath9k/ar9003_paprd.c 2011-05-22 19:36:31.000000000 -0400
35882 @@ -356,6 +356,8 @@ static bool create_pa_curve(u32 *data_L,
35883 int theta_low_bin = 0;
35884 int i;
35885
35886 + pax_track_stack();
35887 +
35888 /* disregard any bin that contains <= 16 samples */
35889 thresh_accum_cnt = 16;
35890 scale_factor = 5;
35891 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath9k/debug.c linux-2.6.39.2/drivers/net/wireless/ath/ath9k/debug.c
35892 --- linux-2.6.39.2/drivers/net/wireless/ath/ath9k/debug.c 2011-05-19 00:06:34.000000000 -0400
35893 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath9k/debug.c 2011-05-22 19:36:31.000000000 -0400
35894 @@ -335,6 +335,8 @@ static ssize_t read_file_interrupt(struc
35895 char buf[512];
35896 unsigned int len = 0;
35897
35898 + pax_track_stack();
35899 +
35900 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
35901 len += snprintf(buf + len, sizeof(buf) - len,
35902 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
35903 @@ -422,6 +424,8 @@ static ssize_t read_file_wiphy(struct fi
35904 u8 addr[ETH_ALEN];
35905 u32 tmp;
35906
35907 + pax_track_stack();
35908 +
35909 len += snprintf(buf + len, sizeof(buf) - len,
35910 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
35911 wiphy_name(sc->hw->wiphy),
35912 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc_drv_main.c linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc_drv_main.c
35913 --- linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-19 00:06:34.000000000 -0400
35914 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc_drv_main.c 2011-05-22 19:36:31.000000000 -0400
35915 @@ -737,6 +737,8 @@ static ssize_t read_file_tgt_stats(struc
35916 unsigned int len = 0;
35917 int ret = 0;
35918
35919 + pax_track_stack();
35920 +
35921 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
35922
35923 WMI_CMD(WMI_TGT_STATS_CMDID);
35924 @@ -782,6 +784,8 @@ static ssize_t read_file_xmit(struct fil
35925 char buf[512];
35926 unsigned int len = 0;
35927
35928 + pax_track_stack();
35929 +
35930 len += snprintf(buf + len, sizeof(buf) - len,
35931 "%20s : %10u\n", "Buffers queued",
35932 priv->debug.tx_stats.buf_queued);
35933 @@ -831,6 +835,8 @@ static ssize_t read_file_recv(struct fil
35934 char buf[512];
35935 unsigned int len = 0;
35936
35937 + pax_track_stack();
35938 +
35939 len += snprintf(buf + len, sizeof(buf) - len,
35940 "%20s : %10u\n", "SKBs allocated",
35941 priv->debug.rx_stats.skb_allocated);
35942 @@ -1816,7 +1822,7 @@ static void ath9k_htc_set_coverage_class
35943 mutex_unlock(&priv->mutex);
35944 }
35945
35946 -struct ieee80211_ops ath9k_htc_ops = {
35947 +const struct ieee80211_ops ath9k_htc_ops = {
35948 .tx = ath9k_htc_tx,
35949 .start = ath9k_htc_start,
35950 .stop = ath9k_htc_stop,
35951 diff -urNp linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc.h linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc.h
35952 --- linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc.h 2011-05-19 00:06:34.000000000 -0400
35953 +++ linux-2.6.39.2/drivers/net/wireless/ath/ath9k/htc.h 2011-05-22 19:36:31.000000000 -0400
35954 @@ -42,7 +42,7 @@
35955 #define TSF_TO_TU(_h, _l) \
35956 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
35957
35958 -extern struct ieee80211_ops ath9k_htc_ops;
35959 +extern const struct ieee80211_ops ath9k_htc_ops;
35960 extern int htc_modparam_nohwcrypt;
35961
35962 enum htc_phymode {
35963 diff -urNp linux-2.6.39.2/drivers/net/wireless/b43/debugfs.c linux-2.6.39.2/drivers/net/wireless/b43/debugfs.c
35964 --- linux-2.6.39.2/drivers/net/wireless/b43/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35965 +++ linux-2.6.39.2/drivers/net/wireless/b43/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35966 @@ -43,7 +43,7 @@ static struct dentry *rootdir;
35967 struct b43_debugfs_fops {
35968 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
35969 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
35970 - struct file_operations fops;
35971 + const struct file_operations fops;
35972 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
35973 size_t file_struct_offset;
35974 };
35975 diff -urNp linux-2.6.39.2/drivers/net/wireless/b43legacy/debugfs.c linux-2.6.39.2/drivers/net/wireless/b43legacy/debugfs.c
35976 --- linux-2.6.39.2/drivers/net/wireless/b43legacy/debugfs.c 2011-05-19 00:06:34.000000000 -0400
35977 +++ linux-2.6.39.2/drivers/net/wireless/b43legacy/debugfs.c 2011-05-22 19:36:31.000000000 -0400
35978 @@ -44,7 +44,7 @@ static struct dentry *rootdir;
35979 struct b43legacy_debugfs_fops {
35980 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
35981 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
35982 - struct file_operations fops;
35983 + const struct file_operations fops;
35984 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
35985 size_t file_struct_offset;
35986 /* Take wl->irq_lock before calling read/write? */
35987 diff -urNp linux-2.6.39.2/drivers/net/wireless/ipw2x00/ipw2100.c linux-2.6.39.2/drivers/net/wireless/ipw2x00/ipw2100.c
35988 --- linux-2.6.39.2/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-19 00:06:34.000000000 -0400
35989 +++ linux-2.6.39.2/drivers/net/wireless/ipw2x00/ipw2100.c 2011-05-22 19:36:31.000000000 -0400
35990 @@ -2100,6 +2100,8 @@ static int ipw2100_set_essid(struct ipw2
35991 int err;
35992 DECLARE_SSID_BUF(ssid);
35993
35994 + pax_track_stack();
35995 +
35996 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
35997
35998 if (ssid_len)
35999 @@ -5449,6 +5451,8 @@ static int ipw2100_set_key(struct ipw210
36000 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
36001 int err;
36002
36003 + pax_track_stack();
36004 +
36005 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
36006 idx, keylen, len);
36007
36008 diff -urNp linux-2.6.39.2/drivers/net/wireless/ipw2x00/libipw_rx.c linux-2.6.39.2/drivers/net/wireless/ipw2x00/libipw_rx.c
36009 --- linux-2.6.39.2/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-19 00:06:34.000000000 -0400
36010 +++ linux-2.6.39.2/drivers/net/wireless/ipw2x00/libipw_rx.c 2011-05-22 19:36:31.000000000 -0400
36011 @@ -1565,6 +1565,8 @@ static void libipw_process_probe_respons
36012 unsigned long flags;
36013 DECLARE_SSID_BUF(ssid);
36014
36015 + pax_track_stack();
36016 +
36017 LIBIPW_DEBUG_SCAN("'%s' (%pM"
36018 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
36019 print_ssid(ssid, info_element->data, info_element->len),
36020 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-3945.c linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-3945.c
36021 --- linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-19 00:06:34.000000000 -0400
36022 +++ linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-3945.c 2011-05-22 19:36:31.000000000 -0400
36023 @@ -2630,7 +2630,7 @@ static int iwl3945_load_bsm(struct iwl_p
36024 return 0;
36025 }
36026
36027 -static struct iwl_hcmd_ops iwl3945_hcmd = {
36028 +static const struct iwl_hcmd_ops iwl3945_hcmd = {
36029 .rxon_assoc = iwl3945_send_rxon_assoc,
36030 .commit_rxon = iwl3945_commit_rxon,
36031 };
36032 @@ -2675,7 +2675,7 @@ static const struct iwl_legacy_ops iwl39
36033 .manage_ibss_station = iwl3945_manage_ibss_station,
36034 };
36035
36036 -static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
36037 +static const struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
36038 .get_hcmd_size = iwl3945_get_hcmd_size,
36039 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
36040 .request_scan = iwl3945_request_scan,
36041 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.c linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.c
36042 --- linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-06-25 12:55:22.000000000 -0400
36043 +++ linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.c 2011-06-25 13:00:26.000000000 -0400
36044 @@ -1902,7 +1902,7 @@ static void iwl4965_rx_handler_setup(str
36045 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
36046 }
36047
36048 -static struct iwl_hcmd_ops iwl4965_hcmd = {
36049 +static const struct iwl_hcmd_ops iwl4965_hcmd = {
36050 .rxon_assoc = iwl4965_send_rxon_assoc,
36051 .commit_rxon = iwl4965_commit_rxon,
36052 .set_rxon_chain = iwl4965_set_rxon_chain,
36053 @@ -2054,7 +2054,7 @@ static void iwl4965_config_ap(struct iwl
36054 iwl4965_send_beacon_cmd(priv);
36055 }
36056
36057 -static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36058 +static const struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
36059 .get_hcmd_size = iwl4965_get_hcmd_size,
36060 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
36061 .request_scan = iwl4965_request_scan,
36062 @@ -2112,7 +2112,7 @@ static const struct iwl_legacy_ops iwl49
36063 .update_bcast_stations = iwl4965_update_bcast_stations,
36064 };
36065
36066 -struct ieee80211_ops iwl4965_hw_ops = {
36067 +const struct ieee80211_ops iwl4965_hw_ops = {
36068 .tx = iwl4965_mac_tx,
36069 .start = iwl4965_mac_start,
36070 .stop = iwl4965_mac_stop,
36071 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.h linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.h
36072 --- linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-19 00:06:34.000000000 -0400
36073 +++ linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-4965.h 2011-05-22 19:36:32.000000000 -0400
36074 @@ -70,7 +70,7 @@ extern struct iwl_cfg iwl4965_cfg;
36075
36076 extern struct iwl_mod_params iwl4965_mod_params;
36077
36078 -extern struct ieee80211_ops iwl4965_hw_ops;
36079 +extern const struct ieee80211_ops iwl4965_hw_ops;
36080
36081 /* tx queue */
36082 void iwl4965_free_tfds_in_queue(struct iwl_priv *priv,
36083 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-core.h linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-core.h
36084 --- linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-core.h 2011-06-25 12:55:22.000000000 -0400
36085 +++ linux-2.6.39.2/drivers/net/wireless/iwlegacy/iwl-core.h 2011-06-25 13:00:26.000000000 -0400
36086 @@ -150,7 +150,7 @@ struct iwl_lib_ops {
36087 int (*set_channel_switch)(struct iwl_priv *priv,
36088 struct ieee80211_channel_switch *ch_switch);
36089 /* power management */
36090 - struct iwl_apm_ops apm_ops;
36091 + const struct iwl_apm_ops apm_ops;
36092
36093 /* power */
36094 int (*send_tx_power) (struct iwl_priv *priv);
36095 @@ -160,12 +160,12 @@ struct iwl_lib_ops {
36096 struct iwl_eeprom_ops eeprom_ops;
36097
36098 /* temperature */
36099 - struct iwl_temp_ops temp_ops;
36100 + const struct iwl_temp_ops temp_ops;
36101 /* check for plcp health */
36102 bool (*check_plcp_health)(struct iwl_priv *priv,
36103 struct iwl_rx_packet *pkt);
36104
36105 - struct iwl_debugfs_ops debugfs_ops;
36106 + const struct iwl_debugfs_ops debugfs_ops;
36107
36108 };
36109
36110 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-6000.c linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-6000.c
36111 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-06-25 12:55:22.000000000 -0400
36112 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-6000.c 2011-06-25 13:00:26.000000000 -0400
36113 @@ -420,11 +420,11 @@ static struct iwl_lib_ops iwl6030_lib =
36114 }
36115 };
36116
36117 -static struct iwl_nic_ops iwl6050_nic_ops = {
36118 +static const struct iwl_nic_ops iwl6050_nic_ops = {
36119 .additional_nic_config = &iwl6050_additional_nic_config,
36120 };
36121
36122 -static struct iwl_nic_ops iwl6150_nic_ops = {
36123 +static const struct iwl_nic_ops iwl6150_nic_ops = {
36124 .additional_nic_config = &iwl6150_additional_nic_config,
36125 };
36126
36127 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn.h linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn.h
36128 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-19 00:06:34.000000000 -0400
36129 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn.h 2011-05-22 19:36:32.000000000 -0400
36130 @@ -109,9 +109,9 @@ extern struct iwl_cfg iwl230_bg_cfg;
36131 extern struct iwl_cfg iwl230_bgn_cfg;
36132
36133 extern struct iwl_mod_params iwlagn_mod_params;
36134 -extern struct iwl_hcmd_ops iwlagn_hcmd;
36135 -extern struct iwl_hcmd_ops iwlagn_bt_hcmd;
36136 -extern struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36137 +extern const struct iwl_hcmd_ops iwlagn_hcmd;
36138 +extern const struct iwl_hcmd_ops iwlagn_bt_hcmd;
36139 +extern const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils;
36140
36141 extern struct ieee80211_ops iwlagn_hw_ops;
36142 extern struct ieee80211_ops iwl4965_hw_ops;
36143 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
36144 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-06-25 12:55:22.000000000 -0400
36145 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c 2011-06-25 13:00:26.000000000 -0400
36146 @@ -355,7 +355,7 @@ static int iwlagn_set_pan_params(struct
36147 return ret;
36148 }
36149
36150 -struct iwl_hcmd_ops iwlagn_hcmd = {
36151 +const struct iwl_hcmd_ops iwlagn_hcmd = {
36152 .rxon_assoc = iwlagn_send_rxon_assoc,
36153 .commit_rxon = iwlagn_commit_rxon,
36154 .set_rxon_chain = iwlagn_set_rxon_chain,
36155 @@ -364,7 +364,7 @@ struct iwl_hcmd_ops iwlagn_hcmd = {
36156 .set_pan_params = iwlagn_set_pan_params,
36157 };
36158
36159 -struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36160 +const struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36161 .rxon_assoc = iwlagn_send_rxon_assoc,
36162 .commit_rxon = iwlagn_commit_rxon,
36163 .set_rxon_chain = iwlagn_set_rxon_chain,
36164 @@ -373,7 +373,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
36165 .set_pan_params = iwlagn_set_pan_params,
36166 };
36167
36168 -struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36169 +const struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
36170 .get_hcmd_size = iwlagn_get_hcmd_size,
36171 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
36172 .gain_computation = iwlagn_gain_computation,
36173 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-rs.c linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
36174 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-19 00:06:34.000000000 -0400
36175 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-agn-rs.c 2011-05-22 19:36:32.000000000 -0400
36176 @@ -883,6 +883,8 @@ static void rs_tx_status(void *priv_r, s
36177 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
36178 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
36179
36180 + pax_track_stack();
36181 +
36182 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
36183
36184 /* Treat uninitialized rate scaling data same as non-existing. */
36185 @@ -2894,6 +2896,8 @@ static void rs_fill_link_cmd(struct iwl_
36186 container_of(lq_sta, struct iwl_station_priv, lq_sta);
36187 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
36188
36189 + pax_track_stack();
36190 +
36191 /* Override starting rate (index 0) if needed for debug purposes */
36192 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
36193
36194 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-core.h linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-core.h
36195 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-core.h 2011-06-25 12:55:22.000000000 -0400
36196 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-core.h 2011-06-25 13:00:26.000000000 -0400
36197 @@ -198,28 +198,25 @@ struct iwl_lib_ops {
36198 int (*set_channel_switch)(struct iwl_priv *priv,
36199 struct ieee80211_channel_switch *ch_switch);
36200 /* power management */
36201 - struct iwl_apm_ops apm_ops;
36202 + const struct iwl_apm_ops apm_ops;
36203
36204 /* power */
36205 int (*send_tx_power) (struct iwl_priv *priv);
36206 void (*update_chain_flags)(struct iwl_priv *priv);
36207
36208 /* isr */
36209 - struct iwl_isr_ops isr_ops;
36210 + const struct iwl_isr_ops isr_ops;
36211
36212 /* eeprom operations (as defined in iwl-eeprom.h) */
36213 struct iwl_eeprom_ops eeprom_ops;
36214
36215 /* temperature */
36216 - struct iwl_temp_ops temp_ops;
36217 + const struct iwl_temp_ops temp_ops;
36218
36219 int (*txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36220 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
36221
36222 - struct iwl_debugfs_ops debugfs_ops;
36223 -
36224 - /* thermal throttling */
36225 - struct iwl_tt_ops tt_ops;
36226 + const struct iwl_debugfs_ops debugfs_ops;const struct iwl_tt_ops tt_ops;
36227 };
36228
36229 struct iwl_led_ops {
36230 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debugfs.c linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debugfs.c
36231 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-19 00:06:34.000000000 -0400
36232 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2011-05-22 19:36:32.000000000 -0400
36233 @@ -549,6 +549,8 @@ static ssize_t iwl_dbgfs_status_read(str
36234 int pos = 0;
36235 const size_t bufsz = sizeof(buf);
36236
36237 + pax_track_stack();
36238 +
36239 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
36240 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
36241 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
36242 @@ -681,6 +683,8 @@ static ssize_t iwl_dbgfs_qos_read(struct
36243 char buf[256 * NUM_IWL_RXON_CTX];
36244 const size_t bufsz = sizeof(buf);
36245
36246 + pax_track_stack();
36247 +
36248 for_each_context(priv, ctx) {
36249 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
36250 ctx->ctxid);
36251 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debug.h linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debug.h
36252 --- linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-19 00:06:34.000000000 -0400
36253 +++ linux-2.6.39.2/drivers/net/wireless/iwlwifi/iwl-debug.h 2011-05-22 19:36:32.000000000 -0400
36254 @@ -68,8 +68,8 @@ do {
36255 } while (0)
36256
36257 #else
36258 -#define IWL_DEBUG(__priv, level, fmt, args...)
36259 -#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
36260 +#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
36261 +#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
36262 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
36263 const void *p, u32 len)
36264 {}
36265 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/cfg80211.c linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/cfg80211.c
36266 --- linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
36267 +++ linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
36268 @@ -763,7 +763,7 @@ static int iwm_cfg80211_flush_pmksa(stru
36269 }
36270
36271
36272 -static struct cfg80211_ops iwm_cfg80211_ops = {
36273 +static const struct cfg80211_ops iwm_cfg80211_ops = {
36274 .change_virtual_intf = iwm_cfg80211_change_iface,
36275 .add_key = iwm_cfg80211_add_key,
36276 .get_key = iwm_cfg80211_get_key,
36277 diff -urNp linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/debugfs.c linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/debugfs.c
36278 --- linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36279 +++ linux-2.6.39.2/drivers/net/wireless/iwmc3200wifi/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36280 @@ -327,6 +327,8 @@ static ssize_t iwm_debugfs_fw_err_read(s
36281 int buf_len = 512;
36282 size_t len = 0;
36283
36284 + pax_track_stack();
36285 +
36286 if (*ppos != 0)
36287 return 0;
36288 if (count < sizeof(buf))
36289 diff -urNp linux-2.6.39.2/drivers/net/wireless/libertas/cfg.c linux-2.6.39.2/drivers/net/wireless/libertas/cfg.c
36290 --- linux-2.6.39.2/drivers/net/wireless/libertas/cfg.c 2011-05-19 00:06:34.000000000 -0400
36291 +++ linux-2.6.39.2/drivers/net/wireless/libertas/cfg.c 2011-05-22 19:36:32.000000000 -0400
36292 @@ -2003,7 +2003,7 @@ static int lbs_leave_ibss(struct wiphy *
36293 * Initialization
36294 */
36295
36296 -static struct cfg80211_ops lbs_cfg80211_ops = {
36297 +static const struct cfg80211_ops lbs_cfg80211_ops = {
36298 .set_channel = lbs_cfg_set_channel,
36299 .scan = lbs_cfg_scan,
36300 .connect = lbs_cfg_connect,
36301 diff -urNp linux-2.6.39.2/drivers/net/wireless/libertas/debugfs.c linux-2.6.39.2/drivers/net/wireless/libertas/debugfs.c
36302 --- linux-2.6.39.2/drivers/net/wireless/libertas/debugfs.c 2011-05-19 00:06:34.000000000 -0400
36303 +++ linux-2.6.39.2/drivers/net/wireless/libertas/debugfs.c 2011-05-22 19:36:32.000000000 -0400
36304 @@ -702,7 +702,7 @@ out_unlock:
36305 struct lbs_debugfs_files {
36306 const char *name;
36307 int perm;
36308 - struct file_operations fops;
36309 + const struct file_operations fops;
36310 };
36311
36312 static const struct lbs_debugfs_files debugfs_files[] = {
36313 diff -urNp linux-2.6.39.2/drivers/net/wireless/rndis_wlan.c linux-2.6.39.2/drivers/net/wireless/rndis_wlan.c
36314 --- linux-2.6.39.2/drivers/net/wireless/rndis_wlan.c 2011-05-19 00:06:34.000000000 -0400
36315 +++ linux-2.6.39.2/drivers/net/wireless/rndis_wlan.c 2011-05-22 19:36:32.000000000 -0400
36316 @@ -1277,7 +1277,7 @@ static int set_rts_threshold(struct usbn
36317
36318 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36319
36320 - if (rts_threshold < 0 || rts_threshold > 2347)
36321 + if (rts_threshold > 2347)
36322 rts_threshold = 2347;
36323
36324 tmp = cpu_to_le32(rts_threshold);
36325 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.c linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.c
36326 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.c 2011-05-19 00:06:34.000000000 -0400
36327 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.c 2011-05-22 19:36:32.000000000 -0400
36328 @@ -1869,7 +1869,7 @@ int rtl_pci_resume(struct pci_dev *pdev)
36329 }
36330 EXPORT_SYMBOL(rtl_pci_resume);
36331
36332 -struct rtl_intf_ops rtl_pci_ops = {
36333 +const struct rtl_intf_ops rtl_pci_ops = {
36334 .adapter_start = rtl_pci_start,
36335 .adapter_stop = rtl_pci_stop,
36336 .adapter_tx = rtl_pci_tx,
36337 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.h linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.h
36338 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.h 2011-05-19 00:06:34.000000000 -0400
36339 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/pci.h 2011-05-22 19:36:32.000000000 -0400
36340 @@ -234,7 +234,7 @@ struct rtl_pci_priv {
36341
36342 int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
36343
36344 -extern struct rtl_intf_ops rtl_pci_ops;
36345 +extern const struct rtl_intf_ops rtl_pci_ops;
36346
36347 int __devinit rtl_pci_probe(struct pci_dev *pdev,
36348 const struct pci_device_id *id);
36349 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
36350 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-19 00:06:34.000000000 -0400
36351 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c 2011-05-22 19:36:32.000000000 -0400
36352 @@ -827,6 +827,8 @@ static bool _rtl92c_phy_sw_chnl_step_by_
36353 u8 rfpath;
36354 u8 num_total_rfpath = rtlphy->num_total_rfpath;
36355
36356 + pax_track_stack();
36357 +
36358 precommoncmdcnt = 0;
36359 _rtl92c_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
36360 MAX_PRECMD_CNT,
36361 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
36362 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-19 00:06:34.000000000 -0400
36363 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c 2011-05-22 19:36:32.000000000 -0400
36364 @@ -96,7 +96,7 @@ void rtl92c_deinit_sw_vars(struct ieee80
36365 }
36366 }
36367
36368 -static struct rtl_hal_ops rtl8192ce_hal_ops = {
36369 +static const struct rtl_hal_ops rtl8192ce_hal_ops = {
36370 .init_sw_vars = rtl92c_init_sw_vars,
36371 .deinit_sw_vars = rtl92c_deinit_sw_vars,
36372 .read_eeprom_info = rtl92ce_read_eeprom_info,
36373 @@ -151,7 +151,7 @@ static struct rtl_mod_params rtl92ce_mod
36374 .sw_crypto = 0,
36375 };
36376
36377 -static struct rtl_hal_cfg rtl92ce_hal_cfg = {
36378 +static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
36379 .name = "rtl92c_pci",
36380 .fw_name = "rtlwifi/rtl8192cfw.bin",
36381 .ops = &rtl8192ce_hal_ops,
36382 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
36383 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-19 00:06:34.000000000 -0400
36384 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c 2011-05-22 19:36:32.000000000 -0400
36385 @@ -77,7 +77,7 @@ static void rtl92cu_deinit_sw_vars(struc
36386 }
36387 }
36388
36389 -static struct rtl_hal_ops rtl8192cu_hal_ops = {
36390 +static const struct rtl_hal_ops rtl8192cu_hal_ops = {
36391 .init_sw_vars = rtl92cu_init_sw_vars,
36392 .deinit_sw_vars = rtl92cu_deinit_sw_vars,
36393 .read_chip_version = rtl92c_read_chip_version,
36394 @@ -147,7 +147,7 @@ static struct rtl_hal_usbint_cfg rtl92cu
36395 .usb_mq_to_hwq = rtl8192cu_mq_to_hwq,
36396 };
36397
36398 -static struct rtl_hal_cfg rtl92cu_hal_cfg = {
36399 +static const struct rtl_hal_cfg rtl92cu_hal_cfg = {
36400 .name = "rtl92c_usb",
36401 .fw_name = "rtlwifi/rtl8192cufw.bin",
36402 .ops = &rtl8192cu_hal_ops,
36403 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/usb.c linux-2.6.39.2/drivers/net/wireless/rtlwifi/usb.c
36404 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/usb.c 2011-05-19 00:06:34.000000000 -0400
36405 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/usb.c 2011-05-22 19:36:32.000000000 -0400
36406 @@ -913,7 +913,7 @@ static bool rtl_usb_tx_chk_waitq_insert(
36407 return false;
36408 }
36409
36410 -static struct rtl_intf_ops rtl_usb_ops = {
36411 +static const struct rtl_intf_ops rtl_usb_ops = {
36412 .adapter_start = rtl_usb_start,
36413 .adapter_stop = rtl_usb_stop,
36414 .adapter_tx = rtl_usb_tx,
36415 diff -urNp linux-2.6.39.2/drivers/net/wireless/rtlwifi/wifi.h linux-2.6.39.2/drivers/net/wireless/rtlwifi/wifi.h
36416 --- linux-2.6.39.2/drivers/net/wireless/rtlwifi/wifi.h 2011-05-19 00:06:34.000000000 -0400
36417 +++ linux-2.6.39.2/drivers/net/wireless/rtlwifi/wifi.h 2011-05-22 19:36:32.000000000 -0400
36418 @@ -1447,7 +1447,7 @@ struct rtl_hal_cfg {
36419 u8 bar_id;
36420 char *name;
36421 char *fw_name;
36422 - struct rtl_hal_ops *ops;
36423 + const struct rtl_hal_ops *ops;
36424 struct rtl_mod_params *mod_params;
36425 struct rtl_hal_usbint_cfg *usb_interface_cfg;
36426
36427 @@ -1533,7 +1533,7 @@ struct rtl_priv {
36428 *intf_ops : for diff interrface usb/pcie
36429 */
36430 struct rtl_hal_cfg *cfg;
36431 - struct rtl_intf_ops *intf_ops;
36432 + const struct rtl_intf_ops *intf_ops;
36433
36434 /*this var will be set by set_bit,
36435 and was used to indicate status of
36436 diff -urNp linux-2.6.39.2/drivers/net/wireless/wl12xx/spi.c linux-2.6.39.2/drivers/net/wireless/wl12xx/spi.c
36437 --- linux-2.6.39.2/drivers/net/wireless/wl12xx/spi.c 2011-05-19 00:06:34.000000000 -0400
36438 +++ linux-2.6.39.2/drivers/net/wireless/wl12xx/spi.c 2011-05-22 19:36:32.000000000 -0400
36439 @@ -280,6 +280,8 @@ static void wl1271_spi_raw_write(struct
36440 u32 chunk_len;
36441 int i;
36442
36443 + pax_track_stack();
36444 +
36445 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
36446
36447 spi_message_init(&m);
36448 diff -urNp linux-2.6.39.2/drivers/net/xen-netback/interface.c linux-2.6.39.2/drivers/net/xen-netback/interface.c
36449 --- linux-2.6.39.2/drivers/net/xen-netback/interface.c 2011-05-19 00:06:34.000000000 -0400
36450 +++ linux-2.6.39.2/drivers/net/xen-netback/interface.c 2011-05-22 19:36:32.000000000 -0400
36451 @@ -273,7 +273,7 @@ static void xenvif_get_strings(struct ne
36452 }
36453 }
36454
36455 -static struct ethtool_ops xenvif_ethtool_ops = {
36456 +static const struct ethtool_ops xenvif_ethtool_ops = {
36457 .get_tx_csum = ethtool_op_get_tx_csum,
36458 .set_tx_csum = xenvif_set_tx_csum,
36459 .get_sg = ethtool_op_get_sg,
36460 diff -urNp linux-2.6.39.2/drivers/net/xilinx_emaclite.c linux-2.6.39.2/drivers/net/xilinx_emaclite.c
36461 --- linux-2.6.39.2/drivers/net/xilinx_emaclite.c 2011-05-19 00:06:34.000000000 -0400
36462 +++ linux-2.6.39.2/drivers/net/xilinx_emaclite.c 2011-05-22 19:36:32.000000000 -0400
36463 @@ -1085,7 +1085,7 @@ static bool get_bool(struct platform_dev
36464 }
36465 }
36466
36467 -static struct net_device_ops xemaclite_netdev_ops;
36468 +static const struct net_device_ops xemaclite_netdev_ops;
36469
36470 /**
36471 * xemaclite_of_probe - Probe method for the Emaclite device.
36472 @@ -1264,7 +1264,7 @@ xemaclite_poll_controller(struct net_dev
36473 }
36474 #endif
36475
36476 -static struct net_device_ops xemaclite_netdev_ops = {
36477 +static const struct net_device_ops xemaclite_netdev_ops = {
36478 .ndo_open = xemaclite_open,
36479 .ndo_stop = xemaclite_close,
36480 .ndo_start_xmit = xemaclite_send,
36481 diff -urNp linux-2.6.39.2/drivers/nfc/pn544.c linux-2.6.39.2/drivers/nfc/pn544.c
36482 --- linux-2.6.39.2/drivers/nfc/pn544.c 2011-05-19 00:06:34.000000000 -0400
36483 +++ linux-2.6.39.2/drivers/nfc/pn544.c 2011-05-22 19:36:32.000000000 -0400
36484 @@ -89,7 +89,7 @@ static ssize_t pn544_test(struct device
36485
36486 static int pn544_enable(struct pn544_info *info, int mode)
36487 {
36488 - struct pn544_nfc_platform_data *pdata;
36489 + const struct pn544_nfc_platform_data *pdata;
36490 struct i2c_client *client = info->i2c_dev;
36491
36492 int r;
36493 @@ -118,7 +118,7 @@ static int pn544_enable(struct pn544_inf
36494
36495 static void pn544_disable(struct pn544_info *info)
36496 {
36497 - struct pn544_nfc_platform_data *pdata;
36498 + const struct pn544_nfc_platform_data *pdata;
36499 struct i2c_client *client = info->i2c_dev;
36500
36501 pdata = client->dev.platform_data;
36502 @@ -509,7 +509,7 @@ static long pn544_ioctl(struct file *fil
36503 struct pn544_info *info = container_of(file->private_data,
36504 struct pn544_info, miscdev);
36505 struct i2c_client *client = info->i2c_dev;
36506 - struct pn544_nfc_platform_data *pdata;
36507 + const struct pn544_nfc_platform_data *pdata;
36508 unsigned int val;
36509 int r = 0;
36510
36511 @@ -715,7 +715,7 @@ static int __devinit pn544_probe(struct
36512 const struct i2c_device_id *id)
36513 {
36514 struct pn544_info *info;
36515 - struct pn544_nfc_platform_data *pdata;
36516 + const struct pn544_nfc_platform_data *pdata;
36517 int r = 0;
36518
36519 dev_dbg(&client->dev, "%s\n", __func__);
36520 diff -urNp linux-2.6.39.2/drivers/of/pdt.c linux-2.6.39.2/drivers/of/pdt.c
36521 --- linux-2.6.39.2/drivers/of/pdt.c 2011-05-19 00:06:34.000000000 -0400
36522 +++ linux-2.6.39.2/drivers/of/pdt.c 2011-05-22 19:36:32.000000000 -0400
36523 @@ -24,7 +24,7 @@
36524 #include <linux/of_pdt.h>
36525 #include <asm/prom.h>
36526
36527 -static struct of_pdt_ops *of_pdt_prom_ops __initdata;
36528 +static const struct of_pdt_ops *of_pdt_prom_ops;
36529
36530 void __initdata (*of_pdt_build_more)(struct device_node *dp,
36531 struct device_node ***nextp);
36532 diff -urNp linux-2.6.39.2/drivers/oprofile/buffer_sync.c linux-2.6.39.2/drivers/oprofile/buffer_sync.c
36533 --- linux-2.6.39.2/drivers/oprofile/buffer_sync.c 2011-06-25 12:55:22.000000000 -0400
36534 +++ linux-2.6.39.2/drivers/oprofile/buffer_sync.c 2011-06-25 13:00:26.000000000 -0400
36535 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *en
36536 if (cookie == NO_COOKIE)
36537 offset = pc;
36538 if (cookie == INVALID_COOKIE) {
36539 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36540 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36541 offset = pc;
36542 }
36543 if (cookie != last_cookie) {
36544 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct
36545 /* add userspace sample */
36546
36547 if (!mm) {
36548 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36549 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36550 return 0;
36551 }
36552
36553 cookie = lookup_dcookie(mm, s->eip, &offset);
36554
36555 if (cookie == INVALID_COOKIE) {
36556 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36557 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36558 return 0;
36559 }
36560
36561 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36562 /* ignore backtraces if failed to add a sample */
36563 if (state == sb_bt_start) {
36564 state = sb_bt_ignore;
36565 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36566 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36567 }
36568 }
36569 release_mm(mm);
36570 diff -urNp linux-2.6.39.2/drivers/oprofile/event_buffer.c linux-2.6.39.2/drivers/oprofile/event_buffer.c
36571 --- linux-2.6.39.2/drivers/oprofile/event_buffer.c 2011-05-19 00:06:34.000000000 -0400
36572 +++ linux-2.6.39.2/drivers/oprofile/event_buffer.c 2011-05-22 19:36:32.000000000 -0400
36573 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value
36574 }
36575
36576 if (buffer_pos == buffer_size) {
36577 - atomic_inc(&oprofile_stats.event_lost_overflow);
36578 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36579 return;
36580 }
36581
36582 diff -urNp linux-2.6.39.2/drivers/oprofile/oprof.c linux-2.6.39.2/drivers/oprofile/oprof.c
36583 --- linux-2.6.39.2/drivers/oprofile/oprof.c 2011-05-19 00:06:34.000000000 -0400
36584 +++ linux-2.6.39.2/drivers/oprofile/oprof.c 2011-05-22 19:36:32.000000000 -0400
36585 @@ -110,7 +110,7 @@ static void switch_worker(struct work_st
36586 if (oprofile_ops.switch_events())
36587 return;
36588
36589 - atomic_inc(&oprofile_stats.multiplex_counter);
36590 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36591 start_switch_worker();
36592 }
36593
36594 diff -urNp linux-2.6.39.2/drivers/oprofile/oprofilefs.c linux-2.6.39.2/drivers/oprofile/oprofilefs.c
36595 --- linux-2.6.39.2/drivers/oprofile/oprofilefs.c 2011-05-19 00:06:34.000000000 -0400
36596 +++ linux-2.6.39.2/drivers/oprofile/oprofilefs.c 2011-05-22 19:36:32.000000000 -0400
36597 @@ -186,7 +186,7 @@ static const struct file_operations atom
36598
36599
36600 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36601 - char const *name, atomic_t *val)
36602 + char const *name, atomic_unchecked_t *val)
36603 {
36604 return __oprofilefs_create_file(sb, root, name,
36605 &atomic_ro_fops, 0444, val);
36606 diff -urNp linux-2.6.39.2/drivers/oprofile/oprofile_stats.c linux-2.6.39.2/drivers/oprofile/oprofile_stats.c
36607 --- linux-2.6.39.2/drivers/oprofile/oprofile_stats.c 2011-05-19 00:06:34.000000000 -0400
36608 +++ linux-2.6.39.2/drivers/oprofile/oprofile_stats.c 2011-05-22 19:36:32.000000000 -0400
36609 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36610 cpu_buf->sample_invalid_eip = 0;
36611 }
36612
36613 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36614 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36615 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36616 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36617 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36618 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36619 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36620 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36621 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36622 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36623 }
36624
36625
36626 diff -urNp linux-2.6.39.2/drivers/oprofile/oprofile_stats.h linux-2.6.39.2/drivers/oprofile/oprofile_stats.h
36627 --- linux-2.6.39.2/drivers/oprofile/oprofile_stats.h 2011-05-19 00:06:34.000000000 -0400
36628 +++ linux-2.6.39.2/drivers/oprofile/oprofile_stats.h 2011-05-22 19:36:32.000000000 -0400
36629 @@ -13,11 +13,11 @@
36630 #include <asm/atomic.h>
36631
36632 struct oprofile_stat_struct {
36633 - atomic_t sample_lost_no_mm;
36634 - atomic_t sample_lost_no_mapping;
36635 - atomic_t bt_lost_no_mapping;
36636 - atomic_t event_lost_overflow;
36637 - atomic_t multiplex_counter;
36638 + atomic_unchecked_t sample_lost_no_mm;
36639 + atomic_unchecked_t sample_lost_no_mapping;
36640 + atomic_unchecked_t bt_lost_no_mapping;
36641 + atomic_unchecked_t event_lost_overflow;
36642 + atomic_unchecked_t multiplex_counter;
36643 };
36644
36645 extern struct oprofile_stat_struct oprofile_stats;
36646 diff -urNp linux-2.6.39.2/drivers/parisc/dino.c linux-2.6.39.2/drivers/parisc/dino.c
36647 --- linux-2.6.39.2/drivers/parisc/dino.c 2011-05-19 00:06:34.000000000 -0400
36648 +++ linux-2.6.39.2/drivers/parisc/dino.c 2011-05-22 19:36:32.000000000 -0400
36649 @@ -238,7 +238,7 @@ static int dino_cfg_write(struct pci_bus
36650 return 0;
36651 }
36652
36653 -static struct pci_ops dino_cfg_ops = {
36654 +static const struct pci_ops dino_cfg_ops = {
36655 .read = dino_cfg_read,
36656 .write = dino_cfg_write,
36657 };
36658 diff -urNp linux-2.6.39.2/drivers/parisc/lba_pci.c linux-2.6.39.2/drivers/parisc/lba_pci.c
36659 --- linux-2.6.39.2/drivers/parisc/lba_pci.c 2011-05-19 00:06:34.000000000 -0400
36660 +++ linux-2.6.39.2/drivers/parisc/lba_pci.c 2011-05-22 19:36:32.000000000 -0400
36661 @@ -468,7 +468,7 @@ static int elroy_cfg_write(struct pci_bu
36662 }
36663
36664
36665 -static struct pci_ops elroy_cfg_ops = {
36666 +static const struct pci_ops elroy_cfg_ops = {
36667 .read = elroy_cfg_read,
36668 .write = elroy_cfg_write,
36669 };
36670 @@ -541,7 +541,7 @@ static int mercury_cfg_write(struct pci_
36671 return 0;
36672 }
36673
36674 -static struct pci_ops mercury_cfg_ops = {
36675 +static const struct pci_ops mercury_cfg_ops = {
36676 .read = mercury_cfg_read,
36677 .write = mercury_cfg_write,
36678 };
36679 @@ -1405,7 +1405,7 @@ lba_driver_probe(struct parisc_device *d
36680 {
36681 struct lba_device *lba_dev;
36682 struct pci_bus *lba_bus;
36683 - struct pci_ops *cfg_ops;
36684 + const struct pci_ops *cfg_ops;
36685 u32 func_class;
36686 void *tmp_obj;
36687 char *version;
36688 diff -urNp linux-2.6.39.2/drivers/parport/procfs.c linux-2.6.39.2/drivers/parport/procfs.c
36689 --- linux-2.6.39.2/drivers/parport/procfs.c 2011-05-19 00:06:34.000000000 -0400
36690 +++ linux-2.6.39.2/drivers/parport/procfs.c 2011-05-22 19:36:32.000000000 -0400
36691 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *t
36692
36693 *ppos += len;
36694
36695 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36696 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36697 }
36698
36699 #ifdef CONFIG_PARPORT_1284
36700 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table
36701
36702 *ppos += len;
36703
36704 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36705 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36706 }
36707 #endif /* IEEE1284.3 support. */
36708
36709 diff -urNp linux-2.6.39.2/drivers/pci/access.c linux-2.6.39.2/drivers/pci/access.c
36710 --- linux-2.6.39.2/drivers/pci/access.c 2011-05-19 00:06:34.000000000 -0400
36711 +++ linux-2.6.39.2/drivers/pci/access.c 2011-05-22 19:36:32.000000000 -0400
36712 @@ -74,9 +74,9 @@ EXPORT_SYMBOL(pci_bus_write_config_dword
36713 *
36714 * Return previous raw operations
36715 */
36716 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
36717 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops)
36718 {
36719 - struct pci_ops *old_ops;
36720 + const struct pci_ops *old_ops;
36721 unsigned long flags;
36722
36723 raw_spin_lock_irqsave(&pci_lock, flags);
36724 diff -urNp linux-2.6.39.2/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.39.2/drivers/pci/hotplug/acpiphp_glue.c
36725 --- linux-2.6.39.2/drivers/pci/hotplug/acpiphp_glue.c 2011-05-19 00:06:34.000000000 -0400
36726 +++ linux-2.6.39.2/drivers/pci/hotplug/acpiphp_glue.c 2011-05-22 19:36:32.000000000 -0400
36727 @@ -110,7 +110,7 @@ static int post_dock_fixups(struct notif
36728 }
36729
36730
36731 -static struct acpi_dock_ops acpiphp_dock_ops = {
36732 +static const struct acpi_dock_ops acpiphp_dock_ops = {
36733 .handler = handle_hotplug_event_func,
36734 };
36735
36736 diff -urNp linux-2.6.39.2/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.39.2/drivers/pci/hotplug/cpqphp_nvram.c
36737 --- linux-2.6.39.2/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-19 00:06:34.000000000 -0400
36738 +++ linux-2.6.39.2/drivers/pci/hotplug/cpqphp_nvram.c 2011-05-22 19:36:32.000000000 -0400
36739 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_
36740
36741 void compaq_nvram_init (void __iomem *rom_start)
36742 {
36743 +
36744 +#ifndef CONFIG_PAX_KERNEXEC
36745 if (rom_start) {
36746 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36747 }
36748 +#endif
36749 +
36750 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36751
36752 /* initialize our int15 lock */
36753 diff -urNp linux-2.6.39.2/drivers/pci/hotplug/shpchp.h linux-2.6.39.2/drivers/pci/hotplug/shpchp.h
36754 --- linux-2.6.39.2/drivers/pci/hotplug/shpchp.h 2011-05-19 00:06:34.000000000 -0400
36755 +++ linux-2.6.39.2/drivers/pci/hotplug/shpchp.h 2011-05-22 19:36:32.000000000 -0400
36756 @@ -86,7 +86,7 @@ struct slot {
36757 u8 presence_save;
36758 u8 pwr_save;
36759 struct controller *ctrl;
36760 - struct hpc_ops *hpc_ops;
36761 + const struct hpc_ops *hpc_ops;
36762 struct hotplug_slot *hotplug_slot;
36763 struct list_head slot_list;
36764 struct delayed_work work; /* work for button event */
36765 @@ -107,7 +107,7 @@ struct controller {
36766 int slot_num_inc; /* 1 or -1 */
36767 struct pci_dev *pci_dev;
36768 struct list_head slot_list;
36769 - struct hpc_ops *hpc_ops;
36770 + const struct hpc_ops *hpc_ops;
36771 wait_queue_head_t queue; /* sleep & wake process */
36772 u8 slot_device_offset;
36773 u32 pcix_misc2_reg; /* for amd pogo errata */
36774 diff -urNp linux-2.6.39.2/drivers/pci/hotplug/shpchp_hpc.c linux-2.6.39.2/drivers/pci/hotplug/shpchp_hpc.c
36775 --- linux-2.6.39.2/drivers/pci/hotplug/shpchp_hpc.c 2011-05-19 00:06:34.000000000 -0400
36776 +++ linux-2.6.39.2/drivers/pci/hotplug/shpchp_hpc.c 2011-05-22 19:36:32.000000000 -0400
36777 @@ -910,7 +910,7 @@ static int shpc_get_max_bus_speed(struct
36778 return retval;
36779 }
36780
36781 -static struct hpc_ops shpchp_hpc_ops = {
36782 +static const struct hpc_ops shpchp_hpc_ops = {
36783 .power_on_slot = hpc_power_on_slot,
36784 .slot_enable = hpc_slot_enable,
36785 .slot_disable = hpc_slot_disable,
36786 diff -urNp linux-2.6.39.2/drivers/pci/intel-iommu.c linux-2.6.39.2/drivers/pci/intel-iommu.c
36787 --- linux-2.6.39.2/drivers/pci/intel-iommu.c 2011-06-25 12:55:22.000000000 -0400
36788 +++ linux-2.6.39.2/drivers/pci/intel-iommu.c 2011-06-25 13:00:26.000000000 -0400
36789 @@ -393,7 +393,7 @@ static int intel_iommu_strict;
36790 static DEFINE_SPINLOCK(device_domain_lock);
36791 static LIST_HEAD(device_domain_list);
36792
36793 -static struct iommu_ops intel_iommu_ops;
36794 +static const struct iommu_ops intel_iommu_ops;
36795
36796 static int __init intel_iommu_setup(char *str)
36797 {
36798 @@ -2964,7 +2964,7 @@ static int intel_mapping_error(struct de
36799 return !dma_addr;
36800 }
36801
36802 -struct dma_map_ops intel_dma_ops = {
36803 +const struct dma_map_ops intel_dma_ops = {
36804 .alloc_coherent = intel_alloc_coherent,
36805 .free_coherent = intel_free_coherent,
36806 .map_sg = intel_map_sg,
36807 @@ -3761,7 +3761,7 @@ static int intel_iommu_domain_has_cap(st
36808 return 0;
36809 }
36810
36811 -static struct iommu_ops intel_iommu_ops = {
36812 +static const struct iommu_ops intel_iommu_ops = {
36813 .domain_init = intel_iommu_domain_init,
36814 .domain_destroy = intel_iommu_domain_destroy,
36815 .attach_dev = intel_iommu_attach_device,
36816 diff -urNp linux-2.6.39.2/drivers/pci/pci-acpi.c linux-2.6.39.2/drivers/pci/pci-acpi.c
36817 --- linux-2.6.39.2/drivers/pci/pci-acpi.c 2011-05-19 00:06:34.000000000 -0400
36818 +++ linux-2.6.39.2/drivers/pci/pci-acpi.c 2011-05-22 19:36:32.000000000 -0400
36819 @@ -332,7 +332,7 @@ static int acpi_pci_run_wake(struct pci_
36820 return 0;
36821 }
36822
36823 -static struct pci_platform_pm_ops acpi_pci_platform_pm = {
36824 +static const struct pci_platform_pm_ops acpi_pci_platform_pm = {
36825 .is_manageable = acpi_pci_power_manageable,
36826 .set_state = acpi_pci_set_power_state,
36827 .choose_state = acpi_pci_choose_state,
36828 diff -urNp linux-2.6.39.2/drivers/pci/pci.c linux-2.6.39.2/drivers/pci/pci.c
36829 --- linux-2.6.39.2/drivers/pci/pci.c 2011-05-19 00:06:34.000000000 -0400
36830 +++ linux-2.6.39.2/drivers/pci/pci.c 2011-05-22 19:36:32.000000000 -0400
36831 @@ -480,9 +480,9 @@ pci_restore_bars(struct pci_dev *dev)
36832 pci_update_resource(dev, i);
36833 }
36834
36835 -static struct pci_platform_pm_ops *pci_platform_pm;
36836 +static const struct pci_platform_pm_ops *pci_platform_pm;
36837
36838 -int pci_set_platform_pm(struct pci_platform_pm_ops *ops)
36839 +int pci_set_platform_pm(const struct pci_platform_pm_ops *ops)
36840 {
36841 if (!ops->is_manageable || !ops->set_state || !ops->choose_state
36842 || !ops->sleep_wake || !ops->can_wakeup)
36843 diff -urNp linux-2.6.39.2/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.39.2/drivers/pci/pcie/aer/aerdrv_core.c
36844 --- linux-2.6.39.2/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-19 00:06:34.000000000 -0400
36845 +++ linux-2.6.39.2/drivers/pci/pcie/aer/aerdrv_core.c 2011-05-22 19:36:32.000000000 -0400
36846 @@ -239,7 +239,7 @@ static bool find_source_device(struct pc
36847 static int report_error_detected(struct pci_dev *dev, void *data)
36848 {
36849 pci_ers_result_t vote;
36850 - struct pci_error_handlers *err_handler;
36851 + const struct pci_error_handlers *err_handler;
36852 struct aer_broadcast_data *result_data;
36853 result_data = (struct aer_broadcast_data *) data;
36854
36855 @@ -273,7 +273,7 @@ static int report_error_detected(struct
36856 static int report_mmio_enabled(struct pci_dev *dev, void *data)
36857 {
36858 pci_ers_result_t vote;
36859 - struct pci_error_handlers *err_handler;
36860 + const struct pci_error_handlers *err_handler;
36861 struct aer_broadcast_data *result_data;
36862 result_data = (struct aer_broadcast_data *) data;
36863
36864 @@ -291,7 +291,7 @@ static int report_mmio_enabled(struct pc
36865 static int report_slot_reset(struct pci_dev *dev, void *data)
36866 {
36867 pci_ers_result_t vote;
36868 - struct pci_error_handlers *err_handler;
36869 + const struct pci_error_handlers *err_handler;
36870 struct aer_broadcast_data *result_data;
36871 result_data = (struct aer_broadcast_data *) data;
36872
36873 @@ -308,7 +308,7 @@ static int report_slot_reset(struct pci_
36874
36875 static int report_resume(struct pci_dev *dev, void *data)
36876 {
36877 - struct pci_error_handlers *err_handler;
36878 + const struct pci_error_handlers *err_handler;
36879
36880 dev->error_state = pci_channel_io_normal;
36881
36882 diff -urNp linux-2.6.39.2/drivers/pci/pcie/aer/aer_inject.c linux-2.6.39.2/drivers/pci/pcie/aer/aer_inject.c
36883 --- linux-2.6.39.2/drivers/pci/pcie/aer/aer_inject.c 2011-05-19 00:06:34.000000000 -0400
36884 +++ linux-2.6.39.2/drivers/pci/pcie/aer/aer_inject.c 2011-05-22 19:36:32.000000000 -0400
36885 @@ -64,7 +64,7 @@ struct aer_error {
36886 struct pci_bus_ops {
36887 struct list_head list;
36888 struct pci_bus *bus;
36889 - struct pci_ops *ops;
36890 + const struct pci_ops *ops;
36891 };
36892
36893 static LIST_HEAD(einjected);
36894 @@ -110,7 +110,7 @@ static struct aer_error *__find_aer_erro
36895 }
36896
36897 /* inject_lock must be held before calling */
36898 -static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36899 +static const struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
36900 {
36901 struct pci_bus_ops *bus_ops;
36902
36903 @@ -187,7 +187,7 @@ static int pci_read_aer(struct pci_bus *
36904 u32 *sim;
36905 struct aer_error *err;
36906 unsigned long flags;
36907 - struct pci_ops *ops;
36908 + const struct pci_ops *ops;
36909 int domain;
36910
36911 spin_lock_irqsave(&inject_lock, flags);
36912 @@ -219,7 +219,7 @@ int pci_write_aer(struct pci_bus *bus, u
36913 struct aer_error *err;
36914 unsigned long flags;
36915 int rw1cs;
36916 - struct pci_ops *ops;
36917 + const struct pci_ops *ops;
36918 int domain;
36919
36920 spin_lock_irqsave(&inject_lock, flags);
36921 @@ -254,7 +254,7 @@ static struct pci_ops pci_ops_aer = {
36922
36923 static void pci_bus_ops_init(struct pci_bus_ops *bus_ops,
36924 struct pci_bus *bus,
36925 - struct pci_ops *ops)
36926 + const struct pci_ops *ops)
36927 {
36928 INIT_LIST_HEAD(&bus_ops->list);
36929 bus_ops->bus = bus;
36930 @@ -263,7 +263,7 @@ static void pci_bus_ops_init(struct pci_
36931
36932 static int pci_bus_set_aer_ops(struct pci_bus *bus)
36933 {
36934 - struct pci_ops *ops;
36935 + const struct pci_ops *ops;
36936 struct pci_bus_ops *bus_ops;
36937 unsigned long flags;
36938
36939 diff -urNp linux-2.6.39.2/drivers/pci/pcie/aspm.c linux-2.6.39.2/drivers/pci/pcie/aspm.c
36940 --- linux-2.6.39.2/drivers/pci/pcie/aspm.c 2011-05-19 00:06:34.000000000 -0400
36941 +++ linux-2.6.39.2/drivers/pci/pcie/aspm.c 2011-05-22 19:36:32.000000000 -0400
36942 @@ -27,9 +27,9 @@
36943 #define MODULE_PARAM_PREFIX "pcie_aspm."
36944
36945 /* Note: those are not register definitions */
36946 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36947 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36948 -#define ASPM_STATE_L1 (4) /* L1 state */
36949 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36950 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36951 +#define ASPM_STATE_L1 (4U) /* L1 state */
36952 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36953 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36954
36955 diff -urNp linux-2.6.39.2/drivers/pci/pci.h linux-2.6.39.2/drivers/pci/pci.h
36956 --- linux-2.6.39.2/drivers/pci/pci.h 2011-05-19 00:06:34.000000000 -0400
36957 +++ linux-2.6.39.2/drivers/pci/pci.h 2011-05-22 19:36:32.000000000 -0400
36958 @@ -65,7 +65,7 @@ struct pci_platform_pm_ops {
36959 int (*run_wake)(struct pci_dev *dev, bool enable);
36960 };
36961
36962 -extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
36963 +extern int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
36964 extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
36965 extern void pci_disable_enabled_device(struct pci_dev *dev);
36966 extern int pci_finish_runtime_suspend(struct pci_dev *dev);
36967 diff -urNp linux-2.6.39.2/drivers/pci/probe.c linux-2.6.39.2/drivers/pci/probe.c
36968 --- linux-2.6.39.2/drivers/pci/probe.c 2011-05-19 00:06:34.000000000 -0400
36969 +++ linux-2.6.39.2/drivers/pci/probe.c 2011-05-22 19:36:32.000000000 -0400
36970 @@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(
36971 return ret;
36972 }
36973
36974 -static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
36975 +static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
36976 struct device_attribute *attr,
36977 char *buf)
36978 {
36979 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
36980 }
36981
36982 -static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
36983 +static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
36984 struct device_attribute *attr,
36985 char *buf)
36986 {
36987 @@ -165,7 +165,7 @@ int __pci_read_base(struct pci_dev *dev,
36988 u32 l, sz, mask;
36989 u16 orig_cmd;
36990
36991 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36992 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36993
36994 if (!dev->mmio_always_on) {
36995 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36996 @@ -1407,7 +1407,7 @@ unsigned int __devinit pci_scan_child_bu
36997 }
36998
36999 struct pci_bus * pci_create_bus(struct device *parent,
37000 - int bus, struct pci_ops *ops, void *sysdata)
37001 + int bus, const struct pci_ops *ops, void *sysdata)
37002 {
37003 int error;
37004 struct pci_bus *b, *b2;
37005 @@ -1483,7 +1483,7 @@ err_out:
37006 }
37007
37008 struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,
37009 - int bus, struct pci_ops *ops, void *sysdata)
37010 + int bus, const struct pci_ops *ops, void *sysdata)
37011 {
37012 struct pci_bus *b;
37013
37014 diff -urNp linux-2.6.39.2/drivers/pci/proc.c linux-2.6.39.2/drivers/pci/proc.c
37015 --- linux-2.6.39.2/drivers/pci/proc.c 2011-05-19 00:06:34.000000000 -0400
37016 +++ linux-2.6.39.2/drivers/pci/proc.c 2011-05-22 19:41:37.000000000 -0400
37017 @@ -476,7 +476,16 @@ static const struct file_operations proc
37018 static int __init pci_proc_init(void)
37019 {
37020 struct pci_dev *dev = NULL;
37021 +
37022 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37023 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37024 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37025 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37026 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37027 +#endif
37028 +#else
37029 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37030 +#endif
37031 proc_create("devices", 0, proc_bus_pci_dir,
37032 &proc_bus_pci_dev_operations);
37033 proc_initialized = 1;
37034 diff -urNp linux-2.6.39.2/drivers/pci/xen-pcifront.c linux-2.6.39.2/drivers/pci/xen-pcifront.c
37035 --- linux-2.6.39.2/drivers/pci/xen-pcifront.c 2011-05-19 00:06:34.000000000 -0400
37036 +++ linux-2.6.39.2/drivers/pci/xen-pcifront.c 2011-05-22 19:36:32.000000000 -0400
37037 @@ -187,6 +187,8 @@ static int pcifront_bus_read(struct pci_
37038 struct pcifront_sd *sd = bus->sysdata;
37039 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37040
37041 + pax_track_stack();
37042 +
37043 if (verbose_request)
37044 dev_info(&pdev->xdev->dev,
37045 "read dev=%04x:%02x:%02x.%01x - offset %x size %d\n",
37046 @@ -226,6 +228,8 @@ static int pcifront_bus_write(struct pci
37047 struct pcifront_sd *sd = bus->sysdata;
37048 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37049
37050 + pax_track_stack();
37051 +
37052 if (verbose_request)
37053 dev_info(&pdev->xdev->dev,
37054 "write dev=%04x:%02x:%02x.%01x - "
37055 @@ -236,7 +240,7 @@ static int pcifront_bus_write(struct pci
37056 return errno_to_pcibios_err(do_pci_op(pdev, &op));
37057 }
37058
37059 -struct pci_ops pcifront_bus_ops = {
37060 +const struct pci_ops pcifront_bus_ops = {
37061 .read = pcifront_bus_read,
37062 .write = pcifront_bus_write,
37063 };
37064 @@ -258,6 +262,8 @@ static int pci_frontend_enable_msix(stru
37065 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37066 struct msi_desc *entry;
37067
37068 + pax_track_stack();
37069 +
37070 if (nvec > SH_INFO_MAX_VEC) {
37071 dev_err(&dev->dev, "too much vector for pci frontend: %x."
37072 " Increase SH_INFO_MAX_VEC.\n", nvec);
37073 @@ -309,6 +315,8 @@ static void pci_frontend_disable_msix(st
37074 struct pcifront_sd *sd = dev->bus->sysdata;
37075 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37076
37077 + pax_track_stack();
37078 +
37079 err = do_pci_op(pdev, &op);
37080
37081 /* What should do for error ? */
37082 @@ -328,6 +336,8 @@ static int pci_frontend_enable_msi(struc
37083 struct pcifront_sd *sd = dev->bus->sysdata;
37084 struct pcifront_device *pdev = pcifront_get_pdev(sd);
37085
37086 + pax_track_stack();
37087 +
37088 err = do_pci_op(pdev, &op);
37089 if (likely(!err)) {
37090 vector[0] = op.value;
37091 @@ -368,7 +378,7 @@ static void pci_frontend_disable_msi(str
37092 printk(KERN_DEBUG "get fake response frombackend\n");
37093 }
37094
37095 -static struct xen_pci_frontend_ops pci_frontend_ops = {
37096 +static const struct xen_pci_frontend_ops pci_frontend_ops = {
37097 .enable_msi = pci_frontend_enable_msi,
37098 .disable_msi = pci_frontend_disable_msi,
37099 .enable_msix = pci_frontend_enable_msix,
37100 diff -urNp linux-2.6.39.2/drivers/pcmcia/at91_cf.c linux-2.6.39.2/drivers/pcmcia/at91_cf.c
37101 --- linux-2.6.39.2/drivers/pcmcia/at91_cf.c 2011-05-19 00:06:34.000000000 -0400
37102 +++ linux-2.6.39.2/drivers/pcmcia/at91_cf.c 2011-05-22 19:36:32.000000000 -0400
37103 @@ -203,7 +203,7 @@ at91_cf_set_mem_map(struct pcmcia_socket
37104 return 0;
37105 }
37106
37107 -static struct pccard_operations at91_cf_ops = {
37108 +static const struct pccard_operations at91_cf_ops = {
37109 .init = at91_cf_ss_init,
37110 .suspend = at91_cf_ss_suspend,
37111 .get_status = at91_cf_get_status,
37112 diff -urNp linux-2.6.39.2/drivers/pcmcia/bfin_cf_pcmcia.c linux-2.6.39.2/drivers/pcmcia/bfin_cf_pcmcia.c
37113 --- linux-2.6.39.2/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37114 +++ linux-2.6.39.2/drivers/pcmcia/bfin_cf_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37115 @@ -184,7 +184,7 @@ bfin_cf_set_mem_map(struct pcmcia_socket
37116 return 0;
37117 }
37118
37119 -static struct pccard_operations bfin_cf_ops = {
37120 +static const struct pccard_operations bfin_cf_ops = {
37121 .init = bfin_cf_ss_init,
37122 .suspend = bfin_cf_ss_suspend,
37123 .get_status = bfin_cf_get_status,
37124 diff -urNp linux-2.6.39.2/drivers/pcmcia/db1xxx_ss.c linux-2.6.39.2/drivers/pcmcia/db1xxx_ss.c
37125 --- linux-2.6.39.2/drivers/pcmcia/db1xxx_ss.c 2011-05-19 00:06:34.000000000 -0400
37126 +++ linux-2.6.39.2/drivers/pcmcia/db1xxx_ss.c 2011-05-22 19:36:32.000000000 -0400
37127 @@ -384,7 +384,7 @@ static int au1x00_pcmcia_set_mem_map(str
37128 return 0;
37129 }
37130
37131 -static struct pccard_operations db1x_pcmcia_operations = {
37132 +static const struct pccard_operations db1x_pcmcia_operations = {
37133 .init = db1x_pcmcia_sock_init,
37134 .suspend = db1x_pcmcia_sock_suspend,
37135 .get_status = db1x_pcmcia_get_status,
37136 diff -urNp linux-2.6.39.2/drivers/pcmcia/electra_cf.c linux-2.6.39.2/drivers/pcmcia/electra_cf.c
37137 --- linux-2.6.39.2/drivers/pcmcia/electra_cf.c 2011-05-19 00:06:34.000000000 -0400
37138 +++ linux-2.6.39.2/drivers/pcmcia/electra_cf.c 2011-05-22 19:36:32.000000000 -0400
37139 @@ -173,7 +173,7 @@ static int electra_cf_set_mem_map(struct
37140 return 0;
37141 }
37142
37143 -static struct pccard_operations electra_cf_ops = {
37144 +static const struct pccard_operations electra_cf_ops = {
37145 .init = electra_cf_ss_init,
37146 .get_status = electra_cf_get_status,
37147 .set_socket = electra_cf_set_socket,
37148 diff -urNp linux-2.6.39.2/drivers/pcmcia/m32r_cfc.c linux-2.6.39.2/drivers/pcmcia/m32r_cfc.c
37149 --- linux-2.6.39.2/drivers/pcmcia/m32r_cfc.c 2011-05-19 00:06:34.000000000 -0400
37150 +++ linux-2.6.39.2/drivers/pcmcia/m32r_cfc.c 2011-05-22 19:36:32.000000000 -0400
37151 @@ -674,7 +674,7 @@ static int pcc_init(struct pcmcia_socket
37152 return 0;
37153 }
37154
37155 -static struct pccard_operations pcc_operations = {
37156 +static const struct pccard_operations pcc_operations = {
37157 .init = pcc_init,
37158 .get_status = pcc_get_status,
37159 .set_socket = pcc_set_socket,
37160 diff -urNp linux-2.6.39.2/drivers/pcmcia/m32r_pcc.c linux-2.6.39.2/drivers/pcmcia/m32r_pcc.c
37161 --- linux-2.6.39.2/drivers/pcmcia/m32r_pcc.c 2011-05-19 00:06:34.000000000 -0400
37162 +++ linux-2.6.39.2/drivers/pcmcia/m32r_pcc.c 2011-05-22 19:36:32.000000000 -0400
37163 @@ -652,7 +652,7 @@ static int pcc_init(struct pcmcia_socket
37164 return 0;
37165 }
37166
37167 -static struct pccard_operations pcc_operations = {
37168 +static const struct pccard_operations pcc_operations = {
37169 .init = pcc_init,
37170 .get_status = pcc_get_status,
37171 .set_socket = pcc_set_socket,
37172 diff -urNp linux-2.6.39.2/drivers/pcmcia/m8xx_pcmcia.c linux-2.6.39.2/drivers/pcmcia/m8xx_pcmcia.c
37173 --- linux-2.6.39.2/drivers/pcmcia/m8xx_pcmcia.c 2011-05-19 00:06:34.000000000 -0400
37174 +++ linux-2.6.39.2/drivers/pcmcia/m8xx_pcmcia.c 2011-05-22 19:36:32.000000000 -0400
37175 @@ -1139,7 +1139,7 @@ static int m8xx_sock_suspend(struct pcmc
37176 return m8xx_set_socket(sock, &dead_socket);
37177 }
37178
37179 -static struct pccard_operations m8xx_services = {
37180 +static const struct pccard_operations m8xx_services = {
37181 .init = m8xx_sock_init,
37182 .suspend = m8xx_sock_suspend,
37183 .get_status = m8xx_get_status,
37184 diff -urNp linux-2.6.39.2/drivers/pcmcia/omap_cf.c linux-2.6.39.2/drivers/pcmcia/omap_cf.c
37185 --- linux-2.6.39.2/drivers/pcmcia/omap_cf.c 2011-05-19 00:06:34.000000000 -0400
37186 +++ linux-2.6.39.2/drivers/pcmcia/omap_cf.c 2011-05-22 19:36:32.000000000 -0400
37187 @@ -185,7 +185,7 @@ omap_cf_set_mem_map(struct pcmcia_socket
37188 return 0;
37189 }
37190
37191 -static struct pccard_operations omap_cf_ops = {
37192 +static const struct pccard_operations omap_cf_ops = {
37193 .init = omap_cf_ss_init,
37194 .suspend = omap_cf_ss_suspend,
37195 .get_status = omap_cf_get_status,
37196 diff -urNp linux-2.6.39.2/drivers/pcmcia/rsrc_iodyn.c linux-2.6.39.2/drivers/pcmcia/rsrc_iodyn.c
37197 --- linux-2.6.39.2/drivers/pcmcia/rsrc_iodyn.c 2011-05-19 00:06:34.000000000 -0400
37198 +++ linux-2.6.39.2/drivers/pcmcia/rsrc_iodyn.c 2011-05-22 19:36:32.000000000 -0400
37199 @@ -161,7 +161,7 @@ static int iodyn_find_io(struct pcmcia_s
37200 }
37201
37202
37203 -struct pccard_resource_ops pccard_iodyn_ops = {
37204 +const struct pccard_resource_ops pccard_iodyn_ops = {
37205 .validate_mem = NULL,
37206 .find_io = iodyn_find_io,
37207 .find_mem = NULL,
37208 diff -urNp linux-2.6.39.2/drivers/pcmcia/rsrc_mgr.c linux-2.6.39.2/drivers/pcmcia/rsrc_mgr.c
37209 --- linux-2.6.39.2/drivers/pcmcia/rsrc_mgr.c 2011-05-19 00:06:34.000000000 -0400
37210 +++ linux-2.6.39.2/drivers/pcmcia/rsrc_mgr.c 2011-05-22 19:36:32.000000000 -0400
37211 @@ -57,7 +57,7 @@ static int static_find_io(struct pcmcia_
37212 }
37213
37214
37215 -struct pccard_resource_ops pccard_static_ops = {
37216 +const struct pccard_resource_ops pccard_static_ops = {
37217 .validate_mem = NULL,
37218 .find_io = static_find_io,
37219 .find_mem = NULL,
37220 diff -urNp linux-2.6.39.2/drivers/pcmcia/vrc4171_card.c linux-2.6.39.2/drivers/pcmcia/vrc4171_card.c
37221 --- linux-2.6.39.2/drivers/pcmcia/vrc4171_card.c 2011-05-19 00:06:34.000000000 -0400
37222 +++ linux-2.6.39.2/drivers/pcmcia/vrc4171_card.c 2011-05-22 19:36:32.000000000 -0400
37223 @@ -479,7 +479,7 @@ static int pccard_set_mem_map(struct pcm
37224 return 0;
37225 }
37226
37227 -static struct pccard_operations vrc4171_pccard_operations = {
37228 +static const struct pccard_operations vrc4171_pccard_operations = {
37229 .init = pccard_init,
37230 .get_status = pccard_get_status,
37231 .set_socket = pccard_set_socket,
37232 diff -urNp linux-2.6.39.2/drivers/pcmcia/vrc4173_cardu.c linux-2.6.39.2/drivers/pcmcia/vrc4173_cardu.c
37233 --- linux-2.6.39.2/drivers/pcmcia/vrc4173_cardu.c 2011-05-19 00:06:34.000000000 -0400
37234 +++ linux-2.6.39.2/drivers/pcmcia/vrc4173_cardu.c 2011-05-22 19:36:32.000000000 -0400
37235 @@ -384,7 +384,7 @@ static void cardu_proc_setup(unsigned in
37236 {
37237 }
37238
37239 -static struct pccard_operations cardu_operations = {
37240 +static const struct pccard_operations cardu_operations = {
37241 .init = cardu_init,
37242 .register_callback = cardu_register_callback,
37243 .inquire_socket = cardu_inquire_socket,
37244 diff -urNp linux-2.6.39.2/drivers/pcmcia/xxs1500_ss.c linux-2.6.39.2/drivers/pcmcia/xxs1500_ss.c
37245 --- linux-2.6.39.2/drivers/pcmcia/xxs1500_ss.c 2011-05-19 00:06:34.000000000 -0400
37246 +++ linux-2.6.39.2/drivers/pcmcia/xxs1500_ss.c 2011-05-22 19:36:32.000000000 -0400
37247 @@ -196,7 +196,7 @@ static int au1x00_pcmcia_set_mem_map(str
37248 return 0;
37249 }
37250
37251 -static struct pccard_operations xxs1500_pcmcia_operations = {
37252 +static const struct pccard_operations xxs1500_pcmcia_operations = {
37253 .init = xxs1500_pcmcia_sock_init,
37254 .suspend = xxs1500_pcmcia_sock_suspend,
37255 .get_status = xxs1500_pcmcia_get_status,
37256 diff -urNp linux-2.6.39.2/drivers/platform/x86/acerhdf.c linux-2.6.39.2/drivers/platform/x86/acerhdf.c
37257 --- linux-2.6.39.2/drivers/platform/x86/acerhdf.c 2011-05-19 00:06:34.000000000 -0400
37258 +++ linux-2.6.39.2/drivers/platform/x86/acerhdf.c 2011-05-22 19:36:32.000000000 -0400
37259 @@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct
37260 }
37261
37262 /* bind callback functions to thermalzone */
37263 -static struct thermal_zone_device_ops acerhdf_dev_ops = {
37264 +static const struct thermal_zone_device_ops acerhdf_dev_ops = {
37265 .bind = acerhdf_bind,
37266 .unbind = acerhdf_unbind,
37267 .get_temp = acerhdf_get_ec_temp,
37268 @@ -481,7 +481,7 @@ err_out:
37269 }
37270
37271 /* bind fan callbacks to fan device */
37272 -static struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37273 +static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
37274 .get_max_state = acerhdf_get_max_state,
37275 .get_cur_state = acerhdf_get_cur_state,
37276 .set_cur_state = acerhdf_set_cur_state,
37277 diff -urNp linux-2.6.39.2/drivers/platform/x86/ideapad-laptop.c linux-2.6.39.2/drivers/platform/x86/ideapad-laptop.c
37278 --- linux-2.6.39.2/drivers/platform/x86/ideapad-laptop.c 2011-05-19 00:06:34.000000000 -0400
37279 +++ linux-2.6.39.2/drivers/platform/x86/ideapad-laptop.c 2011-05-22 19:36:32.000000000 -0400
37280 @@ -207,7 +207,7 @@ static int ideapad_rfk_set(void *data, b
37281 return write_ec_cmd(ideapad_handle, opcode, !blocked);
37282 }
37283
37284 -static struct rfkill_ops ideapad_rfk_ops = {
37285 +static const struct rfkill_ops ideapad_rfk_ops = {
37286 .set_block = ideapad_rfk_set,
37287 };
37288
37289 diff -urNp linux-2.6.39.2/drivers/platform/x86/intel_menlow.c linux-2.6.39.2/drivers/platform/x86/intel_menlow.c
37290 --- linux-2.6.39.2/drivers/platform/x86/intel_menlow.c 2011-05-19 00:06:34.000000000 -0400
37291 +++ linux-2.6.39.2/drivers/platform/x86/intel_menlow.c 2011-05-22 19:36:32.000000000 -0400
37292 @@ -143,7 +143,7 @@ static int memory_set_cur_bandwidth(stru
37293 return 0;
37294 }
37295
37296 -static struct thermal_cooling_device_ops memory_cooling_ops = {
37297 +static const struct thermal_cooling_device_ops memory_cooling_ops = {
37298 .get_max_state = memory_get_max_bandwidth,
37299 .get_cur_state = memory_get_cur_bandwidth,
37300 .set_cur_state = memory_set_cur_bandwidth,
37301 diff -urNp linux-2.6.39.2/drivers/platform/x86/intel_mid_thermal.c linux-2.6.39.2/drivers/platform/x86/intel_mid_thermal.c
37302 --- linux-2.6.39.2/drivers/platform/x86/intel_mid_thermal.c 2011-05-19 00:06:34.000000000 -0400
37303 +++ linux-2.6.39.2/drivers/platform/x86/intel_mid_thermal.c 2011-05-22 19:36:32.000000000 -0400
37304 @@ -458,7 +458,7 @@ static int read_curr_temp(struct thermal
37305 }
37306
37307 /* Can't be const */
37308 -static struct thermal_zone_device_ops tzd_ops = {
37309 +static const struct thermal_zone_device_ops tzd_ops = {
37310 .get_temp = read_curr_temp,
37311 };
37312
37313 diff -urNp linux-2.6.39.2/drivers/platform/x86/samsung-laptop.c linux-2.6.39.2/drivers/platform/x86/samsung-laptop.c
37314 --- linux-2.6.39.2/drivers/platform/x86/samsung-laptop.c 2011-05-19 00:06:34.000000000 -0400
37315 +++ linux-2.6.39.2/drivers/platform/x86/samsung-laptop.c 2011-05-22 19:36:32.000000000 -0400
37316 @@ -419,7 +419,7 @@ static int rfkill_set(void *data, bool b
37317 return 0;
37318 }
37319
37320 -static struct rfkill_ops rfkill_ops = {
37321 +static const struct rfkill_ops rfkill_ops = {
37322 .set_block = rfkill_set,
37323 };
37324
37325 diff -urNp linux-2.6.39.2/drivers/pnp/pnpbios/bioscalls.c linux-2.6.39.2/drivers/pnp/pnpbios/bioscalls.c
37326 --- linux-2.6.39.2/drivers/pnp/pnpbios/bioscalls.c 2011-05-19 00:06:34.000000000 -0400
37327 +++ linux-2.6.39.2/drivers/pnp/pnpbios/bioscalls.c 2011-05-22 19:36:32.000000000 -0400
37328 @@ -59,7 +59,7 @@ do { \
37329 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37330 } while(0)
37331
37332 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37333 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37334 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37335
37336 /*
37337 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func
37338
37339 cpu = get_cpu();
37340 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37341 +
37342 + pax_open_kernel();
37343 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37344 + pax_close_kernel();
37345
37346 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37347 spin_lock_irqsave(&pnp_bios_lock, flags);
37348 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func
37349 :"memory");
37350 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37351
37352 + pax_open_kernel();
37353 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37354 + pax_close_kernel();
37355 +
37356 put_cpu();
37357
37358 /* If we get here and this is set then the PnP BIOS faulted on us. */
37359 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 n
37360 return status;
37361 }
37362
37363 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37364 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37365 {
37366 int i;
37367
37368 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_i
37369 pnp_bios_callpoint.offset = header->fields.pm16offset;
37370 pnp_bios_callpoint.segment = PNP_CS16;
37371
37372 + pax_open_kernel();
37373 +
37374 for_each_possible_cpu(i) {
37375 struct desc_struct *gdt = get_cpu_gdt_table(i);
37376 if (!gdt)
37377 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_i
37378 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37379 (unsigned long)__va(header->fields.pm16dseg));
37380 }
37381 +
37382 + pax_close_kernel();
37383 }
37384 diff -urNp linux-2.6.39.2/drivers/pnp/resource.c linux-2.6.39.2/drivers/pnp/resource.c
37385 --- linux-2.6.39.2/drivers/pnp/resource.c 2011-05-19 00:06:34.000000000 -0400
37386 +++ linux-2.6.39.2/drivers/pnp/resource.c 2011-05-22 19:36:32.000000000 -0400
37387 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
37388 return 1;
37389
37390 /* check if the resource is valid */
37391 - if (*irq < 0 || *irq > 15)
37392 + if (*irq > 15)
37393 return 0;
37394
37395 /* check if the resource is reserved */
37396 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
37397 return 1;
37398
37399 /* check if the resource is valid */
37400 - if (*dma < 0 || *dma == 4 || *dma > 7)
37401 + if (*dma == 4 || *dma > 7)
37402 return 0;
37403
37404 /* check if the resource is reserved */
37405 diff -urNp linux-2.6.39.2/drivers/power/max8925_power.c linux-2.6.39.2/drivers/power/max8925_power.c
37406 --- linux-2.6.39.2/drivers/power/max8925_power.c 2011-05-19 00:06:34.000000000 -0400
37407 +++ linux-2.6.39.2/drivers/power/max8925_power.c 2011-05-22 19:36:32.000000000 -0400
37408 @@ -426,7 +426,7 @@ static __devinit int max8925_power_probe
37409 {
37410 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
37411 struct max8925_platform_data *max8925_pdata;
37412 - struct max8925_power_pdata *pdata = NULL;
37413 + const struct max8925_power_pdata *pdata = NULL;
37414 struct max8925_power_info *info;
37415 int ret;
37416
37417 diff -urNp linux-2.6.39.2/drivers/regulator/core.c linux-2.6.39.2/drivers/regulator/core.c
37418 --- linux-2.6.39.2/drivers/regulator/core.c 2011-05-19 00:06:34.000000000 -0400
37419 +++ linux-2.6.39.2/drivers/regulator/core.c 2011-05-22 19:36:32.000000000 -0400
37420 @@ -2883,7 +2883,7 @@ core_initcall(regulator_init);
37421 static int __init regulator_init_complete(void)
37422 {
37423 struct regulator_dev *rdev;
37424 - struct regulator_ops *ops;
37425 + const struct regulator_ops *ops;
37426 struct regulation_constraints *c;
37427 int enabled, ret;
37428
37429 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-at32ap700x.c linux-2.6.39.2/drivers/rtc/rtc-at32ap700x.c
37430 --- linux-2.6.39.2/drivers/rtc/rtc-at32ap700x.c 2011-05-19 00:06:34.000000000 -0400
37431 +++ linux-2.6.39.2/drivers/rtc/rtc-at32ap700x.c 2011-05-22 19:36:32.000000000 -0400
37432 @@ -187,7 +187,7 @@ static irqreturn_t at32_rtc_interrupt(in
37433 return ret;
37434 }
37435
37436 -static struct rtc_class_ops at32_rtc_ops = {
37437 +static const struct rtc_class_ops at32_rtc_ops = {
37438 .read_time = at32_rtc_readtime,
37439 .set_time = at32_rtc_settime,
37440 .read_alarm = at32_rtc_readalarm,
37441 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-au1xxx.c linux-2.6.39.2/drivers/rtc/rtc-au1xxx.c
37442 --- linux-2.6.39.2/drivers/rtc/rtc-au1xxx.c 2011-05-19 00:06:34.000000000 -0400
37443 +++ linux-2.6.39.2/drivers/rtc/rtc-au1xxx.c 2011-05-22 19:36:32.000000000 -0400
37444 @@ -57,7 +57,7 @@ static int au1xtoy_rtc_set_time(struct d
37445 return 0;
37446 }
37447
37448 -static struct rtc_class_ops au1xtoy_rtc_ops = {
37449 +static const struct rtc_class_ops au1xtoy_rtc_ops = {
37450 .read_time = au1xtoy_rtc_read_time,
37451 .set_time = au1xtoy_rtc_set_time,
37452 };
37453 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-bfin.c linux-2.6.39.2/drivers/rtc/rtc-bfin.c
37454 --- linux-2.6.39.2/drivers/rtc/rtc-bfin.c 2011-05-19 00:06:34.000000000 -0400
37455 +++ linux-2.6.39.2/drivers/rtc/rtc-bfin.c 2011-05-22 19:36:32.000000000 -0400
37456 @@ -333,7 +333,7 @@ static int bfin_rtc_proc(struct device *
37457 #undef yesno
37458 }
37459
37460 -static struct rtc_class_ops bfin_rtc_ops = {
37461 +static const struct rtc_class_ops bfin_rtc_ops = {
37462 .read_time = bfin_rtc_read_time,
37463 .set_time = bfin_rtc_set_time,
37464 .read_alarm = bfin_rtc_read_alarm,
37465 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-coh901331.c linux-2.6.39.2/drivers/rtc/rtc-coh901331.c
37466 --- linux-2.6.39.2/drivers/rtc/rtc-coh901331.c 2011-05-19 00:06:34.000000000 -0400
37467 +++ linux-2.6.39.2/drivers/rtc/rtc-coh901331.c 2011-05-22 19:36:32.000000000 -0400
37468 @@ -142,7 +142,7 @@ static int coh901331_alarm_irq_enable(st
37469 return 0;
37470 }
37471
37472 -static struct rtc_class_ops coh901331_ops = {
37473 +static const struct rtc_class_ops coh901331_ops = {
37474 .read_time = coh901331_read_time,
37475 .set_mmss = coh901331_set_mmss,
37476 .read_alarm = coh901331_read_alarm,
37477 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-davinci.c linux-2.6.39.2/drivers/rtc/rtc-davinci.c
37478 --- linux-2.6.39.2/drivers/rtc/rtc-davinci.c 2011-05-19 00:06:34.000000000 -0400
37479 +++ linux-2.6.39.2/drivers/rtc/rtc-davinci.c 2011-05-22 19:36:32.000000000 -0400
37480 @@ -469,7 +469,7 @@ static int davinci_rtc_set_alarm(struct
37481 return 0;
37482 }
37483
37484 -static struct rtc_class_ops davinci_rtc_ops = {
37485 +static const struct rtc_class_ops davinci_rtc_ops = {
37486 .ioctl = davinci_rtc_ioctl,
37487 .read_time = davinci_rtc_read_time,
37488 .set_time = davinci_rtc_set_time,
37489 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-dev.c linux-2.6.39.2/drivers/rtc/rtc-dev.c
37490 --- linux-2.6.39.2/drivers/rtc/rtc-dev.c 2011-05-19 00:06:34.000000000 -0400
37491 +++ linux-2.6.39.2/drivers/rtc/rtc-dev.c 2011-05-22 19:41:37.000000000 -0400
37492 @@ -14,6 +14,7 @@
37493 #include <linux/module.h>
37494 #include <linux/rtc.h>
37495 #include <linux/sched.h>
37496 +#include <linux/grsecurity.h>
37497 #include "rtc-core.h"
37498
37499 static dev_t rtc_devt;
37500 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *f
37501 if (copy_from_user(&tm, uarg, sizeof(tm)))
37502 return -EFAULT;
37503
37504 + gr_log_timechange();
37505 +
37506 return rtc_set_time(rtc, &tm);
37507
37508 case RTC_PIE_ON:
37509 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-dm355evm.c linux-2.6.39.2/drivers/rtc/rtc-dm355evm.c
37510 --- linux-2.6.39.2/drivers/rtc/rtc-dm355evm.c 2011-05-19 00:06:34.000000000 -0400
37511 +++ linux-2.6.39.2/drivers/rtc/rtc-dm355evm.c 2011-05-22 19:36:32.000000000 -0400
37512 @@ -115,7 +115,7 @@ static int dm355evm_rtc_set_time(struct
37513 return 0;
37514 }
37515
37516 -static struct rtc_class_ops dm355evm_rtc_ops = {
37517 +static const struct rtc_class_ops dm355evm_rtc_ops = {
37518 .read_time = dm355evm_rtc_read_time,
37519 .set_time = dm355evm_rtc_set_time,
37520 };
37521 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-ds1302.c linux-2.6.39.2/drivers/rtc/rtc-ds1302.c
37522 --- linux-2.6.39.2/drivers/rtc/rtc-ds1302.c 2011-05-19 00:06:34.000000000 -0400
37523 +++ linux-2.6.39.2/drivers/rtc/rtc-ds1302.c 2011-05-22 19:36:32.000000000 -0400
37524 @@ -199,7 +199,7 @@ static int ds1302_rtc_ioctl(struct devic
37525 return -ENOIOCTLCMD;
37526 }
37527
37528 -static struct rtc_class_ops ds1302_rtc_ops = {
37529 +static const struct rtc_class_ops ds1302_rtc_ops = {
37530 .read_time = ds1302_rtc_read_time,
37531 .set_time = ds1302_rtc_set_time,
37532 .ioctl = ds1302_rtc_ioctl,
37533 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-imxdi.c linux-2.6.39.2/drivers/rtc/rtc-imxdi.c
37534 --- linux-2.6.39.2/drivers/rtc/rtc-imxdi.c 2011-05-19 00:06:34.000000000 -0400
37535 +++ linux-2.6.39.2/drivers/rtc/rtc-imxdi.c 2011-05-22 19:36:32.000000000 -0400
37536 @@ -290,7 +290,7 @@ static int dryice_rtc_set_alarm(struct d
37537 return 0;
37538 }
37539
37540 -static struct rtc_class_ops dryice_rtc_ops = {
37541 +static const struct rtc_class_ops dryice_rtc_ops = {
37542 .read_time = dryice_rtc_read_time,
37543 .set_mmss = dryice_rtc_set_mmss,
37544 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
37545 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-jz4740.c linux-2.6.39.2/drivers/rtc/rtc-jz4740.c
37546 --- linux-2.6.39.2/drivers/rtc/rtc-jz4740.c 2011-05-19 00:06:34.000000000 -0400
37547 +++ linux-2.6.39.2/drivers/rtc/rtc-jz4740.c 2011-05-22 19:36:32.000000000 -0400
37548 @@ -174,7 +174,7 @@ static int jz4740_rtc_alarm_irq_enable(s
37549 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
37550 }
37551
37552 -static struct rtc_class_ops jz4740_rtc_ops = {
37553 +static const struct rtc_class_ops jz4740_rtc_ops = {
37554 .read_time = jz4740_rtc_read_time,
37555 .set_mmss = jz4740_rtc_set_mmss,
37556 .read_alarm = jz4740_rtc_read_alarm,
37557 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-m41t80.c linux-2.6.39.2/drivers/rtc/rtc-m41t80.c
37558 --- linux-2.6.39.2/drivers/rtc/rtc-m41t80.c 2011-05-19 00:06:34.000000000 -0400
37559 +++ linux-2.6.39.2/drivers/rtc/rtc-m41t80.c 2011-05-22 19:36:32.000000000 -0400
37560 @@ -354,7 +354,7 @@ static int m41t80_rtc_read_alarm(struct
37561 return 0;
37562 }
37563
37564 -static struct rtc_class_ops m41t80_rtc_ops = {
37565 +static const struct rtc_class_ops m41t80_rtc_ops = {
37566 .read_time = m41t80_rtc_read_time,
37567 .set_time = m41t80_rtc_set_time,
37568 .read_alarm = m41t80_rtc_read_alarm,
37569 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-mxc.c linux-2.6.39.2/drivers/rtc/rtc-mxc.c
37570 --- linux-2.6.39.2/drivers/rtc/rtc-mxc.c 2011-05-19 00:06:34.000000000 -0400
37571 +++ linux-2.6.39.2/drivers/rtc/rtc-mxc.c 2011-05-22 19:36:32.000000000 -0400
37572 @@ -355,7 +355,7 @@ static int mxc_rtc_set_alarm(struct devi
37573 }
37574
37575 /* RTC layer */
37576 -static struct rtc_class_ops mxc_rtc_ops = {
37577 +static const struct rtc_class_ops mxc_rtc_ops = {
37578 .release = mxc_rtc_release,
37579 .read_time = mxc_rtc_read_time,
37580 .set_mmss = mxc_rtc_set_mmss,
37581 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-nuc900.c linux-2.6.39.2/drivers/rtc/rtc-nuc900.c
37582 --- linux-2.6.39.2/drivers/rtc/rtc-nuc900.c 2011-05-19 00:06:34.000000000 -0400
37583 +++ linux-2.6.39.2/drivers/rtc/rtc-nuc900.c 2011-05-22 19:36:32.000000000 -0400
37584 @@ -214,7 +214,7 @@ static int nuc900_rtc_set_alarm(struct d
37585 return 0;
37586 }
37587
37588 -static struct rtc_class_ops nuc900_rtc_ops = {
37589 +static const struct rtc_class_ops nuc900_rtc_ops = {
37590 .read_time = nuc900_rtc_read_time,
37591 .set_time = nuc900_rtc_set_time,
37592 .read_alarm = nuc900_rtc_read_alarm,
37593 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-omap.c linux-2.6.39.2/drivers/rtc/rtc-omap.c
37594 --- linux-2.6.39.2/drivers/rtc/rtc-omap.c 2011-05-19 00:06:34.000000000 -0400
37595 +++ linux-2.6.39.2/drivers/rtc/rtc-omap.c 2011-05-22 19:36:32.000000000 -0400
37596 @@ -274,7 +274,7 @@ static int omap_rtc_set_alarm(struct dev
37597 return 0;
37598 }
37599
37600 -static struct rtc_class_ops omap_rtc_ops = {
37601 +static const struct rtc_class_ops omap_rtc_ops = {
37602 .read_time = omap_rtc_read_time,
37603 .set_time = omap_rtc_set_time,
37604 .read_alarm = omap_rtc_read_alarm,
37605 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-pcf50633.c linux-2.6.39.2/drivers/rtc/rtc-pcf50633.c
37606 --- linux-2.6.39.2/drivers/rtc/rtc-pcf50633.c 2011-05-19 00:06:34.000000000 -0400
37607 +++ linux-2.6.39.2/drivers/rtc/rtc-pcf50633.c 2011-05-22 19:36:32.000000000 -0400
37608 @@ -238,7 +238,7 @@ static int pcf50633_rtc_set_alarm(struct
37609 return ret;
37610 }
37611
37612 -static struct rtc_class_ops pcf50633_rtc_ops = {
37613 +static const struct rtc_class_ops pcf50633_rtc_ops = {
37614 .read_time = pcf50633_rtc_read_time,
37615 .set_time = pcf50633_rtc_set_time,
37616 .read_alarm = pcf50633_rtc_read_alarm,
37617 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-pl031.c linux-2.6.39.2/drivers/rtc/rtc-pl031.c
37618 --- linux-2.6.39.2/drivers/rtc/rtc-pl031.c 2011-05-19 00:06:34.000000000 -0400
37619 +++ linux-2.6.39.2/drivers/rtc/rtc-pl031.c 2011-05-22 19:36:32.000000000 -0400
37620 @@ -374,7 +374,7 @@ err_req:
37621 }
37622
37623 /* Operations for the original ARM version */
37624 -static struct rtc_class_ops arm_pl031_ops = {
37625 +static const struct rtc_class_ops arm_pl031_ops = {
37626 .read_time = pl031_read_time,
37627 .set_time = pl031_set_time,
37628 .read_alarm = pl031_read_alarm,
37629 @@ -383,7 +383,7 @@ static struct rtc_class_ops arm_pl031_op
37630 };
37631
37632 /* The First ST derivative */
37633 -static struct rtc_class_ops stv1_pl031_ops = {
37634 +static const struct rtc_class_ops stv1_pl031_ops = {
37635 .read_time = pl031_read_time,
37636 .set_time = pl031_set_time,
37637 .read_alarm = pl031_read_alarm,
37638 @@ -392,7 +392,7 @@ static struct rtc_class_ops stv1_pl031_o
37639 };
37640
37641 /* And the second ST derivative */
37642 -static struct rtc_class_ops stv2_pl031_ops = {
37643 +static const struct rtc_class_ops stv2_pl031_ops = {
37644 .read_time = pl031_stv2_read_time,
37645 .set_time = pl031_stv2_set_time,
37646 .read_alarm = pl031_stv2_read_alarm,
37647 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-rx8025.c linux-2.6.39.2/drivers/rtc/rtc-rx8025.c
37648 --- linux-2.6.39.2/drivers/rtc/rtc-rx8025.c 2011-05-19 00:06:34.000000000 -0400
37649 +++ linux-2.6.39.2/drivers/rtc/rtc-rx8025.c 2011-05-22 19:36:32.000000000 -0400
37650 @@ -424,7 +424,7 @@ static int rx8025_alarm_irq_enable(struc
37651 return 0;
37652 }
37653
37654 -static struct rtc_class_ops rx8025_rtc_ops = {
37655 +static const struct rtc_class_ops rx8025_rtc_ops = {
37656 .read_time = rx8025_get_time,
37657 .set_time = rx8025_set_time,
37658 .read_alarm = rx8025_read_alarm,
37659 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-sh.c linux-2.6.39.2/drivers/rtc/rtc-sh.c
37660 --- linux-2.6.39.2/drivers/rtc/rtc-sh.c 2011-05-19 00:06:34.000000000 -0400
37661 +++ linux-2.6.39.2/drivers/rtc/rtc-sh.c 2011-05-22 19:36:32.000000000 -0400
37662 @@ -576,7 +576,7 @@ static int sh_rtc_set_alarm(struct devic
37663 return 0;
37664 }
37665
37666 -static struct rtc_class_ops sh_rtc_ops = {
37667 +static const struct rtc_class_ops sh_rtc_ops = {
37668 .read_time = sh_rtc_read_time,
37669 .set_time = sh_rtc_set_time,
37670 .read_alarm = sh_rtc_read_alarm,
37671 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-stmp3xxx.c linux-2.6.39.2/drivers/rtc/rtc-stmp3xxx.c
37672 --- linux-2.6.39.2/drivers/rtc/rtc-stmp3xxx.c 2011-05-19 00:06:34.000000000 -0400
37673 +++ linux-2.6.39.2/drivers/rtc/rtc-stmp3xxx.c 2011-05-22 19:36:32.000000000 -0400
37674 @@ -133,7 +133,7 @@ static int stmp3xxx_rtc_set_alarm(struct
37675 return 0;
37676 }
37677
37678 -static struct rtc_class_ops stmp3xxx_rtc_ops = {
37679 +static const struct rtc_class_ops stmp3xxx_rtc_ops = {
37680 .alarm_irq_enable =
37681 stmp3xxx_alarm_irq_enable,
37682 .read_time = stmp3xxx_rtc_gettime,
37683 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-tegra.c linux-2.6.39.2/drivers/rtc/rtc-tegra.c
37684 --- linux-2.6.39.2/drivers/rtc/rtc-tegra.c 2011-05-19 00:06:34.000000000 -0400
37685 +++ linux-2.6.39.2/drivers/rtc/rtc-tegra.c 2011-05-22 19:36:32.000000000 -0400
37686 @@ -294,7 +294,7 @@ static irqreturn_t tegra_rtc_irq_handler
37687 return IRQ_HANDLED;
37688 }
37689
37690 -static struct rtc_class_ops tegra_rtc_ops = {
37691 +static const struct rtc_class_ops tegra_rtc_ops = {
37692 .read_time = tegra_rtc_read_time,
37693 .set_time = tegra_rtc_set_time,
37694 .read_alarm = tegra_rtc_read_alarm,
37695 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-twl.c linux-2.6.39.2/drivers/rtc/rtc-twl.c
37696 --- linux-2.6.39.2/drivers/rtc/rtc-twl.c 2011-05-19 00:06:34.000000000 -0400
37697 +++ linux-2.6.39.2/drivers/rtc/rtc-twl.c 2011-05-22 19:36:32.000000000 -0400
37698 @@ -415,7 +415,7 @@ out:
37699 return ret;
37700 }
37701
37702 -static struct rtc_class_ops twl_rtc_ops = {
37703 +static const struct rtc_class_ops twl_rtc_ops = {
37704 .read_time = twl_rtc_read_time,
37705 .set_time = twl_rtc_set_time,
37706 .read_alarm = twl_rtc_read_alarm,
37707 diff -urNp linux-2.6.39.2/drivers/rtc/rtc-v3020.c linux-2.6.39.2/drivers/rtc/rtc-v3020.c
37708 --- linux-2.6.39.2/drivers/rtc/rtc-v3020.c 2011-05-19 00:06:34.000000000 -0400
37709 +++ linux-2.6.39.2/drivers/rtc/rtc-v3020.c 2011-05-22 19:36:32.000000000 -0400
37710 @@ -62,7 +62,7 @@ struct v3020 {
37711 /* GPIO access */
37712 struct v3020_gpio *gpio;
37713
37714 - struct v3020_chip_ops *ops;
37715 + const struct v3020_chip_ops *ops;
37716
37717 struct rtc_device *rtc;
37718 };
37719 @@ -100,7 +100,7 @@ static unsigned char v3020_mmio_read_bit
37720 return !!(readl(chip->ioaddress) & (1 << chip->leftshift));
37721 }
37722
37723 -static struct v3020_chip_ops v3020_mmio_ops = {
37724 +static const struct v3020_chip_ops v3020_mmio_ops = {
37725 .map_io = v3020_mmio_map,
37726 .unmap_io = v3020_mmio_unmap,
37727 .read_bit = v3020_mmio_read_bit,
37728 @@ -177,7 +177,7 @@ static unsigned char v3020_gpio_read_bit
37729 return bit;
37730 }
37731
37732 -static struct v3020_chip_ops v3020_gpio_ops = {
37733 +static const struct v3020_chip_ops v3020_gpio_ops = {
37734 .map_io = v3020_gpio_map,
37735 .unmap_io = v3020_gpio_unmap,
37736 .read_bit = v3020_gpio_read_bit,
37737 diff -urNp linux-2.6.39.2/drivers/s390/char/con3270.c linux-2.6.39.2/drivers/s390/char/con3270.c
37738 --- linux-2.6.39.2/drivers/s390/char/con3270.c 2011-05-19 00:06:34.000000000 -0400
37739 +++ linux-2.6.39.2/drivers/s390/char/con3270.c 2011-05-22 19:36:32.000000000 -0400
37740 @@ -28,7 +28,7 @@
37741 #define CON3270_OUTPUT_BUFFER_SIZE 1024
37742 #define CON3270_STRING_PAGES 4
37743
37744 -static struct raw3270_fn con3270_fn;
37745 +static const struct raw3270_fn con3270_fn;
37746
37747 /*
37748 * Main 3270 console view data structure.
37749 @@ -413,7 +413,7 @@ con3270_irq(struct con3270 *cp, struct r
37750 }
37751
37752 /* Console view to a 3270 device. */
37753 -static struct raw3270_fn con3270_fn = {
37754 +static const struct raw3270_fn con3270_fn = {
37755 .activate = con3270_activate,
37756 .deactivate = con3270_deactivate,
37757 .intv = (void *) con3270_irq
37758 diff -urNp linux-2.6.39.2/drivers/s390/char/fs3270.c linux-2.6.39.2/drivers/s390/char/fs3270.c
37759 --- linux-2.6.39.2/drivers/s390/char/fs3270.c 2011-05-19 00:06:34.000000000 -0400
37760 +++ linux-2.6.39.2/drivers/s390/char/fs3270.c 2011-05-22 19:36:32.000000000 -0400
37761 @@ -24,7 +24,7 @@
37762 #include "raw3270.h"
37763 #include "ctrlchar.h"
37764
37765 -static struct raw3270_fn fs3270_fn;
37766 +static const struct raw3270_fn fs3270_fn;
37767
37768 struct fs3270 {
37769 struct raw3270_view view;
37770 @@ -413,7 +413,7 @@ fs3270_release(struct raw3270_view *view
37771 }
37772
37773 /* View to a 3270 device. Can be console, tty or fullscreen. */
37774 -static struct raw3270_fn fs3270_fn = {
37775 +static const struct raw3270_fn fs3270_fn = {
37776 .activate = fs3270_activate,
37777 .deactivate = fs3270_deactivate,
37778 .intv = (void *) fs3270_irq,
37779 diff -urNp linux-2.6.39.2/drivers/s390/char/raw3270.c linux-2.6.39.2/drivers/s390/char/raw3270.c
37780 --- linux-2.6.39.2/drivers/s390/char/raw3270.c 2011-05-19 00:06:34.000000000 -0400
37781 +++ linux-2.6.39.2/drivers/s390/char/raw3270.c 2011-05-22 19:36:32.000000000 -0400
37782 @@ -488,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *vi
37783 return RAW3270_IO_DONE;
37784 }
37785
37786 -static struct raw3270_fn raw3270_init_fn = {
37787 +static const struct raw3270_fn raw3270_init_fn = {
37788 .intv = raw3270_init_irq
37789 };
37790
37791 diff -urNp linux-2.6.39.2/drivers/s390/char/tty3270.c linux-2.6.39.2/drivers/s390/char/tty3270.c
37792 --- linux-2.6.39.2/drivers/s390/char/tty3270.c 2011-05-19 00:06:34.000000000 -0400
37793 +++ linux-2.6.39.2/drivers/s390/char/tty3270.c 2011-05-22 19:36:32.000000000 -0400
37794 @@ -37,7 +37,7 @@
37795 struct tty_driver *tty3270_driver;
37796 static int tty3270_max_index;
37797
37798 -static struct raw3270_fn tty3270_fn;
37799 +static const struct raw3270_fn tty3270_fn;
37800
37801 struct tty3270_cell {
37802 unsigned char character;
37803 @@ -834,7 +834,7 @@ tty3270_del_views(void)
37804 }
37805 }
37806
37807 -static struct raw3270_fn tty3270_fn = {
37808 +static const struct raw3270_fn tty3270_fn = {
37809 .activate = tty3270_activate,
37810 .deactivate = tty3270_deactivate,
37811 .intv = (void *) tty3270_irq,
37812 diff -urNp linux-2.6.39.2/drivers/s390/cio/qdio_debug.c linux-2.6.39.2/drivers/s390/cio/qdio_debug.c
37813 --- linux-2.6.39.2/drivers/s390/cio/qdio_debug.c 2011-05-19 00:06:34.000000000 -0400
37814 +++ linux-2.6.39.2/drivers/s390/cio/qdio_debug.c 2011-05-22 19:36:32.000000000 -0400
37815 @@ -225,7 +225,7 @@ static int qperf_seq_open(struct inode *
37816 filp->f_path.dentry->d_inode->i_private);
37817 }
37818
37819 -static struct file_operations debugfs_perf_fops = {
37820 +static const struct file_operations debugfs_perf_fops = {
37821 .owner = THIS_MODULE,
37822 .open = qperf_seq_open,
37823 .read = seq_read,
37824 diff -urNp linux-2.6.39.2/drivers/s390/crypto/zcrypt_cex2a.c linux-2.6.39.2/drivers/s390/crypto/zcrypt_cex2a.c
37825 --- linux-2.6.39.2/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-19 00:06:34.000000000 -0400
37826 +++ linux-2.6.39.2/drivers/s390/crypto/zcrypt_cex2a.c 2011-05-22 19:36:32.000000000 -0400
37827 @@ -415,7 +415,7 @@ out_free:
37828 /**
37829 * The crypto operations for a CEX2A card.
37830 */
37831 -static struct zcrypt_ops zcrypt_cex2a_ops = {
37832 +static const struct zcrypt_ops zcrypt_cex2a_ops = {
37833 .rsa_modexpo = zcrypt_cex2a_modexpo,
37834 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,
37835 };
37836 diff -urNp linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcica.c linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcica.c
37837 --- linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcica.c 2011-05-19 00:06:34.000000000 -0400
37838 +++ linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcica.c 2011-05-22 19:36:32.000000000 -0400
37839 @@ -347,7 +347,7 @@ out_free:
37840 /**
37841 * The crypto operations for a PCICA card.
37842 */
37843 -static struct zcrypt_ops zcrypt_pcica_ops = {
37844 +static const struct zcrypt_ops zcrypt_pcica_ops = {
37845 .rsa_modexpo = zcrypt_pcica_modexpo,
37846 .rsa_modexpo_crt = zcrypt_pcica_modexpo_crt,
37847 };
37848 diff -urNp linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcicc.c linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcicc.c
37849 --- linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-19 00:06:34.000000000 -0400
37850 +++ linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcicc.c 2011-05-22 19:36:32.000000000 -0400
37851 @@ -553,7 +553,7 @@ out_free:
37852 /**
37853 * The crypto operations for a PCICC card.
37854 */
37855 -static struct zcrypt_ops zcrypt_pcicc_ops = {
37856 +static const struct zcrypt_ops zcrypt_pcicc_ops = {
37857 .rsa_modexpo = zcrypt_pcicc_modexpo,
37858 .rsa_modexpo_crt = zcrypt_pcicc_modexpo_crt,
37859 };
37860 diff -urNp linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcixcc.c linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcixcc.c
37861 --- linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-19 00:06:34.000000000 -0400
37862 +++ linux-2.6.39.2/drivers/s390/crypto/zcrypt_pcixcc.c 2011-05-22 19:36:32.000000000 -0400
37863 @@ -851,13 +851,13 @@ static long zcrypt_pcixcc_rng(struct zcr
37864 /**
37865 * The crypto operations for a PCIXCC/CEX2C card.
37866 */
37867 -static struct zcrypt_ops zcrypt_pcixcc_ops = {
37868 +static const struct zcrypt_ops zcrypt_pcixcc_ops = {
37869 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37870 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37871 .send_cprb = zcrypt_pcixcc_send_cprb,
37872 };
37873
37874 -static struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37875 +static const struct zcrypt_ops zcrypt_pcixcc_with_rng_ops = {
37876 .rsa_modexpo = zcrypt_pcixcc_modexpo,
37877 .rsa_modexpo_crt = zcrypt_pcixcc_modexpo_crt,
37878 .send_cprb = zcrypt_pcixcc_send_cprb,
37879 diff -urNp linux-2.6.39.2/drivers/s390/kvm/kvm_virtio.c linux-2.6.39.2/drivers/s390/kvm/kvm_virtio.c
37880 --- linux-2.6.39.2/drivers/s390/kvm/kvm_virtio.c 2011-05-19 00:06:34.000000000 -0400
37881 +++ linux-2.6.39.2/drivers/s390/kvm/kvm_virtio.c 2011-05-22 19:36:32.000000000 -0400
37882 @@ -266,7 +266,7 @@ error:
37883 /*
37884 * The config ops structure as defined by virtio config
37885 */
37886 -static struct virtio_config_ops kvm_vq_configspace_ops = {
37887 +static const struct virtio_config_ops kvm_vq_configspace_ops = {
37888 .get_features = kvm_get_features,
37889 .finalize_features = kvm_finalize_features,
37890 .get = kvm_get,
37891 diff -urNp linux-2.6.39.2/drivers/s390/net/qeth_core.h linux-2.6.39.2/drivers/s390/net/qeth_core.h
37892 --- linux-2.6.39.2/drivers/s390/net/qeth_core.h 2011-05-19 00:06:34.000000000 -0400
37893 +++ linux-2.6.39.2/drivers/s390/net/qeth_core.h 2011-05-22 19:36:32.000000000 -0400
37894 @@ -743,7 +743,7 @@ struct qeth_card {
37895 struct qeth_qdio_info qdio;
37896 struct qeth_perf_stats perf_stats;
37897 int read_or_write_problem;
37898 - struct qeth_osn_info osn_info;
37899 + const struct qeth_osn_info osn_info;
37900 struct qeth_discipline discipline;
37901 atomic_t force_alloc_skb;
37902 struct service_level qeth_service_level;
37903 diff -urNp linux-2.6.39.2/drivers/scsi/53c700.c linux-2.6.39.2/drivers/scsi/53c700.c
37904 --- linux-2.6.39.2/drivers/scsi/53c700.c 2011-05-19 00:06:34.000000000 -0400
37905 +++ linux-2.6.39.2/drivers/scsi/53c700.c 2011-05-22 19:36:32.000000000 -0400
37906 @@ -2153,7 +2153,7 @@ EXPORT_SYMBOL(NCR_700_detect);
37907 EXPORT_SYMBOL(NCR_700_release);
37908 EXPORT_SYMBOL(NCR_700_intr);
37909
37910 -static struct spi_function_template NCR_700_transport_functions = {
37911 +static struct spi_function_template NCR_700_transport_functions = {
37912 .set_period = NCR_700_set_period,
37913 .show_period = 1,
37914 .set_offset = NCR_700_set_offset,
37915 diff -urNp linux-2.6.39.2/drivers/scsi/aacraid/commctrl.c linux-2.6.39.2/drivers/scsi/aacraid/commctrl.c
37916 --- linux-2.6.39.2/drivers/scsi/aacraid/commctrl.c 2011-05-19 00:06:34.000000000 -0400
37917 +++ linux-2.6.39.2/drivers/scsi/aacraid/commctrl.c 2011-05-22 19:36:32.000000000 -0400
37918 @@ -482,6 +482,7 @@ static int aac_send_raw_srb(struct aac_d
37919 u32 actual_fibsize64, actual_fibsize = 0;
37920 int i;
37921
37922 + pax_track_stack();
37923
37924 if (dev->in_reset) {
37925 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
37926 diff -urNp linux-2.6.39.2/drivers/scsi/aic94xx/aic94xx_init.c linux-2.6.39.2/drivers/scsi/aic94xx/aic94xx_init.c
37927 --- linux-2.6.39.2/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-19 00:06:34.000000000 -0400
37928 +++ linux-2.6.39.2/drivers/scsi/aic94xx/aic94xx_init.c 2011-05-22 19:41:37.000000000 -0400
37929 @@ -486,7 +486,7 @@ static ssize_t asd_show_update_bios(stru
37930 flash_error_table[i].reason);
37931 }
37932
37933 -static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
37934 +static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
37935 asd_show_update_bios, asd_store_update_bios);
37936
37937 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
37938 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfa_core.c linux-2.6.39.2/drivers/scsi/bfa/bfa_core.c
37939 --- linux-2.6.39.2/drivers/scsi/bfa/bfa_core.c 2011-05-19 00:06:34.000000000 -0400
37940 +++ linux-2.6.39.2/drivers/scsi/bfa/bfa_core.c 2011-05-22 19:36:32.000000000 -0400
37941 @@ -24,7 +24,7 @@ BFA_TRC_FILE(HAL, CORE);
37942 /*
37943 * BFA module list terminated by NULL
37944 */
37945 -static struct bfa_module_s *hal_mods[] = {
37946 +static const struct bfa_module_s *hal_mods[] = {
37947 &hal_mod_sgpg,
37948 &hal_mod_fcport,
37949 &hal_mod_fcxp,
37950 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfad.c linux-2.6.39.2/drivers/scsi/bfa/bfad.c
37951 --- linux-2.6.39.2/drivers/scsi/bfa/bfad.c 2011-05-19 00:06:34.000000000 -0400
37952 +++ linux-2.6.39.2/drivers/scsi/bfa/bfad.c 2011-05-22 19:36:32.000000000 -0400
37953 @@ -1027,6 +1027,8 @@ bfad_start_ops(struct bfad_s *bfad) {
37954 struct bfad_vport_s *vport, *vport_new;
37955 struct bfa_fcs_driver_info_s driver_info;
37956
37957 + pax_track_stack();
37958 +
37959 /* Fill the driver_info info to fcs*/
37960 memset(&driver_info, 0, sizeof(driver_info));
37961 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
37962 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs.c linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs.c
37963 --- linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs.c 2011-05-19 00:06:34.000000000 -0400
37964 +++ linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs.c 2011-05-22 19:36:32.000000000 -0400
37965 @@ -70,7 +70,7 @@ bfa_fcs_attach(struct bfa_fcs_s *fcs, st
37966 bfa_boolean_t min_cfg)
37967 {
37968 int i;
37969 - struct bfa_fcs_mod_s *mod;
37970 + const struct bfa_fcs_mod_s *mod;
37971
37972 fcs->bfa = bfa;
37973 fcs->bfad = bfad;
37974 @@ -93,7 +93,7 @@ void
37975 bfa_fcs_init(struct bfa_fcs_s *fcs)
37976 {
37977 int i, npbc_vports;
37978 - struct bfa_fcs_mod_s *mod;
37979 + const struct bfa_fcs_mod_s *mod;
37980 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
37981
37982 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
37983 @@ -140,7 +140,7 @@ bfa_fcs_driver_info_init(struct bfa_fcs_
37984 void
37985 bfa_fcs_exit(struct bfa_fcs_s *fcs)
37986 {
37987 - struct bfa_fcs_mod_s *mod;
37988 + const struct bfa_fcs_mod_s *mod;
37989 int nmods, i;
37990
37991 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
37992 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_lport.c linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_lport.c
37993 --- linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-19 00:06:34.000000000 -0400
37994 +++ linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_lport.c 2011-05-22 19:36:32.000000000 -0400
37995 @@ -1559,6 +1559,8 @@ bfa_fcs_lport_fdmi_build_rhba_pyld(struc
37996 u16 len, count;
37997 u16 templen;
37998
37999 + pax_track_stack();
38000 +
38001 /*
38002 * get hba attributes
38003 */
38004 @@ -1836,6 +1838,8 @@ bfa_fcs_lport_fdmi_build_portattr_block(
38005 u8 count = 0;
38006 u16 templen;
38007
38008 + pax_track_stack();
38009 +
38010 /*
38011 * get port attributes
38012 */
38013 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_rport.c linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_rport.c
38014 --- linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-19 00:06:34.000000000 -0400
38015 +++ linux-2.6.39.2/drivers/scsi/bfa/bfa_fcs_rport.c 2011-05-22 19:36:32.000000000 -0400
38016 @@ -1844,6 +1844,8 @@ bfa_fcs_rport_process_rpsc(struct bfa_fc
38017 struct fc_rpsc_speed_info_s speeds;
38018 struct bfa_port_attr_s pport_attr;
38019
38020 + pax_track_stack();
38021 +
38022 bfa_trc(port->fcs, rx_fchs->s_id);
38023 bfa_trc(port->fcs, rx_fchs->d_id);
38024
38025 diff -urNp linux-2.6.39.2/drivers/scsi/bfa/bfa_modules.h linux-2.6.39.2/drivers/scsi/bfa/bfa_modules.h
38026 --- linux-2.6.39.2/drivers/scsi/bfa/bfa_modules.h 2011-05-19 00:06:34.000000000 -0400
38027 +++ linux-2.6.39.2/drivers/scsi/bfa/bfa_modules.h 2011-05-22 19:36:32.000000000 -0400
38028 @@ -68,8 +68,8 @@ enum {
38029 static void bfa_ ## __mod ## _stop(struct bfa_s *bfa); \
38030 static void bfa_ ## __mod ## _iocdisable(struct bfa_s *bfa); \
38031 \
38032 - extern struct bfa_module_s hal_mod_ ## __mod; \
38033 - struct bfa_module_s hal_mod_ ## __mod = { \
38034 + extern const struct bfa_module_s hal_mod_ ## __mod; \
38035 + const struct bfa_module_s hal_mod_ ## __mod = { \
38036 bfa_ ## __mod ## _meminfo, \
38037 bfa_ ## __mod ## _attach, \
38038 bfa_ ## __mod ## _detach, \
38039 @@ -116,12 +116,12 @@ struct bfa_s {
38040 };
38041
38042 extern bfa_boolean_t bfa_auto_recover;
38043 -extern struct bfa_module_s hal_mod_sgpg;
38044 -extern struct bfa_module_s hal_mod_fcport;
38045 -extern struct bfa_module_s hal_mod_fcxp;
38046 -extern struct bfa_module_s hal_mod_lps;
38047 -extern struct bfa_module_s hal_mod_uf;
38048 -extern struct bfa_module_s hal_mod_rport;
38049 -extern struct bfa_module_s hal_mod_fcpim;
38050 +extern const struct bfa_module_s hal_mod_sgpg;
38051 +extern const struct bfa_module_s hal_mod_fcport;
38052 +extern const struct bfa_module_s hal_mod_fcxp;
38053 +extern const struct bfa_module_s hal_mod_lps;
38054 +extern const struct bfa_module_s hal_mod_uf;
38055 +extern const struct bfa_module_s hal_mod_rport;
38056 +extern const struct bfa_module_s hal_mod_fcpim;
38057
38058 #endif /* __BFA_MODULES_H__ */
38059 diff -urNp linux-2.6.39.2/drivers/scsi/BusLogic.c linux-2.6.39.2/drivers/scsi/BusLogic.c
38060 --- linux-2.6.39.2/drivers/scsi/BusLogic.c 2011-05-19 00:06:34.000000000 -0400
38061 +++ linux-2.6.39.2/drivers/scsi/BusLogic.c 2011-05-22 19:36:32.000000000 -0400
38062 @@ -962,6 +962,8 @@ static int __init BusLogic_InitializeFla
38063 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
38064 *PrototypeHostAdapter)
38065 {
38066 + pax_track_stack();
38067 +
38068 /*
38069 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
38070 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
38071 diff -urNp linux-2.6.39.2/drivers/scsi/dpt_i2o.c linux-2.6.39.2/drivers/scsi/dpt_i2o.c
38072 --- linux-2.6.39.2/drivers/scsi/dpt_i2o.c 2011-05-19 00:06:34.000000000 -0400
38073 +++ linux-2.6.39.2/drivers/scsi/dpt_i2o.c 2011-05-22 19:36:32.000000000 -0400
38074 @@ -1811,6 +1811,8 @@ static int adpt_i2o_passthru(adpt_hba* p
38075 dma_addr_t addr;
38076 ulong flags = 0;
38077
38078 + pax_track_stack();
38079 +
38080 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
38081 // get user msg size in u32s
38082 if(get_user(size, &user_msg[0])){
38083 @@ -2317,6 +2319,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pH
38084 s32 rcode;
38085 dma_addr_t addr;
38086
38087 + pax_track_stack();
38088 +
38089 memset(msg, 0 , sizeof(msg));
38090 len = scsi_bufflen(cmd);
38091 direction = 0x00000000;
38092 diff -urNp linux-2.6.39.2/drivers/scsi/eata.c linux-2.6.39.2/drivers/scsi/eata.c
38093 --- linux-2.6.39.2/drivers/scsi/eata.c 2011-05-19 00:06:34.000000000 -0400
38094 +++ linux-2.6.39.2/drivers/scsi/eata.c 2011-05-22 19:36:32.000000000 -0400
38095 @@ -1087,6 +1087,8 @@ static int port_detect(unsigned long por
38096 struct hostdata *ha;
38097 char name[16];
38098
38099 + pax_track_stack();
38100 +
38101 sprintf(name, "%s%d", driver_name, j);
38102
38103 if (!request_region(port_base, REGION_SIZE, driver_name)) {
38104 diff -urNp linux-2.6.39.2/drivers/scsi/esp_scsi.c linux-2.6.39.2/drivers/scsi/esp_scsi.c
38105 --- linux-2.6.39.2/drivers/scsi/esp_scsi.c 2011-05-19 00:06:34.000000000 -0400
38106 +++ linux-2.6.39.2/drivers/scsi/esp_scsi.c 2011-05-22 19:36:32.000000000 -0400
38107 @@ -2680,7 +2680,7 @@ static void esp_set_width(struct scsi_ta
38108 tp->flags |= ESP_TGT_CHECK_NEGO;
38109 }
38110
38111 -static struct spi_function_template esp_transport_ops = {
38112 +static const struct spi_function_template esp_transport_ops = {
38113 .set_offset = esp_set_offset,
38114 .show_offset = 1,
38115 .set_period = esp_set_period,
38116 diff -urNp linux-2.6.39.2/drivers/scsi/fcoe/fcoe.c linux-2.6.39.2/drivers/scsi/fcoe/fcoe.c
38117 --- linux-2.6.39.2/drivers/scsi/fcoe/fcoe.c 2011-05-19 00:06:34.000000000 -0400
38118 +++ linux-2.6.39.2/drivers/scsi/fcoe/fcoe.c 2011-05-22 19:36:32.000000000 -0400
38119 @@ -138,7 +138,7 @@ static int fcoe_vport_disable(struct fc_
38120 static void fcoe_set_vport_symbolic_name(struct fc_vport *);
38121 static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *);
38122
38123 -static struct libfc_function_template fcoe_libfc_fcn_templ = {
38124 +static const struct libfc_function_template fcoe_libfc_fcn_templ = {
38125 .frame_send = fcoe_xmit,
38126 .ddp_setup = fcoe_ddp_setup,
38127 .ddp_done = fcoe_ddp_done,
38128 diff -urNp linux-2.6.39.2/drivers/scsi/fcoe/fcoe_ctlr.c linux-2.6.39.2/drivers/scsi/fcoe/fcoe_ctlr.c
38129 --- linux-2.6.39.2/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-19 00:06:34.000000000 -0400
38130 +++ linux-2.6.39.2/drivers/scsi/fcoe/fcoe_ctlr.c 2011-05-22 19:36:32.000000000 -0400
38131 @@ -1912,7 +1912,7 @@ static void fcoe_ctlr_vn_rport_callback(
38132 mutex_unlock(&fip->ctlr_mutex);
38133 }
38134
38135 -static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38136 +static const struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
38137 .event_callback = fcoe_ctlr_vn_rport_callback,
38138 };
38139
38140 @@ -2458,6 +2458,8 @@ static int fcoe_ctlr_vn_recv(struct fcoe
38141 } buf;
38142 int rc;
38143
38144 + pax_track_stack();
38145 +
38146 fiph = (struct fip_header *)skb->data;
38147 sub = fiph->fip_subcode;
38148
38149 diff -urNp linux-2.6.39.2/drivers/scsi/fnic/fnic_main.c linux-2.6.39.2/drivers/scsi/fnic/fnic_main.c
38150 --- linux-2.6.39.2/drivers/scsi/fnic/fnic_main.c 2011-05-19 00:06:34.000000000 -0400
38151 +++ linux-2.6.39.2/drivers/scsi/fnic/fnic_main.c 2011-05-22 19:36:32.000000000 -0400
38152 @@ -69,7 +69,7 @@ module_param(fnic_log_level, int, S_IRUG
38153 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
38154
38155
38156 -static struct libfc_function_template fnic_transport_template = {
38157 +static const struct libfc_function_template fnic_transport_template = {
38158 .frame_send = fnic_send,
38159 .lport_set_port_id = fnic_set_port_id,
38160 .fcp_abort_io = fnic_empty_scsi_cleanup,
38161 diff -urNp linux-2.6.39.2/drivers/scsi/gdth.c linux-2.6.39.2/drivers/scsi/gdth.c
38162 --- linux-2.6.39.2/drivers/scsi/gdth.c 2011-05-19 00:06:34.000000000 -0400
38163 +++ linux-2.6.39.2/drivers/scsi/gdth.c 2011-05-22 19:36:32.000000000 -0400
38164 @@ -4107,6 +4107,8 @@ static int ioc_lockdrv(void __user *arg)
38165 unsigned long flags;
38166 gdth_ha_str *ha;
38167
38168 + pax_track_stack();
38169 +
38170 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
38171 return -EFAULT;
38172 ha = gdth_find_ha(ldrv.ionode);
38173 @@ -4139,6 +4141,8 @@ static int ioc_resetdrv(void __user *arg
38174 gdth_ha_str *ha;
38175 int rval;
38176
38177 + pax_track_stack();
38178 +
38179 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
38180 res.number >= MAX_HDRIVES)
38181 return -EFAULT;
38182 @@ -4174,6 +4178,8 @@ static int ioc_general(void __user *arg,
38183 gdth_ha_str *ha;
38184 int rval;
38185
38186 + pax_track_stack();
38187 +
38188 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
38189 return -EFAULT;
38190 ha = gdth_find_ha(gen.ionode);
38191 @@ -4642,6 +4648,9 @@ static void gdth_flush(gdth_ha_str *ha)
38192 int i;
38193 gdth_cmd_str gdtcmd;
38194 char cmnd[MAX_COMMAND_SIZE];
38195 +
38196 + pax_track_stack();
38197 +
38198 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
38199
38200 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
38201 diff -urNp linux-2.6.39.2/drivers/scsi/gdth_proc.c linux-2.6.39.2/drivers/scsi/gdth_proc.c
38202 --- linux-2.6.39.2/drivers/scsi/gdth_proc.c 2011-05-19 00:06:34.000000000 -0400
38203 +++ linux-2.6.39.2/drivers/scsi/gdth_proc.c 2011-05-22 19:36:32.000000000 -0400
38204 @@ -47,6 +47,9 @@ static int gdth_set_asc_info(struct Scsi
38205 u64 paddr;
38206
38207 char cmnd[MAX_COMMAND_SIZE];
38208 +
38209 + pax_track_stack();
38210 +
38211 memset(cmnd, 0xff, 12);
38212 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38213
38214 @@ -175,6 +178,8 @@ static int gdth_get_info(char *buffer,ch
38215 gdth_hget_str *phg;
38216 char cmnd[MAX_COMMAND_SIZE];
38217
38218 + pax_track_stack();
38219 +
38220 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
38221 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
38222 if (!gdtcmd || !estr)
38223 diff -urNp linux-2.6.39.2/drivers/scsi/hosts.c linux-2.6.39.2/drivers/scsi/hosts.c
38224 --- linux-2.6.39.2/drivers/scsi/hosts.c 2011-05-19 00:06:34.000000000 -0400
38225 +++ linux-2.6.39.2/drivers/scsi/hosts.c 2011-05-22 19:36:32.000000000 -0400
38226 @@ -42,7 +42,7 @@
38227 #include "scsi_logging.h"
38228
38229
38230 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
38231 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
38232
38233
38234 static void scsi_host_cls_release(struct device *dev)
38235 @@ -354,7 +354,7 @@ struct Scsi_Host *scsi_host_alloc(struct
38236 * subtract one because we increment first then return, but we need to
38237 * know what the next host number was before increment
38238 */
38239 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38240 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38241 shost->dma_channel = 0xff;
38242
38243 /* These three are default values which can be overridden */
38244 diff -urNp linux-2.6.39.2/drivers/scsi/hpsa.h linux-2.6.39.2/drivers/scsi/hpsa.h
38245 --- linux-2.6.39.2/drivers/scsi/hpsa.h 2011-05-19 00:06:34.000000000 -0400
38246 +++ linux-2.6.39.2/drivers/scsi/hpsa.h 2011-05-22 19:36:32.000000000 -0400
38247 @@ -347,7 +347,7 @@ static struct access_method SA5_access =
38248 SA5_completed,
38249 };
38250
38251 -static struct access_method SA5_performant_access = {
38252 +static const struct access_method SA5_performant_access = {
38253 SA5_submit_command,
38254 SA5_performant_intr_mask,
38255 SA5_fifo_full,
38256 diff -urNp linux-2.6.39.2/drivers/scsi/hptiop.c linux-2.6.39.2/drivers/scsi/hptiop.c
38257 --- linux-2.6.39.2/drivers/scsi/hptiop.c 2011-05-19 00:06:34.000000000 -0400
38258 +++ linux-2.6.39.2/drivers/scsi/hptiop.c 2011-05-22 19:36:32.000000000 -0400
38259 @@ -1226,7 +1226,7 @@ static void hptiop_remove(struct pci_dev
38260 scsi_host_put(host);
38261 }
38262
38263 -static struct hptiop_adapter_ops hptiop_itl_ops = {
38264 +static const struct hptiop_adapter_ops hptiop_itl_ops = {
38265 .iop_wait_ready = iop_wait_ready_itl,
38266 .internal_memalloc = NULL,
38267 .internal_memfree = NULL,
38268 @@ -1241,7 +1241,7 @@ static struct hptiop_adapter_ops hptiop_
38269 .post_req = hptiop_post_req_itl,
38270 };
38271
38272 -static struct hptiop_adapter_ops hptiop_mv_ops = {
38273 +static const struct hptiop_adapter_ops hptiop_mv_ops = {
38274 .iop_wait_ready = iop_wait_ready_mv,
38275 .internal_memalloc = hptiop_internal_memalloc_mv,
38276 .internal_memfree = hptiop_internal_memfree_mv,
38277 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvfc.c linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvfc.c
38278 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-19 00:06:34.000000000 -0400
38279 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvfc.c 2011-05-22 19:36:32.000000000 -0400
38280 @@ -4881,7 +4881,7 @@ static struct vio_device_id ibmvfc_devic
38281 };
38282 MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
38283
38284 -static struct dev_pm_ops ibmvfc_pm_ops = {
38285 +static const struct dev_pm_ops ibmvfc_pm_ops = {
38286 .resume = ibmvfc_resume
38287 };
38288
38289 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.c linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.c
38290 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-19 00:06:34.000000000 -0400
38291 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.c 2011-05-22 19:36:32.000000000 -0400
38292 @@ -104,7 +104,7 @@ static struct scsi_transport_template *i
38293
38294 #define IBMVSCSI_VERSION "1.5.9"
38295
38296 -static struct ibmvscsi_ops *ibmvscsi_ops;
38297 +static const struct ibmvscsi_ops *ibmvscsi_ops;
38298
38299 MODULE_DESCRIPTION("IBM Virtual SCSI");
38300 MODULE_AUTHOR("Dave Boutcher");
38301 @@ -2059,7 +2059,7 @@ static struct vio_device_id ibmvscsi_dev
38302 };
38303 MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
38304
38305 -static struct dev_pm_ops ibmvscsi_pm_ops = {
38306 +static const struct dev_pm_ops ibmvscsi_pm_ops = {
38307 .resume = ibmvscsi_resume
38308 };
38309
38310 @@ -2075,7 +2075,7 @@ static struct vio_driver ibmvscsi_driver
38311 }
38312 };
38313
38314 -static struct srp_function_template ibmvscsi_transport_functions = {
38315 +static const struct srp_function_template ibmvscsi_transport_functions = {
38316 };
38317
38318 int __init ibmvscsi_module_init(void)
38319 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.h linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.h
38320 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-19 00:06:34.000000000 -0400
38321 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvscsi.h 2011-05-22 19:36:32.000000000 -0400
38322 @@ -127,7 +127,7 @@ struct ibmvscsi_ops {
38323 int (*resume) (struct ibmvscsi_host_data *hostdata);
38324 };
38325
38326 -extern struct ibmvscsi_ops iseriesvscsi_ops;
38327 -extern struct ibmvscsi_ops rpavscsi_ops;
38328 +extern const struct ibmvscsi_ops iseriesvscsi_ops;
38329 +extern const struct ibmvscsi_ops rpavscsi_ops;
38330
38331 #endif /* IBMVSCSI_H */
38332 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvstgt.c linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvstgt.c
38333 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-19 00:06:34.000000000 -0400
38334 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/ibmvstgt.c 2011-05-22 19:36:32.000000000 -0400
38335 @@ -951,7 +951,7 @@ static int get_system_info(void)
38336 return 0;
38337 }
38338
38339 -static struct srp_function_template ibmvstgt_transport_functions = {
38340 +static const struct srp_function_template ibmvstgt_transport_functions = {
38341 .tsk_mgmt_response = ibmvstgt_tsk_mgmt_response,
38342 .it_nexus_response = ibmvstgt_it_nexus_response,
38343 };
38344 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/iseries_vscsi.c linux-2.6.39.2/drivers/scsi/ibmvscsi/iseries_vscsi.c
38345 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38346 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/iseries_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38347 @@ -163,7 +163,7 @@ static int iseriesvscsi_resume(struct ib
38348 return 0;
38349 }
38350
38351 -struct ibmvscsi_ops iseriesvscsi_ops = {
38352 +const struct ibmvscsi_ops iseriesvscsi_ops = {
38353 .init_crq_queue = iseriesvscsi_init_crq_queue,
38354 .release_crq_queue = iseriesvscsi_release_crq_queue,
38355 .reset_crq_queue = iseriesvscsi_reset_crq_queue,
38356 diff -urNp linux-2.6.39.2/drivers/scsi/ibmvscsi/rpa_vscsi.c linux-2.6.39.2/drivers/scsi/ibmvscsi/rpa_vscsi.c
38357 --- linux-2.6.39.2/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-19 00:06:34.000000000 -0400
38358 +++ linux-2.6.39.2/drivers/scsi/ibmvscsi/rpa_vscsi.c 2011-05-22 19:36:32.000000000 -0400
38359 @@ -358,7 +358,7 @@ static int rpavscsi_resume(struct ibmvsc
38360 return 0;
38361 }
38362
38363 -struct ibmvscsi_ops rpavscsi_ops = {
38364 +const struct ibmvscsi_ops rpavscsi_ops = {
38365 .init_crq_queue = rpavscsi_init_crq_queue,
38366 .release_crq_queue = rpavscsi_release_crq_queue,
38367 .reset_crq_queue = rpavscsi_reset_crq_queue,
38368 diff -urNp linux-2.6.39.2/drivers/scsi/ipr.c linux-2.6.39.2/drivers/scsi/ipr.c
38369 --- linux-2.6.39.2/drivers/scsi/ipr.c 2011-05-19 00:06:34.000000000 -0400
38370 +++ linux-2.6.39.2/drivers/scsi/ipr.c 2011-05-22 19:36:32.000000000 -0400
38371 @@ -6210,7 +6210,7 @@ static bool ipr_qc_fill_rtf(struct ata_q
38372 return true;
38373 }
38374
38375 -static struct ata_port_operations ipr_sata_ops = {
38376 +static const struct ata_port_operations ipr_sata_ops = {
38377 .phy_reset = ipr_ata_phy_reset,
38378 .hardreset = ipr_sata_reset,
38379 .post_internal_cmd = ipr_ata_post_internal,
38380 diff -urNp linux-2.6.39.2/drivers/scsi/libfc/fc_exch.c linux-2.6.39.2/drivers/scsi/libfc/fc_exch.c
38381 --- linux-2.6.39.2/drivers/scsi/libfc/fc_exch.c 2011-05-19 00:06:34.000000000 -0400
38382 +++ linux-2.6.39.2/drivers/scsi/libfc/fc_exch.c 2011-05-22 19:36:32.000000000 -0400
38383 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
38384 * all together if not used XXX
38385 */
38386 struct {
38387 - atomic_t no_free_exch;
38388 - atomic_t no_free_exch_xid;
38389 - atomic_t xid_not_found;
38390 - atomic_t xid_busy;
38391 - atomic_t seq_not_found;
38392 - atomic_t non_bls_resp;
38393 + atomic_unchecked_t no_free_exch;
38394 + atomic_unchecked_t no_free_exch_xid;
38395 + atomic_unchecked_t xid_not_found;
38396 + atomic_unchecked_t xid_busy;
38397 + atomic_unchecked_t seq_not_found;
38398 + atomic_unchecked_t non_bls_resp;
38399 } stats;
38400 };
38401
38402 @@ -700,7 +700,7 @@ static struct fc_exch *fc_exch_em_alloc(
38403 /* allocate memory for exchange */
38404 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38405 if (!ep) {
38406 - atomic_inc(&mp->stats.no_free_exch);
38407 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38408 goto out;
38409 }
38410 memset(ep, 0, sizeof(*ep));
38411 @@ -761,7 +761,7 @@ out:
38412 return ep;
38413 err:
38414 spin_unlock_bh(&pool->lock);
38415 - atomic_inc(&mp->stats.no_free_exch_xid);
38416 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38417 mempool_free(ep, mp->ep_pool);
38418 return NULL;
38419 }
38420 @@ -906,7 +906,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38421 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38422 ep = fc_exch_find(mp, xid);
38423 if (!ep) {
38424 - atomic_inc(&mp->stats.xid_not_found);
38425 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38426 reject = FC_RJT_OX_ID;
38427 goto out;
38428 }
38429 @@ -936,7 +936,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38430 ep = fc_exch_find(mp, xid);
38431 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38432 if (ep) {
38433 - atomic_inc(&mp->stats.xid_busy);
38434 + atomic_inc_unchecked(&mp->stats.xid_busy);
38435 reject = FC_RJT_RX_ID;
38436 goto rel;
38437 }
38438 @@ -947,7 +947,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38439 }
38440 xid = ep->xid; /* get our XID */
38441 } else if (!ep) {
38442 - atomic_inc(&mp->stats.xid_not_found);
38443 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38444 reject = FC_RJT_RX_ID; /* XID not found */
38445 goto out;
38446 }
38447 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_look
38448 } else {
38449 sp = &ep->seq;
38450 if (sp->id != fh->fh_seq_id) {
38451 - atomic_inc(&mp->stats.seq_not_found);
38452 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38453 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
38454 goto rel;
38455 }
38456 @@ -1392,22 +1392,22 @@ static void fc_exch_recv_seq_resp(struct
38457
38458 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38459 if (!ep) {
38460 - atomic_inc(&mp->stats.xid_not_found);
38461 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38462 goto out;
38463 }
38464 if (ep->esb_stat & ESB_ST_COMPLETE) {
38465 - atomic_inc(&mp->stats.xid_not_found);
38466 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38467 goto rel;
38468 }
38469 if (ep->rxid == FC_XID_UNKNOWN)
38470 ep->rxid = ntohs(fh->fh_rx_id);
38471 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38472 - atomic_inc(&mp->stats.xid_not_found);
38473 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38474 goto rel;
38475 }
38476 if (ep->did != ntoh24(fh->fh_s_id) &&
38477 ep->did != FC_FID_FLOGI) {
38478 - atomic_inc(&mp->stats.xid_not_found);
38479 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38480 goto rel;
38481 }
38482 sof = fr_sof(fp);
38483 @@ -1416,7 +1416,7 @@ static void fc_exch_recv_seq_resp(struct
38484 sp->ssb_stat |= SSB_ST_RESP;
38485 sp->id = fh->fh_seq_id;
38486 } else if (sp->id != fh->fh_seq_id) {
38487 - atomic_inc(&mp->stats.seq_not_found);
38488 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38489 goto rel;
38490 }
38491
38492 @@ -1479,9 +1479,9 @@ static void fc_exch_recv_resp(struct fc_
38493 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38494
38495 if (!sp)
38496 - atomic_inc(&mp->stats.xid_not_found);
38497 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38498 else
38499 - atomic_inc(&mp->stats.non_bls_resp);
38500 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38501
38502 fc_frame_free(fp);
38503 }
38504 diff -urNp linux-2.6.39.2/drivers/scsi/libfc/fc_lport.c linux-2.6.39.2/drivers/scsi/libfc/fc_lport.c
38505 --- linux-2.6.39.2/drivers/scsi/libfc/fc_lport.c 2011-05-19 00:06:34.000000000 -0400
38506 +++ linux-2.6.39.2/drivers/scsi/libfc/fc_lport.c 2011-05-22 19:36:32.000000000 -0400
38507 @@ -1299,7 +1299,7 @@ static void fc_lport_enter_ns(struct fc_
38508 fc_lport_error(lport, fp);
38509 }
38510
38511 -static struct fc_rport_operations fc_lport_rport_ops = {
38512 +static const struct fc_rport_operations fc_lport_rport_ops = {
38513 .event_callback = fc_lport_rport_callback,
38514 };
38515
38516 diff -urNp linux-2.6.39.2/drivers/scsi/libfc/fc_rport.c linux-2.6.39.2/drivers/scsi/libfc/fc_rport.c
38517 --- linux-2.6.39.2/drivers/scsi/libfc/fc_rport.c 2011-05-19 00:06:34.000000000 -0400
38518 +++ linux-2.6.39.2/drivers/scsi/libfc/fc_rport.c 2011-05-22 19:36:32.000000000 -0400
38519 @@ -256,7 +256,7 @@ static void fc_rport_work(struct work_st
38520 struct fc_rport_libfc_priv *rpriv;
38521 enum fc_rport_event event;
38522 struct fc_lport *lport = rdata->local_port;
38523 - struct fc_rport_operations *rport_ops;
38524 + const struct fc_rport_operations *rport_ops;
38525 struct fc_rport_identifiers ids;
38526 struct fc_rport *rport;
38527 struct fc4_prov *prov;
38528 diff -urNp linux-2.6.39.2/drivers/scsi/libsas/sas_ata.c linux-2.6.39.2/drivers/scsi/libsas/sas_ata.c
38529 --- linux-2.6.39.2/drivers/scsi/libsas/sas_ata.c 2011-05-19 00:06:34.000000000 -0400
38530 +++ linux-2.6.39.2/drivers/scsi/libsas/sas_ata.c 2011-05-22 19:36:32.000000000 -0400
38531 @@ -307,14 +307,14 @@ static void sas_ata_post_internal(struct
38532 }
38533 }
38534
38535 -static struct ata_port_operations sas_sata_ops = {
38536 +static const struct ata_port_operations sas_sata_ops = {
38537 .prereset = ata_std_prereset,
38538 .softreset = NULL,
38539 .hardreset = sas_ata_hard_reset,
38540 .postreset = ata_std_postreset,
38541 .error_handler = ata_std_error_handler,
38542 .post_internal_cmd = sas_ata_post_internal,
38543 - .qc_defer = ata_std_qc_defer,
38544 + .qc_defer = ata_std_qc_defer,
38545 .qc_prep = ata_noop_qc_prep,
38546 .qc_issue = sas_ata_qc_issue,
38547 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38548 diff -urNp linux-2.6.39.2/drivers/scsi/lpfc/lpfc_debugfs.c linux-2.6.39.2/drivers/scsi/lpfc/lpfc_debugfs.c
38549 --- linux-2.6.39.2/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-19 00:06:34.000000000 -0400
38550 +++ linux-2.6.39.2/drivers/scsi/lpfc/lpfc_debugfs.c 2011-05-22 19:36:32.000000000 -0400
38551 @@ -104,7 +104,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_
38552
38553 #include <linux/debugfs.h>
38554
38555 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38556 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38557 static unsigned long lpfc_debugfs_start_time = 0L;
38558
38559 /* iDiag */
38560 @@ -141,7 +141,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_v
38561 lpfc_debugfs_enable = 0;
38562
38563 len = 0;
38564 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38565 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38566 (lpfc_debugfs_max_disc_trc - 1);
38567 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38568 dtp = vport->disc_trc + i;
38569 @@ -202,7 +202,7 @@ lpfc_debugfs_slow_ring_trc_data(struct l
38570 lpfc_debugfs_enable = 0;
38571
38572 len = 0;
38573 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38574 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38575 (lpfc_debugfs_max_slow_ring_trc - 1);
38576 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38577 dtp = phba->slow_ring_trc + i;
38578 @@ -380,6 +380,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpf
38579 uint32_t *ptr;
38580 char buffer[1024];
38581
38582 + pax_track_stack();
38583 +
38584 off = 0;
38585 spin_lock_irq(&phba->hbalock);
38586
38587 @@ -617,14 +619,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport
38588 !vport || !vport->disc_trc)
38589 return;
38590
38591 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38592 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38593 (lpfc_debugfs_max_disc_trc - 1);
38594 dtp = vport->disc_trc + index;
38595 dtp->fmt = fmt;
38596 dtp->data1 = data1;
38597 dtp->data2 = data2;
38598 dtp->data3 = data3;
38599 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38600 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38601 dtp->jif = jiffies;
38602 #endif
38603 return;
38604 @@ -655,14 +657,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_h
38605 !phba || !phba->slow_ring_trc)
38606 return;
38607
38608 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38609 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38610 (lpfc_debugfs_max_slow_ring_trc - 1);
38611 dtp = phba->slow_ring_trc + index;
38612 dtp->fmt = fmt;
38613 dtp->data1 = data1;
38614 dtp->data2 = data2;
38615 dtp->data3 = data3;
38616 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38617 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38618 dtp->jif = jiffies;
38619 #endif
38620 return;
38621 @@ -2145,7 +2147,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38622 "slow_ring buffer\n");
38623 goto debug_failed;
38624 }
38625 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38626 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38627 memset(phba->slow_ring_trc, 0,
38628 (sizeof(struct lpfc_debugfs_trc) *
38629 lpfc_debugfs_max_slow_ring_trc));
38630 @@ -2191,7 +2193,7 @@ lpfc_debugfs_initialize(struct lpfc_vpor
38631 "buffer\n");
38632 goto debug_failed;
38633 }
38634 - atomic_set(&vport->disc_trc_cnt, 0);
38635 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38636
38637 snprintf(name, sizeof(name), "discovery_trace");
38638 vport->debug_disc_trc =
38639 diff -urNp linux-2.6.39.2/drivers/scsi/lpfc/lpfc.h linux-2.6.39.2/drivers/scsi/lpfc/lpfc.h
38640 --- linux-2.6.39.2/drivers/scsi/lpfc/lpfc.h 2011-05-19 00:06:34.000000000 -0400
38641 +++ linux-2.6.39.2/drivers/scsi/lpfc/lpfc.h 2011-05-22 19:36:32.000000000 -0400
38642 @@ -419,7 +419,7 @@ struct lpfc_vport {
38643 struct dentry *debug_nodelist;
38644 struct dentry *vport_debugfs_root;
38645 struct lpfc_debugfs_trc *disc_trc;
38646 - atomic_t disc_trc_cnt;
38647 + atomic_unchecked_t disc_trc_cnt;
38648 #endif
38649 uint8_t stat_data_enabled;
38650 uint8_t stat_data_blocked;
38651 @@ -785,8 +785,8 @@ struct lpfc_hba {
38652 struct timer_list fabric_block_timer;
38653 unsigned long bit_flags;
38654 #define FABRIC_COMANDS_BLOCKED 0
38655 - atomic_t num_rsrc_err;
38656 - atomic_t num_cmd_success;
38657 + atomic_unchecked_t num_rsrc_err;
38658 + atomic_unchecked_t num_cmd_success;
38659 unsigned long last_rsrc_error_time;
38660 unsigned long last_ramp_down_time;
38661 unsigned long last_ramp_up_time;
38662 @@ -800,7 +800,7 @@ struct lpfc_hba {
38663 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
38664 struct dentry *debug_slow_ring_trc;
38665 struct lpfc_debugfs_trc *slow_ring_trc;
38666 - atomic_t slow_ring_trc_cnt;
38667 + atomic_unchecked_t slow_ring_trc_cnt;
38668 /* iDiag debugfs sub-directory */
38669 struct dentry *idiag_root;
38670 struct dentry *idiag_pci_cfg;
38671 diff -urNp linux-2.6.39.2/drivers/scsi/lpfc/lpfc_scsi.c linux-2.6.39.2/drivers/scsi/lpfc/lpfc_scsi.c
38672 --- linux-2.6.39.2/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-19 00:06:34.000000000 -0400
38673 +++ linux-2.6.39.2/drivers/scsi/lpfc/lpfc_scsi.c 2011-05-22 19:36:32.000000000 -0400
38674 @@ -297,7 +297,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hb
38675 uint32_t evt_posted;
38676
38677 spin_lock_irqsave(&phba->hbalock, flags);
38678 - atomic_inc(&phba->num_rsrc_err);
38679 + atomic_inc_unchecked(&phba->num_rsrc_err);
38680 phba->last_rsrc_error_time = jiffies;
38681
38682 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38683 @@ -338,7 +338,7 @@ lpfc_rampup_queue_depth(struct lpfc_vpor
38684 unsigned long flags;
38685 struct lpfc_hba *phba = vport->phba;
38686 uint32_t evt_posted;
38687 - atomic_inc(&phba->num_cmd_success);
38688 + atomic_inc_unchecked(&phba->num_cmd_success);
38689
38690 if (vport->cfg_lun_queue_depth <= queue_depth)
38691 return;
38692 @@ -382,8 +382,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38693 unsigned long num_rsrc_err, num_cmd_success;
38694 int i;
38695
38696 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38697 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38698 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38699 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38700
38701 vports = lpfc_create_vport_work_array(phba);
38702 if (vports != NULL)
38703 @@ -403,8 +403,8 @@ lpfc_ramp_down_queue_handler(struct lpfc
38704 }
38705 }
38706 lpfc_destroy_vport_work_array(phba, vports);
38707 - atomic_set(&phba->num_rsrc_err, 0);
38708 - atomic_set(&phba->num_cmd_success, 0);
38709 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38710 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38711 }
38712
38713 /**
38714 @@ -438,8 +438,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_h
38715 }
38716 }
38717 lpfc_destroy_vport_work_array(phba, vports);
38718 - atomic_set(&phba->num_rsrc_err, 0);
38719 - atomic_set(&phba->num_cmd_success, 0);
38720 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38721 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38722 }
38723
38724 /**
38725 diff -urNp linux-2.6.39.2/drivers/scsi/mac_esp.c linux-2.6.39.2/drivers/scsi/mac_esp.c
38726 --- linux-2.6.39.2/drivers/scsi/mac_esp.c 2011-05-19 00:06:34.000000000 -0400
38727 +++ linux-2.6.39.2/drivers/scsi/mac_esp.c 2011-05-22 19:36:32.000000000 -0400
38728 @@ -473,7 +473,7 @@ static irqreturn_t mac_scsi_esp_intr(int
38729 return IRQ_HANDLED;
38730 }
38731
38732 -static struct esp_driver_ops mac_esp_ops = {
38733 +static const struct esp_driver_ops mac_esp_ops = {
38734 .esp_write8 = mac_esp_write8,
38735 .esp_read8 = mac_esp_read8,
38736 .map_single = mac_esp_map_single,
38737 diff -urNp linux-2.6.39.2/drivers/scsi/megaraid/megaraid_mbox.c linux-2.6.39.2/drivers/scsi/megaraid/megaraid_mbox.c
38738 --- linux-2.6.39.2/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-19 00:06:34.000000000 -0400
38739 +++ linux-2.6.39.2/drivers/scsi/megaraid/megaraid_mbox.c 2011-05-22 19:36:32.000000000 -0400
38740 @@ -3510,6 +3510,8 @@ megaraid_cmm_register(adapter_t *adapter
38741 int rval;
38742 int i;
38743
38744 + pax_track_stack();
38745 +
38746 // Allocate memory for the base list of scb for management module.
38747 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
38748
38749 diff -urNp linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_base.c linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_base.c
38750 --- linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-19 00:06:34.000000000 -0400
38751 +++ linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_base.c 2011-05-22 19:36:32.000000000 -0400
38752 @@ -366,7 +366,7 @@ megasas_check_reset_xscale(struct megasa
38753 return 0;
38754 }
38755
38756 -static struct megasas_instance_template megasas_instance_template_xscale = {
38757 +static const struct megasas_instance_template megasas_instance_template_xscale = {
38758
38759 .fire_cmd = megasas_fire_cmd_xscale,
38760 .enable_intr = megasas_enable_intr_xscale,
38761 @@ -497,7 +497,7 @@ megasas_check_reset_ppc(struct megasas_i
38762 {
38763 return 0;
38764 }
38765 -static struct megasas_instance_template megasas_instance_template_ppc = {
38766 +static const struct megasas_instance_template megasas_instance_template_ppc = {
38767
38768 .fire_cmd = megasas_fire_cmd_ppc,
38769 .enable_intr = megasas_enable_intr_ppc,
38770 @@ -623,7 +623,7 @@ megasas_check_reset_skinny(struct megasa
38771 return 0;
38772 }
38773
38774 -static struct megasas_instance_template megasas_instance_template_skinny = {
38775 +static const struct megasas_instance_template megasas_instance_template_skinny = {
38776
38777 .fire_cmd = megasas_fire_cmd_skinny,
38778 .enable_intr = megasas_enable_intr_skinny,
38779 @@ -810,7 +810,7 @@ megasas_check_reset_gen2(struct megasas_
38780 return 0;
38781 }
38782
38783 -static struct megasas_instance_template megasas_instance_template_gen2 = {
38784 +static const struct megasas_instance_template megasas_instance_template_gen2 = {
38785
38786 .fire_cmd = megasas_fire_cmd_gen2,
38787 .enable_intr = megasas_enable_intr_gen2,
38788 @@ -834,7 +834,7 @@ static struct megasas_instance_template
38789 /*
38790 * Template added for TB (Fusion)
38791 */
38792 -extern struct megasas_instance_template megasas_instance_template_fusion;
38793 +extern const struct megasas_instance_template megasas_instance_template_fusion;
38794
38795 /**
38796 * megasas_issue_polled - Issues a polling command
38797 diff -urNp linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_fusion.c linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_fusion.c
38798 --- linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-19 00:06:34.000000000 -0400
38799 +++ linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas_fusion.c 2011-05-22 19:36:32.000000000 -0400
38800 @@ -2236,7 +2236,7 @@ void megasas_fusion_ocr_wq(struct work_s
38801 megasas_reset_fusion(instance->host);
38802 }
38803
38804 -struct megasas_instance_template megasas_instance_template_fusion = {
38805 +const struct megasas_instance_template megasas_instance_template_fusion = {
38806 .fire_cmd = megasas_fire_cmd_fusion,
38807 .enable_intr = megasas_enable_intr_fusion,
38808 .disable_intr = megasas_disable_intr_fusion,
38809 diff -urNp linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas.h linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas.h
38810 --- linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas.h 2011-05-19 00:06:34.000000000 -0400
38811 +++ linux-2.6.39.2/drivers/scsi/megaraid/megaraid_sas.h 2011-05-22 19:36:32.000000000 -0400
38812 @@ -1330,7 +1330,7 @@ struct megasas_instance {
38813 atomic_t fw_outstanding;
38814 atomic_t fw_reset_no_pci_access;
38815
38816 - struct megasas_instance_template *instancet;
38817 + const struct megasas_instance_template *instancet;
38818 struct tasklet_struct isr_tasklet;
38819 struct work_struct work_init;
38820
38821 diff -urNp linux-2.6.39.2/drivers/scsi/ncr53c8xx.c linux-2.6.39.2/drivers/scsi/ncr53c8xx.c
38822 --- linux-2.6.39.2/drivers/scsi/ncr53c8xx.c 2011-05-19 00:06:34.000000000 -0400
38823 +++ linux-2.6.39.2/drivers/scsi/ncr53c8xx.c 2011-05-22 19:36:32.000000000 -0400
38824 @@ -8606,7 +8606,7 @@ static void ncr53c8xx_get_signalling(str
38825 spi_signalling(shost) = type;
38826 }
38827
38828 -static struct spi_function_template ncr53c8xx_transport_functions = {
38829 +static struct spi_function_template ncr53c8xx_transport_functions = {
38830 .set_period = ncr53c8xx_set_period,
38831 .show_period = 1,
38832 .set_offset = ncr53c8xx_set_offset,
38833 diff -urNp linux-2.6.39.2/drivers/scsi/osd/osd_initiator.c linux-2.6.39.2/drivers/scsi/osd/osd_initiator.c
38834 --- linux-2.6.39.2/drivers/scsi/osd/osd_initiator.c 2011-05-19 00:06:34.000000000 -0400
38835 +++ linux-2.6.39.2/drivers/scsi/osd/osd_initiator.c 2011-05-22 19:36:32.000000000 -0400
38836 @@ -97,6 +97,8 @@ static int _osd_get_print_system_info(st
38837 int nelem = ARRAY_SIZE(get_attrs), a = 0;
38838 int ret;
38839
38840 + pax_track_stack();
38841 +
38842 or = osd_start_request(od, GFP_KERNEL);
38843 if (!or)
38844 return -ENOMEM;
38845 diff -urNp linux-2.6.39.2/drivers/scsi/pmcraid.c linux-2.6.39.2/drivers/scsi/pmcraid.c
38846 --- linux-2.6.39.2/drivers/scsi/pmcraid.c 2011-05-19 00:06:34.000000000 -0400
38847 +++ linux-2.6.39.2/drivers/scsi/pmcraid.c 2011-05-22 19:36:32.000000000 -0400
38848 @@ -201,8 +201,8 @@ static int pmcraid_slave_alloc(struct sc
38849 res->scsi_dev = scsi_dev;
38850 scsi_dev->hostdata = res;
38851 res->change_detected = 0;
38852 - atomic_set(&res->read_failures, 0);
38853 - atomic_set(&res->write_failures, 0);
38854 + atomic_set_unchecked(&res->read_failures, 0);
38855 + atomic_set_unchecked(&res->write_failures, 0);
38856 rc = 0;
38857 }
38858 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38859 @@ -2677,9 +2677,9 @@ static int pmcraid_error_handler(struct
38860
38861 /* If this was a SCSI read/write command keep count of errors */
38862 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38863 - atomic_inc(&res->read_failures);
38864 + atomic_inc_unchecked(&res->read_failures);
38865 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38866 - atomic_inc(&res->write_failures);
38867 + atomic_inc_unchecked(&res->write_failures);
38868
38869 if (!RES_IS_GSCSI(res->cfg_entry) &&
38870 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38871 @@ -3535,7 +3535,7 @@ static int pmcraid_queuecommand_lck(
38872 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38873 * hrrq_id assigned here in queuecommand
38874 */
38875 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38876 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38877 pinstance->num_hrrq;
38878 cmd->cmd_done = pmcraid_io_done;
38879
38880 @@ -3860,7 +3860,7 @@ static long pmcraid_ioctl_passthrough(
38881 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38882 * hrrq_id assigned here in queuecommand
38883 */
38884 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38885 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38886 pinstance->num_hrrq;
38887
38888 if (request_size) {
38889 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(stru
38890
38891 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38892 /* add resources only after host is added into system */
38893 - if (!atomic_read(&pinstance->expose_resources))
38894 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38895 return;
38896
38897 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38898 @@ -5329,8 +5329,8 @@ static int __devinit pmcraid_init_instan
38899 init_waitqueue_head(&pinstance->reset_wait_q);
38900
38901 atomic_set(&pinstance->outstanding_cmds, 0);
38902 - atomic_set(&pinstance->last_message_id, 0);
38903 - atomic_set(&pinstance->expose_resources, 0);
38904 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38905 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38906
38907 INIT_LIST_HEAD(&pinstance->free_res_q);
38908 INIT_LIST_HEAD(&pinstance->used_res_q);
38909 @@ -6045,7 +6045,7 @@ static int __devinit pmcraid_probe(
38910 /* Schedule worker thread to handle CCN and take care of adding and
38911 * removing devices to OS
38912 */
38913 - atomic_set(&pinstance->expose_resources, 1);
38914 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38915 schedule_work(&pinstance->worker_q);
38916 return rc;
38917
38918 diff -urNp linux-2.6.39.2/drivers/scsi/pmcraid.h linux-2.6.39.2/drivers/scsi/pmcraid.h
38919 --- linux-2.6.39.2/drivers/scsi/pmcraid.h 2011-05-19 00:06:34.000000000 -0400
38920 +++ linux-2.6.39.2/drivers/scsi/pmcraid.h 2011-05-22 19:36:32.000000000 -0400
38921 @@ -750,7 +750,7 @@ struct pmcraid_instance {
38922 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38923
38924 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38925 - atomic_t last_message_id;
38926 + atomic_unchecked_t last_message_id;
38927
38928 /* configuration table */
38929 struct pmcraid_config_table *cfg_table;
38930 @@ -779,7 +779,7 @@ struct pmcraid_instance {
38931 atomic_t outstanding_cmds;
38932
38933 /* should add/delete resources to mid-layer now ?*/
38934 - atomic_t expose_resources;
38935 + atomic_unchecked_t expose_resources;
38936
38937
38938
38939 @@ -815,8 +815,8 @@ struct pmcraid_resource_entry {
38940 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38941 };
38942 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38943 - atomic_t read_failures; /* count of failed READ commands */
38944 - atomic_t write_failures; /* count of failed WRITE commands */
38945 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38946 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38947
38948 /* To indicate add/delete/modify during CCN */
38949 u8 change_detected;
38950 diff -urNp linux-2.6.39.2/drivers/scsi/qla2xxx/qla_os.c linux-2.6.39.2/drivers/scsi/qla2xxx/qla_os.c
38951 --- linux-2.6.39.2/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:04:14.000000000 -0400
38952 +++ linux-2.6.39.2/drivers/scsi/qla2xxx/qla_os.c 2011-06-03 00:32:06.000000000 -0400
38953 @@ -4103,7 +4103,7 @@ static struct pci_driver qla2xxx_pci_dri
38954 .err_handler = &qla2xxx_err_handler,
38955 };
38956
38957 -static struct file_operations apidev_fops = {
38958 +static const struct file_operations apidev_fops = {
38959 .owner = THIS_MODULE,
38960 .llseek = noop_llseek,
38961 };
38962 diff -urNp linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_def.h linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_def.h
38963 --- linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_def.h 2011-05-19 00:06:34.000000000 -0400
38964 +++ linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_def.h 2011-05-22 19:36:32.000000000 -0400
38965 @@ -256,7 +256,7 @@ struct ddb_entry {
38966 atomic_t retry_relogin_timer; /* Min Time between relogins
38967 * (4000 only) */
38968 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
38969 - atomic_t relogin_retry_count; /* Num of times relogin has been
38970 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38971 * retried */
38972
38973 uint16_t port;
38974 diff -urNp linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_init.c linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_init.c
38975 --- linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_init.c 2011-05-19 00:06:34.000000000 -0400
38976 +++ linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_init.c 2011-05-22 19:36:32.000000000 -0400
38977 @@ -680,7 +680,7 @@ static struct ddb_entry * qla4xxx_alloc_
38978 ddb_entry->fw_ddb_index = fw_ddb_index;
38979 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38980 atomic_set(&ddb_entry->relogin_timer, 0);
38981 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38982 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38983 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38984 list_add_tail(&ddb_entry->list, &ha->ddb_list);
38985 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
38986 @@ -1433,7 +1433,7 @@ int qla4xxx_process_ddb_changed(struct s
38987 if ((ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) &&
38988 (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)) {
38989 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
38990 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38991 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38992 atomic_set(&ddb_entry->relogin_timer, 0);
38993 clear_bit(DF_RELOGIN, &ddb_entry->flags);
38994 iscsi_unblock_session(ddb_entry->sess);
38995 diff -urNp linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_os.c linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_os.c
38996 --- linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_os.c 2011-05-19 00:06:34.000000000 -0400
38997 +++ linux-2.6.39.2/drivers/scsi/qla4xxx/ql4_os.c 2011-05-22 19:36:32.000000000 -0400
38998 @@ -802,13 +802,13 @@ static void qla4xxx_timer(struct scsi_ql
38999 ddb_entry->fw_ddb_device_state ==
39000 DDB_DS_SESSION_FAILED) {
39001 /* Reset retry relogin timer */
39002 - atomic_inc(&ddb_entry->relogin_retry_count);
39003 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39004 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
39005 " timed out-retrying"
39006 " relogin (%d)\n",
39007 ha->host_no,
39008 ddb_entry->fw_ddb_index,
39009 - atomic_read(&ddb_entry->
39010 + atomic_read_unchecked(&ddb_entry->
39011 relogin_retry_count))
39012 );
39013 start_dpc++;
39014 diff -urNp linux-2.6.39.2/drivers/scsi/scsi.c linux-2.6.39.2/drivers/scsi/scsi.c
39015 --- linux-2.6.39.2/drivers/scsi/scsi.c 2011-05-19 00:06:34.000000000 -0400
39016 +++ linux-2.6.39.2/drivers/scsi/scsi.c 2011-05-22 19:36:32.000000000 -0400
39017 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *
39018 unsigned long timeout;
39019 int rtn = 0;
39020
39021 - atomic_inc(&cmd->device->iorequest_cnt);
39022 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39023
39024 /* check if the device is still usable */
39025 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39026 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_debug.c linux-2.6.39.2/drivers/scsi/scsi_debug.c
39027 --- linux-2.6.39.2/drivers/scsi/scsi_debug.c 2011-05-19 00:06:34.000000000 -0400
39028 +++ linux-2.6.39.2/drivers/scsi/scsi_debug.c 2011-05-22 19:36:32.000000000 -0400
39029 @@ -1493,6 +1493,8 @@ static int resp_mode_select(struct scsi_
39030 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
39031 unsigned char *cmd = (unsigned char *)scp->cmnd;
39032
39033 + pax_track_stack();
39034 +
39035 if ((errsts = check_readiness(scp, 1, devip)))
39036 return errsts;
39037 memset(arr, 0, sizeof(arr));
39038 @@ -1590,6 +1592,8 @@ static int resp_log_sense(struct scsi_cm
39039 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
39040 unsigned char *cmd = (unsigned char *)scp->cmnd;
39041
39042 + pax_track_stack();
39043 +
39044 if ((errsts = check_readiness(scp, 1, devip)))
39045 return errsts;
39046 memset(arr, 0, sizeof(arr));
39047 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_lib.c linux-2.6.39.2/drivers/scsi/scsi_lib.c
39048 --- linux-2.6.39.2/drivers/scsi/scsi_lib.c 2011-05-19 00:06:34.000000000 -0400
39049 +++ linux-2.6.39.2/drivers/scsi/scsi_lib.c 2011-05-22 19:36:32.000000000 -0400
39050 @@ -1410,7 +1410,7 @@ static void scsi_kill_request(struct req
39051 shost = sdev->host;
39052 scsi_init_cmd_errh(cmd);
39053 cmd->result = DID_NO_CONNECT << 16;
39054 - atomic_inc(&cmd->device->iorequest_cnt);
39055 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39056
39057 /*
39058 * SCSI request completion path will do scsi_device_unbusy(),
39059 @@ -1436,9 +1436,9 @@ static void scsi_softirq_done(struct req
39060
39061 INIT_LIST_HEAD(&cmd->eh_entry);
39062
39063 - atomic_inc(&cmd->device->iodone_cnt);
39064 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39065 if (cmd->result)
39066 - atomic_inc(&cmd->device->ioerr_cnt);
39067 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39068
39069 disposition = scsi_decide_disposition(cmd);
39070 if (disposition != SUCCESS &&
39071 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_sysfs.c linux-2.6.39.2/drivers/scsi/scsi_sysfs.c
39072 --- linux-2.6.39.2/drivers/scsi/scsi_sysfs.c 2011-06-25 12:55:22.000000000 -0400
39073 +++ linux-2.6.39.2/drivers/scsi/scsi_sysfs.c 2011-06-25 13:00:26.000000000 -0400
39074 @@ -622,7 +622,7 @@ show_iostat_##field(struct device *dev,
39075 char *buf) \
39076 { \
39077 struct scsi_device *sdev = to_scsi_device(dev); \
39078 - unsigned long long count = atomic_read(&sdev->field); \
39079 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39080 return snprintf(buf, 20, "0x%llx\n", count); \
39081 } \
39082 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39083 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_transport_fc.c linux-2.6.39.2/drivers/scsi/scsi_transport_fc.c
39084 --- linux-2.6.39.2/drivers/scsi/scsi_transport_fc.c 2011-05-19 00:06:34.000000000 -0400
39085 +++ linux-2.6.39.2/drivers/scsi/scsi_transport_fc.c 2011-05-22 19:36:32.000000000 -0400
39086 @@ -485,7 +485,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_
39087 * Netlink Infrastructure
39088 */
39089
39090 -static atomic_t fc_event_seq;
39091 +static atomic_unchecked_t fc_event_seq;
39092
39093 /**
39094 * fc_get_event_number - Obtain the next sequential FC event number
39095 @@ -498,7 +498,7 @@ static atomic_t fc_event_seq;
39096 u32
39097 fc_get_event_number(void)
39098 {
39099 - return atomic_add_return(1, &fc_event_seq);
39100 + return atomic_add_return_unchecked(1, &fc_event_seq);
39101 }
39102 EXPORT_SYMBOL(fc_get_event_number);
39103
39104 @@ -646,7 +646,7 @@ static __init int fc_transport_init(void
39105 {
39106 int error;
39107
39108 - atomic_set(&fc_event_seq, 0);
39109 + atomic_set_unchecked(&fc_event_seq, 0);
39110
39111 error = transport_class_register(&fc_host_class);
39112 if (error)
39113 @@ -836,7 +836,7 @@ static int fc_str_to_dev_loss(const char
39114 char *cp;
39115
39116 *val = simple_strtoul(buf, &cp, 0);
39117 - if ((*cp && (*cp != '\n')) || (*val < 0))
39118 + if (*cp && (*cp != '\n'))
39119 return -EINVAL;
39120 /*
39121 * Check for overflow; dev_loss_tmo is u32
39122 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_transport_iscsi.c linux-2.6.39.2/drivers/scsi/scsi_transport_iscsi.c
39123 --- linux-2.6.39.2/drivers/scsi/scsi_transport_iscsi.c 2011-05-19 00:06:34.000000000 -0400
39124 +++ linux-2.6.39.2/drivers/scsi/scsi_transport_iscsi.c 2011-05-22 19:36:32.000000000 -0400
39125 @@ -83,7 +83,7 @@ struct iscsi_internal {
39126 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
39127 };
39128
39129 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39130 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39131 static struct workqueue_struct *iscsi_eh_timer_workq;
39132
39133 /*
39134 @@ -761,7 +761,7 @@ int iscsi_add_session(struct iscsi_cls_s
39135 int err;
39136
39137 ihost = shost->shost_data;
39138 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39139 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39140
39141 if (id == ISCSI_MAX_TARGET) {
39142 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
39143 @@ -2200,7 +2200,7 @@ static __init int iscsi_transport_init(v
39144 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39145 ISCSI_TRANSPORT_VERSION);
39146
39147 - atomic_set(&iscsi_session_nr, 0);
39148 + atomic_set_unchecked(&iscsi_session_nr, 0);
39149
39150 err = class_register(&iscsi_transport_class);
39151 if (err)
39152 diff -urNp linux-2.6.39.2/drivers/scsi/scsi_transport_srp.c linux-2.6.39.2/drivers/scsi/scsi_transport_srp.c
39153 --- linux-2.6.39.2/drivers/scsi/scsi_transport_srp.c 2011-05-19 00:06:34.000000000 -0400
39154 +++ linux-2.6.39.2/drivers/scsi/scsi_transport_srp.c 2011-05-22 19:36:32.000000000 -0400
39155 @@ -33,7 +33,7 @@
39156 #include "scsi_transport_srp_internal.h"
39157
39158 struct srp_host_attrs {
39159 - atomic_t next_port_id;
39160 + atomic_unchecked_t next_port_id;
39161 };
39162 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39163
39164 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transpo
39165 struct Scsi_Host *shost = dev_to_shost(dev);
39166 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39167
39168 - atomic_set(&srp_host->next_port_id, 0);
39169 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39170 return 0;
39171 }
39172
39173 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct S
39174 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39175 rport->roles = ids->roles;
39176
39177 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39178 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39179 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39180
39181 transport_setup_device(&rport->dev);
39182 diff -urNp linux-2.6.39.2/drivers/scsi/sg.c linux-2.6.39.2/drivers/scsi/sg.c
39183 --- linux-2.6.39.2/drivers/scsi/sg.c 2011-05-19 00:06:34.000000000 -0400
39184 +++ linux-2.6.39.2/drivers/scsi/sg.c 2011-05-22 19:36:32.000000000 -0400
39185 @@ -2310,7 +2310,7 @@ struct sg_proc_leaf {
39186 const struct file_operations * fops;
39187 };
39188
39189 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
39190 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
39191 {"allow_dio", &adio_fops},
39192 {"debug", &debug_fops},
39193 {"def_reserved_size", &dressz_fops},
39194 @@ -2325,7 +2325,7 @@ sg_proc_init(void)
39195 {
39196 int k, mask;
39197 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
39198 - struct sg_proc_leaf * leaf;
39199 + const struct sg_proc_leaf * leaf;
39200
39201 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
39202 if (!sg_proc_sgp)
39203 diff -urNp linux-2.6.39.2/drivers/scsi/sym53c8xx_2/sym_glue.c linux-2.6.39.2/drivers/scsi/sym53c8xx_2/sym_glue.c
39204 --- linux-2.6.39.2/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-19 00:06:34.000000000 -0400
39205 +++ linux-2.6.39.2/drivers/scsi/sym53c8xx_2/sym_glue.c 2011-05-22 19:36:32.000000000 -0400
39206 @@ -1756,6 +1756,8 @@ static int __devinit sym2_probe(struct p
39207 int do_iounmap = 0;
39208 int do_disable_device = 1;
39209
39210 + pax_track_stack();
39211 +
39212 memset(&sym_dev, 0, sizeof(sym_dev));
39213 memset(&nvram, 0, sizeof(nvram));
39214 sym_dev.pdev = pdev;
39215 diff -urNp linux-2.6.39.2/drivers/scsi/vmw_pvscsi.c linux-2.6.39.2/drivers/scsi/vmw_pvscsi.c
39216 --- linux-2.6.39.2/drivers/scsi/vmw_pvscsi.c 2011-05-19 00:06:34.000000000 -0400
39217 +++ linux-2.6.39.2/drivers/scsi/vmw_pvscsi.c 2011-05-22 19:36:32.000000000 -0400
39218 @@ -447,6 +447,8 @@ static void pvscsi_setup_all_rings(const
39219 dma_addr_t base;
39220 unsigned i;
39221
39222 + pax_track_stack();
39223 +
39224 cmd.ringsStatePPN = adapter->ringStatePA >> PAGE_SHIFT;
39225 cmd.reqRingNumPages = adapter->req_pages;
39226 cmd.cmpRingNumPages = adapter->cmp_pages;
39227 diff -urNp linux-2.6.39.2/drivers/sh/clk/cpg.c linux-2.6.39.2/drivers/sh/clk/cpg.c
39228 --- linux-2.6.39.2/drivers/sh/clk/cpg.c 2011-06-03 00:04:14.000000000 -0400
39229 +++ linux-2.6.39.2/drivers/sh/clk/cpg.c 2011-06-03 00:32:06.000000000 -0400
39230 @@ -26,7 +26,7 @@ static void sh_clk_mstp32_disable(struct
39231 clk->enable_reg);
39232 }
39233
39234 -static struct clk_ops sh_clk_mstp32_clk_ops = {
39235 +static const struct clk_ops sh_clk_mstp32_clk_ops = {
39236 .enable = sh_clk_mstp32_enable,
39237 .disable = sh_clk_mstp32_disable,
39238 .recalc = followparent_recalc,
39239 @@ -150,7 +150,7 @@ static void sh_clk_div6_disable(struct c
39240 __raw_writel(value, clk->enable_reg);
39241 }
39242
39243 -static struct clk_ops sh_clk_div6_clk_ops = {
39244 +static const struct clk_ops sh_clk_div6_clk_ops = {
39245 .recalc = sh_clk_div6_recalc,
39246 .round_rate = sh_clk_div_round_rate,
39247 .set_rate = sh_clk_div6_set_rate,
39248 @@ -158,7 +158,7 @@ static struct clk_ops sh_clk_div6_clk_op
39249 .disable = sh_clk_div6_disable,
39250 };
39251
39252 -static struct clk_ops sh_clk_div6_reparent_clk_ops = {
39253 +static const struct clk_ops sh_clk_div6_reparent_clk_ops = {
39254 .recalc = sh_clk_div6_recalc,
39255 .round_rate = sh_clk_div_round_rate,
39256 .set_rate = sh_clk_div6_set_rate,
39257 @@ -282,13 +282,13 @@ static void sh_clk_div4_disable(struct c
39258 __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
39259 }
39260
39261 -static struct clk_ops sh_clk_div4_clk_ops = {
39262 +static const struct clk_ops sh_clk_div4_clk_ops = {
39263 .recalc = sh_clk_div4_recalc,
39264 .set_rate = sh_clk_div4_set_rate,
39265 .round_rate = sh_clk_div_round_rate,
39266 };
39267
39268 -static struct clk_ops sh_clk_div4_enable_clk_ops = {
39269 +static const struct clk_ops sh_clk_div4_enable_clk_ops = {
39270 .recalc = sh_clk_div4_recalc,
39271 .set_rate = sh_clk_div4_set_rate,
39272 .round_rate = sh_clk_div_round_rate,
39273 @@ -296,7 +296,7 @@ static struct clk_ops sh_clk_div4_enable
39274 .disable = sh_clk_div4_disable,
39275 };
39276
39277 -static struct clk_ops sh_clk_div4_reparent_clk_ops = {
39278 +static const struct clk_ops sh_clk_div4_reparent_clk_ops = {
39279 .recalc = sh_clk_div4_recalc,
39280 .set_rate = sh_clk_div4_set_rate,
39281 .round_rate = sh_clk_div_round_rate,
39282 diff -urNp linux-2.6.39.2/drivers/spi/dw_spi.h linux-2.6.39.2/drivers/spi/dw_spi.h
39283 --- linux-2.6.39.2/drivers/spi/dw_spi.h 2011-05-19 00:06:34.000000000 -0400
39284 +++ linux-2.6.39.2/drivers/spi/dw_spi.h 2011-05-22 19:36:32.000000000 -0400
39285 @@ -151,7 +151,7 @@ struct dw_spi {
39286 int dma_chan_done;
39287 struct device *dma_dev;
39288 dma_addr_t dma_addr; /* phy address of the Data register */
39289 - struct dw_spi_dma_ops *dma_ops;
39290 + const struct dw_spi_dma_ops *dma_ops;
39291 void *dma_priv; /* platform relate info */
39292 struct pci_dev *dmac;
39293
39294 diff -urNp linux-2.6.39.2/drivers/spi/dw_spi_mid.c linux-2.6.39.2/drivers/spi/dw_spi_mid.c
39295 --- linux-2.6.39.2/drivers/spi/dw_spi_mid.c 2011-05-19 00:06:34.000000000 -0400
39296 +++ linux-2.6.39.2/drivers/spi/dw_spi_mid.c 2011-05-22 19:36:32.000000000 -0400
39297 @@ -180,7 +180,7 @@ static int mid_spi_dma_transfer(struct d
39298 return 0;
39299 }
39300
39301 -static struct dw_spi_dma_ops mid_dma_ops = {
39302 +static const struct dw_spi_dma_ops mid_dma_ops = {
39303 .dma_init = mid_spi_dma_init,
39304 .dma_exit = mid_spi_dma_exit,
39305 .dma_transfer = mid_spi_dma_transfer,
39306 diff -urNp linux-2.6.39.2/drivers/spi/spi.c linux-2.6.39.2/drivers/spi/spi.c
39307 --- linux-2.6.39.2/drivers/spi/spi.c 2011-05-19 00:06:34.000000000 -0400
39308 +++ linux-2.6.39.2/drivers/spi/spi.c 2011-05-22 19:36:32.000000000 -0400
39309 @@ -1023,7 +1023,7 @@ int spi_bus_unlock(struct spi_master *ma
39310 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39311
39312 /* portable code must never pass more than 32 bytes */
39313 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39314 +#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
39315
39316 static u8 *buf;
39317
39318 diff -urNp linux-2.6.39.2/drivers/ssb/driver_pcicore.c linux-2.6.39.2/drivers/ssb/driver_pcicore.c
39319 --- linux-2.6.39.2/drivers/ssb/driver_pcicore.c 2011-05-19 00:06:34.000000000 -0400
39320 +++ linux-2.6.39.2/drivers/ssb/driver_pcicore.c 2011-05-22 19:36:32.000000000 -0400
39321 @@ -223,7 +223,7 @@ static int ssb_pcicore_write_config(stru
39322 return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
39323 }
39324
39325 -static struct pci_ops ssb_pcicore_pciops = {
39326 +static const struct pci_ops ssb_pcicore_pciops = {
39327 .read = ssb_pcicore_read_config,
39328 .write = ssb_pcicore_write_config,
39329 };
39330 diff -urNp linux-2.6.39.2/drivers/staging/ath6kl/os/linux/cfg80211.c linux-2.6.39.2/drivers/staging/ath6kl/os/linux/cfg80211.c
39331 --- linux-2.6.39.2/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39332 +++ linux-2.6.39.2/drivers/staging/ath6kl/os/linux/cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39333 @@ -1391,8 +1391,7 @@ u32 cipher_suites[] = {
39334 WLAN_CIPHER_SUITE_CCMP,
39335 };
39336
39337 -static struct
39338 -cfg80211_ops ar6k_cfg80211_ops = {
39339 +static const struct cfg80211_ops ar6k_cfg80211_ops = {
39340 .change_virtual_intf = ar6k_cfg80211_change_iface,
39341 .add_virtual_intf = ar6k_cfg80211_add_virtual_intf,
39342 .del_virtual_intf = ar6k_cfg80211_del_virtual_intf,
39343 diff -urNp linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/dhd_linux.c linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
39344 --- linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-19 00:06:34.000000000 -0400
39345 +++ linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/dhd_linux.c 2011-05-22 19:36:32.000000000 -0400
39346 @@ -857,14 +857,14 @@ static void dhd_op_if(dhd_if_t *ifp)
39347 free_netdev(ifp->net);
39348 }
39349 /* Allocate etherdev, including space for private structure */
39350 - ifp->net = alloc_etherdev(sizeof(dhd));
39351 + ifp->net = alloc_etherdev(sizeof(*dhd));
39352 if (!ifp->net) {
39353 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39354 ret = -ENOMEM;
39355 }
39356 if (ret == 0) {
39357 strcpy(ifp->net->name, ifp->name);
39358 - memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
39359 + memcpy(netdev_priv(ifp->net), dhd, sizeof(*dhd));
39360 err = dhd_net_attach(&dhd->pub, ifp->idx);
39361 if (err != 0) {
39362 DHD_ERROR(("%s: dhd_net_attach failed, "
39363 @@ -1500,7 +1500,7 @@ static void dhd_ethtool_get_drvinfo(stru
39364 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
39365 }
39366
39367 -struct ethtool_ops dhd_ethtool_ops = {
39368 +const struct ethtool_ops dhd_ethtool_ops = {
39369 .get_drvinfo = dhd_ethtool_get_drvinfo
39370 };
39371
39372 @@ -1923,7 +1923,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39373 strcpy(nv_path, nvram_path);
39374
39375 /* Allocate etherdev, including space for private structure */
39376 - net = alloc_etherdev(sizeof(dhd));
39377 + net = alloc_etherdev(sizeof(*dhd));
39378 if (!net) {
39379 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
39380 goto fail;
39381 @@ -1939,7 +1939,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39382 /*
39383 * Save the dhd_info into the priv
39384 */
39385 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39386 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39387
39388 /* Set network interface name if it was provided as module parameter */
39389 if (iface_name[0]) {
39390 @@ -2056,7 +2056,7 @@ dhd_pub_t *dhd_attach(struct dhd_bus *bu
39391 /*
39392 * Save the dhd_info into the priv
39393 */
39394 - memcpy(netdev_priv(net), &dhd, sizeof(dhd));
39395 + memcpy(netdev_priv(net), dhd, sizeof(*dhd));
39396
39397 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
39398 g_bus = bus;
39399 @@ -2206,7 +2206,7 @@ dhd_iovar(dhd_pub_t *pub, int ifidx, cha
39400 return ret;
39401 }
39402
39403 -static struct net_device_ops dhd_ops_pri = {
39404 +static const struct net_device_ops dhd_ops_pri = {
39405 .ndo_open = dhd_open,
39406 .ndo_stop = dhd_stop,
39407 .ndo_get_stats = dhd_get_stats,
39408 diff -urNp linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
39409 --- linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-19 00:06:34.000000000 -0400
39410 +++ linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c 2011-05-22 19:36:32.000000000 -0400
39411 @@ -2109,7 +2109,7 @@ wl_cfg80211_flush_pmksa(struct wiphy *wi
39412
39413 }
39414
39415 -static struct cfg80211_ops wl_cfg80211_ops = {
39416 +static const struct cfg80211_ops wl_cfg80211_ops = {
39417 .change_virtual_intf = wl_cfg80211_change_iface,
39418 .scan = wl_cfg80211_scan,
39419 .set_wiphy_params = wl_cfg80211_set_wiphy_params,
39420 diff -urNp linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_iw.c linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_iw.c
39421 --- linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-19 00:06:34.000000000 -0400
39422 +++ linux-2.6.39.2/drivers/staging/brcm80211/brcmfmac/wl_iw.c 2011-05-22 19:36:32.000000000 -0400
39423 @@ -495,7 +495,7 @@ wl_iw_get_range(struct net_device *dev,
39424 list = (wl_u32_list_t *) channels;
39425
39426 dwrq->length = sizeof(struct iw_range);
39427 - memset(range, 0, sizeof(range));
39428 + memset(range, 0, sizeof(*range));
39429
39430 range->min_nwid = range->max_nwid = 0;
39431
39432 diff -urNp linux-2.6.39.2/drivers/staging/comedi/comedi_fops.c linux-2.6.39.2/drivers/staging/comedi/comedi_fops.c
39433 --- linux-2.6.39.2/drivers/staging/comedi/comedi_fops.c 2011-05-19 00:06:34.000000000 -0400
39434 +++ linux-2.6.39.2/drivers/staging/comedi/comedi_fops.c 2011-05-22 19:36:32.000000000 -0400
39435 @@ -1445,7 +1445,7 @@ static void comedi_unmap(struct vm_area_
39436 mutex_unlock(&dev->mutex);
39437 }
39438
39439 -static struct vm_operations_struct comedi_vm_ops = {
39440 +static const struct vm_operations_struct comedi_vm_ops = {
39441 .close = comedi_unmap,
39442 };
39443
39444 diff -urNp linux-2.6.39.2/drivers/staging/cx25821/cx25821-alsa.c linux-2.6.39.2/drivers/staging/cx25821/cx25821-alsa.c
39445 --- linux-2.6.39.2/drivers/staging/cx25821/cx25821-alsa.c 2011-05-19 00:06:34.000000000 -0400
39446 +++ linux-2.6.39.2/drivers/staging/cx25821/cx25821-alsa.c 2011-05-22 19:36:32.000000000 -0400
39447 @@ -586,7 +586,7 @@ static struct page *snd_cx25821_page(str
39448 /*
39449 * operators
39450 */
39451 -static struct snd_pcm_ops snd_cx25821_pcm_ops = {
39452 +static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
39453 .open = snd_cx25821_pcm_open,
39454 .close = snd_cx25821_close,
39455 .ioctl = snd_pcm_lib_ioctl,
39456 diff -urNp linux-2.6.39.2/drivers/staging/cx25821/cx25821-i2c.c linux-2.6.39.2/drivers/staging/cx25821/cx25821-i2c.c
39457 --- linux-2.6.39.2/drivers/staging/cx25821/cx25821-i2c.c 2011-05-19 00:06:34.000000000 -0400
39458 +++ linux-2.6.39.2/drivers/staging/cx25821/cx25821-i2c.c 2011-05-22 19:36:32.000000000 -0400
39459 @@ -282,7 +282,7 @@ static u32 cx25821_functionality(struct
39460 I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
39461 }
39462
39463 -static struct i2c_algorithm cx25821_i2c_algo_template = {
39464 +static const struct i2c_algorithm cx25821_i2c_algo_template = {
39465 .master_xfer = i2c_xfer,
39466 .functionality = cx25821_functionality,
39467 #ifdef NEED_ALGO_CONTROL
39468 diff -urNp linux-2.6.39.2/drivers/staging/et131x/et1310_tx.c linux-2.6.39.2/drivers/staging/et131x/et1310_tx.c
39469 --- linux-2.6.39.2/drivers/staging/et131x/et1310_tx.c 2011-05-19 00:06:34.000000000 -0400
39470 +++ linux-2.6.39.2/drivers/staging/et131x/et1310_tx.c 2011-05-22 19:36:32.000000000 -0400
39471 @@ -635,11 +635,11 @@ inline void et131x_free_send_packet(stru
39472 struct net_device_stats *stats = &etdev->net_stats;
39473
39474 if (tcb->flags & fMP_DEST_BROAD)
39475 - atomic_inc(&etdev->Stats.brdcstxmt);
39476 + atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
39477 else if (tcb->flags & fMP_DEST_MULTI)
39478 - atomic_inc(&etdev->Stats.multixmt);
39479 + atomic_inc_unchecked(&etdev->Stats.multixmt);
39480 else
39481 - atomic_inc(&etdev->Stats.unixmt);
39482 + atomic_inc_unchecked(&etdev->Stats.unixmt);
39483
39484 if (tcb->skb) {
39485 stats->tx_bytes += tcb->skb->len;
39486 diff -urNp linux-2.6.39.2/drivers/staging/et131x/et131x_adapter.h linux-2.6.39.2/drivers/staging/et131x/et131x_adapter.h
39487 --- linux-2.6.39.2/drivers/staging/et131x/et131x_adapter.h 2011-05-19 00:06:34.000000000 -0400
39488 +++ linux-2.6.39.2/drivers/staging/et131x/et131x_adapter.h 2011-05-22 19:36:32.000000000 -0400
39489 @@ -110,11 +110,11 @@ typedef struct _ce_stats_t {
39490 * operations
39491 */
39492 u32 unircv; /* # multicast packets received */
39493 - atomic_t unixmt; /* # multicast packets for Tx */
39494 + atomic_unchecked_t unixmt; /* # multicast packets for Tx */
39495 u32 multircv; /* # multicast packets received */
39496 - atomic_t multixmt; /* # multicast packets for Tx */
39497 + atomic_unchecked_t multixmt; /* # multicast packets for Tx */
39498 u32 brdcstrcv; /* # broadcast packets received */
39499 - atomic_t brdcstxmt; /* # broadcast packets for Tx */
39500 + atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
39501 u32 norcvbuf; /* # Rx packets discarded */
39502 u32 noxmtbuf; /* # Tx packets discarded */
39503
39504 diff -urNp linux-2.6.39.2/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c linux-2.6.39.2/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
39505 --- linux-2.6.39.2/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-19 00:06:34.000000000 -0400
39506 +++ linux-2.6.39.2/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c 2011-05-22 19:36:32.000000000 -0400
39507 @@ -55,7 +55,7 @@ int numofmsgbuf = 0;
39508 //
39509 // Table of entry-point routines for char device
39510 //
39511 -static struct file_operations ft1000fops =
39512 +static const struct file_operations ft1000fops =
39513 {
39514 .unlocked_ioctl = ft1000_ioctl,
39515 .poll = ft1000_poll_dev,
39516 diff -urNp linux-2.6.39.2/drivers/staging/generic_serial/rio/rio_linux.c linux-2.6.39.2/drivers/staging/generic_serial/rio/rio_linux.c
39517 --- linux-2.6.39.2/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-19 00:06:34.000000000 -0400
39518 +++ linux-2.6.39.2/drivers/staging/generic_serial/rio/rio_linux.c 2011-05-22 19:36:32.000000000 -0400
39519 @@ -221,7 +221,7 @@ module_param(rio_poll, int, 0);
39520 module_param(rio_debug, int, 0644);
39521 module_param(rio_irqmask, long, 0);
39522
39523 -static struct real_driver rio_real_driver = {
39524 +static const struct real_driver rio_real_driver = {
39525 rio_disable_tx_interrupts,
39526 rio_enable_tx_interrupts,
39527 rio_disable_rx_interrupts,
39528 diff -urNp linux-2.6.39.2/drivers/staging/generic_serial/ser_a2232.c linux-2.6.39.2/drivers/staging/generic_serial/ser_a2232.c
39529 --- linux-2.6.39.2/drivers/staging/generic_serial/ser_a2232.c 2011-05-19 00:06:34.000000000 -0400
39530 +++ linux-2.6.39.2/drivers/staging/generic_serial/ser_a2232.c 2011-05-22 19:36:32.000000000 -0400
39531 @@ -144,7 +144,7 @@ static int a2232_open(struct tty_struct
39532 /*---------------------------------------------------------------------------
39533 * Interface from generic_serial.c back here
39534 *--------------------------------------------------------------------------*/
39535 -static struct real_driver a2232_real_driver = {
39536 +static const struct real_driver a2232_real_driver = {
39537 a2232_disable_tx_interrupts,
39538 a2232_enable_tx_interrupts,
39539 a2232_disable_rx_interrupts,
39540 diff -urNp linux-2.6.39.2/drivers/staging/generic_serial/sx.c linux-2.6.39.2/drivers/staging/generic_serial/sx.c
39541 --- linux-2.6.39.2/drivers/staging/generic_serial/sx.c 2011-05-19 00:06:34.000000000 -0400
39542 +++ linux-2.6.39.2/drivers/staging/generic_serial/sx.c 2011-05-22 19:36:32.000000000 -0400
39543 @@ -355,7 +355,7 @@ module_param(sx_irqmask, int, 0);
39544
39545 MODULE_LICENSE("GPL");
39546
39547 -static struct real_driver sx_real_driver = {
39548 +static const struct real_driver sx_real_driver = {
39549 sx_disable_tx_interrupts,
39550 sx_enable_tx_interrupts,
39551 sx_disable_rx_interrupts,
39552 diff -urNp linux-2.6.39.2/drivers/staging/generic_serial/vme_scc.c linux-2.6.39.2/drivers/staging/generic_serial/vme_scc.c
39553 --- linux-2.6.39.2/drivers/staging/generic_serial/vme_scc.c 2011-05-19 00:06:34.000000000 -0400
39554 +++ linux-2.6.39.2/drivers/staging/generic_serial/vme_scc.c 2011-05-22 19:36:32.000000000 -0400
39555 @@ -94,7 +94,7 @@ static struct scc_port scc_ports[2];
39556 * Interface from generic_serial.c back here
39557 *--------------------------------------------------------------------------*/
39558
39559 -static struct real_driver scc_real_driver = {
39560 +static const struct real_driver scc_real_driver = {
39561 scc_disable_tx_interrupts,
39562 scc_enable_tx_interrupts,
39563 scc_disable_rx_interrupts,
39564 diff -urNp linux-2.6.39.2/drivers/staging/gma500/psb_fb.c linux-2.6.39.2/drivers/staging/gma500/psb_fb.c
39565 --- linux-2.6.39.2/drivers/staging/gma500/psb_fb.c 2011-06-25 12:55:22.000000000 -0400
39566 +++ linux-2.6.39.2/drivers/staging/gma500/psb_fb.c 2011-06-25 13:00:26.000000000 -0400
39567 @@ -230,7 +230,7 @@ static void psbfb_vm_close(struct vm_are
39568 DRM_DEBUG("vm_close\n");
39569 }
39570
39571 -static struct vm_operations_struct psbfb_vm_ops = {
39572 +static const struct vm_operations_struct psbfb_vm_ops = {
39573 .fault = psbfb_vm_fault,
39574 .open = psbfb_vm_open,
39575 .close = psbfb_vm_close
39576 diff -urNp linux-2.6.39.2/drivers/staging/go7007/go7007-i2c.c linux-2.6.39.2/drivers/staging/go7007/go7007-i2c.c
39577 --- linux-2.6.39.2/drivers/staging/go7007/go7007-i2c.c 2011-05-19 00:06:34.000000000 -0400
39578 +++ linux-2.6.39.2/drivers/staging/go7007/go7007-i2c.c 2011-05-22 19:36:32.000000000 -0400
39579 @@ -198,7 +198,7 @@ static u32 go7007_functionality(struct i
39580 return I2C_FUNC_SMBUS_BYTE_DATA;
39581 }
39582
39583 -static struct i2c_algorithm go7007_algo = {
39584 +static const struct i2c_algorithm go7007_algo = {
39585 .smbus_xfer = go7007_smbus_xfer,
39586 .master_xfer = go7007_i2c_master_xfer,
39587 .functionality = go7007_functionality,
39588 diff -urNp linux-2.6.39.2/drivers/staging/go7007/go7007-usb.c linux-2.6.39.2/drivers/staging/go7007/go7007-usb.c
39589 --- linux-2.6.39.2/drivers/staging/go7007/go7007-usb.c 2011-05-19 00:06:34.000000000 -0400
39590 +++ linux-2.6.39.2/drivers/staging/go7007/go7007-usb.c 2011-05-22 19:36:32.000000000 -0400
39591 @@ -849,7 +849,7 @@ static int go7007_usb_send_firmware(stru
39592 &transferred, timeout);
39593 }
39594
39595 -static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39596 +static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
39597 .interface_reset = go7007_usb_interface_reset,
39598 .write_interrupt = go7007_usb_ezusb_write_interrupt,
39599 .read_interrupt = go7007_usb_read_interrupt,
39600 @@ -858,7 +858,7 @@ static struct go7007_hpi_ops go7007_usb_
39601 .send_firmware = go7007_usb_send_firmware,
39602 };
39603
39604 -static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39605 +static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
39606 .interface_reset = go7007_usb_interface_reset,
39607 .write_interrupt = go7007_usb_onboard_write_interrupt,
39608 .read_interrupt = go7007_usb_read_interrupt,
39609 @@ -950,7 +950,7 @@ static u32 go7007_usb_functionality(stru
39610 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
39611 }
39612
39613 -static struct i2c_algorithm go7007_usb_algo = {
39614 +static const struct i2c_algorithm go7007_usb_algo = {
39615 .master_xfer = go7007_usb_i2c_master_xfer,
39616 .functionality = go7007_usb_functionality,
39617 };
39618 diff -urNp linux-2.6.39.2/drivers/staging/go7007/go7007-v4l2.c linux-2.6.39.2/drivers/staging/go7007/go7007-v4l2.c
39619 --- linux-2.6.39.2/drivers/staging/go7007/go7007-v4l2.c 2011-05-19 00:06:34.000000000 -0400
39620 +++ linux-2.6.39.2/drivers/staging/go7007/go7007-v4l2.c 2011-05-22 19:36:32.000000000 -0400
39621 @@ -1672,7 +1672,7 @@ static int go7007_vm_fault(struct vm_are
39622 return 0;
39623 }
39624
39625 -static struct vm_operations_struct go7007_vm_ops = {
39626 +static const struct vm_operations_struct go7007_vm_ops = {
39627 .open = go7007_vm_open,
39628 .close = go7007_vm_close,
39629 .fault = go7007_vm_fault,
39630 diff -urNp linux-2.6.39.2/drivers/staging/go7007/saa7134-go7007.c linux-2.6.39.2/drivers/staging/go7007/saa7134-go7007.c
39631 --- linux-2.6.39.2/drivers/staging/go7007/saa7134-go7007.c 2011-05-19 00:06:34.000000000 -0400
39632 +++ linux-2.6.39.2/drivers/staging/go7007/saa7134-go7007.c 2011-05-22 19:36:32.000000000 -0400
39633 @@ -421,7 +421,7 @@ static int saa7134_go7007_send_command(s
39634
39635 }
39636
39637 -static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39638 +static const struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
39639 .interface_reset = saa7134_go7007_interface_reset,
39640 .write_interrupt = saa7134_go7007_write_interrupt,
39641 .read_interrupt = saa7134_go7007_read_interrupt,
39642 diff -urNp linux-2.6.39.2/drivers/staging/go7007/snd-go7007.c linux-2.6.39.2/drivers/staging/go7007/snd-go7007.c
39643 --- linux-2.6.39.2/drivers/staging/go7007/snd-go7007.c 2011-05-19 00:06:34.000000000 -0400
39644 +++ linux-2.6.39.2/drivers/staging/go7007/snd-go7007.c 2011-05-22 19:36:32.000000000 -0400
39645 @@ -204,7 +204,7 @@ static struct page *go7007_snd_pcm_page(
39646 return vmalloc_to_page(substream->runtime->dma_area + offset);
39647 }
39648
39649 -static struct snd_pcm_ops go7007_snd_capture_ops = {
39650 +static const struct snd_pcm_ops go7007_snd_capture_ops = {
39651 .open = go7007_snd_capture_open,
39652 .close = go7007_snd_capture_close,
39653 .ioctl = snd_pcm_lib_ioctl,
39654 @@ -227,7 +227,7 @@ static int go7007_snd_free(struct snd_de
39655 return 0;
39656 }
39657
39658 -static struct snd_device_ops go7007_snd_device_ops = {
39659 +static const struct snd_device_ops go7007_snd_device_ops = {
39660 .dev_free = go7007_snd_free,
39661 };
39662
39663 diff -urNp linux-2.6.39.2/drivers/staging/hv/channel.c linux-2.6.39.2/drivers/staging/hv/channel.c
39664 --- linux-2.6.39.2/drivers/staging/hv/channel.c 2011-05-19 00:06:34.000000000 -0400
39665 +++ linux-2.6.39.2/drivers/staging/hv/channel.c 2011-05-22 19:36:32.000000000 -0400
39666 @@ -509,8 +509,8 @@ int vmbus_establish_gpadl(struct vmbus_c
39667 unsigned long flags;
39668 int ret = 0;
39669
39670 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39671 - atomic_inc(&vmbus_connection.next_gpadl_handle);
39672 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39673 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39674
39675 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39676 if (ret)
39677 diff -urNp linux-2.6.39.2/drivers/staging/hv/hv.c linux-2.6.39.2/drivers/staging/hv/hv.c
39678 --- linux-2.6.39.2/drivers/staging/hv/hv.c 2011-05-19 00:06:34.000000000 -0400
39679 +++ linux-2.6.39.2/drivers/staging/hv/hv.c 2011-05-22 19:36:32.000000000 -0400
39680 @@ -163,7 +163,7 @@ static u64 do_hypercall(u64 control, voi
39681 u64 output_address = (output) ? virt_to_phys(output) : 0;
39682 u32 output_address_hi = output_address >> 32;
39683 u32 output_address_lo = output_address & 0xFFFFFFFF;
39684 - volatile void *hypercall_page = hv_context.hypercall_page;
39685 + volatile void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39686
39687 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
39688 control, input, output);
39689 diff -urNp linux-2.6.39.2/drivers/staging/hv/rndis_filter.c linux-2.6.39.2/drivers/staging/hv/rndis_filter.c
39690 --- linux-2.6.39.2/drivers/staging/hv/rndis_filter.c 2011-05-19 00:06:34.000000000 -0400
39691 +++ linux-2.6.39.2/drivers/staging/hv/rndis_filter.c 2011-05-22 19:36:32.000000000 -0400
39692 @@ -49,7 +49,7 @@ struct rndis_device {
39693
39694 enum rndis_device_state state;
39695 u32 link_stat;
39696 - atomic_t new_req_id;
39697 + atomic_unchecked_t new_req_id;
39698
39699 spinlock_t request_lock;
39700 struct list_head req_list;
39701 @@ -144,7 +144,7 @@ static struct rndis_request *get_rndis_r
39702 * template
39703 */
39704 set = &rndis_msg->msg.set_req;
39705 - set->req_id = atomic_inc_return(&dev->new_req_id);
39706 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39707
39708 /* Add to the request list */
39709 spin_lock_irqsave(&dev->request_lock, flags);
39710 @@ -709,7 +709,7 @@ static void rndis_filter_halt_device(str
39711
39712 /* Setup the rndis set */
39713 halt = &request->request_msg.msg.halt_req;
39714 - halt->req_id = atomic_inc_return(&dev->new_req_id);
39715 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39716
39717 /* Ignore return since this msg is optional. */
39718 rndis_filter_send_request(dev, request);
39719 diff -urNp linux-2.6.39.2/drivers/staging/hv/vmbus_drv.c linux-2.6.39.2/drivers/staging/hv/vmbus_drv.c
39720 --- linux-2.6.39.2/drivers/staging/hv/vmbus_drv.c 2011-05-19 00:06:34.000000000 -0400
39721 +++ linux-2.6.39.2/drivers/staging/hv/vmbus_drv.c 2011-05-22 19:36:32.000000000 -0400
39722 @@ -661,14 +661,14 @@ int vmbus_child_device_register(struct h
39723 {
39724 int ret = 0;
39725
39726 - static atomic_t device_num = ATOMIC_INIT(0);
39727 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39728
39729 DPRINT_DBG(VMBUS_DRV, "child device (%p) registering",
39730 child_device_obj);
39731
39732 /* Set the device name. Otherwise, device_register() will fail. */
39733 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39734 - atomic_inc_return(&device_num));
39735 + atomic_inc_return_unchecked(&device_num));
39736
39737 /* The new device belongs to this bus */
39738 child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */
39739 diff -urNp linux-2.6.39.2/drivers/staging/hv/vmbus_private.h linux-2.6.39.2/drivers/staging/hv/vmbus_private.h
39740 --- linux-2.6.39.2/drivers/staging/hv/vmbus_private.h 2011-05-19 00:06:34.000000000 -0400
39741 +++ linux-2.6.39.2/drivers/staging/hv/vmbus_private.h 2011-05-22 19:36:32.000000000 -0400
39742 @@ -58,7 +58,7 @@ enum vmbus_connect_state {
39743 struct vmbus_connection {
39744 enum vmbus_connect_state conn_state;
39745
39746 - atomic_t next_gpadl_handle;
39747 + atomic_unchecked_t next_gpadl_handle;
39748
39749 /*
39750 * Represents channel interrupts. Each bit position represents a
39751 diff -urNp linux-2.6.39.2/drivers/staging/iio/ring_generic.h linux-2.6.39.2/drivers/staging/iio/ring_generic.h
39752 --- linux-2.6.39.2/drivers/staging/iio/ring_generic.h 2011-05-19 00:06:34.000000000 -0400
39753 +++ linux-2.6.39.2/drivers/staging/iio/ring_generic.h 2011-05-25 16:55:27.000000000 -0400
39754 @@ -134,7 +134,7 @@ struct iio_ring_buffer {
39755 struct iio_handler access_handler;
39756 struct iio_event_interface ev_int;
39757 struct iio_shared_ev_pointer shared_ev_pointer;
39758 - struct iio_ring_access_funcs access;
39759 + struct iio_ring_access_funcs access;
39760 int (*preenable)(struct iio_dev *);
39761 int (*postenable)(struct iio_dev *);
39762 int (*predisable)(struct iio_dev *);
39763 diff -urNp linux-2.6.39.2/drivers/staging/intel_sst/intelmid_ctrl.c linux-2.6.39.2/drivers/staging/intel_sst/intelmid_ctrl.c
39764 --- linux-2.6.39.2/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-19 00:06:34.000000000 -0400
39765 +++ linux-2.6.39.2/drivers/staging/intel_sst/intelmid_ctrl.c 2011-05-22 19:36:32.000000000 -0400
39766 @@ -494,7 +494,7 @@ static int snd_intelmad_device_set(struc
39767 struct snd_intelmad *intelmaddata;
39768 struct snd_pmic_ops *scard_ops;
39769 int ret_val = 0, vendor, status;
39770 - struct intel_sst_pcm_control *pcm_control;
39771 + const struct intel_sst_pcm_control *pcm_control;
39772
39773 pr_debug("snd_intelmad_device_set called\n");
39774
39775 diff -urNp linux-2.6.39.2/drivers/staging/intel_sst/intel_sst_drv_interface.c linux-2.6.39.2/drivers/staging/intel_sst/intel_sst_drv_interface.c
39776 --- linux-2.6.39.2/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-19 00:06:34.000000000 -0400
39777 +++ linux-2.6.39.2/drivers/staging/intel_sst/intel_sst_drv_interface.c 2011-05-22 19:36:32.000000000 -0400
39778 @@ -470,7 +470,7 @@ int sst_device_control(int cmd, void *ar
39779 }
39780
39781
39782 -struct intel_sst_pcm_control pcm_ops = {
39783 +const struct intel_sst_pcm_control pcm_ops = {
39784 .open = sst_open_pcm_stream,
39785 .device_control = sst_device_control,
39786 .close = sst_close_pcm_stream,
39787 diff -urNp linux-2.6.39.2/drivers/staging/line6/capture.c linux-2.6.39.2/drivers/staging/line6/capture.c
39788 --- linux-2.6.39.2/drivers/staging/line6/capture.c 2011-05-19 00:06:34.000000000 -0400
39789 +++ linux-2.6.39.2/drivers/staging/line6/capture.c 2011-05-22 19:36:32.000000000 -0400
39790 @@ -378,7 +378,7 @@ snd_line6_capture_pointer(struct snd_pcm
39791 }
39792
39793 /* capture operators */
39794 -struct snd_pcm_ops snd_line6_capture_ops = {
39795 +const struct snd_pcm_ops snd_line6_capture_ops = {
39796 .open = snd_line6_capture_open,
39797 .close = snd_line6_capture_close,
39798 .ioctl = snd_pcm_lib_ioctl,
39799 diff -urNp linux-2.6.39.2/drivers/staging/line6/capture.h linux-2.6.39.2/drivers/staging/line6/capture.h
39800 --- linux-2.6.39.2/drivers/staging/line6/capture.h 2011-05-19 00:06:34.000000000 -0400
39801 +++ linux-2.6.39.2/drivers/staging/line6/capture.h 2011-05-22 19:36:32.000000000 -0400
39802 @@ -17,7 +17,7 @@
39803 #include "driver.h"
39804 #include "pcm.h"
39805
39806 -extern struct snd_pcm_ops snd_line6_capture_ops;
39807 +extern const struct snd_pcm_ops snd_line6_capture_ops;
39808
39809 extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
39810 int fsize);
39811 diff -urNp linux-2.6.39.2/drivers/staging/line6/midi.c linux-2.6.39.2/drivers/staging/line6/midi.c
39812 --- linux-2.6.39.2/drivers/staging/line6/midi.c 2011-05-19 00:06:34.000000000 -0400
39813 +++ linux-2.6.39.2/drivers/staging/line6/midi.c 2011-05-22 19:36:32.000000000 -0400
39814 @@ -239,14 +239,14 @@ static void line6_midi_input_trigger(str
39815 line6->line6midi->substream_receive = 0;
39816 }
39817
39818 -static struct snd_rawmidi_ops line6_midi_output_ops = {
39819 +static const struct snd_rawmidi_ops line6_midi_output_ops = {
39820 .open = line6_midi_output_open,
39821 .close = line6_midi_output_close,
39822 .trigger = line6_midi_output_trigger,
39823 .drain = line6_midi_output_drain,
39824 };
39825
39826 -static struct snd_rawmidi_ops line6_midi_input_ops = {
39827 +static const struct snd_rawmidi_ops line6_midi_input_ops = {
39828 .open = line6_midi_input_open,
39829 .close = line6_midi_input_close,
39830 .trigger = line6_midi_input_trigger,
39831 @@ -373,7 +373,7 @@ static int snd_line6_midi_free(struct sn
39832 */
39833 int line6_init_midi(struct usb_line6 *line6)
39834 {
39835 - static struct snd_device_ops midi_ops = {
39836 + static const struct snd_device_ops midi_ops = {
39837 .dev_free = snd_line6_midi_free,
39838 };
39839
39840 diff -urNp linux-2.6.39.2/drivers/staging/line6/pcm.c linux-2.6.39.2/drivers/staging/line6/pcm.c
39841 --- linux-2.6.39.2/drivers/staging/line6/pcm.c 2011-05-19 00:06:34.000000000 -0400
39842 +++ linux-2.6.39.2/drivers/staging/line6/pcm.c 2011-05-22 19:36:32.000000000 -0400
39843 @@ -384,7 +384,7 @@ void line6_pcm_disconnect(struct snd_lin
39844 int line6_init_pcm(struct usb_line6 *line6,
39845 struct line6_pcm_properties *properties)
39846 {
39847 - static struct snd_device_ops pcm_ops = {
39848 + static const struct snd_device_ops pcm_ops = {
39849 .dev_free = snd_line6_pcm_free,
39850 };
39851
39852 diff -urNp linux-2.6.39.2/drivers/staging/line6/playback.c linux-2.6.39.2/drivers/staging/line6/playback.c
39853 --- linux-2.6.39.2/drivers/staging/line6/playback.c 2011-05-19 00:06:34.000000000 -0400
39854 +++ linux-2.6.39.2/drivers/staging/line6/playback.c 2011-05-22 19:36:32.000000000 -0400
39855 @@ -536,7 +536,7 @@ snd_line6_playback_pointer(struct snd_pc
39856 }
39857
39858 /* playback operators */
39859 -struct snd_pcm_ops snd_line6_playback_ops = {
39860 +const struct snd_pcm_ops snd_line6_playback_ops = {
39861 .open = snd_line6_playback_open,
39862 .close = snd_line6_playback_close,
39863 .ioctl = snd_pcm_lib_ioctl,
39864 diff -urNp linux-2.6.39.2/drivers/staging/line6/playback.h linux-2.6.39.2/drivers/staging/line6/playback.h
39865 --- linux-2.6.39.2/drivers/staging/line6/playback.h 2011-05-19 00:06:34.000000000 -0400
39866 +++ linux-2.6.39.2/drivers/staging/line6/playback.h 2011-05-22 19:36:32.000000000 -0400
39867 @@ -27,7 +27,7 @@
39868 */
39869 #define USE_CLEAR_BUFFER_WORKAROUND 1
39870
39871 -extern struct snd_pcm_ops snd_line6_playback_ops;
39872 +extern const struct snd_pcm_ops snd_line6_playback_ops;
39873
39874 extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
39875 extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
39876 diff -urNp linux-2.6.39.2/drivers/staging/msm/staging-devices.c linux-2.6.39.2/drivers/staging/msm/staging-devices.c
39877 --- linux-2.6.39.2/drivers/staging/msm/staging-devices.c 2011-05-19 00:06:34.000000000 -0400
39878 +++ linux-2.6.39.2/drivers/staging/msm/staging-devices.c 2011-05-22 19:36:32.000000000 -0400
39879 @@ -211,7 +211,7 @@ static int msm_fb_lcdc_gpio_config(int o
39880 }
39881
39882
39883 -static struct lcdc_platform_data lcdc_pdata = {
39884 +static const struct lcdc_platform_data lcdc_pdata = {
39885 .lcdc_gpio_config = msm_fb_lcdc_gpio_config,
39886 };
39887
39888 diff -urNp linux-2.6.39.2/drivers/staging/octeon/ethernet.c linux-2.6.39.2/drivers/staging/octeon/ethernet.c
39889 --- linux-2.6.39.2/drivers/staging/octeon/ethernet.c 2011-05-19 00:06:34.000000000 -0400
39890 +++ linux-2.6.39.2/drivers/staging/octeon/ethernet.c 2011-05-22 19:36:32.000000000 -0400
39891 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_
39892 * since the RX tasklet also increments it.
39893 */
39894 #ifdef CONFIG_64BIT
39895 - atomic64_add(rx_status.dropped_packets,
39896 - (atomic64_t *)&priv->stats.rx_dropped);
39897 + atomic64_add_unchecked(rx_status.dropped_packets,
39898 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39899 #else
39900 - atomic_add(rx_status.dropped_packets,
39901 - (atomic_t *)&priv->stats.rx_dropped);
39902 + atomic_add_unchecked(rx_status.dropped_packets,
39903 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39904 #endif
39905 }
39906
39907 diff -urNp linux-2.6.39.2/drivers/staging/octeon/ethernet-rx.c linux-2.6.39.2/drivers/staging/octeon/ethernet-rx.c
39908 --- linux-2.6.39.2/drivers/staging/octeon/ethernet-rx.c 2011-05-19 00:06:34.000000000 -0400
39909 +++ linux-2.6.39.2/drivers/staging/octeon/ethernet-rx.c 2011-05-22 19:36:32.000000000 -0400
39910 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi
39911 /* Increment RX stats for virtual ports */
39912 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39913 #ifdef CONFIG_64BIT
39914 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39915 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39916 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39917 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39918 #else
39919 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39920 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39921 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39922 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39923 #endif
39924 }
39925 netif_receive_skb(skb);
39926 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi
39927 dev->name);
39928 */
39929 #ifdef CONFIG_64BIT
39930 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39931 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39932 #else
39933 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39934 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39935 #endif
39936 dev_kfree_skb_irq(skb);
39937 }
39938 diff -urNp linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.c linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.c
39939 --- linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-19 00:06:34.000000000 -0400
39940 +++ linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.c 2011-05-22 19:36:32.000000000 -0400
39941 @@ -43,7 +43,7 @@ module_param(noinit, int, 0444);
39942 static int useaa = 1;
39943 module_param(useaa, int, 0444);
39944
39945 -static struct dcon_platform_data *pdata;
39946 +static const struct dcon_platform_data *pdata;
39947
39948 /* I2C structures */
39949
39950 diff -urNp linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.h linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.h
39951 --- linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-19 00:06:34.000000000 -0400
39952 +++ linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon.h 2011-05-22 19:36:32.000000000 -0400
39953 @@ -92,11 +92,11 @@ struct dcon_platform_data {
39954 extern irqreturn_t dcon_interrupt(int irq, void *id);
39955
39956 #ifdef CONFIG_FB_OLPC_DCON_1
39957 -extern struct dcon_platform_data dcon_pdata_xo_1;
39958 +extern const struct dcon_platform_data dcon_pdata_xo_1;
39959 #endif
39960
39961 #ifdef CONFIG_FB_OLPC_DCON_1_5
39962 -extern struct dcon_platform_data dcon_pdata_xo_1_5;
39963 +extern const struct dcon_platform_data dcon_pdata_xo_1_5;
39964 #endif
39965
39966 #endif
39967 diff -urNp linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
39968 --- linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-19 00:06:34.000000000 -0400
39969 +++ linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c 2011-05-22 19:36:32.000000000 -0400
39970 @@ -185,7 +185,7 @@ static u8 dcon_read_status_xo_1_5(void)
39971 return status;
39972 }
39973
39974 -struct dcon_platform_data dcon_pdata_xo_1_5 = {
39975 +const struct dcon_platform_data dcon_pdata_xo_1_5 = {
39976 .init = dcon_init_xo_1_5,
39977 .bus_stabilize_wiggle = dcon_wiggle_xo_1_5,
39978 .set_dconload = dcon_set_dconload_xo_1_5,
39979 diff -urNp linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c
39980 --- linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-19 00:06:34.000000000 -0400
39981 +++ linux-2.6.39.2/drivers/staging/olpc_dcon/olpc_dcon_xo_1.c 2011-05-22 19:36:32.000000000 -0400
39982 @@ -196,7 +196,7 @@ static u8 dcon_read_status_xo_1(void)
39983 return status;
39984 }
39985
39986 -struct dcon_platform_data dcon_pdata_xo_1 = {
39987 +const struct dcon_platform_data dcon_pdata_xo_1 = {
39988 .init = dcon_init_xo_1,
39989 .bus_stabilize_wiggle = dcon_wiggle_xo_1,
39990 .set_dconload = dcon_set_dconload_1,
39991 diff -urNp linux-2.6.39.2/drivers/staging/phison/phison.c linux-2.6.39.2/drivers/staging/phison/phison.c
39992 --- linux-2.6.39.2/drivers/staging/phison/phison.c 2011-05-19 00:06:34.000000000 -0400
39993 +++ linux-2.6.39.2/drivers/staging/phison/phison.c 2011-05-22 19:36:32.000000000 -0400
39994 @@ -43,7 +43,7 @@ static struct scsi_host_template phison_
39995 ATA_BMDMA_SHT(DRV_NAME),
39996 };
39997
39998 -static struct ata_port_operations phison_ops = {
39999 +static const struct ata_port_operations phison_ops = {
40000 .inherits = &ata_bmdma_port_ops,
40001 .prereset = phison_pre_reset,
40002 };
40003 diff -urNp linux-2.6.39.2/drivers/staging/pohmelfs/inode.c linux-2.6.39.2/drivers/staging/pohmelfs/inode.c
40004 --- linux-2.6.39.2/drivers/staging/pohmelfs/inode.c 2011-05-19 00:06:34.000000000 -0400
40005 +++ linux-2.6.39.2/drivers/staging/pohmelfs/inode.c 2011-05-22 19:36:32.000000000 -0400
40006 @@ -1855,7 +1855,7 @@ static int pohmelfs_fill_super(struct su
40007 mutex_init(&psb->mcache_lock);
40008 psb->mcache_root = RB_ROOT;
40009 psb->mcache_timeout = msecs_to_jiffies(5000);
40010 - atomic_long_set(&psb->mcache_gen, 0);
40011 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
40012
40013 psb->trans_max_pages = 100;
40014
40015 @@ -1870,7 +1870,7 @@ static int pohmelfs_fill_super(struct su
40016 INIT_LIST_HEAD(&psb->crypto_ready_list);
40017 INIT_LIST_HEAD(&psb->crypto_active_list);
40018
40019 - atomic_set(&psb->trans_gen, 1);
40020 + atomic_set_unchecked(&psb->trans_gen, 1);
40021 atomic_long_set(&psb->total_inodes, 0);
40022
40023 mutex_init(&psb->state_lock);
40024 diff -urNp linux-2.6.39.2/drivers/staging/pohmelfs/mcache.c linux-2.6.39.2/drivers/staging/pohmelfs/mcache.c
40025 --- linux-2.6.39.2/drivers/staging/pohmelfs/mcache.c 2011-05-19 00:06:34.000000000 -0400
40026 +++ linux-2.6.39.2/drivers/staging/pohmelfs/mcache.c 2011-05-22 19:36:32.000000000 -0400
40027 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_
40028 m->data = data;
40029 m->start = start;
40030 m->size = size;
40031 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
40032 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
40033
40034 mutex_lock(&psb->mcache_lock);
40035 err = pohmelfs_mcache_insert(psb, m);
40036 diff -urNp linux-2.6.39.2/drivers/staging/pohmelfs/netfs.h linux-2.6.39.2/drivers/staging/pohmelfs/netfs.h
40037 --- linux-2.6.39.2/drivers/staging/pohmelfs/netfs.h 2011-05-19 00:06:34.000000000 -0400
40038 +++ linux-2.6.39.2/drivers/staging/pohmelfs/netfs.h 2011-05-22 19:36:32.000000000 -0400
40039 @@ -571,14 +571,14 @@ struct pohmelfs_config;
40040 struct pohmelfs_sb {
40041 struct rb_root mcache_root;
40042 struct mutex mcache_lock;
40043 - atomic_long_t mcache_gen;
40044 + atomic_long_unchecked_t mcache_gen;
40045 unsigned long mcache_timeout;
40046
40047 unsigned int idx;
40048
40049 unsigned int trans_retries;
40050
40051 - atomic_t trans_gen;
40052 + atomic_unchecked_t trans_gen;
40053
40054 unsigned int crypto_attached_size;
40055 unsigned int crypto_align_size;
40056 diff -urNp linux-2.6.39.2/drivers/staging/pohmelfs/trans.c linux-2.6.39.2/drivers/staging/pohmelfs/trans.c
40057 --- linux-2.6.39.2/drivers/staging/pohmelfs/trans.c 2011-05-19 00:06:34.000000000 -0400
40058 +++ linux-2.6.39.2/drivers/staging/pohmelfs/trans.c 2011-05-22 19:36:32.000000000 -0400
40059 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_tran
40060 int err;
40061 struct netfs_cmd *cmd = t->iovec.iov_base;
40062
40063 - t->gen = atomic_inc_return(&psb->trans_gen);
40064 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
40065
40066 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
40067 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
40068 diff -urNp linux-2.6.39.2/drivers/staging/rtl8192u/ieee80211/proc.c linux-2.6.39.2/drivers/staging/rtl8192u/ieee80211/proc.c
40069 --- linux-2.6.39.2/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-19 00:06:34.000000000 -0400
40070 +++ linux-2.6.39.2/drivers/staging/rtl8192u/ieee80211/proc.c 2011-05-22 19:36:32.000000000 -0400
40071 @@ -87,7 +87,7 @@ static int c_show(struct seq_file *m, vo
40072 return 0;
40073 }
40074
40075 -static struct seq_operations crypto_seq_ops = {
40076 +static const struct seq_operations crypto_seq_ops = {
40077 .start = c_start,
40078 .next = c_next,
40079 .stop = c_stop,
40080 @@ -99,7 +99,7 @@ static int crypto_info_open(struct inode
40081 return seq_open(file, &crypto_seq_ops);
40082 }
40083
40084 -static struct file_operations proc_crypto_ops = {
40085 +static const struct file_operations proc_crypto_ops = {
40086 .open = crypto_info_open,
40087 .read = seq_read,
40088 .llseek = seq_lseek,
40089 diff -urNp linux-2.6.39.2/drivers/staging/rtl8712/rtl871x_io.h linux-2.6.39.2/drivers/staging/rtl8712/rtl871x_io.h
40090 --- linux-2.6.39.2/drivers/staging/rtl8712/rtl871x_io.h 2011-05-19 00:06:34.000000000 -0400
40091 +++ linux-2.6.39.2/drivers/staging/rtl8712/rtl871x_io.h 2011-05-22 19:36:32.000000000 -0400
40092 @@ -107,7 +107,7 @@ struct intf_hdl {
40093 void (*intf_hdl_unload)(u8 *priv);
40094 void (*intf_hdl_open)(u8 *priv);
40095 void (*intf_hdl_close)(u8 *priv);
40096 - struct _io_ops io_ops;
40097 + const struct _io_ops io_ops;
40098 };
40099
40100 struct reg_protocol_rd {
40101 diff -urNp linux-2.6.39.2/drivers/staging/solo6x10/g723.c linux-2.6.39.2/drivers/staging/solo6x10/g723.c
40102 --- linux-2.6.39.2/drivers/staging/solo6x10/g723.c 2011-05-19 00:06:34.000000000 -0400
40103 +++ linux-2.6.39.2/drivers/staging/solo6x10/g723.c 2011-05-22 19:36:32.000000000 -0400
40104 @@ -237,7 +237,7 @@ static int snd_solo_pcm_copy(struct snd_
40105 return 0;
40106 }
40107
40108 -static struct snd_pcm_ops snd_solo_pcm_ops = {
40109 +static const struct snd_pcm_ops snd_solo_pcm_ops = {
40110 .open = snd_solo_pcm_open,
40111 .close = snd_solo_pcm_close,
40112 .ioctl = snd_pcm_lib_ioctl,
40113 @@ -334,7 +334,7 @@ static int solo_snd_pcm_init(struct solo
40114
40115 int solo_g723_init(struct solo_dev *solo_dev)
40116 {
40117 - static struct snd_device_ops ops = { NULL };
40118 + static const struct snd_device_ops ops = { NULL };
40119 struct snd_card *card;
40120 struct snd_kcontrol_new kctl;
40121 char name[32];
40122 diff -urNp linux-2.6.39.2/drivers/staging/spectra/ffsport.c linux-2.6.39.2/drivers/staging/spectra/ffsport.c
40123 --- linux-2.6.39.2/drivers/staging/spectra/ffsport.c 2011-05-19 00:06:34.000000000 -0400
40124 +++ linux-2.6.39.2/drivers/staging/spectra/ffsport.c 2011-05-22 19:36:32.000000000 -0400
40125 @@ -604,7 +604,7 @@ int GLOB_SBD_unlocked_ioctl(struct block
40126 return ret;
40127 }
40128
40129 -static struct block_device_operations GLOB_SBD_ops = {
40130 +static const struct block_device_operations GLOB_SBD_ops = {
40131 .owner = THIS_MODULE,
40132 .open = GLOB_SBD_open,
40133 .release = GLOB_SBD_release,
40134 diff -urNp linux-2.6.39.2/drivers/staging/tm6000/tm6000-alsa.c linux-2.6.39.2/drivers/staging/tm6000/tm6000-alsa.c
40135 --- linux-2.6.39.2/drivers/staging/tm6000/tm6000-alsa.c 2011-05-19 00:06:34.000000000 -0400
40136 +++ linux-2.6.39.2/drivers/staging/tm6000/tm6000-alsa.c 2011-05-22 19:36:32.000000000 -0400
40137 @@ -380,7 +380,7 @@ static snd_pcm_uframes_t snd_tm6000_poin
40138 /*
40139 * operators
40140 */
40141 -static struct snd_pcm_ops snd_tm6000_pcm_ops = {
40142 +static const struct snd_pcm_ops snd_tm6000_pcm_ops = {
40143 .open = snd_tm6000_pcm_open,
40144 .close = snd_tm6000_close,
40145 .ioctl = snd_pcm_lib_ioctl,
40146 diff -urNp linux-2.6.39.2/drivers/staging/tty/istallion.c linux-2.6.39.2/drivers/staging/tty/istallion.c
40147 --- linux-2.6.39.2/drivers/staging/tty/istallion.c 2011-05-19 00:06:34.000000000 -0400
40148 +++ linux-2.6.39.2/drivers/staging/tty/istallion.c 2011-05-22 20:49:07.000000000 -0400
40149 @@ -186,7 +186,6 @@ static struct ktermios stli_deftermios
40150 * re-used for each stats call.
40151 */
40152 static comstats_t stli_comstats;
40153 -static combrd_t stli_brdstats;
40154 static struct asystats stli_cdkstats;
40155
40156 /*****************************************************************************/
40157 @@ -4003,6 +4002,7 @@ out:
40158
40159 static int stli_getbrdstats(combrd_t __user *bp)
40160 {
40161 + combrd_t stli_brdstats;
40162 struct stlibrd *brdp;
40163 unsigned int i;
40164
40165 @@ -4226,6 +4226,8 @@ static int stli_getportstruct(struct stl
40166 struct stliport stli_dummyport;
40167 struct stliport *portp;
40168
40169 + pax_track_stack();
40170 +
40171 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
40172 return -EFAULT;
40173 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
40174 @@ -4248,6 +4250,8 @@ static int stli_getbrdstruct(struct stli
40175 struct stlibrd stli_dummybrd;
40176 struct stlibrd *brdp;
40177
40178 + pax_track_stack();
40179 +
40180 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
40181 return -EFAULT;
40182 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
40183 diff -urNp linux-2.6.39.2/drivers/staging/tty/stallion.c linux-2.6.39.2/drivers/staging/tty/stallion.c
40184 --- linux-2.6.39.2/drivers/staging/tty/stallion.c 2011-05-19 00:06:34.000000000 -0400
40185 +++ linux-2.6.39.2/drivers/staging/tty/stallion.c 2011-05-22 19:36:32.000000000 -0400
40186 @@ -2406,6 +2406,8 @@ static int stl_getportstruct(struct stlp
40187 struct stlport stl_dummyport;
40188 struct stlport *portp;
40189
40190 + pax_track_stack();
40191 +
40192 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
40193 return -EFAULT;
40194 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
40195 diff -urNp linux-2.6.39.2/drivers/staging/usbip/vhci.h linux-2.6.39.2/drivers/staging/usbip/vhci.h
40196 --- linux-2.6.39.2/drivers/staging/usbip/vhci.h 2011-05-19 00:06:34.000000000 -0400
40197 +++ linux-2.6.39.2/drivers/staging/usbip/vhci.h 2011-05-22 19:36:32.000000000 -0400
40198 @@ -92,7 +92,7 @@ struct vhci_hcd {
40199 unsigned resuming:1;
40200 unsigned long re_timeout;
40201
40202 - atomic_t seqnum;
40203 + atomic_unchecked_t seqnum;
40204
40205 /*
40206 * NOTE:
40207 diff -urNp linux-2.6.39.2/drivers/staging/usbip/vhci_hcd.c linux-2.6.39.2/drivers/staging/usbip/vhci_hcd.c
40208 --- linux-2.6.39.2/drivers/staging/usbip/vhci_hcd.c 2011-05-19 00:06:34.000000000 -0400
40209 +++ linux-2.6.39.2/drivers/staging/usbip/vhci_hcd.c 2011-05-22 19:36:32.000000000 -0400
40210 @@ -536,7 +536,7 @@ static void vhci_tx_urb(struct urb *urb)
40211 return;
40212 }
40213
40214 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40215 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40216 if (priv->seqnum == 0xffff)
40217 usbip_uinfo("seqnum max\n");
40218
40219 @@ -795,7 +795,7 @@ static int vhci_urb_dequeue(struct usb_h
40220 return -ENOMEM;
40221 }
40222
40223 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40224 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40225 if (unlink->seqnum == 0xffff)
40226 usbip_uinfo("seqnum max\n");
40227
40228 @@ -992,7 +992,7 @@ static int vhci_start(struct usb_hcd *hc
40229 vdev->rhport = rhport;
40230 }
40231
40232 - atomic_set(&vhci->seqnum, 0);
40233 + atomic_set_unchecked(&vhci->seqnum, 0);
40234 spin_lock_init(&vhci->lock);
40235
40236
40237 diff -urNp linux-2.6.39.2/drivers/staging/usbip/vhci_rx.c linux-2.6.39.2/drivers/staging/usbip/vhci_rx.c
40238 --- linux-2.6.39.2/drivers/staging/usbip/vhci_rx.c 2011-05-19 00:06:34.000000000 -0400
40239 +++ linux-2.6.39.2/drivers/staging/usbip/vhci_rx.c 2011-05-22 19:36:32.000000000 -0400
40240 @@ -81,7 +81,7 @@ static void vhci_recv_ret_submit(struct
40241 usbip_uerr("cannot find a urb of seqnum %u\n",
40242 pdu->base.seqnum);
40243 usbip_uinfo("max seqnum %d\n",
40244 - atomic_read(&the_controller->seqnum));
40245 + atomic_read_unchecked(&the_controller->seqnum));
40246 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40247 return;
40248 }
40249 diff -urNp linux-2.6.39.2/drivers/staging/vme/devices/vme_user.c linux-2.6.39.2/drivers/staging/vme/devices/vme_user.c
40250 --- linux-2.6.39.2/drivers/staging/vme/devices/vme_user.c 2011-05-19 00:06:34.000000000 -0400
40251 +++ linux-2.6.39.2/drivers/staging/vme/devices/vme_user.c 2011-05-22 19:36:32.000000000 -0400
40252 @@ -138,7 +138,7 @@ static long vme_user_unlocked_ioctl(stru
40253 static int __devinit vme_user_probe(struct device *, int, int);
40254 static int __devexit vme_user_remove(struct device *, int, int);
40255
40256 -static struct file_operations vme_user_fops = {
40257 +static const struct file_operations vme_user_fops = {
40258 .open = vme_user_open,
40259 .release = vme_user_release,
40260 .read = vme_user_read,
40261 diff -urNp linux-2.6.39.2/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c linux-2.6.39.2/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c
40262 --- linux-2.6.39.2/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-19 00:06:34.000000000 -0400
40263 +++ linux-2.6.39.2/drivers/staging/westbridge/astoria/block/cyasblkdev_block.c 2011-05-22 19:36:32.000000000 -0400
40264 @@ -426,7 +426,7 @@ int cyasblkdev_revalidate_disk(struct ge
40265
40266
40267 /*standard block device driver interface */
40268 -static struct block_device_operations cyasblkdev_bdops = {
40269 +static const struct block_device_operations cyasblkdev_bdops = {
40270 .open = cyasblkdev_blk_open,
40271 .release = cyasblkdev_blk_release,
40272 .ioctl = cyasblkdev_blk_ioctl,
40273 diff -urNp linux-2.6.39.2/drivers/staging/wlags49_h2/wl_netdev.c linux-2.6.39.2/drivers/staging/wlags49_h2/wl_netdev.c
40274 --- linux-2.6.39.2/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-19 00:06:34.000000000 -0400
40275 +++ linux-2.6.39.2/drivers/staging/wlags49_h2/wl_netdev.c 2011-05-22 19:36:32.000000000 -0400
40276 @@ -474,7 +474,7 @@ static void wl_get_drvinfo(struct net_de
40277 }
40278 } // wl_get_drvinfo
40279
40280 -static struct ethtool_ops wl_ethtool_ops = {
40281 +static const struct ethtool_ops wl_ethtool_ops = {
40282 .get_drvinfo = wl_get_drvinfo,
40283 .get_link = ethtool_op_get_link,
40284 };
40285 diff -urNp linux-2.6.39.2/drivers/staging/wlan-ng/hfa384x_usb.c linux-2.6.39.2/drivers/staging/wlan-ng/hfa384x_usb.c
40286 --- linux-2.6.39.2/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-19 00:06:34.000000000 -0400
40287 +++ linux-2.6.39.2/drivers/staging/wlan-ng/hfa384x_usb.c 2011-05-22 19:36:32.000000000 -0400
40288 @@ -671,7 +671,7 @@ struct usbctlx_cmd_completor {
40289 hfa384x_cmdresult_t *result;
40290 };
40291
40292 -static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
40293 +static inline int usbctlx_cmd_completor_fn(const struct usbctlx_completor *head)
40294 {
40295 struct usbctlx_cmd_completor *complete;
40296
40297 @@ -705,7 +705,7 @@ struct usbctlx_rrid_completor {
40298 unsigned int riddatalen;
40299 };
40300
40301 -static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
40302 +static int usbctlx_rrid_completor_fn(const struct usbctlx_completor *head)
40303 {
40304 struct usbctlx_rrid_completor *complete;
40305 hfa384x_rridresult_t rridresult;
40306 @@ -768,7 +768,7 @@ struct usbctlx_rmem_completor {
40307 };
40308 typedef struct usbctlx_rmem_completor usbctlx_rmem_completor_t;
40309
40310 -static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
40311 +static int usbctlx_rmem_completor_fn(const struct usbctlx_completor *head)
40312 {
40313 usbctlx_rmem_completor_t *complete = (usbctlx_rmem_completor_t *) head;
40314
40315 diff -urNp linux-2.6.39.2/drivers/staging/zcache/tmem.c linux-2.6.39.2/drivers/staging/zcache/tmem.c
40316 --- linux-2.6.39.2/drivers/staging/zcache/tmem.c 2011-05-19 00:06:34.000000000 -0400
40317 +++ linux-2.6.39.2/drivers/staging/zcache/tmem.c 2011-05-22 19:36:32.000000000 -0400
40318 @@ -39,7 +39,7 @@
40319 * A tmem host implementation must use this function to register callbacks
40320 * for memory allocation.
40321 */
40322 -static struct tmem_hostops tmem_hostops;
40323 +static const struct tmem_hostops tmem_hostops;
40324
40325 static void tmem_objnode_tree_init(void);
40326
40327 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_h
40328 * A tmem host implementation must use this function to register
40329 * callbacks for a page-accessible memory (PAM) implementation
40330 */
40331 -static struct tmem_pamops tmem_pamops;
40332 +static const struct tmem_pamops tmem_pamops;
40333
40334 void tmem_register_pamops(struct tmem_pamops *m)
40335 {
40336 diff -urNp linux-2.6.39.2/drivers/staging/zcache/zcache.c linux-2.6.39.2/drivers/staging/zcache/zcache.c
40337 --- linux-2.6.39.2/drivers/staging/zcache/zcache.c 2011-05-19 00:06:34.000000000 -0400
40338 +++ linux-2.6.39.2/drivers/staging/zcache/zcache.c 2011-05-22 19:36:32.000000000 -0400
40339 @@ -882,7 +882,7 @@ static void zcache_obj_free(struct tmem_
40340 kmem_cache_free(zcache_obj_cache, obj);
40341 }
40342
40343 -static struct tmem_hostops zcache_hostops = {
40344 +static const struct tmem_hostops zcache_hostops = {
40345 .obj_alloc = zcache_obj_alloc,
40346 .obj_free = zcache_obj_free,
40347 .objnode_alloc = zcache_objnode_alloc,
40348 @@ -987,7 +987,7 @@ static void zcache_pampd_free(void *pamp
40349 }
40350 }
40351
40352 -static struct tmem_pamops zcache_pamops = {
40353 +static const struct tmem_pamops zcache_pamops = {
40354 .create = zcache_pampd_create,
40355 .get_data = zcache_pampd_get_data,
40356 .free = zcache_pampd_free,
40357 diff -urNp linux-2.6.39.2/drivers/target/target_core_alua.c linux-2.6.39.2/drivers/target/target_core_alua.c
40358 --- linux-2.6.39.2/drivers/target/target_core_alua.c 2011-05-19 00:06:34.000000000 -0400
40359 +++ linux-2.6.39.2/drivers/target/target_core_alua.c 2011-05-22 19:36:32.000000000 -0400
40360 @@ -675,6 +675,8 @@ static int core_alua_update_tpg_primary_
40361 char path[ALUA_METADATA_PATH_LEN];
40362 int len;
40363
40364 + pax_track_stack();
40365 +
40366 memset(path, 0, ALUA_METADATA_PATH_LEN);
40367
40368 len = snprintf(md_buf, tg_pt_gp->tg_pt_gp_md_buf_len,
40369 @@ -938,6 +940,8 @@ static int core_alua_update_tpg_secondar
40370 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN];
40371 int len;
40372
40373 + pax_track_stack();
40374 +
40375 memset(path, 0, ALUA_METADATA_PATH_LEN);
40376 memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN);
40377
40378 diff -urNp linux-2.6.39.2/drivers/target/target_core_cdb.c linux-2.6.39.2/drivers/target/target_core_cdb.c
40379 --- linux-2.6.39.2/drivers/target/target_core_cdb.c 2011-05-19 00:06:34.000000000 -0400
40380 +++ linux-2.6.39.2/drivers/target/target_core_cdb.c 2011-05-22 19:36:32.000000000 -0400
40381 @@ -838,6 +838,8 @@ target_emulate_modesense(struct se_cmd *
40382 int length = 0;
40383 unsigned char buf[SE_MODE_PAGE_BUF];
40384
40385 + pax_track_stack();
40386 +
40387 memset(buf, 0, SE_MODE_PAGE_BUF);
40388
40389 switch (cdb[2] & 0x3f) {
40390 diff -urNp linux-2.6.39.2/drivers/target/target_core_configfs.c linux-2.6.39.2/drivers/target/target_core_configfs.c
40391 --- linux-2.6.39.2/drivers/target/target_core_configfs.c 2011-05-19 00:06:34.000000000 -0400
40392 +++ linux-2.6.39.2/drivers/target/target_core_configfs.c 2011-05-22 19:36:32.000000000 -0400
40393 @@ -1280,6 +1280,8 @@ static ssize_t target_core_dev_pr_show_a
40394 ssize_t len = 0;
40395 int reg_count = 0, prf_isid;
40396
40397 + pax_track_stack();
40398 +
40399 if (!(su_dev->se_dev_ptr))
40400 return -ENODEV;
40401
40402 @@ -2682,7 +2684,7 @@ static void target_core_alua_drop_tg_pt_
40403 config_item_put(item);
40404 }
40405
40406 -static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40407 +static const struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
40408 .make_group = &target_core_alua_create_tg_pt_gp,
40409 .drop_item = &target_core_alua_drop_tg_pt_gp,
40410 };
40411 @@ -2726,7 +2728,7 @@ static void target_core_stat_rmdir(
40412 return;
40413 }
40414
40415 -static struct configfs_group_operations target_core_stat_group_ops = {
40416 +static const struct configfs_group_operations target_core_stat_group_ops = {
40417 .make_group = &target_core_stat_mkdir,
40418 .drop_item = &target_core_stat_rmdir,
40419 };
40420 @@ -2939,7 +2941,7 @@ static void target_core_drop_subdev(
40421 mutex_unlock(&hba->hba_access_mutex);
40422 }
40423
40424 -static struct configfs_group_operations target_core_hba_group_ops = {
40425 +static const struct configfs_group_operations target_core_hba_group_ops = {
40426 .make_group = target_core_make_subdev,
40427 .drop_item = target_core_drop_subdev,
40428 };
40429 @@ -3117,7 +3119,7 @@ static void target_core_call_delhbafromt
40430 config_item_put(item);
40431 }
40432
40433 -static struct configfs_group_operations target_core_group_ops = {
40434 +static const struct configfs_group_operations target_core_group_ops = {
40435 .make_group = target_core_call_addhbatotarget,
40436 .drop_item = target_core_call_delhbafromtarget,
40437 };
40438 diff -urNp linux-2.6.39.2/drivers/target/target_core_fabric_configfs.c linux-2.6.39.2/drivers/target/target_core_fabric_configfs.c
40439 --- linux-2.6.39.2/drivers/target/target_core_fabric_configfs.c 2011-05-19 00:06:34.000000000 -0400
40440 +++ linux-2.6.39.2/drivers/target/target_core_fabric_configfs.c 2011-05-22 19:36:32.000000000 -0400
40441 @@ -1174,7 +1174,7 @@ static void target_fabric_drop_wwn(
40442 config_item_put(item);
40443 }
40444
40445 -static struct configfs_group_operations target_fabric_wwn_group_ops = {
40446 +static const struct configfs_group_operations target_fabric_wwn_group_ops = {
40447 .make_group = target_fabric_make_wwn,
40448 .drop_item = target_fabric_drop_wwn,
40449 };
40450 diff -urNp linux-2.6.39.2/drivers/target/target_core_pr.c linux-2.6.39.2/drivers/target/target_core_pr.c
40451 --- linux-2.6.39.2/drivers/target/target_core_pr.c 2011-05-19 00:06:34.000000000 -0400
40452 +++ linux-2.6.39.2/drivers/target/target_core_pr.c 2011-05-22 19:36:32.000000000 -0400
40453 @@ -918,6 +918,8 @@ static int __core_scsi3_check_aptpl_regi
40454 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
40455 u16 tpgt;
40456
40457 + pax_track_stack();
40458 +
40459 memset(i_port, 0, PR_APTPL_MAX_IPORT_LEN);
40460 memset(t_port, 0, PR_APTPL_MAX_TPORT_LEN);
40461 /*
40462 @@ -1861,6 +1863,8 @@ static int __core_scsi3_update_aptpl_buf
40463 ssize_t len = 0;
40464 int reg_count = 0;
40465
40466 + pax_track_stack();
40467 +
40468 memset(buf, 0, pr_aptpl_buf_len);
40469 /*
40470 * Called to clear metadata once APTPL has been deactivated.
40471 @@ -1983,6 +1987,8 @@ static int __core_scsi3_write_aptpl_to_f
40472 char path[512];
40473 int ret;
40474
40475 + pax_track_stack();
40476 +
40477 memset(iov, 0, sizeof(struct iovec));
40478 memset(path, 0, 512);
40479
40480 diff -urNp linux-2.6.39.2/drivers/target/target_core_tmr.c linux-2.6.39.2/drivers/target/target_core_tmr.c
40481 --- linux-2.6.39.2/drivers/target/target_core_tmr.c 2011-06-03 00:04:14.000000000 -0400
40482 +++ linux-2.6.39.2/drivers/target/target_core_tmr.c 2011-06-03 00:32:07.000000000 -0400
40483 @@ -263,7 +263,7 @@ int core_tmr_lun_reset(
40484 CMD_TFO(cmd)->get_task_tag(cmd), cmd->pr_res_key,
40485 T_TASK(cmd)->t_task_cdbs,
40486 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40487 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40488 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40489 atomic_read(&T_TASK(cmd)->t_transport_active),
40490 atomic_read(&T_TASK(cmd)->t_transport_stop),
40491 atomic_read(&T_TASK(cmd)->t_transport_sent));
40492 @@ -305,7 +305,7 @@ int core_tmr_lun_reset(
40493 DEBUG_LR("LUN_RESET: got t_transport_active = 1 for"
40494 " task: %p, t_fe_count: %d dev: %p\n", task,
40495 fe_count, dev);
40496 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40497 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40498 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock,
40499 flags);
40500 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40501 @@ -315,7 +315,7 @@ int core_tmr_lun_reset(
40502 }
40503 DEBUG_LR("LUN_RESET: Got t_transport_active = 0 for task: %p,"
40504 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
40505 - atomic_set(&T_TASK(cmd)->t_transport_aborted, 1);
40506 + atomic_set_unchecked(&T_TASK(cmd)->t_transport_aborted, 1);
40507 spin_unlock_irqrestore(&T_TASK(cmd)->t_state_lock, flags);
40508 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
40509
40510 diff -urNp linux-2.6.39.2/drivers/target/target_core_transport.c linux-2.6.39.2/drivers/target/target_core_transport.c
40511 --- linux-2.6.39.2/drivers/target/target_core_transport.c 2011-06-03 00:04:14.000000000 -0400
40512 +++ linux-2.6.39.2/drivers/target/target_core_transport.c 2011-06-03 00:32:07.000000000 -0400
40513 @@ -1681,7 +1681,7 @@ struct se_device *transport_add_device_t
40514
40515 dev->queue_depth = dev_limits->queue_depth;
40516 atomic_set(&dev->depth_left, dev->queue_depth);
40517 - atomic_set(&dev->dev_ordered_id, 0);
40518 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
40519
40520 se_dev_set_default_attribs(dev, dev_limits);
40521
40522 @@ -1882,7 +1882,7 @@ static int transport_check_alloc_task_at
40523 * Used to determine when ORDERED commands should go from
40524 * Dormant to Active status.
40525 */
40526 - cmd->se_ordered_id = atomic_inc_return(&SE_DEV(cmd)->dev_ordered_id);
40527 + cmd->se_ordered_id = atomic_inc_return_unchecked(&SE_DEV(cmd)->dev_ordered_id);
40528 smp_mb__after_atomic_inc();
40529 DEBUG_STA("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40530 cmd->se_ordered_id, cmd->sam_task_attr,
40531 @@ -2169,7 +2169,7 @@ static void transport_generic_request_fa
40532 " t_transport_active: %d t_transport_stop: %d"
40533 " t_transport_sent: %d\n", T_TASK(cmd)->t_task_cdbs,
40534 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40535 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40536 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40537 atomic_read(&T_TASK(cmd)->t_task_cdbs_ex_left),
40538 atomic_read(&T_TASK(cmd)->t_transport_active),
40539 atomic_read(&T_TASK(cmd)->t_transport_stop),
40540 @@ -2673,9 +2673,9 @@ check_depth:
40541 spin_lock_irqsave(&T_TASK(cmd)->t_state_lock, flags);
40542 atomic_set(&task->task_active, 1);
40543 atomic_set(&task->task_sent, 1);
40544 - atomic_inc(&T_TASK(cmd)->t_task_cdbs_sent);
40545 + atomic_inc_unchecked(&T_TASK(cmd)->t_task_cdbs_sent);
40546
40547 - if (atomic_read(&T_TASK(cmd)->t_task_cdbs_sent) ==
40548 + if (atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent) ==
40549 T_TASK(cmd)->t_task_cdbs)
40550 atomic_set(&cmd->transport_sent, 1);
40551
40552 @@ -5568,7 +5568,7 @@ static void transport_generic_wait_for_t
40553 atomic_set(&T_TASK(cmd)->transport_lun_stop, 0);
40554 }
40555 if (!atomic_read(&T_TASK(cmd)->t_transport_active) ||
40556 - atomic_read(&T_TASK(cmd)->t_transport_aborted))
40557 + atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted))
40558 goto remove;
40559
40560 atomic_set(&T_TASK(cmd)->t_transport_stop, 1);
40561 @@ -5797,7 +5797,7 @@ int transport_check_aborted_status(struc
40562 {
40563 int ret = 0;
40564
40565 - if (atomic_read(&T_TASK(cmd)->t_transport_aborted) != 0) {
40566 + if (atomic_read_unchecked(&T_TASK(cmd)->t_transport_aborted) != 0) {
40567 if (!(send_status) ||
40568 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
40569 return 1;
40570 @@ -5825,7 +5825,7 @@ void transport_send_task_abort(struct se
40571 */
40572 if (cmd->data_direction == DMA_TO_DEVICE) {
40573 if (CMD_TFO(cmd)->write_pending_status(cmd) != 0) {
40574 - atomic_inc(&T_TASK(cmd)->t_transport_aborted);
40575 + atomic_inc_unchecked(&T_TASK(cmd)->t_transport_aborted);
40576 smp_mb__after_atomic_inc();
40577 cmd->scsi_status = SAM_STAT_TASK_ABORTED;
40578 transport_new_cmd_failure(cmd);
40579 @@ -5949,7 +5949,7 @@ static void transport_processing_shutdow
40580 CMD_TFO(cmd)->get_task_tag(cmd),
40581 T_TASK(cmd)->t_task_cdbs,
40582 atomic_read(&T_TASK(cmd)->t_task_cdbs_left),
40583 - atomic_read(&T_TASK(cmd)->t_task_cdbs_sent),
40584 + atomic_read_unchecked(&T_TASK(cmd)->t_task_cdbs_sent),
40585 atomic_read(&T_TASK(cmd)->t_transport_active),
40586 atomic_read(&T_TASK(cmd)->t_transport_stop),
40587 atomic_read(&T_TASK(cmd)->t_transport_sent));
40588 diff -urNp linux-2.6.39.2/drivers/telephony/ixj.c linux-2.6.39.2/drivers/telephony/ixj.c
40589 --- linux-2.6.39.2/drivers/telephony/ixj.c 2011-05-19 00:06:34.000000000 -0400
40590 +++ linux-2.6.39.2/drivers/telephony/ixj.c 2011-05-22 19:36:32.000000000 -0400
40591 @@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
40592 bool mContinue;
40593 char *pIn, *pOut;
40594
40595 + pax_track_stack();
40596 +
40597 if (!SCI_Prepare(j))
40598 return 0;
40599
40600 diff -urNp linux-2.6.39.2/drivers/tty/hvc/hvc_console.h linux-2.6.39.2/drivers/tty/hvc/hvc_console.h
40601 --- linux-2.6.39.2/drivers/tty/hvc/hvc_console.h 2011-05-19 00:06:34.000000000 -0400
40602 +++ linux-2.6.39.2/drivers/tty/hvc/hvc_console.h 2011-05-22 19:36:32.000000000 -0400
40603 @@ -82,6 +82,7 @@ extern int hvc_instantiate(uint32_t vter
40604 /* register a vterm for hvc tty operation (module_init or hotplug add) */
40605 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
40606 const struct hv_ops *ops, int outbuf_size);
40607 +
40608 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
40609 extern int hvc_remove(struct hvc_struct *hp);
40610
40611 diff -urNp linux-2.6.39.2/drivers/tty/hvc/hvc_iucv.c linux-2.6.39.2/drivers/tty/hvc/hvc_iucv.c
40612 --- linux-2.6.39.2/drivers/tty/hvc/hvc_iucv.c 2011-05-19 00:06:34.000000000 -0400
40613 +++ linux-2.6.39.2/drivers/tty/hvc/hvc_iucv.c 2011-05-22 19:36:32.000000000 -0400
40614 @@ -1203,7 +1203,7 @@ static int param_get_vmidfilter(char *bu
40615
40616 #define param_check_vmidfilter(name, p) __param_check(name, p, void)
40617
40618 -static struct kernel_param_ops param_ops_vmidfilter = {
40619 +static const struct kernel_param_ops param_ops_vmidfilter = {
40620 .set = param_set_vmidfilter,
40621 .get = param_get_vmidfilter,
40622 };
40623 diff -urNp linux-2.6.39.2/drivers/tty/hvc/hvcs.c linux-2.6.39.2/drivers/tty/hvc/hvcs.c
40624 --- linux-2.6.39.2/drivers/tty/hvc/hvcs.c 2011-05-19 00:06:34.000000000 -0400
40625 +++ linux-2.6.39.2/drivers/tty/hvc/hvcs.c 2011-05-22 19:36:32.000000000 -0400
40626 @@ -83,6 +83,7 @@
40627 #include <asm/hvcserver.h>
40628 #include <asm/uaccess.h>
40629 #include <asm/vio.h>
40630 +#include <asm/local.h>
40631
40632 /*
40633 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40634 @@ -270,7 +271,7 @@ struct hvcs_struct {
40635 unsigned int index;
40636
40637 struct tty_struct *tty;
40638 - int open_count;
40639 + local_t open_count;
40640
40641 /*
40642 * Used to tell the driver kernel_thread what operations need to take
40643 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(st
40644
40645 spin_lock_irqsave(&hvcsd->lock, flags);
40646
40647 - if (hvcsd->open_count > 0) {
40648 + if (local_read(&hvcsd->open_count) > 0) {
40649 spin_unlock_irqrestore(&hvcsd->lock, flags);
40650 printk(KERN_INFO "HVCS: vterm state unchanged. "
40651 "The hvcs device node is still in use.\n");
40652 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *
40653 if ((retval = hvcs_partner_connect(hvcsd)))
40654 goto error_release;
40655
40656 - hvcsd->open_count = 1;
40657 + local_set(&hvcsd->open_count, 1);
40658 hvcsd->tty = tty;
40659 tty->driver_data = hvcsd;
40660
40661 @@ -1179,7 +1180,7 @@ fast_open:
40662
40663 spin_lock_irqsave(&hvcsd->lock, flags);
40664 kref_get(&hvcsd->kref);
40665 - hvcsd->open_count++;
40666 + local_inc(&hvcsd->open_count);
40667 hvcsd->todo_mask |= HVCS_SCHED_READ;
40668 spin_unlock_irqrestore(&hvcsd->lock, flags);
40669
40670 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct
40671 hvcsd = tty->driver_data;
40672
40673 spin_lock_irqsave(&hvcsd->lock, flags);
40674 - if (--hvcsd->open_count == 0) {
40675 + if (local_dec_and_test(&hvcsd->open_count)) {
40676
40677 vio_disable_interrupts(hvcsd->vdev);
40678
40679 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct
40680 free_irq(irq, hvcsd);
40681 kref_put(&hvcsd->kref, destroy_hvcs_struct);
40682 return;
40683 - } else if (hvcsd->open_count < 0) {
40684 + } else if (local_read(&hvcsd->open_count) < 0) {
40685 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40686 " is missmanaged.\n",
40687 - hvcsd->vdev->unit_address, hvcsd->open_count);
40688 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
40689 }
40690
40691 spin_unlock_irqrestore(&hvcsd->lock, flags);
40692 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struc
40693
40694 spin_lock_irqsave(&hvcsd->lock, flags);
40695 /* Preserve this so that we know how many kref refs to put */
40696 - temp_open_count = hvcsd->open_count;
40697 + temp_open_count = local_read(&hvcsd->open_count);
40698
40699 /*
40700 * Don't kref put inside the spinlock because the destruction
40701 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struc
40702 hvcsd->tty->driver_data = NULL;
40703 hvcsd->tty = NULL;
40704
40705 - hvcsd->open_count = 0;
40706 + local_set(&hvcsd->open_count, 0);
40707
40708 /* This will drop any buffered data on the floor which is OK in a hangup
40709 * scenario. */
40710 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct
40711 * the middle of a write operation? This is a crummy place to do this
40712 * but we want to keep it all in the spinlock.
40713 */
40714 - if (hvcsd->open_count <= 0) {
40715 + if (local_read(&hvcsd->open_count) <= 0) {
40716 spin_unlock_irqrestore(&hvcsd->lock, flags);
40717 return -ENODEV;
40718 }
40719 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_st
40720 {
40721 struct hvcs_struct *hvcsd = tty->driver_data;
40722
40723 - if (!hvcsd || hvcsd->open_count <= 0)
40724 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
40725 return 0;
40726
40727 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40728 diff -urNp linux-2.6.39.2/drivers/tty/hvc/hvc_xen.c linux-2.6.39.2/drivers/tty/hvc/hvc_xen.c
40729 --- linux-2.6.39.2/drivers/tty/hvc/hvc_xen.c 2011-05-19 00:06:34.000000000 -0400
40730 +++ linux-2.6.39.2/drivers/tty/hvc/hvc_xen.c 2011-05-22 19:36:32.000000000 -0400
40731 @@ -123,7 +123,7 @@ static int domU_read_console(uint32_t vt
40732 return recv;
40733 }
40734
40735 -static struct hv_ops domU_hvc_ops = {
40736 +static const struct hv_ops domU_hvc_ops = {
40737 .get_chars = domU_read_console,
40738 .put_chars = domU_write_console,
40739 .notifier_add = notifier_add_irq,
40740 @@ -149,7 +149,7 @@ static int dom0_write_console(uint32_t v
40741 return len;
40742 }
40743
40744 -static struct hv_ops dom0_hvc_ops = {
40745 +static const struct hv_ops dom0_hvc_ops = {
40746 .get_chars = dom0_read_console,
40747 .put_chars = dom0_write_console,
40748 .notifier_add = notifier_add_irq,
40749 @@ -160,7 +160,7 @@ static struct hv_ops dom0_hvc_ops = {
40750 static int __init xen_hvc_init(void)
40751 {
40752 struct hvc_struct *hp;
40753 - struct hv_ops *ops;
40754 + const struct hv_ops *ops;
40755
40756 if (!xen_pv_domain())
40757 return -ENODEV;
40758 @@ -205,7 +205,7 @@ static void __exit xen_hvc_fini(void)
40759
40760 static int xen_cons_init(void)
40761 {
40762 - struct hv_ops *ops;
40763 + const struct hv_ops *ops;
40764
40765 if (!xen_pv_domain())
40766 return 0;
40767 diff -urNp linux-2.6.39.2/drivers/tty/ipwireless/tty.c linux-2.6.39.2/drivers/tty/ipwireless/tty.c
40768 --- linux-2.6.39.2/drivers/tty/ipwireless/tty.c 2011-05-19 00:06:34.000000000 -0400
40769 +++ linux-2.6.39.2/drivers/tty/ipwireless/tty.c 2011-05-22 19:36:32.000000000 -0400
40770 @@ -29,6 +29,7 @@
40771 #include <linux/tty_driver.h>
40772 #include <linux/tty_flip.h>
40773 #include <linux/uaccess.h>
40774 +#include <asm/local.h>
40775
40776 #include "tty.h"
40777 #include "network.h"
40778 @@ -51,7 +52,7 @@ struct ipw_tty {
40779 int tty_type;
40780 struct ipw_network *network;
40781 struct tty_struct *linux_tty;
40782 - int open_count;
40783 + local_t open_count;
40784 unsigned int control_lines;
40785 struct mutex ipw_tty_mutex;
40786 int tx_bytes_queued;
40787 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *l
40788 mutex_unlock(&tty->ipw_tty_mutex);
40789 return -ENODEV;
40790 }
40791 - if (tty->open_count == 0)
40792 + if (local_read(&tty->open_count) == 0)
40793 tty->tx_bytes_queued = 0;
40794
40795 - tty->open_count++;
40796 + local_inc(&tty->open_count);
40797
40798 tty->linux_tty = linux_tty;
40799 linux_tty->driver_data = tty;
40800 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *l
40801
40802 static void do_ipw_close(struct ipw_tty *tty)
40803 {
40804 - tty->open_count--;
40805 -
40806 - if (tty->open_count == 0) {
40807 + if (local_dec_return(&tty->open_count) == 0) {
40808 struct tty_struct *linux_tty = tty->linux_tty;
40809
40810 if (linux_tty != NULL) {
40811 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct
40812 return;
40813
40814 mutex_lock(&tty->ipw_tty_mutex);
40815 - if (tty->open_count == 0) {
40816 + if (local_read(&tty->open_count) == 0) {
40817 mutex_unlock(&tty->ipw_tty_mutex);
40818 return;
40819 }
40820 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_
40821 return;
40822 }
40823
40824 - if (!tty->open_count) {
40825 + if (!local_read(&tty->open_count)) {
40826 mutex_unlock(&tty->ipw_tty_mutex);
40827 return;
40828 }
40829 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *
40830 return -ENODEV;
40831
40832 mutex_lock(&tty->ipw_tty_mutex);
40833 - if (!tty->open_count) {
40834 + if (!local_read(&tty->open_count)) {
40835 mutex_unlock(&tty->ipw_tty_mutex);
40836 return -EINVAL;
40837 }
40838 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_str
40839 if (!tty)
40840 return -ENODEV;
40841
40842 - if (!tty->open_count)
40843 + if (!local_read(&tty->open_count))
40844 return -EINVAL;
40845
40846 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40847 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tt
40848 if (!tty)
40849 return 0;
40850
40851 - if (!tty->open_count)
40852 + if (!local_read(&tty->open_count))
40853 return 0;
40854
40855 return tty->tx_bytes_queued;
40856 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struc
40857 if (!tty)
40858 return -ENODEV;
40859
40860 - if (!tty->open_count)
40861 + if (!local_read(&tty->open_count))
40862 return -EINVAL;
40863
40864 return get_control_lines(tty);
40865 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tt
40866 if (!tty)
40867 return -ENODEV;
40868
40869 - if (!tty->open_count)
40870 + if (!local_read(&tty->open_count))
40871 return -EINVAL;
40872
40873 return set_control_lines(tty, set, clear);
40874 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *
40875 if (!tty)
40876 return -ENODEV;
40877
40878 - if (!tty->open_count)
40879 + if (!local_read(&tty->open_count))
40880 return -EINVAL;
40881
40882 /* FIXME: Exactly how is the tty object locked here .. */
40883 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty
40884 against a parallel ioctl etc */
40885 mutex_lock(&ttyj->ipw_tty_mutex);
40886 }
40887 - while (ttyj->open_count)
40888 + while (local_read(&ttyj->open_count))
40889 do_ipw_close(ttyj);
40890 ipwireless_disassociate_network_ttys(network,
40891 ttyj->channel_idx);
40892 diff -urNp linux-2.6.39.2/drivers/tty/mxser.c linux-2.6.39.2/drivers/tty/mxser.c
40893 --- linux-2.6.39.2/drivers/tty/mxser.c 2011-05-19 00:06:34.000000000 -0400
40894 +++ linux-2.6.39.2/drivers/tty/mxser.c 2011-05-22 19:36:32.000000000 -0400
40895 @@ -2340,7 +2340,7 @@ static const struct tty_operations mxser
40896 .get_icount = mxser_get_icount,
40897 };
40898
40899 -struct tty_port_operations mxser_port_ops = {
40900 +const struct tty_port_operations mxser_port_ops = {
40901 .carrier_raised = mxser_carrier_raised,
40902 .dtr_rts = mxser_dtr_rts,
40903 .activate = mxser_activate,
40904 diff -urNp linux-2.6.39.2/drivers/tty/n_gsm.c linux-2.6.39.2/drivers/tty/n_gsm.c
40905 --- linux-2.6.39.2/drivers/tty/n_gsm.c 2011-05-19 00:06:34.000000000 -0400
40906 +++ linux-2.6.39.2/drivers/tty/n_gsm.c 2011-05-22 19:36:32.000000000 -0400
40907 @@ -1588,7 +1588,7 @@ static struct gsm_dlci *gsm_dlci_alloc(s
40908 return NULL;
40909 spin_lock_init(&dlci->lock);
40910 dlci->fifo = &dlci->_fifo;
40911 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40912 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40913 kfree(dlci);
40914 return NULL;
40915 }
40916 diff -urNp linux-2.6.39.2/drivers/tty/n_tty.c linux-2.6.39.2/drivers/tty/n_tty.c
40917 --- linux-2.6.39.2/drivers/tty/n_tty.c 2011-05-19 00:06:34.000000000 -0400
40918 +++ linux-2.6.39.2/drivers/tty/n_tty.c 2011-05-22 19:36:32.000000000 -0400
40919 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_
40920 {
40921 *ops = tty_ldisc_N_TTY;
40922 ops->owner = NULL;
40923 - ops->refcount = ops->flags = 0;
40924 + atomic_set(&ops->refcount, 0);
40925 + ops->flags = 0;
40926 }
40927 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40928 diff -urNp linux-2.6.39.2/drivers/tty/pty.c linux-2.6.39.2/drivers/tty/pty.c
40929 --- linux-2.6.39.2/drivers/tty/pty.c 2011-05-19 00:06:34.000000000 -0400
40930 +++ linux-2.6.39.2/drivers/tty/pty.c 2011-05-22 19:36:32.000000000 -0400
40931 @@ -699,7 +699,18 @@ out:
40932 return retval;
40933 }
40934
40935 -static struct file_operations ptmx_fops;
40936 +static const struct file_operations ptmx_fops = {
40937 + .llseek = no_llseek,
40938 + .read = tty_read,
40939 + .write = tty_write,
40940 + .poll = tty_poll,
40941 + .unlocked_ioctl = tty_ioctl,
40942 + .compat_ioctl = tty_compat_ioctl,
40943 + .open = ptmx_open,
40944 + .release = tty_release,
40945 + .fasync = tty_fasync,
40946 +};
40947 +
40948
40949 static void __init unix98_pty_init(void)
40950 {
40951 @@ -752,10 +763,6 @@ static void __init unix98_pty_init(void)
40952
40953 register_sysctl_table(pty_root_table);
40954
40955 - /* Now create the /dev/ptmx special device */
40956 - tty_default_fops(&ptmx_fops);
40957 - ptmx_fops.open = ptmx_open;
40958 -
40959 cdev_init(&ptmx_cdev, &ptmx_fops);
40960 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40961 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
40962 diff -urNp linux-2.6.39.2/drivers/tty/rocket.c linux-2.6.39.2/drivers/tty/rocket.c
40963 --- linux-2.6.39.2/drivers/tty/rocket.c 2011-05-19 00:06:34.000000000 -0400
40964 +++ linux-2.6.39.2/drivers/tty/rocket.c 2011-05-22 19:36:32.000000000 -0400
40965 @@ -1277,6 +1277,8 @@ static int get_ports(struct r_port *info
40966 struct rocket_ports tmp;
40967 int board;
40968
40969 + pax_track_stack();
40970 +
40971 if (!retports)
40972 return -EFAULT;
40973 memset(&tmp, 0, sizeof (tmp));
40974 diff -urNp linux-2.6.39.2/drivers/tty/serial/21285.c linux-2.6.39.2/drivers/tty/serial/21285.c
40975 --- linux-2.6.39.2/drivers/tty/serial/21285.c 2011-05-19 00:06:34.000000000 -0400
40976 +++ linux-2.6.39.2/drivers/tty/serial/21285.c 2011-05-22 19:36:32.000000000 -0400
40977 @@ -340,7 +340,7 @@ static int serial21285_verify_port(struc
40978 return ret;
40979 }
40980
40981 -static struct uart_ops serial21285_ops = {
40982 +static const struct uart_ops serial21285_ops = {
40983 .tx_empty = serial21285_tx_empty,
40984 .get_mctrl = serial21285_get_mctrl,
40985 .set_mctrl = serial21285_set_mctrl,
40986 diff -urNp linux-2.6.39.2/drivers/tty/serial/8250.c linux-2.6.39.2/drivers/tty/serial/8250.c
40987 --- linux-2.6.39.2/drivers/tty/serial/8250.c 2011-05-19 00:06:34.000000000 -0400
40988 +++ linux-2.6.39.2/drivers/tty/serial/8250.c 2011-05-22 19:36:32.000000000 -0400
40989 @@ -2708,7 +2708,7 @@ serial8250_type(struct uart_port *port)
40990 return uart_config[type].name;
40991 }
40992
40993 -static struct uart_ops serial8250_pops = {
40994 +static const struct uart_ops serial8250_pops = {
40995 .tx_empty = serial8250_tx_empty,
40996 .set_mctrl = serial8250_set_mctrl,
40997 .get_mctrl = serial8250_get_mctrl,
40998 diff -urNp linux-2.6.39.2/drivers/tty/serial/altera_jtaguart.c linux-2.6.39.2/drivers/tty/serial/altera_jtaguart.c
40999 --- linux-2.6.39.2/drivers/tty/serial/altera_jtaguart.c 2011-05-19 00:06:34.000000000 -0400
41000 +++ linux-2.6.39.2/drivers/tty/serial/altera_jtaguart.c 2011-05-22 19:36:32.000000000 -0400
41001 @@ -281,7 +281,7 @@ static int altera_jtaguart_verify_port(s
41002 /*
41003 * Define the basic serial functions we support.
41004 */
41005 -static struct uart_ops altera_jtaguart_ops = {
41006 +static const struct uart_ops altera_jtaguart_ops = {
41007 .tx_empty = altera_jtaguart_tx_empty,
41008 .get_mctrl = altera_jtaguart_get_mctrl,
41009 .set_mctrl = altera_jtaguart_set_mctrl,
41010 diff -urNp linux-2.6.39.2/drivers/tty/serial/altera_uart.c linux-2.6.39.2/drivers/tty/serial/altera_uart.c
41011 --- linux-2.6.39.2/drivers/tty/serial/altera_uart.c 2011-05-19 00:06:34.000000000 -0400
41012 +++ linux-2.6.39.2/drivers/tty/serial/altera_uart.c 2011-05-22 19:36:32.000000000 -0400
41013 @@ -380,7 +380,7 @@ static int altera_uart_verify_port(struc
41014 /*
41015 * Define the basic serial functions we support.
41016 */
41017 -static struct uart_ops altera_uart_ops = {
41018 +static const struct uart_ops altera_uart_ops = {
41019 .tx_empty = altera_uart_tx_empty,
41020 .get_mctrl = altera_uart_get_mctrl,
41021 .set_mctrl = altera_uart_set_mctrl,
41022 diff -urNp linux-2.6.39.2/drivers/tty/serial/amba-pl010.c linux-2.6.39.2/drivers/tty/serial/amba-pl010.c
41023 --- linux-2.6.39.2/drivers/tty/serial/amba-pl010.c 2011-05-19 00:06:34.000000000 -0400
41024 +++ linux-2.6.39.2/drivers/tty/serial/amba-pl010.c 2011-05-22 19:36:32.000000000 -0400
41025 @@ -529,7 +529,7 @@ static int pl010_verify_port(struct uart
41026 return ret;
41027 }
41028
41029 -static struct uart_ops amba_pl010_pops = {
41030 +static const struct uart_ops amba_pl010_pops = {
41031 .tx_empty = pl010_tx_empty,
41032 .set_mctrl = pl010_set_mctrl,
41033 .get_mctrl = pl010_get_mctrl,
41034 diff -urNp linux-2.6.39.2/drivers/tty/serial/amba-pl011.c linux-2.6.39.2/drivers/tty/serial/amba-pl011.c
41035 --- linux-2.6.39.2/drivers/tty/serial/amba-pl011.c 2011-05-19 00:06:34.000000000 -0400
41036 +++ linux-2.6.39.2/drivers/tty/serial/amba-pl011.c 2011-05-22 19:36:32.000000000 -0400
41037 @@ -1581,7 +1581,7 @@ static int pl010_verify_port(struct uart
41038 return ret;
41039 }
41040
41041 -static struct uart_ops amba_pl011_pops = {
41042 +static const struct uart_ops amba_pl011_pops = {
41043 .tx_empty = pl01x_tx_empty,
41044 .set_mctrl = pl011_set_mctrl,
41045 .get_mctrl = pl01x_get_mctrl,
41046 diff -urNp linux-2.6.39.2/drivers/tty/serial/apbuart.c linux-2.6.39.2/drivers/tty/serial/apbuart.c
41047 --- linux-2.6.39.2/drivers/tty/serial/apbuart.c 2011-05-19 00:06:34.000000000 -0400
41048 +++ linux-2.6.39.2/drivers/tty/serial/apbuart.c 2011-05-22 19:36:32.000000000 -0400
41049 @@ -328,7 +328,7 @@ static int apbuart_verify_port(struct ua
41050 return ret;
41051 }
41052
41053 -static struct uart_ops grlib_apbuart_ops = {
41054 +static const struct uart_ops grlib_apbuart_ops = {
41055 .tx_empty = apbuart_tx_empty,
41056 .set_mctrl = apbuart_set_mctrl,
41057 .get_mctrl = apbuart_get_mctrl,
41058 diff -urNp linux-2.6.39.2/drivers/tty/serial/atmel_serial.c linux-2.6.39.2/drivers/tty/serial/atmel_serial.c
41059 --- linux-2.6.39.2/drivers/tty/serial/atmel_serial.c 2011-05-19 00:06:34.000000000 -0400
41060 +++ linux-2.6.39.2/drivers/tty/serial/atmel_serial.c 2011-05-22 19:36:32.000000000 -0400
41061 @@ -1382,7 +1382,7 @@ atmel_ioctl(struct uart_port *port, unsi
41062
41063
41064
41065 -static struct uart_ops atmel_pops = {
41066 +static const struct uart_ops atmel_pops = {
41067 .tx_empty = atmel_tx_empty,
41068 .set_mctrl = atmel_set_mctrl,
41069 .get_mctrl = atmel_get_mctrl,
41070 diff -urNp linux-2.6.39.2/drivers/tty/serial/bcm63xx_uart.c linux-2.6.39.2/drivers/tty/serial/bcm63xx_uart.c
41071 --- linux-2.6.39.2/drivers/tty/serial/bcm63xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41072 +++ linux-2.6.39.2/drivers/tty/serial/bcm63xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41073 @@ -636,7 +636,7 @@ static int bcm_uart_verify_port(struct u
41074 }
41075
41076 /* serial core callbacks */
41077 -static struct uart_ops bcm_uart_ops = {
41078 +static const struct uart_ops bcm_uart_ops = {
41079 .tx_empty = bcm_uart_tx_empty,
41080 .get_mctrl = bcm_uart_get_mctrl,
41081 .set_mctrl = bcm_uart_set_mctrl,
41082 diff -urNp linux-2.6.39.2/drivers/tty/serial/bfin_5xx.c linux-2.6.39.2/drivers/tty/serial/bfin_5xx.c
41083 --- linux-2.6.39.2/drivers/tty/serial/bfin_5xx.c 2011-05-19 00:06:34.000000000 -0400
41084 +++ linux-2.6.39.2/drivers/tty/serial/bfin_5xx.c 2011-05-22 19:36:32.000000000 -0400
41085 @@ -1036,7 +1036,7 @@ static int bfin_kgdboc_port_startup(stru
41086 }
41087 #endif
41088
41089 -static struct uart_ops bfin_serial_pops = {
41090 +static const struct uart_ops bfin_serial_pops = {
41091 .tx_empty = bfin_serial_tx_empty,
41092 .set_mctrl = bfin_serial_set_mctrl,
41093 .get_mctrl = bfin_serial_get_mctrl,
41094 diff -urNp linux-2.6.39.2/drivers/tty/serial/bfin_sport_uart.c linux-2.6.39.2/drivers/tty/serial/bfin_sport_uart.c
41095 --- linux-2.6.39.2/drivers/tty/serial/bfin_sport_uart.c 2011-05-19 00:06:34.000000000 -0400
41096 +++ linux-2.6.39.2/drivers/tty/serial/bfin_sport_uart.c 2011-05-22 19:36:32.000000000 -0400
41097 @@ -571,7 +571,7 @@ static void sport_set_termios(struct uar
41098 spin_unlock_irqrestore(&up->port.lock, flags);
41099 }
41100
41101 -struct uart_ops sport_uart_ops = {
41102 +const struct uart_ops sport_uart_ops = {
41103 .tx_empty = sport_tx_empty,
41104 .set_mctrl = sport_set_mctrl,
41105 .get_mctrl = sport_get_mctrl,
41106 diff -urNp linux-2.6.39.2/drivers/tty/serial/clps711x.c linux-2.6.39.2/drivers/tty/serial/clps711x.c
41107 --- linux-2.6.39.2/drivers/tty/serial/clps711x.c 2011-05-19 00:06:34.000000000 -0400
41108 +++ linux-2.6.39.2/drivers/tty/serial/clps711x.c 2011-05-22 19:36:32.000000000 -0400
41109 @@ -380,7 +380,7 @@ static int clps711xuart_request_port(str
41110 return 0;
41111 }
41112
41113 -static struct uart_ops clps711x_pops = {
41114 +static const struct uart_ops clps711x_pops = {
41115 .tx_empty = clps711xuart_tx_empty,
41116 .set_mctrl = clps711xuart_set_mctrl_null,
41117 .get_mctrl = clps711xuart_get_mctrl,
41118 diff -urNp linux-2.6.39.2/drivers/tty/serial/cpm_uart/cpm_uart_core.c linux-2.6.39.2/drivers/tty/serial/cpm_uart/cpm_uart_core.c
41119 --- linux-2.6.39.2/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-19 00:06:34.000000000 -0400
41120 +++ linux-2.6.39.2/drivers/tty/serial/cpm_uart/cpm_uart_core.c 2011-05-22 19:36:32.000000000 -0400
41121 @@ -1099,7 +1099,7 @@ static void cpm_put_poll_char(struct uar
41122 }
41123 #endif /* CONFIG_CONSOLE_POLL */
41124
41125 -static struct uart_ops cpm_uart_pops = {
41126 +static const struct uart_ops cpm_uart_pops = {
41127 .tx_empty = cpm_uart_tx_empty,
41128 .set_mctrl = cpm_uart_set_mctrl,
41129 .get_mctrl = cpm_uart_get_mctrl,
41130 diff -urNp linux-2.6.39.2/drivers/tty/serial/dz.c linux-2.6.39.2/drivers/tty/serial/dz.c
41131 --- linux-2.6.39.2/drivers/tty/serial/dz.c 2011-05-19 00:06:34.000000000 -0400
41132 +++ linux-2.6.39.2/drivers/tty/serial/dz.c 2011-05-22 19:36:32.000000000 -0400
41133 @@ -746,7 +746,7 @@ static int dz_verify_port(struct uart_po
41134 return ret;
41135 }
41136
41137 -static struct uart_ops dz_ops = {
41138 +static const struct uart_ops dz_ops = {
41139 .tx_empty = dz_tx_empty,
41140 .get_mctrl = dz_get_mctrl,
41141 .set_mctrl = dz_set_mctrl,
41142 diff -urNp linux-2.6.39.2/drivers/tty/serial/imx.c linux-2.6.39.2/drivers/tty/serial/imx.c
41143 --- linux-2.6.39.2/drivers/tty/serial/imx.c 2011-05-19 00:06:34.000000000 -0400
41144 +++ linux-2.6.39.2/drivers/tty/serial/imx.c 2011-05-22 19:36:32.000000000 -0400
41145 @@ -1018,7 +1018,7 @@ imx_verify_port(struct uart_port *port,
41146 return ret;
41147 }
41148
41149 -static struct uart_ops imx_pops = {
41150 +static const struct uart_ops imx_pops = {
41151 .tx_empty = imx_tx_empty,
41152 .set_mctrl = imx_set_mctrl,
41153 .get_mctrl = imx_get_mctrl,
41154 diff -urNp linux-2.6.39.2/drivers/tty/serial/ioc3_serial.c linux-2.6.39.2/drivers/tty/serial/ioc3_serial.c
41155 --- linux-2.6.39.2/drivers/tty/serial/ioc3_serial.c 2011-05-19 00:06:34.000000000 -0400
41156 +++ linux-2.6.39.2/drivers/tty/serial/ioc3_serial.c 2011-05-22 19:36:32.000000000 -0400
41157 @@ -1874,7 +1874,7 @@ static int ic3_request_port(struct uart_
41158 }
41159
41160 /* Associate the uart functions above - given to serial core */
41161 -static struct uart_ops ioc3_ops = {
41162 +static const struct uart_ops ioc3_ops = {
41163 .tx_empty = ic3_tx_empty,
41164 .set_mctrl = ic3_set_mctrl,
41165 .get_mctrl = ic3_get_mctrl,
41166 diff -urNp linux-2.6.39.2/drivers/tty/serial/ioc4_serial.c linux-2.6.39.2/drivers/tty/serial/ioc4_serial.c
41167 --- linux-2.6.39.2/drivers/tty/serial/ioc4_serial.c 2011-05-19 00:06:34.000000000 -0400
41168 +++ linux-2.6.39.2/drivers/tty/serial/ioc4_serial.c 2011-05-22 19:36:32.000000000 -0400
41169 @@ -2593,7 +2593,7 @@ static int ic4_request_port(struct uart_
41170
41171 /* Associate the uart functions above - given to serial core */
41172
41173 -static struct uart_ops ioc4_ops = {
41174 +static const struct uart_ops ioc4_ops = {
41175 .tx_empty = ic4_tx_empty,
41176 .set_mctrl = ic4_set_mctrl,
41177 .get_mctrl = ic4_get_mctrl,
41178 diff -urNp linux-2.6.39.2/drivers/tty/serial/ip22zilog.c linux-2.6.39.2/drivers/tty/serial/ip22zilog.c
41179 --- linux-2.6.39.2/drivers/tty/serial/ip22zilog.c 2011-05-19 00:06:34.000000000 -0400
41180 +++ linux-2.6.39.2/drivers/tty/serial/ip22zilog.c 2011-05-22 19:36:32.000000000 -0400
41181 @@ -928,7 +928,7 @@ static int ip22zilog_verify_port(struct
41182 return -EINVAL;
41183 }
41184
41185 -static struct uart_ops ip22zilog_pops = {
41186 +static const struct uart_ops ip22zilog_pops = {
41187 .tx_empty = ip22zilog_tx_empty,
41188 .set_mctrl = ip22zilog_set_mctrl,
41189 .get_mctrl = ip22zilog_get_mctrl,
41190 diff -urNp linux-2.6.39.2/drivers/tty/serial/kgdboc.c linux-2.6.39.2/drivers/tty/serial/kgdboc.c
41191 --- linux-2.6.39.2/drivers/tty/serial/kgdboc.c 2011-05-19 00:06:34.000000000 -0400
41192 +++ linux-2.6.39.2/drivers/tty/serial/kgdboc.c 2011-05-22 19:36:32.000000000 -0400
41193 @@ -22,7 +22,7 @@
41194
41195 #define MAX_CONFIG_LEN 40
41196
41197 -static struct kgdb_io kgdboc_io_ops;
41198 +static struct kgdb_io kgdboc_io_ops; /* cannot be const, see configure_kgdboc() */
41199
41200 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41201 static int configured = -1;
41202 @@ -293,7 +293,7 @@ static void kgdboc_post_exp_handler(void
41203 kgdboc_restore_input();
41204 }
41205
41206 -static struct kgdb_io kgdboc_io_ops = {
41207 +static struct kgdb_io kgdboc_io_ops = { /* cannot be const, see configure_kgdboc() */
41208 .name = "kgdboc",
41209 .read_char = kgdboc_get_char,
41210 .write_char = kgdboc_put_char,
41211 diff -urNp linux-2.6.39.2/drivers/tty/serial/m32r_sio.c linux-2.6.39.2/drivers/tty/serial/m32r_sio.c
41212 --- linux-2.6.39.2/drivers/tty/serial/m32r_sio.c 2011-05-19 00:06:34.000000000 -0400
41213 +++ linux-2.6.39.2/drivers/tty/serial/m32r_sio.c 2011-05-22 19:36:32.000000000 -0400
41214 @@ -939,7 +939,7 @@ m32r_sio_type(struct uart_port *port)
41215 return uart_config[type].name;
41216 }
41217
41218 -static struct uart_ops m32r_sio_pops = {
41219 +static const struct uart_ops m32r_sio_pops = {
41220 .tx_empty = m32r_sio_tx_empty,
41221 .set_mctrl = m32r_sio_set_mctrl,
41222 .get_mctrl = m32r_sio_get_mctrl,
41223 diff -urNp linux-2.6.39.2/drivers/tty/serial/max3100.c linux-2.6.39.2/drivers/tty/serial/max3100.c
41224 --- linux-2.6.39.2/drivers/tty/serial/max3100.c 2011-05-19 00:06:34.000000000 -0400
41225 +++ linux-2.6.39.2/drivers/tty/serial/max3100.c 2011-05-22 19:36:32.000000000 -0400
41226 @@ -710,7 +710,7 @@ static void max3100_break_ctl(struct uar
41227 dev_dbg(&s->spi->dev, "%s\n", __func__);
41228 }
41229
41230 -static struct uart_ops max3100_ops = {
41231 +static const struct uart_ops max3100_ops = {
41232 .tx_empty = max3100_tx_empty,
41233 .set_mctrl = max3100_set_mctrl,
41234 .get_mctrl = max3100_get_mctrl,
41235 diff -urNp linux-2.6.39.2/drivers/tty/serial/max3107.c linux-2.6.39.2/drivers/tty/serial/max3107.c
41236 --- linux-2.6.39.2/drivers/tty/serial/max3107.c 2011-05-19 00:06:34.000000000 -0400
41237 +++ linux-2.6.39.2/drivers/tty/serial/max3107.c 2011-05-22 19:36:32.000000000 -0400
41238 @@ -910,7 +910,7 @@ static void max3107_break_ctl(struct uar
41239
41240
41241 /* Port functions */
41242 -static struct uart_ops max3107_ops = {
41243 +static const struct uart_ops max3107_ops = {
41244 .tx_empty = max3107_tx_empty,
41245 .set_mctrl = max3107_set_mctrl,
41246 .get_mctrl = max3107_get_mctrl,
41247 diff -urNp linux-2.6.39.2/drivers/tty/serial/mfd.c linux-2.6.39.2/drivers/tty/serial/mfd.c
41248 --- linux-2.6.39.2/drivers/tty/serial/mfd.c 2011-05-19 00:06:34.000000000 -0400
41249 +++ linux-2.6.39.2/drivers/tty/serial/mfd.c 2011-05-22 19:36:32.000000000 -0400
41250 @@ -1178,7 +1178,7 @@ static struct console serial_hsu_console
41251 };
41252 #endif
41253
41254 -struct uart_ops serial_hsu_pops = {
41255 +const struct uart_ops serial_hsu_pops = {
41256 .tx_empty = serial_hsu_tx_empty,
41257 .set_mctrl = serial_hsu_set_mctrl,
41258 .get_mctrl = serial_hsu_get_mctrl,
41259 diff -urNp linux-2.6.39.2/drivers/tty/serial/mpc52xx_uart.c linux-2.6.39.2/drivers/tty/serial/mpc52xx_uart.c
41260 --- linux-2.6.39.2/drivers/tty/serial/mpc52xx_uart.c 2011-05-19 00:06:34.000000000 -0400
41261 +++ linux-2.6.39.2/drivers/tty/serial/mpc52xx_uart.c 2011-05-22 19:36:32.000000000 -0400
41262 @@ -283,7 +283,7 @@ static irqreturn_t mpc52xx_psc_handle_ir
41263 return mpc5xxx_uart_process_int(port);
41264 }
41265
41266 -static struct psc_ops mpc52xx_psc_ops = {
41267 +static const struct psc_ops mpc52xx_psc_ops = {
41268 .fifo_init = mpc52xx_psc_fifo_init,
41269 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41270 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41271 @@ -304,7 +304,7 @@ static struct psc_ops mpc52xx_psc_ops =
41272 .handle_irq = mpc52xx_psc_handle_irq,
41273 };
41274
41275 -static struct psc_ops mpc5200b_psc_ops = {
41276 +static const struct psc_ops mpc5200b_psc_ops = {
41277 .fifo_init = mpc52xx_psc_fifo_init,
41278 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
41279 .raw_tx_rdy = mpc52xx_psc_raw_tx_rdy,
41280 @@ -571,7 +571,7 @@ static void mpc512x_psc_get_irq(struct u
41281 port->irq = psc_fifoc_irq;
41282 }
41283
41284 -static struct psc_ops mpc512x_psc_ops = {
41285 +static const struct psc_ops mpc512x_psc_ops = {
41286 .fifo_init = mpc512x_psc_fifo_init,
41287 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
41288 .raw_tx_rdy = mpc512x_psc_raw_tx_rdy,
41289 @@ -596,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops =
41290 };
41291 #endif
41292
41293 -static struct psc_ops *psc_ops;
41294 +static const struct psc_ops *psc_ops;
41295
41296 /* ======================================================================== */
41297 /* UART operations */
41298 @@ -905,7 +905,7 @@ mpc52xx_uart_verify_port(struct uart_por
41299 }
41300
41301
41302 -static struct uart_ops mpc52xx_uart_ops = {
41303 +static const struct uart_ops mpc52xx_uart_ops = {
41304 .tx_empty = mpc52xx_uart_tx_empty,
41305 .set_mctrl = mpc52xx_uart_set_mctrl,
41306 .get_mctrl = mpc52xx_uart_get_mctrl,
41307 diff -urNp linux-2.6.39.2/drivers/tty/serial/mpsc.c linux-2.6.39.2/drivers/tty/serial/mpsc.c
41308 --- linux-2.6.39.2/drivers/tty/serial/mpsc.c 2011-05-19 00:06:34.000000000 -0400
41309 +++ linux-2.6.39.2/drivers/tty/serial/mpsc.c 2011-05-22 19:36:32.000000000 -0400
41310 @@ -1663,7 +1663,7 @@ static void mpsc_put_poll_char(struct ua
41311 }
41312 #endif
41313
41314 -static struct uart_ops mpsc_pops = {
41315 +static const struct uart_ops mpsc_pops = {
41316 .tx_empty = mpsc_tx_empty,
41317 .set_mctrl = mpsc_set_mctrl,
41318 .get_mctrl = mpsc_get_mctrl,
41319 diff -urNp linux-2.6.39.2/drivers/tty/serial/mrst_max3110.c linux-2.6.39.2/drivers/tty/serial/mrst_max3110.c
41320 --- linux-2.6.39.2/drivers/tty/serial/mrst_max3110.c 2011-05-19 00:06:34.000000000 -0400
41321 +++ linux-2.6.39.2/drivers/tty/serial/mrst_max3110.c 2011-05-22 19:36:32.000000000 -0400
41322 @@ -393,6 +393,8 @@ static void max3110_con_receive(struct u
41323 int loop = 1, num, total = 0;
41324 u8 recv_buf[512], *pbuf;
41325
41326 + pax_track_stack();
41327 +
41328 pbuf = recv_buf;
41329 do {
41330 num = max3110_read_multi(max, pbuf);
41331 @@ -726,7 +728,7 @@ static void serial_m3110_enable_ms(struc
41332 {
41333 }
41334
41335 -struct uart_ops serial_m3110_ops = {
41336 +const struct uart_ops serial_m3110_ops = {
41337 .tx_empty = serial_m3110_tx_empty,
41338 .set_mctrl = serial_m3110_set_mctrl,
41339 .get_mctrl = serial_m3110_get_mctrl,
41340 diff -urNp linux-2.6.39.2/drivers/tty/serial/msm_serial.c linux-2.6.39.2/drivers/tty/serial/msm_serial.c
41341 --- linux-2.6.39.2/drivers/tty/serial/msm_serial.c 2011-05-19 00:06:34.000000000 -0400
41342 +++ linux-2.6.39.2/drivers/tty/serial/msm_serial.c 2011-05-22 19:36:32.000000000 -0400
41343 @@ -702,7 +702,7 @@ static void msm_power(struct uart_port *
41344 }
41345 }
41346
41347 -static struct uart_ops msm_uart_pops = {
41348 +static const struct uart_ops msm_uart_pops = {
41349 .tx_empty = msm_tx_empty,
41350 .set_mctrl = msm_set_mctrl,
41351 .get_mctrl = msm_get_mctrl,
41352 diff -urNp linux-2.6.39.2/drivers/tty/serial/msm_serial_hs.c linux-2.6.39.2/drivers/tty/serial/msm_serial_hs.c
41353 --- linux-2.6.39.2/drivers/tty/serial/msm_serial_hs.c 2011-05-19 00:06:34.000000000 -0400
41354 +++ linux-2.6.39.2/drivers/tty/serial/msm_serial_hs.c 2011-05-22 19:36:32.000000000 -0400
41355 @@ -360,7 +360,7 @@ struct msm_hs_port {
41356 static struct msm_hs_port q_uart_port[UARTDM_NR];
41357 static struct platform_driver msm_serial_hs_platform_driver;
41358 static struct uart_driver msm_hs_driver;
41359 -static struct uart_ops msm_hs_ops;
41360 +static const struct uart_ops msm_hs_ops;
41361 static struct workqueue_struct *msm_hs_workqueue;
41362
41363 #define UARTDM_TO_MSM(uart_port) \
41364 @@ -1856,7 +1856,7 @@ static struct uart_driver msm_hs_driver
41365 .cons = 0,
41366 };
41367
41368 -static struct uart_ops msm_hs_ops = {
41369 +static const struct uart_ops msm_hs_ops = {
41370 .tx_empty = msm_hs_tx_empty,
41371 .set_mctrl = msm_hs_set_mctrl_locked,
41372 .get_mctrl = msm_hs_get_mctrl_locked,
41373 diff -urNp linux-2.6.39.2/drivers/tty/serial/mux.c linux-2.6.39.2/drivers/tty/serial/mux.c
41374 --- linux-2.6.39.2/drivers/tty/serial/mux.c 2011-05-19 00:06:34.000000000 -0400
41375 +++ linux-2.6.39.2/drivers/tty/serial/mux.c 2011-05-22 19:36:32.000000000 -0400
41376 @@ -442,7 +442,7 @@ static struct console mux_console = {
41377 #define MUX_CONSOLE NULL
41378 #endif
41379
41380 -static struct uart_ops mux_pops = {
41381 +static const struct uart_ops mux_pops = {
41382 .tx_empty = mux_tx_empty,
41383 .set_mctrl = mux_set_mctrl,
41384 .get_mctrl = mux_get_mctrl,
41385 diff -urNp linux-2.6.39.2/drivers/tty/serial/mxs-auart.c linux-2.6.39.2/drivers/tty/serial/mxs-auart.c
41386 --- linux-2.6.39.2/drivers/tty/serial/mxs-auart.c 2011-05-19 00:06:34.000000000 -0400
41387 +++ linux-2.6.39.2/drivers/tty/serial/mxs-auart.c 2011-05-22 19:36:32.000000000 -0400
41388 @@ -499,7 +499,7 @@ static void mxs_auart_enable_ms(struct u
41389 /* just empty */
41390 }
41391
41392 -static struct uart_ops mxs_auart_ops = {
41393 +static const struct uart_ops mxs_auart_ops = {
41394 .tx_empty = mxs_auart_tx_empty,
41395 .start_tx = mxs_auart_start_tx,
41396 .stop_tx = mxs_auart_stop_tx,
41397 diff -urNp linux-2.6.39.2/drivers/tty/serial/netx-serial.c linux-2.6.39.2/drivers/tty/serial/netx-serial.c
41398 --- linux-2.6.39.2/drivers/tty/serial/netx-serial.c 2011-05-19 00:06:34.000000000 -0400
41399 +++ linux-2.6.39.2/drivers/tty/serial/netx-serial.c 2011-05-22 19:36:32.000000000 -0400
41400 @@ -464,7 +464,7 @@ netx_verify_port(struct uart_port *port,
41401 return ret;
41402 }
41403
41404 -static struct uart_ops netx_pops = {
41405 +static const struct uart_ops netx_pops = {
41406 .tx_empty = netx_tx_empty,
41407 .set_mctrl = netx_set_mctrl,
41408 .get_mctrl = netx_get_mctrl,
41409 diff -urNp linux-2.6.39.2/drivers/tty/serial/nwpserial.c linux-2.6.39.2/drivers/tty/serial/nwpserial.c
41410 --- linux-2.6.39.2/drivers/tty/serial/nwpserial.c 2011-05-19 00:06:34.000000000 -0400
41411 +++ linux-2.6.39.2/drivers/tty/serial/nwpserial.c 2011-05-22 19:36:32.000000000 -0400
41412 @@ -303,7 +303,7 @@ static unsigned int nwpserial_tx_empty(s
41413 return ret & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
41414 }
41415
41416 -static struct uart_ops nwpserial_pops = {
41417 +static const struct uart_ops nwpserial_pops = {
41418 .tx_empty = nwpserial_tx_empty,
41419 .set_mctrl = nwpserial_set_mctrl,
41420 .get_mctrl = nwpserial_get_mctrl,
41421 diff -urNp linux-2.6.39.2/drivers/tty/serial/omap-serial.c linux-2.6.39.2/drivers/tty/serial/omap-serial.c
41422 --- linux-2.6.39.2/drivers/tty/serial/omap-serial.c 2011-05-19 00:06:34.000000000 -0400
41423 +++ linux-2.6.39.2/drivers/tty/serial/omap-serial.c 2011-05-22 19:36:32.000000000 -0400
41424 @@ -1029,7 +1029,7 @@ static inline void serial_omap_add_conso
41425
41426 #endif
41427
41428 -static struct uart_ops serial_omap_pops = {
41429 +static const struct uart_ops serial_omap_pops = {
41430 .tx_empty = serial_omap_tx_empty,
41431 .set_mctrl = serial_omap_set_mctrl,
41432 .get_mctrl = serial_omap_get_mctrl,
41433 diff -urNp linux-2.6.39.2/drivers/tty/serial/pch_uart.c linux-2.6.39.2/drivers/tty/serial/pch_uart.c
41434 --- linux-2.6.39.2/drivers/tty/serial/pch_uart.c 2011-05-19 00:06:34.000000000 -0400
41435 +++ linux-2.6.39.2/drivers/tty/serial/pch_uart.c 2011-05-22 19:36:32.000000000 -0400
41436 @@ -1351,7 +1351,7 @@ static int pch_uart_verify_port(struct u
41437 return 0;
41438 }
41439
41440 -static struct uart_ops pch_uart_ops = {
41441 +static const struct uart_ops pch_uart_ops = {
41442 .tx_empty = pch_uart_tx_empty,
41443 .set_mctrl = pch_uart_set_mctrl,
41444 .get_mctrl = pch_uart_get_mctrl,
41445 diff -urNp linux-2.6.39.2/drivers/tty/serial/pmac_zilog.c linux-2.6.39.2/drivers/tty/serial/pmac_zilog.c
41446 --- linux-2.6.39.2/drivers/tty/serial/pmac_zilog.c 2011-05-19 00:06:34.000000000 -0400
41447 +++ linux-2.6.39.2/drivers/tty/serial/pmac_zilog.c 2011-05-22 19:36:32.000000000 -0400
41448 @@ -1427,7 +1427,7 @@ static void pmz_poll_put_char(struct uar
41449
41450 #endif /* CONFIG_CONSOLE_POLL */
41451
41452 -static struct uart_ops pmz_pops = {
41453 +static const struct uart_ops pmz_pops = {
41454 .tx_empty = pmz_tx_empty,
41455 .set_mctrl = pmz_set_mctrl,
41456 .get_mctrl = pmz_get_mctrl,
41457 diff -urNp linux-2.6.39.2/drivers/tty/serial/pnx8xxx_uart.c linux-2.6.39.2/drivers/tty/serial/pnx8xxx_uart.c
41458 --- linux-2.6.39.2/drivers/tty/serial/pnx8xxx_uart.c 2011-05-19 00:06:34.000000000 -0400
41459 +++ linux-2.6.39.2/drivers/tty/serial/pnx8xxx_uart.c 2011-05-22 19:36:32.000000000 -0400
41460 @@ -614,7 +614,7 @@ pnx8xxx_verify_port(struct uart_port *po
41461 return ret;
41462 }
41463
41464 -static struct uart_ops pnx8xxx_pops = {
41465 +static const struct uart_ops pnx8xxx_pops = {
41466 .tx_empty = pnx8xxx_tx_empty,
41467 .set_mctrl = pnx8xxx_set_mctrl,
41468 .get_mctrl = pnx8xxx_get_mctrl,
41469 diff -urNp linux-2.6.39.2/drivers/tty/serial/pxa.c linux-2.6.39.2/drivers/tty/serial/pxa.c
41470 --- linux-2.6.39.2/drivers/tty/serial/pxa.c 2011-05-19 00:06:34.000000000 -0400
41471 +++ linux-2.6.39.2/drivers/tty/serial/pxa.c 2011-05-22 19:36:32.000000000 -0400
41472 @@ -706,7 +706,7 @@ static struct console serial_pxa_console
41473 #define PXA_CONSOLE NULL
41474 #endif
41475
41476 -struct uart_ops serial_pxa_pops = {
41477 +const struct uart_ops serial_pxa_pops = {
41478 .tx_empty = serial_pxa_tx_empty,
41479 .set_mctrl = serial_pxa_set_mctrl,
41480 .get_mctrl = serial_pxa_get_mctrl,
41481 diff -urNp linux-2.6.39.2/drivers/tty/serial/sa1100.c linux-2.6.39.2/drivers/tty/serial/sa1100.c
41482 --- linux-2.6.39.2/drivers/tty/serial/sa1100.c 2011-05-19 00:06:34.000000000 -0400
41483 +++ linux-2.6.39.2/drivers/tty/serial/sa1100.c 2011-05-22 19:36:32.000000000 -0400
41484 @@ -577,7 +577,7 @@ sa1100_verify_port(struct uart_port *por
41485 return ret;
41486 }
41487
41488 -static struct uart_ops sa1100_pops = {
41489 +static const struct uart_ops sa1100_pops = {
41490 .tx_empty = sa1100_tx_empty,
41491 .set_mctrl = sa1100_set_mctrl,
41492 .get_mctrl = sa1100_get_mctrl,
41493 diff -urNp linux-2.6.39.2/drivers/tty/serial/samsung.c linux-2.6.39.2/drivers/tty/serial/samsung.c
41494 --- linux-2.6.39.2/drivers/tty/serial/samsung.c 2011-05-19 00:06:34.000000000 -0400
41495 +++ linux-2.6.39.2/drivers/tty/serial/samsung.c 2011-05-22 19:36:32.000000000 -0400
41496 @@ -860,7 +860,7 @@ static struct console s3c24xx_serial_con
41497 #define S3C24XX_SERIAL_CONSOLE NULL
41498 #endif
41499
41500 -static struct uart_ops s3c24xx_serial_ops = {
41501 +static const struct uart_ops s3c24xx_serial_ops = {
41502 .pm = s3c24xx_serial_pm,
41503 .tx_empty = s3c24xx_serial_tx_empty,
41504 .get_mctrl = s3c24xx_serial_get_mctrl,
41505 diff -urNp linux-2.6.39.2/drivers/tty/serial/sc26xx.c linux-2.6.39.2/drivers/tty/serial/sc26xx.c
41506 --- linux-2.6.39.2/drivers/tty/serial/sc26xx.c 2011-05-19 00:06:34.000000000 -0400
41507 +++ linux-2.6.39.2/drivers/tty/serial/sc26xx.c 2011-05-22 19:36:32.000000000 -0400
41508 @@ -515,7 +515,7 @@ static int sc26xx_verify_port(struct uar
41509 return -EINVAL;
41510 }
41511
41512 -static struct uart_ops sc26xx_ops = {
41513 +static const struct uart_ops sc26xx_ops = {
41514 .tx_empty = sc26xx_tx_empty,
41515 .set_mctrl = sc26xx_set_mctrl,
41516 .get_mctrl = sc26xx_get_mctrl,
41517 diff -urNp linux-2.6.39.2/drivers/tty/serial/serial_ks8695.c linux-2.6.39.2/drivers/tty/serial/serial_ks8695.c
41518 --- linux-2.6.39.2/drivers/tty/serial/serial_ks8695.c 2011-05-19 00:06:34.000000000 -0400
41519 +++ linux-2.6.39.2/drivers/tty/serial/serial_ks8695.c 2011-05-22 19:36:32.000000000 -0400
41520 @@ -528,7 +528,7 @@ static int ks8695uart_verify_port(struct
41521 return ret;
41522 }
41523
41524 -static struct uart_ops ks8695uart_pops = {
41525 +static const struct uart_ops ks8695uart_pops = {
41526 .tx_empty = ks8695uart_tx_empty,
41527 .set_mctrl = ks8695uart_set_mctrl,
41528 .get_mctrl = ks8695uart_get_mctrl,
41529 diff -urNp linux-2.6.39.2/drivers/tty/serial/serial_txx9.c linux-2.6.39.2/drivers/tty/serial/serial_txx9.c
41530 --- linux-2.6.39.2/drivers/tty/serial/serial_txx9.c 2011-05-19 00:06:34.000000000 -0400
41531 +++ linux-2.6.39.2/drivers/tty/serial/serial_txx9.c 2011-05-22 19:36:32.000000000 -0400
41532 @@ -857,7 +857,7 @@ serial_txx9_type(struct uart_port *port)
41533 return "txx9";
41534 }
41535
41536 -static struct uart_ops serial_txx9_pops = {
41537 +static const struct uart_ops serial_txx9_pops = {
41538 .tx_empty = serial_txx9_tx_empty,
41539 .set_mctrl = serial_txx9_set_mctrl,
41540 .get_mctrl = serial_txx9_get_mctrl,
41541 diff -urNp linux-2.6.39.2/drivers/tty/serial/sn_console.c linux-2.6.39.2/drivers/tty/serial/sn_console.c
41542 --- linux-2.6.39.2/drivers/tty/serial/sn_console.c 2011-05-19 00:06:34.000000000 -0400
41543 +++ linux-2.6.39.2/drivers/tty/serial/sn_console.c 2011-05-22 19:36:32.000000000 -0400
41544 @@ -388,7 +388,7 @@ static void snp_config_port(struct uart_
41545
41546 /* Associate the uart functions above - given to serial core */
41547
41548 -static struct uart_ops sn_console_ops = {
41549 +static const struct uart_ops sn_console_ops = {
41550 .tx_empty = snp_tx_empty,
41551 .set_mctrl = snp_set_mctrl,
41552 .get_mctrl = snp_get_mctrl,
41553 diff -urNp linux-2.6.39.2/drivers/tty/serial/sunhv.c linux-2.6.39.2/drivers/tty/serial/sunhv.c
41554 --- linux-2.6.39.2/drivers/tty/serial/sunhv.c 2011-05-19 00:06:34.000000000 -0400
41555 +++ linux-2.6.39.2/drivers/tty/serial/sunhv.c 2011-05-22 19:36:32.000000000 -0400
41556 @@ -168,12 +168,12 @@ struct sunhv_ops {
41557 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
41558 };
41559
41560 -static struct sunhv_ops bychar_ops = {
41561 +static const struct sunhv_ops bychar_ops = {
41562 .transmit_chars = transmit_chars_putchar,
41563 .receive_chars = receive_chars_getchar,
41564 };
41565
41566 -static struct sunhv_ops bywrite_ops = {
41567 +static const struct sunhv_ops bywrite_ops = {
41568 .transmit_chars = transmit_chars_write,
41569 .receive_chars = receive_chars_read,
41570 };
41571 @@ -370,7 +370,7 @@ static int sunhv_verify_port(struct uart
41572 return -EINVAL;
41573 }
41574
41575 -static struct uart_ops sunhv_pops = {
41576 +static const struct uart_ops sunhv_pops = {
41577 .tx_empty = sunhv_tx_empty,
41578 .set_mctrl = sunhv_set_mctrl,
41579 .get_mctrl = sunhv_get_mctrl,
41580 diff -urNp linux-2.6.39.2/drivers/tty/serial/sunsab.c linux-2.6.39.2/drivers/tty/serial/sunsab.c
41581 --- linux-2.6.39.2/drivers/tty/serial/sunsab.c 2011-05-19 00:06:34.000000000 -0400
41582 +++ linux-2.6.39.2/drivers/tty/serial/sunsab.c 2011-05-22 19:36:32.000000000 -0400
41583 @@ -804,7 +804,7 @@ static int sunsab_verify_port(struct uar
41584 return -EINVAL;
41585 }
41586
41587 -static struct uart_ops sunsab_pops = {
41588 +static const struct uart_ops sunsab_pops = {
41589 .tx_empty = sunsab_tx_empty,
41590 .set_mctrl = sunsab_set_mctrl,
41591 .get_mctrl = sunsab_get_mctrl,
41592 diff -urNp linux-2.6.39.2/drivers/tty/serial/sunsu.c linux-2.6.39.2/drivers/tty/serial/sunsu.c
41593 --- linux-2.6.39.2/drivers/tty/serial/sunsu.c 2011-05-19 00:06:34.000000000 -0400
41594 +++ linux-2.6.39.2/drivers/tty/serial/sunsu.c 2011-05-22 19:36:32.000000000 -0400
41595 @@ -946,7 +946,7 @@ sunsu_type(struct uart_port *port)
41596 return uart_config[type].name;
41597 }
41598
41599 -static struct uart_ops sunsu_pops = {
41600 +static const struct uart_ops sunsu_pops = {
41601 .tx_empty = sunsu_tx_empty,
41602 .set_mctrl = sunsu_set_mctrl,
41603 .get_mctrl = sunsu_get_mctrl,
41604 diff -urNp linux-2.6.39.2/drivers/tty/serial/sunzilog.c linux-2.6.39.2/drivers/tty/serial/sunzilog.c
41605 --- linux-2.6.39.2/drivers/tty/serial/sunzilog.c 2011-05-19 00:06:34.000000000 -0400
41606 +++ linux-2.6.39.2/drivers/tty/serial/sunzilog.c 2011-05-22 19:36:32.000000000 -0400
41607 @@ -1042,7 +1042,7 @@ static void sunzilog_put_poll_char(struc
41608 }
41609 #endif /* CONFIG_CONSOLE_POLL */
41610
41611 -static struct uart_ops sunzilog_pops = {
41612 +static const struct uart_ops sunzilog_pops = {
41613 .tx_empty = sunzilog_tx_empty,
41614 .set_mctrl = sunzilog_set_mctrl,
41615 .get_mctrl = sunzilog_get_mctrl,
41616 diff -urNp linux-2.6.39.2/drivers/tty/serial/timbuart.c linux-2.6.39.2/drivers/tty/serial/timbuart.c
41617 --- linux-2.6.39.2/drivers/tty/serial/timbuart.c 2011-05-19 00:06:34.000000000 -0400
41618 +++ linux-2.6.39.2/drivers/tty/serial/timbuart.c 2011-05-22 19:36:32.000000000 -0400
41619 @@ -394,7 +394,7 @@ static int timbuart_verify_port(struct u
41620 return -EINVAL;
41621 }
41622
41623 -static struct uart_ops timbuart_ops = {
41624 +static const struct uart_ops timbuart_ops = {
41625 .tx_empty = timbuart_tx_empty,
41626 .set_mctrl = timbuart_set_mctrl,
41627 .get_mctrl = timbuart_get_mctrl,
41628 diff -urNp linux-2.6.39.2/drivers/tty/serial/uartlite.c linux-2.6.39.2/drivers/tty/serial/uartlite.c
41629 --- linux-2.6.39.2/drivers/tty/serial/uartlite.c 2011-05-19 00:06:34.000000000 -0400
41630 +++ linux-2.6.39.2/drivers/tty/serial/uartlite.c 2011-05-22 19:36:32.000000000 -0400
41631 @@ -331,7 +331,7 @@ static void ulite_put_poll_char(struct u
41632 }
41633 #endif
41634
41635 -static struct uart_ops ulite_ops = {
41636 +static const struct uart_ops ulite_ops = {
41637 .tx_empty = ulite_tx_empty,
41638 .set_mctrl = ulite_set_mctrl,
41639 .get_mctrl = ulite_get_mctrl,
41640 diff -urNp linux-2.6.39.2/drivers/tty/serial/ucc_uart.c linux-2.6.39.2/drivers/tty/serial/ucc_uart.c
41641 --- linux-2.6.39.2/drivers/tty/serial/ucc_uart.c 2011-05-19 00:06:34.000000000 -0400
41642 +++ linux-2.6.39.2/drivers/tty/serial/ucc_uart.c 2011-05-22 19:36:32.000000000 -0400
41643 @@ -1088,7 +1088,7 @@ static int qe_uart_verify_port(struct ua
41644 *
41645 * Details on these functions can be found in Documentation/serial/driver
41646 */
41647 -static struct uart_ops qe_uart_pops = {
41648 +static const struct uart_ops qe_uart_pops = {
41649 .tx_empty = qe_uart_tx_empty,
41650 .set_mctrl = qe_uart_set_mctrl,
41651 .get_mctrl = qe_uart_get_mctrl,
41652 diff -urNp linux-2.6.39.2/drivers/tty/serial/vr41xx_siu.c linux-2.6.39.2/drivers/tty/serial/vr41xx_siu.c
41653 --- linux-2.6.39.2/drivers/tty/serial/vr41xx_siu.c 2011-05-19 00:06:34.000000000 -0400
41654 +++ linux-2.6.39.2/drivers/tty/serial/vr41xx_siu.c 2011-05-22 19:36:32.000000000 -0400
41655 @@ -683,7 +683,7 @@ static int siu_verify_port(struct uart_p
41656 return 0;
41657 }
41658
41659 -static struct uart_ops siu_uart_ops = {
41660 +static const struct uart_ops siu_uart_ops = {
41661 .tx_empty = siu_tx_empty,
41662 .set_mctrl = siu_set_mctrl,
41663 .get_mctrl = siu_get_mctrl,
41664 diff -urNp linux-2.6.39.2/drivers/tty/serial/vt8500_serial.c linux-2.6.39.2/drivers/tty/serial/vt8500_serial.c
41665 --- linux-2.6.39.2/drivers/tty/serial/vt8500_serial.c 2011-05-19 00:06:34.000000000 -0400
41666 +++ linux-2.6.39.2/drivers/tty/serial/vt8500_serial.c 2011-05-22 19:36:32.000000000 -0400
41667 @@ -519,7 +519,7 @@ static struct console vt8500_console = {
41668 #define VT8500_CONSOLE NULL
41669 #endif
41670
41671 -static struct uart_ops vt8500_uart_pops = {
41672 +static const struct uart_ops vt8500_uart_pops = {
41673 .tx_empty = vt8500_tx_empty,
41674 .set_mctrl = vt8500_set_mctrl,
41675 .get_mctrl = vt8500_get_mctrl,
41676 diff -urNp linux-2.6.39.2/drivers/tty/serial/zs.c linux-2.6.39.2/drivers/tty/serial/zs.c
41677 --- linux-2.6.39.2/drivers/tty/serial/zs.c 2011-05-19 00:06:34.000000000 -0400
41678 +++ linux-2.6.39.2/drivers/tty/serial/zs.c 2011-05-22 19:36:32.000000000 -0400
41679 @@ -1044,7 +1044,7 @@ static int zs_verify_port(struct uart_po
41680 }
41681
41682
41683 -static struct uart_ops zs_ops = {
41684 +static const struct uart_ops zs_ops = {
41685 .tx_empty = zs_tx_empty,
41686 .set_mctrl = zs_set_mctrl,
41687 .get_mctrl = zs_get_mctrl,
41688 diff -urNp linux-2.6.39.2/drivers/tty/tty_io.c linux-2.6.39.2/drivers/tty/tty_io.c
41689 --- linux-2.6.39.2/drivers/tty/tty_io.c 2011-05-19 00:06:34.000000000 -0400
41690 +++ linux-2.6.39.2/drivers/tty/tty_io.c 2011-05-22 19:36:32.000000000 -0400
41691 @@ -139,21 +139,11 @@ EXPORT_SYMBOL(tty_mutex);
41692 /* Spinlock to protect the tty->tty_files list */
41693 DEFINE_SPINLOCK(tty_files_lock);
41694
41695 -static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
41696 -static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
41697 ssize_t redirected_tty_write(struct file *, const char __user *,
41698 size_t, loff_t *);
41699 -static unsigned int tty_poll(struct file *, poll_table *);
41700 static int tty_open(struct inode *, struct file *);
41701 long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
41702 -#ifdef CONFIG_COMPAT
41703 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41704 - unsigned long arg);
41705 -#else
41706 -#define tty_compat_ioctl NULL
41707 -#endif
41708 static int __tty_fasync(int fd, struct file *filp, int on);
41709 -static int tty_fasync(int fd, struct file *filp, int on);
41710 static void release_tty(struct tty_struct *tty, int idx);
41711 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41712 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
41713 @@ -937,7 +927,7 @@ EXPORT_SYMBOL(start_tty);
41714 * read calls may be outstanding in parallel.
41715 */
41716
41717 -static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41718 +ssize_t tty_read(struct file *file, char __user *buf, size_t count,
41719 loff_t *ppos)
41720 {
41721 int i;
41722 @@ -963,6 +953,8 @@ static ssize_t tty_read(struct file *fil
41723 return i;
41724 }
41725
41726 +EXPORT_SYMBOL(tty_read);
41727 +
41728 void tty_write_unlock(struct tty_struct *tty)
41729 {
41730 mutex_unlock(&tty->atomic_write_lock);
41731 @@ -1112,7 +1104,7 @@ void tty_write_message(struct tty_struct
41732 * write method will not be invoked in parallel for each device.
41733 */
41734
41735 -static ssize_t tty_write(struct file *file, const char __user *buf,
41736 +ssize_t tty_write(struct file *file, const char __user *buf,
41737 size_t count, loff_t *ppos)
41738 {
41739 struct inode *inode = file->f_path.dentry->d_inode;
41740 @@ -1138,6 +1130,8 @@ static ssize_t tty_write(struct file *fi
41741 return ret;
41742 }
41743
41744 +EXPORT_SYMBOL(tty_write);
41745 +
41746 ssize_t redirected_tty_write(struct file *file, const char __user *buf,
41747 size_t count, loff_t *ppos)
41748 {
41749 @@ -1777,6 +1771,8 @@ int tty_release(struct inode *inode, str
41750 return 0;
41751 }
41752
41753 +EXPORT_SYMBOL(tty_release);
41754 +
41755 /**
41756 * tty_open - open a tty device
41757 * @inode: inode of device file
41758 @@ -1968,7 +1964,7 @@ got_driver:
41759 * may be re-entered freely by other callers.
41760 */
41761
41762 -static unsigned int tty_poll(struct file *filp, poll_table *wait)
41763 +unsigned int tty_poll(struct file *filp, poll_table *wait)
41764 {
41765 struct tty_struct *tty = file_tty(filp);
41766 struct tty_ldisc *ld;
41767 @@ -1984,6 +1980,8 @@ static unsigned int tty_poll(struct file
41768 return ret;
41769 }
41770
41771 +EXPORT_SYMBOL(tty_poll);
41772 +
41773 static int __tty_fasync(int fd, struct file *filp, int on)
41774 {
41775 struct tty_struct *tty = file_tty(filp);
41776 @@ -2025,7 +2023,7 @@ out:
41777 return retval;
41778 }
41779
41780 -static int tty_fasync(int fd, struct file *filp, int on)
41781 +int tty_fasync(int fd, struct file *filp, int on)
41782 {
41783 int retval;
41784 tty_lock();
41785 @@ -2034,6 +2032,8 @@ static int tty_fasync(int fd, struct fil
41786 return retval;
41787 }
41788
41789 +EXPORT_SYMBOL(tty_fasync);
41790 +
41791 /**
41792 * tiocsti - fake input character
41793 * @tty: tty to fake input into
41794 @@ -2695,8 +2695,10 @@ long tty_ioctl(struct file *file, unsign
41795 return retval;
41796 }
41797
41798 +EXPORT_SYMBOL(tty_ioctl);
41799 +
41800 #ifdef CONFIG_COMPAT
41801 -static long tty_compat_ioctl(struct file *file, unsigned int cmd,
41802 +long tty_compat_ioctl(struct file *file, unsigned int cmd,
41803 unsigned long arg)
41804 {
41805 struct inode *inode = file->f_dentry->d_inode;
41806 @@ -2720,6 +2722,9 @@ static long tty_compat_ioctl(struct file
41807
41808 return retval;
41809 }
41810 +
41811 +EXPORT_SYMBOL(tty_compat_ioctl);
41812 +
41813 #endif
41814
41815 /*
41816 @@ -3198,11 +3203,6 @@ struct tty_struct *get_current_tty(void)
41817 }
41818 EXPORT_SYMBOL_GPL(get_current_tty);
41819
41820 -void tty_default_fops(struct file_operations *fops)
41821 -{
41822 - *fops = tty_fops;
41823 -}
41824 -
41825 /*
41826 * Initialize the console device. This is called *early*, so
41827 * we can't necessarily depend on lots of kernel help here.
41828 diff -urNp linux-2.6.39.2/drivers/tty/tty_ldisc.c linux-2.6.39.2/drivers/tty/tty_ldisc.c
41829 --- linux-2.6.39.2/drivers/tty/tty_ldisc.c 2011-05-19 00:06:34.000000000 -0400
41830 +++ linux-2.6.39.2/drivers/tty/tty_ldisc.c 2011-05-22 19:36:32.000000000 -0400
41831 @@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *
41832 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
41833 struct tty_ldisc_ops *ldo = ld->ops;
41834
41835 - ldo->refcount--;
41836 + atomic_dec(&ldo->refcount);
41837 module_put(ldo->owner);
41838 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41839
41840 @@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct
41841 spin_lock_irqsave(&tty_ldisc_lock, flags);
41842 tty_ldiscs[disc] = new_ldisc;
41843 new_ldisc->num = disc;
41844 - new_ldisc->refcount = 0;
41845 + atomic_set(&new_ldisc->refcount, 0);
41846 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41847
41848 return ret;
41849 @@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
41850 return -EINVAL;
41851
41852 spin_lock_irqsave(&tty_ldisc_lock, flags);
41853 - if (tty_ldiscs[disc]->refcount)
41854 + if (atomic_read(&tty_ldiscs[disc]->refcount))
41855 ret = -EBUSY;
41856 else
41857 tty_ldiscs[disc] = NULL;
41858 @@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(i
41859 if (ldops) {
41860 ret = ERR_PTR(-EAGAIN);
41861 if (try_module_get(ldops->owner)) {
41862 - ldops->refcount++;
41863 + atomic_inc(&ldops->refcount);
41864 ret = ldops;
41865 }
41866 }
41867 @@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_o
41868 unsigned long flags;
41869
41870 spin_lock_irqsave(&tty_ldisc_lock, flags);
41871 - ldops->refcount--;
41872 + atomic_dec(&ldops->refcount);
41873 module_put(ldops->owner);
41874 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41875 }
41876 diff -urNp linux-2.6.39.2/drivers/tty/vt/keyboard.c linux-2.6.39.2/drivers/tty/vt/keyboard.c
41877 --- linux-2.6.39.2/drivers/tty/vt/keyboard.c 2011-05-19 00:06:34.000000000 -0400
41878 +++ linux-2.6.39.2/drivers/tty/vt/keyboard.c 2011-05-22 20:32:43.000000000 -0400
41879 @@ -658,6 +658,16 @@ static void k_spec(struct vc_data *vc, u
41880 kbd->kbdmode == VC_OFF) &&
41881 value != KVAL(K_SAK))
41882 return; /* SAK is allowed even in raw mode */
41883 +
41884 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41885 + {
41886 + void *func = fn_handler[value];
41887 + if (func == fn_show_state || func == fn_show_ptregs ||
41888 + func == fn_show_mem)
41889 + return;
41890 + }
41891 +#endif
41892 +
41893 fn_handler[value](vc);
41894 }
41895
41896 diff -urNp linux-2.6.39.2/drivers/tty/vt/vt.c linux-2.6.39.2/drivers/tty/vt/vt.c
41897 --- linux-2.6.39.2/drivers/tty/vt/vt.c 2011-05-19 00:06:34.000000000 -0400
41898 +++ linux-2.6.39.2/drivers/tty/vt/vt.c 2011-05-22 19:36:32.000000000 -0400
41899 @@ -261,7 +261,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier
41900
41901 static void notify_write(struct vc_data *vc, unsigned int unicode)
41902 {
41903 - struct vt_notifier_param param = { .vc = vc, unicode = unicode };
41904 + struct vt_notifier_param param = { .vc = vc, .c = unicode };
41905 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
41906 }
41907
41908 diff -urNp linux-2.6.39.2/drivers/tty/vt/vt_ioctl.c linux-2.6.39.2/drivers/tty/vt/vt_ioctl.c
41909 --- linux-2.6.39.2/drivers/tty/vt/vt_ioctl.c 2011-05-19 00:06:34.000000000 -0400
41910 +++ linux-2.6.39.2/drivers/tty/vt/vt_ioctl.c 2011-05-22 19:41:37.000000000 -0400
41911 @@ -209,9 +209,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41912 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41913 return -EFAULT;
41914
41915 - if (!capable(CAP_SYS_TTY_CONFIG))
41916 - perm = 0;
41917 -
41918 switch (cmd) {
41919 case KDGKBENT:
41920 key_map = key_maps[s];
41921 @@ -223,6 +220,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __
41922 val = (i ? K_HOLE : K_NOSUCHMAP);
41923 return put_user(val, &user_kbe->kb_value);
41924 case KDSKBENT:
41925 + if (!capable(CAP_SYS_TTY_CONFIG))
41926 + perm = 0;
41927 +
41928 if (!perm)
41929 return -EPERM;
41930 if (!i && v == K_NOSUCHMAP) {
41931 @@ -324,9 +324,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41932 int i, j, k;
41933 int ret;
41934
41935 - if (!capable(CAP_SYS_TTY_CONFIG))
41936 - perm = 0;
41937 -
41938 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41939 if (!kbs) {
41940 ret = -ENOMEM;
41941 @@ -360,6 +357,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
41942 kfree(kbs);
41943 return ((p && *p) ? -EOVERFLOW : 0);
41944 case KDSKBSENT:
41945 + if (!capable(CAP_SYS_TTY_CONFIG))
41946 + perm = 0;
41947 +
41948 if (!perm) {
41949 ret = -EPERM;
41950 goto reterr;
41951 diff -urNp linux-2.6.39.2/drivers/uio/uio.c linux-2.6.39.2/drivers/uio/uio.c
41952 --- linux-2.6.39.2/drivers/uio/uio.c 2011-05-19 00:06:34.000000000 -0400
41953 +++ linux-2.6.39.2/drivers/uio/uio.c 2011-05-22 19:36:32.000000000 -0400
41954 @@ -25,6 +25,7 @@
41955 #include <linux/kobject.h>
41956 #include <linux/cdev.h>
41957 #include <linux/uio_driver.h>
41958 +#include <asm/local.h>
41959
41960 #define UIO_MAX_DEVICES (1U << MINORBITS)
41961
41962 @@ -32,10 +33,10 @@ struct uio_device {
41963 struct module *owner;
41964 struct device *dev;
41965 int minor;
41966 - atomic_t event;
41967 + atomic_unchecked_t event;
41968 struct fasync_struct *async_queue;
41969 wait_queue_head_t wait;
41970 - int vma_count;
41971 + local_t vma_count;
41972 struct uio_info *info;
41973 struct kobject *map_dir;
41974 struct kobject *portio_dir;
41975 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device
41976 struct device_attribute *attr, char *buf)
41977 {
41978 struct uio_device *idev = dev_get_drvdata(dev);
41979 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41980 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41981 }
41982
41983 static struct device_attribute uio_class_attributes[] = {
41984 @@ -402,7 +403,7 @@ void uio_event_notify(struct uio_info *i
41985 {
41986 struct uio_device *idev = info->uio_dev;
41987
41988 - atomic_inc(&idev->event);
41989 + atomic_inc_unchecked(&idev->event);
41990 wake_up_interruptible(&idev->wait);
41991 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41992 }
41993 @@ -455,7 +456,7 @@ static int uio_open(struct inode *inode,
41994 }
41995
41996 listener->dev = idev;
41997 - listener->event_count = atomic_read(&idev->event);
41998 + listener->event_count = atomic_read_unchecked(&idev->event);
41999 filep->private_data = listener;
42000
42001 if (idev->info->open) {
42002 @@ -506,7 +507,7 @@ static unsigned int uio_poll(struct file
42003 return -EIO;
42004
42005 poll_wait(filep, &idev->wait, wait);
42006 - if (listener->event_count != atomic_read(&idev->event))
42007 + if (listener->event_count != atomic_read_unchecked(&idev->event))
42008 return POLLIN | POLLRDNORM;
42009 return 0;
42010 }
42011 @@ -531,7 +532,7 @@ static ssize_t uio_read(struct file *fil
42012 do {
42013 set_current_state(TASK_INTERRUPTIBLE);
42014
42015 - event_count = atomic_read(&idev->event);
42016 + event_count = atomic_read_unchecked(&idev->event);
42017 if (event_count != listener->event_count) {
42018 if (copy_to_user(buf, &event_count, count))
42019 retval = -EFAULT;
42020 @@ -602,13 +603,13 @@ static int uio_find_mem_index(struct vm_
42021 static void uio_vma_open(struct vm_area_struct *vma)
42022 {
42023 struct uio_device *idev = vma->vm_private_data;
42024 - idev->vma_count++;
42025 + local_inc(&idev->vma_count);
42026 }
42027
42028 static void uio_vma_close(struct vm_area_struct *vma)
42029 {
42030 struct uio_device *idev = vma->vm_private_data;
42031 - idev->vma_count--;
42032 + local_dec(&idev->vma_count);
42033 }
42034
42035 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42036 @@ -819,7 +820,7 @@ int __uio_register_device(struct module
42037 idev->owner = owner;
42038 idev->info = info;
42039 init_waitqueue_head(&idev->wait);
42040 - atomic_set(&idev->event, 0);
42041 + atomic_set_unchecked(&idev->event, 0);
42042
42043 ret = uio_get_minor(idev);
42044 if (ret)
42045 diff -urNp linux-2.6.39.2/drivers/usb/atm/cxacru.c linux-2.6.39.2/drivers/usb/atm/cxacru.c
42046 --- linux-2.6.39.2/drivers/usb/atm/cxacru.c 2011-05-19 00:06:34.000000000 -0400
42047 +++ linux-2.6.39.2/drivers/usb/atm/cxacru.c 2011-05-22 19:36:32.000000000 -0400
42048 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_c
42049 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
42050 if (ret < 2)
42051 return -EINVAL;
42052 - if (index < 0 || index > 0x7f)
42053 + if (index > 0x7f)
42054 return -EINVAL;
42055 pos += tmp;
42056
42057 diff -urNp linux-2.6.39.2/drivers/usb/atm/usbatm.c linux-2.6.39.2/drivers/usb/atm/usbatm.c
42058 --- linux-2.6.39.2/drivers/usb/atm/usbatm.c 2011-05-19 00:06:34.000000000 -0400
42059 +++ linux-2.6.39.2/drivers/usb/atm/usbatm.c 2011-05-22 19:36:32.000000000 -0400
42060 @@ -332,7 +332,7 @@ static void usbatm_extract_one_cell(stru
42061 if (printk_ratelimit())
42062 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42063 __func__, vpi, vci);
42064 - atomic_inc(&vcc->stats->rx_err);
42065 + atomic_inc_unchecked(&vcc->stats->rx_err);
42066 return;
42067 }
42068
42069 @@ -360,7 +360,7 @@ static void usbatm_extract_one_cell(stru
42070 if (length > ATM_MAX_AAL5_PDU) {
42071 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42072 __func__, length, vcc);
42073 - atomic_inc(&vcc->stats->rx_err);
42074 + atomic_inc_unchecked(&vcc->stats->rx_err);
42075 goto out;
42076 }
42077
42078 @@ -369,14 +369,14 @@ static void usbatm_extract_one_cell(stru
42079 if (sarb->len < pdu_length) {
42080 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42081 __func__, pdu_length, sarb->len, vcc);
42082 - atomic_inc(&vcc->stats->rx_err);
42083 + atomic_inc_unchecked(&vcc->stats->rx_err);
42084 goto out;
42085 }
42086
42087 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42088 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42089 __func__, vcc);
42090 - atomic_inc(&vcc->stats->rx_err);
42091 + atomic_inc_unchecked(&vcc->stats->rx_err);
42092 goto out;
42093 }
42094
42095 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(stru
42096 if (printk_ratelimit())
42097 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42098 __func__, length);
42099 - atomic_inc(&vcc->stats->rx_drop);
42100 + atomic_inc_unchecked(&vcc->stats->rx_drop);
42101 goto out;
42102 }
42103
42104 @@ -411,7 +411,7 @@ static void usbatm_extract_one_cell(stru
42105
42106 vcc->push(vcc, skb);
42107
42108 - atomic_inc(&vcc->stats->rx);
42109 + atomic_inc_unchecked(&vcc->stats->rx);
42110 out:
42111 skb_trim(sarb, 0);
42112 }
42113 @@ -614,7 +614,7 @@ static void usbatm_tx_process(unsigned l
42114 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42115
42116 usbatm_pop(vcc, skb);
42117 - atomic_inc(&vcc->stats->tx);
42118 + atomic_inc_unchecked(&vcc->stats->tx);
42119
42120 skb = skb_dequeue(&instance->sndqueue);
42121 }
42122 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct a
42123 if (!left--)
42124 return sprintf(page,
42125 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42126 - atomic_read(&atm_dev->stats.aal5.tx),
42127 - atomic_read(&atm_dev->stats.aal5.tx_err),
42128 - atomic_read(&atm_dev->stats.aal5.rx),
42129 - atomic_read(&atm_dev->stats.aal5.rx_err),
42130 - atomic_read(&atm_dev->stats.aal5.rx_drop));
42131 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42132 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42133 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42134 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42135 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42136
42137 if (!left--) {
42138 if (instance->disconnected)
42139 diff -urNp linux-2.6.39.2/drivers/usb/core/devices.c linux-2.6.39.2/drivers/usb/core/devices.c
42140 --- linux-2.6.39.2/drivers/usb/core/devices.c 2011-05-19 00:06:34.000000000 -0400
42141 +++ linux-2.6.39.2/drivers/usb/core/devices.c 2011-05-22 19:36:32.000000000 -0400
42142 @@ -126,7 +126,7 @@ static const char *format_endpt =
42143 * time it gets called.
42144 */
42145 static struct device_connect_event {
42146 - atomic_t count;
42147 + atomic_unchecked_t count;
42148 wait_queue_head_t wait;
42149 } device_event = {
42150 .count = ATOMIC_INIT(1),
42151 @@ -164,7 +164,7 @@ static const struct class_info clas_info
42152
42153 void usbfs_conn_disc_event(void)
42154 {
42155 - atomic_add(2, &device_event.count);
42156 + atomic_add_unchecked(2, &device_event.count);
42157 wake_up(&device_event.wait);
42158 }
42159
42160 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(stru
42161
42162 poll_wait(file, &device_event.wait, wait);
42163
42164 - event_count = atomic_read(&device_event.count);
42165 + event_count = atomic_read_unchecked(&device_event.count);
42166 if (file->f_version != event_count) {
42167 file->f_version = event_count;
42168 return POLLIN | POLLRDNORM;
42169 diff -urNp linux-2.6.39.2/drivers/usb/core/hcd.c linux-2.6.39.2/drivers/usb/core/hcd.c
42170 --- linux-2.6.39.2/drivers/usb/core/hcd.c 2011-06-03 00:04:14.000000000 -0400
42171 +++ linux-2.6.39.2/drivers/usb/core/hcd.c 2011-06-03 00:32:07.000000000 -0400
42172 @@ -2574,7 +2574,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutd
42173
42174 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42175
42176 -struct usb_mon_operations *mon_ops;
42177 +const struct usb_mon_operations *mon_ops;
42178
42179 /*
42180 * The registration is unlocked.
42181 @@ -2584,7 +2584,7 @@ struct usb_mon_operations *mon_ops;
42182 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42183 */
42184
42185 -int usb_mon_register (struct usb_mon_operations *ops)
42186 +int usb_mon_register (const struct usb_mon_operations *ops)
42187 {
42188
42189 if (mon_ops)
42190 diff -urNp linux-2.6.39.2/drivers/usb/core/message.c linux-2.6.39.2/drivers/usb/core/message.c
42191 --- linux-2.6.39.2/drivers/usb/core/message.c 2011-05-19 00:06:34.000000000 -0400
42192 +++ linux-2.6.39.2/drivers/usb/core/message.c 2011-05-22 19:36:32.000000000 -0400
42193 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device
42194 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42195 if (buf) {
42196 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42197 - if (len > 0) {
42198 - smallbuf = kmalloc(++len, GFP_NOIO);
42199 + if (len++ > 0) {
42200 + smallbuf = kmalloc(len, GFP_NOIO);
42201 if (!smallbuf)
42202 return buf;
42203 memcpy(smallbuf, buf, len);
42204 diff -urNp linux-2.6.39.2/drivers/usb/early/ehci-dbgp.c linux-2.6.39.2/drivers/usb/early/ehci-dbgp.c
42205 --- linux-2.6.39.2/drivers/usb/early/ehci-dbgp.c 2011-05-19 00:06:34.000000000 -0400
42206 +++ linux-2.6.39.2/drivers/usb/early/ehci-dbgp.c 2011-05-22 19:36:32.000000000 -0400
42207 @@ -96,7 +96,7 @@ static inline u32 dbgp_len_update(u32 x,
42208 }
42209
42210 #ifdef CONFIG_KGDB
42211 -static struct kgdb_io kgdbdbgp_io_ops;
42212 +static struct kgdb_io kgdbdbgp_io_ops; /* cannot be const, see kgdbdbgp_parse_config */
42213 #define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
42214 #else
42215 #define dbgp_kgdb_mode (0)
42216 @@ -1026,7 +1026,7 @@ static void kgdbdbgp_write_char(u8 chr)
42217 early_dbgp_write(NULL, &chr, 1);
42218 }
42219
42220 -static struct kgdb_io kgdbdbgp_io_ops = {
42221 +static struct kgdb_io kgdbdbgp_io_ops = { /* cannot be const, see kgdbdbgp_parse_config() */
42222 .name = "kgdbdbgp",
42223 .read_char = kgdbdbgp_read_char,
42224 .write_char = kgdbdbgp_write_char,
42225 diff -urNp linux-2.6.39.2/drivers/usb/gadget/fsl_qe_udc.c linux-2.6.39.2/drivers/usb/gadget/fsl_qe_udc.c
42226 --- linux-2.6.39.2/drivers/usb/gadget/fsl_qe_udc.c 2011-05-19 00:06:34.000000000 -0400
42227 +++ linux-2.6.39.2/drivers/usb/gadget/fsl_qe_udc.c 2011-05-22 19:36:32.000000000 -0400
42228 @@ -1859,7 +1859,7 @@ out:
42229 return status;
42230 }
42231
42232 -static struct usb_ep_ops qe_ep_ops = {
42233 +static const struct usb_ep_ops qe_ep_ops = {
42234 .enable = qe_ep_enable,
42235 .disable = qe_ep_disable,
42236
42237 @@ -1928,7 +1928,7 @@ static int qe_pullup(struct usb_gadget *
42238 }
42239
42240 /* defined in usb_gadget.h */
42241 -static struct usb_gadget_ops qe_gadget_ops = {
42242 +static const struct usb_gadget_ops qe_gadget_ops = {
42243 .get_frame = qe_get_frame,
42244 .wakeup = qe_wakeup,
42245 /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */
42246 diff -urNp linux-2.6.39.2/drivers/usb/gadget/fsl_udc_core.c linux-2.6.39.2/drivers/usb/gadget/fsl_udc_core.c
42247 --- linux-2.6.39.2/drivers/usb/gadget/fsl_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42248 +++ linux-2.6.39.2/drivers/usb/gadget/fsl_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42249 @@ -1003,7 +1003,7 @@ static void fsl_ep_fifo_flush(struct usb
42250 } while (fsl_readl(&dr_regs->endptstatus) & bits);
42251 }
42252
42253 -static struct usb_ep_ops fsl_ep_ops = {
42254 +static const struct usb_ep_ops fsl_ep_ops = {
42255 .enable = fsl_ep_enable,
42256 .disable = fsl_ep_disable,
42257
42258 @@ -1114,7 +1114,7 @@ static int fsl_pullup(struct usb_gadget
42259 }
42260
42261 /* defined in gadget.h */
42262 -static struct usb_gadget_ops fsl_gadget_ops = {
42263 +static const struct usb_gadget_ops fsl_gadget_ops = {
42264 .get_frame = fsl_get_frame,
42265 .wakeup = fsl_wakeup,
42266 /* .set_selfpowered = fsl_set_selfpowered, */ /* Always selfpowered */
42267 diff -urNp linux-2.6.39.2/drivers/usb/gadget/fusb300_udc.c linux-2.6.39.2/drivers/usb/gadget/fusb300_udc.c
42268 --- linux-2.6.39.2/drivers/usb/gadget/fusb300_udc.c 2011-05-19 00:06:34.000000000 -0400
42269 +++ linux-2.6.39.2/drivers/usb/gadget/fusb300_udc.c 2011-05-22 19:36:32.000000000 -0400
42270 @@ -527,7 +527,7 @@ static void fusb300_fifo_flush(struct us
42271 {
42272 }
42273
42274 -static struct usb_ep_ops fusb300_ep_ops = {
42275 +static const struct usb_ep_ops fusb300_ep_ops = {
42276 .enable = fusb300_enable,
42277 .disable = fusb300_disable,
42278
42279 @@ -1570,7 +1570,7 @@ static int fusb300_udc_pullup(struct usb
42280 return 0;
42281 }
42282
42283 -static struct usb_gadget_ops fusb300_gadget_ops = {
42284 +static const struct usb_gadget_ops fusb300_gadget_ops = {
42285 .pullup = fusb300_udc_pullup,
42286 };
42287
42288 diff -urNp linux-2.6.39.2/drivers/usb/gadget/goku_udc.c linux-2.6.39.2/drivers/usb/gadget/goku_udc.c
42289 --- linux-2.6.39.2/drivers/usb/gadget/goku_udc.c 2011-05-19 00:06:34.000000000 -0400
42290 +++ linux-2.6.39.2/drivers/usb/gadget/goku_udc.c 2011-05-22 19:36:32.000000000 -0400
42291 @@ -973,7 +973,7 @@ static void goku_fifo_flush(struct usb_e
42292 command(regs, COMMAND_FIFO_CLEAR, ep->num);
42293 }
42294
42295 -static struct usb_ep_ops goku_ep_ops = {
42296 +static const struct usb_ep_ops goku_ep_ops = {
42297 .enable = goku_ep_enable,
42298 .disable = goku_ep_disable,
42299
42300 diff -urNp linux-2.6.39.2/drivers/usb/gadget/imx_udc.c linux-2.6.39.2/drivers/usb/gadget/imx_udc.c
42301 --- linux-2.6.39.2/drivers/usb/gadget/imx_udc.c 2011-05-19 00:06:34.000000000 -0400
42302 +++ linux-2.6.39.2/drivers/usb/gadget/imx_udc.c 2011-05-22 19:36:32.000000000 -0400
42303 @@ -937,7 +937,7 @@ static void imx_ep_fifo_flush(struct usb
42304 local_irq_restore(flags);
42305 }
42306
42307 -static struct usb_ep_ops imx_ep_ops = {
42308 +static const struct usb_ep_ops imx_ep_ops = {
42309 .enable = imx_ep_enable,
42310 .disable = imx_ep_disable,
42311
42312 diff -urNp linux-2.6.39.2/drivers/usb/gadget/m66592-udc.c linux-2.6.39.2/drivers/usb/gadget/m66592-udc.c
42313 --- linux-2.6.39.2/drivers/usb/gadget/m66592-udc.c 2011-05-19 00:06:34.000000000 -0400
42314 +++ linux-2.6.39.2/drivers/usb/gadget/m66592-udc.c 2011-05-22 19:36:32.000000000 -0400
42315 @@ -1437,7 +1437,7 @@ static void m66592_fifo_flush(struct usb
42316 spin_unlock_irqrestore(&ep->m66592->lock, flags);
42317 }
42318
42319 -static struct usb_ep_ops m66592_ep_ops = {
42320 +static const struct usb_ep_ops m66592_ep_ops = {
42321 .enable = m66592_enable,
42322 .disable = m66592_disable,
42323
42324 @@ -1542,7 +1542,7 @@ static int m66592_get_frame(struct usb_g
42325 return m66592_read(m66592, M66592_FRMNUM) & 0x03FF;
42326 }
42327
42328 -static struct usb_gadget_ops m66592_gadget_ops = {
42329 +static const struct usb_gadget_ops m66592_gadget_ops = {
42330 .get_frame = m66592_get_frame,
42331 };
42332
42333 diff -urNp linux-2.6.39.2/drivers/usb/gadget/mv_udc_core.c linux-2.6.39.2/drivers/usb/gadget/mv_udc_core.c
42334 --- linux-2.6.39.2/drivers/usb/gadget/mv_udc_core.c 2011-05-19 00:06:34.000000000 -0400
42335 +++ linux-2.6.39.2/drivers/usb/gadget/mv_udc_core.c 2011-05-22 19:36:32.000000000 -0400
42336 @@ -972,7 +972,7 @@ static int mv_ep_set_wedge(struct usb_ep
42337 return mv_ep_set_halt_wedge(_ep, 1, 1);
42338 }
42339
42340 -static struct usb_ep_ops mv_ep_ops = {
42341 +static const struct usb_ep_ops mv_ep_ops = {
42342 .enable = mv_ep_enable,
42343 .disable = mv_ep_disable,
42344
42345 diff -urNp linux-2.6.39.2/drivers/usb/gadget/omap_udc.c linux-2.6.39.2/drivers/usb/gadget/omap_udc.c
42346 --- linux-2.6.39.2/drivers/usb/gadget/omap_udc.c 2011-05-19 00:06:34.000000000 -0400
42347 +++ linux-2.6.39.2/drivers/usb/gadget/omap_udc.c 2011-05-22 19:36:32.000000000 -0400
42348 @@ -1177,7 +1177,7 @@ done:
42349 return status;
42350 }
42351
42352 -static struct usb_ep_ops omap_ep_ops = {
42353 +static const struct usb_ep_ops omap_ep_ops = {
42354 .enable = omap_ep_enable,
42355 .disable = omap_ep_disable,
42356
42357 @@ -1374,7 +1374,7 @@ static int omap_pullup(struct usb_gadget
42358 return 0;
42359 }
42360
42361 -static struct usb_gadget_ops omap_gadget_ops = {
42362 +static const struct usb_gadget_ops omap_gadget_ops = {
42363 .get_frame = omap_get_frame,
42364 .wakeup = omap_wakeup,
42365 .set_selfpowered = omap_set_selfpowered,
42366 diff -urNp linux-2.6.39.2/drivers/usb/gadget/pxa25x_udc.c linux-2.6.39.2/drivers/usb/gadget/pxa25x_udc.c
42367 --- linux-2.6.39.2/drivers/usb/gadget/pxa25x_udc.c 2011-05-19 00:06:34.000000000 -0400
42368 +++ linux-2.6.39.2/drivers/usb/gadget/pxa25x_udc.c 2011-05-22 19:36:32.000000000 -0400
42369 @@ -896,7 +896,7 @@ static void pxa25x_ep_fifo_flush(struct
42370 }
42371
42372
42373 -static struct usb_ep_ops pxa25x_ep_ops = {
42374 +static const struct usb_ep_ops pxa25x_ep_ops = {
42375 .enable = pxa25x_ep_enable,
42376 .disable = pxa25x_ep_disable,
42377
42378 diff -urNp linux-2.6.39.2/drivers/usb/gadget/pxa27x_udc.c linux-2.6.39.2/drivers/usb/gadget/pxa27x_udc.c
42379 --- linux-2.6.39.2/drivers/usb/gadget/pxa27x_udc.c 2011-05-19 00:06:34.000000000 -0400
42380 +++ linux-2.6.39.2/drivers/usb/gadget/pxa27x_udc.c 2011-05-22 19:36:32.000000000 -0400
42381 @@ -1491,7 +1491,7 @@ static int pxa_ep_disable(struct usb_ep
42382 return 0;
42383 }
42384
42385 -static struct usb_ep_ops pxa_ep_ops = {
42386 +static const struct usb_ep_ops pxa_ep_ops = {
42387 .enable = pxa_ep_enable,
42388 .disable = pxa_ep_disable,
42389
42390 diff -urNp linux-2.6.39.2/drivers/usb/gadget/r8a66597-udc.c linux-2.6.39.2/drivers/usb/gadget/r8a66597-udc.c
42391 --- linux-2.6.39.2/drivers/usb/gadget/r8a66597-udc.c 2011-05-19 00:06:34.000000000 -0400
42392 +++ linux-2.6.39.2/drivers/usb/gadget/r8a66597-udc.c 2011-05-22 19:36:32.000000000 -0400
42393 @@ -1392,7 +1392,7 @@ static void r8a66597_fifo_flush(struct u
42394 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
42395 }
42396
42397 -static struct usb_ep_ops r8a66597_ep_ops = {
42398 +static const struct usb_ep_ops r8a66597_ep_ops = {
42399 .enable = r8a66597_enable,
42400 .disable = r8a66597_disable,
42401
42402 @@ -1497,7 +1497,7 @@ static int r8a66597_get_frame(struct usb
42403 return r8a66597_read(r8a66597, FRMNUM) & 0x03FF;
42404 }
42405
42406 -static struct usb_gadget_ops r8a66597_gadget_ops = {
42407 +static const struct usb_gadget_ops r8a66597_gadget_ops = {
42408 .get_frame = r8a66597_get_frame,
42409 };
42410
42411 diff -urNp linux-2.6.39.2/drivers/usb/gadget/s3c-hsotg.c linux-2.6.39.2/drivers/usb/gadget/s3c-hsotg.c
42412 --- linux-2.6.39.2/drivers/usb/gadget/s3c-hsotg.c 2011-05-19 00:06:34.000000000 -0400
42413 +++ linux-2.6.39.2/drivers/usb/gadget/s3c-hsotg.c 2011-05-22 19:36:32.000000000 -0400
42414 @@ -2461,7 +2461,7 @@ static int s3c_hsotg_ep_sethalt(struct u
42415 return 0;
42416 }
42417
42418 -static struct usb_ep_ops s3c_hsotg_ep_ops = {
42419 +static const struct usb_ep_ops s3c_hsotg_ep_ops = {
42420 .enable = s3c_hsotg_ep_enable,
42421 .disable = s3c_hsotg_ep_disable,
42422 .alloc_request = s3c_hsotg_ep_alloc_request,
42423 @@ -2725,7 +2725,7 @@ static int s3c_hsotg_gadget_getframe(str
42424 return s3c_hsotg_read_frameno(to_hsotg(gadget));
42425 }
42426
42427 -static struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42428 +static const struct usb_gadget_ops s3c_hsotg_gadget_ops = {
42429 .get_frame = s3c_hsotg_gadget_getframe,
42430 };
42431
42432 diff -urNp linux-2.6.39.2/drivers/usb/gadget/uvc_queue.c linux-2.6.39.2/drivers/usb/gadget/uvc_queue.c
42433 --- linux-2.6.39.2/drivers/usb/gadget/uvc_queue.c 2011-05-19 00:06:34.000000000 -0400
42434 +++ linux-2.6.39.2/drivers/usb/gadget/uvc_queue.c 2011-05-22 19:36:32.000000000 -0400
42435 @@ -400,7 +400,7 @@ static void uvc_vm_close(struct vm_area_
42436 buffer->vma_use_count--;
42437 }
42438
42439 -static struct vm_operations_struct uvc_vm_ops = {
42440 +static const struct vm_operations_struct uvc_vm_ops = {
42441 .open = uvc_vm_open,
42442 .close = uvc_vm_close,
42443 };
42444 diff -urNp linux-2.6.39.2/drivers/usb/host/ehci-fsl.c linux-2.6.39.2/drivers/usb/host/ehci-fsl.c
42445 --- linux-2.6.39.2/drivers/usb/host/ehci-fsl.c 2011-05-19 00:06:34.000000000 -0400
42446 +++ linux-2.6.39.2/drivers/usb/host/ehci-fsl.c 2011-05-22 19:36:32.000000000 -0400
42447 @@ -380,7 +380,7 @@ static int ehci_fsl_drv_restore(struct d
42448 return 0;
42449 }
42450
42451 -static struct dev_pm_ops ehci_fsl_pm_ops = {
42452 +static const struct dev_pm_ops ehci_fsl_pm_ops = {
42453 .suspend = ehci_fsl_drv_suspend,
42454 .resume = ehci_fsl_drv_resume,
42455 .restore = ehci_fsl_drv_restore,
42456 diff -urNp linux-2.6.39.2/drivers/usb/host/xhci-mem.c linux-2.6.39.2/drivers/usb/host/xhci-mem.c
42457 --- linux-2.6.39.2/drivers/usb/host/xhci-mem.c 2011-06-25 12:55:23.000000000 -0400
42458 +++ linux-2.6.39.2/drivers/usb/host/xhci-mem.c 2011-06-25 13:00:26.000000000 -0400
42459 @@ -1680,6 +1680,8 @@ static int xhci_check_trb_in_td_math(str
42460 unsigned int num_tests;
42461 int i, ret;
42462
42463 + pax_track_stack();
42464 +
42465 num_tests = ARRAY_SIZE(simple_test_vector);
42466 for (i = 0; i < num_tests; i++) {
42467 ret = xhci_test_trb_in_td(xhci,
42468 diff -urNp linux-2.6.39.2/drivers/usb/mon/mon_main.c linux-2.6.39.2/drivers/usb/mon/mon_main.c
42469 --- linux-2.6.39.2/drivers/usb/mon/mon_main.c 2011-05-19 00:06:34.000000000 -0400
42470 +++ linux-2.6.39.2/drivers/usb/mon/mon_main.c 2011-05-22 19:36:32.000000000 -0400
42471 @@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42472 /*
42473 * Ops
42474 */
42475 -static struct usb_mon_operations mon_ops_0 = {
42476 +static const struct usb_mon_operations mon_ops_0 = {
42477 .urb_submit = mon_submit,
42478 .urb_submit_error = mon_submit_error,
42479 .urb_complete = mon_complete,
42480 diff -urNp linux-2.6.39.2/drivers/usb/musb/cppi_dma.h linux-2.6.39.2/drivers/usb/musb/cppi_dma.h
42481 --- linux-2.6.39.2/drivers/usb/musb/cppi_dma.h 2011-05-19 00:06:34.000000000 -0400
42482 +++ linux-2.6.39.2/drivers/usb/musb/cppi_dma.h 2011-05-22 19:36:32.000000000 -0400
42483 @@ -113,7 +113,7 @@ struct cppi_channel {
42484
42485 /* CPPI DMA controller object */
42486 struct cppi {
42487 - struct dma_controller controller;
42488 + const struct dma_controller controller;
42489 struct musb *musb;
42490 void __iomem *mregs; /* Mentor regs */
42491 void __iomem *tibase; /* TI/CPPI regs */
42492 diff -urNp linux-2.6.39.2/drivers/usb/otg/msm_otg.c linux-2.6.39.2/drivers/usb/otg/msm_otg.c
42493 --- linux-2.6.39.2/drivers/usb/otg/msm_otg.c 2011-05-19 00:06:34.000000000 -0400
42494 +++ linux-2.6.39.2/drivers/usb/otg/msm_otg.c 2011-05-22 19:36:32.000000000 -0400
42495 @@ -95,7 +95,7 @@ static int ulpi_write(struct otg_transce
42496 return 0;
42497 }
42498
42499 -static struct otg_io_access_ops msm_otg_io_ops = {
42500 +static const struct otg_io_access_ops msm_otg_io_ops = {
42501 .read = ulpi_read,
42502 .write = ulpi_write,
42503 };
42504 diff -urNp linux-2.6.39.2/drivers/usb/otg/ulpi_viewport.c linux-2.6.39.2/drivers/usb/otg/ulpi_viewport.c
42505 --- linux-2.6.39.2/drivers/usb/otg/ulpi_viewport.c 2011-05-19 00:06:34.000000000 -0400
42506 +++ linux-2.6.39.2/drivers/usb/otg/ulpi_viewport.c 2011-05-22 19:36:32.000000000 -0400
42507 @@ -74,7 +74,7 @@ static int ulpi_viewport_write(struct ot
42508 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
42509 }
42510
42511 -struct otg_io_access_ops ulpi_viewport_access_ops = {
42512 +const struct otg_io_access_ops ulpi_viewport_access_ops = {
42513 .read = ulpi_viewport_read,
42514 .write = ulpi_viewport_write,
42515 };
42516 diff -urNp linux-2.6.39.2/drivers/usb/serial/ftdi_sio.c linux-2.6.39.2/drivers/usb/serial/ftdi_sio.c
42517 --- linux-2.6.39.2/drivers/usb/serial/ftdi_sio.c 2011-06-25 12:55:23.000000000 -0400
42518 +++ linux-2.6.39.2/drivers/usb/serial/ftdi_sio.c 2011-06-25 13:00:26.000000000 -0400
42519 @@ -104,27 +104,27 @@ static int ftdi_stmclite_probe(struct
42520 static void ftdi_USB_UIRT_setup(struct ftdi_private *priv);
42521 static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv);
42522
42523 -static struct ftdi_sio_quirk ftdi_jtag_quirk = {
42524 +static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
42525 .probe = ftdi_jtag_probe,
42526 };
42527
42528 -static struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42529 +static const struct ftdi_sio_quirk ftdi_mtxorb_hack_quirk = {
42530 .probe = ftdi_mtxorb_hack_setup,
42531 };
42532
42533 -static struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42534 +static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = {
42535 .probe = ftdi_NDI_device_setup,
42536 };
42537
42538 -static struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42539 +static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = {
42540 .port_probe = ftdi_USB_UIRT_setup,
42541 };
42542
42543 -static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42544 +static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
42545 .port_probe = ftdi_HE_TIRA1_setup,
42546 };
42547
42548 -static struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42549 +static const struct ftdi_sio_quirk ftdi_stmclite_quirk = {
42550 .probe = ftdi_stmclite_probe,
42551 };
42552
42553 diff -urNp linux-2.6.39.2/drivers/usb/wusbcore/wa-hc.h linux-2.6.39.2/drivers/usb/wusbcore/wa-hc.h
42554 --- linux-2.6.39.2/drivers/usb/wusbcore/wa-hc.h 2011-05-19 00:06:34.000000000 -0400
42555 +++ linux-2.6.39.2/drivers/usb/wusbcore/wa-hc.h 2011-05-22 19:36:32.000000000 -0400
42556 @@ -192,7 +192,7 @@ struct wahc {
42557 struct list_head xfer_delayed_list;
42558 spinlock_t xfer_list_lock;
42559 struct work_struct xfer_work;
42560 - atomic_t xfer_id_count;
42561 + atomic_unchecked_t xfer_id_count;
42562 };
42563
42564
42565 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *
42566 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42567 spin_lock_init(&wa->xfer_list_lock);
42568 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42569 - atomic_set(&wa->xfer_id_count, 1);
42570 + atomic_set_unchecked(&wa->xfer_id_count, 1);
42571 }
42572
42573 /**
42574 diff -urNp linux-2.6.39.2/drivers/usb/wusbcore/wa-xfer.c linux-2.6.39.2/drivers/usb/wusbcore/wa-xfer.c
42575 --- linux-2.6.39.2/drivers/usb/wusbcore/wa-xfer.c 2011-05-19 00:06:34.000000000 -0400
42576 +++ linux-2.6.39.2/drivers/usb/wusbcore/wa-xfer.c 2011-05-22 19:36:32.000000000 -0400
42577 @@ -294,7 +294,7 @@ out:
42578 */
42579 static void wa_xfer_id_init(struct wa_xfer *xfer)
42580 {
42581 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42582 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42583 }
42584
42585 /*
42586 diff -urNp linux-2.6.39.2/drivers/vhost/vhost.c linux-2.6.39.2/drivers/vhost/vhost.c
42587 --- linux-2.6.39.2/drivers/vhost/vhost.c 2011-05-19 00:06:34.000000000 -0400
42588 +++ linux-2.6.39.2/drivers/vhost/vhost.c 2011-05-22 19:36:32.000000000 -0400
42589 @@ -580,7 +580,7 @@ static int init_used(struct vhost_virtqu
42590 return get_user(vq->last_used_idx, &used->idx);
42591 }
42592
42593 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
42594 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
42595 {
42596 struct file *eventfp, *filep = NULL,
42597 *pollstart = NULL, *pollstop = NULL;
42598 diff -urNp linux-2.6.39.2/drivers/video/backlight/corgi_lcd.c linux-2.6.39.2/drivers/video/backlight/corgi_lcd.c
42599 --- linux-2.6.39.2/drivers/video/backlight/corgi_lcd.c 2011-05-19 00:06:34.000000000 -0400
42600 +++ linux-2.6.39.2/drivers/video/backlight/corgi_lcd.c 2011-05-22 19:36:32.000000000 -0400
42601 @@ -383,7 +383,7 @@ static int corgi_lcd_get_power(struct lc
42602 return lcd->power;
42603 }
42604
42605 -static struct lcd_ops corgi_lcd_ops = {
42606 +static const struct lcd_ops corgi_lcd_ops = {
42607 .get_power = corgi_lcd_get_power,
42608 .set_power = corgi_lcd_set_power,
42609 .set_mode = corgi_lcd_set_mode,
42610 diff -urNp linux-2.6.39.2/drivers/video/backlight/cr_bllcd.c linux-2.6.39.2/drivers/video/backlight/cr_bllcd.c
42611 --- linux-2.6.39.2/drivers/video/backlight/cr_bllcd.c 2011-05-19 00:06:34.000000000 -0400
42612 +++ linux-2.6.39.2/drivers/video/backlight/cr_bllcd.c 2011-05-22 19:36:32.000000000 -0400
42613 @@ -165,7 +165,7 @@ static int cr_lcd_set_power(struct lcd_d
42614 return 0;
42615 }
42616
42617 -static struct lcd_ops cr_lcd_ops = {
42618 +static const struct lcd_ops cr_lcd_ops = {
42619 .set_power = cr_lcd_set_power,
42620 };
42621
42622 diff -urNp linux-2.6.39.2/drivers/video/backlight/ili9320.c linux-2.6.39.2/drivers/video/backlight/ili9320.c
42623 --- linux-2.6.39.2/drivers/video/backlight/ili9320.c 2011-05-19 00:06:34.000000000 -0400
42624 +++ linux-2.6.39.2/drivers/video/backlight/ili9320.c 2011-05-22 19:36:32.000000000 -0400
42625 @@ -166,7 +166,7 @@ static int ili9320_get_power(struct lcd_
42626 return lcd->power;
42627 }
42628
42629 -static struct lcd_ops ili9320_ops = {
42630 +static const struct lcd_ops ili9320_ops = {
42631 .get_power = ili9320_get_power,
42632 .set_power = ili9320_set_power,
42633 };
42634 diff -urNp linux-2.6.39.2/drivers/video/backlight/jornada720_lcd.c linux-2.6.39.2/drivers/video/backlight/jornada720_lcd.c
42635 --- linux-2.6.39.2/drivers/video/backlight/jornada720_lcd.c 2011-05-19 00:06:34.000000000 -0400
42636 +++ linux-2.6.39.2/drivers/video/backlight/jornada720_lcd.c 2011-05-22 19:36:32.000000000 -0400
42637 @@ -87,7 +87,7 @@ static int jornada_lcd_set_power(struct
42638 return 0;
42639 }
42640
42641 -static struct lcd_ops jornada_lcd_props = {
42642 +static const struct lcd_ops jornada_lcd_props = {
42643 .get_contrast = jornada_lcd_get_contrast,
42644 .set_contrast = jornada_lcd_set_contrast,
42645 .get_power = jornada_lcd_get_power,
42646 diff -urNp linux-2.6.39.2/drivers/video/backlight/l4f00242t03.c linux-2.6.39.2/drivers/video/backlight/l4f00242t03.c
42647 --- linux-2.6.39.2/drivers/video/backlight/l4f00242t03.c 2011-05-19 00:06:34.000000000 -0400
42648 +++ linux-2.6.39.2/drivers/video/backlight/l4f00242t03.c 2011-05-22 19:36:32.000000000 -0400
42649 @@ -149,7 +149,7 @@ static int l4f00242t03_lcd_power_set(str
42650 return 0;
42651 }
42652
42653 -static struct lcd_ops l4f_ops = {
42654 +static const struct lcd_ops l4f_ops = {
42655 .set_power = l4f00242t03_lcd_power_set,
42656 .get_power = l4f00242t03_lcd_power_get,
42657 };
42658 diff -urNp linux-2.6.39.2/drivers/video/backlight/lcd.c linux-2.6.39.2/drivers/video/backlight/lcd.c
42659 --- linux-2.6.39.2/drivers/video/backlight/lcd.c 2011-05-19 00:06:34.000000000 -0400
42660 +++ linux-2.6.39.2/drivers/video/backlight/lcd.c 2011-05-22 19:36:32.000000000 -0400
42661 @@ -192,7 +192,7 @@ static struct device_attribute lcd_devic
42662 * or a pointer to the newly allocated device.
42663 */
42664 struct lcd_device *lcd_device_register(const char *name, struct device *parent,
42665 - void *devdata, struct lcd_ops *ops)
42666 + void *devdata, const struct lcd_ops *ops)
42667 {
42668 struct lcd_device *new_ld;
42669 int rc;
42670 diff -urNp linux-2.6.39.2/drivers/video/backlight/ld9040.c linux-2.6.39.2/drivers/video/backlight/ld9040.c
42671 --- linux-2.6.39.2/drivers/video/backlight/ld9040.c 2011-05-19 00:06:34.000000000 -0400
42672 +++ linux-2.6.39.2/drivers/video/backlight/ld9040.c 2011-05-22 19:36:32.000000000 -0400
42673 @@ -651,7 +651,7 @@ static int ld9040_set_brightness(struct
42674 return ret;
42675 }
42676
42677 -static struct lcd_ops ld9040_lcd_ops = {
42678 +static const struct lcd_ops ld9040_lcd_ops = {
42679 .set_power = ld9040_set_power,
42680 .get_power = ld9040_get_power,
42681 };
42682 diff -urNp linux-2.6.39.2/drivers/video/backlight/lms283gf05.c linux-2.6.39.2/drivers/video/backlight/lms283gf05.c
42683 --- linux-2.6.39.2/drivers/video/backlight/lms283gf05.c 2011-05-19 00:06:34.000000000 -0400
42684 +++ linux-2.6.39.2/drivers/video/backlight/lms283gf05.c 2011-05-22 19:36:32.000000000 -0400
42685 @@ -144,7 +144,7 @@ static int lms283gf05_power_set(struct l
42686 return 0;
42687 }
42688
42689 -static struct lcd_ops lms_ops = {
42690 +static const struct lcd_ops lms_ops = {
42691 .set_power = lms283gf05_power_set,
42692 .get_power = NULL,
42693 };
42694 diff -urNp linux-2.6.39.2/drivers/video/backlight/ltv350qv.c linux-2.6.39.2/drivers/video/backlight/ltv350qv.c
42695 --- linux-2.6.39.2/drivers/video/backlight/ltv350qv.c 2011-05-19 00:06:34.000000000 -0400
42696 +++ linux-2.6.39.2/drivers/video/backlight/ltv350qv.c 2011-05-22 19:36:32.000000000 -0400
42697 @@ -221,7 +221,7 @@ static int ltv350qv_get_power(struct lcd
42698 return lcd->power;
42699 }
42700
42701 -static struct lcd_ops ltv_ops = {
42702 +static const struct lcd_ops ltv_ops = {
42703 .get_power = ltv350qv_get_power,
42704 .set_power = ltv350qv_set_power,
42705 };
42706 diff -urNp linux-2.6.39.2/drivers/video/backlight/platform_lcd.c linux-2.6.39.2/drivers/video/backlight/platform_lcd.c
42707 --- linux-2.6.39.2/drivers/video/backlight/platform_lcd.c 2011-05-19 00:06:34.000000000 -0400
42708 +++ linux-2.6.39.2/drivers/video/backlight/platform_lcd.c 2011-05-22 19:36:32.000000000 -0400
42709 @@ -66,7 +66,7 @@ static int platform_lcd_match(struct lcd
42710 return plcd->us->parent == info->device;
42711 }
42712
42713 -static struct lcd_ops platform_lcd_ops = {
42714 +static const struct lcd_ops platform_lcd_ops = {
42715 .get_power = platform_lcd_get_power,
42716 .set_power = platform_lcd_set_power,
42717 .check_fb = platform_lcd_match,
42718 diff -urNp linux-2.6.39.2/drivers/video/backlight/s6e63m0.c linux-2.6.39.2/drivers/video/backlight/s6e63m0.c
42719 --- linux-2.6.39.2/drivers/video/backlight/s6e63m0.c 2011-05-19 00:06:34.000000000 -0400
42720 +++ linux-2.6.39.2/drivers/video/backlight/s6e63m0.c 2011-05-22 19:36:32.000000000 -0400
42721 @@ -644,7 +644,7 @@ static int s6e63m0_set_brightness(struct
42722 return ret;
42723 }
42724
42725 -static struct lcd_ops s6e63m0_lcd_ops = {
42726 +static const struct lcd_ops s6e63m0_lcd_ops = {
42727 .set_power = s6e63m0_set_power,
42728 .get_power = s6e63m0_get_power,
42729 };
42730 diff -urNp linux-2.6.39.2/drivers/video/backlight/tdo24m.c linux-2.6.39.2/drivers/video/backlight/tdo24m.c
42731 --- linux-2.6.39.2/drivers/video/backlight/tdo24m.c 2011-05-19 00:06:34.000000000 -0400
42732 +++ linux-2.6.39.2/drivers/video/backlight/tdo24m.c 2011-05-22 19:36:32.000000000 -0400
42733 @@ -322,7 +322,7 @@ static int tdo24m_set_mode(struct lcd_de
42734 return lcd->adj_mode(lcd, mode);
42735 }
42736
42737 -static struct lcd_ops tdo24m_ops = {
42738 +static const struct lcd_ops tdo24m_ops = {
42739 .get_power = tdo24m_get_power,
42740 .set_power = tdo24m_set_power,
42741 .set_mode = tdo24m_set_mode,
42742 diff -urNp linux-2.6.39.2/drivers/video/backlight/tosa_lcd.c linux-2.6.39.2/drivers/video/backlight/tosa_lcd.c
42743 --- linux-2.6.39.2/drivers/video/backlight/tosa_lcd.c 2011-05-19 00:06:34.000000000 -0400
42744 +++ linux-2.6.39.2/drivers/video/backlight/tosa_lcd.c 2011-05-22 19:36:32.000000000 -0400
42745 @@ -163,7 +163,7 @@ static int tosa_lcd_set_mode(struct lcd_
42746 return 0;
42747 }
42748
42749 -static struct lcd_ops tosa_lcd_ops = {
42750 +static const struct lcd_ops tosa_lcd_ops = {
42751 .set_power = tosa_lcd_set_power,
42752 .get_power = tosa_lcd_get_power,
42753 .set_mode = tosa_lcd_set_mode,
42754 diff -urNp linux-2.6.39.2/drivers/video/bf537-lq035.c linux-2.6.39.2/drivers/video/bf537-lq035.c
42755 --- linux-2.6.39.2/drivers/video/bf537-lq035.c 2011-05-19 00:06:34.000000000 -0400
42756 +++ linux-2.6.39.2/drivers/video/bf537-lq035.c 2011-05-22 19:36:32.000000000 -0400
42757 @@ -682,7 +682,7 @@ static int bfin_lcd_check_fb(struct lcd_
42758 return 0;
42759 }
42760
42761 -static struct lcd_ops bfin_lcd_ops = {
42762 +static const struct lcd_ops bfin_lcd_ops = {
42763 .get_power = bfin_lcd_get_power,
42764 .set_power = bfin_lcd_set_power,
42765 .get_contrast = bfin_lcd_get_contrast,
42766 diff -urNp linux-2.6.39.2/drivers/video/bf54x-lq043fb.c linux-2.6.39.2/drivers/video/bf54x-lq043fb.c
42767 --- linux-2.6.39.2/drivers/video/bf54x-lq043fb.c 2011-05-19 00:06:34.000000000 -0400
42768 +++ linux-2.6.39.2/drivers/video/bf54x-lq043fb.c 2011-05-22 19:36:32.000000000 -0400
42769 @@ -467,7 +467,7 @@ static int bfin_lcd_check_fb(struct lcd_
42770 return 0;
42771 }
42772
42773 -static struct lcd_ops bfin_lcd_ops = {
42774 +static const struct lcd_ops bfin_lcd_ops = {
42775 .get_power = bfin_lcd_get_power,
42776 .set_power = bfin_lcd_set_power,
42777 .get_contrast = bfin_lcd_get_contrast,
42778 diff -urNp linux-2.6.39.2/drivers/video/bfin-t350mcqb-fb.c linux-2.6.39.2/drivers/video/bfin-t350mcqb-fb.c
42779 --- linux-2.6.39.2/drivers/video/bfin-t350mcqb-fb.c 2011-05-19 00:06:34.000000000 -0400
42780 +++ linux-2.6.39.2/drivers/video/bfin-t350mcqb-fb.c 2011-05-22 19:36:32.000000000 -0400
42781 @@ -387,7 +387,7 @@ static int bfin_lcd_check_fb(struct lcd_
42782 return 0;
42783 }
42784
42785 -static struct lcd_ops bfin_lcd_ops = {
42786 +static const struct lcd_ops bfin_lcd_ops = {
42787 .get_power = bfin_lcd_get_power,
42788 .set_power = bfin_lcd_set_power,
42789 .get_contrast = bfin_lcd_get_contrast,
42790 diff -urNp linux-2.6.39.2/drivers/video/fbcmap.c linux-2.6.39.2/drivers/video/fbcmap.c
42791 --- linux-2.6.39.2/drivers/video/fbcmap.c 2011-05-19 00:06:34.000000000 -0400
42792 +++ linux-2.6.39.2/drivers/video/fbcmap.c 2011-05-22 19:36:32.000000000 -0400
42793 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user
42794 rc = -ENODEV;
42795 goto out;
42796 }
42797 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42798 - !info->fbops->fb_setcmap)) {
42799 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42800 rc = -EINVAL;
42801 goto out1;
42802 }
42803 diff -urNp linux-2.6.39.2/drivers/video/fbmem.c linux-2.6.39.2/drivers/video/fbmem.c
42804 --- linux-2.6.39.2/drivers/video/fbmem.c 2011-05-19 00:06:34.000000000 -0400
42805 +++ linux-2.6.39.2/drivers/video/fbmem.c 2011-05-22 19:36:32.000000000 -0400
42806 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_in
42807 image->dx += image->width + 8;
42808 }
42809 } else if (rotate == FB_ROTATE_UD) {
42810 - for (x = 0; x < num && image->dx >= 0; x++) {
42811 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42812 info->fbops->fb_imageblit(info, image);
42813 image->dx -= image->width + 8;
42814 }
42815 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_in
42816 image->dy += image->height + 8;
42817 }
42818 } else if (rotate == FB_ROTATE_CCW) {
42819 - for (x = 0; x < num && image->dy >= 0; x++) {
42820 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42821 info->fbops->fb_imageblit(info, image);
42822 image->dy -= image->height + 8;
42823 }
42824 @@ -939,6 +939,8 @@ fb_set_var(struct fb_info *info, struct
42825 int flags = info->flags;
42826 int ret = 0;
42827
42828 + pax_track_stack();
42829 +
42830 if (var->activate & FB_ACTIVATE_INV_MODE) {
42831 struct fb_videomode mode1, mode2;
42832
42833 @@ -1064,6 +1066,8 @@ static long do_fb_ioctl(struct fb_info *
42834 void __user *argp = (void __user *)arg;
42835 long ret = 0;
42836
42837 + pax_track_stack();
42838 +
42839 switch (cmd) {
42840 case FBIOGET_VSCREENINFO:
42841 if (!lock_fb_info(info))
42842 @@ -1143,7 +1147,7 @@ static long do_fb_ioctl(struct fb_info *
42843 return -EFAULT;
42844 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42845 return -EINVAL;
42846 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42847 + if (con2fb.framebuffer >= FB_MAX)
42848 return -EINVAL;
42849 if (!registered_fb[con2fb.framebuffer])
42850 request_module("fb%d", con2fb.framebuffer);
42851 diff -urNp linux-2.6.39.2/drivers/video/geode/display_gx1.c linux-2.6.39.2/drivers/video/geode/display_gx1.c
42852 --- linux-2.6.39.2/drivers/video/geode/display_gx1.c 2011-05-19 00:06:34.000000000 -0400
42853 +++ linux-2.6.39.2/drivers/video/geode/display_gx1.c 2011-05-22 19:36:32.000000000 -0400
42854 @@ -208,7 +208,7 @@ static void gx1_set_hw_palette_reg(struc
42855 writel(val, par->dc_regs + DC_PAL_DATA);
42856 }
42857
42858 -struct geode_dc_ops gx1_dc_ops = {
42859 +const struct geode_dc_ops gx1_dc_ops = {
42860 .set_mode = gx1_set_mode,
42861 .set_palette_reg = gx1_set_hw_palette_reg,
42862 };
42863 diff -urNp linux-2.6.39.2/drivers/video/geode/display_gx1.h linux-2.6.39.2/drivers/video/geode/display_gx1.h
42864 --- linux-2.6.39.2/drivers/video/geode/display_gx1.h 2011-05-19 00:06:34.000000000 -0400
42865 +++ linux-2.6.39.2/drivers/video/geode/display_gx1.h 2011-05-22 19:36:32.000000000 -0400
42866 @@ -18,7 +18,7 @@
42867 unsigned gx1_gx_base(void);
42868 int gx1_frame_buffer_size(void);
42869
42870 -extern struct geode_dc_ops gx1_dc_ops;
42871 +extern const struct geode_dc_ops gx1_dc_ops;
42872
42873 /* GX1 configuration I/O registers */
42874
42875 diff -urNp linux-2.6.39.2/drivers/video/geode/geodefb.h linux-2.6.39.2/drivers/video/geode/geodefb.h
42876 --- linux-2.6.39.2/drivers/video/geode/geodefb.h 2011-05-19 00:06:34.000000000 -0400
42877 +++ linux-2.6.39.2/drivers/video/geode/geodefb.h 2011-05-22 19:36:32.000000000 -0400
42878 @@ -31,8 +31,8 @@ struct geodefb_par {
42879 int panel_y;
42880 void __iomem *dc_regs;
42881 void __iomem *vid_regs;
42882 - struct geode_dc_ops *dc_ops;
42883 - struct geode_vid_ops *vid_ops;
42884 + const struct geode_dc_ops *dc_ops;
42885 + const struct geode_vid_ops *vid_ops;
42886 };
42887
42888 #endif /* !__GEODEFB_H__ */
42889 diff -urNp linux-2.6.39.2/drivers/video/geode/video_cs5530.c linux-2.6.39.2/drivers/video/geode/video_cs5530.c
42890 --- linux-2.6.39.2/drivers/video/geode/video_cs5530.c 2011-05-19 00:06:34.000000000 -0400
42891 +++ linux-2.6.39.2/drivers/video/geode/video_cs5530.c 2011-05-22 19:36:32.000000000 -0400
42892 @@ -186,7 +186,7 @@ static int cs5530_blank_display(struct f
42893 return 0;
42894 }
42895
42896 -struct geode_vid_ops cs5530_vid_ops = {
42897 +const struct geode_vid_ops cs5530_vid_ops = {
42898 .set_dclk = cs5530_set_dclk_frequency,
42899 .configure_display = cs5530_configure_display,
42900 .blank_display = cs5530_blank_display,
42901 diff -urNp linux-2.6.39.2/drivers/video/geode/video_cs5530.h linux-2.6.39.2/drivers/video/geode/video_cs5530.h
42902 --- linux-2.6.39.2/drivers/video/geode/video_cs5530.h 2011-05-19 00:06:34.000000000 -0400
42903 +++ linux-2.6.39.2/drivers/video/geode/video_cs5530.h 2011-05-22 19:36:32.000000000 -0400
42904 @@ -15,7 +15,7 @@
42905 #ifndef __VIDEO_CS5530_H__
42906 #define __VIDEO_CS5530_H__
42907
42908 -extern struct geode_vid_ops cs5530_vid_ops;
42909 +extern const struct geode_vid_ops cs5530_vid_ops;
42910
42911 /* CS5530 Video device registers */
42912
42913 diff -urNp linux-2.6.39.2/drivers/video/i810/i810_accel.c linux-2.6.39.2/drivers/video/i810/i810_accel.c
42914 --- linux-2.6.39.2/drivers/video/i810/i810_accel.c 2011-05-19 00:06:34.000000000 -0400
42915 +++ linux-2.6.39.2/drivers/video/i810/i810_accel.c 2011-05-22 19:36:32.000000000 -0400
42916 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct
42917 }
42918 }
42919 printk("ringbuffer lockup!!!\n");
42920 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42921 i810_report_error(mmio);
42922 par->dev_flags |= LOCKUP;
42923 info->pixmap.scan_align = 1;
42924 diff -urNp linux-2.6.39.2/drivers/video/matrox/matroxfb_base.c linux-2.6.39.2/drivers/video/matrox/matroxfb_base.c
42925 --- linux-2.6.39.2/drivers/video/matrox/matroxfb_base.c 2011-05-19 00:06:34.000000000 -0400
42926 +++ linux-2.6.39.2/drivers/video/matrox/matroxfb_base.c 2011-05-22 19:36:32.000000000 -0400
42927 @@ -1232,7 +1232,7 @@ static struct fb_ops matroxfb_ops = {
42928 #define RSText 0x7
42929 #define RSText8 0x8
42930 /* 9-F */
42931 -static struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42932 +static const struct { struct fb_bitfield red, green, blue, transp; int bits_per_pixel; } colors[] = {
42933 { { 0, 8, 0}, { 0, 8, 0}, { 0, 8, 0}, { 0, 0, 0}, 8 },
42934 { { 10, 5, 0}, { 5, 5, 0}, { 0, 5, 0}, { 15, 1, 0}, 16 },
42935 { { 11, 5, 0}, { 5, 6, 0}, { 0, 5, 0}, { 0, 0, 0}, 16 },
42936 diff -urNp linux-2.6.39.2/drivers/video/omap/lcd_ams_delta.c linux-2.6.39.2/drivers/video/omap/lcd_ams_delta.c
42937 --- linux-2.6.39.2/drivers/video/omap/lcd_ams_delta.c 2011-05-19 00:06:34.000000000 -0400
42938 +++ linux-2.6.39.2/drivers/video/omap/lcd_ams_delta.c 2011-05-22 19:36:32.000000000 -0400
42939 @@ -87,7 +87,7 @@ static int ams_delta_lcd_get_contrast(st
42940 return ams_delta_lcd & AMS_DELTA_MAX_CONTRAST;
42941 }
42942
42943 -static struct lcd_ops ams_delta_lcd_ops = {
42944 +static const struct lcd_ops ams_delta_lcd_ops = {
42945 .get_power = ams_delta_lcd_get_power,
42946 .set_power = ams_delta_lcd_set_power,
42947 .get_contrast = ams_delta_lcd_get_contrast,
42948 diff -urNp linux-2.6.39.2/drivers/video/pxa3xx-gcu.c linux-2.6.39.2/drivers/video/pxa3xx-gcu.c
42949 --- linux-2.6.39.2/drivers/video/pxa3xx-gcu.c 2011-05-19 00:06:34.000000000 -0400
42950 +++ linux-2.6.39.2/drivers/video/pxa3xx-gcu.c 2011-05-22 19:36:32.000000000 -0400
42951 @@ -103,7 +103,7 @@ struct pxa3xx_gcu_priv {
42952 dma_addr_t shared_phys;
42953 struct resource *resource_mem;
42954 struct miscdevice misc_dev;
42955 - struct file_operations misc_fops;
42956 + const struct file_operations misc_fops;
42957 wait_queue_head_t wait_idle;
42958 wait_queue_head_t wait_free;
42959 spinlock_t spinlock;
42960 diff -urNp linux-2.6.39.2/drivers/video/sh_mobile_lcdcfb.c linux-2.6.39.2/drivers/video/sh_mobile_lcdcfb.c
42961 --- linux-2.6.39.2/drivers/video/sh_mobile_lcdcfb.c 2011-05-19 00:06:34.000000000 -0400
42962 +++ linux-2.6.39.2/drivers/video/sh_mobile_lcdcfb.c 2011-05-22 19:36:32.000000000 -0400
42963 @@ -245,7 +245,7 @@ static unsigned long lcdc_sys_read_data(
42964 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
42965 }
42966
42967 -struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42968 +const struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
42969 lcdc_sys_write_index,
42970 lcdc_sys_write_data,
42971 lcdc_sys_read_data,
42972 diff -urNp linux-2.6.39.2/drivers/video/udlfb.c linux-2.6.39.2/drivers/video/udlfb.c
42973 --- linux-2.6.39.2/drivers/video/udlfb.c 2011-05-19 00:06:34.000000000 -0400
42974 +++ linux-2.6.39.2/drivers/video/udlfb.c 2011-05-22 19:36:32.000000000 -0400
42975 @@ -584,11 +584,11 @@ int dlfb_handle_damage(struct dlfb_data
42976 dlfb_urb_completion(urb);
42977
42978 error:
42979 - atomic_add(bytes_sent, &dev->bytes_sent);
42980 - atomic_add(bytes_identical, &dev->bytes_identical);
42981 - atomic_add(width*height*2, &dev->bytes_rendered);
42982 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42983 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42984 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42985 end_cycles = get_cycles();
42986 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42987 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42988 >> 10)), /* Kcycles */
42989 &dev->cpu_kcycles_used);
42990
42991 @@ -709,11 +709,11 @@ static void dlfb_dpy_deferred_io(struct
42992 dlfb_urb_completion(urb);
42993
42994 error:
42995 - atomic_add(bytes_sent, &dev->bytes_sent);
42996 - atomic_add(bytes_identical, &dev->bytes_identical);
42997 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42998 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42999 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43000 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43001 end_cycles = get_cycles();
43002 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
43003 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43004 >> 10)), /* Kcycles */
43005 &dev->cpu_kcycles_used);
43006 }
43007 @@ -1301,7 +1301,7 @@ static ssize_t metrics_bytes_rendered_sh
43008 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43009 struct dlfb_data *dev = fb_info->par;
43010 return snprintf(buf, PAGE_SIZE, "%u\n",
43011 - atomic_read(&dev->bytes_rendered));
43012 + atomic_read_unchecked(&dev->bytes_rendered));
43013 }
43014
43015 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43016 @@ -1309,7 +1309,7 @@ static ssize_t metrics_bytes_identical_s
43017 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43018 struct dlfb_data *dev = fb_info->par;
43019 return snprintf(buf, PAGE_SIZE, "%u\n",
43020 - atomic_read(&dev->bytes_identical));
43021 + atomic_read_unchecked(&dev->bytes_identical));
43022 }
43023
43024 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43025 @@ -1317,7 +1317,7 @@ static ssize_t metrics_bytes_sent_show(s
43026 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43027 struct dlfb_data *dev = fb_info->par;
43028 return snprintf(buf, PAGE_SIZE, "%u\n",
43029 - atomic_read(&dev->bytes_sent));
43030 + atomic_read_unchecked(&dev->bytes_sent));
43031 }
43032
43033 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43034 @@ -1325,7 +1325,7 @@ static ssize_t metrics_cpu_kcycles_used_
43035 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43036 struct dlfb_data *dev = fb_info->par;
43037 return snprintf(buf, PAGE_SIZE, "%u\n",
43038 - atomic_read(&dev->cpu_kcycles_used));
43039 + atomic_read_unchecked(&dev->cpu_kcycles_used));
43040 }
43041
43042 static ssize_t edid_show(
43043 @@ -1382,10 +1382,10 @@ static ssize_t metrics_reset_store(struc
43044 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43045 struct dlfb_data *dev = fb_info->par;
43046
43047 - atomic_set(&dev->bytes_rendered, 0);
43048 - atomic_set(&dev->bytes_identical, 0);
43049 - atomic_set(&dev->bytes_sent, 0);
43050 - atomic_set(&dev->cpu_kcycles_used, 0);
43051 + atomic_set_unchecked(&dev->bytes_rendered, 0);
43052 + atomic_set_unchecked(&dev->bytes_identical, 0);
43053 + atomic_set_unchecked(&dev->bytes_sent, 0);
43054 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43055
43056 return count;
43057 }
43058 diff -urNp linux-2.6.39.2/drivers/video/uvesafb.c linux-2.6.39.2/drivers/video/uvesafb.c
43059 --- linux-2.6.39.2/drivers/video/uvesafb.c 2011-05-19 00:06:34.000000000 -0400
43060 +++ linux-2.6.39.2/drivers/video/uvesafb.c 2011-05-22 19:36:32.000000000 -0400
43061 @@ -19,6 +19,7 @@
43062 #include <linux/io.h>
43063 #include <linux/mutex.h>
43064 #include <linux/slab.h>
43065 +#include <linux/moduleloader.h>
43066 #include <video/edid.h>
43067 #include <video/uvesafb.h>
43068 #ifdef CONFIG_X86
43069 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
43070 NULL,
43071 };
43072
43073 - return call_usermodehelper(v86d_path, argv, envp, 1);
43074 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
43075 }
43076
43077 /*
43078 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(
43079 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43080 par->pmi_setpal = par->ypan = 0;
43081 } else {
43082 +
43083 +#ifdef CONFIG_PAX_KERNEXEC
43084 +#ifdef CONFIG_MODULES
43085 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43086 +#endif
43087 + if (!par->pmi_code) {
43088 + par->pmi_setpal = par->ypan = 0;
43089 + return 0;
43090 + }
43091 +#endif
43092 +
43093 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43094 + task->t.regs.edi);
43095 +
43096 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43097 + pax_open_kernel();
43098 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43099 + pax_close_kernel();
43100 +
43101 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43102 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43103 +#else
43104 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43105 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43106 +#endif
43107 +
43108 printk(KERN_INFO "uvesafb: protected mode interface info at "
43109 "%04x:%04x\n",
43110 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43111 @@ -1821,6 +1844,11 @@ out:
43112 if (par->vbe_modes)
43113 kfree(par->vbe_modes);
43114
43115 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43116 + if (par->pmi_code)
43117 + module_free_exec(NULL, par->pmi_code);
43118 +#endif
43119 +
43120 framebuffer_release(info);
43121 return err;
43122 }
43123 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platfor
43124 kfree(par->vbe_state_orig);
43125 if (par->vbe_state_saved)
43126 kfree(par->vbe_state_saved);
43127 +
43128 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43129 + if (par->pmi_code)
43130 + module_free_exec(NULL, par->pmi_code);
43131 +#endif
43132 +
43133 }
43134
43135 framebuffer_release(info);
43136 @@ -2013,7 +2047,7 @@ static int param_set_scroll(const char *
43137
43138 return 0;
43139 }
43140 -static struct kernel_param_ops param_ops_scroll = {
43141 +static const struct kernel_param_ops param_ops_scroll = {
43142 .set = param_set_scroll,
43143 };
43144 #define param_check_scroll(name, p) __param_check(name, p, void)
43145 diff -urNp linux-2.6.39.2/drivers/video/vesafb.c linux-2.6.39.2/drivers/video/vesafb.c
43146 --- linux-2.6.39.2/drivers/video/vesafb.c 2011-05-19 00:06:34.000000000 -0400
43147 +++ linux-2.6.39.2/drivers/video/vesafb.c 2011-05-22 19:36:32.000000000 -0400
43148 @@ -9,6 +9,7 @@
43149 */
43150
43151 #include <linux/module.h>
43152 +#include <linux/moduleloader.h>
43153 #include <linux/kernel.h>
43154 #include <linux/errno.h>
43155 #include <linux/string.h>
43156 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /*
43157 static int vram_total __initdata; /* Set total amount of memory */
43158 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43159 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43160 -static void (*pmi_start)(void) __read_mostly;
43161 -static void (*pmi_pal) (void) __read_mostly;
43162 +static void (*pmi_start)(void) __read_only;
43163 +static void (*pmi_pal) (void) __read_only;
43164 static int depth __read_mostly;
43165 static int vga_compat __read_mostly;
43166 /* --------------------------------------------------------------------- */
43167 @@ -232,6 +233,7 @@ static int __init vesafb_probe(struct pl
43168 unsigned int size_vmode;
43169 unsigned int size_remap;
43170 unsigned int size_total;
43171 + void *pmi_code = NULL;
43172
43173 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43174 return -ENODEV;
43175 @@ -274,10 +276,6 @@ static int __init vesafb_probe(struct pl
43176 size_remap = size_total;
43177 vesafb_fix.smem_len = size_remap;
43178
43179 -#ifndef __i386__
43180 - screen_info.vesapm_seg = 0;
43181 -#endif
43182 -
43183 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43184 printk(KERN_WARNING
43185 "vesafb: cannot reserve video memory at 0x%lx\n",
43186 @@ -306,9 +304,21 @@ static int __init vesafb_probe(struct pl
43187 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43188 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43189
43190 +#ifdef __i386__
43191 +
43192 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43193 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
43194 + if (!pmi_code)
43195 +#elif !defined(CONFIG_PAX_KERNEXEC)
43196 + if (0)
43197 +#endif
43198 +
43199 +#endif
43200 + screen_info.vesapm_seg = 0;
43201 +
43202 if (screen_info.vesapm_seg) {
43203 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43204 - screen_info.vesapm_seg,screen_info.vesapm_off);
43205 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43206 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43207 }
43208
43209 if (screen_info.vesapm_seg < 0xc000)
43210 @@ -316,9 +326,25 @@ static int __init vesafb_probe(struct pl
43211
43212 if (ypan || pmi_setpal) {
43213 unsigned short *pmi_base;
43214 - pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43215 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43216 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43217 +
43218 + pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43219 +
43220 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43221 + pax_open_kernel();
43222 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43223 +#else
43224 + pmi_code = pmi_base;
43225 +#endif
43226 +
43227 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43228 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43229 +
43230 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43231 + pmi_start = ktva_ktla(pmi_start);
43232 + pmi_pal = ktva_ktla(pmi_pal);
43233 + pax_close_kernel();
43234 +#endif
43235 +
43236 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43237 if (pmi_base[3]) {
43238 printk(KERN_INFO "vesafb: pmi: ports = ");
43239 @@ -487,6 +513,11 @@ static int __init vesafb_probe(struct pl
43240 info->node, info->fix.id);
43241 return 0;
43242 err:
43243 +
43244 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43245 + module_free_exec(NULL, pmi_code);
43246 +#endif
43247 +
43248 if (info->screen_base)
43249 iounmap(info->screen_base);
43250 framebuffer_release(info);
43251 diff -urNp linux-2.6.39.2/drivers/virtio/virtio_balloon.c linux-2.6.39.2/drivers/virtio/virtio_balloon.c
43252 --- linux-2.6.39.2/drivers/virtio/virtio_balloon.c 2011-05-19 00:06:34.000000000 -0400
43253 +++ linux-2.6.39.2/drivers/virtio/virtio_balloon.c 2011-05-22 19:36:32.000000000 -0400
43254 @@ -176,6 +176,8 @@ static void update_balloon_stats(struct
43255 struct sysinfo i;
43256 int idx = 0;
43257
43258 + pax_track_stack();
43259 +
43260 all_vm_events(events);
43261 si_meminfo(&i);
43262
43263 diff -urNp linux-2.6.39.2/drivers/xen/gntalloc.c linux-2.6.39.2/drivers/xen/gntalloc.c
43264 --- linux-2.6.39.2/drivers/xen/gntalloc.c 2011-05-19 00:06:34.000000000 -0400
43265 +++ linux-2.6.39.2/drivers/xen/gntalloc.c 2011-05-22 19:36:32.000000000 -0400
43266 @@ -440,7 +440,7 @@ static void gntalloc_vma_close(struct vm
43267 spin_unlock(&gref_lock);
43268 }
43269
43270 -static struct vm_operations_struct gntalloc_vmops = {
43271 +static const struct vm_operations_struct gntalloc_vmops = {
43272 .close = gntalloc_vma_close,
43273 };
43274
43275 diff -urNp linux-2.6.39.2/drivers/xen/gntdev.c linux-2.6.39.2/drivers/xen/gntdev.c
43276 --- linux-2.6.39.2/drivers/xen/gntdev.c 2011-05-19 00:06:34.000000000 -0400
43277 +++ linux-2.6.39.2/drivers/xen/gntdev.c 2011-05-22 19:36:32.000000000 -0400
43278 @@ -340,7 +340,7 @@ static void gntdev_vma_close(struct vm_a
43279 gntdev_put_map(map);
43280 }
43281
43282 -static struct vm_operations_struct gntdev_vmops = {
43283 +static const struct vm_operations_struct gntdev_vmops = {
43284 .close = gntdev_vma_close,
43285 };
43286
43287 @@ -404,7 +404,7 @@ static void mn_release(struct mmu_notifi
43288 spin_unlock(&priv->lock);
43289 }
43290
43291 -struct mmu_notifier_ops gntdev_mmu_ops = {
43292 +const struct mmu_notifier_ops gntdev_mmu_ops = {
43293 .release = mn_release,
43294 .invalidate_page = mn_invl_page,
43295 .invalidate_range_start = mn_invl_range_start,
43296 diff -urNp linux-2.6.39.2/drivers/xen/xenfs/privcmd.c linux-2.6.39.2/drivers/xen/xenfs/privcmd.c
43297 --- linux-2.6.39.2/drivers/xen/xenfs/privcmd.c 2011-05-19 00:06:34.000000000 -0400
43298 +++ linux-2.6.39.2/drivers/xen/xenfs/privcmd.c 2011-05-22 19:36:32.000000000 -0400
43299 @@ -268,7 +268,7 @@ static int mmap_return_errors(void *data
43300 return put_user(*mfnp, st->user++);
43301 }
43302
43303 -static struct vm_operations_struct privcmd_vm_ops;
43304 +static const struct vm_operations_struct privcmd_vm_ops;
43305
43306 static long privcmd_ioctl_mmap_batch(void __user *udata)
43307 {
43308 @@ -369,7 +369,7 @@ static int privcmd_fault(struct vm_area_
43309 return VM_FAULT_SIGBUS;
43310 }
43311
43312 -static struct vm_operations_struct privcmd_vm_ops = {
43313 +static const struct vm_operations_struct privcmd_vm_ops = {
43314 .fault = privcmd_fault
43315 };
43316
43317 diff -urNp linux-2.6.39.2/fs/9p/vfs_inode.c linux-2.6.39.2/fs/9p/vfs_inode.c
43318 --- linux-2.6.39.2/fs/9p/vfs_inode.c 2011-05-19 00:06:34.000000000 -0400
43319 +++ linux-2.6.39.2/fs/9p/vfs_inode.c 2011-05-22 19:36:32.000000000 -0400
43320 @@ -1210,7 +1210,7 @@ static void *v9fs_vfs_follow_link(struct
43321 void
43322 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
43323 {
43324 - char *s = nd_get_link(nd);
43325 + const char *s = nd_get_link(nd);
43326
43327 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
43328 IS_ERR(s) ? "<error>" : s);
43329 diff -urNp linux-2.6.39.2/fs/aio.c linux-2.6.39.2/fs/aio.c
43330 --- linux-2.6.39.2/fs/aio.c 2011-05-19 00:06:34.000000000 -0400
43331 +++ linux-2.6.39.2/fs/aio.c 2011-06-03 01:00:34.000000000 -0400
43332 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx
43333 size += sizeof(struct io_event) * nr_events;
43334 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
43335
43336 - if (nr_pages < 0)
43337 + if (nr_pages <= 0)
43338 return -EINVAL;
43339
43340 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
43341 @@ -1088,6 +1088,8 @@ static int read_events(struct kioctx *ct
43342 struct aio_timeout to;
43343 int retry = 0;
43344
43345 + pax_track_stack();
43346 +
43347 /* needed to zero any padding within an entry (there shouldn't be
43348 * any, but C is fun!
43349 */
43350 @@ -1381,22 +1383,27 @@ static ssize_t aio_fsync(struct kiocb *i
43351 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
43352 {
43353 ssize_t ret;
43354 + struct iovec iovstack;
43355
43356 #ifdef CONFIG_COMPAT
43357 if (compat)
43358 ret = compat_rw_copy_check_uvector(type,
43359 (struct compat_iovec __user *)kiocb->ki_buf,
43360 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43361 + kiocb->ki_nbytes, 1, &iovstack,
43362 &kiocb->ki_iovec);
43363 else
43364 #endif
43365 ret = rw_copy_check_uvector(type,
43366 (struct iovec __user *)kiocb->ki_buf,
43367 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
43368 + kiocb->ki_nbytes, 1, &iovstack,
43369 &kiocb->ki_iovec);
43370 if (ret < 0)
43371 goto out;
43372
43373 + if (kiocb->ki_iovec == &iovstack) {
43374 + kiocb->ki_inline_vec = iovstack;
43375 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
43376 + }
43377 kiocb->ki_nr_segs = kiocb->ki_nbytes;
43378 kiocb->ki_cur_seg = 0;
43379 /* ki_nbytes/left now reflect bytes instead of segs */
43380 diff -urNp linux-2.6.39.2/fs/attr.c linux-2.6.39.2/fs/attr.c
43381 --- linux-2.6.39.2/fs/attr.c 2011-05-19 00:06:34.000000000 -0400
43382 +++ linux-2.6.39.2/fs/attr.c 2011-05-22 19:41:37.000000000 -0400
43383 @@ -98,6 +98,7 @@ int inode_newsize_ok(const struct inode
43384 unsigned long limit;
43385
43386 limit = rlimit(RLIMIT_FSIZE);
43387 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
43388 if (limit != RLIM_INFINITY && offset > limit)
43389 goto out_sig;
43390 if (offset > inode->i_sb->s_maxbytes)
43391 diff -urNp linux-2.6.39.2/fs/befs/linuxvfs.c linux-2.6.39.2/fs/befs/linuxvfs.c
43392 --- linux-2.6.39.2/fs/befs/linuxvfs.c 2011-05-19 00:06:34.000000000 -0400
43393 +++ linux-2.6.39.2/fs/befs/linuxvfs.c 2011-05-22 19:36:32.000000000 -0400
43394 @@ -498,7 +498,7 @@ static void befs_put_link(struct dentry
43395 {
43396 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
43397 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
43398 - char *link = nd_get_link(nd);
43399 + const char *link = nd_get_link(nd);
43400 if (!IS_ERR(link))
43401 kfree(link);
43402 }
43403 diff -urNp linux-2.6.39.2/fs/binfmt_aout.c linux-2.6.39.2/fs/binfmt_aout.c
43404 --- linux-2.6.39.2/fs/binfmt_aout.c 2011-05-19 00:06:34.000000000 -0400
43405 +++ linux-2.6.39.2/fs/binfmt_aout.c 2011-05-22 19:41:37.000000000 -0400
43406 @@ -16,6 +16,7 @@
43407 #include <linux/string.h>
43408 #include <linux/fs.h>
43409 #include <linux/file.h>
43410 +#include <linux/security.h>
43411 #include <linux/stat.h>
43412 #include <linux/fcntl.h>
43413 #include <linux/ptrace.h>
43414 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredum
43415 #endif
43416 # define START_STACK(u) ((void __user *)u.start_stack)
43417
43418 + memset(&dump, 0, sizeof(dump));
43419 +
43420 fs = get_fs();
43421 set_fs(KERNEL_DS);
43422 has_dumped = 1;
43423 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredum
43424
43425 /* If the size of the dump file exceeds the rlimit, then see what would happen
43426 if we wrote the stack, but not the data area. */
43427 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
43428 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
43429 dump.u_dsize = 0;
43430
43431 /* Make sure we have enough room to write the stack and data areas. */
43432 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
43433 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
43434 dump.u_ssize = 0;
43435
43436 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux
43437 rlim = rlimit(RLIMIT_DATA);
43438 if (rlim >= RLIM_INFINITY)
43439 rlim = ~0;
43440 +
43441 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
43442 if (ex.a_data + ex.a_bss > rlim)
43443 return -ENOMEM;
43444
43445 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux
43446 install_exec_creds(bprm);
43447 current->flags &= ~PF_FORKNOEXEC;
43448
43449 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43450 + current->mm->pax_flags = 0UL;
43451 +#endif
43452 +
43453 +#ifdef CONFIG_PAX_PAGEEXEC
43454 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
43455 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
43456 +
43457 +#ifdef CONFIG_PAX_EMUTRAMP
43458 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
43459 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
43460 +#endif
43461 +
43462 +#ifdef CONFIG_PAX_MPROTECT
43463 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
43464 + current->mm->pax_flags |= MF_PAX_MPROTECT;
43465 +#endif
43466 +
43467 + }
43468 +#endif
43469 +
43470 if (N_MAGIC(ex) == OMAGIC) {
43471 unsigned long text_addr, map_size;
43472 loff_t pos;
43473 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux
43474
43475 down_write(&current->mm->mmap_sem);
43476 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
43477 - PROT_READ | PROT_WRITE | PROT_EXEC,
43478 + PROT_READ | PROT_WRITE,
43479 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
43480 fd_offset + ex.a_text);
43481 up_write(&current->mm->mmap_sem);
43482 diff -urNp linux-2.6.39.2/fs/binfmt_elf.c linux-2.6.39.2/fs/binfmt_elf.c
43483 --- linux-2.6.39.2/fs/binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
43484 +++ linux-2.6.39.2/fs/binfmt_elf.c 2011-05-22 19:41:37.000000000 -0400
43485 @@ -51,6 +51,10 @@ static int elf_core_dump(struct coredump
43486 #define elf_core_dump NULL
43487 #endif
43488
43489 +#ifdef CONFIG_PAX_MPROTECT
43490 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43491 +#endif
43492 +
43493 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43494 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43495 #else
43496 @@ -70,6 +74,11 @@ static struct linux_binfmt elf_format =
43497 .load_binary = load_elf_binary,
43498 .load_shlib = load_elf_library,
43499 .core_dump = elf_core_dump,
43500 +
43501 +#ifdef CONFIG_PAX_MPROTECT
43502 + .handle_mprotect= elf_handle_mprotect,
43503 +#endif
43504 +
43505 .min_coredump = ELF_EXEC_PAGESIZE,
43506 };
43507
43508 @@ -77,6 +86,8 @@ static struct linux_binfmt elf_format =
43509
43510 static int set_brk(unsigned long start, unsigned long end)
43511 {
43512 + unsigned long e = end;
43513 +
43514 start = ELF_PAGEALIGN(start);
43515 end = ELF_PAGEALIGN(end);
43516 if (end > start) {
43517 @@ -87,7 +98,7 @@ static int set_brk(unsigned long start,
43518 if (BAD_ADDR(addr))
43519 return addr;
43520 }
43521 - current->mm->start_brk = current->mm->brk = end;
43522 + current->mm->start_brk = current->mm->brk = e;
43523 return 0;
43524 }
43525
43526 @@ -148,12 +159,15 @@ create_elf_tables(struct linux_binprm *b
43527 elf_addr_t __user *u_rand_bytes;
43528 const char *k_platform = ELF_PLATFORM;
43529 const char *k_base_platform = ELF_BASE_PLATFORM;
43530 - unsigned char k_rand_bytes[16];
43531 + u32 k_rand_bytes[4];
43532 int items;
43533 elf_addr_t *elf_info;
43534 int ei_index = 0;
43535 const struct cred *cred = current_cred();
43536 struct vm_area_struct *vma;
43537 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43538 +
43539 + pax_track_stack();
43540
43541 /*
43542 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43543 @@ -195,8 +209,12 @@ create_elf_tables(struct linux_binprm *b
43544 * Generate 16 random bytes for userspace PRNG seeding.
43545 */
43546 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43547 - u_rand_bytes = (elf_addr_t __user *)
43548 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43549 + srandom32(k_rand_bytes[0] ^ random32());
43550 + srandom32(k_rand_bytes[1] ^ random32());
43551 + srandom32(k_rand_bytes[2] ^ random32());
43552 + srandom32(k_rand_bytes[3] ^ random32());
43553 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43554 + u_rand_bytes = (elf_addr_t __user *) p;
43555 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43556 return -EFAULT;
43557
43558 @@ -308,9 +326,11 @@ create_elf_tables(struct linux_binprm *b
43559 return -EFAULT;
43560 current->mm->env_end = p;
43561
43562 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43563 +
43564 /* Put the elf_info on the stack in the right place. */
43565 sp = (elf_addr_t __user *)envp + 1;
43566 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43567 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43568 return -EFAULT;
43569 return 0;
43570 }
43571 @@ -381,10 +401,10 @@ static unsigned long load_elf_interp(str
43572 {
43573 struct elf_phdr *elf_phdata;
43574 struct elf_phdr *eppnt;
43575 - unsigned long load_addr = 0;
43576 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43577 int load_addr_set = 0;
43578 unsigned long last_bss = 0, elf_bss = 0;
43579 - unsigned long error = ~0UL;
43580 + unsigned long error = -EINVAL;
43581 unsigned long total_size;
43582 int retval, i, size;
43583
43584 @@ -430,6 +450,11 @@ static unsigned long load_elf_interp(str
43585 goto out_close;
43586 }
43587
43588 +#ifdef CONFIG_PAX_SEGMEXEC
43589 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43590 + pax_task_size = SEGMEXEC_TASK_SIZE;
43591 +#endif
43592 +
43593 eppnt = elf_phdata;
43594 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43595 if (eppnt->p_type == PT_LOAD) {
43596 @@ -473,8 +498,8 @@ static unsigned long load_elf_interp(str
43597 k = load_addr + eppnt->p_vaddr;
43598 if (BAD_ADDR(k) ||
43599 eppnt->p_filesz > eppnt->p_memsz ||
43600 - eppnt->p_memsz > TASK_SIZE ||
43601 - TASK_SIZE - eppnt->p_memsz < k) {
43602 + eppnt->p_memsz > pax_task_size ||
43603 + pax_task_size - eppnt->p_memsz < k) {
43604 error = -ENOMEM;
43605 goto out_close;
43606 }
43607 @@ -528,6 +553,193 @@ out:
43608 return error;
43609 }
43610
43611 +#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
43612 +static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
43613 +{
43614 + unsigned long pax_flags = 0UL;
43615 +
43616 +#ifdef CONFIG_PAX_PAGEEXEC
43617 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43618 + pax_flags |= MF_PAX_PAGEEXEC;
43619 +#endif
43620 +
43621 +#ifdef CONFIG_PAX_SEGMEXEC
43622 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43623 + pax_flags |= MF_PAX_SEGMEXEC;
43624 +#endif
43625 +
43626 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43627 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43628 + if ((__supported_pte_mask & _PAGE_NX))
43629 + pax_flags &= ~MF_PAX_SEGMEXEC;
43630 + else
43631 + pax_flags &= ~MF_PAX_PAGEEXEC;
43632 + }
43633 +#endif
43634 +
43635 +#ifdef CONFIG_PAX_EMUTRAMP
43636 + if (elf_phdata->p_flags & PF_EMUTRAMP)
43637 + pax_flags |= MF_PAX_EMUTRAMP;
43638 +#endif
43639 +
43640 +#ifdef CONFIG_PAX_MPROTECT
43641 + if (elf_phdata->p_flags & PF_MPROTECT)
43642 + pax_flags |= MF_PAX_MPROTECT;
43643 +#endif
43644 +
43645 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43646 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43647 + pax_flags |= MF_PAX_RANDMMAP;
43648 +#endif
43649 +
43650 + return pax_flags;
43651 +}
43652 +#endif
43653 +
43654 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43655 +static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
43656 +{
43657 + unsigned long pax_flags = 0UL;
43658 +
43659 +#ifdef CONFIG_PAX_PAGEEXEC
43660 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43661 + pax_flags |= MF_PAX_PAGEEXEC;
43662 +#endif
43663 +
43664 +#ifdef CONFIG_PAX_SEGMEXEC
43665 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43666 + pax_flags |= MF_PAX_SEGMEXEC;
43667 +#endif
43668 +
43669 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43670 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43671 + if ((__supported_pte_mask & _PAGE_NX))
43672 + pax_flags &= ~MF_PAX_SEGMEXEC;
43673 + else
43674 + pax_flags &= ~MF_PAX_PAGEEXEC;
43675 + }
43676 +#endif
43677 +
43678 +#ifdef CONFIG_PAX_EMUTRAMP
43679 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43680 + pax_flags |= MF_PAX_EMUTRAMP;
43681 +#endif
43682 +
43683 +#ifdef CONFIG_PAX_MPROTECT
43684 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43685 + pax_flags |= MF_PAX_MPROTECT;
43686 +#endif
43687 +
43688 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43689 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43690 + pax_flags |= MF_PAX_RANDMMAP;
43691 +#endif
43692 +
43693 + return pax_flags;
43694 +}
43695 +#endif
43696 +
43697 +#ifdef CONFIG_PAX_EI_PAX
43698 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43699 +{
43700 + unsigned long pax_flags = 0UL;
43701 +
43702 +#ifdef CONFIG_PAX_PAGEEXEC
43703 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43704 + pax_flags |= MF_PAX_PAGEEXEC;
43705 +#endif
43706 +
43707 +#ifdef CONFIG_PAX_SEGMEXEC
43708 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43709 + pax_flags |= MF_PAX_SEGMEXEC;
43710 +#endif
43711 +
43712 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43713 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43714 + if ((__supported_pte_mask & _PAGE_NX))
43715 + pax_flags &= ~MF_PAX_SEGMEXEC;
43716 + else
43717 + pax_flags &= ~MF_PAX_PAGEEXEC;
43718 + }
43719 +#endif
43720 +
43721 +#ifdef CONFIG_PAX_EMUTRAMP
43722 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43723 + pax_flags |= MF_PAX_EMUTRAMP;
43724 +#endif
43725 +
43726 +#ifdef CONFIG_PAX_MPROTECT
43727 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43728 + pax_flags |= MF_PAX_MPROTECT;
43729 +#endif
43730 +
43731 +#ifdef CONFIG_PAX_ASLR
43732 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43733 + pax_flags |= MF_PAX_RANDMMAP;
43734 +#endif
43735 +
43736 + return pax_flags;
43737 +}
43738 +#endif
43739 +
43740 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43741 +static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43742 +{
43743 + unsigned long pax_flags = 0UL;
43744 +
43745 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43746 + unsigned long i;
43747 + int found_flags = 0;
43748 +#endif
43749 +
43750 +#ifdef CONFIG_PAX_EI_PAX
43751 + pax_flags = pax_parse_ei_pax(elf_ex);
43752 +#endif
43753 +
43754 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43755 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43756 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43757 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43758 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43759 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43760 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43761 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43762 + return -EINVAL;
43763 +
43764 +#ifdef CONFIG_PAX_SOFTMODE
43765 + if (pax_softmode)
43766 + pax_flags = pax_parse_softmode(&elf_phdata[i]);
43767 + else
43768 +#endif
43769 +
43770 + pax_flags = pax_parse_hardmode(&elf_phdata[i]);
43771 + found_flags = 1;
43772 + break;
43773 + }
43774 +#endif
43775 +
43776 +#if !defined(CONFIG_PAX_EI_PAX) && defined(CONFIG_PAX_PT_PAX_FLAGS)
43777 + if (found_flags == 0) {
43778 + struct elf_phdr phdr;
43779 + memset(&phdr, 0, sizeof(phdr));
43780 + phdr.p_flags = PF_NOEMUTRAMP;
43781 +#ifdef CONFIG_PAX_SOFTMODE
43782 + if (pax_softmode)
43783 + pax_flags = pax_parse_softmode(&phdr);
43784 + else
43785 +#endif
43786 + pax_flags = pax_parse_hardmode(&phdr);
43787 + }
43788 +#endif
43789 +
43790 + if (0 > pax_check_flags(&pax_flags))
43791 + return -EINVAL;
43792 +
43793 + current->mm->pax_flags = pax_flags;
43794 + return 0;
43795 +}
43796 +#endif
43797 +
43798 /*
43799 * These are the functions used to load ELF style executables and shared
43800 * libraries. There is no binary dependent code anywhere else.
43801 @@ -544,6 +756,11 @@ static unsigned long randomize_stack_top
43802 {
43803 unsigned int random_variable = 0;
43804
43805 +#ifdef CONFIG_PAX_RANDUSTACK
43806 + if (randomize_va_space)
43807 + return stack_top - current->mm->delta_stack;
43808 +#endif
43809 +
43810 if ((current->flags & PF_RANDOMIZE) &&
43811 !(current->personality & ADDR_NO_RANDOMIZE)) {
43812 random_variable = get_random_int() & STACK_RND_MASK;
43813 @@ -562,7 +779,7 @@ static int load_elf_binary(struct linux_
43814 unsigned long load_addr = 0, load_bias = 0;
43815 int load_addr_set = 0;
43816 char * elf_interpreter = NULL;
43817 - unsigned long error;
43818 + unsigned long error = 0;
43819 struct elf_phdr *elf_ppnt, *elf_phdata;
43820 unsigned long elf_bss, elf_brk;
43821 int retval, i;
43822 @@ -572,11 +789,11 @@ static int load_elf_binary(struct linux_
43823 unsigned long start_code, end_code, start_data, end_data;
43824 unsigned long reloc_func_desc __maybe_unused = 0;
43825 int executable_stack = EXSTACK_DEFAULT;
43826 - unsigned long def_flags = 0;
43827 struct {
43828 struct elfhdr elf_ex;
43829 struct elfhdr interp_elf_ex;
43830 } *loc;
43831 + unsigned long pax_task_size = TASK_SIZE;
43832
43833 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43834 if (!loc) {
43835 @@ -714,11 +931,81 @@ static int load_elf_binary(struct linux_
43836
43837 /* OK, This is the point of no return */
43838 current->flags &= ~PF_FORKNOEXEC;
43839 - current->mm->def_flags = def_flags;
43840 +
43841 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43842 + current->mm->pax_flags = 0UL;
43843 +#endif
43844 +
43845 +#ifdef CONFIG_PAX_DLRESOLVE
43846 + current->mm->call_dl_resolve = 0UL;
43847 +#endif
43848 +
43849 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43850 + current->mm->call_syscall = 0UL;
43851 +#endif
43852 +
43853 +#ifdef CONFIG_PAX_ASLR
43854 + current->mm->delta_mmap = 0UL;
43855 + current->mm->delta_stack = 0UL;
43856 +#endif
43857 +
43858 + current->mm->def_flags = 0;
43859 +
43860 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
43861 + if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
43862 + send_sig(SIGKILL, current, 0);
43863 + goto out_free_dentry;
43864 + }
43865 +#endif
43866 +
43867 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43868 + pax_set_initial_flags(bprm);
43869 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43870 + if (pax_set_initial_flags_func)
43871 + (pax_set_initial_flags_func)(bprm);
43872 +#endif
43873 +
43874 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43875 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43876 + current->mm->context.user_cs_limit = PAGE_SIZE;
43877 + current->mm->def_flags |= VM_PAGEEXEC;
43878 + }
43879 +#endif
43880 +
43881 +#ifdef CONFIG_PAX_SEGMEXEC
43882 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43883 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43884 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43885 + pax_task_size = SEGMEXEC_TASK_SIZE;
43886 + current->mm->def_flags |= VM_NOHUGEPAGE;
43887 + }
43888 +#endif
43889 +
43890 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43891 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43892 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43893 + put_cpu();
43894 + }
43895 +#endif
43896
43897 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43898 may depend on the personality. */
43899 SET_PERSONALITY(loc->elf_ex);
43900 +
43901 +#ifdef CONFIG_PAX_ASLR
43902 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43903 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43904 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43905 + }
43906 +#endif
43907 +
43908 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43909 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43910 + executable_stack = EXSTACK_DISABLE_X;
43911 + current->personality &= ~READ_IMPLIES_EXEC;
43912 + } else
43913 +#endif
43914 +
43915 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43916 current->personality |= READ_IMPLIES_EXEC;
43917
43918 @@ -800,6 +1087,20 @@ static int load_elf_binary(struct linux_
43919 #else
43920 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43921 #endif
43922 +
43923 +#ifdef CONFIG_PAX_RANDMMAP
43924 + /* PaX: randomize base address at the default exe base if requested */
43925 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43926 +#ifdef CONFIG_SPARC64
43927 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43928 +#else
43929 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43930 +#endif
43931 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43932 + elf_flags |= MAP_FIXED;
43933 + }
43934 +#endif
43935 +
43936 }
43937
43938 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43939 @@ -832,9 +1133,9 @@ static int load_elf_binary(struct linux_
43940 * allowed task size. Note that p_filesz must always be
43941 * <= p_memsz so it is only necessary to check p_memsz.
43942 */
43943 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43944 - elf_ppnt->p_memsz > TASK_SIZE ||
43945 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43946 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43947 + elf_ppnt->p_memsz > pax_task_size ||
43948 + pax_task_size - elf_ppnt->p_memsz < k) {
43949 /* set_brk can never work. Avoid overflows. */
43950 send_sig(SIGKILL, current, 0);
43951 retval = -EINVAL;
43952 @@ -862,6 +1163,11 @@ static int load_elf_binary(struct linux_
43953 start_data += load_bias;
43954 end_data += load_bias;
43955
43956 +#ifdef CONFIG_PAX_RANDMMAP
43957 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
43958 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
43959 +#endif
43960 +
43961 /* Calling set_brk effectively mmaps the pages that we need
43962 * for the bss and break sections. We must do this before
43963 * mapping in the interpreter, to make sure it doesn't wind
43964 @@ -873,9 +1179,11 @@ static int load_elf_binary(struct linux_
43965 goto out_free_dentry;
43966 }
43967 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43968 - send_sig(SIGSEGV, current, 0);
43969 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43970 - goto out_free_dentry;
43971 + /*
43972 + * This bss-zeroing can fail if the ELF
43973 + * file specifies odd protections. So
43974 + * we don't check the return value
43975 + */
43976 }
43977
43978 if (elf_interpreter) {
43979 @@ -1090,7 +1398,7 @@ out:
43980 * Decide what to dump of a segment, part, all or none.
43981 */
43982 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43983 - unsigned long mm_flags)
43984 + unsigned long mm_flags, long signr)
43985 {
43986 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43987
43988 @@ -1124,7 +1432,7 @@ static unsigned long vma_dump_size(struc
43989 if (vma->vm_file == NULL)
43990 return 0;
43991
43992 - if (FILTER(MAPPED_PRIVATE))
43993 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43994 goto whole;
43995
43996 /*
43997 @@ -1346,9 +1654,9 @@ static void fill_auxv_note(struct memelf
43998 {
43999 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
44000 int i = 0;
44001 - do
44002 + do {
44003 i += 2;
44004 - while (auxv[i - 2] != AT_NULL);
44005 + } while (auxv[i - 2] != AT_NULL);
44006 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
44007 }
44008
44009 @@ -1854,14 +2162,14 @@ static void fill_extnum_info(struct elfh
44010 }
44011
44012 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
44013 - unsigned long mm_flags)
44014 + struct coredump_params *cprm)
44015 {
44016 struct vm_area_struct *vma;
44017 size_t size = 0;
44018
44019 for (vma = first_vma(current, gate_vma); vma != NULL;
44020 vma = next_vma(vma, gate_vma))
44021 - size += vma_dump_size(vma, mm_flags);
44022 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44023 return size;
44024 }
44025
44026 @@ -1955,7 +2263,7 @@ static int elf_core_dump(struct coredump
44027
44028 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
44029
44030 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
44031 + offset += elf_core_vma_data_size(gate_vma, cprm);
44032 offset += elf_core_extra_data_size();
44033 e_shoff = offset;
44034
44035 @@ -1969,10 +2277,12 @@ static int elf_core_dump(struct coredump
44036 offset = dataoff;
44037
44038 size += sizeof(*elf);
44039 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44040 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44041 goto end_coredump;
44042
44043 size += sizeof(*phdr4note);
44044 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44045 if (size > cprm->limit
44046 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44047 goto end_coredump;
44048 @@ -1986,7 +2296,7 @@ static int elf_core_dump(struct coredump
44049 phdr.p_offset = offset;
44050 phdr.p_vaddr = vma->vm_start;
44051 phdr.p_paddr = 0;
44052 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44053 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44054 phdr.p_memsz = vma->vm_end - vma->vm_start;
44055 offset += phdr.p_filesz;
44056 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44057 @@ -1997,6 +2307,7 @@ static int elf_core_dump(struct coredump
44058 phdr.p_align = ELF_EXEC_PAGESIZE;
44059
44060 size += sizeof(phdr);
44061 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44062 if (size > cprm->limit
44063 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44064 goto end_coredump;
44065 @@ -2021,7 +2332,7 @@ static int elf_core_dump(struct coredump
44066 unsigned long addr;
44067 unsigned long end;
44068
44069 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44070 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
44071
44072 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44073 struct page *page;
44074 @@ -2030,6 +2341,7 @@ static int elf_core_dump(struct coredump
44075 page = get_dump_page(addr);
44076 if (page) {
44077 void *kaddr = kmap(page);
44078 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44079 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44080 !dump_write(cprm->file, kaddr,
44081 PAGE_SIZE);
44082 @@ -2047,6 +2359,7 @@ static int elf_core_dump(struct coredump
44083
44084 if (e_phnum == PN_XNUM) {
44085 size += sizeof(*shdr4extnum);
44086 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
44087 if (size > cprm->limit
44088 || !dump_write(cprm->file, shdr4extnum,
44089 sizeof(*shdr4extnum)))
44090 @@ -2067,6 +2380,97 @@ out:
44091
44092 #endif /* CONFIG_ELF_CORE */
44093
44094 +#ifdef CONFIG_PAX_MPROTECT
44095 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
44096 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
44097 + * we'll remove VM_MAYWRITE for good on RELRO segments.
44098 + *
44099 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
44100 + * basis because we want to allow the common case and not the special ones.
44101 + */
44102 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
44103 +{
44104 + struct elfhdr elf_h;
44105 + struct elf_phdr elf_p;
44106 + unsigned long i;
44107 + unsigned long oldflags;
44108 + bool is_textrel_rw, is_textrel_rx, is_relro;
44109 +
44110 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
44111 + return;
44112 +
44113 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
44114 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
44115 +
44116 +#ifdef CONFIG_PAX_ELFRELOCS
44117 + /* possible TEXTREL */
44118 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
44119 + is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
44120 +#else
44121 + is_textrel_rw = false;
44122 + is_textrel_rx = false;
44123 +#endif
44124 +
44125 + /* possible RELRO */
44126 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
44127 +
44128 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
44129 + return;
44130 +
44131 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
44132 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
44133 +
44134 +#ifdef CONFIG_PAX_ETEXECRELOCS
44135 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44136 +#else
44137 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
44138 +#endif
44139 +
44140 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
44141 + !elf_check_arch(&elf_h) ||
44142 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
44143 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
44144 + return;
44145 +
44146 + for (i = 0UL; i < elf_h.e_phnum; i++) {
44147 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
44148 + return;
44149 + switch (elf_p.p_type) {
44150 + case PT_DYNAMIC:
44151 + if (!is_textrel_rw && !is_textrel_rx)
44152 + continue;
44153 + i = 0UL;
44154 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
44155 + elf_dyn dyn;
44156 +
44157 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
44158 + return;
44159 + if (dyn.d_tag == DT_NULL)
44160 + return;
44161 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
44162 + gr_log_textrel(vma);
44163 + if (is_textrel_rw)
44164 + vma->vm_flags |= VM_MAYWRITE;
44165 + else
44166 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
44167 + vma->vm_flags &= ~VM_MAYWRITE;
44168 + return;
44169 + }
44170 + i++;
44171 + }
44172 + return;
44173 +
44174 + case PT_GNU_RELRO:
44175 + if (!is_relro)
44176 + continue;
44177 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
44178 + vma->vm_flags &= ~VM_MAYWRITE;
44179 + return;
44180 + }
44181 + }
44182 +}
44183 +#endif
44184 +
44185 static int __init init_elf_binfmt(void)
44186 {
44187 return register_binfmt(&elf_format);
44188 diff -urNp linux-2.6.39.2/fs/binfmt_flat.c linux-2.6.39.2/fs/binfmt_flat.c
44189 --- linux-2.6.39.2/fs/binfmt_flat.c 2011-05-19 00:06:34.000000000 -0400
44190 +++ linux-2.6.39.2/fs/binfmt_flat.c 2011-05-22 19:36:32.000000000 -0400
44191 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_b
44192 realdatastart = (unsigned long) -ENOMEM;
44193 printk("Unable to allocate RAM for process data, errno %d\n",
44194 (int)-realdatastart);
44195 + down_write(&current->mm->mmap_sem);
44196 do_munmap(current->mm, textpos, text_len);
44197 + up_write(&current->mm->mmap_sem);
44198 ret = realdatastart;
44199 goto err;
44200 }
44201 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_b
44202 }
44203 if (IS_ERR_VALUE(result)) {
44204 printk("Unable to read data+bss, errno %d\n", (int)-result);
44205 + down_write(&current->mm->mmap_sem);
44206 do_munmap(current->mm, textpos, text_len);
44207 do_munmap(current->mm, realdatastart, len);
44208 + up_write(&current->mm->mmap_sem);
44209 ret = result;
44210 goto err;
44211 }
44212 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_b
44213 }
44214 if (IS_ERR_VALUE(result)) {
44215 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
44216 + down_write(&current->mm->mmap_sem);
44217 do_munmap(current->mm, textpos, text_len + data_len + extra +
44218 MAX_SHARED_LIBS * sizeof(unsigned long));
44219 + up_write(&current->mm->mmap_sem);
44220 ret = result;
44221 goto err;
44222 }
44223 diff -urNp linux-2.6.39.2/fs/bio.c linux-2.6.39.2/fs/bio.c
44224 --- linux-2.6.39.2/fs/bio.c 2011-05-19 00:06:34.000000000 -0400
44225 +++ linux-2.6.39.2/fs/bio.c 2011-05-22 19:36:32.000000000 -0400
44226 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct b
44227 const int read = bio_data_dir(bio) == READ;
44228 struct bio_map_data *bmd = bio->bi_private;
44229 int i;
44230 - char *p = bmd->sgvecs[0].iov_base;
44231 + char *p = (__force char *)bmd->sgvecs[0].iov_base;
44232
44233 __bio_for_each_segment(bvec, bio, i, 0) {
44234 char *addr = page_address(bvec->bv_page);
44235 diff -urNp linux-2.6.39.2/fs/block_dev.c linux-2.6.39.2/fs/block_dev.c
44236 --- linux-2.6.39.2/fs/block_dev.c 2011-06-25 12:55:23.000000000 -0400
44237 +++ linux-2.6.39.2/fs/block_dev.c 2011-06-06 19:57:05.000000000 -0400
44238 @@ -671,7 +671,7 @@ static bool bd_may_claim(struct block_de
44239 else if (bdev->bd_contains == bdev)
44240 return true; /* is a whole device which isn't held */
44241
44242 - else if (whole->bd_holder == bd_may_claim)
44243 + else if (whole->bd_holder == (void *)bd_may_claim)
44244 return true; /* is a partition of a device that is being partitioned */
44245 else if (whole->bd_holder != NULL)
44246 return false; /* is a partition of a held device */
44247 diff -urNp linux-2.6.39.2/fs/btrfs/compression.c linux-2.6.39.2/fs/btrfs/compression.c
44248 --- linux-2.6.39.2/fs/btrfs/compression.c 2011-05-19 00:06:34.000000000 -0400
44249 +++ linux-2.6.39.2/fs/btrfs/compression.c 2011-05-22 19:36:32.000000000 -0400
44250 @@ -719,7 +719,7 @@ static int comp_num_workspace[BTRFS_COMP
44251 static atomic_t comp_alloc_workspace[BTRFS_COMPRESS_TYPES];
44252 static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
44253
44254 -struct btrfs_compress_op *btrfs_compress_op[] = {
44255 +const struct btrfs_compress_op *btrfs_compress_op[] = {
44256 &btrfs_zlib_compress,
44257 &btrfs_lzo_compress,
44258 };
44259 diff -urNp linux-2.6.39.2/fs/btrfs/compression.h linux-2.6.39.2/fs/btrfs/compression.h
44260 --- linux-2.6.39.2/fs/btrfs/compression.h 2011-05-19 00:06:34.000000000 -0400
44261 +++ linux-2.6.39.2/fs/btrfs/compression.h 2011-05-22 19:36:32.000000000 -0400
44262 @@ -77,7 +77,7 @@ struct btrfs_compress_op {
44263 size_t srclen, size_t destlen);
44264 };
44265
44266 -extern struct btrfs_compress_op btrfs_zlib_compress;
44267 -extern struct btrfs_compress_op btrfs_lzo_compress;
44268 +extern const struct btrfs_compress_op btrfs_zlib_compress;
44269 +extern const struct btrfs_compress_op btrfs_lzo_compress;
44270
44271 #endif
44272 diff -urNp linux-2.6.39.2/fs/btrfs/ctree.c linux-2.6.39.2/fs/btrfs/ctree.c
44273 --- linux-2.6.39.2/fs/btrfs/ctree.c 2011-05-19 00:06:34.000000000 -0400
44274 +++ linux-2.6.39.2/fs/btrfs/ctree.c 2011-05-22 19:36:32.000000000 -0400
44275 @@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(st
44276 free_extent_buffer(buf);
44277 add_root_to_dirty_list(root);
44278 } else {
44279 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
44280 - parent_start = parent->start;
44281 - else
44282 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
44283 + if (parent)
44284 + parent_start = parent->start;
44285 + else
44286 + parent_start = 0;
44287 + } else
44288 parent_start = 0;
44289
44290 WARN_ON(trans->transid != btrfs_header_generation(parent));
44291 @@ -3647,7 +3650,6 @@ setup_items_for_insert(struct btrfs_tran
44292
44293 ret = 0;
44294 if (slot == 0) {
44295 - struct btrfs_disk_key disk_key;
44296 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
44297 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
44298 }
44299 diff -urNp linux-2.6.39.2/fs/btrfs/disk-io.c linux-2.6.39.2/fs/btrfs/disk-io.c
44300 --- linux-2.6.39.2/fs/btrfs/disk-io.c 2011-05-19 00:06:34.000000000 -0400
44301 +++ linux-2.6.39.2/fs/btrfs/disk-io.c 2011-05-22 19:36:32.000000000 -0400
44302 @@ -42,7 +42,7 @@
44303 #include "tree-log.h"
44304 #include "free-space-cache.h"
44305
44306 -static struct extent_io_ops btree_extent_io_ops;
44307 +static const struct extent_io_ops btree_extent_io_ops;
44308 static void end_workqueue_fn(struct btrfs_work *work);
44309 static void free_fs_root(struct btrfs_root *root);
44310 static void btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
44311 @@ -3070,7 +3070,7 @@ static int btrfs_cleanup_transaction(str
44312 return 0;
44313 }
44314
44315 -static struct extent_io_ops btree_extent_io_ops = {
44316 +static const struct extent_io_ops btree_extent_io_ops = {
44317 .write_cache_pages_lock_hook = btree_lock_page_hook,
44318 .readpage_end_io_hook = btree_readpage_end_io_hook,
44319 .submit_bio_hook = btree_submit_bio_hook,
44320 diff -urNp linux-2.6.39.2/fs/btrfs/extent_io.h linux-2.6.39.2/fs/btrfs/extent_io.h
44321 --- linux-2.6.39.2/fs/btrfs/extent_io.h 2011-05-19 00:06:34.000000000 -0400
44322 +++ linux-2.6.39.2/fs/btrfs/extent_io.h 2011-05-22 19:36:32.000000000 -0400
44323 @@ -56,36 +56,36 @@ typedef int (extent_submit_bio_hook_t)(s
44324 struct bio *bio, int mirror_num,
44325 unsigned long bio_flags, u64 bio_offset);
44326 struct extent_io_ops {
44327 - int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
44328 + int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
44329 u64 start, u64 end, int *page_started,
44330 unsigned long *nr_written);
44331 - int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
44332 - int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
44333 + int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
44334 + int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
44335 extent_submit_bio_hook_t *submit_bio_hook;
44336 - int (*merge_bio_hook)(struct page *page, unsigned long offset,
44337 + int (* const merge_bio_hook)(struct page *page, unsigned long offset,
44338 size_t size, struct bio *bio,
44339 unsigned long bio_flags);
44340 - int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
44341 - int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
44342 + int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
44343 + int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
44344 u64 start, u64 end,
44345 struct extent_state *state);
44346 - int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
44347 + int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
44348 u64 start, u64 end,
44349 struct extent_state *state);
44350 - int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44351 + int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
44352 struct extent_state *state);
44353 - int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44354 + int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
44355 struct extent_state *state, int uptodate);
44356 - int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
44357 + int (* const set_bit_hook)(struct inode *inode, struct extent_state *state,
44358 int *bits);
44359 - int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
44360 + int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
44361 int *bits);
44362 - int (*merge_extent_hook)(struct inode *inode,
44363 + int (* const merge_extent_hook)(struct inode *inode,
44364 struct extent_state *new,
44365 struct extent_state *other);
44366 - int (*split_extent_hook)(struct inode *inode,
44367 + int (* const split_extent_hook)(struct inode *inode,
44368 struct extent_state *orig, u64 split);
44369 - int (*write_cache_pages_lock_hook)(struct page *page);
44370 + int (* const write_cache_pages_lock_hook)(struct page *page);
44371 };
44372
44373 struct extent_io_tree {
44374 @@ -95,7 +95,7 @@ struct extent_io_tree {
44375 u64 dirty_bytes;
44376 spinlock_t lock;
44377 spinlock_t buffer_lock;
44378 - struct extent_io_ops *ops;
44379 + const struct extent_io_ops *ops;
44380 };
44381
44382 struct extent_state {
44383 diff -urNp linux-2.6.39.2/fs/btrfs/free-space-cache.c linux-2.6.39.2/fs/btrfs/free-space-cache.c
44384 --- linux-2.6.39.2/fs/btrfs/free-space-cache.c 2011-05-19 00:06:34.000000000 -0400
44385 +++ linux-2.6.39.2/fs/btrfs/free-space-cache.c 2011-05-22 19:36:32.000000000 -0400
44386 @@ -1910,8 +1910,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44387 while(1) {
44388 if (entry->bytes < bytes ||
44389 (!entry->bitmap && entry->offset < min_start)) {
44390 - struct rb_node *node;
44391 -
44392 node = rb_next(&entry->offset_index);
44393 if (!node)
44394 break;
44395 @@ -1925,7 +1923,6 @@ u64 btrfs_alloc_from_cluster(struct btrf
44396 cluster, entry, bytes,
44397 min_start);
44398 if (ret == 0) {
44399 - struct rb_node *node;
44400 node = rb_next(&entry->offset_index);
44401 if (!node)
44402 break;
44403 diff -urNp linux-2.6.39.2/fs/btrfs/inode.c linux-2.6.39.2/fs/btrfs/inode.c
44404 --- linux-2.6.39.2/fs/btrfs/inode.c 2011-05-19 00:06:34.000000000 -0400
44405 +++ linux-2.6.39.2/fs/btrfs/inode.c 2011-05-22 20:42:42.000000000 -0400
44406 @@ -65,7 +65,7 @@ static const struct inode_operations btr
44407 static const struct address_space_operations btrfs_aops;
44408 static const struct address_space_operations btrfs_symlink_aops;
44409 static const struct file_operations btrfs_dir_file_operations;
44410 -static struct extent_io_ops btrfs_extent_io_ops;
44411 +static const struct extent_io_ops btrfs_extent_io_ops;
44412
44413 static struct kmem_cache *btrfs_inode_cachep;
44414 struct kmem_cache *btrfs_trans_handle_cachep;
44415 @@ -6947,7 +6947,7 @@ fail:
44416 return -ENOMEM;
44417 }
44418
44419 -static int btrfs_getattr(struct vfsmount *mnt,
44420 +int btrfs_getattr(struct vfsmount *mnt,
44421 struct dentry *dentry, struct kstat *stat)
44422 {
44423 struct inode *inode = dentry->d_inode;
44424 @@ -6959,6 +6959,14 @@ static int btrfs_getattr(struct vfsmount
44425 return 0;
44426 }
44427
44428 +EXPORT_SYMBOL(btrfs_getattr);
44429 +
44430 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
44431 +{
44432 + return BTRFS_I(inode)->root->anon_super.s_dev;
44433 +}
44434 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
44435 +
44436 /*
44437 * If a file is moved, it will inherit the cow and compression flags of the new
44438 * directory.
44439 @@ -7488,7 +7496,7 @@ static const struct file_operations btrf
44440 .fsync = btrfs_sync_file,
44441 };
44442
44443 -static struct extent_io_ops btrfs_extent_io_ops = {
44444 +static const struct extent_io_ops btrfs_extent_io_ops = {
44445 .fill_delalloc = run_delalloc_range,
44446 .submit_bio_hook = btrfs_submit_bio_hook,
44447 .merge_bio_hook = btrfs_merge_bio_hook,
44448 diff -urNp linux-2.6.39.2/fs/btrfs/ioctl.c linux-2.6.39.2/fs/btrfs/ioctl.c
44449 --- linux-2.6.39.2/fs/btrfs/ioctl.c 2011-05-19 00:06:34.000000000 -0400
44450 +++ linux-2.6.39.2/fs/btrfs/ioctl.c 2011-05-22 19:41:37.000000000 -0400
44451 @@ -2361,9 +2361,12 @@ long btrfs_ioctl_space_info(struct btrfs
44452 for (i = 0; i < num_types; i++) {
44453 struct btrfs_space_info *tmp;
44454
44455 + /* Don't copy in more than we allocated */
44456 if (!slot_count)
44457 break;
44458
44459 + slot_count--;
44460 +
44461 info = NULL;
44462 rcu_read_lock();
44463 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44464 @@ -2385,10 +2388,7 @@ long btrfs_ioctl_space_info(struct btrfs
44465 memcpy(dest, &space, sizeof(space));
44466 dest++;
44467 space_args.total_spaces++;
44468 - slot_count--;
44469 }
44470 - if (!slot_count)
44471 - break;
44472 }
44473 up_read(&info->groups_sem);
44474 }
44475 diff -urNp linux-2.6.39.2/fs/btrfs/lzo.c linux-2.6.39.2/fs/btrfs/lzo.c
44476 --- linux-2.6.39.2/fs/btrfs/lzo.c 2011-05-19 00:06:34.000000000 -0400
44477 +++ linux-2.6.39.2/fs/btrfs/lzo.c 2011-05-22 19:36:32.000000000 -0400
44478 @@ -418,7 +418,7 @@ out:
44479 return ret;
44480 }
44481
44482 -struct btrfs_compress_op btrfs_lzo_compress = {
44483 +const struct btrfs_compress_op btrfs_lzo_compress = {
44484 .alloc_workspace = lzo_alloc_workspace,
44485 .free_workspace = lzo_free_workspace,
44486 .compress_pages = lzo_compress_pages,
44487 diff -urNp linux-2.6.39.2/fs/btrfs/relocation.c linux-2.6.39.2/fs/btrfs/relocation.c
44488 --- linux-2.6.39.2/fs/btrfs/relocation.c 2011-05-19 00:06:34.000000000 -0400
44489 +++ linux-2.6.39.2/fs/btrfs/relocation.c 2011-05-22 19:36:32.000000000 -0400
44490 @@ -1239,7 +1239,7 @@ static int __update_reloc_root(struct bt
44491 }
44492 spin_unlock(&rc->reloc_root_tree.lock);
44493
44494 - BUG_ON((struct btrfs_root *)node->data != root);
44495 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44496
44497 if (!del) {
44498 spin_lock(&rc->reloc_root_tree.lock);
44499 diff -urNp linux-2.6.39.2/fs/btrfs/zlib.c linux-2.6.39.2/fs/btrfs/zlib.c
44500 --- linux-2.6.39.2/fs/btrfs/zlib.c 2011-05-19 00:06:34.000000000 -0400
44501 +++ linux-2.6.39.2/fs/btrfs/zlib.c 2011-05-22 19:36:32.000000000 -0400
44502 @@ -390,7 +390,7 @@ next:
44503 return ret;
44504 }
44505
44506 -struct btrfs_compress_op btrfs_zlib_compress = {
44507 +const struct btrfs_compress_op btrfs_zlib_compress = {
44508 .alloc_workspace = zlib_alloc_workspace,
44509 .free_workspace = zlib_free_workspace,
44510 .compress_pages = zlib_compress_pages,
44511 diff -urNp linux-2.6.39.2/fs/cachefiles/bind.c linux-2.6.39.2/fs/cachefiles/bind.c
44512 --- linux-2.6.39.2/fs/cachefiles/bind.c 2011-05-19 00:06:34.000000000 -0400
44513 +++ linux-2.6.39.2/fs/cachefiles/bind.c 2011-05-22 19:36:32.000000000 -0400
44514 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachef
44515 args);
44516
44517 /* start by checking things over */
44518 - ASSERT(cache->fstop_percent >= 0 &&
44519 - cache->fstop_percent < cache->fcull_percent &&
44520 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44521 cache->fcull_percent < cache->frun_percent &&
44522 cache->frun_percent < 100);
44523
44524 - ASSERT(cache->bstop_percent >= 0 &&
44525 - cache->bstop_percent < cache->bcull_percent &&
44526 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44527 cache->bcull_percent < cache->brun_percent &&
44528 cache->brun_percent < 100);
44529
44530 diff -urNp linux-2.6.39.2/fs/cachefiles/daemon.c linux-2.6.39.2/fs/cachefiles/daemon.c
44531 --- linux-2.6.39.2/fs/cachefiles/daemon.c 2011-05-19 00:06:34.000000000 -0400
44532 +++ linux-2.6.39.2/fs/cachefiles/daemon.c 2011-05-22 19:36:32.000000000 -0400
44533 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(st
44534 if (n > buflen)
44535 return -EMSGSIZE;
44536
44537 - if (copy_to_user(_buffer, buffer, n) != 0)
44538 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44539 return -EFAULT;
44540
44541 return n;
44542 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(s
44543 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44544 return -EIO;
44545
44546 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44547 + if (datalen > PAGE_SIZE - 1)
44548 return -EOPNOTSUPP;
44549
44550 /* drag the command string into the kernel so we can parse it */
44551 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struc
44552 if (args[0] != '%' || args[1] != '\0')
44553 return -EINVAL;
44554
44555 - if (fstop < 0 || fstop >= cache->fcull_percent)
44556 + if (fstop >= cache->fcull_percent)
44557 return cachefiles_daemon_range_error(cache, args);
44558
44559 cache->fstop_percent = fstop;
44560 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struc
44561 if (args[0] != '%' || args[1] != '\0')
44562 return -EINVAL;
44563
44564 - if (bstop < 0 || bstop >= cache->bcull_percent)
44565 + if (bstop >= cache->bcull_percent)
44566 return cachefiles_daemon_range_error(cache, args);
44567
44568 cache->bstop_percent = bstop;
44569 diff -urNp linux-2.6.39.2/fs/cachefiles/internal.h linux-2.6.39.2/fs/cachefiles/internal.h
44570 --- linux-2.6.39.2/fs/cachefiles/internal.h 2011-05-19 00:06:34.000000000 -0400
44571 +++ linux-2.6.39.2/fs/cachefiles/internal.h 2011-05-22 19:36:32.000000000 -0400
44572 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44573 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44574 struct rb_root active_nodes; /* active nodes (can't be culled) */
44575 rwlock_t active_lock; /* lock for active_nodes */
44576 - atomic_t gravecounter; /* graveyard uniquifier */
44577 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44578 unsigned frun_percent; /* when to stop culling (% files) */
44579 unsigned fcull_percent; /* when to start culling (% files) */
44580 unsigned fstop_percent; /* when to stop allocating (% files) */
44581 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struc
44582 * proc.c
44583 */
44584 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44585 -extern atomic_t cachefiles_lookup_histogram[HZ];
44586 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44587 -extern atomic_t cachefiles_create_histogram[HZ];
44588 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44589 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44590 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44591
44592 extern int __init cachefiles_proc_init(void);
44593 extern void cachefiles_proc_cleanup(void);
44594 static inline
44595 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44596 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44597 {
44598 unsigned long jif = jiffies - start_jif;
44599 if (jif >= HZ)
44600 jif = HZ - 1;
44601 - atomic_inc(&histogram[jif]);
44602 + atomic_inc_unchecked(&histogram[jif]);
44603 }
44604
44605 #else
44606 diff -urNp linux-2.6.39.2/fs/cachefiles/namei.c linux-2.6.39.2/fs/cachefiles/namei.c
44607 --- linux-2.6.39.2/fs/cachefiles/namei.c 2011-05-19 00:06:34.000000000 -0400
44608 +++ linux-2.6.39.2/fs/cachefiles/namei.c 2011-05-22 19:36:32.000000000 -0400
44609 @@ -318,7 +318,7 @@ try_again:
44610 /* first step is to make up a grave dentry in the graveyard */
44611 sprintf(nbuffer, "%08x%08x",
44612 (uint32_t) get_seconds(),
44613 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44614 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44615
44616 /* do the multiway lock magic */
44617 trap = lock_rename(cache->graveyard, dir);
44618 diff -urNp linux-2.6.39.2/fs/cachefiles/proc.c linux-2.6.39.2/fs/cachefiles/proc.c
44619 --- linux-2.6.39.2/fs/cachefiles/proc.c 2011-05-19 00:06:34.000000000 -0400
44620 +++ linux-2.6.39.2/fs/cachefiles/proc.c 2011-05-22 19:36:32.000000000 -0400
44621 @@ -14,9 +14,9 @@
44622 #include <linux/seq_file.h>
44623 #include "internal.h"
44624
44625 -atomic_t cachefiles_lookup_histogram[HZ];
44626 -atomic_t cachefiles_mkdir_histogram[HZ];
44627 -atomic_t cachefiles_create_histogram[HZ];
44628 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44629 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44630 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44631
44632 /*
44633 * display the latency histogram
44634 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(str
44635 return 0;
44636 default:
44637 index = (unsigned long) v - 3;
44638 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44639 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44640 - z = atomic_read(&cachefiles_create_histogram[index]);
44641 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44642 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44643 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44644 if (x == 0 && y == 0 && z == 0)
44645 return 0;
44646
44647 diff -urNp linux-2.6.39.2/fs/cachefiles/rdwr.c linux-2.6.39.2/fs/cachefiles/rdwr.c
44648 --- linux-2.6.39.2/fs/cachefiles/rdwr.c 2011-05-19 00:06:34.000000000 -0400
44649 +++ linux-2.6.39.2/fs/cachefiles/rdwr.c 2011-05-22 19:36:32.000000000 -0400
44650 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache
44651 old_fs = get_fs();
44652 set_fs(KERNEL_DS);
44653 ret = file->f_op->write(
44654 - file, (const void __user *) data, len, &pos);
44655 + file, (__force const void __user *) data, len, &pos);
44656 set_fs(old_fs);
44657 kunmap(page);
44658 if (ret != len)
44659 diff -urNp linux-2.6.39.2/fs/ceph/addr.c linux-2.6.39.2/fs/ceph/addr.c
44660 --- linux-2.6.39.2/fs/ceph/addr.c 2011-05-19 00:06:34.000000000 -0400
44661 +++ linux-2.6.39.2/fs/ceph/addr.c 2011-05-22 19:36:32.000000000 -0400
44662 @@ -1164,7 +1164,7 @@ out:
44663 return ret;
44664 }
44665
44666 -static struct vm_operations_struct ceph_vmops = {
44667 +static const struct vm_operations_struct ceph_vmops = {
44668 .fault = filemap_fault,
44669 .page_mkwrite = ceph_page_mkwrite,
44670 };
44671 diff -urNp linux-2.6.39.2/fs/ceph/dir.c linux-2.6.39.2/fs/ceph/dir.c
44672 --- linux-2.6.39.2/fs/ceph/dir.c 2011-05-19 00:06:34.000000000 -0400
44673 +++ linux-2.6.39.2/fs/ceph/dir.c 2011-05-22 19:36:32.000000000 -0400
44674 @@ -226,7 +226,7 @@ static int ceph_readdir(struct file *fil
44675 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44676 struct ceph_mds_client *mdsc = fsc->mdsc;
44677 unsigned frag = fpos_frag(filp->f_pos);
44678 - int off = fpos_off(filp->f_pos);
44679 + unsigned int off = fpos_off(filp->f_pos);
44680 int err;
44681 u32 ftype;
44682 struct ceph_mds_reply_info_parsed *rinfo;
44683 @@ -360,7 +360,7 @@ more:
44684 rinfo = &fi->last_readdir->r_reply_info;
44685 dout("readdir frag %x num %d off %d chunkoff %d\n", frag,
44686 rinfo->dir_nr, off, fi->offset);
44687 - while (off - fi->offset >= 0 && off - fi->offset < rinfo->dir_nr) {
44688 + while (off >= fi->offset && off - fi->offset < rinfo->dir_nr) {
44689 u64 pos = ceph_make_fpos(frag, off);
44690 struct ceph_mds_reply_inode *in =
44691 rinfo->dir_in[off - fi->offset].in;
44692 diff -urNp linux-2.6.39.2/fs/cifs/cifs_debug.c linux-2.6.39.2/fs/cifs/cifs_debug.c
44693 --- linux-2.6.39.2/fs/cifs/cifs_debug.c 2011-05-19 00:06:34.000000000 -0400
44694 +++ linux-2.6.39.2/fs/cifs/cifs_debug.c 2011-05-22 19:36:32.000000000 -0400
44695 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(str
44696 tcon = list_entry(tmp3,
44697 struct cifsTconInfo,
44698 tcon_list);
44699 - atomic_set(&tcon->num_smbs_sent, 0);
44700 - atomic_set(&tcon->num_writes, 0);
44701 - atomic_set(&tcon->num_reads, 0);
44702 - atomic_set(&tcon->num_oplock_brks, 0);
44703 - atomic_set(&tcon->num_opens, 0);
44704 - atomic_set(&tcon->num_posixopens, 0);
44705 - atomic_set(&tcon->num_posixmkdirs, 0);
44706 - atomic_set(&tcon->num_closes, 0);
44707 - atomic_set(&tcon->num_deletes, 0);
44708 - atomic_set(&tcon->num_mkdirs, 0);
44709 - atomic_set(&tcon->num_rmdirs, 0);
44710 - atomic_set(&tcon->num_renames, 0);
44711 - atomic_set(&tcon->num_t2renames, 0);
44712 - atomic_set(&tcon->num_ffirst, 0);
44713 - atomic_set(&tcon->num_fnext, 0);
44714 - atomic_set(&tcon->num_fclose, 0);
44715 - atomic_set(&tcon->num_hardlinks, 0);
44716 - atomic_set(&tcon->num_symlinks, 0);
44717 - atomic_set(&tcon->num_locks, 0);
44718 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44719 + atomic_set_unchecked(&tcon->num_writes, 0);
44720 + atomic_set_unchecked(&tcon->num_reads, 0);
44721 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44722 + atomic_set_unchecked(&tcon->num_opens, 0);
44723 + atomic_set_unchecked(&tcon->num_posixopens, 0);
44724 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44725 + atomic_set_unchecked(&tcon->num_closes, 0);
44726 + atomic_set_unchecked(&tcon->num_deletes, 0);
44727 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44728 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44729 + atomic_set_unchecked(&tcon->num_renames, 0);
44730 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44731 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44732 + atomic_set_unchecked(&tcon->num_fnext, 0);
44733 + atomic_set_unchecked(&tcon->num_fclose, 0);
44734 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44735 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44736 + atomic_set_unchecked(&tcon->num_locks, 0);
44737 }
44738 }
44739 }
44740 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct s
44741 if (tcon->need_reconnect)
44742 seq_puts(m, "\tDISCONNECTED ");
44743 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44744 - atomic_read(&tcon->num_smbs_sent),
44745 - atomic_read(&tcon->num_oplock_brks));
44746 + atomic_read_unchecked(&tcon->num_smbs_sent),
44747 + atomic_read_unchecked(&tcon->num_oplock_brks));
44748 seq_printf(m, "\nReads: %d Bytes: %lld",
44749 - atomic_read(&tcon->num_reads),
44750 + atomic_read_unchecked(&tcon->num_reads),
44751 (long long)(tcon->bytes_read));
44752 seq_printf(m, "\nWrites: %d Bytes: %lld",
44753 - atomic_read(&tcon->num_writes),
44754 + atomic_read_unchecked(&tcon->num_writes),
44755 (long long)(tcon->bytes_written));
44756 seq_printf(m, "\nFlushes: %d",
44757 - atomic_read(&tcon->num_flushes));
44758 + atomic_read_unchecked(&tcon->num_flushes));
44759 seq_printf(m, "\nLocks: %d HardLinks: %d "
44760 "Symlinks: %d",
44761 - atomic_read(&tcon->num_locks),
44762 - atomic_read(&tcon->num_hardlinks),
44763 - atomic_read(&tcon->num_symlinks));
44764 + atomic_read_unchecked(&tcon->num_locks),
44765 + atomic_read_unchecked(&tcon->num_hardlinks),
44766 + atomic_read_unchecked(&tcon->num_symlinks));
44767 seq_printf(m, "\nOpens: %d Closes: %d "
44768 "Deletes: %d",
44769 - atomic_read(&tcon->num_opens),
44770 - atomic_read(&tcon->num_closes),
44771 - atomic_read(&tcon->num_deletes));
44772 + atomic_read_unchecked(&tcon->num_opens),
44773 + atomic_read_unchecked(&tcon->num_closes),
44774 + atomic_read_unchecked(&tcon->num_deletes));
44775 seq_printf(m, "\nPosix Opens: %d "
44776 "Posix Mkdirs: %d",
44777 - atomic_read(&tcon->num_posixopens),
44778 - atomic_read(&tcon->num_posixmkdirs));
44779 + atomic_read_unchecked(&tcon->num_posixopens),
44780 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44781 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44782 - atomic_read(&tcon->num_mkdirs),
44783 - atomic_read(&tcon->num_rmdirs));
44784 + atomic_read_unchecked(&tcon->num_mkdirs),
44785 + atomic_read_unchecked(&tcon->num_rmdirs));
44786 seq_printf(m, "\nRenames: %d T2 Renames %d",
44787 - atomic_read(&tcon->num_renames),
44788 - atomic_read(&tcon->num_t2renames));
44789 + atomic_read_unchecked(&tcon->num_renames),
44790 + atomic_read_unchecked(&tcon->num_t2renames));
44791 seq_printf(m, "\nFindFirst: %d FNext %d "
44792 "FClose %d",
44793 - atomic_read(&tcon->num_ffirst),
44794 - atomic_read(&tcon->num_fnext),
44795 - atomic_read(&tcon->num_fclose));
44796 + atomic_read_unchecked(&tcon->num_ffirst),
44797 + atomic_read_unchecked(&tcon->num_fnext),
44798 + atomic_read_unchecked(&tcon->num_fclose));
44799 }
44800 }
44801 }
44802 diff -urNp linux-2.6.39.2/fs/cifs/cifsglob.h linux-2.6.39.2/fs/cifs/cifsglob.h
44803 --- linux-2.6.39.2/fs/cifs/cifsglob.h 2011-05-19 00:06:34.000000000 -0400
44804 +++ linux-2.6.39.2/fs/cifs/cifsglob.h 2011-05-22 19:36:32.000000000 -0400
44805 @@ -305,28 +305,28 @@ struct cifsTconInfo {
44806 __u16 Flags; /* optional support bits */
44807 enum statusEnum tidStatus;
44808 #ifdef CONFIG_CIFS_STATS
44809 - atomic_t num_smbs_sent;
44810 - atomic_t num_writes;
44811 - atomic_t num_reads;
44812 - atomic_t num_flushes;
44813 - atomic_t num_oplock_brks;
44814 - atomic_t num_opens;
44815 - atomic_t num_closes;
44816 - atomic_t num_deletes;
44817 - atomic_t num_mkdirs;
44818 - atomic_t num_posixopens;
44819 - atomic_t num_posixmkdirs;
44820 - atomic_t num_rmdirs;
44821 - atomic_t num_renames;
44822 - atomic_t num_t2renames;
44823 - atomic_t num_ffirst;
44824 - atomic_t num_fnext;
44825 - atomic_t num_fclose;
44826 - atomic_t num_hardlinks;
44827 - atomic_t num_symlinks;
44828 - atomic_t num_locks;
44829 - atomic_t num_acl_get;
44830 - atomic_t num_acl_set;
44831 + atomic_unchecked_t num_smbs_sent;
44832 + atomic_unchecked_t num_writes;
44833 + atomic_unchecked_t num_reads;
44834 + atomic_unchecked_t num_flushes;
44835 + atomic_unchecked_t num_oplock_brks;
44836 + atomic_unchecked_t num_opens;
44837 + atomic_unchecked_t num_closes;
44838 + atomic_unchecked_t num_deletes;
44839 + atomic_unchecked_t num_mkdirs;
44840 + atomic_unchecked_t num_posixopens;
44841 + atomic_unchecked_t num_posixmkdirs;
44842 + atomic_unchecked_t num_rmdirs;
44843 + atomic_unchecked_t num_renames;
44844 + atomic_unchecked_t num_t2renames;
44845 + atomic_unchecked_t num_ffirst;
44846 + atomic_unchecked_t num_fnext;
44847 + atomic_unchecked_t num_fclose;
44848 + atomic_unchecked_t num_hardlinks;
44849 + atomic_unchecked_t num_symlinks;
44850 + atomic_unchecked_t num_locks;
44851 + atomic_unchecked_t num_acl_get;
44852 + atomic_unchecked_t num_acl_set;
44853 #ifdef CONFIG_CIFS_STATS2
44854 unsigned long long time_writes;
44855 unsigned long long time_reads;
44856 @@ -509,7 +509,7 @@ static inline char CIFS_DIR_SEP(const st
44857 }
44858
44859 #ifdef CONFIG_CIFS_STATS
44860 -#define cifs_stats_inc atomic_inc
44861 +#define cifs_stats_inc atomic_inc_unchecked
44862
44863 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
44864 unsigned int bytes)
44865 diff -urNp linux-2.6.39.2/fs/cifs/link.c linux-2.6.39.2/fs/cifs/link.c
44866 --- linux-2.6.39.2/fs/cifs/link.c 2011-05-19 00:06:34.000000000 -0400
44867 +++ linux-2.6.39.2/fs/cifs/link.c 2011-05-22 19:36:32.000000000 -0400
44868 @@ -577,7 +577,7 @@ symlink_exit:
44869
44870 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44871 {
44872 - char *p = nd_get_link(nd);
44873 + const char *p = nd_get_link(nd);
44874 if (!IS_ERR(p))
44875 kfree(p);
44876 }
44877 diff -urNp linux-2.6.39.2/fs/coda/cache.c linux-2.6.39.2/fs/coda/cache.c
44878 --- linux-2.6.39.2/fs/coda/cache.c 2011-05-19 00:06:34.000000000 -0400
44879 +++ linux-2.6.39.2/fs/coda/cache.c 2011-05-22 19:36:32.000000000 -0400
44880 @@ -24,7 +24,7 @@
44881 #include "coda_linux.h"
44882 #include "coda_cache.h"
44883
44884 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44885 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44886
44887 /* replace or extend an acl cache hit */
44888 void coda_cache_enter(struct inode *inode, int mask)
44889 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inod
44890 struct coda_inode_info *cii = ITOC(inode);
44891
44892 spin_lock(&cii->c_lock);
44893 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44894 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44895 if (cii->c_uid != current_fsuid()) {
44896 cii->c_uid = current_fsuid();
44897 cii->c_cached_perm = mask;
44898 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode
44899 {
44900 struct coda_inode_info *cii = ITOC(inode);
44901 spin_lock(&cii->c_lock);
44902 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44903 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44904 spin_unlock(&cii->c_lock);
44905 }
44906
44907 /* remove all acl caches */
44908 void coda_cache_clear_all(struct super_block *sb)
44909 {
44910 - atomic_inc(&permission_epoch);
44911 + atomic_inc_unchecked(&permission_epoch);
44912 }
44913
44914
44915 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode
44916 spin_lock(&cii->c_lock);
44917 hit = (mask & cii->c_cached_perm) == mask &&
44918 cii->c_uid == current_fsuid() &&
44919 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44920 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44921 spin_unlock(&cii->c_lock);
44922
44923 return hit;
44924 diff -urNp linux-2.6.39.2/fs/compat_binfmt_elf.c linux-2.6.39.2/fs/compat_binfmt_elf.c
44925 --- linux-2.6.39.2/fs/compat_binfmt_elf.c 2011-05-19 00:06:34.000000000 -0400
44926 +++ linux-2.6.39.2/fs/compat_binfmt_elf.c 2011-05-22 19:36:32.000000000 -0400
44927 @@ -30,11 +30,13 @@
44928 #undef elf_phdr
44929 #undef elf_shdr
44930 #undef elf_note
44931 +#undef elf_dyn
44932 #undef elf_addr_t
44933 #define elfhdr elf32_hdr
44934 #define elf_phdr elf32_phdr
44935 #define elf_shdr elf32_shdr
44936 #define elf_note elf32_note
44937 +#define elf_dyn Elf32_Dyn
44938 #define elf_addr_t Elf32_Addr
44939
44940 /*
44941 diff -urNp linux-2.6.39.2/fs/compat.c linux-2.6.39.2/fs/compat.c
44942 --- linux-2.6.39.2/fs/compat.c 2011-05-19 00:06:34.000000000 -0400
44943 +++ linux-2.6.39.2/fs/compat.c 2011-05-22 19:41:37.000000000 -0400
44944 @@ -566,7 +566,7 @@ ssize_t compat_rw_copy_check_uvector(int
44945 goto out;
44946
44947 ret = -EINVAL;
44948 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44949 + if (nr_segs > UIO_MAXIOV)
44950 goto out;
44951 if (nr_segs > fast_segs) {
44952 ret = -ENOMEM;
44953 @@ -848,6 +848,7 @@ struct compat_old_linux_dirent {
44954
44955 struct compat_readdir_callback {
44956 struct compat_old_linux_dirent __user *dirent;
44957 + struct file * file;
44958 int result;
44959 };
44960
44961 @@ -865,6 +866,10 @@ static int compat_fillonedir(void *__buf
44962 buf->result = -EOVERFLOW;
44963 return -EOVERFLOW;
44964 }
44965 +
44966 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44967 + return 0;
44968 +
44969 buf->result++;
44970 dirent = buf->dirent;
44971 if (!access_ok(VERIFY_WRITE, dirent,
44972 @@ -897,6 +902,7 @@ asmlinkage long compat_sys_old_readdir(u
44973
44974 buf.result = 0;
44975 buf.dirent = dirent;
44976 + buf.file = file;
44977
44978 error = vfs_readdir(file, compat_fillonedir, &buf);
44979 if (buf.result)
44980 @@ -917,6 +923,7 @@ struct compat_linux_dirent {
44981 struct compat_getdents_callback {
44982 struct compat_linux_dirent __user *current_dir;
44983 struct compat_linux_dirent __user *previous;
44984 + struct file * file;
44985 int count;
44986 int error;
44987 };
44988 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, c
44989 buf->error = -EOVERFLOW;
44990 return -EOVERFLOW;
44991 }
44992 +
44993 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44994 + return 0;
44995 +
44996 dirent = buf->previous;
44997 if (dirent) {
44998 if (__put_user(offset, &dirent->d_off))
44999 @@ -985,6 +996,7 @@ asmlinkage long compat_sys_getdents(unsi
45000 buf.previous = NULL;
45001 buf.count = count;
45002 buf.error = 0;
45003 + buf.file = file;
45004
45005 error = vfs_readdir(file, compat_filldir, &buf);
45006 if (error >= 0)
45007 @@ -1006,6 +1018,7 @@ out:
45008 struct compat_getdents_callback64 {
45009 struct linux_dirent64 __user *current_dir;
45010 struct linux_dirent64 __user *previous;
45011 + struct file * file;
45012 int count;
45013 int error;
45014 };
45015 @@ -1022,6 +1035,10 @@ static int compat_filldir64(void * __buf
45016 buf->error = -EINVAL; /* only used if we fail.. */
45017 if (reclen > buf->count)
45018 return -EINVAL;
45019 +
45020 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45021 + return 0;
45022 +
45023 dirent = buf->previous;
45024
45025 if (dirent) {
45026 @@ -1073,6 +1090,7 @@ asmlinkage long compat_sys_getdents64(un
45027 buf.previous = NULL;
45028 buf.count = count;
45029 buf.error = 0;
45030 + buf.file = file;
45031
45032 error = vfs_readdir(file, compat_filldir64, &buf);
45033 if (error >= 0)
45034 @@ -1436,6 +1454,11 @@ int compat_do_execve(char * filename,
45035 compat_uptr_t __user *envp,
45036 struct pt_regs * regs)
45037 {
45038 +#ifdef CONFIG_GRKERNSEC
45039 + struct file *old_exec_file;
45040 + struct acl_subject_label *old_acl;
45041 + struct rlimit old_rlim[RLIM_NLIMITS];
45042 +#endif
45043 struct linux_binprm *bprm;
45044 struct file *file;
45045 struct files_struct *displaced;
45046 @@ -1472,6 +1495,19 @@ int compat_do_execve(char * filename,
45047 bprm->filename = filename;
45048 bprm->interp = filename;
45049
45050 + if (gr_process_user_ban()) {
45051 + retval = -EPERM;
45052 + goto out_file;
45053 + }
45054 +
45055 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45056 + retval = -EAGAIN;
45057 + if (gr_handle_nproc())
45058 + goto out_file;
45059 + retval = -EACCES;
45060 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
45061 + goto out_file;
45062 +
45063 retval = bprm_mm_init(bprm);
45064 if (retval)
45065 goto out_file;
45066 @@ -1501,9 +1537,40 @@ int compat_do_execve(char * filename,
45067 if (retval < 0)
45068 goto out;
45069
45070 + if (!gr_tpe_allow(file)) {
45071 + retval = -EACCES;
45072 + goto out;
45073 + }
45074 +
45075 + if (gr_check_crash_exec(file)) {
45076 + retval = -EACCES;
45077 + goto out;
45078 + }
45079 +
45080 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45081 +
45082 + gr_handle_exec_args_compat(bprm, argv);
45083 +
45084 +#ifdef CONFIG_GRKERNSEC
45085 + old_acl = current->acl;
45086 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45087 + old_exec_file = current->exec_file;
45088 + get_file(file);
45089 + current->exec_file = file;
45090 +#endif
45091 +
45092 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45093 + bprm->unsafe & LSM_UNSAFE_SHARE);
45094 + if (retval < 0)
45095 + goto out_fail;
45096 +
45097 retval = search_binary_handler(bprm, regs);
45098 if (retval < 0)
45099 - goto out;
45100 + goto out_fail;
45101 +#ifdef CONFIG_GRKERNSEC
45102 + if (old_exec_file)
45103 + fput(old_exec_file);
45104 +#endif
45105
45106 /* execve succeeded */
45107 current->fs->in_exec = 0;
45108 @@ -1514,6 +1581,14 @@ int compat_do_execve(char * filename,
45109 put_files_struct(displaced);
45110 return retval;
45111
45112 +out_fail:
45113 +#ifdef CONFIG_GRKERNSEC
45114 + current->acl = old_acl;
45115 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45116 + fput(current->exec_file);
45117 + current->exec_file = old_exec_file;
45118 +#endif
45119 +
45120 out:
45121 if (bprm->mm) {
45122 acct_arg_size(bprm, 0);
45123 @@ -1681,6 +1756,8 @@ int compat_core_sys_select(int n, compat
45124 struct fdtable *fdt;
45125 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
45126
45127 + pax_track_stack();
45128 +
45129 if (n < 0)
45130 goto out_nofds;
45131
45132 diff -urNp linux-2.6.39.2/fs/compat_ioctl.c linux-2.6.39.2/fs/compat_ioctl.c
45133 --- linux-2.6.39.2/fs/compat_ioctl.c 2011-05-19 00:06:34.000000000 -0400
45134 +++ linux-2.6.39.2/fs/compat_ioctl.c 2011-05-22 19:36:32.000000000 -0400
45135 @@ -208,6 +208,8 @@ static int do_video_set_spu_palette(unsi
45136
45137 err = get_user(palp, &up->palette);
45138 err |= get_user(length, &up->length);
45139 + if (err)
45140 + return -EFAULT;
45141
45142 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
45143 err = put_user(compat_ptr(palp), &up_native->palette);
45144 @@ -1638,8 +1640,8 @@ asmlinkage long compat_sys_ioctl(unsigne
45145 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
45146 {
45147 unsigned int a, b;
45148 - a = *(unsigned int *)p;
45149 - b = *(unsigned int *)q;
45150 + a = *(const unsigned int *)p;
45151 + b = *(const unsigned int *)q;
45152 if (a > b)
45153 return 1;
45154 if (a < b)
45155 diff -urNp linux-2.6.39.2/fs/configfs/dir.c linux-2.6.39.2/fs/configfs/dir.c
45156 --- linux-2.6.39.2/fs/configfs/dir.c 2011-05-19 00:06:34.000000000 -0400
45157 +++ linux-2.6.39.2/fs/configfs/dir.c 2011-05-22 19:36:32.000000000 -0400
45158 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file
45159 }
45160 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
45161 struct configfs_dirent *next;
45162 - const char * name;
45163 + const unsigned char * name;
45164 + char d_name[sizeof(next->s_dentry->d_iname)];
45165 int len;
45166 struct inode *inode = NULL;
45167
45168 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file
45169 continue;
45170
45171 name = configfs_get_name(next);
45172 - len = strlen(name);
45173 + if (next->s_dentry && name == next->s_dentry->d_iname) {
45174 + len = next->s_dentry->d_name.len;
45175 + memcpy(d_name, name, len);
45176 + name = d_name;
45177 + } else
45178 + len = strlen(name);
45179
45180 /*
45181 * We'll have a dentry and an inode for
45182 diff -urNp linux-2.6.39.2/fs/configfs/file.c linux-2.6.39.2/fs/configfs/file.c
45183 --- linux-2.6.39.2/fs/configfs/file.c 2011-05-19 00:06:34.000000000 -0400
45184 +++ linux-2.6.39.2/fs/configfs/file.c 2011-05-22 19:36:32.000000000 -0400
45185 @@ -215,7 +215,7 @@ static int check_perm(struct inode * ino
45186 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
45187 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
45188 struct configfs_buffer * buffer;
45189 - struct configfs_item_operations * ops = NULL;
45190 + struct configfs_item_operations *ops = NULL;
45191 int error = 0;
45192
45193 if (!item || !attr)
45194 diff -urNp linux-2.6.39.2/fs/configfs/item.c linux-2.6.39.2/fs/configfs/item.c
45195 --- linux-2.6.39.2/fs/configfs/item.c 2011-05-19 00:06:34.000000000 -0400
45196 +++ linux-2.6.39.2/fs/configfs/item.c 2011-05-22 19:36:32.000000000 -0400
45197 @@ -123,7 +123,7 @@ void config_item_init_type_name(struct c
45198 EXPORT_SYMBOL(config_item_init_type_name);
45199
45200 void config_group_init_type_name(struct config_group *group, const char *name,
45201 - struct config_item_type *type)
45202 + struct config_item_type *type)
45203 {
45204 config_item_set_name(&group->cg_item, name);
45205 group->cg_item.ci_type = type;
45206 diff -urNp linux-2.6.39.2/fs/dcache.c linux-2.6.39.2/fs/dcache.c
45207 --- linux-2.6.39.2/fs/dcache.c 2011-05-19 00:06:34.000000000 -0400
45208 +++ linux-2.6.39.2/fs/dcache.c 2011-05-22 19:36:32.000000000 -0400
45209 @@ -3069,7 +3069,7 @@ void __init vfs_caches_init(unsigned lon
45210 mempages -= reserve;
45211
45212 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
45213 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
45214 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
45215
45216 dcache_init();
45217 inode_init();
45218 diff -urNp linux-2.6.39.2/fs/dlm/lockspace.c linux-2.6.39.2/fs/dlm/lockspace.c
45219 --- linux-2.6.39.2/fs/dlm/lockspace.c 2011-05-19 00:06:34.000000000 -0400
45220 +++ linux-2.6.39.2/fs/dlm/lockspace.c 2011-05-22 19:36:32.000000000 -0400
45221 @@ -200,7 +200,7 @@ static int dlm_uevent(struct kset *kset,
45222 return 0;
45223 }
45224
45225 -static struct kset_uevent_ops dlm_uevent_ops = {
45226 +static const struct kset_uevent_ops dlm_uevent_ops = {
45227 .uevent = dlm_uevent,
45228 };
45229
45230 diff -urNp linux-2.6.39.2/fs/ecryptfs/inode.c linux-2.6.39.2/fs/ecryptfs/inode.c
45231 --- linux-2.6.39.2/fs/ecryptfs/inode.c 2011-06-03 00:04:14.000000000 -0400
45232 +++ linux-2.6.39.2/fs/ecryptfs/inode.c 2011-06-03 00:32:07.000000000 -0400
45233 @@ -623,7 +623,7 @@ static int ecryptfs_readlink_lower(struc
45234 old_fs = get_fs();
45235 set_fs(get_ds());
45236 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
45237 - (char __user *)lower_buf,
45238 + (__force char __user *)lower_buf,
45239 lower_bufsiz);
45240 set_fs(old_fs);
45241 if (rc < 0)
45242 @@ -669,7 +669,7 @@ static void *ecryptfs_follow_link(struct
45243 }
45244 old_fs = get_fs();
45245 set_fs(get_ds());
45246 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
45247 + rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
45248 set_fs(old_fs);
45249 if (rc < 0) {
45250 kfree(buf);
45251 @@ -684,7 +684,7 @@ out:
45252 static void
45253 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
45254 {
45255 - char *buf = nd_get_link(nd);
45256 + const char *buf = nd_get_link(nd);
45257 if (!IS_ERR(buf)) {
45258 /* Free the char* */
45259 kfree(buf);
45260 diff -urNp linux-2.6.39.2/fs/ecryptfs/miscdev.c linux-2.6.39.2/fs/ecryptfs/miscdev.c
45261 --- linux-2.6.39.2/fs/ecryptfs/miscdev.c 2011-05-19 00:06:34.000000000 -0400
45262 +++ linux-2.6.39.2/fs/ecryptfs/miscdev.c 2011-05-22 19:36:32.000000000 -0400
45263 @@ -328,7 +328,7 @@ check_list:
45264 goto out_unlock_msg_ctx;
45265 i = 5;
45266 if (msg_ctx->msg) {
45267 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
45268 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
45269 goto out_unlock_msg_ctx;
45270 i += packet_length_size;
45271 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
45272 diff -urNp linux-2.6.39.2/fs/exec.c linux-2.6.39.2/fs/exec.c
45273 --- linux-2.6.39.2/fs/exec.c 2011-06-25 12:55:23.000000000 -0400
45274 +++ linux-2.6.39.2/fs/exec.c 2011-06-25 13:00:28.000000000 -0400
45275 @@ -55,12 +55,24 @@
45276 #include <linux/fs_struct.h>
45277 #include <linux/pipe_fs_i.h>
45278 #include <linux/oom.h>
45279 +#include <linux/random.h>
45280 +#include <linux/seq_file.h>
45281 +
45282 +#ifdef CONFIG_PAX_REFCOUNT
45283 +#include <linux/kallsyms.h>
45284 +#include <linux/kdebug.h>
45285 +#endif
45286
45287 #include <asm/uaccess.h>
45288 #include <asm/mmu_context.h>
45289 #include <asm/tlb.h>
45290 #include "internal.h"
45291
45292 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45293 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45294 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45295 +#endif
45296 +
45297 int core_uses_pid;
45298 char core_pattern[CORENAME_MAX_SIZE] = "core";
45299 unsigned int core_pipe_limit;
45300 @@ -70,7 +82,7 @@ struct core_name {
45301 char *corename;
45302 int used, size;
45303 };
45304 -static atomic_t call_count = ATOMIC_INIT(1);
45305 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45306
45307 /* The maximal length of core_pattern is also specified in sysctl.c */
45308
45309 @@ -116,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __use
45310 char *tmp = getname(library);
45311 int error = PTR_ERR(tmp);
45312 static const struct open_flags uselib_flags = {
45313 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45314 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45315 .acc_mode = MAY_READ | MAY_EXEC | MAY_OPEN,
45316 .intent = LOOKUP_OPEN
45317 };
45318 @@ -190,18 +202,10 @@ struct page *get_arg_page(struct linux_b
45319 int write)
45320 {
45321 struct page *page;
45322 - int ret;
45323
45324 -#ifdef CONFIG_STACK_GROWSUP
45325 - if (write) {
45326 - ret = expand_stack_downwards(bprm->vma, pos);
45327 - if (ret < 0)
45328 - return NULL;
45329 - }
45330 -#endif
45331 - ret = get_user_pages(current, bprm->mm, pos,
45332 - 1, write, 1, &page, NULL);
45333 - if (ret <= 0)
45334 + if (0 > expand_stack_downwards(bprm->vma, pos))
45335 + return NULL;
45336 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45337 return NULL;
45338
45339 if (write) {
45340 @@ -276,6 +280,11 @@ static int __bprm_mm_init(struct linux_b
45341 vma->vm_end = STACK_TOP_MAX;
45342 vma->vm_start = vma->vm_end - PAGE_SIZE;
45343 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45344 +
45345 +#ifdef CONFIG_PAX_SEGMEXEC
45346 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45347 +#endif
45348 +
45349 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45350 INIT_LIST_HEAD(&vma->anon_vma_chain);
45351
45352 @@ -290,6 +299,12 @@ static int __bprm_mm_init(struct linux_b
45353 mm->stack_vm = mm->total_vm = 1;
45354 up_write(&mm->mmap_sem);
45355 bprm->p = vma->vm_end - sizeof(void *);
45356 +
45357 +#ifdef CONFIG_PAX_RANDUSTACK
45358 + if (randomize_va_space)
45359 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
45360 +#endif
45361 +
45362 return 0;
45363 err:
45364 up_write(&mm->mmap_sem);
45365 @@ -525,7 +540,7 @@ int copy_strings_kernel(int argc, const
45366 int r;
45367 mm_segment_t oldfs = get_fs();
45368 set_fs(KERNEL_DS);
45369 - r = copy_strings(argc, (const char __user *const __user *)argv, bprm);
45370 + r = copy_strings(argc, (__force const char __user *const __user *)argv, bprm);
45371 set_fs(oldfs);
45372 return r;
45373 }
45374 @@ -555,7 +570,8 @@ static int shift_arg_pages(struct vm_are
45375 unsigned long new_end = old_end - shift;
45376 struct mmu_gather *tlb;
45377
45378 - BUG_ON(new_start > new_end);
45379 + if (new_start >= new_end || new_start < mmap_min_addr)
45380 + return -ENOMEM;
45381
45382 /*
45383 * ensure there are no vmas between where we want to go
45384 @@ -564,6 +580,10 @@ static int shift_arg_pages(struct vm_are
45385 if (vma != find_vma(mm, new_start))
45386 return -EFAULT;
45387
45388 +#ifdef CONFIG_PAX_SEGMEXEC
45389 + BUG_ON(pax_find_mirror_vma(vma));
45390 +#endif
45391 +
45392 /*
45393 * cover the whole range: [new_start, old_end)
45394 */
45395 @@ -644,10 +664,6 @@ int setup_arg_pages(struct linux_binprm
45396 stack_top = arch_align_stack(stack_top);
45397 stack_top = PAGE_ALIGN(stack_top);
45398
45399 - if (unlikely(stack_top < mmap_min_addr) ||
45400 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45401 - return -ENOMEM;
45402 -
45403 stack_shift = vma->vm_end - stack_top;
45404
45405 bprm->p -= stack_shift;
45406 @@ -659,8 +675,28 @@ int setup_arg_pages(struct linux_binprm
45407 bprm->exec -= stack_shift;
45408
45409 down_write(&mm->mmap_sem);
45410 +
45411 + /* Move stack pages down in memory. */
45412 + if (stack_shift) {
45413 + ret = shift_arg_pages(vma, stack_shift);
45414 + if (ret)
45415 + goto out_unlock;
45416 + }
45417 +
45418 vm_flags = VM_STACK_FLAGS;
45419
45420 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45421 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45422 + vm_flags &= ~VM_EXEC;
45423 +
45424 +#ifdef CONFIG_PAX_MPROTECT
45425 + if (mm->pax_flags & MF_PAX_MPROTECT)
45426 + vm_flags &= ~VM_MAYEXEC;
45427 +#endif
45428 +
45429 + }
45430 +#endif
45431 +
45432 /*
45433 * Adjust stack execute permissions; explicitly enable for
45434 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45435 @@ -679,13 +715,6 @@ int setup_arg_pages(struct linux_binprm
45436 goto out_unlock;
45437 BUG_ON(prev != vma);
45438
45439 - /* Move stack pages down in memory. */
45440 - if (stack_shift) {
45441 - ret = shift_arg_pages(vma, stack_shift);
45442 - if (ret)
45443 - goto out_unlock;
45444 - }
45445 -
45446 /* mprotect_fixup is overkill to remove the temporary stack flags */
45447 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45448
45449 @@ -725,7 +754,7 @@ struct file *open_exec(const char *name)
45450 struct file *file;
45451 int err;
45452 static const struct open_flags open_exec_flags = {
45453 - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
45454 + .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC | FMODE_GREXEC,
45455 .acc_mode = MAY_EXEC | MAY_OPEN,
45456 .intent = LOOKUP_OPEN
45457 };
45458 @@ -766,7 +795,7 @@ int kernel_read(struct file *file, loff_
45459 old_fs = get_fs();
45460 set_fs(get_ds());
45461 /* The cast to a user pointer is valid due to the set_fs() */
45462 - result = vfs_read(file, (void __user *)addr, count, &pos);
45463 + result = vfs_read(file, (__force void __user *)addr, count, &pos);
45464 set_fs(old_fs);
45465 return result;
45466 }
45467 @@ -1189,7 +1218,7 @@ int check_unsafe_exec(struct linux_binpr
45468 }
45469 rcu_read_unlock();
45470
45471 - if (p->fs->users > n_fs) {
45472 + if (atomic_read(&p->fs->users) > n_fs) {
45473 bprm->unsafe |= LSM_UNSAFE_SHARE;
45474 } else {
45475 res = -EAGAIN;
45476 @@ -1381,6 +1410,11 @@ int do_execve(const char * filename,
45477 const char __user *const __user *envp,
45478 struct pt_regs * regs)
45479 {
45480 +#ifdef CONFIG_GRKERNSEC
45481 + struct file *old_exec_file;
45482 + struct acl_subject_label *old_acl;
45483 + struct rlimit old_rlim[RLIM_NLIMITS];
45484 +#endif
45485 struct linux_binprm *bprm;
45486 struct file *file;
45487 struct files_struct *displaced;
45488 @@ -1417,6 +1451,23 @@ int do_execve(const char * filename,
45489 bprm->filename = filename;
45490 bprm->interp = filename;
45491
45492 + if (gr_process_user_ban()) {
45493 + retval = -EPERM;
45494 + goto out_file;
45495 + }
45496 +
45497 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45498 +
45499 + if (gr_handle_nproc()) {
45500 + retval = -EAGAIN;
45501 + goto out_file;
45502 + }
45503 +
45504 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45505 + retval = -EACCES;
45506 + goto out_file;
45507 + }
45508 +
45509 retval = bprm_mm_init(bprm);
45510 if (retval)
45511 goto out_file;
45512 @@ -1446,9 +1497,40 @@ int do_execve(const char * filename,
45513 if (retval < 0)
45514 goto out;
45515
45516 + if (!gr_tpe_allow(file)) {
45517 + retval = -EACCES;
45518 + goto out;
45519 + }
45520 +
45521 + if (gr_check_crash_exec(file)) {
45522 + retval = -EACCES;
45523 + goto out;
45524 + }
45525 +
45526 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45527 +
45528 + gr_handle_exec_args(bprm, argv);
45529 +
45530 +#ifdef CONFIG_GRKERNSEC
45531 + old_acl = current->acl;
45532 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45533 + old_exec_file = current->exec_file;
45534 + get_file(file);
45535 + current->exec_file = file;
45536 +#endif
45537 +
45538 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45539 + bprm->unsafe & LSM_UNSAFE_SHARE);
45540 + if (retval < 0)
45541 + goto out_fail;
45542 +
45543 retval = search_binary_handler(bprm,regs);
45544 if (retval < 0)
45545 - goto out;
45546 + goto out_fail;
45547 +#ifdef CONFIG_GRKERNSEC
45548 + if (old_exec_file)
45549 + fput(old_exec_file);
45550 +#endif
45551
45552 /* execve succeeded */
45553 current->fs->in_exec = 0;
45554 @@ -1459,6 +1541,14 @@ int do_execve(const char * filename,
45555 put_files_struct(displaced);
45556 return retval;
45557
45558 +out_fail:
45559 +#ifdef CONFIG_GRKERNSEC
45560 + current->acl = old_acl;
45561 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45562 + fput(current->exec_file);
45563 + current->exec_file = old_exec_file;
45564 +#endif
45565 +
45566 out:
45567 if (bprm->mm) {
45568 acct_arg_size(bprm, 0);
45569 @@ -1504,7 +1594,7 @@ static int expand_corename(struct core_n
45570 {
45571 char *old_corename = cn->corename;
45572
45573 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45574 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45575 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45576
45577 if (!cn->corename) {
45578 @@ -1557,7 +1647,7 @@ static int format_corename(struct core_n
45579 int pid_in_pattern = 0;
45580 int err = 0;
45581
45582 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45583 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45584 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45585 cn->used = 0;
45586
45587 @@ -1645,6 +1735,219 @@ out:
45588 return ispipe;
45589 }
45590
45591 +int pax_check_flags(unsigned long *flags)
45592 +{
45593 + int retval = 0;
45594 +
45595 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45596 + if (*flags & MF_PAX_SEGMEXEC)
45597 + {
45598 + *flags &= ~MF_PAX_SEGMEXEC;
45599 + retval = -EINVAL;
45600 + }
45601 +#endif
45602 +
45603 + if ((*flags & MF_PAX_PAGEEXEC)
45604 +
45605 +#ifdef CONFIG_PAX_PAGEEXEC
45606 + && (*flags & MF_PAX_SEGMEXEC)
45607 +#endif
45608 +
45609 + )
45610 + {
45611 + *flags &= ~MF_PAX_PAGEEXEC;
45612 + retval = -EINVAL;
45613 + }
45614 +
45615 + if ((*flags & MF_PAX_MPROTECT)
45616 +
45617 +#ifdef CONFIG_PAX_MPROTECT
45618 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45619 +#endif
45620 +
45621 + )
45622 + {
45623 + *flags &= ~MF_PAX_MPROTECT;
45624 + retval = -EINVAL;
45625 + }
45626 +
45627 + if ((*flags & MF_PAX_EMUTRAMP)
45628 +
45629 +#ifdef CONFIG_PAX_EMUTRAMP
45630 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45631 +#endif
45632 +
45633 + )
45634 + {
45635 + *flags &= ~MF_PAX_EMUTRAMP;
45636 + retval = -EINVAL;
45637 + }
45638 +
45639 + return retval;
45640 +}
45641 +
45642 +EXPORT_SYMBOL(pax_check_flags);
45643 +
45644 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45645 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45646 +{
45647 + struct task_struct *tsk = current;
45648 + struct mm_struct *mm = current->mm;
45649 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45650 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45651 + char *path_exec = NULL;
45652 + char *path_fault = NULL;
45653 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45654 +
45655 + if (buffer_exec && buffer_fault) {
45656 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45657 +
45658 + down_read(&mm->mmap_sem);
45659 + vma = mm->mmap;
45660 + while (vma && (!vma_exec || !vma_fault)) {
45661 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45662 + vma_exec = vma;
45663 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45664 + vma_fault = vma;
45665 + vma = vma->vm_next;
45666 + }
45667 + if (vma_exec) {
45668 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45669 + if (IS_ERR(path_exec))
45670 + path_exec = "<path too long>";
45671 + else {
45672 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45673 + if (path_exec) {
45674 + *path_exec = 0;
45675 + path_exec = buffer_exec;
45676 + } else
45677 + path_exec = "<path too long>";
45678 + }
45679 + }
45680 + if (vma_fault) {
45681 + start = vma_fault->vm_start;
45682 + end = vma_fault->vm_end;
45683 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45684 + if (vma_fault->vm_file) {
45685 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45686 + if (IS_ERR(path_fault))
45687 + path_fault = "<path too long>";
45688 + else {
45689 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45690 + if (path_fault) {
45691 + *path_fault = 0;
45692 + path_fault = buffer_fault;
45693 + } else
45694 + path_fault = "<path too long>";
45695 + }
45696 + } else
45697 + path_fault = "<anonymous mapping>";
45698 + }
45699 + up_read(&mm->mmap_sem);
45700 + }
45701 + if (tsk->signal->curr_ip)
45702 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45703 + else
45704 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45705 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45706 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45707 + task_uid(tsk), task_euid(tsk), pc, sp);
45708 + free_page((unsigned long)buffer_exec);
45709 + free_page((unsigned long)buffer_fault);
45710 + pax_report_insns(pc, sp);
45711 + do_coredump(SIGKILL, SIGKILL, regs);
45712 +}
45713 +#endif
45714 +
45715 +#ifdef CONFIG_PAX_REFCOUNT
45716 +void pax_report_refcount_overflow(struct pt_regs *regs)
45717 +{
45718 + if (current->signal->curr_ip)
45719 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45720 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45721 + else
45722 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45723 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45724 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45725 + show_regs(regs);
45726 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45727 +}
45728 +#endif
45729 +
45730 +#ifdef CONFIG_PAX_USERCOPY
45731 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45732 +int object_is_on_stack(const void *obj, unsigned long len)
45733 +{
45734 + const void * const stack = task_stack_page(current);
45735 + const void * const stackend = stack + THREAD_SIZE;
45736 +
45737 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45738 + const void *frame = NULL;
45739 + const void *oldframe;
45740 +#endif
45741 +
45742 + if (obj + len < obj)
45743 + return -1;
45744 +
45745 + if (obj + len <= stack || stackend <= obj)
45746 + return 0;
45747 +
45748 + if (obj < stack || stackend < obj + len)
45749 + return -1;
45750 +
45751 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45752 + oldframe = __builtin_frame_address(1);
45753 + if (oldframe)
45754 + frame = __builtin_frame_address(2);
45755 + /*
45756 + low ----------------------------------------------> high
45757 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45758 + ^----------------^
45759 + allow copies only within here
45760 + */
45761 + while (stack <= frame && frame < stackend) {
45762 + /* if obj + len extends past the last frame, this
45763 + check won't pass and the next frame will be 0,
45764 + causing us to bail out and correctly report
45765 + the copy as invalid
45766 + */
45767 + if (obj + len <= frame)
45768 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45769 + oldframe = frame;
45770 + frame = *(const void * const *)frame;
45771 + }
45772 + return -1;
45773 +#else
45774 + return 1;
45775 +#endif
45776 +}
45777 +
45778 +
45779 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45780 +{
45781 + if (current->signal->curr_ip)
45782 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45783 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45784 + else
45785 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45786 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45787 + dump_stack();
45788 + gr_handle_kernel_exploit();
45789 + do_group_exit(SIGKILL);
45790 +}
45791 +#endif
45792 +
45793 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45794 +void pax_track_stack(void)
45795 +{
45796 + unsigned long sp = (unsigned long)&sp;
45797 + if (sp < current_thread_info()->lowest_stack &&
45798 + sp > (unsigned long)task_stack_page(current))
45799 + current_thread_info()->lowest_stack = sp;
45800 +}
45801 +EXPORT_SYMBOL(pax_track_stack);
45802 +#endif
45803 +
45804 static int zap_process(struct task_struct *start, int exit_code)
45805 {
45806 struct task_struct *t;
45807 @@ -1855,17 +2158,17 @@ static void wait_for_dump_helpers(struct
45808 pipe = file->f_path.dentry->d_inode->i_pipe;
45809
45810 pipe_lock(pipe);
45811 - pipe->readers++;
45812 - pipe->writers--;
45813 + atomic_inc(&pipe->readers);
45814 + atomic_dec(&pipe->writers);
45815
45816 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45817 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45818 wake_up_interruptible_sync(&pipe->wait);
45819 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45820 pipe_wait(pipe);
45821 }
45822
45823 - pipe->readers--;
45824 - pipe->writers++;
45825 + atomic_dec(&pipe->readers);
45826 + atomic_inc(&pipe->writers);
45827 pipe_unlock(pipe);
45828
45829 }
45830 @@ -1926,7 +2229,7 @@ void do_coredump(long signr, int exit_co
45831 int retval = 0;
45832 int flag = 0;
45833 int ispipe;
45834 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45835 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45836 struct coredump_params cprm = {
45837 .signr = signr,
45838 .regs = regs,
45839 @@ -1941,6 +2244,9 @@ void do_coredump(long signr, int exit_co
45840
45841 audit_core_dumps(signr);
45842
45843 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45844 + gr_handle_brute_attach(current, cprm.mm_flags);
45845 +
45846 binfmt = mm->binfmt;
45847 if (!binfmt || !binfmt->core_dump)
45848 goto fail;
45849 @@ -1981,6 +2287,8 @@ void do_coredump(long signr, int exit_co
45850 goto fail_corename;
45851 }
45852
45853 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45854 +
45855 if (ispipe) {
45856 int dump_count;
45857 char **helper_argv;
45858 @@ -2008,7 +2316,7 @@ void do_coredump(long signr, int exit_co
45859 }
45860 cprm.limit = RLIM_INFINITY;
45861
45862 - dump_count = atomic_inc_return(&core_dump_count);
45863 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45864 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45865 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45866 task_tgid_vnr(current), current->comm);
45867 @@ -2078,7 +2386,7 @@ close_fail:
45868 filp_close(cprm.file, NULL);
45869 fail_dropcount:
45870 if (ispipe)
45871 - atomic_dec(&core_dump_count);
45872 + atomic_dec_unchecked(&core_dump_count);
45873 fail_unlock:
45874 kfree(cn.corename);
45875 fail_corename:
45876 diff -urNp linux-2.6.39.2/fs/ext2/balloc.c linux-2.6.39.2/fs/ext2/balloc.c
45877 --- linux-2.6.39.2/fs/ext2/balloc.c 2011-05-19 00:06:34.000000000 -0400
45878 +++ linux-2.6.39.2/fs/ext2/balloc.c 2011-05-22 19:41:37.000000000 -0400
45879 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
45880
45881 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45882 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45883 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45884 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45885 sbi->s_resuid != current_fsuid() &&
45886 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45887 return 0;
45888 diff -urNp linux-2.6.39.2/fs/ext3/balloc.c linux-2.6.39.2/fs/ext3/balloc.c
45889 --- linux-2.6.39.2/fs/ext3/balloc.c 2011-05-19 00:06:34.000000000 -0400
45890 +++ linux-2.6.39.2/fs/ext3/balloc.c 2011-05-22 19:41:37.000000000 -0400
45891 @@ -1441,7 +1441,7 @@ static int ext3_has_free_blocks(struct e
45892
45893 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45894 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45895 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45896 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45897 sbi->s_resuid != current_fsuid() &&
45898 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45899 return 0;
45900 diff -urNp linux-2.6.39.2/fs/ext4/balloc.c linux-2.6.39.2/fs/ext4/balloc.c
45901 --- linux-2.6.39.2/fs/ext4/balloc.c 2011-05-19 00:06:34.000000000 -0400
45902 +++ linux-2.6.39.2/fs/ext4/balloc.c 2011-05-22 19:41:37.000000000 -0400
45903 @@ -522,7 +522,7 @@ static int ext4_has_free_blocks(struct e
45904 /* Hm, nope. Are (enough) root reserved blocks available? */
45905 if (sbi->s_resuid == current_fsuid() ||
45906 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45907 - capable(CAP_SYS_RESOURCE)) {
45908 + capable_nolog(CAP_SYS_RESOURCE)) {
45909 if (free_blocks >= (nblocks + dirty_blocks))
45910 return 1;
45911 }
45912 diff -urNp linux-2.6.39.2/fs/ext4/ext4.h linux-2.6.39.2/fs/ext4/ext4.h
45913 --- linux-2.6.39.2/fs/ext4/ext4.h 2011-06-03 00:04:14.000000000 -0400
45914 +++ linux-2.6.39.2/fs/ext4/ext4.h 2011-06-03 00:32:07.000000000 -0400
45915 @@ -1166,19 +1166,19 @@ struct ext4_sb_info {
45916 unsigned long s_mb_last_start;
45917
45918 /* stats for buddy allocator */
45919 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45920 - atomic_t s_bal_success; /* we found long enough chunks */
45921 - atomic_t s_bal_allocated; /* in blocks */
45922 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45923 - atomic_t s_bal_goals; /* goal hits */
45924 - atomic_t s_bal_breaks; /* too long searches */
45925 - atomic_t s_bal_2orders; /* 2^order hits */
45926 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45927 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45928 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45929 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45930 + atomic_unchecked_t s_bal_goals; /* goal hits */
45931 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45932 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45933 spinlock_t s_bal_lock;
45934 unsigned long s_mb_buddies_generated;
45935 unsigned long long s_mb_generation_time;
45936 - atomic_t s_mb_lost_chunks;
45937 - atomic_t s_mb_preallocated;
45938 - atomic_t s_mb_discarded;
45939 + atomic_unchecked_t s_mb_lost_chunks;
45940 + atomic_unchecked_t s_mb_preallocated;
45941 + atomic_unchecked_t s_mb_discarded;
45942 atomic_t s_lock_busy;
45943
45944 /* locality groups */
45945 diff -urNp linux-2.6.39.2/fs/ext4/mballoc.c linux-2.6.39.2/fs/ext4/mballoc.c
45946 --- linux-2.6.39.2/fs/ext4/mballoc.c 2011-06-03 00:04:14.000000000 -0400
45947 +++ linux-2.6.39.2/fs/ext4/mballoc.c 2011-06-03 00:32:07.000000000 -0400
45948 @@ -1853,7 +1853,7 @@ void ext4_mb_simple_scan_group(struct ex
45949 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45950
45951 if (EXT4_SB(sb)->s_mb_stats)
45952 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45953 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45954
45955 break;
45956 }
45957 @@ -2147,7 +2147,7 @@ repeat:
45958 ac->ac_status = AC_STATUS_CONTINUE;
45959 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45960 cr = 3;
45961 - atomic_inc(&sbi->s_mb_lost_chunks);
45962 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45963 goto repeat;
45964 }
45965 }
45966 @@ -2190,6 +2190,8 @@ static int ext4_mb_seq_groups_show(struc
45967 ext4_grpblk_t counters[16];
45968 } sg;
45969
45970 + pax_track_stack();
45971 +
45972 group--;
45973 if (group == 0)
45974 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
45975 @@ -2613,25 +2615,25 @@ int ext4_mb_release(struct super_block *
45976 if (sbi->s_mb_stats) {
45977 printk(KERN_INFO
45978 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
45979 - atomic_read(&sbi->s_bal_allocated),
45980 - atomic_read(&sbi->s_bal_reqs),
45981 - atomic_read(&sbi->s_bal_success));
45982 + atomic_read_unchecked(&sbi->s_bal_allocated),
45983 + atomic_read_unchecked(&sbi->s_bal_reqs),
45984 + atomic_read_unchecked(&sbi->s_bal_success));
45985 printk(KERN_INFO
45986 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
45987 "%u 2^N hits, %u breaks, %u lost\n",
45988 - atomic_read(&sbi->s_bal_ex_scanned),
45989 - atomic_read(&sbi->s_bal_goals),
45990 - atomic_read(&sbi->s_bal_2orders),
45991 - atomic_read(&sbi->s_bal_breaks),
45992 - atomic_read(&sbi->s_mb_lost_chunks));
45993 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45994 + atomic_read_unchecked(&sbi->s_bal_goals),
45995 + atomic_read_unchecked(&sbi->s_bal_2orders),
45996 + atomic_read_unchecked(&sbi->s_bal_breaks),
45997 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45998 printk(KERN_INFO
45999 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
46000 sbi->s_mb_buddies_generated++,
46001 sbi->s_mb_generation_time);
46002 printk(KERN_INFO
46003 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
46004 - atomic_read(&sbi->s_mb_preallocated),
46005 - atomic_read(&sbi->s_mb_discarded));
46006 + atomic_read_unchecked(&sbi->s_mb_preallocated),
46007 + atomic_read_unchecked(&sbi->s_mb_discarded));
46008 }
46009
46010 free_percpu(sbi->s_locality_groups);
46011 @@ -3107,16 +3109,16 @@ static void ext4_mb_collect_stats(struct
46012 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
46013
46014 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
46015 - atomic_inc(&sbi->s_bal_reqs);
46016 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46017 + atomic_inc_unchecked(&sbi->s_bal_reqs);
46018 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
46019 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
46020 - atomic_inc(&sbi->s_bal_success);
46021 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
46022 + atomic_inc_unchecked(&sbi->s_bal_success);
46023 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
46024 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
46025 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
46026 - atomic_inc(&sbi->s_bal_goals);
46027 + atomic_inc_unchecked(&sbi->s_bal_goals);
46028 if (ac->ac_found > sbi->s_mb_max_to_scan)
46029 - atomic_inc(&sbi->s_bal_breaks);
46030 + atomic_inc_unchecked(&sbi->s_bal_breaks);
46031 }
46032
46033 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
46034 @@ -3514,7 +3516,7 @@ ext4_mb_new_inode_pa(struct ext4_allocat
46035 trace_ext4_mb_new_inode_pa(ac, pa);
46036
46037 ext4_mb_use_inode_pa(ac, pa);
46038 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46039 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46040
46041 ei = EXT4_I(ac->ac_inode);
46042 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46043 @@ -3574,7 +3576,7 @@ ext4_mb_new_group_pa(struct ext4_allocat
46044 trace_ext4_mb_new_group_pa(ac, pa);
46045
46046 ext4_mb_use_group_pa(ac, pa);
46047 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46048 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
46049
46050 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
46051 lg = ac->ac_lg;
46052 @@ -3661,7 +3663,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
46053 * from the bitmap and continue.
46054 */
46055 }
46056 - atomic_add(free, &sbi->s_mb_discarded);
46057 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
46058
46059 return err;
46060 }
46061 @@ -3679,7 +3681,7 @@ ext4_mb_release_group_pa(struct ext4_bud
46062 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
46063 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
46064 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
46065 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46066 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
46067 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
46068
46069 return 0;
46070 diff -urNp linux-2.6.39.2/fs/fcntl.c linux-2.6.39.2/fs/fcntl.c
46071 --- linux-2.6.39.2/fs/fcntl.c 2011-05-19 00:06:34.000000000 -0400
46072 +++ linux-2.6.39.2/fs/fcntl.c 2011-05-22 20:45:50.000000000 -0400
46073 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct
46074 if (err)
46075 return err;
46076
46077 + if (gr_handle_chroot_fowner(pid, type))
46078 + return -ENOENT;
46079 + if (gr_check_protected_task_fowner(pid, type))
46080 + return -EACCES;
46081 +
46082 f_modown(filp, pid, type, force);
46083 return 0;
46084 }
46085 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned in
46086 switch (cmd) {
46087 case F_DUPFD:
46088 case F_DUPFD_CLOEXEC:
46089 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
46090 if (arg >= rlimit(RLIMIT_NOFILE))
46091 break;
46092 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46093 @@ -835,14 +841,14 @@ static int __init fcntl_init(void)
46094 * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
46095 * is defined as O_NONBLOCK on some platforms and not on others.
46096 */
46097 - BUILD_BUG_ON(19 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46098 + BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
46099 O_RDONLY | O_WRONLY | O_RDWR |
46100 O_CREAT | O_EXCL | O_NOCTTY |
46101 O_TRUNC | O_APPEND | /* O_NONBLOCK | */
46102 __O_SYNC | O_DSYNC | FASYNC |
46103 O_DIRECT | O_LARGEFILE | O_DIRECTORY |
46104 O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
46105 - __FMODE_EXEC | O_PATH
46106 + __FMODE_EXEC | O_PATH | FMODE_GREXEC
46107 ));
46108
46109 fasync_cache = kmem_cache_create("fasync_cache",
46110 diff -urNp linux-2.6.39.2/fs/fifo.c linux-2.6.39.2/fs/fifo.c
46111 --- linux-2.6.39.2/fs/fifo.c 2011-05-19 00:06:34.000000000 -0400
46112 +++ linux-2.6.39.2/fs/fifo.c 2011-05-22 19:36:32.000000000 -0400
46113 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode
46114 */
46115 filp->f_op = &read_pipefifo_fops;
46116 pipe->r_counter++;
46117 - if (pipe->readers++ == 0)
46118 + if (atomic_inc_return(&pipe->readers) == 1)
46119 wake_up_partner(inode);
46120
46121 - if (!pipe->writers) {
46122 + if (!atomic_read(&pipe->writers)) {
46123 if ((filp->f_flags & O_NONBLOCK)) {
46124 /* suppress POLLHUP until we have
46125 * seen a writer */
46126 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode
46127 * errno=ENXIO when there is no process reading the FIFO.
46128 */
46129 ret = -ENXIO;
46130 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46131 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46132 goto err;
46133
46134 filp->f_op = &write_pipefifo_fops;
46135 pipe->w_counter++;
46136 - if (!pipe->writers++)
46137 + if (atomic_inc_return(&pipe->writers) == 1)
46138 wake_up_partner(inode);
46139
46140 - if (!pipe->readers) {
46141 + if (!atomic_read(&pipe->readers)) {
46142 wait_for_partner(inode, &pipe->r_counter);
46143 if (signal_pending(current))
46144 goto err_wr;
46145 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode
46146 */
46147 filp->f_op = &rdwr_pipefifo_fops;
46148
46149 - pipe->readers++;
46150 - pipe->writers++;
46151 + atomic_inc(&pipe->readers);
46152 + atomic_inc(&pipe->writers);
46153 pipe->r_counter++;
46154 pipe->w_counter++;
46155 - if (pipe->readers == 1 || pipe->writers == 1)
46156 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46157 wake_up_partner(inode);
46158 break;
46159
46160 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode
46161 return 0;
46162
46163 err_rd:
46164 - if (!--pipe->readers)
46165 + if (atomic_dec_and_test(&pipe->readers))
46166 wake_up_interruptible(&pipe->wait);
46167 ret = -ERESTARTSYS;
46168 goto err;
46169
46170 err_wr:
46171 - if (!--pipe->writers)
46172 + if (atomic_dec_and_test(&pipe->writers))
46173 wake_up_interruptible(&pipe->wait);
46174 ret = -ERESTARTSYS;
46175 goto err;
46176
46177 err:
46178 - if (!pipe->readers && !pipe->writers)
46179 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46180 free_pipe_info(inode);
46181
46182 err_nocleanup:
46183 diff -urNp linux-2.6.39.2/fs/file.c linux-2.6.39.2/fs/file.c
46184 --- linux-2.6.39.2/fs/file.c 2011-05-19 00:06:34.000000000 -0400
46185 +++ linux-2.6.39.2/fs/file.c 2011-05-22 19:41:37.000000000 -0400
46186 @@ -15,6 +15,7 @@
46187 #include <linux/slab.h>
46188 #include <linux/vmalloc.h>
46189 #include <linux/file.h>
46190 +#include <linux/security.h>
46191 #include <linux/fdtable.h>
46192 #include <linux/bitops.h>
46193 #include <linux/interrupt.h>
46194 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *fi
46195 * N.B. For clone tasks sharing a files structure, this test
46196 * will limit the total number of files that can be opened.
46197 */
46198 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46199 if (nr >= rlimit(RLIMIT_NOFILE))
46200 return -EMFILE;
46201
46202 diff -urNp linux-2.6.39.2/fs/filesystems.c linux-2.6.39.2/fs/filesystems.c
46203 --- linux-2.6.39.2/fs/filesystems.c 2011-05-19 00:06:34.000000000 -0400
46204 +++ linux-2.6.39.2/fs/filesystems.c 2011-05-22 19:41:37.000000000 -0400
46205 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(con
46206 int len = dot ? dot - name : strlen(name);
46207
46208 fs = __get_fs_type(name, len);
46209 +
46210 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46211 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46212 +#else
46213 if (!fs && (request_module("%.*s", len, name) == 0))
46214 +#endif
46215 fs = __get_fs_type(name, len);
46216
46217 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46218 diff -urNp linux-2.6.39.2/fs/fscache/cookie.c linux-2.6.39.2/fs/fscache/cookie.c
46219 --- linux-2.6.39.2/fs/fscache/cookie.c 2011-05-19 00:06:34.000000000 -0400
46220 +++ linux-2.6.39.2/fs/fscache/cookie.c 2011-05-22 19:36:32.000000000 -0400
46221 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire
46222 parent ? (char *) parent->def->name : "<no-parent>",
46223 def->name, netfs_data);
46224
46225 - fscache_stat(&fscache_n_acquires);
46226 + fscache_stat_unchecked(&fscache_n_acquires);
46227
46228 /* if there's no parent cookie, then we don't create one here either */
46229 if (!parent) {
46230 - fscache_stat(&fscache_n_acquires_null);
46231 + fscache_stat_unchecked(&fscache_n_acquires_null);
46232 _leave(" [no parent]");
46233 return NULL;
46234 }
46235 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire
46236 /* allocate and initialise a cookie */
46237 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46238 if (!cookie) {
46239 - fscache_stat(&fscache_n_acquires_oom);
46240 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46241 _leave(" [ENOMEM]");
46242 return NULL;
46243 }
46244 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire
46245
46246 switch (cookie->def->type) {
46247 case FSCACHE_COOKIE_TYPE_INDEX:
46248 - fscache_stat(&fscache_n_cookie_index);
46249 + fscache_stat_unchecked(&fscache_n_cookie_index);
46250 break;
46251 case FSCACHE_COOKIE_TYPE_DATAFILE:
46252 - fscache_stat(&fscache_n_cookie_data);
46253 + fscache_stat_unchecked(&fscache_n_cookie_data);
46254 break;
46255 default:
46256 - fscache_stat(&fscache_n_cookie_special);
46257 + fscache_stat_unchecked(&fscache_n_cookie_special);
46258 break;
46259 }
46260
46261 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire
46262 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46263 atomic_dec(&parent->n_children);
46264 __fscache_cookie_put(cookie);
46265 - fscache_stat(&fscache_n_acquires_nobufs);
46266 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46267 _leave(" = NULL");
46268 return NULL;
46269 }
46270 }
46271
46272 - fscache_stat(&fscache_n_acquires_ok);
46273 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46274 _leave(" = %p", cookie);
46275 return cookie;
46276 }
46277 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_coo
46278 cache = fscache_select_cache_for_object(cookie->parent);
46279 if (!cache) {
46280 up_read(&fscache_addremove_sem);
46281 - fscache_stat(&fscache_n_acquires_no_cache);
46282 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46283 _leave(" = -ENOMEDIUM [no cache]");
46284 return -ENOMEDIUM;
46285 }
46286 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct f
46287 object = cache->ops->alloc_object(cache, cookie);
46288 fscache_stat_d(&fscache_n_cop_alloc_object);
46289 if (IS_ERR(object)) {
46290 - fscache_stat(&fscache_n_object_no_alloc);
46291 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46292 ret = PTR_ERR(object);
46293 goto error;
46294 }
46295
46296 - fscache_stat(&fscache_n_object_alloc);
46297 + fscache_stat_unchecked(&fscache_n_object_alloc);
46298
46299 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46300
46301 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fsca
46302 struct fscache_object *object;
46303 struct hlist_node *_p;
46304
46305 - fscache_stat(&fscache_n_updates);
46306 + fscache_stat_unchecked(&fscache_n_updates);
46307
46308 if (!cookie) {
46309 - fscache_stat(&fscache_n_updates_null);
46310 + fscache_stat_unchecked(&fscache_n_updates_null);
46311 _leave(" [no cookie]");
46312 return;
46313 }
46314 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct
46315 struct fscache_object *object;
46316 unsigned long event;
46317
46318 - fscache_stat(&fscache_n_relinquishes);
46319 + fscache_stat_unchecked(&fscache_n_relinquishes);
46320 if (retire)
46321 - fscache_stat(&fscache_n_relinquishes_retire);
46322 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46323
46324 if (!cookie) {
46325 - fscache_stat(&fscache_n_relinquishes_null);
46326 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46327 _leave(" [no cookie]");
46328 return;
46329 }
46330 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct
46331
46332 /* wait for the cookie to finish being instantiated (or to fail) */
46333 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46334 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46335 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46336 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46337 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46338 }
46339 diff -urNp linux-2.6.39.2/fs/fscache/internal.h linux-2.6.39.2/fs/fscache/internal.h
46340 --- linux-2.6.39.2/fs/fscache/internal.h 2011-05-19 00:06:34.000000000 -0400
46341 +++ linux-2.6.39.2/fs/fscache/internal.h 2011-05-22 19:36:32.000000000 -0400
46342 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46343 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46344 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46345
46346 -extern atomic_t fscache_n_op_pend;
46347 -extern atomic_t fscache_n_op_run;
46348 -extern atomic_t fscache_n_op_enqueue;
46349 -extern atomic_t fscache_n_op_deferred_release;
46350 -extern atomic_t fscache_n_op_release;
46351 -extern atomic_t fscache_n_op_gc;
46352 -extern atomic_t fscache_n_op_cancelled;
46353 -extern atomic_t fscache_n_op_rejected;
46354 -
46355 -extern atomic_t fscache_n_attr_changed;
46356 -extern atomic_t fscache_n_attr_changed_ok;
46357 -extern atomic_t fscache_n_attr_changed_nobufs;
46358 -extern atomic_t fscache_n_attr_changed_nomem;
46359 -extern atomic_t fscache_n_attr_changed_calls;
46360 -
46361 -extern atomic_t fscache_n_allocs;
46362 -extern atomic_t fscache_n_allocs_ok;
46363 -extern atomic_t fscache_n_allocs_wait;
46364 -extern atomic_t fscache_n_allocs_nobufs;
46365 -extern atomic_t fscache_n_allocs_intr;
46366 -extern atomic_t fscache_n_allocs_object_dead;
46367 -extern atomic_t fscache_n_alloc_ops;
46368 -extern atomic_t fscache_n_alloc_op_waits;
46369 -
46370 -extern atomic_t fscache_n_retrievals;
46371 -extern atomic_t fscache_n_retrievals_ok;
46372 -extern atomic_t fscache_n_retrievals_wait;
46373 -extern atomic_t fscache_n_retrievals_nodata;
46374 -extern atomic_t fscache_n_retrievals_nobufs;
46375 -extern atomic_t fscache_n_retrievals_intr;
46376 -extern atomic_t fscache_n_retrievals_nomem;
46377 -extern atomic_t fscache_n_retrievals_object_dead;
46378 -extern atomic_t fscache_n_retrieval_ops;
46379 -extern atomic_t fscache_n_retrieval_op_waits;
46380 -
46381 -extern atomic_t fscache_n_stores;
46382 -extern atomic_t fscache_n_stores_ok;
46383 -extern atomic_t fscache_n_stores_again;
46384 -extern atomic_t fscache_n_stores_nobufs;
46385 -extern atomic_t fscache_n_stores_oom;
46386 -extern atomic_t fscache_n_store_ops;
46387 -extern atomic_t fscache_n_store_calls;
46388 -extern atomic_t fscache_n_store_pages;
46389 -extern atomic_t fscache_n_store_radix_deletes;
46390 -extern atomic_t fscache_n_store_pages_over_limit;
46391 -
46392 -extern atomic_t fscache_n_store_vmscan_not_storing;
46393 -extern atomic_t fscache_n_store_vmscan_gone;
46394 -extern atomic_t fscache_n_store_vmscan_busy;
46395 -extern atomic_t fscache_n_store_vmscan_cancelled;
46396 -
46397 -extern atomic_t fscache_n_marks;
46398 -extern atomic_t fscache_n_uncaches;
46399 -
46400 -extern atomic_t fscache_n_acquires;
46401 -extern atomic_t fscache_n_acquires_null;
46402 -extern atomic_t fscache_n_acquires_no_cache;
46403 -extern atomic_t fscache_n_acquires_ok;
46404 -extern atomic_t fscache_n_acquires_nobufs;
46405 -extern atomic_t fscache_n_acquires_oom;
46406 -
46407 -extern atomic_t fscache_n_updates;
46408 -extern atomic_t fscache_n_updates_null;
46409 -extern atomic_t fscache_n_updates_run;
46410 -
46411 -extern atomic_t fscache_n_relinquishes;
46412 -extern atomic_t fscache_n_relinquishes_null;
46413 -extern atomic_t fscache_n_relinquishes_waitcrt;
46414 -extern atomic_t fscache_n_relinquishes_retire;
46415 -
46416 -extern atomic_t fscache_n_cookie_index;
46417 -extern atomic_t fscache_n_cookie_data;
46418 -extern atomic_t fscache_n_cookie_special;
46419 -
46420 -extern atomic_t fscache_n_object_alloc;
46421 -extern atomic_t fscache_n_object_no_alloc;
46422 -extern atomic_t fscache_n_object_lookups;
46423 -extern atomic_t fscache_n_object_lookups_negative;
46424 -extern atomic_t fscache_n_object_lookups_positive;
46425 -extern atomic_t fscache_n_object_lookups_timed_out;
46426 -extern atomic_t fscache_n_object_created;
46427 -extern atomic_t fscache_n_object_avail;
46428 -extern atomic_t fscache_n_object_dead;
46429 -
46430 -extern atomic_t fscache_n_checkaux_none;
46431 -extern atomic_t fscache_n_checkaux_okay;
46432 -extern atomic_t fscache_n_checkaux_update;
46433 -extern atomic_t fscache_n_checkaux_obsolete;
46434 +extern atomic_unchecked_t fscache_n_op_pend;
46435 +extern atomic_unchecked_t fscache_n_op_run;
46436 +extern atomic_unchecked_t fscache_n_op_enqueue;
46437 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46438 +extern atomic_unchecked_t fscache_n_op_release;
46439 +extern atomic_unchecked_t fscache_n_op_gc;
46440 +extern atomic_unchecked_t fscache_n_op_cancelled;
46441 +extern atomic_unchecked_t fscache_n_op_rejected;
46442 +
46443 +extern atomic_unchecked_t fscache_n_attr_changed;
46444 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46445 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46446 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46447 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46448 +
46449 +extern atomic_unchecked_t fscache_n_allocs;
46450 +extern atomic_unchecked_t fscache_n_allocs_ok;
46451 +extern atomic_unchecked_t fscache_n_allocs_wait;
46452 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46453 +extern atomic_unchecked_t fscache_n_allocs_intr;
46454 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46455 +extern atomic_unchecked_t fscache_n_alloc_ops;
46456 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46457 +
46458 +extern atomic_unchecked_t fscache_n_retrievals;
46459 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46460 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46461 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46462 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46463 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46464 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46465 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46466 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46467 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46468 +
46469 +extern atomic_unchecked_t fscache_n_stores;
46470 +extern atomic_unchecked_t fscache_n_stores_ok;
46471 +extern atomic_unchecked_t fscache_n_stores_again;
46472 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46473 +extern atomic_unchecked_t fscache_n_stores_oom;
46474 +extern atomic_unchecked_t fscache_n_store_ops;
46475 +extern atomic_unchecked_t fscache_n_store_calls;
46476 +extern atomic_unchecked_t fscache_n_store_pages;
46477 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46478 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46479 +
46480 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46481 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46482 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46483 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46484 +
46485 +extern atomic_unchecked_t fscache_n_marks;
46486 +extern atomic_unchecked_t fscache_n_uncaches;
46487 +
46488 +extern atomic_unchecked_t fscache_n_acquires;
46489 +extern atomic_unchecked_t fscache_n_acquires_null;
46490 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46491 +extern atomic_unchecked_t fscache_n_acquires_ok;
46492 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46493 +extern atomic_unchecked_t fscache_n_acquires_oom;
46494 +
46495 +extern atomic_unchecked_t fscache_n_updates;
46496 +extern atomic_unchecked_t fscache_n_updates_null;
46497 +extern atomic_unchecked_t fscache_n_updates_run;
46498 +
46499 +extern atomic_unchecked_t fscache_n_relinquishes;
46500 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46501 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46502 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46503 +
46504 +extern atomic_unchecked_t fscache_n_cookie_index;
46505 +extern atomic_unchecked_t fscache_n_cookie_data;
46506 +extern atomic_unchecked_t fscache_n_cookie_special;
46507 +
46508 +extern atomic_unchecked_t fscache_n_object_alloc;
46509 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46510 +extern atomic_unchecked_t fscache_n_object_lookups;
46511 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46512 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46513 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46514 +extern atomic_unchecked_t fscache_n_object_created;
46515 +extern atomic_unchecked_t fscache_n_object_avail;
46516 +extern atomic_unchecked_t fscache_n_object_dead;
46517 +
46518 +extern atomic_unchecked_t fscache_n_checkaux_none;
46519 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46520 +extern atomic_unchecked_t fscache_n_checkaux_update;
46521 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46522
46523 extern atomic_t fscache_n_cop_alloc_object;
46524 extern atomic_t fscache_n_cop_lookup_object;
46525 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t
46526 atomic_inc(stat);
46527 }
46528
46529 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46530 +{
46531 + atomic_inc_unchecked(stat);
46532 +}
46533 +
46534 static inline void fscache_stat_d(atomic_t *stat)
46535 {
46536 atomic_dec(stat);
46537 @@ -267,6 +272,7 @@ extern const struct file_operations fsca
46538
46539 #define __fscache_stat(stat) (NULL)
46540 #define fscache_stat(stat) do {} while (0)
46541 +#define fscache_stat_unchecked(stat) do {} while (0)
46542 #define fscache_stat_d(stat) do {} while (0)
46543 #endif
46544
46545 diff -urNp linux-2.6.39.2/fs/fscache/object.c linux-2.6.39.2/fs/fscache/object.c
46546 --- linux-2.6.39.2/fs/fscache/object.c 2011-05-19 00:06:34.000000000 -0400
46547 +++ linux-2.6.39.2/fs/fscache/object.c 2011-05-22 19:36:32.000000000 -0400
46548 @@ -128,7 +128,7 @@ static void fscache_object_state_machine
46549 /* update the object metadata on disk */
46550 case FSCACHE_OBJECT_UPDATING:
46551 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46552 - fscache_stat(&fscache_n_updates_run);
46553 + fscache_stat_unchecked(&fscache_n_updates_run);
46554 fscache_stat(&fscache_n_cop_update_object);
46555 object->cache->ops->update_object(object);
46556 fscache_stat_d(&fscache_n_cop_update_object);
46557 @@ -217,7 +217,7 @@ static void fscache_object_state_machine
46558 spin_lock(&object->lock);
46559 object->state = FSCACHE_OBJECT_DEAD;
46560 spin_unlock(&object->lock);
46561 - fscache_stat(&fscache_n_object_dead);
46562 + fscache_stat_unchecked(&fscache_n_object_dead);
46563 goto terminal_transit;
46564
46565 /* handle the parent cache of this object being withdrawn from
46566 @@ -232,7 +232,7 @@ static void fscache_object_state_machine
46567 spin_lock(&object->lock);
46568 object->state = FSCACHE_OBJECT_DEAD;
46569 spin_unlock(&object->lock);
46570 - fscache_stat(&fscache_n_object_dead);
46571 + fscache_stat_unchecked(&fscache_n_object_dead);
46572 goto terminal_transit;
46573
46574 /* complain about the object being woken up once it is
46575 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct
46576 parent->cookie->def->name, cookie->def->name,
46577 object->cache->tag->name);
46578
46579 - fscache_stat(&fscache_n_object_lookups);
46580 + fscache_stat_unchecked(&fscache_n_object_lookups);
46581 fscache_stat(&fscache_n_cop_lookup_object);
46582 ret = object->cache->ops->lookup_object(object);
46583 fscache_stat_d(&fscache_n_cop_lookup_object);
46584 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct
46585 if (ret == -ETIMEDOUT) {
46586 /* probably stuck behind another object, so move this one to
46587 * the back of the queue */
46588 - fscache_stat(&fscache_n_object_lookups_timed_out);
46589 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46590 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46591 }
46592
46593 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(stru
46594
46595 spin_lock(&object->lock);
46596 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46597 - fscache_stat(&fscache_n_object_lookups_negative);
46598 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46599
46600 /* transit here to allow write requests to begin stacking up
46601 * and read requests to begin returning ENODATA */
46602 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fsca
46603 * result, in which case there may be data available */
46604 spin_lock(&object->lock);
46605 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46606 - fscache_stat(&fscache_n_object_lookups_positive);
46607 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46608
46609 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46610
46611 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fsca
46612 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46613 } else {
46614 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46615 - fscache_stat(&fscache_n_object_created);
46616 + fscache_stat_unchecked(&fscache_n_object_created);
46617
46618 object->state = FSCACHE_OBJECT_AVAILABLE;
46619 spin_unlock(&object->lock);
46620 @@ -602,7 +602,7 @@ static void fscache_object_available(str
46621 fscache_enqueue_dependents(object);
46622
46623 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46624 - fscache_stat(&fscache_n_object_avail);
46625 + fscache_stat_unchecked(&fscache_n_object_avail);
46626
46627 _leave("");
46628 }
46629 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(
46630 enum fscache_checkaux result;
46631
46632 if (!object->cookie->def->check_aux) {
46633 - fscache_stat(&fscache_n_checkaux_none);
46634 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46635 return FSCACHE_CHECKAUX_OKAY;
46636 }
46637
46638 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(
46639 switch (result) {
46640 /* entry okay as is */
46641 case FSCACHE_CHECKAUX_OKAY:
46642 - fscache_stat(&fscache_n_checkaux_okay);
46643 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46644 break;
46645
46646 /* entry requires update */
46647 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46648 - fscache_stat(&fscache_n_checkaux_update);
46649 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46650 break;
46651
46652 /* entry requires deletion */
46653 case FSCACHE_CHECKAUX_OBSOLETE:
46654 - fscache_stat(&fscache_n_checkaux_obsolete);
46655 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46656 break;
46657
46658 default:
46659 diff -urNp linux-2.6.39.2/fs/fscache/operation.c linux-2.6.39.2/fs/fscache/operation.c
46660 --- linux-2.6.39.2/fs/fscache/operation.c 2011-05-19 00:06:34.000000000 -0400
46661 +++ linux-2.6.39.2/fs/fscache/operation.c 2011-05-22 19:36:32.000000000 -0400
46662 @@ -17,7 +17,7 @@
46663 #include <linux/slab.h>
46664 #include "internal.h"
46665
46666 -atomic_t fscache_op_debug_id;
46667 +atomic_unchecked_t fscache_op_debug_id;
46668 EXPORT_SYMBOL(fscache_op_debug_id);
46669
46670 /**
46671 @@ -40,7 +40,7 @@ void fscache_enqueue_operation(struct fs
46672 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46673 ASSERTCMP(atomic_read(&op->usage), >, 0);
46674
46675 - fscache_stat(&fscache_n_op_enqueue);
46676 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46677 switch (op->flags & FSCACHE_OP_TYPE) {
46678 case FSCACHE_OP_ASYNC:
46679 _debug("queue async");
46680 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscach
46681 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46682 if (op->processor)
46683 fscache_enqueue_operation(op);
46684 - fscache_stat(&fscache_n_op_run);
46685 + fscache_stat_unchecked(&fscache_n_op_run);
46686 }
46687
46688 /*
46689 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct f
46690 if (object->n_ops > 1) {
46691 atomic_inc(&op->usage);
46692 list_add_tail(&op->pend_link, &object->pending_ops);
46693 - fscache_stat(&fscache_n_op_pend);
46694 + fscache_stat_unchecked(&fscache_n_op_pend);
46695 } else if (!list_empty(&object->pending_ops)) {
46696 atomic_inc(&op->usage);
46697 list_add_tail(&op->pend_link, &object->pending_ops);
46698 - fscache_stat(&fscache_n_op_pend);
46699 + fscache_stat_unchecked(&fscache_n_op_pend);
46700 fscache_start_operations(object);
46701 } else {
46702 ASSERTCMP(object->n_in_progress, ==, 0);
46703 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct f
46704 object->n_exclusive++; /* reads and writes must wait */
46705 atomic_inc(&op->usage);
46706 list_add_tail(&op->pend_link, &object->pending_ops);
46707 - fscache_stat(&fscache_n_op_pend);
46708 + fscache_stat_unchecked(&fscache_n_op_pend);
46709 ret = 0;
46710 } else {
46711 /* not allowed to submit ops in any other state */
46712 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_obj
46713 if (object->n_exclusive > 0) {
46714 atomic_inc(&op->usage);
46715 list_add_tail(&op->pend_link, &object->pending_ops);
46716 - fscache_stat(&fscache_n_op_pend);
46717 + fscache_stat_unchecked(&fscache_n_op_pend);
46718 } else if (!list_empty(&object->pending_ops)) {
46719 atomic_inc(&op->usage);
46720 list_add_tail(&op->pend_link, &object->pending_ops);
46721 - fscache_stat(&fscache_n_op_pend);
46722 + fscache_stat_unchecked(&fscache_n_op_pend);
46723 fscache_start_operations(object);
46724 } else {
46725 ASSERTCMP(object->n_exclusive, ==, 0);
46726 @@ -227,12 +227,12 @@ int fscache_submit_op(struct fscache_obj
46727 object->n_ops++;
46728 atomic_inc(&op->usage);
46729 list_add_tail(&op->pend_link, &object->pending_ops);
46730 - fscache_stat(&fscache_n_op_pend);
46731 + fscache_stat_unchecked(&fscache_n_op_pend);
46732 ret = 0;
46733 } else if (object->state == FSCACHE_OBJECT_DYING ||
46734 object->state == FSCACHE_OBJECT_LC_DYING ||
46735 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46736 - fscache_stat(&fscache_n_op_rejected);
46737 + fscache_stat_unchecked(&fscache_n_op_rejected);
46738 ret = -ENOBUFS;
46739 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46740 fscache_report_unexpected_submission(object, op, ostate);
46741 @@ -302,7 +302,7 @@ int fscache_cancel_op(struct fscache_ope
46742
46743 ret = -EBUSY;
46744 if (!list_empty(&op->pend_link)) {
46745 - fscache_stat(&fscache_n_op_cancelled);
46746 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46747 list_del_init(&op->pend_link);
46748 object->n_ops--;
46749 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46750 @@ -341,7 +341,7 @@ void fscache_put_operation(struct fscach
46751 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46752 BUG();
46753
46754 - fscache_stat(&fscache_n_op_release);
46755 + fscache_stat_unchecked(&fscache_n_op_release);
46756
46757 if (op->release) {
46758 op->release(op);
46759 @@ -358,7 +358,7 @@ void fscache_put_operation(struct fscach
46760 * lock, and defer it otherwise */
46761 if (!spin_trylock(&object->lock)) {
46762 _debug("defer put");
46763 - fscache_stat(&fscache_n_op_deferred_release);
46764 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46765
46766 cache = object->cache;
46767 spin_lock(&cache->op_gc_list_lock);
46768 @@ -420,7 +420,7 @@ void fscache_operation_gc(struct work_st
46769
46770 _debug("GC DEFERRED REL OBJ%x OP%x",
46771 object->debug_id, op->debug_id);
46772 - fscache_stat(&fscache_n_op_gc);
46773 + fscache_stat_unchecked(&fscache_n_op_gc);
46774
46775 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46776
46777 diff -urNp linux-2.6.39.2/fs/fscache/page.c linux-2.6.39.2/fs/fscache/page.c
46778 --- linux-2.6.39.2/fs/fscache/page.c 2011-05-19 00:06:34.000000000 -0400
46779 +++ linux-2.6.39.2/fs/fscache/page.c 2011-05-22 19:36:32.000000000 -0400
46780 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct
46781 val = radix_tree_lookup(&cookie->stores, page->index);
46782 if (!val) {
46783 rcu_read_unlock();
46784 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46785 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46786 __fscache_uncache_page(cookie, page);
46787 return true;
46788 }
46789 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct
46790 spin_unlock(&cookie->stores_lock);
46791
46792 if (xpage) {
46793 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46794 - fscache_stat(&fscache_n_store_radix_deletes);
46795 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46796 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46797 ASSERTCMP(xpage, ==, page);
46798 } else {
46799 - fscache_stat(&fscache_n_store_vmscan_gone);
46800 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46801 }
46802
46803 wake_up_bit(&cookie->flags, 0);
46804 @@ -107,7 +107,7 @@ page_busy:
46805 /* we might want to wait here, but that could deadlock the allocator as
46806 * the work threads writing to the cache may all end up sleeping
46807 * on memory allocation */
46808 - fscache_stat(&fscache_n_store_vmscan_busy);
46809 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46810 return false;
46811 }
46812 EXPORT_SYMBOL(__fscache_maybe_release_page);
46813 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struc
46814 FSCACHE_COOKIE_STORING_TAG);
46815 if (!radix_tree_tag_get(&cookie->stores, page->index,
46816 FSCACHE_COOKIE_PENDING_TAG)) {
46817 - fscache_stat(&fscache_n_store_radix_deletes);
46818 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46819 xpage = radix_tree_delete(&cookie->stores, page->index);
46820 }
46821 spin_unlock(&cookie->stores_lock);
46822 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(stru
46823
46824 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46825
46826 - fscache_stat(&fscache_n_attr_changed_calls);
46827 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46828
46829 if (fscache_object_is_active(object)) {
46830 fscache_set_op_state(op, "CallFS");
46831 @@ -179,11 +179,11 @@ int __fscache_attr_changed(struct fscach
46832
46833 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46834
46835 - fscache_stat(&fscache_n_attr_changed);
46836 + fscache_stat_unchecked(&fscache_n_attr_changed);
46837
46838 op = kzalloc(sizeof(*op), GFP_KERNEL);
46839 if (!op) {
46840 - fscache_stat(&fscache_n_attr_changed_nomem);
46841 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46842 _leave(" = -ENOMEM");
46843 return -ENOMEM;
46844 }
46845 @@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscach
46846 if (fscache_submit_exclusive_op(object, op) < 0)
46847 goto nobufs;
46848 spin_unlock(&cookie->lock);
46849 - fscache_stat(&fscache_n_attr_changed_ok);
46850 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46851 fscache_put_operation(op);
46852 _leave(" = 0");
46853 return 0;
46854 @@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscach
46855 nobufs:
46856 spin_unlock(&cookie->lock);
46857 kfree(op);
46858 - fscache_stat(&fscache_n_attr_changed_nobufs);
46859 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46860 _leave(" = %d", -ENOBUFS);
46861 return -ENOBUFS;
46862 }
46863 @@ -246,7 +246,7 @@ static struct fscache_retrieval *fscache
46864 /* allocate a retrieval operation and attempt to submit it */
46865 op = kzalloc(sizeof(*op), GFP_NOIO);
46866 if (!op) {
46867 - fscache_stat(&fscache_n_retrievals_nomem);
46868 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46869 return NULL;
46870 }
46871
46872 @@ -275,13 +275,13 @@ static int fscache_wait_for_deferred_loo
46873 return 0;
46874 }
46875
46876 - fscache_stat(&fscache_n_retrievals_wait);
46877 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46878
46879 jif = jiffies;
46880 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46881 fscache_wait_bit_interruptible,
46882 TASK_INTERRUPTIBLE) != 0) {
46883 - fscache_stat(&fscache_n_retrievals_intr);
46884 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46885 _leave(" = -ERESTARTSYS");
46886 return -ERESTARTSYS;
46887 }
46888 @@ -299,8 +299,8 @@ static int fscache_wait_for_deferred_loo
46889 */
46890 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46891 struct fscache_retrieval *op,
46892 - atomic_t *stat_op_waits,
46893 - atomic_t *stat_object_dead)
46894 + atomic_unchecked_t *stat_op_waits,
46895 + atomic_unchecked_t *stat_object_dead)
46896 {
46897 int ret;
46898
46899 @@ -308,7 +308,7 @@ static int fscache_wait_for_retrieval_ac
46900 goto check_if_dead;
46901
46902 _debug(">>> WT");
46903 - fscache_stat(stat_op_waits);
46904 + fscache_stat_unchecked(stat_op_waits);
46905 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46906 fscache_wait_bit_interruptible,
46907 TASK_INTERRUPTIBLE) < 0) {
46908 @@ -325,7 +325,7 @@ static int fscache_wait_for_retrieval_ac
46909
46910 check_if_dead:
46911 if (unlikely(fscache_object_is_dead(object))) {
46912 - fscache_stat(stat_object_dead);
46913 + fscache_stat_unchecked(stat_object_dead);
46914 return -ENOBUFS;
46915 }
46916 return 0;
46917 @@ -352,7 +352,7 @@ int __fscache_read_or_alloc_page(struct
46918
46919 _enter("%p,%p,,,", cookie, page);
46920
46921 - fscache_stat(&fscache_n_retrievals);
46922 + fscache_stat_unchecked(&fscache_n_retrievals);
46923
46924 if (hlist_empty(&cookie->backing_objects))
46925 goto nobufs;
46926 @@ -386,7 +386,7 @@ int __fscache_read_or_alloc_page(struct
46927 goto nobufs_unlock;
46928 spin_unlock(&cookie->lock);
46929
46930 - fscache_stat(&fscache_n_retrieval_ops);
46931 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46932
46933 /* pin the netfs read context in case we need to do the actual netfs
46934 * read because we've encountered a cache read failure */
46935 @@ -416,15 +416,15 @@ int __fscache_read_or_alloc_page(struct
46936
46937 error:
46938 if (ret == -ENOMEM)
46939 - fscache_stat(&fscache_n_retrievals_nomem);
46940 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46941 else if (ret == -ERESTARTSYS)
46942 - fscache_stat(&fscache_n_retrievals_intr);
46943 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46944 else if (ret == -ENODATA)
46945 - fscache_stat(&fscache_n_retrievals_nodata);
46946 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46947 else if (ret < 0)
46948 - fscache_stat(&fscache_n_retrievals_nobufs);
46949 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46950 else
46951 - fscache_stat(&fscache_n_retrievals_ok);
46952 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46953
46954 fscache_put_retrieval(op);
46955 _leave(" = %d", ret);
46956 @@ -434,7 +434,7 @@ nobufs_unlock:
46957 spin_unlock(&cookie->lock);
46958 kfree(op);
46959 nobufs:
46960 - fscache_stat(&fscache_n_retrievals_nobufs);
46961 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46962 _leave(" = -ENOBUFS");
46963 return -ENOBUFS;
46964 }
46965 @@ -472,7 +472,7 @@ int __fscache_read_or_alloc_pages(struct
46966
46967 _enter("%p,,%d,,,", cookie, *nr_pages);
46968
46969 - fscache_stat(&fscache_n_retrievals);
46970 + fscache_stat_unchecked(&fscache_n_retrievals);
46971
46972 if (hlist_empty(&cookie->backing_objects))
46973 goto nobufs;
46974 @@ -503,7 +503,7 @@ int __fscache_read_or_alloc_pages(struct
46975 goto nobufs_unlock;
46976 spin_unlock(&cookie->lock);
46977
46978 - fscache_stat(&fscache_n_retrieval_ops);
46979 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46980
46981 /* pin the netfs read context in case we need to do the actual netfs
46982 * read because we've encountered a cache read failure */
46983 @@ -533,15 +533,15 @@ int __fscache_read_or_alloc_pages(struct
46984
46985 error:
46986 if (ret == -ENOMEM)
46987 - fscache_stat(&fscache_n_retrievals_nomem);
46988 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46989 else if (ret == -ERESTARTSYS)
46990 - fscache_stat(&fscache_n_retrievals_intr);
46991 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46992 else if (ret == -ENODATA)
46993 - fscache_stat(&fscache_n_retrievals_nodata);
46994 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46995 else if (ret < 0)
46996 - fscache_stat(&fscache_n_retrievals_nobufs);
46997 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46998 else
46999 - fscache_stat(&fscache_n_retrievals_ok);
47000 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47001
47002 fscache_put_retrieval(op);
47003 _leave(" = %d", ret);
47004 @@ -551,7 +551,7 @@ nobufs_unlock:
47005 spin_unlock(&cookie->lock);
47006 kfree(op);
47007 nobufs:
47008 - fscache_stat(&fscache_n_retrievals_nobufs);
47009 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47010 _leave(" = -ENOBUFS");
47011 return -ENOBUFS;
47012 }
47013 @@ -575,7 +575,7 @@ int __fscache_alloc_page(struct fscache_
47014
47015 _enter("%p,%p,,,", cookie, page);
47016
47017 - fscache_stat(&fscache_n_allocs);
47018 + fscache_stat_unchecked(&fscache_n_allocs);
47019
47020 if (hlist_empty(&cookie->backing_objects))
47021 goto nobufs;
47022 @@ -602,7 +602,7 @@ int __fscache_alloc_page(struct fscache_
47023 goto nobufs_unlock;
47024 spin_unlock(&cookie->lock);
47025
47026 - fscache_stat(&fscache_n_alloc_ops);
47027 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47028
47029 ret = fscache_wait_for_retrieval_activation(
47030 object, op,
47031 @@ -618,11 +618,11 @@ int __fscache_alloc_page(struct fscache_
47032
47033 error:
47034 if (ret == -ERESTARTSYS)
47035 - fscache_stat(&fscache_n_allocs_intr);
47036 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47037 else if (ret < 0)
47038 - fscache_stat(&fscache_n_allocs_nobufs);
47039 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47040 else
47041 - fscache_stat(&fscache_n_allocs_ok);
47042 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47043
47044 fscache_put_retrieval(op);
47045 _leave(" = %d", ret);
47046 @@ -632,7 +632,7 @@ nobufs_unlock:
47047 spin_unlock(&cookie->lock);
47048 kfree(op);
47049 nobufs:
47050 - fscache_stat(&fscache_n_allocs_nobufs);
47051 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47052 _leave(" = -ENOBUFS");
47053 return -ENOBUFS;
47054 }
47055 @@ -675,7 +675,7 @@ static void fscache_write_op(struct fsca
47056
47057 spin_lock(&cookie->stores_lock);
47058
47059 - fscache_stat(&fscache_n_store_calls);
47060 + fscache_stat_unchecked(&fscache_n_store_calls);
47061
47062 /* find a page to store */
47063 page = NULL;
47064 @@ -686,7 +686,7 @@ static void fscache_write_op(struct fsca
47065 page = results[0];
47066 _debug("gang %d [%lx]", n, page->index);
47067 if (page->index > op->store_limit) {
47068 - fscache_stat(&fscache_n_store_pages_over_limit);
47069 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47070 goto superseded;
47071 }
47072
47073 @@ -699,7 +699,7 @@ static void fscache_write_op(struct fsca
47074 spin_unlock(&object->lock);
47075
47076 fscache_set_op_state(&op->op, "Store");
47077 - fscache_stat(&fscache_n_store_pages);
47078 + fscache_stat_unchecked(&fscache_n_store_pages);
47079 fscache_stat(&fscache_n_cop_write_page);
47080 ret = object->cache->ops->write_page(op, page);
47081 fscache_stat_d(&fscache_n_cop_write_page);
47082 @@ -769,7 +769,7 @@ int __fscache_write_page(struct fscache_
47083 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47084 ASSERT(PageFsCache(page));
47085
47086 - fscache_stat(&fscache_n_stores);
47087 + fscache_stat_unchecked(&fscache_n_stores);
47088
47089 op = kzalloc(sizeof(*op), GFP_NOIO);
47090 if (!op)
47091 @@ -821,7 +821,7 @@ int __fscache_write_page(struct fscache_
47092 spin_unlock(&cookie->stores_lock);
47093 spin_unlock(&object->lock);
47094
47095 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47096 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47097 op->store_limit = object->store_limit;
47098
47099 if (fscache_submit_op(object, &op->op) < 0)
47100 @@ -829,8 +829,8 @@ int __fscache_write_page(struct fscache_
47101
47102 spin_unlock(&cookie->lock);
47103 radix_tree_preload_end();
47104 - fscache_stat(&fscache_n_store_ops);
47105 - fscache_stat(&fscache_n_stores_ok);
47106 + fscache_stat_unchecked(&fscache_n_store_ops);
47107 + fscache_stat_unchecked(&fscache_n_stores_ok);
47108
47109 /* the work queue now carries its own ref on the object */
47110 fscache_put_operation(&op->op);
47111 @@ -838,14 +838,14 @@ int __fscache_write_page(struct fscache_
47112 return 0;
47113
47114 already_queued:
47115 - fscache_stat(&fscache_n_stores_again);
47116 + fscache_stat_unchecked(&fscache_n_stores_again);
47117 already_pending:
47118 spin_unlock(&cookie->stores_lock);
47119 spin_unlock(&object->lock);
47120 spin_unlock(&cookie->lock);
47121 radix_tree_preload_end();
47122 kfree(op);
47123 - fscache_stat(&fscache_n_stores_ok);
47124 + fscache_stat_unchecked(&fscache_n_stores_ok);
47125 _leave(" = 0");
47126 return 0;
47127
47128 @@ -864,14 +864,14 @@ nobufs:
47129 spin_unlock(&cookie->lock);
47130 radix_tree_preload_end();
47131 kfree(op);
47132 - fscache_stat(&fscache_n_stores_nobufs);
47133 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47134 _leave(" = -ENOBUFS");
47135 return -ENOBUFS;
47136
47137 nomem_free:
47138 kfree(op);
47139 nomem:
47140 - fscache_stat(&fscache_n_stores_oom);
47141 + fscache_stat_unchecked(&fscache_n_stores_oom);
47142 _leave(" = -ENOMEM");
47143 return -ENOMEM;
47144 }
47145 @@ -889,7 +889,7 @@ void __fscache_uncache_page(struct fscac
47146 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47147 ASSERTCMP(page, !=, NULL);
47148
47149 - fscache_stat(&fscache_n_uncaches);
47150 + fscache_stat_unchecked(&fscache_n_uncaches);
47151
47152 /* cache withdrawal may beat us to it */
47153 if (!PageFsCache(page))
47154 @@ -942,7 +942,7 @@ void fscache_mark_pages_cached(struct fs
47155 unsigned long loop;
47156
47157 #ifdef CONFIG_FSCACHE_STATS
47158 - atomic_add(pagevec->nr, &fscache_n_marks);
47159 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47160 #endif
47161
47162 for (loop = 0; loop < pagevec->nr; loop++) {
47163 diff -urNp linux-2.6.39.2/fs/fscache/stats.c linux-2.6.39.2/fs/fscache/stats.c
47164 --- linux-2.6.39.2/fs/fscache/stats.c 2011-05-19 00:06:34.000000000 -0400
47165 +++ linux-2.6.39.2/fs/fscache/stats.c 2011-05-22 19:36:32.000000000 -0400
47166 @@ -18,95 +18,95 @@
47167 /*
47168 * operation counters
47169 */
47170 -atomic_t fscache_n_op_pend;
47171 -atomic_t fscache_n_op_run;
47172 -atomic_t fscache_n_op_enqueue;
47173 -atomic_t fscache_n_op_requeue;
47174 -atomic_t fscache_n_op_deferred_release;
47175 -atomic_t fscache_n_op_release;
47176 -atomic_t fscache_n_op_gc;
47177 -atomic_t fscache_n_op_cancelled;
47178 -atomic_t fscache_n_op_rejected;
47179 -
47180 -atomic_t fscache_n_attr_changed;
47181 -atomic_t fscache_n_attr_changed_ok;
47182 -atomic_t fscache_n_attr_changed_nobufs;
47183 -atomic_t fscache_n_attr_changed_nomem;
47184 -atomic_t fscache_n_attr_changed_calls;
47185 -
47186 -atomic_t fscache_n_allocs;
47187 -atomic_t fscache_n_allocs_ok;
47188 -atomic_t fscache_n_allocs_wait;
47189 -atomic_t fscache_n_allocs_nobufs;
47190 -atomic_t fscache_n_allocs_intr;
47191 -atomic_t fscache_n_allocs_object_dead;
47192 -atomic_t fscache_n_alloc_ops;
47193 -atomic_t fscache_n_alloc_op_waits;
47194 -
47195 -atomic_t fscache_n_retrievals;
47196 -atomic_t fscache_n_retrievals_ok;
47197 -atomic_t fscache_n_retrievals_wait;
47198 -atomic_t fscache_n_retrievals_nodata;
47199 -atomic_t fscache_n_retrievals_nobufs;
47200 -atomic_t fscache_n_retrievals_intr;
47201 -atomic_t fscache_n_retrievals_nomem;
47202 -atomic_t fscache_n_retrievals_object_dead;
47203 -atomic_t fscache_n_retrieval_ops;
47204 -atomic_t fscache_n_retrieval_op_waits;
47205 -
47206 -atomic_t fscache_n_stores;
47207 -atomic_t fscache_n_stores_ok;
47208 -atomic_t fscache_n_stores_again;
47209 -atomic_t fscache_n_stores_nobufs;
47210 -atomic_t fscache_n_stores_oom;
47211 -atomic_t fscache_n_store_ops;
47212 -atomic_t fscache_n_store_calls;
47213 -atomic_t fscache_n_store_pages;
47214 -atomic_t fscache_n_store_radix_deletes;
47215 -atomic_t fscache_n_store_pages_over_limit;
47216 -
47217 -atomic_t fscache_n_store_vmscan_not_storing;
47218 -atomic_t fscache_n_store_vmscan_gone;
47219 -atomic_t fscache_n_store_vmscan_busy;
47220 -atomic_t fscache_n_store_vmscan_cancelled;
47221 -
47222 -atomic_t fscache_n_marks;
47223 -atomic_t fscache_n_uncaches;
47224 -
47225 -atomic_t fscache_n_acquires;
47226 -atomic_t fscache_n_acquires_null;
47227 -atomic_t fscache_n_acquires_no_cache;
47228 -atomic_t fscache_n_acquires_ok;
47229 -atomic_t fscache_n_acquires_nobufs;
47230 -atomic_t fscache_n_acquires_oom;
47231 -
47232 -atomic_t fscache_n_updates;
47233 -atomic_t fscache_n_updates_null;
47234 -atomic_t fscache_n_updates_run;
47235 -
47236 -atomic_t fscache_n_relinquishes;
47237 -atomic_t fscache_n_relinquishes_null;
47238 -atomic_t fscache_n_relinquishes_waitcrt;
47239 -atomic_t fscache_n_relinquishes_retire;
47240 -
47241 -atomic_t fscache_n_cookie_index;
47242 -atomic_t fscache_n_cookie_data;
47243 -atomic_t fscache_n_cookie_special;
47244 -
47245 -atomic_t fscache_n_object_alloc;
47246 -atomic_t fscache_n_object_no_alloc;
47247 -atomic_t fscache_n_object_lookups;
47248 -atomic_t fscache_n_object_lookups_negative;
47249 -atomic_t fscache_n_object_lookups_positive;
47250 -atomic_t fscache_n_object_lookups_timed_out;
47251 -atomic_t fscache_n_object_created;
47252 -atomic_t fscache_n_object_avail;
47253 -atomic_t fscache_n_object_dead;
47254 -
47255 -atomic_t fscache_n_checkaux_none;
47256 -atomic_t fscache_n_checkaux_okay;
47257 -atomic_t fscache_n_checkaux_update;
47258 -atomic_t fscache_n_checkaux_obsolete;
47259 +atomic_unchecked_t fscache_n_op_pend;
47260 +atomic_unchecked_t fscache_n_op_run;
47261 +atomic_unchecked_t fscache_n_op_enqueue;
47262 +atomic_unchecked_t fscache_n_op_requeue;
47263 +atomic_unchecked_t fscache_n_op_deferred_release;
47264 +atomic_unchecked_t fscache_n_op_release;
47265 +atomic_unchecked_t fscache_n_op_gc;
47266 +atomic_unchecked_t fscache_n_op_cancelled;
47267 +atomic_unchecked_t fscache_n_op_rejected;
47268 +
47269 +atomic_unchecked_t fscache_n_attr_changed;
47270 +atomic_unchecked_t fscache_n_attr_changed_ok;
47271 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47272 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47273 +atomic_unchecked_t fscache_n_attr_changed_calls;
47274 +
47275 +atomic_unchecked_t fscache_n_allocs;
47276 +atomic_unchecked_t fscache_n_allocs_ok;
47277 +atomic_unchecked_t fscache_n_allocs_wait;
47278 +atomic_unchecked_t fscache_n_allocs_nobufs;
47279 +atomic_unchecked_t fscache_n_allocs_intr;
47280 +atomic_unchecked_t fscache_n_allocs_object_dead;
47281 +atomic_unchecked_t fscache_n_alloc_ops;
47282 +atomic_unchecked_t fscache_n_alloc_op_waits;
47283 +
47284 +atomic_unchecked_t fscache_n_retrievals;
47285 +atomic_unchecked_t fscache_n_retrievals_ok;
47286 +atomic_unchecked_t fscache_n_retrievals_wait;
47287 +atomic_unchecked_t fscache_n_retrievals_nodata;
47288 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47289 +atomic_unchecked_t fscache_n_retrievals_intr;
47290 +atomic_unchecked_t fscache_n_retrievals_nomem;
47291 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47292 +atomic_unchecked_t fscache_n_retrieval_ops;
47293 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47294 +
47295 +atomic_unchecked_t fscache_n_stores;
47296 +atomic_unchecked_t fscache_n_stores_ok;
47297 +atomic_unchecked_t fscache_n_stores_again;
47298 +atomic_unchecked_t fscache_n_stores_nobufs;
47299 +atomic_unchecked_t fscache_n_stores_oom;
47300 +atomic_unchecked_t fscache_n_store_ops;
47301 +atomic_unchecked_t fscache_n_store_calls;
47302 +atomic_unchecked_t fscache_n_store_pages;
47303 +atomic_unchecked_t fscache_n_store_radix_deletes;
47304 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47305 +
47306 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47307 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47308 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47309 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47310 +
47311 +atomic_unchecked_t fscache_n_marks;
47312 +atomic_unchecked_t fscache_n_uncaches;
47313 +
47314 +atomic_unchecked_t fscache_n_acquires;
47315 +atomic_unchecked_t fscache_n_acquires_null;
47316 +atomic_unchecked_t fscache_n_acquires_no_cache;
47317 +atomic_unchecked_t fscache_n_acquires_ok;
47318 +atomic_unchecked_t fscache_n_acquires_nobufs;
47319 +atomic_unchecked_t fscache_n_acquires_oom;
47320 +
47321 +atomic_unchecked_t fscache_n_updates;
47322 +atomic_unchecked_t fscache_n_updates_null;
47323 +atomic_unchecked_t fscache_n_updates_run;
47324 +
47325 +atomic_unchecked_t fscache_n_relinquishes;
47326 +atomic_unchecked_t fscache_n_relinquishes_null;
47327 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47328 +atomic_unchecked_t fscache_n_relinquishes_retire;
47329 +
47330 +atomic_unchecked_t fscache_n_cookie_index;
47331 +atomic_unchecked_t fscache_n_cookie_data;
47332 +atomic_unchecked_t fscache_n_cookie_special;
47333 +
47334 +atomic_unchecked_t fscache_n_object_alloc;
47335 +atomic_unchecked_t fscache_n_object_no_alloc;
47336 +atomic_unchecked_t fscache_n_object_lookups;
47337 +atomic_unchecked_t fscache_n_object_lookups_negative;
47338 +atomic_unchecked_t fscache_n_object_lookups_positive;
47339 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47340 +atomic_unchecked_t fscache_n_object_created;
47341 +atomic_unchecked_t fscache_n_object_avail;
47342 +atomic_unchecked_t fscache_n_object_dead;
47343 +
47344 +atomic_unchecked_t fscache_n_checkaux_none;
47345 +atomic_unchecked_t fscache_n_checkaux_okay;
47346 +atomic_unchecked_t fscache_n_checkaux_update;
47347 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47348
47349 atomic_t fscache_n_cop_alloc_object;
47350 atomic_t fscache_n_cop_lookup_object;
47351 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq
47352 seq_puts(m, "FS-Cache statistics\n");
47353
47354 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47355 - atomic_read(&fscache_n_cookie_index),
47356 - atomic_read(&fscache_n_cookie_data),
47357 - atomic_read(&fscache_n_cookie_special));
47358 + atomic_read_unchecked(&fscache_n_cookie_index),
47359 + atomic_read_unchecked(&fscache_n_cookie_data),
47360 + atomic_read_unchecked(&fscache_n_cookie_special));
47361
47362 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47363 - atomic_read(&fscache_n_object_alloc),
47364 - atomic_read(&fscache_n_object_no_alloc),
47365 - atomic_read(&fscache_n_object_avail),
47366 - atomic_read(&fscache_n_object_dead));
47367 + atomic_read_unchecked(&fscache_n_object_alloc),
47368 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47369 + atomic_read_unchecked(&fscache_n_object_avail),
47370 + atomic_read_unchecked(&fscache_n_object_dead));
47371 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47372 - atomic_read(&fscache_n_checkaux_none),
47373 - atomic_read(&fscache_n_checkaux_okay),
47374 - atomic_read(&fscache_n_checkaux_update),
47375 - atomic_read(&fscache_n_checkaux_obsolete));
47376 + atomic_read_unchecked(&fscache_n_checkaux_none),
47377 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47378 + atomic_read_unchecked(&fscache_n_checkaux_update),
47379 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47380
47381 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47382 - atomic_read(&fscache_n_marks),
47383 - atomic_read(&fscache_n_uncaches));
47384 + atomic_read_unchecked(&fscache_n_marks),
47385 + atomic_read_unchecked(&fscache_n_uncaches));
47386
47387 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47388 " oom=%u\n",
47389 - atomic_read(&fscache_n_acquires),
47390 - atomic_read(&fscache_n_acquires_null),
47391 - atomic_read(&fscache_n_acquires_no_cache),
47392 - atomic_read(&fscache_n_acquires_ok),
47393 - atomic_read(&fscache_n_acquires_nobufs),
47394 - atomic_read(&fscache_n_acquires_oom));
47395 + atomic_read_unchecked(&fscache_n_acquires),
47396 + atomic_read_unchecked(&fscache_n_acquires_null),
47397 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47398 + atomic_read_unchecked(&fscache_n_acquires_ok),
47399 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47400 + atomic_read_unchecked(&fscache_n_acquires_oom));
47401
47402 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47403 - atomic_read(&fscache_n_object_lookups),
47404 - atomic_read(&fscache_n_object_lookups_negative),
47405 - atomic_read(&fscache_n_object_lookups_positive),
47406 - atomic_read(&fscache_n_object_created),
47407 - atomic_read(&fscache_n_object_lookups_timed_out));
47408 + atomic_read_unchecked(&fscache_n_object_lookups),
47409 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47410 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47411 + atomic_read_unchecked(&fscache_n_object_created),
47412 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47413
47414 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47415 - atomic_read(&fscache_n_updates),
47416 - atomic_read(&fscache_n_updates_null),
47417 - atomic_read(&fscache_n_updates_run));
47418 + atomic_read_unchecked(&fscache_n_updates),
47419 + atomic_read_unchecked(&fscache_n_updates_null),
47420 + atomic_read_unchecked(&fscache_n_updates_run));
47421
47422 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47423 - atomic_read(&fscache_n_relinquishes),
47424 - atomic_read(&fscache_n_relinquishes_null),
47425 - atomic_read(&fscache_n_relinquishes_waitcrt),
47426 - atomic_read(&fscache_n_relinquishes_retire));
47427 + atomic_read_unchecked(&fscache_n_relinquishes),
47428 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47429 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47430 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47431
47432 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47433 - atomic_read(&fscache_n_attr_changed),
47434 - atomic_read(&fscache_n_attr_changed_ok),
47435 - atomic_read(&fscache_n_attr_changed_nobufs),
47436 - atomic_read(&fscache_n_attr_changed_nomem),
47437 - atomic_read(&fscache_n_attr_changed_calls));
47438 + atomic_read_unchecked(&fscache_n_attr_changed),
47439 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47440 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47441 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47442 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47443
47444 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47445 - atomic_read(&fscache_n_allocs),
47446 - atomic_read(&fscache_n_allocs_ok),
47447 - atomic_read(&fscache_n_allocs_wait),
47448 - atomic_read(&fscache_n_allocs_nobufs),
47449 - atomic_read(&fscache_n_allocs_intr));
47450 + atomic_read_unchecked(&fscache_n_allocs),
47451 + atomic_read_unchecked(&fscache_n_allocs_ok),
47452 + atomic_read_unchecked(&fscache_n_allocs_wait),
47453 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47454 + atomic_read_unchecked(&fscache_n_allocs_intr));
47455 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47456 - atomic_read(&fscache_n_alloc_ops),
47457 - atomic_read(&fscache_n_alloc_op_waits),
47458 - atomic_read(&fscache_n_allocs_object_dead));
47459 + atomic_read_unchecked(&fscache_n_alloc_ops),
47460 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47461 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47462
47463 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47464 " int=%u oom=%u\n",
47465 - atomic_read(&fscache_n_retrievals),
47466 - atomic_read(&fscache_n_retrievals_ok),
47467 - atomic_read(&fscache_n_retrievals_wait),
47468 - atomic_read(&fscache_n_retrievals_nodata),
47469 - atomic_read(&fscache_n_retrievals_nobufs),
47470 - atomic_read(&fscache_n_retrievals_intr),
47471 - atomic_read(&fscache_n_retrievals_nomem));
47472 + atomic_read_unchecked(&fscache_n_retrievals),
47473 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47474 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47475 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47476 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47477 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47478 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47479 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47480 - atomic_read(&fscache_n_retrieval_ops),
47481 - atomic_read(&fscache_n_retrieval_op_waits),
47482 - atomic_read(&fscache_n_retrievals_object_dead));
47483 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47484 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47485 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47486
47487 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47488 - atomic_read(&fscache_n_stores),
47489 - atomic_read(&fscache_n_stores_ok),
47490 - atomic_read(&fscache_n_stores_again),
47491 - atomic_read(&fscache_n_stores_nobufs),
47492 - atomic_read(&fscache_n_stores_oom));
47493 + atomic_read_unchecked(&fscache_n_stores),
47494 + atomic_read_unchecked(&fscache_n_stores_ok),
47495 + atomic_read_unchecked(&fscache_n_stores_again),
47496 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47497 + atomic_read_unchecked(&fscache_n_stores_oom));
47498 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47499 - atomic_read(&fscache_n_store_ops),
47500 - atomic_read(&fscache_n_store_calls),
47501 - atomic_read(&fscache_n_store_pages),
47502 - atomic_read(&fscache_n_store_radix_deletes),
47503 - atomic_read(&fscache_n_store_pages_over_limit));
47504 + atomic_read_unchecked(&fscache_n_store_ops),
47505 + atomic_read_unchecked(&fscache_n_store_calls),
47506 + atomic_read_unchecked(&fscache_n_store_pages),
47507 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47508 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47509
47510 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47511 - atomic_read(&fscache_n_store_vmscan_not_storing),
47512 - atomic_read(&fscache_n_store_vmscan_gone),
47513 - atomic_read(&fscache_n_store_vmscan_busy),
47514 - atomic_read(&fscache_n_store_vmscan_cancelled));
47515 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47516 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47517 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47518 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47519
47520 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47521 - atomic_read(&fscache_n_op_pend),
47522 - atomic_read(&fscache_n_op_run),
47523 - atomic_read(&fscache_n_op_enqueue),
47524 - atomic_read(&fscache_n_op_cancelled),
47525 - atomic_read(&fscache_n_op_rejected));
47526 + atomic_read_unchecked(&fscache_n_op_pend),
47527 + atomic_read_unchecked(&fscache_n_op_run),
47528 + atomic_read_unchecked(&fscache_n_op_enqueue),
47529 + atomic_read_unchecked(&fscache_n_op_cancelled),
47530 + atomic_read_unchecked(&fscache_n_op_rejected));
47531 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47532 - atomic_read(&fscache_n_op_deferred_release),
47533 - atomic_read(&fscache_n_op_release),
47534 - atomic_read(&fscache_n_op_gc));
47535 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47536 + atomic_read_unchecked(&fscache_n_op_release),
47537 + atomic_read_unchecked(&fscache_n_op_gc));
47538
47539 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47540 atomic_read(&fscache_n_cop_alloc_object),
47541 diff -urNp linux-2.6.39.2/fs/fs_struct.c linux-2.6.39.2/fs/fs_struct.c
47542 --- linux-2.6.39.2/fs/fs_struct.c 2011-05-19 00:06:34.000000000 -0400
47543 +++ linux-2.6.39.2/fs/fs_struct.c 2011-05-22 19:41:37.000000000 -0400
47544 @@ -4,6 +4,7 @@
47545 #include <linux/path.h>
47546 #include <linux/slab.h>
47547 #include <linux/fs_struct.h>
47548 +#include <linux/grsecurity.h>
47549 #include "internal.h"
47550
47551 static inline void path_get_longterm(struct path *path)
47552 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, s
47553 old_root = fs->root;
47554 fs->root = *path;
47555 path_get_longterm(path);
47556 + gr_set_chroot_entries(current, path);
47557 write_seqcount_end(&fs->seq);
47558 spin_unlock(&fs->lock);
47559 if (old_root.dentry)
47560 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_roo
47561 && fs->root.mnt == old_root->mnt) {
47562 path_get_longterm(new_root);
47563 fs->root = *new_root;
47564 + gr_set_chroot_entries(p, new_root);
47565 count++;
47566 }
47567 if (fs->pwd.dentry == old_root->dentry
47568 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
47569 spin_lock(&fs->lock);
47570 write_seqcount_begin(&fs->seq);
47571 tsk->fs = NULL;
47572 - kill = !--fs->users;
47573 + gr_clear_chroot_entries(tsk);
47574 + kill = !atomic_dec_return(&fs->users);
47575 write_seqcount_end(&fs->seq);
47576 spin_unlock(&fs->lock);
47577 task_unlock(tsk);
47578 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct
47579 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47580 /* We don't need to lock fs - think why ;-) */
47581 if (fs) {
47582 - fs->users = 1;
47583 + atomic_set(&fs->users, 1);
47584 fs->in_exec = 0;
47585 spin_lock_init(&fs->lock);
47586 seqcount_init(&fs->seq);
47587 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct
47588 spin_lock(&old->lock);
47589 fs->root = old->root;
47590 path_get_longterm(&fs->root);
47591 + /* instead of calling gr_set_chroot_entries here,
47592 + we call it from every caller of this function
47593 + */
47594 fs->pwd = old->pwd;
47595 path_get_longterm(&fs->pwd);
47596 spin_unlock(&old->lock);
47597 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
47598
47599 task_lock(current);
47600 spin_lock(&fs->lock);
47601 - kill = !--fs->users;
47602 + kill = !atomic_dec_return(&fs->users);
47603 current->fs = new_fs;
47604 + gr_set_chroot_entries(current, &new_fs->root);
47605 spin_unlock(&fs->lock);
47606 task_unlock(current);
47607
47608 @@ -170,7 +178,7 @@ EXPORT_SYMBOL(current_umask);
47609
47610 /* to be mentioned only in INIT_TASK */
47611 struct fs_struct init_fs = {
47612 - .users = 1,
47613 + .users = ATOMIC_INIT(1),
47614 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47615 .seq = SEQCNT_ZERO,
47616 .umask = 0022,
47617 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
47618 task_lock(current);
47619
47620 spin_lock(&init_fs.lock);
47621 - init_fs.users++;
47622 + atomic_inc(&init_fs.users);
47623 spin_unlock(&init_fs.lock);
47624
47625 spin_lock(&fs->lock);
47626 current->fs = &init_fs;
47627 - kill = !--fs->users;
47628 + gr_set_chroot_entries(current, &current->fs->root);
47629 + kill = !atomic_dec_return(&fs->users);
47630 spin_unlock(&fs->lock);
47631
47632 task_unlock(current);
47633 diff -urNp linux-2.6.39.2/fs/fuse/cuse.c linux-2.6.39.2/fs/fuse/cuse.c
47634 --- linux-2.6.39.2/fs/fuse/cuse.c 2011-05-19 00:06:34.000000000 -0400
47635 +++ linux-2.6.39.2/fs/fuse/cuse.c 2011-05-22 19:36:32.000000000 -0400
47636 @@ -538,8 +538,18 @@ static int cuse_channel_release(struct i
47637 return rc;
47638 }
47639
47640 -static struct file_operations cuse_channel_fops; /* initialized during init */
47641 -
47642 +static const struct file_operations cuse_channel_fops = { /* initialized during init */
47643 + .owner = THIS_MODULE,
47644 + .llseek = no_llseek,
47645 + .read = do_sync_read,
47646 + .aio_read = fuse_dev_read,
47647 + .write = do_sync_write,
47648 + .aio_write = fuse_dev_write,
47649 + .poll = fuse_dev_poll,
47650 + .open = cuse_channel_open,
47651 + .release = cuse_channel_release,
47652 + .fasync = fuse_dev_fasync,
47653 +};
47654
47655 /**************************************************************************
47656 * Misc stuff and module initializatiion
47657 @@ -585,12 +595,6 @@ static int __init cuse_init(void)
47658 for (i = 0; i < CUSE_CONNTBL_LEN; i++)
47659 INIT_LIST_HEAD(&cuse_conntbl[i]);
47660
47661 - /* inherit and extend fuse_dev_operations */
47662 - cuse_channel_fops = fuse_dev_operations;
47663 - cuse_channel_fops.owner = THIS_MODULE;
47664 - cuse_channel_fops.open = cuse_channel_open;
47665 - cuse_channel_fops.release = cuse_channel_release;
47666 -
47667 cuse_class = class_create(THIS_MODULE, "cuse");
47668 if (IS_ERR(cuse_class))
47669 return PTR_ERR(cuse_class);
47670 diff -urNp linux-2.6.39.2/fs/fuse/dev.c linux-2.6.39.2/fs/fuse/dev.c
47671 --- linux-2.6.39.2/fs/fuse/dev.c 2011-05-19 00:06:34.000000000 -0400
47672 +++ linux-2.6.39.2/fs/fuse/dev.c 2011-05-22 19:36:32.000000000 -0400
47673 @@ -1181,7 +1181,7 @@ static ssize_t fuse_dev_do_read(struct f
47674 return err;
47675 }
47676
47677 -static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47678 +ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47679 unsigned long nr_segs, loff_t pos)
47680 {
47681 struct fuse_copy_state cs;
47682 @@ -1195,6 +1195,8 @@ static ssize_t fuse_dev_read(struct kioc
47683 return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
47684 }
47685
47686 +EXPORT_SYMBOL_GPL(fuse_dev_read);
47687 +
47688 static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
47689 struct pipe_buffer *buf)
47690 {
47691 @@ -1238,7 +1240,7 @@ static ssize_t fuse_dev_splice_read(stru
47692 ret = 0;
47693 pipe_lock(pipe);
47694
47695 - if (!pipe->readers) {
47696 + if (!atomic_read(&pipe->readers)) {
47697 send_sig(SIGPIPE, current, 0);
47698 if (!ret)
47699 ret = -EPIPE;
47700 @@ -1731,7 +1733,7 @@ static ssize_t fuse_dev_do_write(struct
47701 return err;
47702 }
47703
47704 -static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47705 +ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47706 unsigned long nr_segs, loff_t pos)
47707 {
47708 struct fuse_copy_state cs;
47709 @@ -1744,6 +1746,8 @@ static ssize_t fuse_dev_write(struct kio
47710 return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
47711 }
47712
47713 +EXPORT_SYMBOL_GPL(fuse_dev_write);
47714 +
47715 static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
47716 struct file *out, loff_t *ppos,
47717 size_t len, unsigned int flags)
47718 @@ -1822,7 +1826,7 @@ out:
47719 return ret;
47720 }
47721
47722 -static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47723 +unsigned fuse_dev_poll(struct file *file, poll_table *wait)
47724 {
47725 unsigned mask = POLLOUT | POLLWRNORM;
47726 struct fuse_conn *fc = fuse_get_conn(file);
47727 @@ -1841,6 +1845,8 @@ static unsigned fuse_dev_poll(struct fil
47728 return mask;
47729 }
47730
47731 +EXPORT_SYMBOL_GPL(fuse_dev_poll);
47732 +
47733 /*
47734 * Abort all requests on the given list (pending or processing)
47735 *
47736 @@ -1977,7 +1983,7 @@ int fuse_dev_release(struct inode *inode
47737 }
47738 EXPORT_SYMBOL_GPL(fuse_dev_release);
47739
47740 -static int fuse_dev_fasync(int fd, struct file *file, int on)
47741 +int fuse_dev_fasync(int fd, struct file *file, int on)
47742 {
47743 struct fuse_conn *fc = fuse_get_conn(file);
47744 if (!fc)
47745 @@ -1987,6 +1993,8 @@ static int fuse_dev_fasync(int fd, struc
47746 return fasync_helper(fd, file, on, &fc->fasync);
47747 }
47748
47749 +EXPORT_SYMBOL_GPL(fuse_dev_fasync);
47750 +
47751 const struct file_operations fuse_dev_operations = {
47752 .owner = THIS_MODULE,
47753 .llseek = no_llseek,
47754 diff -urNp linux-2.6.39.2/fs/fuse/dir.c linux-2.6.39.2/fs/fuse/dir.c
47755 --- linux-2.6.39.2/fs/fuse/dir.c 2011-05-19 00:06:34.000000000 -0400
47756 +++ linux-2.6.39.2/fs/fuse/dir.c 2011-05-22 19:36:32.000000000 -0400
47757 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *de
47758 return link;
47759 }
47760
47761 -static void free_link(char *link)
47762 +static void free_link(const char *link)
47763 {
47764 if (!IS_ERR(link))
47765 free_page((unsigned long) link);
47766 diff -urNp linux-2.6.39.2/fs/fuse/fuse_i.h linux-2.6.39.2/fs/fuse/fuse_i.h
47767 --- linux-2.6.39.2/fs/fuse/fuse_i.h 2011-05-19 00:06:34.000000000 -0400
47768 +++ linux-2.6.39.2/fs/fuse/fuse_i.h 2011-05-22 19:36:32.000000000 -0400
47769 @@ -540,6 +540,16 @@ extern const struct file_operations fuse
47770
47771 extern const struct dentry_operations fuse_dentry_operations;
47772
47773 +extern ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
47774 + unsigned long nr_segs, loff_t pos);
47775 +
47776 +extern ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
47777 + unsigned long nr_segs, loff_t pos);
47778 +
47779 +extern unsigned fuse_dev_poll(struct file *file, poll_table *wait);
47780 +
47781 +extern int fuse_dev_fasync(int fd, struct file *file, int on);
47782 +
47783 /**
47784 * Inode to nodeid comparison.
47785 */
47786 diff -urNp linux-2.6.39.2/fs/gfs2/ops_inode.c linux-2.6.39.2/fs/gfs2/ops_inode.c
47787 --- linux-2.6.39.2/fs/gfs2/ops_inode.c 2011-05-19 00:06:34.000000000 -0400
47788 +++ linux-2.6.39.2/fs/gfs2/ops_inode.c 2011-05-22 19:36:32.000000000 -0400
47789 @@ -740,6 +740,8 @@ static int gfs2_rename(struct inode *odi
47790 unsigned int x;
47791 int error;
47792
47793 + pax_track_stack();
47794 +
47795 if (ndentry->d_inode) {
47796 nip = GFS2_I(ndentry->d_inode);
47797 if (ip == nip)
47798 @@ -1019,7 +1021,7 @@ out:
47799
47800 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47801 {
47802 - char *s = nd_get_link(nd);
47803 + const char *s = nd_get_link(nd);
47804 if (!IS_ERR(s))
47805 kfree(s);
47806 }
47807 diff -urNp linux-2.6.39.2/fs/hfsplus/catalog.c linux-2.6.39.2/fs/hfsplus/catalog.c
47808 --- linux-2.6.39.2/fs/hfsplus/catalog.c 2011-05-19 00:06:34.000000000 -0400
47809 +++ linux-2.6.39.2/fs/hfsplus/catalog.c 2011-05-22 19:36:32.000000000 -0400
47810 @@ -179,6 +179,8 @@ int hfsplus_find_cat(struct super_block
47811 int err;
47812 u16 type;
47813
47814 + pax_track_stack();
47815 +
47816 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
47817 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
47818 if (err)
47819 @@ -210,6 +212,8 @@ int hfsplus_create_cat(u32 cnid, struct
47820 int entry_size;
47821 int err;
47822
47823 + pax_track_stack();
47824 +
47825 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n",
47826 str->name, cnid, inode->i_nlink);
47827 hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
47828 @@ -349,6 +353,8 @@ int hfsplus_rename_cat(u32 cnid,
47829 int entry_size, type;
47830 int err = 0;
47831
47832 + pax_track_stack();
47833 +
47834 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n",
47835 cnid, src_dir->i_ino, src_name->name,
47836 dst_dir->i_ino, dst_name->name);
47837 diff -urNp linux-2.6.39.2/fs/hfsplus/dir.c linux-2.6.39.2/fs/hfsplus/dir.c
47838 --- linux-2.6.39.2/fs/hfsplus/dir.c 2011-05-19 00:06:34.000000000 -0400
47839 +++ linux-2.6.39.2/fs/hfsplus/dir.c 2011-05-22 19:36:32.000000000 -0400
47840 @@ -129,6 +129,8 @@ static int hfsplus_readdir(struct file *
47841 struct hfsplus_readdir_data *rd;
47842 u16 type;
47843
47844 + pax_track_stack();
47845 +
47846 if (filp->f_pos >= inode->i_size)
47847 return 0;
47848
47849 diff -urNp linux-2.6.39.2/fs/hfsplus/inode.c linux-2.6.39.2/fs/hfsplus/inode.c
47850 --- linux-2.6.39.2/fs/hfsplus/inode.c 2011-05-19 00:06:34.000000000 -0400
47851 +++ linux-2.6.39.2/fs/hfsplus/inode.c 2011-05-22 19:36:32.000000000 -0400
47852 @@ -489,6 +489,8 @@ int hfsplus_cat_read_inode(struct inode
47853 int res = 0;
47854 u16 type;
47855
47856 + pax_track_stack();
47857 +
47858 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
47859
47860 HFSPLUS_I(inode)->linkid = 0;
47861 @@ -552,6 +554,8 @@ int hfsplus_cat_write_inode(struct inode
47862 struct hfs_find_data fd;
47863 hfsplus_cat_entry entry;
47864
47865 + pax_track_stack();
47866 +
47867 if (HFSPLUS_IS_RSRC(inode))
47868 main_inode = HFSPLUS_I(inode)->rsrc_inode;
47869
47870 diff -urNp linux-2.6.39.2/fs/hfsplus/ioctl.c linux-2.6.39.2/fs/hfsplus/ioctl.c
47871 --- linux-2.6.39.2/fs/hfsplus/ioctl.c 2011-05-19 00:06:34.000000000 -0400
47872 +++ linux-2.6.39.2/fs/hfsplus/ioctl.c 2011-05-22 19:36:32.000000000 -0400
47873 @@ -122,6 +122,8 @@ int hfsplus_setxattr(struct dentry *dent
47874 struct hfsplus_cat_file *file;
47875 int res;
47876
47877 + pax_track_stack();
47878 +
47879 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47880 return -EOPNOTSUPP;
47881
47882 @@ -166,6 +168,8 @@ ssize_t hfsplus_getxattr(struct dentry *
47883 struct hfsplus_cat_file *file;
47884 ssize_t res = 0;
47885
47886 + pax_track_stack();
47887 +
47888 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
47889 return -EOPNOTSUPP;
47890
47891 diff -urNp linux-2.6.39.2/fs/hfsplus/super.c linux-2.6.39.2/fs/hfsplus/super.c
47892 --- linux-2.6.39.2/fs/hfsplus/super.c 2011-05-19 00:06:34.000000000 -0400
47893 +++ linux-2.6.39.2/fs/hfsplus/super.c 2011-05-22 19:36:32.000000000 -0400
47894 @@ -340,6 +340,8 @@ static int hfsplus_fill_super(struct sup
47895 struct nls_table *nls = NULL;
47896 int err;
47897
47898 + pax_track_stack();
47899 +
47900 err = -EINVAL;
47901 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
47902 if (!sbi)
47903 diff -urNp linux-2.6.39.2/fs/hugetlbfs/inode.c linux-2.6.39.2/fs/hugetlbfs/inode.c
47904 --- linux-2.6.39.2/fs/hugetlbfs/inode.c 2011-05-19 00:06:34.000000000 -0400
47905 +++ linux-2.6.39.2/fs/hugetlbfs/inode.c 2011-05-22 19:41:37.000000000 -0400
47906 @@ -914,7 +914,7 @@ static struct file_system_type hugetlbfs
47907 .kill_sb = kill_litter_super,
47908 };
47909
47910 -static struct vfsmount *hugetlbfs_vfsmount;
47911 +struct vfsmount *hugetlbfs_vfsmount;
47912
47913 static int can_do_hugetlb_shm(void)
47914 {
47915 diff -urNp linux-2.6.39.2/fs/inode.c linux-2.6.39.2/fs/inode.c
47916 --- linux-2.6.39.2/fs/inode.c 2011-05-19 00:06:34.000000000 -0400
47917 +++ linux-2.6.39.2/fs/inode.c 2011-05-22 19:36:32.000000000 -0400
47918 @@ -862,8 +862,8 @@ unsigned int get_next_ino(void)
47919
47920 #ifdef CONFIG_SMP
47921 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47922 - static atomic_t shared_last_ino;
47923 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47924 + static atomic_unchecked_t shared_last_ino;
47925 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47926
47927 res = next - LAST_INO_BATCH;
47928 }
47929 diff -urNp linux-2.6.39.2/fs/jbd/checkpoint.c linux-2.6.39.2/fs/jbd/checkpoint.c
47930 --- linux-2.6.39.2/fs/jbd/checkpoint.c 2011-05-19 00:06:34.000000000 -0400
47931 +++ linux-2.6.39.2/fs/jbd/checkpoint.c 2011-05-22 19:36:32.000000000 -0400
47932 @@ -350,6 +350,8 @@ int log_do_checkpoint(journal_t *journal
47933 tid_t this_tid;
47934 int result;
47935
47936 + pax_track_stack();
47937 +
47938 jbd_debug(1, "Start checkpoint\n");
47939
47940 /*
47941 diff -urNp linux-2.6.39.2/fs/jffs2/compr_rtime.c linux-2.6.39.2/fs/jffs2/compr_rtime.c
47942 --- linux-2.6.39.2/fs/jffs2/compr_rtime.c 2011-05-19 00:06:34.000000000 -0400
47943 +++ linux-2.6.39.2/fs/jffs2/compr_rtime.c 2011-05-22 19:36:32.000000000 -0400
47944 @@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned
47945 int outpos = 0;
47946 int pos=0;
47947
47948 + pax_track_stack();
47949 +
47950 memset(positions,0,sizeof(positions));
47951
47952 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
47953 @@ -78,6 +80,8 @@ static int jffs2_rtime_decompress(unsign
47954 int outpos = 0;
47955 int pos=0;
47956
47957 + pax_track_stack();
47958 +
47959 memset(positions,0,sizeof(positions));
47960
47961 while (outpos<destlen) {
47962 diff -urNp linux-2.6.39.2/fs/jffs2/compr_rubin.c linux-2.6.39.2/fs/jffs2/compr_rubin.c
47963 --- linux-2.6.39.2/fs/jffs2/compr_rubin.c 2011-05-19 00:06:34.000000000 -0400
47964 +++ linux-2.6.39.2/fs/jffs2/compr_rubin.c 2011-05-22 19:36:32.000000000 -0400
47965 @@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsig
47966 int ret;
47967 uint32_t mysrclen, mydstlen;
47968
47969 + pax_track_stack();
47970 +
47971 mysrclen = *sourcelen;
47972 mydstlen = *dstlen - 8;
47973
47974 diff -urNp linux-2.6.39.2/fs/jffs2/erase.c linux-2.6.39.2/fs/jffs2/erase.c
47975 --- linux-2.6.39.2/fs/jffs2/erase.c 2011-05-19 00:06:34.000000000 -0400
47976 +++ linux-2.6.39.2/fs/jffs2/erase.c 2011-05-22 19:36:32.000000000 -0400
47977 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(stru
47978 struct jffs2_unknown_node marker = {
47979 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47980 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47981 - .totlen = cpu_to_je32(c->cleanmarker_size)
47982 + .totlen = cpu_to_je32(c->cleanmarker_size),
47983 + .hdr_crc = cpu_to_je32(0)
47984 };
47985
47986 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47987 diff -urNp linux-2.6.39.2/fs/jffs2/wbuf.c linux-2.6.39.2/fs/jffs2/wbuf.c
47988 --- linux-2.6.39.2/fs/jffs2/wbuf.c 2011-05-19 00:06:34.000000000 -0400
47989 +++ linux-2.6.39.2/fs/jffs2/wbuf.c 2011-05-22 19:36:32.000000000 -0400
47990 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
47991 {
47992 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47993 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47994 - .totlen = constant_cpu_to_je32(8)
47995 + .totlen = constant_cpu_to_je32(8),
47996 + .hdr_crc = constant_cpu_to_je32(0)
47997 };
47998
47999 /*
48000 diff -urNp linux-2.6.39.2/fs/jffs2/xattr.c linux-2.6.39.2/fs/jffs2/xattr.c
48001 --- linux-2.6.39.2/fs/jffs2/xattr.c 2011-05-19 00:06:34.000000000 -0400
48002 +++ linux-2.6.39.2/fs/jffs2/xattr.c 2011-05-22 19:36:32.000000000 -0400
48003 @@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct
48004
48005 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
48006
48007 + pax_track_stack();
48008 +
48009 /* Phase.1 : Merge same xref */
48010 for (i=0; i < XREF_TMPHASH_SIZE; i++)
48011 xref_tmphash[i] = NULL;
48012 diff -urNp linux-2.6.39.2/fs/jfs/super.c linux-2.6.39.2/fs/jfs/super.c
48013 --- linux-2.6.39.2/fs/jfs/super.c 2011-05-19 00:06:34.000000000 -0400
48014 +++ linux-2.6.39.2/fs/jfs/super.c 2011-06-07 18:07:24.000000000 -0400
48015 @@ -803,7 +803,7 @@ static int __init init_jfs_fs(void)
48016
48017 jfs_inode_cachep =
48018 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
48019 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
48020 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
48021 init_once);
48022 if (jfs_inode_cachep == NULL)
48023 return -ENOMEM;
48024 diff -urNp linux-2.6.39.2/fs/Kconfig.binfmt linux-2.6.39.2/fs/Kconfig.binfmt
48025 --- linux-2.6.39.2/fs/Kconfig.binfmt 2011-05-19 00:06:34.000000000 -0400
48026 +++ linux-2.6.39.2/fs/Kconfig.binfmt 2011-05-22 19:36:32.000000000 -0400
48027 @@ -86,7 +86,7 @@ config HAVE_AOUT
48028
48029 config BINFMT_AOUT
48030 tristate "Kernel support for a.out and ECOFF binaries"
48031 - depends on HAVE_AOUT
48032 + depends on HAVE_AOUT && BROKEN
48033 ---help---
48034 A.out (Assembler.OUTput) is a set of formats for libraries and
48035 executables used in the earliest versions of UNIX. Linux used
48036 diff -urNp linux-2.6.39.2/fs/libfs.c linux-2.6.39.2/fs/libfs.c
48037 --- linux-2.6.39.2/fs/libfs.c 2011-05-19 00:06:34.000000000 -0400
48038 +++ linux-2.6.39.2/fs/libfs.c 2011-05-22 19:36:32.000000000 -0400
48039 @@ -163,6 +163,9 @@ int dcache_readdir(struct file * filp, v
48040
48041 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
48042 struct dentry *next;
48043 + char d_name[sizeof(next->d_iname)];
48044 + const unsigned char *name;
48045 +
48046 next = list_entry(p, struct dentry, d_u.d_child);
48047 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
48048 if (!simple_positive(next)) {
48049 @@ -172,7 +175,12 @@ int dcache_readdir(struct file * filp, v
48050
48051 spin_unlock(&next->d_lock);
48052 spin_unlock(&dentry->d_lock);
48053 - if (filldir(dirent, next->d_name.name,
48054 + name = next->d_name.name;
48055 + if (name == next->d_iname) {
48056 + memcpy(d_name, name, next->d_name.len);
48057 + name = d_name;
48058 + }
48059 + if (filldir(dirent, name,
48060 next->d_name.len, filp->f_pos,
48061 next->d_inode->i_ino,
48062 dt_type(next->d_inode)) < 0)
48063 diff -urNp linux-2.6.39.2/fs/lockd/clntproc.c linux-2.6.39.2/fs/lockd/clntproc.c
48064 --- linux-2.6.39.2/fs/lockd/clntproc.c 2011-05-19 00:06:34.000000000 -0400
48065 +++ linux-2.6.39.2/fs/lockd/clntproc.c 2011-05-22 19:36:32.000000000 -0400
48066 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt
48067 /*
48068 * Cookie counter for NLM requests
48069 */
48070 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
48071 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
48072
48073 void nlmclnt_next_cookie(struct nlm_cookie *c)
48074 {
48075 - u32 cookie = atomic_inc_return(&nlm_cookie);
48076 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
48077
48078 memcpy(c->data, &cookie, 4);
48079 c->len=4;
48080 @@ -620,6 +620,8 @@ nlmclnt_reclaim(struct nlm_host *host, s
48081 struct nlm_rqst reqst, *req;
48082 int status;
48083
48084 + pax_track_stack();
48085 +
48086 req = &reqst;
48087 memset(req, 0, sizeof(*req));
48088 locks_init_lock(&req->a_args.lock.fl);
48089 diff -urNp linux-2.6.39.2/fs/lockd/svc.c linux-2.6.39.2/fs/lockd/svc.c
48090 --- linux-2.6.39.2/fs/lockd/svc.c 2011-05-19 00:06:34.000000000 -0400
48091 +++ linux-2.6.39.2/fs/lockd/svc.c 2011-05-22 19:36:32.000000000 -0400
48092 @@ -41,7 +41,7 @@
48093
48094 static struct svc_program nlmsvc_program;
48095
48096 -struct nlmsvc_binding * nlmsvc_ops;
48097 +const struct nlmsvc_binding * nlmsvc_ops;
48098 EXPORT_SYMBOL_GPL(nlmsvc_ops);
48099
48100 static DEFINE_MUTEX(nlmsvc_mutex);
48101 diff -urNp linux-2.6.39.2/fs/locks.c linux-2.6.39.2/fs/locks.c
48102 --- linux-2.6.39.2/fs/locks.c 2011-05-19 00:06:34.000000000 -0400
48103 +++ linux-2.6.39.2/fs/locks.c 2011-05-22 19:36:32.000000000 -0400
48104 @@ -2033,16 +2033,16 @@ void locks_remove_flock(struct file *fil
48105 return;
48106
48107 if (filp->f_op && filp->f_op->flock) {
48108 - struct file_lock fl = {
48109 + struct file_lock flock = {
48110 .fl_pid = current->tgid,
48111 .fl_file = filp,
48112 .fl_flags = FL_FLOCK,
48113 .fl_type = F_UNLCK,
48114 .fl_end = OFFSET_MAX,
48115 };
48116 - filp->f_op->flock(filp, F_SETLKW, &fl);
48117 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
48118 - fl.fl_ops->fl_release_private(&fl);
48119 + filp->f_op->flock(filp, F_SETLKW, &flock);
48120 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
48121 + flock.fl_ops->fl_release_private(&flock);
48122 }
48123
48124 lock_flocks();
48125 diff -urNp linux-2.6.39.2/fs/logfs/super.c linux-2.6.39.2/fs/logfs/super.c
48126 --- linux-2.6.39.2/fs/logfs/super.c 2011-05-19 00:06:34.000000000 -0400
48127 +++ linux-2.6.39.2/fs/logfs/super.c 2011-05-22 19:36:32.000000000 -0400
48128 @@ -266,6 +266,8 @@ static int logfs_recover_sb(struct super
48129 struct logfs_disk_super _ds1, *ds1 = &_ds1;
48130 int err, valid0, valid1;
48131
48132 + pax_track_stack();
48133 +
48134 /* read first superblock */
48135 err = wbuf_read(sb, super->s_sb_ofs[0], sizeof(*ds0), ds0);
48136 if (err)
48137 diff -urNp linux-2.6.39.2/fs/namei.c linux-2.6.39.2/fs/namei.c
48138 --- linux-2.6.39.2/fs/namei.c 2011-06-03 00:04:14.000000000 -0400
48139 +++ linux-2.6.39.2/fs/namei.c 2011-06-03 00:32:07.000000000 -0400
48140 @@ -237,20 +237,30 @@ int generic_permission(struct inode *ino
48141 return ret;
48142
48143 /*
48144 - * Read/write DACs are always overridable.
48145 - * Executable DACs are overridable if at least one exec bit is set.
48146 + * Searching includes executable on directories, else just read.
48147 */
48148 - if (!(mask & MAY_EXEC) || execute_ok(inode))
48149 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48150 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48151 + if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) {
48152 +#ifdef CONFIG_GRKERNSEC
48153 + if (flags & IPERM_FLAG_RCU)
48154 + return -ECHILD;
48155 +#endif
48156 + if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48157 return 0;
48158 + }
48159
48160 /*
48161 - * Searching includes executable on directories, else just read.
48162 + * Read/write DACs are always overridable.
48163 + * Executable DACs are overridable if at least one exec bit is set.
48164 */
48165 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
48166 - if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
48167 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
48168 + if (!(mask & MAY_EXEC) || execute_ok(inode)) {
48169 +#ifdef CONFIG_GRKERNSEC
48170 + if (flags & IPERM_FLAG_RCU)
48171 + return -ECHILD;
48172 +#endif
48173 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
48174 return 0;
48175 + }
48176
48177 return -EACCES;
48178 }
48179 @@ -626,6 +636,9 @@ static inline int handle_reval_path(stru
48180 struct dentry *dentry = nd->path.dentry;
48181 int status;
48182
48183 + if (!(nd->flags & LOOKUP_PARENT) && !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
48184 + return -ENOENT;
48185 +
48186 if (likely(!(nd->flags & LOOKUP_JUMPED)))
48187 return 0;
48188
48189 @@ -671,9 +684,16 @@ static inline int exec_permission(struct
48190 if (ret == -ECHILD)
48191 return ret;
48192
48193 - if (ns_capable(ns, CAP_DAC_OVERRIDE) ||
48194 - ns_capable(ns, CAP_DAC_READ_SEARCH))
48195 + if (ns_capable_nolog(ns, CAP_DAC_OVERRIDE))
48196 goto ok;
48197 + else {
48198 +#ifdef CONFIG_GRKERNSEC
48199 + if (flags & IPERM_FLAG_RCU)
48200 + return -ECHILD;
48201 +#endif
48202 + if (ns_capable(ns, CAP_DAC_READ_SEARCH) || ns_capable(ns, CAP_DAC_OVERRIDE))
48203 + goto ok;
48204 + }
48205
48206 return ret;
48207 ok:
48208 @@ -781,11 +801,19 @@ follow_link(struct path *link, struct na
48209 return error;
48210 }
48211
48212 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
48213 + dentry->d_inode, dentry, nd->path.mnt)) {
48214 + error = -EACCES;
48215 + *p = ERR_PTR(error); /* no ->put_link(), please */
48216 + path_put(&nd->path);
48217 + return error;
48218 + }
48219 +
48220 nd->last_type = LAST_BIND;
48221 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
48222 error = PTR_ERR(*p);
48223 if (!IS_ERR(*p)) {
48224 - char *s = nd_get_link(nd);
48225 + const char *s = nd_get_link(nd);
48226 error = 0;
48227 if (s)
48228 error = __vfs_follow_link(nd, s);
48229 @@ -1697,6 +1725,9 @@ static int do_path_lookup(int dfd, const
48230 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
48231
48232 if (likely(!retval)) {
48233 + if (*name != '/' && nd->path.dentry && nd->inode && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
48234 + return -ENOENT;
48235 +
48236 if (unlikely(!audit_dummy_context())) {
48237 if (nd->path.dentry && nd->inode)
48238 audit_inode(name, nd->path.dentry);
48239 @@ -2007,6 +2038,30 @@ int vfs_create(struct inode *dir, struct
48240 return error;
48241 }
48242
48243 +/*
48244 + * Note that while the flag value (low two bits) for sys_open means:
48245 + * 00 - read-only
48246 + * 01 - write-only
48247 + * 10 - read-write
48248 + * 11 - special
48249 + * it is changed into
48250 + * 00 - no permissions needed
48251 + * 01 - read-permission
48252 + * 10 - write-permission
48253 + * 11 - read-write
48254 + * for the internal routines (ie open_namei()/follow_link() etc)
48255 + * This is more logical, and also allows the 00 "no perm needed"
48256 + * to be used for symlinks (where the permissions are checked
48257 + * later).
48258 + *
48259 +*/
48260 +static inline int open_to_namei_flags(int flag)
48261 +{
48262 + if ((flag+1) & O_ACCMODE)
48263 + flag++;
48264 + return flag;
48265 +}
48266 +
48267 static int may_open(struct path *path, int acc_mode, int flag)
48268 {
48269 struct dentry *dentry = path->dentry;
48270 @@ -2059,7 +2114,27 @@ static int may_open(struct path *path, i
48271 /*
48272 * Ensure there are no outstanding leases on the file.
48273 */
48274 - return break_lease(inode, flag);
48275 + error = break_lease(inode, flag);
48276 +
48277 + if (error)
48278 + return error;
48279 +
48280 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
48281 + error = -EPERM;
48282 + goto exit;
48283 + }
48284 +
48285 + if (gr_handle_rawio(inode)) {
48286 + error = -EPERM;
48287 + goto exit;
48288 + }
48289 +
48290 + if (!gr_acl_handle_open(dentry, path->mnt, open_to_namei_flags(flag))) {
48291 + error = -EACCES;
48292 + goto exit;
48293 + }
48294 +exit:
48295 + return error;
48296 }
48297
48298 static int handle_truncate(struct file *filp)
48299 @@ -2085,30 +2160,6 @@ static int handle_truncate(struct file *
48300 }
48301
48302 /*
48303 - * Note that while the flag value (low two bits) for sys_open means:
48304 - * 00 - read-only
48305 - * 01 - write-only
48306 - * 10 - read-write
48307 - * 11 - special
48308 - * it is changed into
48309 - * 00 - no permissions needed
48310 - * 01 - read-permission
48311 - * 10 - write-permission
48312 - * 11 - read-write
48313 - * for the internal routines (ie open_namei()/follow_link() etc)
48314 - * This is more logical, and also allows the 00 "no perm needed"
48315 - * to be used for symlinks (where the permissions are checked
48316 - * later).
48317 - *
48318 -*/
48319 -static inline int open_to_namei_flags(int flag)
48320 -{
48321 - if ((flag+1) & O_ACCMODE)
48322 - flag++;
48323 - return flag;
48324 -}
48325 -
48326 -/*
48327 * Handle the last step of open()
48328 */
48329 static struct file *do_last(struct nameidata *nd, struct path *path,
48330 @@ -2117,6 +2168,7 @@ static struct file *do_last(struct namei
48331 struct dentry *dir = nd->path.dentry;
48332 struct dentry *dentry;
48333 int open_flag = op->open_flag;
48334 + int flag = open_to_namei_flags(open_flag);
48335 int will_truncate = open_flag & O_TRUNC;
48336 int want_write = 0;
48337 int acc_mode = op->acc_mode;
48338 @@ -2212,6 +2264,12 @@ static struct file *do_last(struct namei
48339 /* Negative dentry, just create the file */
48340 if (!dentry->d_inode) {
48341 int mode = op->mode;
48342 +
48343 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, flag, mode)) {
48344 + error = -EACCES;
48345 + goto exit_mutex_unlock;
48346 + }
48347 +
48348 if (!IS_POSIXACL(dir->d_inode))
48349 mode &= ~current_umask();
48350 /*
48351 @@ -2235,6 +2293,8 @@ static struct file *do_last(struct namei
48352 error = vfs_create(dir->d_inode, dentry, mode, nd);
48353 if (error)
48354 goto exit_mutex_unlock;
48355 + else
48356 + gr_handle_create(path->dentry, path->mnt);
48357 mutex_unlock(&dir->d_inode->i_mutex);
48358 dput(nd->path.dentry);
48359 nd->path.dentry = dentry;
48360 @@ -2244,6 +2304,14 @@ static struct file *do_last(struct namei
48361 /*
48362 * It already exists.
48363 */
48364 +
48365 + /* only check if O_CREAT is specified, all other checks need to go
48366 + into may_open */
48367 + if (gr_handle_fifo(path->dentry, path->mnt, dir, flag, acc_mode)) {
48368 + error = -EACCES;
48369 + goto exit_mutex_unlock;
48370 + }
48371 +
48372 mutex_unlock(&dir->d_inode->i_mutex);
48373 audit_inode(pathname, path->dentry);
48374
48375 @@ -2530,6 +2598,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48376 error = may_mknod(mode);
48377 if (error)
48378 goto out_dput;
48379 +
48380 + if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
48381 + error = -EPERM;
48382 + goto out_dput;
48383 + }
48384 +
48385 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
48386 + error = -EACCES;
48387 + goto out_dput;
48388 + }
48389 +
48390 error = mnt_want_write(nd.path.mnt);
48391 if (error)
48392 goto out_dput;
48393 @@ -2550,6 +2629,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const
48394 }
48395 out_drop_write:
48396 mnt_drop_write(nd.path.mnt);
48397 +
48398 + if (!error)
48399 + gr_handle_create(dentry, nd.path.mnt);
48400 out_dput:
48401 dput(dentry);
48402 out_unlock:
48403 @@ -2602,6 +2684,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48404 if (IS_ERR(dentry))
48405 goto out_unlock;
48406
48407 + if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
48408 + error = -EACCES;
48409 + goto out_dput;
48410 + }
48411 +
48412 if (!IS_POSIXACL(nd.path.dentry->d_inode))
48413 mode &= ~current_umask();
48414 error = mnt_want_write(nd.path.mnt);
48415 @@ -2613,6 +2700,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const
48416 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
48417 out_drop_write:
48418 mnt_drop_write(nd.path.mnt);
48419 +
48420 + if (!error)
48421 + gr_handle_create(dentry, nd.path.mnt);
48422 +
48423 out_dput:
48424 dput(dentry);
48425 out_unlock:
48426 @@ -2692,6 +2783,8 @@ static long do_rmdir(int dfd, const char
48427 char * name;
48428 struct dentry *dentry;
48429 struct nameidata nd;
48430 + ino_t saved_ino = 0;
48431 + dev_t saved_dev = 0;
48432
48433 error = user_path_parent(dfd, pathname, &nd, &name);
48434 if (error)
48435 @@ -2716,6 +2809,19 @@ static long do_rmdir(int dfd, const char
48436 error = PTR_ERR(dentry);
48437 if (IS_ERR(dentry))
48438 goto exit2;
48439 +
48440 + if (dentry->d_inode != NULL) {
48441 + if (dentry->d_inode->i_nlink <= 1) {
48442 + saved_ino = dentry->d_inode->i_ino;
48443 + saved_dev = gr_get_dev_from_dentry(dentry);
48444 + }
48445 +
48446 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48447 + error = -EACCES;
48448 + goto exit3;
48449 + }
48450 + }
48451 +
48452 error = mnt_want_write(nd.path.mnt);
48453 if (error)
48454 goto exit3;
48455 @@ -2723,6 +2829,8 @@ static long do_rmdir(int dfd, const char
48456 if (error)
48457 goto exit4;
48458 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48459 + if (!error && (saved_dev || saved_ino))
48460 + gr_handle_delete(saved_ino, saved_dev);
48461 exit4:
48462 mnt_drop_write(nd.path.mnt);
48463 exit3:
48464 @@ -2785,6 +2893,8 @@ static long do_unlinkat(int dfd, const c
48465 struct dentry *dentry;
48466 struct nameidata nd;
48467 struct inode *inode = NULL;
48468 + ino_t saved_ino = 0;
48469 + dev_t saved_dev = 0;
48470
48471 error = user_path_parent(dfd, pathname, &nd, &name);
48472 if (error)
48473 @@ -2804,8 +2914,17 @@ static long do_unlinkat(int dfd, const c
48474 if (nd.last.name[nd.last.len])
48475 goto slashes;
48476 inode = dentry->d_inode;
48477 - if (inode)
48478 + if (inode) {
48479 ihold(inode);
48480 + if (inode->i_nlink <= 1) {
48481 + saved_ino = inode->i_ino;
48482 + saved_dev = gr_get_dev_from_dentry(dentry);
48483 + }
48484 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48485 + error = -EACCES;
48486 + goto exit2;
48487 + }
48488 + }
48489 error = mnt_want_write(nd.path.mnt);
48490 if (error)
48491 goto exit2;
48492 @@ -2813,6 +2932,8 @@ static long do_unlinkat(int dfd, const c
48493 if (error)
48494 goto exit3;
48495 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48496 + if (!error && (saved_ino || saved_dev))
48497 + gr_handle_delete(saved_ino, saved_dev);
48498 exit3:
48499 mnt_drop_write(nd.path.mnt);
48500 exit2:
48501 @@ -2890,6 +3011,11 @@ SYSCALL_DEFINE3(symlinkat, const char __
48502 if (IS_ERR(dentry))
48503 goto out_unlock;
48504
48505 + if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
48506 + error = -EACCES;
48507 + goto out_dput;
48508 + }
48509 +
48510 error = mnt_want_write(nd.path.mnt);
48511 if (error)
48512 goto out_dput;
48513 @@ -2897,6 +3023,8 @@ SYSCALL_DEFINE3(symlinkat, const char __
48514 if (error)
48515 goto out_drop_write;
48516 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
48517 + if (!error)
48518 + gr_handle_create(dentry, nd.path.mnt);
48519 out_drop_write:
48520 mnt_drop_write(nd.path.mnt);
48521 out_dput:
48522 @@ -3005,6 +3133,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48523 error = PTR_ERR(new_dentry);
48524 if (IS_ERR(new_dentry))
48525 goto out_unlock;
48526 +
48527 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48528 + old_path.dentry->d_inode,
48529 + old_path.dentry->d_inode->i_mode, to)) {
48530 + error = -EACCES;
48531 + goto out_dput;
48532 + }
48533 +
48534 + if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
48535 + old_path.dentry, old_path.mnt, to)) {
48536 + error = -EACCES;
48537 + goto out_dput;
48538 + }
48539 +
48540 error = mnt_want_write(nd.path.mnt);
48541 if (error)
48542 goto out_dput;
48543 @@ -3012,6 +3154,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con
48544 if (error)
48545 goto out_drop_write;
48546 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
48547 + if (!error)
48548 + gr_handle_create(new_dentry, nd.path.mnt);
48549 out_drop_write:
48550 mnt_drop_write(nd.path.mnt);
48551 out_dput:
48552 @@ -3189,6 +3333,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48553 char *to;
48554 int error;
48555
48556 + pax_track_stack();
48557 +
48558 error = user_path_parent(olddfd, oldname, &oldnd, &from);
48559 if (error)
48560 goto exit;
48561 @@ -3245,6 +3391,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48562 if (new_dentry == trap)
48563 goto exit5;
48564
48565 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48566 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48567 + to);
48568 + if (error)
48569 + goto exit5;
48570 +
48571 error = mnt_want_write(oldnd.path.mnt);
48572 if (error)
48573 goto exit5;
48574 @@ -3254,6 +3406,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c
48575 goto exit6;
48576 error = vfs_rename(old_dir->d_inode, old_dentry,
48577 new_dir->d_inode, new_dentry);
48578 + if (!error)
48579 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48580 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48581 exit6:
48582 mnt_drop_write(oldnd.path.mnt);
48583 exit5:
48584 @@ -3279,6 +3434,8 @@ SYSCALL_DEFINE2(rename, const char __use
48585
48586 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48587 {
48588 + char tmpbuf[64];
48589 + const char *newlink;
48590 int len;
48591
48592 len = PTR_ERR(link);
48593 @@ -3288,7 +3445,14 @@ int vfs_readlink(struct dentry *dentry,
48594 len = strlen(link);
48595 if (len > (unsigned) buflen)
48596 len = buflen;
48597 - if (copy_to_user(buffer, link, len))
48598 +
48599 + if (len < sizeof(tmpbuf)) {
48600 + memcpy(tmpbuf, link, len);
48601 + newlink = tmpbuf;
48602 + } else
48603 + newlink = link;
48604 +
48605 + if (copy_to_user(buffer, newlink, len))
48606 len = -EFAULT;
48607 out:
48608 return len;
48609 diff -urNp linux-2.6.39.2/fs/namespace.c linux-2.6.39.2/fs/namespace.c
48610 --- linux-2.6.39.2/fs/namespace.c 2011-05-19 00:06:34.000000000 -0400
48611 +++ linux-2.6.39.2/fs/namespace.c 2011-05-22 20:43:58.000000000 -0400
48612 @@ -1328,6 +1328,9 @@ static int do_umount(struct vfsmount *mn
48613 if (!(sb->s_flags & MS_RDONLY))
48614 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48615 up_write(&sb->s_umount);
48616 +
48617 + gr_log_remount(mnt->mnt_devname, retval);
48618 +
48619 return retval;
48620 }
48621
48622 @@ -1347,6 +1350,9 @@ static int do_umount(struct vfsmount *mn
48623 br_write_unlock(vfsmount_lock);
48624 up_write(&namespace_sem);
48625 release_mounts(&umount_list);
48626 +
48627 + gr_log_unmount(mnt->mnt_devname, retval);
48628 +
48629 return retval;
48630 }
48631
48632 @@ -2338,6 +2344,16 @@ long do_mount(char *dev_name, char *dir_
48633 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48634 MS_STRICTATIME);
48635
48636 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48637 + retval = -EPERM;
48638 + goto dput_out;
48639 + }
48640 +
48641 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48642 + retval = -EPERM;
48643 + goto dput_out;
48644 + }
48645 +
48646 if (flags & MS_REMOUNT)
48647 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48648 data_page);
48649 @@ -2352,6 +2368,9 @@ long do_mount(char *dev_name, char *dir_
48650 dev_name, data_page);
48651 dput_out:
48652 path_put(&path);
48653 +
48654 + gr_log_mount(dev_name, dir_name, retval);
48655 +
48656 return retval;
48657 }
48658
48659 @@ -2575,6 +2594,11 @@ SYSCALL_DEFINE2(pivot_root, const char _
48660 if (error)
48661 goto out2;
48662
48663 + if (gr_handle_chroot_pivot()) {
48664 + error = -EPERM;
48665 + goto out2;
48666 + }
48667 +
48668 get_fs_root(current->fs, &root);
48669 error = lock_mount(&old);
48670 if (error)
48671 diff -urNp linux-2.6.39.2/fs/ncpfs/dir.c linux-2.6.39.2/fs/ncpfs/dir.c
48672 --- linux-2.6.39.2/fs/ncpfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48673 +++ linux-2.6.39.2/fs/ncpfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48674 @@ -299,6 +299,8 @@ ncp_lookup_validate(struct dentry *dentr
48675 int res, val = 0, len;
48676 __u8 __name[NCP_MAXPATHLEN + 1];
48677
48678 + pax_track_stack();
48679 +
48680 if (dentry == dentry->d_sb->s_root)
48681 return 1;
48682
48683 @@ -844,6 +846,8 @@ static struct dentry *ncp_lookup(struct
48684 int error, res, len;
48685 __u8 __name[NCP_MAXPATHLEN + 1];
48686
48687 + pax_track_stack();
48688 +
48689 error = -EIO;
48690 if (!ncp_conn_valid(server))
48691 goto finished;
48692 @@ -931,6 +935,8 @@ int ncp_create_new(struct inode *dir, st
48693 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
48694 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
48695
48696 + pax_track_stack();
48697 +
48698 ncp_age_dentry(server, dentry);
48699 len = sizeof(__name);
48700 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
48701 @@ -992,6 +998,8 @@ static int ncp_mkdir(struct inode *dir,
48702 int error, len;
48703 __u8 __name[NCP_MAXPATHLEN + 1];
48704
48705 + pax_track_stack();
48706 +
48707 DPRINTK("ncp_mkdir: making %s/%s\n",
48708 dentry->d_parent->d_name.name, dentry->d_name.name);
48709
48710 @@ -1135,6 +1143,8 @@ static int ncp_rename(struct inode *old_
48711 int old_len, new_len;
48712 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
48713
48714 + pax_track_stack();
48715 +
48716 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
48717 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
48718 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
48719 diff -urNp linux-2.6.39.2/fs/ncpfs/inode.c linux-2.6.39.2/fs/ncpfs/inode.c
48720 --- linux-2.6.39.2/fs/ncpfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48721 +++ linux-2.6.39.2/fs/ncpfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48722 @@ -461,6 +461,8 @@ static int ncp_fill_super(struct super_b
48723 #endif
48724 struct ncp_entry_info finfo;
48725
48726 + pax_track_stack();
48727 +
48728 data.wdog_pid = NULL;
48729 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
48730 if (!server)
48731 diff -urNp linux-2.6.39.2/fs/nfs/inode.c linux-2.6.39.2/fs/nfs/inode.c
48732 --- linux-2.6.39.2/fs/nfs/inode.c 2011-05-19 00:06:34.000000000 -0400
48733 +++ linux-2.6.39.2/fs/nfs/inode.c 2011-05-22 19:36:32.000000000 -0400
48734 @@ -999,16 +999,16 @@ static int nfs_size_need_update(const st
48735 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48736 }
48737
48738 -static atomic_long_t nfs_attr_generation_counter;
48739 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48740
48741 static unsigned long nfs_read_attr_generation_counter(void)
48742 {
48743 - return atomic_long_read(&nfs_attr_generation_counter);
48744 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48745 }
48746
48747 unsigned long nfs_inc_attr_generation_counter(void)
48748 {
48749 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48750 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48751 }
48752
48753 void nfs_fattr_init(struct nfs_fattr *fattr)
48754 diff -urNp linux-2.6.39.2/fs/nfs/nfs4proc.c linux-2.6.39.2/fs/nfs/nfs4proc.c
48755 --- linux-2.6.39.2/fs/nfs/nfs4proc.c 2011-06-03 00:04:14.000000000 -0400
48756 +++ linux-2.6.39.2/fs/nfs/nfs4proc.c 2011-06-03 00:32:07.000000000 -0400
48757 @@ -5845,14 +5845,14 @@ struct nfs4_state_recovery_ops nfs41_nog
48758 };
48759 #endif /* CONFIG_NFS_V4_1 */
48760
48761 -struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48762 +const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
48763 .sched_state_renewal = nfs4_proc_async_renew,
48764 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
48765 .renew_lease = nfs4_proc_renew,
48766 };
48767
48768 #if defined(CONFIG_NFS_V4_1)
48769 -struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48770 +const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
48771 .sched_state_renewal = nfs41_proc_async_sequence,
48772 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
48773 .renew_lease = nfs4_proc_sequence,
48774 diff -urNp linux-2.6.39.2/fs/nfsd/lockd.c linux-2.6.39.2/fs/nfsd/lockd.c
48775 --- linux-2.6.39.2/fs/nfsd/lockd.c 2011-05-19 00:06:34.000000000 -0400
48776 +++ linux-2.6.39.2/fs/nfsd/lockd.c 2011-05-22 19:36:32.000000000 -0400
48777 @@ -60,7 +60,7 @@ nlm_fclose(struct file *filp)
48778 fput(filp);
48779 }
48780
48781 -static struct nlmsvc_binding nfsd_nlm_ops = {
48782 +static const struct nlmsvc_binding nfsd_nlm_ops = {
48783 .fopen = nlm_fopen, /* open file for locking */
48784 .fclose = nlm_fclose, /* close file */
48785 };
48786 diff -urNp linux-2.6.39.2/fs/nfsd/nfs4state.c linux-2.6.39.2/fs/nfsd/nfs4state.c
48787 --- linux-2.6.39.2/fs/nfsd/nfs4state.c 2011-05-19 00:06:34.000000000 -0400
48788 +++ linux-2.6.39.2/fs/nfsd/nfs4state.c 2011-05-22 19:36:32.000000000 -0400
48789 @@ -3784,6 +3784,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struc
48790 unsigned int strhashval;
48791 int err;
48792
48793 + pax_track_stack();
48794 +
48795 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
48796 (long long) lock->lk_offset,
48797 (long long) lock->lk_length);
48798 diff -urNp linux-2.6.39.2/fs/nfsd/nfs4xdr.c linux-2.6.39.2/fs/nfsd/nfs4xdr.c
48799 --- linux-2.6.39.2/fs/nfsd/nfs4xdr.c 2011-05-19 00:06:34.000000000 -0400
48800 +++ linux-2.6.39.2/fs/nfsd/nfs4xdr.c 2011-05-22 19:36:32.000000000 -0400
48801 @@ -1793,6 +1793,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s
48802 .dentry = dentry,
48803 };
48804
48805 + pax_track_stack();
48806 +
48807 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
48808 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
48809 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
48810 diff -urNp linux-2.6.39.2/fs/nfsd/nfsctl.c linux-2.6.39.2/fs/nfsd/nfsctl.c
48811 --- linux-2.6.39.2/fs/nfsd/nfsctl.c 2011-05-19 00:06:34.000000000 -0400
48812 +++ linux-2.6.39.2/fs/nfsd/nfsctl.c 2011-05-22 19:36:32.000000000 -0400
48813 @@ -182,7 +182,7 @@ static int export_features_open(struct i
48814 return single_open(file, export_features_show, NULL);
48815 }
48816
48817 -static struct file_operations export_features_operations = {
48818 +static const struct file_operations export_features_operations = {
48819 .open = export_features_open,
48820 .read = seq_read,
48821 .llseek = seq_lseek,
48822 diff -urNp linux-2.6.39.2/fs/nfsd/vfs.c linux-2.6.39.2/fs/nfsd/vfs.c
48823 --- linux-2.6.39.2/fs/nfsd/vfs.c 2011-05-19 00:06:34.000000000 -0400
48824 +++ linux-2.6.39.2/fs/nfsd/vfs.c 2011-05-22 19:36:32.000000000 -0400
48825 @@ -898,7 +898,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, st
48826 } else {
48827 oldfs = get_fs();
48828 set_fs(KERNEL_DS);
48829 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48830 + host_err = vfs_readv(file, (__force struct iovec __user *)vec, vlen, &offset);
48831 set_fs(oldfs);
48832 }
48833
48834 @@ -1002,7 +1002,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
48835
48836 /* Write the data. */
48837 oldfs = get_fs(); set_fs(KERNEL_DS);
48838 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48839 + host_err = vfs_writev(file, (__force struct iovec __user *)vec, vlen, &offset);
48840 set_fs(oldfs);
48841 if (host_err < 0)
48842 goto out_nfserr;
48843 @@ -1525,7 +1525,7 @@ nfsd_readlink(struct svc_rqst *rqstp, st
48844 */
48845
48846 oldfs = get_fs(); set_fs(KERNEL_DS);
48847 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
48848 + host_err = inode->i_op->readlink(dentry, (__force char __user *)buf, *lenp);
48849 set_fs(oldfs);
48850
48851 if (host_err < 0)
48852 diff -urNp linux-2.6.39.2/fs/nilfs2/segment.c linux-2.6.39.2/fs/nilfs2/segment.c
48853 --- linux-2.6.39.2/fs/nilfs2/segment.c 2011-05-19 00:06:34.000000000 -0400
48854 +++ linux-2.6.39.2/fs/nilfs2/segment.c 2011-05-22 19:36:32.000000000 -0400
48855 @@ -555,7 +555,7 @@ static void nilfs_write_file_node_binfo(
48856 *vblocknr = binfo->bi_v.bi_vblocknr;
48857 }
48858
48859 -static struct nilfs_sc_operations nilfs_sc_file_ops = {
48860 +static const struct nilfs_sc_operations nilfs_sc_file_ops = {
48861 .collect_data = nilfs_collect_file_data,
48862 .collect_node = nilfs_collect_file_node,
48863 .collect_bmap = nilfs_collect_file_bmap,
48864 @@ -604,7 +604,7 @@ static void nilfs_write_dat_node_binfo(s
48865 *binfo_dat = binfo->bi_dat;
48866 }
48867
48868 -static struct nilfs_sc_operations nilfs_sc_dat_ops = {
48869 +static const struct nilfs_sc_operations nilfs_sc_dat_ops = {
48870 .collect_data = nilfs_collect_dat_data,
48871 .collect_node = nilfs_collect_file_node,
48872 .collect_bmap = nilfs_collect_dat_bmap,
48873 @@ -612,7 +612,7 @@ static struct nilfs_sc_operations nilfs_
48874 .write_node_binfo = nilfs_write_dat_node_binfo,
48875 };
48876
48877 -static struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48878 +static const struct nilfs_sc_operations nilfs_sc_dsync_ops = {
48879 .collect_data = nilfs_collect_file_data,
48880 .collect_node = NULL,
48881 .collect_bmap = NULL,
48882 @@ -971,7 +971,7 @@ static size_t nilfs_segctor_buffer_rest(
48883
48884 static int nilfs_segctor_scan_file(struct nilfs_sc_info *sci,
48885 struct inode *inode,
48886 - struct nilfs_sc_operations *sc_ops)
48887 + const struct nilfs_sc_operations *sc_ops)
48888 {
48889 LIST_HEAD(data_buffers);
48890 LIST_HEAD(node_buffers);
48891 @@ -1475,7 +1475,7 @@ nilfs_segctor_update_payload_blocknr(str
48892 sector_t blocknr;
48893 unsigned long nfinfo = segbuf->sb_sum.nfinfo;
48894 unsigned long nblocks = 0, ndatablk = 0;
48895 - struct nilfs_sc_operations *sc_op = NULL;
48896 + const struct nilfs_sc_operations *sc_op = NULL;
48897 struct nilfs_segsum_pointer ssp;
48898 struct nilfs_finfo *finfo = NULL;
48899 union nilfs_binfo binfo;
48900 diff -urNp linux-2.6.39.2/fs/notify/dnotify/dnotify.c linux-2.6.39.2/fs/notify/dnotify/dnotify.c
48901 --- linux-2.6.39.2/fs/notify/dnotify/dnotify.c 2011-05-19 00:06:34.000000000 -0400
48902 +++ linux-2.6.39.2/fs/notify/dnotify/dnotify.c 2011-05-22 19:36:32.000000000 -0400
48903 @@ -151,7 +151,7 @@ static void dnotify_free_mark(struct fsn
48904 kmem_cache_free(dnotify_mark_cache, dn_mark);
48905 }
48906
48907 -static struct fsnotify_ops dnotify_fsnotify_ops = {
48908 +static const struct fsnotify_ops dnotify_fsnotify_ops = {
48909 .handle_event = dnotify_handle_event,
48910 .should_send_event = dnotify_should_send_event,
48911 .free_group_priv = NULL,
48912 diff -urNp linux-2.6.39.2/fs/notify/notification.c linux-2.6.39.2/fs/notify/notification.c
48913 --- linux-2.6.39.2/fs/notify/notification.c 2011-05-19 00:06:34.000000000 -0400
48914 +++ linux-2.6.39.2/fs/notify/notification.c 2011-05-22 19:36:32.000000000 -0400
48915 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event
48916 * get set to 0 so it will never get 'freed'
48917 */
48918 static struct fsnotify_event *q_overflow_event;
48919 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48920 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48921
48922 /**
48923 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48924 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = A
48925 */
48926 u32 fsnotify_get_cookie(void)
48927 {
48928 - return atomic_inc_return(&fsnotify_sync_cookie);
48929 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48930 }
48931 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48932
48933 diff -urNp linux-2.6.39.2/fs/ntfs/dir.c linux-2.6.39.2/fs/ntfs/dir.c
48934 --- linux-2.6.39.2/fs/ntfs/dir.c 2011-05-19 00:06:34.000000000 -0400
48935 +++ linux-2.6.39.2/fs/ntfs/dir.c 2011-05-22 19:36:32.000000000 -0400
48936 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48937 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48938 ~(s64)(ndir->itype.index.block_size - 1)));
48939 /* Bounds checks. */
48940 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48941 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48942 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48943 "inode 0x%lx or driver bug.", vdir->i_ino);
48944 goto err_out;
48945 diff -urNp linux-2.6.39.2/fs/ntfs/file.c linux-2.6.39.2/fs/ntfs/file.c
48946 --- linux-2.6.39.2/fs/ntfs/file.c 2011-05-19 00:06:34.000000000 -0400
48947 +++ linux-2.6.39.2/fs/ntfs/file.c 2011-05-22 19:36:32.000000000 -0400
48948 @@ -2222,6 +2222,6 @@ const struct inode_operations ntfs_file_
48949 #endif /* NTFS_RW */
48950 };
48951
48952 -const struct file_operations ntfs_empty_file_ops = {};
48953 +const struct file_operations ntfs_empty_file_ops __read_only;
48954
48955 -const struct inode_operations ntfs_empty_inode_ops = {};
48956 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48957 diff -urNp linux-2.6.39.2/fs/ocfs2/cluster/heartbeat.c linux-2.6.39.2/fs/ocfs2/cluster/heartbeat.c
48958 --- linux-2.6.39.2/fs/ocfs2/cluster/heartbeat.c 2011-05-19 00:06:34.000000000 -0400
48959 +++ linux-2.6.39.2/fs/ocfs2/cluster/heartbeat.c 2011-05-22 19:36:32.000000000 -0400
48960 @@ -2261,7 +2261,7 @@ static struct configfs_item_operations o
48961 .store_attribute = o2hb_heartbeat_group_store,
48962 };
48963
48964 -static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48965 +static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
48966 .make_item = o2hb_heartbeat_group_make_item,
48967 .drop_item = o2hb_heartbeat_group_drop_item,
48968 };
48969 diff -urNp linux-2.6.39.2/fs/ocfs2/cluster/nodemanager.c linux-2.6.39.2/fs/ocfs2/cluster/nodemanager.c
48970 --- linux-2.6.39.2/fs/ocfs2/cluster/nodemanager.c 2011-05-19 00:06:34.000000000 -0400
48971 +++ linux-2.6.39.2/fs/ocfs2/cluster/nodemanager.c 2011-05-22 19:36:32.000000000 -0400
48972 @@ -752,7 +752,7 @@ static void o2nm_node_group_drop_item(st
48973 config_item_put(item);
48974 }
48975
48976 -static struct configfs_group_operations o2nm_node_group_group_ops = {
48977 +static const struct configfs_group_operations o2nm_node_group_group_ops = {
48978 .make_item = o2nm_node_group_make_item,
48979 .drop_item = o2nm_node_group_drop_item,
48980 };
48981 @@ -869,7 +869,7 @@ static void o2nm_cluster_group_drop_item
48982 config_item_put(item);
48983 }
48984
48985 -static struct configfs_group_operations o2nm_cluster_group_group_ops = {
48986 +static const struct configfs_group_operations o2nm_cluster_group_group_ops = {
48987 .make_group = o2nm_cluster_group_make_group,
48988 .drop_item = o2nm_cluster_group_drop_item,
48989 };
48990 diff -urNp linux-2.6.39.2/fs/ocfs2/localalloc.c linux-2.6.39.2/fs/ocfs2/localalloc.c
48991 --- linux-2.6.39.2/fs/ocfs2/localalloc.c 2011-05-19 00:06:34.000000000 -0400
48992 +++ linux-2.6.39.2/fs/ocfs2/localalloc.c 2011-05-22 19:36:32.000000000 -0400
48993 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_windo
48994 goto bail;
48995 }
48996
48997 - atomic_inc(&osb->alloc_stats.moves);
48998 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48999
49000 bail:
49001 if (handle)
49002 diff -urNp linux-2.6.39.2/fs/ocfs2/namei.c linux-2.6.39.2/fs/ocfs2/namei.c
49003 --- linux-2.6.39.2/fs/ocfs2/namei.c 2011-05-19 00:06:34.000000000 -0400
49004 +++ linux-2.6.39.2/fs/ocfs2/namei.c 2011-05-22 19:36:32.000000000 -0400
49005 @@ -1063,6 +1063,8 @@ static int ocfs2_rename(struct inode *ol
49006 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
49007 struct ocfs2_dir_lookup_result target_insert = { NULL, };
49008
49009 + pax_track_stack();
49010 +
49011 /* At some point it might be nice to break this function up a
49012 * bit. */
49013
49014 diff -urNp linux-2.6.39.2/fs/ocfs2/ocfs2.h linux-2.6.39.2/fs/ocfs2/ocfs2.h
49015 --- linux-2.6.39.2/fs/ocfs2/ocfs2.h 2011-05-19 00:06:34.000000000 -0400
49016 +++ linux-2.6.39.2/fs/ocfs2/ocfs2.h 2011-05-22 19:36:32.000000000 -0400
49017 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
49018
49019 struct ocfs2_alloc_stats
49020 {
49021 - atomic_t moves;
49022 - atomic_t local_data;
49023 - atomic_t bitmap_data;
49024 - atomic_t bg_allocs;
49025 - atomic_t bg_extends;
49026 + atomic_unchecked_t moves;
49027 + atomic_unchecked_t local_data;
49028 + atomic_unchecked_t bitmap_data;
49029 + atomic_unchecked_t bg_allocs;
49030 + atomic_unchecked_t bg_extends;
49031 };
49032
49033 enum ocfs2_local_alloc_state
49034 diff -urNp linux-2.6.39.2/fs/ocfs2/stackglue.h linux-2.6.39.2/fs/ocfs2/stackglue.h
49035 --- linux-2.6.39.2/fs/ocfs2/stackglue.h 2011-05-19 00:06:34.000000000 -0400
49036 +++ linux-2.6.39.2/fs/ocfs2/stackglue.h 2011-05-22 19:36:32.000000000 -0400
49037 @@ -221,13 +221,13 @@ struct ocfs2_stack_operations {
49038 };
49039
49040 /*
49041 - * Each stack plugin must describe itself by registering a
49042 + * Each stack plugin must describe itself by registerin const g a
49043 * ocfs2_stack_plugin structure. This is only seen by stackglue and the
49044 * stack driver.
49045 */
49046 struct ocfs2_stack_plugin {
49047 char *sp_name;
49048 - struct ocfs2_stack_operations *sp_ops;
49049 + const struct ocfs2_stack_operations *sp_ops;
49050 struct module *sp_owner;
49051
49052 /* These are managed by the stackglue code. */
49053 diff -urNp linux-2.6.39.2/fs/ocfs2/stack_o2cb.c linux-2.6.39.2/fs/ocfs2/stack_o2cb.c
49054 --- linux-2.6.39.2/fs/ocfs2/stack_o2cb.c 2011-05-19 00:06:34.000000000 -0400
49055 +++ linux-2.6.39.2/fs/ocfs2/stack_o2cb.c 2011-06-07 18:07:24.000000000 -0400
49056 @@ -358,7 +358,7 @@ static int o2cb_cluster_this_node(unsign
49057 return 0;
49058 }
49059
49060 -static struct ocfs2_stack_operations o2cb_stack_ops = {
49061 +static const struct ocfs2_stack_operations o2cb_stack_ops = {
49062 .connect = o2cb_cluster_connect,
49063 .disconnect = o2cb_cluster_disconnect,
49064 .this_node = o2cb_cluster_this_node,
49065 diff -urNp linux-2.6.39.2/fs/ocfs2/stack_user.c linux-2.6.39.2/fs/ocfs2/stack_user.c
49066 --- linux-2.6.39.2/fs/ocfs2/stack_user.c 2011-05-19 00:06:34.000000000 -0400
49067 +++ linux-2.6.39.2/fs/ocfs2/stack_user.c 2011-05-22 19:36:32.000000000 -0400
49068 @@ -399,7 +399,7 @@ static int ocfs2_control_do_setversion_m
49069 long major, minor;
49070 char *ptr = NULL;
49071 struct ocfs2_control_private *p = file->private_data;
49072 - struct ocfs2_protocol_version *max =
49073 + const struct ocfs2_protocol_version *max =
49074 &ocfs2_user_plugin.sp_max_proto;
49075
49076 if (ocfs2_control_get_handshake_state(file) !=
49077 @@ -861,7 +861,7 @@ static int user_cluster_this_node(unsign
49078 return 0;
49079 }
49080
49081 -static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49082 +static const struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
49083 .connect = user_cluster_connect,
49084 .disconnect = user_cluster_disconnect,
49085 .this_node = user_cluster_this_node,
49086 diff -urNp linux-2.6.39.2/fs/ocfs2/suballoc.c linux-2.6.39.2/fs/ocfs2/suballoc.c
49087 --- linux-2.6.39.2/fs/ocfs2/suballoc.c 2011-05-19 00:06:34.000000000 -0400
49088 +++ linux-2.6.39.2/fs/ocfs2/suballoc.c 2011-05-22 19:36:32.000000000 -0400
49089 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(s
49090 mlog_errno(status);
49091 goto bail;
49092 }
49093 - atomic_inc(&osb->alloc_stats.bg_extends);
49094 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49095
49096 /* You should never ask for this much metadata */
49097 BUG_ON(bits_wanted >
49098 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handl
49099 mlog_errno(status);
49100 goto bail;
49101 }
49102 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49103 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49104
49105 *suballoc_loc = res.sr_bg_blkno;
49106 *suballoc_bit_start = res.sr_bit_offset;
49107 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_
49108 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49109 res->sr_bits);
49110
49111 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49112 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49113
49114 BUG_ON(res->sr_bits != 1);
49115
49116 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *hand
49117 mlog_errno(status);
49118 goto bail;
49119 }
49120 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49121 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49122
49123 BUG_ON(res.sr_bits != 1);
49124
49125 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *han
49126 cluster_start,
49127 num_clusters);
49128 if (!status)
49129 - atomic_inc(&osb->alloc_stats.local_data);
49130 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
49131 } else {
49132 if (min_clusters > (osb->bitmap_cpg - 1)) {
49133 /* The only paths asking for contiguousness
49134 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *han
49135 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49136 res.sr_bg_blkno,
49137 res.sr_bit_offset);
49138 - atomic_inc(&osb->alloc_stats.bitmap_data);
49139 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49140 *num_clusters = res.sr_bits;
49141 }
49142 }
49143 diff -urNp linux-2.6.39.2/fs/ocfs2/super.c linux-2.6.39.2/fs/ocfs2/super.c
49144 --- linux-2.6.39.2/fs/ocfs2/super.c 2011-05-19 00:06:34.000000000 -0400
49145 +++ linux-2.6.39.2/fs/ocfs2/super.c 2011-05-22 19:36:32.000000000 -0400
49146 @@ -299,11 +299,11 @@ static int ocfs2_osb_dump(struct ocfs2_s
49147 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49148 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49149 "Stats",
49150 - atomic_read(&osb->alloc_stats.bitmap_data),
49151 - atomic_read(&osb->alloc_stats.local_data),
49152 - atomic_read(&osb->alloc_stats.bg_allocs),
49153 - atomic_read(&osb->alloc_stats.moves),
49154 - atomic_read(&osb->alloc_stats.bg_extends));
49155 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49156 + atomic_read_unchecked(&osb->alloc_stats.local_data),
49157 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49158 + atomic_read_unchecked(&osb->alloc_stats.moves),
49159 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49160
49161 out += snprintf(buf + out, len - out,
49162 "%10s => State: %u Descriptor: %llu Size: %u bits "
49163 @@ -2111,11 +2111,11 @@ static int ocfs2_initialize_super(struct
49164 spin_lock_init(&osb->osb_xattr_lock);
49165 ocfs2_init_steal_slots(osb);
49166
49167 - atomic_set(&osb->alloc_stats.moves, 0);
49168 - atomic_set(&osb->alloc_stats.local_data, 0);
49169 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
49170 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
49171 - atomic_set(&osb->alloc_stats.bg_extends, 0);
49172 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49173 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49174 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49175 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49176 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49177
49178 /* Copy the blockcheck stats from the superblock probe */
49179 osb->osb_ecc_stats = *stats;
49180 diff -urNp linux-2.6.39.2/fs/ocfs2/symlink.c linux-2.6.39.2/fs/ocfs2/symlink.c
49181 --- linux-2.6.39.2/fs/ocfs2/symlink.c 2011-05-19 00:06:34.000000000 -0400
49182 +++ linux-2.6.39.2/fs/ocfs2/symlink.c 2011-05-22 19:36:32.000000000 -0400
49183 @@ -142,7 +142,7 @@ bail:
49184
49185 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49186 {
49187 - char *link = nd_get_link(nd);
49188 + const char *link = nd_get_link(nd);
49189 if (!IS_ERR(link))
49190 kfree(link);
49191 }
49192 diff -urNp linux-2.6.39.2/fs/open.c linux-2.6.39.2/fs/open.c
49193 --- linux-2.6.39.2/fs/open.c 2011-05-19 00:06:34.000000000 -0400
49194 +++ linux-2.6.39.2/fs/open.c 2011-05-22 20:46:51.000000000 -0400
49195 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char _
49196 error = locks_verify_truncate(inode, NULL, length);
49197 if (!error)
49198 error = security_path_truncate(&path);
49199 +
49200 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
49201 + error = -EACCES;
49202 +
49203 if (!error)
49204 error = do_truncate(path.dentry, length, 0, NULL);
49205
49206 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, con
49207 if (__mnt_is_readonly(path.mnt))
49208 res = -EROFS;
49209
49210 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
49211 + res = -EACCES;
49212 +
49213 out_path_release:
49214 path_put(&path);
49215 out:
49216 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user
49217 if (error)
49218 goto dput_and_out;
49219
49220 + gr_log_chdir(path.dentry, path.mnt);
49221 +
49222 set_fs_pwd(current->fs, &path);
49223
49224 dput_and_out:
49225 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd
49226 goto out_putf;
49227
49228 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
49229 +
49230 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
49231 + error = -EPERM;
49232 +
49233 + if (!error)
49234 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
49235 +
49236 if (!error)
49237 set_fs_pwd(current->fs, &file->f_path);
49238 out_putf:
49239 @@ -438,7 +454,18 @@ SYSCALL_DEFINE1(chroot, const char __use
49240 if (error)
49241 goto dput_and_out;
49242
49243 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
49244 + goto dput_and_out;
49245 +
49246 + if (gr_handle_chroot_caps(&path)) {
49247 + error = -ENOMEM;
49248 + goto dput_and_out;
49249 + }
49250 +
49251 set_fs_root(current->fs, &path);
49252 +
49253 + gr_handle_chroot_chdir(&path);
49254 +
49255 error = 0;
49256 dput_and_out:
49257 path_put(&path);
49258 @@ -466,12 +493,25 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd
49259 err = mnt_want_write_file(file);
49260 if (err)
49261 goto out_putf;
49262 +
49263 mutex_lock(&inode->i_mutex);
49264 +
49265 + if (!gr_acl_handle_fchmod(dentry, file->f_vfsmnt, mode)) {
49266 + err = -EACCES;
49267 + goto out_unlock;
49268 + }
49269 +
49270 err = security_path_chmod(dentry, file->f_vfsmnt, mode);
49271 if (err)
49272 goto out_unlock;
49273 if (mode == (mode_t) -1)
49274 mode = inode->i_mode;
49275 +
49276 + if (gr_handle_chroot_chmod(dentry, file->f_vfsmnt, mode)) {
49277 + err = -EACCES;
49278 + goto out_unlock;
49279 + }
49280 +
49281 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49282 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49283 err = notify_change(dentry, &newattrs);
49284 @@ -499,12 +539,25 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
49285 error = mnt_want_write(path.mnt);
49286 if (error)
49287 goto dput_and_out;
49288 +
49289 mutex_lock(&inode->i_mutex);
49290 +
49291 + if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
49292 + error = -EACCES;
49293 + goto out_unlock;
49294 + }
49295 +
49296 error = security_path_chmod(path.dentry, path.mnt, mode);
49297 if (error)
49298 goto out_unlock;
49299 if (mode == (mode_t) -1)
49300 mode = inode->i_mode;
49301 +
49302 + if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
49303 + error = -EACCES;
49304 + goto out_unlock;
49305 + }
49306 +
49307 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
49308 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
49309 error = notify_change(path.dentry, &newattrs);
49310 @@ -528,6 +581,9 @@ static int chown_common(struct path *pat
49311 int error;
49312 struct iattr newattrs;
49313
49314 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
49315 + return -EACCES;
49316 +
49317 newattrs.ia_valid = ATTR_CTIME;
49318 if (user != (uid_t) -1) {
49319 newattrs.ia_valid |= ATTR_UID;
49320 @@ -998,7 +1054,10 @@ long do_sys_open(int dfd, const char __u
49321 if (!IS_ERR(tmp)) {
49322 fd = get_unused_fd_flags(flags);
49323 if (fd >= 0) {
49324 - struct file *f = do_filp_open(dfd, tmp, &op, lookup);
49325 + struct file *f;
49326 + /* don't allow to be set by userland */
49327 + flags &= ~FMODE_GREXEC;
49328 + f = do_filp_open(dfd, tmp, &op, lookup);
49329 if (IS_ERR(f)) {
49330 put_unused_fd(fd);
49331 fd = PTR_ERR(f);
49332 diff -urNp linux-2.6.39.2/fs/partitions/ldm.c linux-2.6.39.2/fs/partitions/ldm.c
49333 --- linux-2.6.39.2/fs/partitions/ldm.c 2011-06-03 00:04:14.000000000 -0400
49334 +++ linux-2.6.39.2/fs/partitions/ldm.c 2011-06-03 00:32:07.000000000 -0400
49335 @@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data
49336 ldm_error ("A VBLK claims to have %d parts.", num);
49337 return false;
49338 }
49339 +
49340 if (rec >= num) {
49341 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
49342 return false;
49343 @@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data
49344 goto found;
49345 }
49346
49347 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
49348 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
49349 if (!f) {
49350 ldm_crit ("Out of memory.");
49351 return false;
49352 diff -urNp linux-2.6.39.2/fs/pipe.c linux-2.6.39.2/fs/pipe.c
49353 --- linux-2.6.39.2/fs/pipe.c 2011-05-19 00:06:34.000000000 -0400
49354 +++ linux-2.6.39.2/fs/pipe.c 2011-05-22 19:41:37.000000000 -0400
49355 @@ -420,9 +420,9 @@ redo:
49356 }
49357 if (bufs) /* More to do? */
49358 continue;
49359 - if (!pipe->writers)
49360 + if (!atomic_read(&pipe->writers))
49361 break;
49362 - if (!pipe->waiting_writers) {
49363 + if (!atomic_read(&pipe->waiting_writers)) {
49364 /* syscall merging: Usually we must not sleep
49365 * if O_NONBLOCK is set, or if we got some data.
49366 * But if a writer sleeps in kernel space, then
49367 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const str
49368 mutex_lock(&inode->i_mutex);
49369 pipe = inode->i_pipe;
49370
49371 - if (!pipe->readers) {
49372 + if (!atomic_read(&pipe->readers)) {
49373 send_sig(SIGPIPE, current, 0);
49374 ret = -EPIPE;
49375 goto out;
49376 @@ -530,7 +530,7 @@ redo1:
49377 for (;;) {
49378 int bufs;
49379
49380 - if (!pipe->readers) {
49381 + if (!atomic_read(&pipe->readers)) {
49382 send_sig(SIGPIPE, current, 0);
49383 if (!ret)
49384 ret = -EPIPE;
49385 @@ -616,9 +616,9 @@ redo2:
49386 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49387 do_wakeup = 0;
49388 }
49389 - pipe->waiting_writers++;
49390 + atomic_inc(&pipe->waiting_writers);
49391 pipe_wait(pipe);
49392 - pipe->waiting_writers--;
49393 + atomic_dec(&pipe->waiting_writers);
49394 }
49395 out:
49396 mutex_unlock(&inode->i_mutex);
49397 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table
49398 mask = 0;
49399 if (filp->f_mode & FMODE_READ) {
49400 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
49401 - if (!pipe->writers && filp->f_version != pipe->w_counter)
49402 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
49403 mask |= POLLHUP;
49404 }
49405
49406 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table
49407 * Most Unices do not set POLLERR for FIFOs but on Linux they
49408 * behave exactly like pipes for poll().
49409 */
49410 - if (!pipe->readers)
49411 + if (!atomic_read(&pipe->readers))
49412 mask |= POLLERR;
49413 }
49414
49415 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int de
49416
49417 mutex_lock(&inode->i_mutex);
49418 pipe = inode->i_pipe;
49419 - pipe->readers -= decr;
49420 - pipe->writers -= decw;
49421 + atomic_sub(decr, &pipe->readers);
49422 + atomic_sub(decw, &pipe->writers);
49423
49424 - if (!pipe->readers && !pipe->writers) {
49425 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
49426 free_pipe_info(inode);
49427 } else {
49428 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
49429 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, stru
49430
49431 if (inode->i_pipe) {
49432 ret = 0;
49433 - inode->i_pipe->readers++;
49434 + atomic_inc(&inode->i_pipe->readers);
49435 }
49436
49437 mutex_unlock(&inode->i_mutex);
49438 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, str
49439
49440 if (inode->i_pipe) {
49441 ret = 0;
49442 - inode->i_pipe->writers++;
49443 + atomic_inc(&inode->i_pipe->writers);
49444 }
49445
49446 mutex_unlock(&inode->i_mutex);
49447 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, stru
49448 if (inode->i_pipe) {
49449 ret = 0;
49450 if (filp->f_mode & FMODE_READ)
49451 - inode->i_pipe->readers++;
49452 + atomic_inc(&inode->i_pipe->readers);
49453 if (filp->f_mode & FMODE_WRITE)
49454 - inode->i_pipe->writers++;
49455 + atomic_inc(&inode->i_pipe->writers);
49456 }
49457
49458 mutex_unlock(&inode->i_mutex);
49459 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
49460 inode->i_pipe = NULL;
49461 }
49462
49463 -static struct vfsmount *pipe_mnt __read_mostly;
49464 +struct vfsmount *pipe_mnt __read_mostly;
49465
49466 /*
49467 * pipefs_dname() is called from d_path().
49468 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(voi
49469 goto fail_iput;
49470 inode->i_pipe = pipe;
49471
49472 - pipe->readers = pipe->writers = 1;
49473 + atomic_set(&pipe->readers, 1);
49474 + atomic_set(&pipe->writers, 1);
49475 inode->i_fop = &rdwr_pipefifo_fops;
49476
49477 /*
49478 diff -urNp linux-2.6.39.2/fs/proc/array.c linux-2.6.39.2/fs/proc/array.c
49479 --- linux-2.6.39.2/fs/proc/array.c 2011-05-19 00:06:34.000000000 -0400
49480 +++ linux-2.6.39.2/fs/proc/array.c 2011-05-22 19:41:37.000000000 -0400
49481 @@ -60,6 +60,7 @@
49482 #include <linux/tty.h>
49483 #include <linux/string.h>
49484 #include <linux/mman.h>
49485 +#include <linux/grsecurity.h>
49486 #include <linux/proc_fs.h>
49487 #include <linux/ioport.h>
49488 #include <linux/uaccess.h>
49489 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq
49490 seq_putc(m, '\n');
49491 }
49492
49493 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49494 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
49495 +{
49496 + if (p->mm)
49497 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
49498 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
49499 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
49500 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
49501 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
49502 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
49503 + else
49504 + seq_printf(m, "PaX:\t-----\n");
49505 +}
49506 +#endif
49507 +
49508 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49509 struct pid *pid, struct task_struct *task)
49510 {
49511 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m,
49512 task_cpus_allowed(m, task);
49513 cpuset_task_status_allowed(m, task);
49514 task_context_switch_counts(m, task);
49515 +
49516 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49517 + task_pax(m, task);
49518 +#endif
49519 +
49520 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
49521 + task_grsec_rbac(m, task);
49522 +#endif
49523 +
49524 return 0;
49525 }
49526
49527 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49528 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49529 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49530 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49531 +#endif
49532 +
49533 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49534 struct pid *pid, struct task_struct *task, int whole)
49535 {
49536 @@ -375,9 +406,11 @@ static int do_task_stat(struct seq_file
49537 cputime_t cutime, cstime, utime, stime;
49538 cputime_t cgtime, gtime;
49539 unsigned long rsslim = 0;
49540 - char tcomm[sizeof(task->comm)];
49541 + char tcomm[sizeof(task->comm)] = { 0 };
49542 unsigned long flags;
49543
49544 + pax_track_stack();
49545 +
49546 state = *get_task_state(task);
49547 vsize = eip = esp = 0;
49548 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
49549 @@ -449,6 +482,19 @@ static int do_task_stat(struct seq_file
49550 gtime = task->gtime;
49551 }
49552
49553 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49554 + if (PAX_RAND_FLAGS(mm)) {
49555 + eip = 0;
49556 + esp = 0;
49557 + wchan = 0;
49558 + }
49559 +#endif
49560 +#ifdef CONFIG_GRKERNSEC_HIDESYM
49561 + wchan = 0;
49562 + eip =0;
49563 + esp =0;
49564 +#endif
49565 +
49566 /* scale priority and nice values from timeslices to -20..20 */
49567 /* to make it look like a "normal" Unix priority/nice value */
49568 priority = task_prio(task);
49569 @@ -489,9 +535,15 @@ static int do_task_stat(struct seq_file
49570 vsize,
49571 mm ? get_mm_rss(mm) : 0,
49572 rsslim,
49573 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49574 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
49575 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
49576 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
49577 +#else
49578 mm ? (permitted ? mm->start_code : 1) : 0,
49579 mm ? (permitted ? mm->end_code : 1) : 0,
49580 (permitted && mm) ? mm->start_stack : 0,
49581 +#endif
49582 esp,
49583 eip,
49584 /* The signal information here is obsolete.
49585 @@ -544,3 +596,18 @@ int proc_pid_statm(struct seq_file *m, s
49586
49587 return 0;
49588 }
49589 +
49590 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49591 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49592 +{
49593 + u32 curr_ip = 0;
49594 + unsigned long flags;
49595 +
49596 + if (lock_task_sighand(task, &flags)) {
49597 + curr_ip = task->signal->curr_ip;
49598 + unlock_task_sighand(task, &flags);
49599 + }
49600 +
49601 + return sprintf(buffer, "%pI4\n", &curr_ip);
49602 +}
49603 +#endif
49604 diff -urNp linux-2.6.39.2/fs/proc/base.c linux-2.6.39.2/fs/proc/base.c
49605 --- linux-2.6.39.2/fs/proc/base.c 2011-05-19 00:06:34.000000000 -0400
49606 +++ linux-2.6.39.2/fs/proc/base.c 2011-06-04 21:20:04.000000000 -0400
49607 @@ -104,6 +104,22 @@ struct pid_entry {
49608 union proc_op op;
49609 };
49610
49611 +struct getdents_callback {
49612 + struct linux_dirent __user * current_dir;
49613 + struct linux_dirent __user * previous;
49614 + struct file * file;
49615 + int count;
49616 + int error;
49617 +};
49618 +
49619 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
49620 + loff_t offset, u64 ino, unsigned int d_type)
49621 +{
49622 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
49623 + buf->error = -EINVAL;
49624 + return 0;
49625 +}
49626 +
49627 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49628 .name = (NAME), \
49629 .len = sizeof(NAME) - 1, \
49630 @@ -206,6 +222,9 @@ static struct mm_struct *__check_mem_per
49631 if (task == current)
49632 return mm;
49633
49634 + if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
49635 + return ERR_PTR(-EPERM);
49636 +
49637 /*
49638 * If current is actively ptrace'ing, and would also be
49639 * permitted to freshly attach with ptrace now, permit it.
49640 @@ -279,6 +298,9 @@ static int proc_pid_cmdline(struct task_
49641 if (!mm->arg_end)
49642 goto out_mm; /* Shh! No looking before we're done */
49643
49644 + if (gr_acl_handle_procpidmem(task))
49645 + goto out_mm;
49646 +
49647 len = mm->arg_end - mm->arg_start;
49648
49649 if (len > PAGE_SIZE)
49650 @@ -306,12 +328,28 @@ out:
49651 return res;
49652 }
49653
49654 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49655 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49656 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49657 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49658 +#endif
49659 +
49660 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49661 {
49662 struct mm_struct *mm = mm_for_maps(task);
49663 int res = PTR_ERR(mm);
49664 if (mm && !IS_ERR(mm)) {
49665 unsigned int nwords = 0;
49666 +
49667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49668 + /* allow if we're currently ptracing this task */
49669 + if (PAX_RAND_FLAGS(mm) &&
49670 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49671 + mmput(mm);
49672 + return res;
49673 + }
49674 +#endif
49675 +
49676 do {
49677 nwords += 2;
49678 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49679 @@ -325,7 +363,7 @@ static int proc_pid_auxv(struct task_str
49680 }
49681
49682
49683 -#ifdef CONFIG_KALLSYMS
49684 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49685 /*
49686 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49687 * Returns the resolved symbol. If that fails, simply return the address.
49688 @@ -364,7 +402,7 @@ static void unlock_trace(struct task_str
49689 mutex_unlock(&task->signal->cred_guard_mutex);
49690 }
49691
49692 -#ifdef CONFIG_STACKTRACE
49693 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49694
49695 #define MAX_STACK_TRACE_DEPTH 64
49696
49697 @@ -555,7 +593,7 @@ static int proc_pid_limits(struct task_s
49698 return count;
49699 }
49700
49701 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49702 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49703 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49704 {
49705 long nr;
49706 @@ -584,7 +622,7 @@ static int proc_pid_syscall(struct task_
49707 /************************************************************************/
49708
49709 /* permission checks */
49710 -static int proc_fd_access_allowed(struct inode *inode)
49711 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49712 {
49713 struct task_struct *task;
49714 int allowed = 0;
49715 @@ -594,7 +632,10 @@ static int proc_fd_access_allowed(struct
49716 */
49717 task = get_proc_task(inode);
49718 if (task) {
49719 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49720 + if (log)
49721 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
49722 + else
49723 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49724 put_task_struct(task);
49725 }
49726 return allowed;
49727 @@ -973,6 +1014,9 @@ static ssize_t environ_read(struct file
49728 if (!task)
49729 goto out_no_task;
49730
49731 + if (gr_acl_handle_procpidmem(task))
49732 + goto out;
49733 +
49734 ret = -ENOMEM;
49735 page = (char *)__get_free_page(GFP_TEMPORARY);
49736 if (!page)
49737 @@ -1660,7 +1704,7 @@ static void *proc_pid_follow_link(struct
49738 path_put(&nd->path);
49739
49740 /* Are we allowed to snoop on the tasks file descriptors? */
49741 - if (!proc_fd_access_allowed(inode))
49742 + if (!proc_fd_access_allowed(inode,0))
49743 goto out;
49744
49745 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
49746 @@ -1699,8 +1743,18 @@ static int proc_pid_readlink(struct dent
49747 struct path path;
49748
49749 /* Are we allowed to snoop on the tasks file descriptors? */
49750 - if (!proc_fd_access_allowed(inode))
49751 - goto out;
49752 + /* logging this is needed for learning on chromium to work properly,
49753 + but we don't want to flood the logs from 'ps' which does a readlink
49754 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49755 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49756 + */
49757 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49758 + if (!proc_fd_access_allowed(inode,0))
49759 + goto out;
49760 + } else {
49761 + if (!proc_fd_access_allowed(inode,1))
49762 + goto out;
49763 + }
49764
49765 error = PROC_I(inode)->op.proc_get_link(inode, &path);
49766 if (error)
49767 @@ -1766,7 +1820,11 @@ static struct inode *proc_pid_make_inode
49768 rcu_read_lock();
49769 cred = __task_cred(task);
49770 inode->i_uid = cred->euid;
49771 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49772 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49773 +#else
49774 inode->i_gid = cred->egid;
49775 +#endif
49776 rcu_read_unlock();
49777 }
49778 security_task_to_inode(task, inode);
49779 @@ -1784,6 +1842,9 @@ static int pid_getattr(struct vfsmount *
49780 struct inode *inode = dentry->d_inode;
49781 struct task_struct *task;
49782 const struct cred *cred;
49783 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49784 + const struct cred *tmpcred = current_cred();
49785 +#endif
49786
49787 generic_fillattr(inode, stat);
49788
49789 @@ -1791,13 +1852,41 @@ static int pid_getattr(struct vfsmount *
49790 stat->uid = 0;
49791 stat->gid = 0;
49792 task = pid_task(proc_pid(inode), PIDTYPE_PID);
49793 +
49794 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
49795 + rcu_read_unlock();
49796 + return -ENOENT;
49797 + }
49798 +
49799 if (task) {
49800 + cred = __task_cred(task);
49801 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49802 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49803 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49804 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49805 +#endif
49806 + ) {
49807 +#endif
49808 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49809 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49810 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49811 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49812 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49813 +#endif
49814 task_dumpable(task)) {
49815 - cred = __task_cred(task);
49816 stat->uid = cred->euid;
49817 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49818 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49819 +#else
49820 stat->gid = cred->egid;
49821 +#endif
49822 }
49823 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49824 + } else {
49825 + rcu_read_unlock();
49826 + return -ENOENT;
49827 + }
49828 +#endif
49829 }
49830 rcu_read_unlock();
49831 return 0;
49832 @@ -1834,11 +1923,20 @@ static int pid_revalidate(struct dentry
49833
49834 if (task) {
49835 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49836 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49837 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49838 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49839 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49840 +#endif
49841 task_dumpable(task)) {
49842 rcu_read_lock();
49843 cred = __task_cred(task);
49844 inode->i_uid = cred->euid;
49845 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49846 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49847 +#else
49848 inode->i_gid = cred->egid;
49849 +#endif
49850 rcu_read_unlock();
49851 } else {
49852 inode->i_uid = 0;
49853 @@ -1959,7 +2057,8 @@ static int proc_fd_info(struct inode *in
49854 int fd = proc_fd(inode);
49855
49856 if (task) {
49857 - files = get_files_struct(task);
49858 + if (!gr_acl_handle_procpidmem(task))
49859 + files = get_files_struct(task);
49860 put_task_struct(task);
49861 }
49862 if (files) {
49863 @@ -2219,15 +2318,25 @@ static const struct file_operations proc
49864 */
49865 static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
49866 {
49867 + struct task_struct *task;
49868 int rv;
49869
49870 if (flags & IPERM_FLAG_RCU)
49871 return -ECHILD;
49872 rv = generic_permission(inode, mask, flags, NULL);
49873 - if (rv == 0)
49874 - return 0;
49875 +
49876 if (task_pid(current) == proc_pid(inode))
49877 rv = 0;
49878 +
49879 + task = get_proc_task(inode);
49880 + if (task == NULL)
49881 + return rv;
49882 +
49883 + if (gr_acl_handle_procpidmem(task))
49884 + rv = -EACCES;
49885 +
49886 + put_task_struct(task);
49887 +
49888 return rv;
49889 }
49890
49891 @@ -2337,6 +2446,9 @@ static struct dentry *proc_pident_lookup
49892 if (!task)
49893 goto out_no_task;
49894
49895 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49896 + goto out;
49897 +
49898 /*
49899 * Yes, it does not scale. And it should not. Don't add
49900 * new entries into /proc/<tgid>/ without very good reasons.
49901 @@ -2381,6 +2493,9 @@ static int proc_pident_readdir(struct fi
49902 if (!task)
49903 goto out_no_task;
49904
49905 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49906 + goto out;
49907 +
49908 ret = 0;
49909 i = filp->f_pos;
49910 switch (i) {
49911 @@ -2651,7 +2766,7 @@ static void *proc_self_follow_link(struc
49912 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49913 void *cookie)
49914 {
49915 - char *s = nd_get_link(nd);
49916 + const char *s = nd_get_link(nd);
49917 if (!IS_ERR(s))
49918 __putname(s);
49919 }
49920 @@ -2835,7 +2950,7 @@ static const struct pid_entry tgid_base_
49921 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49922 #endif
49923 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49924 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49925 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49926 INF("syscall", S_IRUGO, proc_pid_syscall),
49927 #endif
49928 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49929 @@ -2860,10 +2975,10 @@ static const struct pid_entry tgid_base_
49930 #ifdef CONFIG_SECURITY
49931 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49932 #endif
49933 -#ifdef CONFIG_KALLSYMS
49934 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49935 INF("wchan", S_IRUGO, proc_pid_wchan),
49936 #endif
49937 -#ifdef CONFIG_STACKTRACE
49938 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49939 ONE("stack", S_IRUGO, proc_pid_stack),
49940 #endif
49941 #ifdef CONFIG_SCHEDSTATS
49942 @@ -2894,6 +3009,9 @@ static const struct pid_entry tgid_base_
49943 #ifdef CONFIG_TASK_IO_ACCOUNTING
49944 INF("io", S_IRUGO, proc_tgid_io_accounting),
49945 #endif
49946 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49947 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49948 +#endif
49949 };
49950
49951 static int proc_tgid_base_readdir(struct file * filp,
49952 @@ -3019,7 +3137,14 @@ static struct dentry *proc_pid_instantia
49953 if (!inode)
49954 goto out;
49955
49956 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49957 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49958 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49959 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49960 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49961 +#else
49962 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49963 +#endif
49964 inode->i_op = &proc_tgid_base_inode_operations;
49965 inode->i_fop = &proc_tgid_base_operations;
49966 inode->i_flags|=S_IMMUTABLE;
49967 @@ -3061,7 +3186,11 @@ struct dentry *proc_pid_lookup(struct in
49968 if (!task)
49969 goto out;
49970
49971 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49972 + goto out_put_task;
49973 +
49974 result = proc_pid_instantiate(dir, dentry, task, NULL);
49975 +out_put_task:
49976 put_task_struct(task);
49977 out:
49978 return result;
49979 @@ -3126,6 +3255,11 @@ int proc_pid_readdir(struct file * filp,
49980 {
49981 unsigned int nr;
49982 struct task_struct *reaper;
49983 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49984 + const struct cred *tmpcred = current_cred();
49985 + const struct cred *itercred;
49986 +#endif
49987 + filldir_t __filldir = filldir;
49988 struct tgid_iter iter;
49989 struct pid_namespace *ns;
49990
49991 @@ -3149,8 +3283,27 @@ int proc_pid_readdir(struct file * filp,
49992 for (iter = next_tgid(ns, iter);
49993 iter.task;
49994 iter.tgid += 1, iter = next_tgid(ns, iter)) {
49995 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49996 + rcu_read_lock();
49997 + itercred = __task_cred(iter.task);
49998 +#endif
49999 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
50000 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50001 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
50002 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50003 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
50004 +#endif
50005 + )
50006 +#endif
50007 + )
50008 + __filldir = &gr_fake_filldir;
50009 + else
50010 + __filldir = filldir;
50011 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50012 + rcu_read_unlock();
50013 +#endif
50014 filp->f_pos = iter.tgid + TGID_OFFSET;
50015 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
50016 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
50017 put_task_struct(iter.task);
50018 goto out;
50019 }
50020 @@ -3177,7 +3330,7 @@ static const struct pid_entry tid_base_s
50021 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50022 #endif
50023 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50024 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50025 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50026 INF("syscall", S_IRUGO, proc_pid_syscall),
50027 #endif
50028 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50029 @@ -3201,10 +3354,10 @@ static const struct pid_entry tid_base_s
50030 #ifdef CONFIG_SECURITY
50031 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50032 #endif
50033 -#ifdef CONFIG_KALLSYMS
50034 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50035 INF("wchan", S_IRUGO, proc_pid_wchan),
50036 #endif
50037 -#ifdef CONFIG_STACKTRACE
50038 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50039 ONE("stack", S_IRUGO, proc_pid_stack),
50040 #endif
50041 #ifdef CONFIG_SCHEDSTATS
50042 diff -urNp linux-2.6.39.2/fs/proc/cmdline.c linux-2.6.39.2/fs/proc/cmdline.c
50043 --- linux-2.6.39.2/fs/proc/cmdline.c 2011-05-19 00:06:34.000000000 -0400
50044 +++ linux-2.6.39.2/fs/proc/cmdline.c 2011-05-22 19:41:37.000000000 -0400
50045 @@ -23,7 +23,11 @@ static const struct file_operations cmdl
50046
50047 static int __init proc_cmdline_init(void)
50048 {
50049 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50050 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50051 +#else
50052 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50053 +#endif
50054 return 0;
50055 }
50056 module_init(proc_cmdline_init);
50057 diff -urNp linux-2.6.39.2/fs/proc/devices.c linux-2.6.39.2/fs/proc/devices.c
50058 --- linux-2.6.39.2/fs/proc/devices.c 2011-05-19 00:06:34.000000000 -0400
50059 +++ linux-2.6.39.2/fs/proc/devices.c 2011-05-22 19:41:37.000000000 -0400
50060 @@ -64,7 +64,11 @@ static const struct file_operations proc
50061
50062 static int __init proc_devices_init(void)
50063 {
50064 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50065 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50066 +#else
50067 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50068 +#endif
50069 return 0;
50070 }
50071 module_init(proc_devices_init);
50072 diff -urNp linux-2.6.39.2/fs/proc/inode.c linux-2.6.39.2/fs/proc/inode.c
50073 --- linux-2.6.39.2/fs/proc/inode.c 2011-05-19 00:06:34.000000000 -0400
50074 +++ linux-2.6.39.2/fs/proc/inode.c 2011-05-22 19:41:37.000000000 -0400
50075 @@ -433,7 +433,11 @@ struct inode *proc_get_inode(struct supe
50076 if (de->mode) {
50077 inode->i_mode = de->mode;
50078 inode->i_uid = de->uid;
50079 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50080 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
50081 +#else
50082 inode->i_gid = de->gid;
50083 +#endif
50084 }
50085 if (de->size)
50086 inode->i_size = de->size;
50087 diff -urNp linux-2.6.39.2/fs/proc/internal.h linux-2.6.39.2/fs/proc/internal.h
50088 --- linux-2.6.39.2/fs/proc/internal.h 2011-05-19 00:06:34.000000000 -0400
50089 +++ linux-2.6.39.2/fs/proc/internal.h 2011-05-22 19:41:37.000000000 -0400
50090 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
50091 struct pid *pid, struct task_struct *task);
50092 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50093 struct pid *pid, struct task_struct *task);
50094 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50095 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50096 +#endif
50097 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50098
50099 extern const struct file_operations proc_maps_operations;
50100 diff -urNp linux-2.6.39.2/fs/proc/Kconfig linux-2.6.39.2/fs/proc/Kconfig
50101 --- linux-2.6.39.2/fs/proc/Kconfig 2011-05-19 00:06:34.000000000 -0400
50102 +++ linux-2.6.39.2/fs/proc/Kconfig 2011-05-22 19:41:37.000000000 -0400
50103 @@ -30,12 +30,12 @@ config PROC_FS
50104
50105 config PROC_KCORE
50106 bool "/proc/kcore support" if !ARM
50107 - depends on PROC_FS && MMU
50108 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50109
50110 config PROC_VMCORE
50111 bool "/proc/vmcore support"
50112 - depends on PROC_FS && CRASH_DUMP
50113 - default y
50114 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50115 + default n
50116 help
50117 Exports the dump image of crashed kernel in ELF format.
50118
50119 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50120 limited in memory.
50121
50122 config PROC_PAGE_MONITOR
50123 - default y
50124 - depends on PROC_FS && MMU
50125 + default n
50126 + depends on PROC_FS && MMU && !GRKERNSEC
50127 bool "Enable /proc page monitoring" if EXPERT
50128 help
50129 Various /proc files exist to monitor process memory utilization:
50130 diff -urNp linux-2.6.39.2/fs/proc/kcore.c linux-2.6.39.2/fs/proc/kcore.c
50131 --- linux-2.6.39.2/fs/proc/kcore.c 2011-05-19 00:06:34.000000000 -0400
50132 +++ linux-2.6.39.2/fs/proc/kcore.c 2011-05-22 19:41:37.000000000 -0400
50133 @@ -321,6 +321,8 @@ static void elf_kcore_store_hdr(char *bu
50134 off_t offset = 0;
50135 struct kcore_list *m;
50136
50137 + pax_track_stack();
50138 +
50139 /* setup ELF header */
50140 elf = (struct elfhdr *) bufp;
50141 bufp += sizeof(struct elfhdr);
50142 @@ -478,9 +480,10 @@ read_kcore(struct file *file, char __use
50143 * the addresses in the elf_phdr on our list.
50144 */
50145 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50146 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50147 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50148 + if (tsz > buflen)
50149 tsz = buflen;
50150 -
50151 +
50152 while (buflen) {
50153 struct kcore_list *m;
50154
50155 @@ -509,20 +512,23 @@ read_kcore(struct file *file, char __use
50156 kfree(elf_buf);
50157 } else {
50158 if (kern_addr_valid(start)) {
50159 - unsigned long n;
50160 + char *elf_buf;
50161 + mm_segment_t oldfs;
50162
50163 - n = copy_to_user(buffer, (char *)start, tsz);
50164 - /*
50165 - * We cannot distingush between fault on source
50166 - * and fault on destination. When this happens
50167 - * we clear too and hope it will trigger the
50168 - * EFAULT again.
50169 - */
50170 - if (n) {
50171 - if (clear_user(buffer + tsz - n,
50172 - n))
50173 + elf_buf = kmalloc(tsz, GFP_KERNEL);
50174 + if (!elf_buf)
50175 + return -ENOMEM;
50176 + oldfs = get_fs();
50177 + set_fs(KERNEL_DS);
50178 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
50179 + set_fs(oldfs);
50180 + if (copy_to_user(buffer, elf_buf, tsz)) {
50181 + kfree(elf_buf);
50182 return -EFAULT;
50183 + }
50184 }
50185 + set_fs(oldfs);
50186 + kfree(elf_buf);
50187 } else {
50188 if (clear_user(buffer, tsz))
50189 return -EFAULT;
50190 @@ -542,6 +548,9 @@ read_kcore(struct file *file, char __use
50191
50192 static int open_kcore(struct inode *inode, struct file *filp)
50193 {
50194 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
50195 + return -EPERM;
50196 +#endif
50197 if (!capable(CAP_SYS_RAWIO))
50198 return -EPERM;
50199 if (kcore_need_update)
50200 diff -urNp linux-2.6.39.2/fs/proc/meminfo.c linux-2.6.39.2/fs/proc/meminfo.c
50201 --- linux-2.6.39.2/fs/proc/meminfo.c 2011-05-19 00:06:34.000000000 -0400
50202 +++ linux-2.6.39.2/fs/proc/meminfo.c 2011-05-22 19:36:32.000000000 -0400
50203 @@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_
50204 unsigned long pages[NR_LRU_LISTS];
50205 int lru;
50206
50207 + pax_track_stack();
50208 +
50209 /*
50210 * display in kilobytes.
50211 */
50212 @@ -157,7 +159,7 @@ static int meminfo_proc_show(struct seq_
50213 vmi.used >> 10,
50214 vmi.largest_chunk >> 10
50215 #ifdef CONFIG_MEMORY_FAILURE
50216 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
50217 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
50218 #endif
50219 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
50220 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
50221 diff -urNp linux-2.6.39.2/fs/proc/nommu.c linux-2.6.39.2/fs/proc/nommu.c
50222 --- linux-2.6.39.2/fs/proc/nommu.c 2011-05-19 00:06:34.000000000 -0400
50223 +++ linux-2.6.39.2/fs/proc/nommu.c 2011-05-22 19:36:32.000000000 -0400
50224 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_
50225 if (len < 1)
50226 len = 1;
50227 seq_printf(m, "%*c", len, ' ');
50228 - seq_path(m, &file->f_path, "");
50229 + seq_path(m, &file->f_path, "\n\\");
50230 }
50231
50232 seq_putc(m, '\n');
50233 diff -urNp linux-2.6.39.2/fs/proc/proc_net.c linux-2.6.39.2/fs/proc/proc_net.c
50234 --- linux-2.6.39.2/fs/proc/proc_net.c 2011-05-19 00:06:34.000000000 -0400
50235 +++ linux-2.6.39.2/fs/proc/proc_net.c 2011-05-22 19:41:37.000000000 -0400
50236 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(str
50237 struct task_struct *task;
50238 struct nsproxy *ns;
50239 struct net *net = NULL;
50240 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50241 + const struct cred *cred = current_cred();
50242 +#endif
50243 +
50244 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50245 + if (cred->fsuid)
50246 + return net;
50247 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50248 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
50249 + return net;
50250 +#endif
50251
50252 rcu_read_lock();
50253 task = pid_task(proc_pid(dir), PIDTYPE_PID);
50254 diff -urNp linux-2.6.39.2/fs/proc/proc_sysctl.c linux-2.6.39.2/fs/proc/proc_sysctl.c
50255 --- linux-2.6.39.2/fs/proc/proc_sysctl.c 2011-05-19 00:06:34.000000000 -0400
50256 +++ linux-2.6.39.2/fs/proc/proc_sysctl.c 2011-05-22 19:41:37.000000000 -0400
50257 @@ -8,6 +8,8 @@
50258 #include <linux/namei.h>
50259 #include "internal.h"
50260
50261 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
50262 +
50263 static const struct dentry_operations proc_sys_dentry_operations;
50264 static const struct file_operations proc_sys_file_operations;
50265 static const struct inode_operations proc_sys_inode_operations;
50266 @@ -111,6 +113,9 @@ static struct dentry *proc_sys_lookup(st
50267 if (!p)
50268 goto out;
50269
50270 + if (gr_handle_sysctl(p, MAY_EXEC))
50271 + goto out;
50272 +
50273 err = ERR_PTR(-ENOMEM);
50274 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
50275 if (h)
50276 @@ -230,6 +235,9 @@ static int scan(struct ctl_table_header
50277 if (*pos < file->f_pos)
50278 continue;
50279
50280 + if (gr_handle_sysctl(table, 0))
50281 + continue;
50282 +
50283 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
50284 if (res)
50285 return res;
50286 @@ -358,6 +366,9 @@ static int proc_sys_getattr(struct vfsmo
50287 if (IS_ERR(head))
50288 return PTR_ERR(head);
50289
50290 + if (table && gr_handle_sysctl(table, MAY_EXEC))
50291 + return -ENOENT;
50292 +
50293 generic_fillattr(inode, stat);
50294 if (table)
50295 stat->mode = (stat->mode & S_IFMT) | table->mode;
50296 diff -urNp linux-2.6.39.2/fs/proc/root.c linux-2.6.39.2/fs/proc/root.c
50297 --- linux-2.6.39.2/fs/proc/root.c 2011-05-19 00:06:34.000000000 -0400
50298 +++ linux-2.6.39.2/fs/proc/root.c 2011-05-22 19:41:37.000000000 -0400
50299 @@ -122,7 +122,15 @@ void __init proc_root_init(void)
50300 #ifdef CONFIG_PROC_DEVICETREE
50301 proc_device_tree_init();
50302 #endif
50303 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50304 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50305 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
50306 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50307 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50308 +#endif
50309 +#else
50310 proc_mkdir("bus", NULL);
50311 +#endif
50312 proc_sys_init();
50313 }
50314
50315 diff -urNp linux-2.6.39.2/fs/proc/task_mmu.c linux-2.6.39.2/fs/proc/task_mmu.c
50316 --- linux-2.6.39.2/fs/proc/task_mmu.c 2011-05-19 00:06:34.000000000 -0400
50317 +++ linux-2.6.39.2/fs/proc/task_mmu.c 2011-05-22 22:43:29.000000000 -0400
50318 @@ -51,8 +51,13 @@ void task_mem(struct seq_file *m, struct
50319 "VmExe:\t%8lu kB\n"
50320 "VmLib:\t%8lu kB\n"
50321 "VmPTE:\t%8lu kB\n"
50322 - "VmSwap:\t%8lu kB\n",
50323 - hiwater_vm << (PAGE_SHIFT-10),
50324 + "VmSwap:\t%8lu kB\n"
50325 +
50326 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50327 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
50328 +#endif
50329 +
50330 + ,hiwater_vm << (PAGE_SHIFT-10),
50331 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
50332 mm->locked_vm << (PAGE_SHIFT-10),
50333 hiwater_rss << (PAGE_SHIFT-10),
50334 @@ -60,7 +65,13 @@ void task_mem(struct seq_file *m, struct
50335 data << (PAGE_SHIFT-10),
50336 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
50337 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
50338 - swap << (PAGE_SHIFT-10));
50339 + swap << (PAGE_SHIFT-10)
50340 +
50341 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
50342 + , mm->context.user_cs_base, mm->context.user_cs_limit
50343 +#endif
50344 +
50345 + );
50346 }
50347
50348 unsigned long task_vsize(struct mm_struct *mm)
50349 @@ -207,6 +218,12 @@ static int do_maps_open(struct inode *in
50350 return ret;
50351 }
50352
50353 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50354 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50355 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50356 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50357 +#endif
50358 +
50359 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
50360 {
50361 struct mm_struct *mm = vma->vm_mm;
50362 @@ -225,13 +242,13 @@ static void show_map_vma(struct seq_file
50363 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
50364 }
50365
50366 - /* We don't show the stack guard page in /proc/maps */
50367 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50368 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
50369 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
50370 +#else
50371 start = vma->vm_start;
50372 - if (stack_guard_page_start(vma, start))
50373 - start += PAGE_SIZE;
50374 end = vma->vm_end;
50375 - if (stack_guard_page_end(vma, end))
50376 - end -= PAGE_SIZE;
50377 +#endif
50378
50379 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
50380 start,
50381 @@ -240,7 +257,11 @@ static void show_map_vma(struct seq_file
50382 flags & VM_WRITE ? 'w' : '-',
50383 flags & VM_EXEC ? 'x' : '-',
50384 flags & VM_MAYSHARE ? 's' : 'p',
50385 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50386 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
50387 +#else
50388 pgoff,
50389 +#endif
50390 MAJOR(dev), MINOR(dev), ino, &len);
50391
50392 /*
50393 @@ -249,7 +270,7 @@ static void show_map_vma(struct seq_file
50394 */
50395 if (file) {
50396 pad_len_spaces(m, len);
50397 - seq_path(m, &file->f_path, "\n");
50398 + seq_path(m, &file->f_path, "\n\\");
50399 } else {
50400 const char *name = arch_vma_name(vma);
50401 if (!name) {
50402 @@ -257,8 +278,9 @@ static void show_map_vma(struct seq_file
50403 if (vma->vm_start <= mm->brk &&
50404 vma->vm_end >= mm->start_brk) {
50405 name = "[heap]";
50406 - } else if (vma->vm_start <= mm->start_stack &&
50407 - vma->vm_end >= mm->start_stack) {
50408 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
50409 + (vma->vm_start <= mm->start_stack &&
50410 + vma->vm_end >= mm->start_stack)) {
50411 name = "[stack]";
50412 }
50413 } else {
50414 @@ -433,11 +455,16 @@ static int show_smap(struct seq_file *m,
50415 };
50416
50417 memset(&mss, 0, sizeof mss);
50418 - mss.vma = vma;
50419 - /* mmap_sem is held in m_start */
50420 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50421 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50422 -
50423 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50424 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50425 +#endif
50426 + mss.vma = vma;
50427 + /* mmap_sem is held in m_start */
50428 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50429 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50430 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50431 + }
50432 +#endif
50433 show_map_vma(m, vma);
50434
50435 seq_printf(m,
50436 @@ -455,7 +482,11 @@ static int show_smap(struct seq_file *m,
50437 "KernelPageSize: %8lu kB\n"
50438 "MMUPageSize: %8lu kB\n"
50439 "Locked: %8lu kB\n",
50440 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50441 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50442 +#else
50443 (vma->vm_end - vma->vm_start) >> 10,
50444 +#endif
50445 mss.resident >> 10,
50446 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50447 mss.shared_clean >> 10,
50448 diff -urNp linux-2.6.39.2/fs/proc/task_nommu.c linux-2.6.39.2/fs/proc/task_nommu.c
50449 --- linux-2.6.39.2/fs/proc/task_nommu.c 2011-05-19 00:06:34.000000000 -0400
50450 +++ linux-2.6.39.2/fs/proc/task_nommu.c 2011-05-22 19:36:32.000000000 -0400
50451 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct
50452 else
50453 bytes += kobjsize(mm);
50454
50455 - if (current->fs && current->fs->users > 1)
50456 + if (current->fs && atomic_read(&current->fs->users) > 1)
50457 sbytes += kobjsize(current->fs);
50458 else
50459 bytes += kobjsize(current->fs);
50460 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_fil
50461
50462 if (file) {
50463 pad_len_spaces(m, len);
50464 - seq_path(m, &file->f_path, "");
50465 + seq_path(m, &file->f_path, "\n\\");
50466 } else if (mm) {
50467 if (vma->vm_start <= mm->start_stack &&
50468 vma->vm_end >= mm->start_stack) {
50469 diff -urNp linux-2.6.39.2/fs/quota/netlink.c linux-2.6.39.2/fs/quota/netlink.c
50470 --- linux-2.6.39.2/fs/quota/netlink.c 2011-05-19 00:06:34.000000000 -0400
50471 +++ linux-2.6.39.2/fs/quota/netlink.c 2011-05-22 19:36:32.000000000 -0400
50472 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_fam
50473 void quota_send_warning(short type, unsigned int id, dev_t dev,
50474 const char warntype)
50475 {
50476 - static atomic_t seq;
50477 + static atomic_unchecked_t seq;
50478 struct sk_buff *skb;
50479 void *msg_head;
50480 int ret;
50481 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsi
50482 "VFS: Not enough memory to send quota warning.\n");
50483 return;
50484 }
50485 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50486 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50487 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50488 if (!msg_head) {
50489 printk(KERN_ERR
50490 diff -urNp linux-2.6.39.2/fs/readdir.c linux-2.6.39.2/fs/readdir.c
50491 --- linux-2.6.39.2/fs/readdir.c 2011-05-19 00:06:34.000000000 -0400
50492 +++ linux-2.6.39.2/fs/readdir.c 2011-05-22 19:41:42.000000000 -0400
50493 @@ -17,6 +17,7 @@
50494 #include <linux/security.h>
50495 #include <linux/syscalls.h>
50496 #include <linux/unistd.h>
50497 +#include <linux/namei.h>
50498
50499 #include <asm/uaccess.h>
50500
50501 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50502
50503 struct readdir_callback {
50504 struct old_linux_dirent __user * dirent;
50505 + struct file * file;
50506 int result;
50507 };
50508
50509 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, cons
50510 buf->result = -EOVERFLOW;
50511 return -EOVERFLOW;
50512 }
50513 +
50514 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50515 + return 0;
50516 +
50517 buf->result++;
50518 dirent = buf->dirent;
50519 if (!access_ok(VERIFY_WRITE, dirent,
50520 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned in
50521
50522 buf.result = 0;
50523 buf.dirent = dirent;
50524 + buf.file = file;
50525
50526 error = vfs_readdir(file, fillonedir, &buf);
50527 if (buf.result)
50528 @@ -142,6 +149,7 @@ struct linux_dirent {
50529 struct getdents_callback {
50530 struct linux_dirent __user * current_dir;
50531 struct linux_dirent __user * previous;
50532 + struct file * file;
50533 int count;
50534 int error;
50535 };
50536 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const c
50537 buf->error = -EOVERFLOW;
50538 return -EOVERFLOW;
50539 }
50540 +
50541 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50542 + return 0;
50543 +
50544 dirent = buf->previous;
50545 if (dirent) {
50546 if (__put_user(offset, &dirent->d_off))
50547 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int,
50548 buf.previous = NULL;
50549 buf.count = count;
50550 buf.error = 0;
50551 + buf.file = file;
50552
50553 error = vfs_readdir(file, filldir, &buf);
50554 if (error >= 0)
50555 @@ -229,6 +242,7 @@ out:
50556 struct getdents_callback64 {
50557 struct linux_dirent64 __user * current_dir;
50558 struct linux_dirent64 __user * previous;
50559 + struct file *file;
50560 int count;
50561 int error;
50562 };
50563 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const
50564 buf->error = -EINVAL; /* only used if we fail.. */
50565 if (reclen > buf->count)
50566 return -EINVAL;
50567 +
50568 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50569 + return 0;
50570 +
50571 dirent = buf->previous;
50572 if (dirent) {
50573 if (__put_user(offset, &dirent->d_off))
50574 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int
50575
50576 buf.current_dir = dirent;
50577 buf.previous = NULL;
50578 + buf.file = file;
50579 buf.count = count;
50580 buf.error = 0;
50581
50582 diff -urNp linux-2.6.39.2/fs/reiserfs/dir.c linux-2.6.39.2/fs/reiserfs/dir.c
50583 --- linux-2.6.39.2/fs/reiserfs/dir.c 2011-05-19 00:06:34.000000000 -0400
50584 +++ linux-2.6.39.2/fs/reiserfs/dir.c 2011-05-22 19:36:32.000000000 -0400
50585 @@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentr
50586 struct reiserfs_dir_entry de;
50587 int ret = 0;
50588
50589 + pax_track_stack();
50590 +
50591 reiserfs_write_lock(inode->i_sb);
50592
50593 reiserfs_check_lock_depth(inode->i_sb, "readdir");
50594 diff -urNp linux-2.6.39.2/fs/reiserfs/do_balan.c linux-2.6.39.2/fs/reiserfs/do_balan.c
50595 --- linux-2.6.39.2/fs/reiserfs/do_balan.c 2011-05-19 00:06:34.000000000 -0400
50596 +++ linux-2.6.39.2/fs/reiserfs/do_balan.c 2011-05-22 19:36:32.000000000 -0400
50597 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb,
50598 return;
50599 }
50600
50601 - atomic_inc(&(fs_generation(tb->tb_sb)));
50602 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50603 do_balance_starts(tb);
50604
50605 /* balance leaf returns 0 except if combining L R and S into
50606 diff -urNp linux-2.6.39.2/fs/reiserfs/item_ops.c linux-2.6.39.2/fs/reiserfs/item_ops.c
50607 --- linux-2.6.39.2/fs/reiserfs/item_ops.c 2011-05-19 00:06:34.000000000 -0400
50608 +++ linux-2.6.39.2/fs/reiserfs/item_ops.c 2011-05-22 19:36:32.000000000 -0400
50609 @@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_i
50610 vi->vi_index, vi->vi_type, vi->vi_ih);
50611 }
50612
50613 -static struct item_operations stat_data_ops = {
50614 +static const struct item_operations stat_data_ops = {
50615 .bytes_number = sd_bytes_number,
50616 .decrement_key = sd_decrement_key,
50617 .is_left_mergeable = sd_is_left_mergeable,
50618 @@ -196,7 +196,7 @@ static void direct_print_vi(struct virtu
50619 vi->vi_index, vi->vi_type, vi->vi_ih);
50620 }
50621
50622 -static struct item_operations direct_ops = {
50623 +static const struct item_operations direct_ops = {
50624 .bytes_number = direct_bytes_number,
50625 .decrement_key = direct_decrement_key,
50626 .is_left_mergeable = direct_is_left_mergeable,
50627 @@ -341,7 +341,7 @@ static void indirect_print_vi(struct vir
50628 vi->vi_index, vi->vi_type, vi->vi_ih);
50629 }
50630
50631 -static struct item_operations indirect_ops = {
50632 +static const struct item_operations indirect_ops = {
50633 .bytes_number = indirect_bytes_number,
50634 .decrement_key = indirect_decrement_key,
50635 .is_left_mergeable = indirect_is_left_mergeable,
50636 @@ -628,7 +628,7 @@ static void direntry_print_vi(struct vir
50637 printk("\n");
50638 }
50639
50640 -static struct item_operations direntry_ops = {
50641 +static const struct item_operations direntry_ops = {
50642 .bytes_number = direntry_bytes_number,
50643 .decrement_key = direntry_decrement_key,
50644 .is_left_mergeable = direntry_is_left_mergeable,
50645 @@ -724,7 +724,7 @@ static void errcatch_print_vi(struct vir
50646 "Invalid item type observed, run fsck ASAP");
50647 }
50648
50649 -static struct item_operations errcatch_ops = {
50650 +static const struct item_operations errcatch_ops = {
50651 errcatch_bytes_number,
50652 errcatch_decrement_key,
50653 errcatch_is_left_mergeable,
50654 @@ -746,7 +746,7 @@ static struct item_operations errcatch_o
50655 #error Item types must use disk-format assigned values.
50656 #endif
50657
50658 -struct item_operations *item_ops[TYPE_ANY + 1] = {
50659 +const struct item_operations * const item_ops[TYPE_ANY + 1] = {
50660 &stat_data_ops,
50661 &indirect_ops,
50662 &direct_ops,
50663 diff -urNp linux-2.6.39.2/fs/reiserfs/journal.c linux-2.6.39.2/fs/reiserfs/journal.c
50664 --- linux-2.6.39.2/fs/reiserfs/journal.c 2011-05-19 00:06:34.000000000 -0400
50665 +++ linux-2.6.39.2/fs/reiserfs/journal.c 2011-05-22 19:36:32.000000000 -0400
50666 @@ -2299,6 +2299,8 @@ static struct buffer_head *reiserfs_brea
50667 struct buffer_head *bh;
50668 int i, j;
50669
50670 + pax_track_stack();
50671 +
50672 bh = __getblk(dev, block, bufsize);
50673 if (buffer_uptodate(bh))
50674 return (bh);
50675 diff -urNp linux-2.6.39.2/fs/reiserfs/namei.c linux-2.6.39.2/fs/reiserfs/namei.c
50676 --- linux-2.6.39.2/fs/reiserfs/namei.c 2011-05-19 00:06:34.000000000 -0400
50677 +++ linux-2.6.39.2/fs/reiserfs/namei.c 2011-05-22 19:36:32.000000000 -0400
50678 @@ -1225,6 +1225,8 @@ static int reiserfs_rename(struct inode
50679 unsigned long savelink = 1;
50680 struct timespec ctime;
50681
50682 + pax_track_stack();
50683 +
50684 /* three balancings: (1) old name removal, (2) new name insertion
50685 and (3) maybe "save" link insertion
50686 stat data updates: (1) old directory,
50687 diff -urNp linux-2.6.39.2/fs/reiserfs/procfs.c linux-2.6.39.2/fs/reiserfs/procfs.c
50688 --- linux-2.6.39.2/fs/reiserfs/procfs.c 2011-05-19 00:06:34.000000000 -0400
50689 +++ linux-2.6.39.2/fs/reiserfs/procfs.c 2011-05-22 19:36:32.000000000 -0400
50690 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m
50691 "SMALL_TAILS " : "NO_TAILS ",
50692 replay_only(sb) ? "REPLAY_ONLY " : "",
50693 convert_reiserfs(sb) ? "CONV " : "",
50694 - atomic_read(&r->s_generation_counter),
50695 + atomic_read_unchecked(&r->s_generation_counter),
50696 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50697 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50698 SF(s_good_search_by_key_reada), SF(s_bmaps),
50699 @@ -299,6 +299,8 @@ static int show_journal(struct seq_file
50700 struct journal_params *jp = &rs->s_v1.s_journal;
50701 char b[BDEVNAME_SIZE];
50702
50703 + pax_track_stack();
50704 +
50705 seq_printf(m, /* on-disk fields */
50706 "jp_journal_1st_block: \t%i\n"
50707 "jp_journal_dev: \t%s[%x]\n"
50708 diff -urNp linux-2.6.39.2/fs/reiserfs/stree.c linux-2.6.39.2/fs/reiserfs/stree.c
50709 --- linux-2.6.39.2/fs/reiserfs/stree.c 2011-05-19 00:06:34.000000000 -0400
50710 +++ linux-2.6.39.2/fs/reiserfs/stree.c 2011-05-22 19:36:32.000000000 -0400
50711 @@ -1196,6 +1196,8 @@ int reiserfs_delete_item(struct reiserfs
50712 int iter = 0;
50713 #endif
50714
50715 + pax_track_stack();
50716 +
50717 BUG_ON(!th->t_trans_id);
50718
50719 init_tb_struct(th, &s_del_balance, sb, path,
50720 @@ -1333,6 +1335,8 @@ void reiserfs_delete_solid_item(struct r
50721 int retval;
50722 int quota_cut_bytes = 0;
50723
50724 + pax_track_stack();
50725 +
50726 BUG_ON(!th->t_trans_id);
50727
50728 le_key2cpu_key(&cpu_key, key);
50729 @@ -1562,6 +1566,8 @@ int reiserfs_cut_from_item(struct reiser
50730 int quota_cut_bytes;
50731 loff_t tail_pos = 0;
50732
50733 + pax_track_stack();
50734 +
50735 BUG_ON(!th->t_trans_id);
50736
50737 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
50738 @@ -1957,6 +1963,8 @@ int reiserfs_paste_into_item(struct reis
50739 int retval;
50740 int fs_gen;
50741
50742 + pax_track_stack();
50743 +
50744 BUG_ON(!th->t_trans_id);
50745
50746 fs_gen = get_generation(inode->i_sb);
50747 @@ -2045,6 +2053,8 @@ int reiserfs_insert_item(struct reiserfs
50748 int fs_gen = 0;
50749 int quota_bytes = 0;
50750
50751 + pax_track_stack();
50752 +
50753 BUG_ON(!th->t_trans_id);
50754
50755 if (inode) { /* Do we count quotas for item? */
50756 diff -urNp linux-2.6.39.2/fs/reiserfs/super.c linux-2.6.39.2/fs/reiserfs/super.c
50757 --- linux-2.6.39.2/fs/reiserfs/super.c 2011-05-19 00:06:34.000000000 -0400
50758 +++ linux-2.6.39.2/fs/reiserfs/super.c 2011-05-22 19:36:32.000000000 -0400
50759 @@ -927,6 +927,8 @@ static int reiserfs_parse_options(struct
50760 {.option_name = NULL}
50761 };
50762
50763 + pax_track_stack();
50764 +
50765 *blocks = 0;
50766 if (!options || !*options)
50767 /* use default configuration: create tails, journaling on, no
50768 diff -urNp linux-2.6.39.2/fs/select.c linux-2.6.39.2/fs/select.c
50769 --- linux-2.6.39.2/fs/select.c 2011-05-19 00:06:34.000000000 -0400
50770 +++ linux-2.6.39.2/fs/select.c 2011-05-22 19:41:42.000000000 -0400
50771 @@ -20,6 +20,7 @@
50772 #include <linux/module.h>
50773 #include <linux/slab.h>
50774 #include <linux/poll.h>
50775 +#include <linux/security.h>
50776 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50777 #include <linux/file.h>
50778 #include <linux/fdtable.h>
50779 @@ -403,6 +404,8 @@ int do_select(int n, fd_set_bits *fds, s
50780 int retval, i, timed_out = 0;
50781 unsigned long slack = 0;
50782
50783 + pax_track_stack();
50784 +
50785 rcu_read_lock();
50786 retval = max_select_fd(n, fds);
50787 rcu_read_unlock();
50788 @@ -528,6 +531,8 @@ int core_sys_select(int n, fd_set __user
50789 /* Allocate small arguments on the stack to save memory and be faster */
50790 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
50791
50792 + pax_track_stack();
50793 +
50794 ret = -EINVAL;
50795 if (n < 0)
50796 goto out_nofds;
50797 @@ -837,6 +842,9 @@ int do_sys_poll(struct pollfd __user *uf
50798 struct poll_list *walk = head;
50799 unsigned long todo = nfds;
50800
50801 + pax_track_stack();
50802 +
50803 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50804 if (nfds > rlimit(RLIMIT_NOFILE))
50805 return -EINVAL;
50806
50807 diff -urNp linux-2.6.39.2/fs/seq_file.c linux-2.6.39.2/fs/seq_file.c
50808 --- linux-2.6.39.2/fs/seq_file.c 2011-05-19 00:06:34.000000000 -0400
50809 +++ linux-2.6.39.2/fs/seq_file.c 2011-05-22 19:36:32.000000000 -0400
50810 @@ -76,7 +76,8 @@ static int traverse(struct seq_file *m,
50811 return 0;
50812 }
50813 if (!m->buf) {
50814 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50815 + m->size = PAGE_SIZE;
50816 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50817 if (!m->buf)
50818 return -ENOMEM;
50819 }
50820 @@ -116,7 +117,8 @@ static int traverse(struct seq_file *m,
50821 Eoverflow:
50822 m->op->stop(m, p);
50823 kfree(m->buf);
50824 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50825 + m->size <<= 1;
50826 + m->buf = kmalloc(m->size, GFP_KERNEL);
50827 return !m->buf ? -ENOMEM : -EAGAIN;
50828 }
50829
50830 @@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char
50831 m->version = file->f_version;
50832 /* grab buffer if we didn't have one */
50833 if (!m->buf) {
50834 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50835 + m->size = PAGE_SIZE;
50836 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
50837 if (!m->buf)
50838 goto Enomem;
50839 }
50840 @@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char
50841 goto Fill;
50842 m->op->stop(m, p);
50843 kfree(m->buf);
50844 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50845 + m->size <<= 1;
50846 + m->buf = kmalloc(m->size, GFP_KERNEL);
50847 if (!m->buf)
50848 goto Enomem;
50849 m->count = 0;
50850 diff -urNp linux-2.6.39.2/fs/splice.c linux-2.6.39.2/fs/splice.c
50851 --- linux-2.6.39.2/fs/splice.c 2011-05-19 00:06:34.000000000 -0400
50852 +++ linux-2.6.39.2/fs/splice.c 2011-05-22 19:36:32.000000000 -0400
50853 @@ -186,7 +186,7 @@ ssize_t splice_to_pipe(struct pipe_inode
50854 pipe_lock(pipe);
50855
50856 for (;;) {
50857 - if (!pipe->readers) {
50858 + if (!atomic_read(&pipe->readers)) {
50859 send_sig(SIGPIPE, current, 0);
50860 if (!ret)
50861 ret = -EPIPE;
50862 @@ -240,9 +240,9 @@ ssize_t splice_to_pipe(struct pipe_inode
50863 do_wakeup = 0;
50864 }
50865
50866 - pipe->waiting_writers++;
50867 + atomic_inc(&pipe->waiting_writers);
50868 pipe_wait(pipe);
50869 - pipe->waiting_writers--;
50870 + atomic_dec(&pipe->waiting_writers);
50871 }
50872
50873 pipe_unlock(pipe);
50874 @@ -316,6 +316,8 @@ __generic_file_splice_read(struct file *
50875 .spd_release = spd_release_page,
50876 };
50877
50878 + pax_track_stack();
50879 +
50880 if (splice_grow_spd(pipe, &spd))
50881 return -ENOMEM;
50882
50883 @@ -556,7 +558,7 @@ static ssize_t kernel_readv(struct file
50884 old_fs = get_fs();
50885 set_fs(get_ds());
50886 /* The cast to a user pointer is valid due to the set_fs() */
50887 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50888 + res = vfs_readv(file, (__force const struct iovec __user *)vec, vlen, &pos);
50889 set_fs(old_fs);
50890
50891 return res;
50892 @@ -571,7 +573,7 @@ static ssize_t kernel_write(struct file
50893 old_fs = get_fs();
50894 set_fs(get_ds());
50895 /* The cast to a user pointer is valid due to the set_fs() */
50896 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50897 + res = vfs_write(file, (__force const char __user *)buf, count, &pos);
50898 set_fs(old_fs);
50899
50900 return res;
50901 @@ -599,6 +601,8 @@ ssize_t default_file_splice_read(struct
50902 .spd_release = spd_release_page,
50903 };
50904
50905 + pax_track_stack();
50906 +
50907 if (splice_grow_spd(pipe, &spd))
50908 return -ENOMEM;
50909
50910 @@ -622,7 +626,7 @@ ssize_t default_file_splice_read(struct
50911 goto err;
50912
50913 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50914 - vec[i].iov_base = (void __user *) page_address(page);
50915 + vec[i].iov_base = (__force void __user *) page_address(page);
50916 vec[i].iov_len = this_len;
50917 spd.pages[i] = page;
50918 spd.nr_pages++;
50919 @@ -842,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50920 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50921 {
50922 while (!pipe->nrbufs) {
50923 - if (!pipe->writers)
50924 + if (!atomic_read(&pipe->writers))
50925 return 0;
50926
50927 - if (!pipe->waiting_writers && sd->num_spliced)
50928 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50929 return 0;
50930
50931 if (sd->flags & SPLICE_F_NONBLOCK)
50932 @@ -1178,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct fi
50933 * out of the pipe right after the splice_to_pipe(). So set
50934 * PIPE_READERS appropriately.
50935 */
50936 - pipe->readers = 1;
50937 + atomic_set(&pipe->readers, 1);
50938
50939 current->splice_pipe = pipe;
50940 }
50941 @@ -1615,6 +1619,8 @@ static long vmsplice_to_pipe(struct file
50942 };
50943 long ret;
50944
50945 + pax_track_stack();
50946 +
50947 pipe = get_pipe_info(file);
50948 if (!pipe)
50949 return -EBADF;
50950 @@ -1730,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_
50951 ret = -ERESTARTSYS;
50952 break;
50953 }
50954 - if (!pipe->writers)
50955 + if (!atomic_read(&pipe->writers))
50956 break;
50957 - if (!pipe->waiting_writers) {
50958 + if (!atomic_read(&pipe->waiting_writers)) {
50959 if (flags & SPLICE_F_NONBLOCK) {
50960 ret = -EAGAIN;
50961 break;
50962 @@ -1764,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_
50963 pipe_lock(pipe);
50964
50965 while (pipe->nrbufs >= pipe->buffers) {
50966 - if (!pipe->readers) {
50967 + if (!atomic_read(&pipe->readers)) {
50968 send_sig(SIGPIPE, current, 0);
50969 ret = -EPIPE;
50970 break;
50971 @@ -1777,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_
50972 ret = -ERESTARTSYS;
50973 break;
50974 }
50975 - pipe->waiting_writers++;
50976 + atomic_inc(&pipe->waiting_writers);
50977 pipe_wait(pipe);
50978 - pipe->waiting_writers--;
50979 + atomic_dec(&pipe->waiting_writers);
50980 }
50981
50982 pipe_unlock(pipe);
50983 @@ -1815,14 +1821,14 @@ retry:
50984 pipe_double_lock(ipipe, opipe);
50985
50986 do {
50987 - if (!opipe->readers) {
50988 + if (!atomic_read(&opipe->readers)) {
50989 send_sig(SIGPIPE, current, 0);
50990 if (!ret)
50991 ret = -EPIPE;
50992 break;
50993 }
50994
50995 - if (!ipipe->nrbufs && !ipipe->writers)
50996 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50997 break;
50998
50999 /*
51000 @@ -1922,7 +1928,7 @@ static int link_pipe(struct pipe_inode_i
51001 pipe_double_lock(ipipe, opipe);
51002
51003 do {
51004 - if (!opipe->readers) {
51005 + if (!atomic_read(&opipe->readers)) {
51006 send_sig(SIGPIPE, current, 0);
51007 if (!ret)
51008 ret = -EPIPE;
51009 @@ -1967,7 +1973,7 @@ static int link_pipe(struct pipe_inode_i
51010 * return EAGAIN if we have the potential of some data in the
51011 * future, otherwise just return 0
51012 */
51013 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51014 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51015 ret = -EAGAIN;
51016
51017 pipe_unlock(ipipe);
51018 diff -urNp linux-2.6.39.2/fs/sysfs/file.c linux-2.6.39.2/fs/sysfs/file.c
51019 --- linux-2.6.39.2/fs/sysfs/file.c 2011-05-19 00:06:34.000000000 -0400
51020 +++ linux-2.6.39.2/fs/sysfs/file.c 2011-05-22 19:36:32.000000000 -0400
51021 @@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent
51022
51023 struct sysfs_open_dirent {
51024 atomic_t refcnt;
51025 - atomic_t event;
51026 + atomic_unchecked_t event;
51027 wait_queue_head_t poll;
51028 struct list_head buffers; /* goes through sysfs_buffer.list */
51029 };
51030 @@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentr
51031 if (!sysfs_get_active(attr_sd))
51032 return -ENODEV;
51033
51034 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
51035 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
51036 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
51037
51038 sysfs_put_active(attr_sd);
51039 @@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct
51040 return -ENOMEM;
51041
51042 atomic_set(&new_od->refcnt, 0);
51043 - atomic_set(&new_od->event, 1);
51044 + atomic_set_unchecked(&new_od->event, 1);
51045 init_waitqueue_head(&new_od->poll);
51046 INIT_LIST_HEAD(&new_od->buffers);
51047 goto retry;
51048 @@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct fi
51049
51050 sysfs_put_active(attr_sd);
51051
51052 - if (buffer->event != atomic_read(&od->event))
51053 + if (buffer->event != atomic_read_unchecked(&od->event))
51054 goto trigger;
51055
51056 return DEFAULT_POLLMASK;
51057 @@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_di
51058
51059 od = sd->s_attr.open;
51060 if (od) {
51061 - atomic_inc(&od->event);
51062 + atomic_inc_unchecked(&od->event);
51063 wake_up_interruptible(&od->poll);
51064 }
51065
51066 diff -urNp linux-2.6.39.2/fs/sysfs/mount.c linux-2.6.39.2/fs/sysfs/mount.c
51067 --- linux-2.6.39.2/fs/sysfs/mount.c 2011-05-19 00:06:34.000000000 -0400
51068 +++ linux-2.6.39.2/fs/sysfs/mount.c 2011-05-22 19:41:42.000000000 -0400
51069 @@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
51070 .s_name = "",
51071 .s_count = ATOMIC_INIT(1),
51072 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT),
51073 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51074 + .s_mode = S_IFDIR | S_IRWXU,
51075 +#else
51076 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
51077 +#endif
51078 .s_ino = 1,
51079 };
51080
51081 diff -urNp linux-2.6.39.2/fs/sysfs/symlink.c linux-2.6.39.2/fs/sysfs/symlink.c
51082 --- linux-2.6.39.2/fs/sysfs/symlink.c 2011-05-19 00:06:34.000000000 -0400
51083 +++ linux-2.6.39.2/fs/sysfs/symlink.c 2011-05-22 19:36:32.000000000 -0400
51084 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct de
51085
51086 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51087 {
51088 - char *page = nd_get_link(nd);
51089 + const char *page = nd_get_link(nd);
51090 if (!IS_ERR(page))
51091 free_page((unsigned long)page);
51092 }
51093 diff -urNp linux-2.6.39.2/fs/udf/inode.c linux-2.6.39.2/fs/udf/inode.c
51094 --- linux-2.6.39.2/fs/udf/inode.c 2011-05-19 00:06:34.000000000 -0400
51095 +++ linux-2.6.39.2/fs/udf/inode.c 2011-05-22 19:36:32.000000000 -0400
51096 @@ -560,6 +560,8 @@ static struct buffer_head *inode_getblk(
51097 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
51098 int lastblock = 0;
51099
51100 + pax_track_stack();
51101 +
51102 prev_epos.offset = udf_file_entry_alloc_offset(inode);
51103 prev_epos.block = iinfo->i_location;
51104 prev_epos.bh = NULL;
51105 diff -urNp linux-2.6.39.2/fs/udf/misc.c linux-2.6.39.2/fs/udf/misc.c
51106 --- linux-2.6.39.2/fs/udf/misc.c 2011-05-19 00:06:34.000000000 -0400
51107 +++ linux-2.6.39.2/fs/udf/misc.c 2011-05-22 19:36:32.000000000 -0400
51108 @@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t id
51109
51110 u8 udf_tag_checksum(const struct tag *t)
51111 {
51112 - u8 *data = (u8 *)t;
51113 + const u8 *data = (const u8 *)t;
51114 u8 checksum = 0;
51115 int i;
51116 for (i = 0; i < sizeof(struct tag); ++i)
51117 diff -urNp linux-2.6.39.2/fs/utimes.c linux-2.6.39.2/fs/utimes.c
51118 --- linux-2.6.39.2/fs/utimes.c 2011-05-19 00:06:34.000000000 -0400
51119 +++ linux-2.6.39.2/fs/utimes.c 2011-05-22 19:41:42.000000000 -0400
51120 @@ -1,6 +1,7 @@
51121 #include <linux/compiler.h>
51122 #include <linux/file.h>
51123 #include <linux/fs.h>
51124 +#include <linux/security.h>
51125 #include <linux/linkage.h>
51126 #include <linux/mount.h>
51127 #include <linux/namei.h>
51128 @@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
51129 goto mnt_drop_write_and_out;
51130 }
51131 }
51132 +
51133 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
51134 + error = -EACCES;
51135 + goto mnt_drop_write_and_out;
51136 + }
51137 +
51138 mutex_lock(&inode->i_mutex);
51139 error = notify_change(path->dentry, &newattrs);
51140 mutex_unlock(&inode->i_mutex);
51141 diff -urNp linux-2.6.39.2/fs/xattr_acl.c linux-2.6.39.2/fs/xattr_acl.c
51142 --- linux-2.6.39.2/fs/xattr_acl.c 2011-05-19 00:06:34.000000000 -0400
51143 +++ linux-2.6.39.2/fs/xattr_acl.c 2011-05-22 19:36:32.000000000 -0400
51144 @@ -17,8 +17,8 @@
51145 struct posix_acl *
51146 posix_acl_from_xattr(const void *value, size_t size)
51147 {
51148 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
51149 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
51150 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
51151 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
51152 int count;
51153 struct posix_acl *acl;
51154 struct posix_acl_entry *acl_e;
51155 diff -urNp linux-2.6.39.2/fs/xattr.c linux-2.6.39.2/fs/xattr.c
51156 --- linux-2.6.39.2/fs/xattr.c 2011-05-19 00:06:34.000000000 -0400
51157 +++ linux-2.6.39.2/fs/xattr.c 2011-05-22 19:41:42.000000000 -0400
51158 @@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
51159 * Extended attribute SET operations
51160 */
51161 static long
51162 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
51163 +setxattr(struct path *path, const char __user *name, const void __user *value,
51164 size_t size, int flags)
51165 {
51166 int error;
51167 @@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __
51168 return PTR_ERR(kvalue);
51169 }
51170
51171 - error = vfs_setxattr(d, kname, kvalue, size, flags);
51172 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
51173 + error = -EACCES;
51174 + goto out;
51175 + }
51176 +
51177 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
51178 +out:
51179 kfree(kvalue);
51180 return error;
51181 }
51182 @@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __u
51183 return error;
51184 error = mnt_want_write(path.mnt);
51185 if (!error) {
51186 - error = setxattr(path.dentry, name, value, size, flags);
51187 + error = setxattr(&path, name, value, size, flags);
51188 mnt_drop_write(path.mnt);
51189 }
51190 path_put(&path);
51191 @@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __
51192 return error;
51193 error = mnt_want_write(path.mnt);
51194 if (!error) {
51195 - error = setxattr(path.dentry, name, value, size, flags);
51196 + error = setxattr(&path, name, value, size, flags);
51197 mnt_drop_write(path.mnt);
51198 }
51199 path_put(&path);
51200 @@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, cons
51201 const void __user *,value, size_t, size, int, flags)
51202 {
51203 struct file *f;
51204 - struct dentry *dentry;
51205 int error = -EBADF;
51206
51207 f = fget(fd);
51208 if (!f)
51209 return error;
51210 - dentry = f->f_path.dentry;
51211 - audit_inode(NULL, dentry);
51212 + audit_inode(NULL, f->f_path.dentry);
51213 error = mnt_want_write_file(f);
51214 if (!error) {
51215 - error = setxattr(dentry, name, value, size, flags);
51216 + error = setxattr(&f->f_path, name, value, size, flags);
51217 mnt_drop_write(f->f_path.mnt);
51218 }
51219 fput(f);
51220 diff -urNp linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl32.c linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl32.c
51221 --- linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-19 00:06:34.000000000 -0400
51222 +++ linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl32.c 2011-05-22 19:41:42.000000000 -0400
51223 @@ -73,6 +73,7 @@ xfs_compat_ioc_fsgeometry_v1(
51224 xfs_fsop_geom_t fsgeo;
51225 int error;
51226
51227 + memset(&fsgeo, 0, sizeof(fsgeo));
51228 error = xfs_fs_geometry(mp, &fsgeo, 3);
51229 if (error)
51230 return -error;
51231 diff -urNp linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl.c
51232 --- linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-19 00:06:34.000000000 -0400
51233 +++ linux-2.6.39.2/fs/xfs/linux-2.6/xfs_ioctl.c 2011-05-22 19:36:32.000000000 -0400
51234 @@ -128,7 +128,7 @@ xfs_find_handle(
51235 }
51236
51237 error = -EFAULT;
51238 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
51239 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
51240 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
51241 goto out_put;
51242
51243 diff -urNp linux-2.6.39.2/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.39.2/fs/xfs/linux-2.6/xfs_iops.c
51244 --- linux-2.6.39.2/fs/xfs/linux-2.6/xfs_iops.c 2011-05-19 00:06:34.000000000 -0400
51245 +++ linux-2.6.39.2/fs/xfs/linux-2.6/xfs_iops.c 2011-05-22 19:36:32.000000000 -0400
51246 @@ -437,7 +437,7 @@ xfs_vn_put_link(
51247 struct nameidata *nd,
51248 void *p)
51249 {
51250 - char *s = nd_get_link(nd);
51251 + const char *s = nd_get_link(nd);
51252
51253 if (!IS_ERR(s))
51254 kfree(s);
51255 diff -urNp linux-2.6.39.2/fs/xfs/xfs_bmap.c linux-2.6.39.2/fs/xfs/xfs_bmap.c
51256 --- linux-2.6.39.2/fs/xfs/xfs_bmap.c 2011-05-19 00:06:34.000000000 -0400
51257 +++ linux-2.6.39.2/fs/xfs/xfs_bmap.c 2011-05-22 19:36:32.000000000 -0400
51258 @@ -287,7 +287,7 @@ xfs_bmap_validate_ret(
51259 int nmap,
51260 int ret_nmap);
51261 #else
51262 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
51263 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
51264 #endif /* DEBUG */
51265
51266 STATIC int
51267 diff -urNp linux-2.6.39.2/fs/xfs/xfs_dir2.c linux-2.6.39.2/fs/xfs/xfs_dir2.c
51268 --- linux-2.6.39.2/fs/xfs/xfs_dir2.c 2011-05-19 00:06:34.000000000 -0400
51269 +++ linux-2.6.39.2/fs/xfs/xfs_dir2.c 2011-05-22 19:36:32.000000000 -0400
51270 @@ -85,7 +85,7 @@ xfs_ascii_ci_compname(
51271 return result;
51272 }
51273
51274 -static struct xfs_nameops xfs_ascii_ci_nameops = {
51275 +static const struct xfs_nameops xfs_ascii_ci_nameops = {
51276 .hashname = xfs_ascii_ci_hashname,
51277 .compname = xfs_ascii_ci_compname,
51278 };
51279 diff -urNp linux-2.6.39.2/fs/xfs/xfs_dir2_sf.c linux-2.6.39.2/fs/xfs/xfs_dir2_sf.c
51280 --- linux-2.6.39.2/fs/xfs/xfs_dir2_sf.c 2011-05-19 00:06:34.000000000 -0400
51281 +++ linux-2.6.39.2/fs/xfs/xfs_dir2_sf.c 2011-05-22 19:36:32.000000000 -0400
51282 @@ -780,7 +780,15 @@ xfs_dir2_sf_getdents(
51283 }
51284
51285 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
51286 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51287 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
51288 + char name[sfep->namelen];
51289 + memcpy(name, sfep->name, sfep->namelen);
51290 + if (filldir(dirent, name, sfep->namelen,
51291 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
51292 + *offset = off & 0x7fffffff;
51293 + return 0;
51294 + }
51295 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
51296 off & 0x7fffffff, ino, DT_UNKNOWN)) {
51297 *offset = off & 0x7fffffff;
51298 return 0;
51299 diff -urNp linux-2.6.39.2/grsecurity/gracl_alloc.c linux-2.6.39.2/grsecurity/gracl_alloc.c
51300 --- linux-2.6.39.2/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
51301 +++ linux-2.6.39.2/grsecurity/gracl_alloc.c 2011-05-22 19:41:42.000000000 -0400
51302 @@ -0,0 +1,105 @@
51303 +#include <linux/kernel.h>
51304 +#include <linux/mm.h>
51305 +#include <linux/slab.h>
51306 +#include <linux/vmalloc.h>
51307 +#include <linux/gracl.h>
51308 +#include <linux/grsecurity.h>
51309 +
51310 +static unsigned long alloc_stack_next = 1;
51311 +static unsigned long alloc_stack_size = 1;
51312 +static void **alloc_stack;
51313 +
51314 +static __inline__ int
51315 +alloc_pop(void)
51316 +{
51317 + if (alloc_stack_next == 1)
51318 + return 0;
51319 +
51320 + kfree(alloc_stack[alloc_stack_next - 2]);
51321 +
51322 + alloc_stack_next--;
51323 +
51324 + return 1;
51325 +}
51326 +
51327 +static __inline__ int
51328 +alloc_push(void *buf)
51329 +{
51330 + if (alloc_stack_next >= alloc_stack_size)
51331 + return 1;
51332 +
51333 + alloc_stack[alloc_stack_next - 1] = buf;
51334 +
51335 + alloc_stack_next++;
51336 +
51337 + return 0;
51338 +}
51339 +
51340 +void *
51341 +acl_alloc(unsigned long len)
51342 +{
51343 + void *ret = NULL;
51344 +
51345 + if (!len || len > PAGE_SIZE)
51346 + goto out;
51347 +
51348 + ret = kmalloc(len, GFP_KERNEL);
51349 +
51350 + if (ret) {
51351 + if (alloc_push(ret)) {
51352 + kfree(ret);
51353 + ret = NULL;
51354 + }
51355 + }
51356 +
51357 +out:
51358 + return ret;
51359 +}
51360 +
51361 +void *
51362 +acl_alloc_num(unsigned long num, unsigned long len)
51363 +{
51364 + if (!len || (num > (PAGE_SIZE / len)))
51365 + return NULL;
51366 +
51367 + return acl_alloc(num * len);
51368 +}
51369 +
51370 +void
51371 +acl_free_all(void)
51372 +{
51373 + if (gr_acl_is_enabled() || !alloc_stack)
51374 + return;
51375 +
51376 + while (alloc_pop()) ;
51377 +
51378 + if (alloc_stack) {
51379 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
51380 + kfree(alloc_stack);
51381 + else
51382 + vfree(alloc_stack);
51383 + }
51384 +
51385 + alloc_stack = NULL;
51386 + alloc_stack_size = 1;
51387 + alloc_stack_next = 1;
51388 +
51389 + return;
51390 +}
51391 +
51392 +int
51393 +acl_alloc_stack_init(unsigned long size)
51394 +{
51395 + if ((size * sizeof (void *)) <= PAGE_SIZE)
51396 + alloc_stack =
51397 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
51398 + else
51399 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
51400 +
51401 + alloc_stack_size = size;
51402 +
51403 + if (!alloc_stack)
51404 + return 0;
51405 + else
51406 + return 1;
51407 +}
51408 diff -urNp linux-2.6.39.2/grsecurity/gracl.c linux-2.6.39.2/grsecurity/gracl.c
51409 --- linux-2.6.39.2/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
51410 +++ linux-2.6.39.2/grsecurity/gracl.c 2011-06-11 16:26:18.000000000 -0400
51411 @@ -0,0 +1,4109 @@
51412 +#include <linux/kernel.h>
51413 +#include <linux/module.h>
51414 +#include <linux/sched.h>
51415 +#include <linux/mm.h>
51416 +#include <linux/file.h>
51417 +#include <linux/fs.h>
51418 +#include <linux/namei.h>
51419 +#include <linux/mount.h>
51420 +#include <linux/tty.h>
51421 +#include <linux/proc_fs.h>
51422 +#include <linux/lglock.h>
51423 +#include <linux/slab.h>
51424 +#include <linux/vmalloc.h>
51425 +#include <linux/types.h>
51426 +#include <linux/sysctl.h>
51427 +#include <linux/netdevice.h>
51428 +#include <linux/ptrace.h>
51429 +#include <linux/gracl.h>
51430 +#include <linux/gralloc.h>
51431 +#include <linux/grsecurity.h>
51432 +#include <linux/grinternal.h>
51433 +#include <linux/pid_namespace.h>
51434 +#include <linux/fdtable.h>
51435 +#include <linux/percpu.h>
51436 +
51437 +#include <asm/uaccess.h>
51438 +#include <asm/errno.h>
51439 +#include <asm/mman.h>
51440 +
51441 +static struct acl_role_db acl_role_set;
51442 +static struct name_db name_set;
51443 +static struct inodev_db inodev_set;
51444 +
51445 +/* for keeping track of userspace pointers used for subjects, so we
51446 + can share references in the kernel as well
51447 +*/
51448 +
51449 +static struct path real_root;
51450 +
51451 +static struct acl_subj_map_db subj_map_set;
51452 +
51453 +static struct acl_role_label *default_role;
51454 +
51455 +static struct acl_role_label *role_list;
51456 +
51457 +static u16 acl_sp_role_value;
51458 +
51459 +extern char *gr_shared_page[4];
51460 +static DEFINE_MUTEX(gr_dev_mutex);
51461 +DEFINE_RWLOCK(gr_inode_lock);
51462 +
51463 +struct gr_arg *gr_usermode;
51464 +
51465 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51466 +
51467 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51468 +extern void gr_clear_learn_entries(void);
51469 +
51470 +#ifdef CONFIG_GRKERNSEC_RESLOG
51471 +extern void gr_log_resource(const struct task_struct *task,
51472 + const int res, const unsigned long wanted, const int gt);
51473 +#endif
51474 +
51475 +unsigned char *gr_system_salt;
51476 +unsigned char *gr_system_sum;
51477 +
51478 +static struct sprole_pw **acl_special_roles = NULL;
51479 +static __u16 num_sprole_pws = 0;
51480 +
51481 +static struct acl_role_label *kernel_role = NULL;
51482 +
51483 +static unsigned int gr_auth_attempts = 0;
51484 +static unsigned long gr_auth_expires = 0UL;
51485 +
51486 +#ifdef CONFIG_NET
51487 +extern struct vfsmount *sock_mnt;
51488 +#endif
51489 +
51490 +extern struct vfsmount *pipe_mnt;
51491 +extern struct vfsmount *shm_mnt;
51492 +#ifdef CONFIG_HUGETLBFS
51493 +extern struct vfsmount *hugetlbfs_vfsmount;
51494 +#endif
51495 +
51496 +static struct acl_object_label *fakefs_obj_rw;
51497 +static struct acl_object_label *fakefs_obj_rwx;
51498 +
51499 +extern int gr_init_uidset(void);
51500 +extern void gr_free_uidset(void);
51501 +extern void gr_remove_uid(uid_t uid);
51502 +extern int gr_find_uid(uid_t uid);
51503 +
51504 +DECLARE_BRLOCK(vfsmount_lock);
51505 +
51506 +__inline__ int
51507 +gr_acl_is_enabled(void)
51508 +{
51509 + return (gr_status & GR_READY);
51510 +}
51511 +
51512 +#ifdef CONFIG_BTRFS_FS
51513 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51514 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51515 +#endif
51516 +
51517 +static inline dev_t __get_dev(const struct dentry *dentry)
51518 +{
51519 +#ifdef CONFIG_BTRFS_FS
51520 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51521 + return get_btrfs_dev_from_inode(dentry->d_inode);
51522 + else
51523 +#endif
51524 + return dentry->d_inode->i_sb->s_dev;
51525 +}
51526 +
51527 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51528 +{
51529 + return __get_dev(dentry);
51530 +}
51531 +
51532 +static char gr_task_roletype_to_char(struct task_struct *task)
51533 +{
51534 + switch (task->role->roletype &
51535 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51536 + GR_ROLE_SPECIAL)) {
51537 + case GR_ROLE_DEFAULT:
51538 + return 'D';
51539 + case GR_ROLE_USER:
51540 + return 'U';
51541 + case GR_ROLE_GROUP:
51542 + return 'G';
51543 + case GR_ROLE_SPECIAL:
51544 + return 'S';
51545 + }
51546 +
51547 + return 'X';
51548 +}
51549 +
51550 +char gr_roletype_to_char(void)
51551 +{
51552 + return gr_task_roletype_to_char(current);
51553 +}
51554 +
51555 +__inline__ int
51556 +gr_acl_tpe_check(void)
51557 +{
51558 + if (unlikely(!(gr_status & GR_READY)))
51559 + return 0;
51560 + if (current->role->roletype & GR_ROLE_TPE)
51561 + return 1;
51562 + else
51563 + return 0;
51564 +}
51565 +
51566 +int
51567 +gr_handle_rawio(const struct inode *inode)
51568 +{
51569 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51570 + if (inode && S_ISBLK(inode->i_mode) &&
51571 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51572 + !capable(CAP_SYS_RAWIO))
51573 + return 1;
51574 +#endif
51575 + return 0;
51576 +}
51577 +
51578 +static int
51579 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51580 +{
51581 + if (likely(lena != lenb))
51582 + return 0;
51583 +
51584 + return !memcmp(a, b, lena);
51585 +}
51586 +
51587 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51588 +{
51589 + *buflen -= namelen;
51590 + if (*buflen < 0)
51591 + return -ENAMETOOLONG;
51592 + *buffer -= namelen;
51593 + memcpy(*buffer, str, namelen);
51594 + return 0;
51595 +}
51596 +
51597 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51598 +{
51599 + return prepend(buffer, buflen, name->name, name->len);
51600 +}
51601 +
51602 +static int prepend_path(const struct path *path, struct path *root,
51603 + char **buffer, int *buflen)
51604 +{
51605 + struct dentry *dentry = path->dentry;
51606 + struct vfsmount *vfsmnt = path->mnt;
51607 + bool slash = false;
51608 + int error = 0;
51609 +
51610 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51611 + struct dentry * parent;
51612 +
51613 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51614 + /* Global root? */
51615 + if (vfsmnt->mnt_parent == vfsmnt) {
51616 + goto out;
51617 + }
51618 + dentry = vfsmnt->mnt_mountpoint;
51619 + vfsmnt = vfsmnt->mnt_parent;
51620 + continue;
51621 + }
51622 + parent = dentry->d_parent;
51623 + prefetch(parent);
51624 + spin_lock(&dentry->d_lock);
51625 + error = prepend_name(buffer, buflen, &dentry->d_name);
51626 + spin_unlock(&dentry->d_lock);
51627 + if (!error)
51628 + error = prepend(buffer, buflen, "/", 1);
51629 + if (error)
51630 + break;
51631 +
51632 + slash = true;
51633 + dentry = parent;
51634 + }
51635 +
51636 +out:
51637 + if (!error && !slash)
51638 + error = prepend(buffer, buflen, "/", 1);
51639 +
51640 + return error;
51641 +}
51642 +
51643 +/* this must be called with vfsmount_lock and rename_lock held */
51644 +
51645 +static char *__our_d_path(const struct path *path, struct path *root,
51646 + char *buf, int buflen)
51647 +{
51648 + char *res = buf + buflen;
51649 + int error;
51650 +
51651 + prepend(&res, &buflen, "\0", 1);
51652 + error = prepend_path(path, root, &res, &buflen);
51653 + if (error)
51654 + return ERR_PTR(error);
51655 +
51656 + return res;
51657 +}
51658 +
51659 +static char *
51660 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51661 +{
51662 + char *retval;
51663 +
51664 + retval = __our_d_path(path, root, buf, buflen);
51665 + if (unlikely(IS_ERR(retval)))
51666 + retval = strcpy(buf, "<path too long>");
51667 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51668 + retval[1] = '\0';
51669 +
51670 + return retval;
51671 +}
51672 +
51673 +static char *
51674 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51675 + char *buf, int buflen)
51676 +{
51677 + struct path path;
51678 + char *res;
51679 +
51680 + path.dentry = (struct dentry *)dentry;
51681 + path.mnt = (struct vfsmount *)vfsmnt;
51682 +
51683 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51684 + by the RBAC system */
51685 + res = gen_full_path(&path, &real_root, buf, buflen);
51686 +
51687 + return res;
51688 +}
51689 +
51690 +static char *
51691 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51692 + char *buf, int buflen)
51693 +{
51694 + char *res;
51695 + struct path path;
51696 + struct path root;
51697 + struct task_struct *reaper = &init_task;
51698 +
51699 + path.dentry = (struct dentry *)dentry;
51700 + path.mnt = (struct vfsmount *)vfsmnt;
51701 +
51702 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51703 + get_fs_root(reaper->fs, &root);
51704 +
51705 + write_seqlock(&rename_lock);
51706 + br_read_lock(vfsmount_lock);
51707 + res = gen_full_path(&path, &root, buf, buflen);
51708 + br_read_unlock(vfsmount_lock);
51709 + write_sequnlock(&rename_lock);
51710 +
51711 + path_put(&root);
51712 + return res;
51713 +}
51714 +
51715 +static char *
51716 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51717 +{
51718 + char *ret;
51719 + write_seqlock(&rename_lock);
51720 + br_read_lock(vfsmount_lock);
51721 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51722 + PAGE_SIZE);
51723 + br_read_unlock(vfsmount_lock);
51724 + write_sequnlock(&rename_lock);
51725 + return ret;
51726 +}
51727 +
51728 +char *
51729 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51730 +{
51731 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51732 + PAGE_SIZE);
51733 +}
51734 +
51735 +char *
51736 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51737 +{
51738 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51739 + PAGE_SIZE);
51740 +}
51741 +
51742 +char *
51743 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51744 +{
51745 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51746 + PAGE_SIZE);
51747 +}
51748 +
51749 +char *
51750 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51751 +{
51752 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51753 + PAGE_SIZE);
51754 +}
51755 +
51756 +char *
51757 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51758 +{
51759 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51760 + PAGE_SIZE);
51761 +}
51762 +
51763 +__inline__ __u32
51764 +to_gr_audit(const __u32 reqmode)
51765 +{
51766 + /* masks off auditable permission flags, then shifts them to create
51767 + auditing flags, and adds the special case of append auditing if
51768 + we're requesting write */
51769 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51770 +}
51771 +
51772 +struct acl_subject_label *
51773 +lookup_subject_map(const struct acl_subject_label *userp)
51774 +{
51775 + unsigned int index = shash(userp, subj_map_set.s_size);
51776 + struct subject_map *match;
51777 +
51778 + match = subj_map_set.s_hash[index];
51779 +
51780 + while (match && match->user != userp)
51781 + match = match->next;
51782 +
51783 + if (match != NULL)
51784 + return match->kernel;
51785 + else
51786 + return NULL;
51787 +}
51788 +
51789 +static void
51790 +insert_subj_map_entry(struct subject_map *subjmap)
51791 +{
51792 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51793 + struct subject_map **curr;
51794 +
51795 + subjmap->prev = NULL;
51796 +
51797 + curr = &subj_map_set.s_hash[index];
51798 + if (*curr != NULL)
51799 + (*curr)->prev = subjmap;
51800 +
51801 + subjmap->next = *curr;
51802 + *curr = subjmap;
51803 +
51804 + return;
51805 +}
51806 +
51807 +static struct acl_role_label *
51808 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51809 + const gid_t gid)
51810 +{
51811 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51812 + struct acl_role_label *match;
51813 + struct role_allowed_ip *ipp;
51814 + unsigned int x;
51815 + u32 curr_ip = task->signal->curr_ip;
51816 +
51817 + task->signal->saved_ip = curr_ip;
51818 +
51819 + match = acl_role_set.r_hash[index];
51820 +
51821 + while (match) {
51822 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51823 + for (x = 0; x < match->domain_child_num; x++) {
51824 + if (match->domain_children[x] == uid)
51825 + goto found;
51826 + }
51827 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51828 + break;
51829 + match = match->next;
51830 + }
51831 +found:
51832 + if (match == NULL) {
51833 + try_group:
51834 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51835 + match = acl_role_set.r_hash[index];
51836 +
51837 + while (match) {
51838 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51839 + for (x = 0; x < match->domain_child_num; x++) {
51840 + if (match->domain_children[x] == gid)
51841 + goto found2;
51842 + }
51843 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51844 + break;
51845 + match = match->next;
51846 + }
51847 +found2:
51848 + if (match == NULL)
51849 + match = default_role;
51850 + if (match->allowed_ips == NULL)
51851 + return match;
51852 + else {
51853 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51854 + if (likely
51855 + ((ntohl(curr_ip) & ipp->netmask) ==
51856 + (ntohl(ipp->addr) & ipp->netmask)))
51857 + return match;
51858 + }
51859 + match = default_role;
51860 + }
51861 + } else if (match->allowed_ips == NULL) {
51862 + return match;
51863 + } else {
51864 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51865 + if (likely
51866 + ((ntohl(curr_ip) & ipp->netmask) ==
51867 + (ntohl(ipp->addr) & ipp->netmask)))
51868 + return match;
51869 + }
51870 + goto try_group;
51871 + }
51872 +
51873 + return match;
51874 +}
51875 +
51876 +struct acl_subject_label *
51877 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51878 + const struct acl_role_label *role)
51879 +{
51880 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51881 + struct acl_subject_label *match;
51882 +
51883 + match = role->subj_hash[index];
51884 +
51885 + while (match && (match->inode != ino || match->device != dev ||
51886 + (match->mode & GR_DELETED))) {
51887 + match = match->next;
51888 + }
51889 +
51890 + if (match && !(match->mode & GR_DELETED))
51891 + return match;
51892 + else
51893 + return NULL;
51894 +}
51895 +
51896 +struct acl_subject_label *
51897 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51898 + const struct acl_role_label *role)
51899 +{
51900 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51901 + struct acl_subject_label *match;
51902 +
51903 + match = role->subj_hash[index];
51904 +
51905 + while (match && (match->inode != ino || match->device != dev ||
51906 + !(match->mode & GR_DELETED))) {
51907 + match = match->next;
51908 + }
51909 +
51910 + if (match && (match->mode & GR_DELETED))
51911 + return match;
51912 + else
51913 + return NULL;
51914 +}
51915 +
51916 +static struct acl_object_label *
51917 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51918 + const struct acl_subject_label *subj)
51919 +{
51920 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51921 + struct acl_object_label *match;
51922 +
51923 + match = subj->obj_hash[index];
51924 +
51925 + while (match && (match->inode != ino || match->device != dev ||
51926 + (match->mode & GR_DELETED))) {
51927 + match = match->next;
51928 + }
51929 +
51930 + if (match && !(match->mode & GR_DELETED))
51931 + return match;
51932 + else
51933 + return NULL;
51934 +}
51935 +
51936 +static struct acl_object_label *
51937 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51938 + const struct acl_subject_label *subj)
51939 +{
51940 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51941 + struct acl_object_label *match;
51942 +
51943 + match = subj->obj_hash[index];
51944 +
51945 + while (match && (match->inode != ino || match->device != dev ||
51946 + !(match->mode & GR_DELETED))) {
51947 + match = match->next;
51948 + }
51949 +
51950 + if (match && (match->mode & GR_DELETED))
51951 + return match;
51952 +
51953 + match = subj->obj_hash[index];
51954 +
51955 + while (match && (match->inode != ino || match->device != dev ||
51956 + (match->mode & GR_DELETED))) {
51957 + match = match->next;
51958 + }
51959 +
51960 + if (match && !(match->mode & GR_DELETED))
51961 + return match;
51962 + else
51963 + return NULL;
51964 +}
51965 +
51966 +static struct name_entry *
51967 +lookup_name_entry(const char *name)
51968 +{
51969 + unsigned int len = strlen(name);
51970 + unsigned int key = full_name_hash(name, len);
51971 + unsigned int index = key % name_set.n_size;
51972 + struct name_entry *match;
51973 +
51974 + match = name_set.n_hash[index];
51975 +
51976 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51977 + match = match->next;
51978 +
51979 + return match;
51980 +}
51981 +
51982 +static struct name_entry *
51983 +lookup_name_entry_create(const char *name)
51984 +{
51985 + unsigned int len = strlen(name);
51986 + unsigned int key = full_name_hash(name, len);
51987 + unsigned int index = key % name_set.n_size;
51988 + struct name_entry *match;
51989 +
51990 + match = name_set.n_hash[index];
51991 +
51992 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51993 + !match->deleted))
51994 + match = match->next;
51995 +
51996 + if (match && match->deleted)
51997 + return match;
51998 +
51999 + match = name_set.n_hash[index];
52000 +
52001 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52002 + match->deleted))
52003 + match = match->next;
52004 +
52005 + if (match && !match->deleted)
52006 + return match;
52007 + else
52008 + return NULL;
52009 +}
52010 +
52011 +static struct inodev_entry *
52012 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52013 +{
52014 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52015 + struct inodev_entry *match;
52016 +
52017 + match = inodev_set.i_hash[index];
52018 +
52019 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52020 + match = match->next;
52021 +
52022 + return match;
52023 +}
52024 +
52025 +static void
52026 +insert_inodev_entry(struct inodev_entry *entry)
52027 +{
52028 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52029 + inodev_set.i_size);
52030 + struct inodev_entry **curr;
52031 +
52032 + entry->prev = NULL;
52033 +
52034 + curr = &inodev_set.i_hash[index];
52035 + if (*curr != NULL)
52036 + (*curr)->prev = entry;
52037 +
52038 + entry->next = *curr;
52039 + *curr = entry;
52040 +
52041 + return;
52042 +}
52043 +
52044 +static void
52045 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52046 +{
52047 + unsigned int index =
52048 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52049 + struct acl_role_label **curr;
52050 + struct acl_role_label *tmp;
52051 +
52052 + curr = &acl_role_set.r_hash[index];
52053 +
52054 + /* if role was already inserted due to domains and already has
52055 + a role in the same bucket as it attached, then we need to
52056 + combine these two buckets
52057 + */
52058 + if (role->next) {
52059 + tmp = role->next;
52060 + while (tmp->next)
52061 + tmp = tmp->next;
52062 + tmp->next = *curr;
52063 + } else
52064 + role->next = *curr;
52065 + *curr = role;
52066 +
52067 + return;
52068 +}
52069 +
52070 +static void
52071 +insert_acl_role_label(struct acl_role_label *role)
52072 +{
52073 + int i;
52074 +
52075 + if (role_list == NULL) {
52076 + role_list = role;
52077 + role->prev = NULL;
52078 + } else {
52079 + role->prev = role_list;
52080 + role_list = role;
52081 + }
52082 +
52083 + /* used for hash chains */
52084 + role->next = NULL;
52085 +
52086 + if (role->roletype & GR_ROLE_DOMAIN) {
52087 + for (i = 0; i < role->domain_child_num; i++)
52088 + __insert_acl_role_label(role, role->domain_children[i]);
52089 + } else
52090 + __insert_acl_role_label(role, role->uidgid);
52091 +}
52092 +
52093 +static int
52094 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52095 +{
52096 + struct name_entry **curr, *nentry;
52097 + struct inodev_entry *ientry;
52098 + unsigned int len = strlen(name);
52099 + unsigned int key = full_name_hash(name, len);
52100 + unsigned int index = key % name_set.n_size;
52101 +
52102 + curr = &name_set.n_hash[index];
52103 +
52104 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52105 + curr = &((*curr)->next);
52106 +
52107 + if (*curr != NULL)
52108 + return 1;
52109 +
52110 + nentry = acl_alloc(sizeof (struct name_entry));
52111 + if (nentry == NULL)
52112 + return 0;
52113 + ientry = acl_alloc(sizeof (struct inodev_entry));
52114 + if (ientry == NULL)
52115 + return 0;
52116 + ientry->nentry = nentry;
52117 +
52118 + nentry->key = key;
52119 + nentry->name = name;
52120 + nentry->inode = inode;
52121 + nentry->device = device;
52122 + nentry->len = len;
52123 + nentry->deleted = deleted;
52124 +
52125 + nentry->prev = NULL;
52126 + curr = &name_set.n_hash[index];
52127 + if (*curr != NULL)
52128 + (*curr)->prev = nentry;
52129 + nentry->next = *curr;
52130 + *curr = nentry;
52131 +
52132 + /* insert us into the table searchable by inode/dev */
52133 + insert_inodev_entry(ientry);
52134 +
52135 + return 1;
52136 +}
52137 +
52138 +static void
52139 +insert_acl_obj_label(struct acl_object_label *obj,
52140 + struct acl_subject_label *subj)
52141 +{
52142 + unsigned int index =
52143 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52144 + struct acl_object_label **curr;
52145 +
52146 +
52147 + obj->prev = NULL;
52148 +
52149 + curr = &subj->obj_hash[index];
52150 + if (*curr != NULL)
52151 + (*curr)->prev = obj;
52152 +
52153 + obj->next = *curr;
52154 + *curr = obj;
52155 +
52156 + return;
52157 +}
52158 +
52159 +static void
52160 +insert_acl_subj_label(struct acl_subject_label *obj,
52161 + struct acl_role_label *role)
52162 +{
52163 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52164 + struct acl_subject_label **curr;
52165 +
52166 + obj->prev = NULL;
52167 +
52168 + curr = &role->subj_hash[index];
52169 + if (*curr != NULL)
52170 + (*curr)->prev = obj;
52171 +
52172 + obj->next = *curr;
52173 + *curr = obj;
52174 +
52175 + return;
52176 +}
52177 +
52178 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52179 +
52180 +static void *
52181 +create_table(__u32 * len, int elementsize)
52182 +{
52183 + unsigned int table_sizes[] = {
52184 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52185 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52186 + 4194301, 8388593, 16777213, 33554393, 67108859
52187 + };
52188 + void *newtable = NULL;
52189 + unsigned int pwr = 0;
52190 +
52191 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52192 + table_sizes[pwr] <= *len)
52193 + pwr++;
52194 +
52195 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52196 + return newtable;
52197 +
52198 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52199 + newtable =
52200 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52201 + else
52202 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52203 +
52204 + *len = table_sizes[pwr];
52205 +
52206 + return newtable;
52207 +}
52208 +
52209 +static int
52210 +init_variables(const struct gr_arg *arg)
52211 +{
52212 + struct task_struct *reaper = &init_task;
52213 + unsigned int stacksize;
52214 +
52215 + subj_map_set.s_size = arg->role_db.num_subjects;
52216 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52217 + name_set.n_size = arg->role_db.num_objects;
52218 + inodev_set.i_size = arg->role_db.num_objects;
52219 +
52220 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52221 + !name_set.n_size || !inodev_set.i_size)
52222 + return 1;
52223 +
52224 + if (!gr_init_uidset())
52225 + return 1;
52226 +
52227 + /* set up the stack that holds allocation info */
52228 +
52229 + stacksize = arg->role_db.num_pointers + 5;
52230 +
52231 + if (!acl_alloc_stack_init(stacksize))
52232 + return 1;
52233 +
52234 + /* grab reference for the real root dentry and vfsmount */
52235 + get_fs_root(reaper->fs, &real_root);
52236 +
52237 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52238 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52239 +#endif
52240 +
52241 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52242 + if (fakefs_obj_rw == NULL)
52243 + return 1;
52244 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52245 +
52246 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52247 + if (fakefs_obj_rwx == NULL)
52248 + return 1;
52249 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52250 +
52251 + subj_map_set.s_hash =
52252 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52253 + acl_role_set.r_hash =
52254 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52255 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52256 + inodev_set.i_hash =
52257 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52258 +
52259 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52260 + !name_set.n_hash || !inodev_set.i_hash)
52261 + return 1;
52262 +
52263 + memset(subj_map_set.s_hash, 0,
52264 + sizeof(struct subject_map *) * subj_map_set.s_size);
52265 + memset(acl_role_set.r_hash, 0,
52266 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52267 + memset(name_set.n_hash, 0,
52268 + sizeof (struct name_entry *) * name_set.n_size);
52269 + memset(inodev_set.i_hash, 0,
52270 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52271 +
52272 + return 0;
52273 +}
52274 +
52275 +/* free information not needed after startup
52276 + currently contains user->kernel pointer mappings for subjects
52277 +*/
52278 +
52279 +static void
52280 +free_init_variables(void)
52281 +{
52282 + __u32 i;
52283 +
52284 + if (subj_map_set.s_hash) {
52285 + for (i = 0; i < subj_map_set.s_size; i++) {
52286 + if (subj_map_set.s_hash[i]) {
52287 + kfree(subj_map_set.s_hash[i]);
52288 + subj_map_set.s_hash[i] = NULL;
52289 + }
52290 + }
52291 +
52292 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52293 + PAGE_SIZE)
52294 + kfree(subj_map_set.s_hash);
52295 + else
52296 + vfree(subj_map_set.s_hash);
52297 + }
52298 +
52299 + return;
52300 +}
52301 +
52302 +static void
52303 +free_variables(void)
52304 +{
52305 + struct acl_subject_label *s;
52306 + struct acl_role_label *r;
52307 + struct task_struct *task, *task2;
52308 + unsigned int x;
52309 +
52310 + gr_clear_learn_entries();
52311 +
52312 + read_lock(&tasklist_lock);
52313 + do_each_thread(task2, task) {
52314 + task->acl_sp_role = 0;
52315 + task->acl_role_id = 0;
52316 + task->acl = NULL;
52317 + task->role = NULL;
52318 + } while_each_thread(task2, task);
52319 + read_unlock(&tasklist_lock);
52320 +
52321 + /* release the reference to the real root dentry and vfsmount */
52322 + path_put(&real_root);
52323 +
52324 + /* free all object hash tables */
52325 +
52326 + FOR_EACH_ROLE_START(r)
52327 + if (r->subj_hash == NULL)
52328 + goto next_role;
52329 + FOR_EACH_SUBJECT_START(r, s, x)
52330 + if (s->obj_hash == NULL)
52331 + break;
52332 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52333 + kfree(s->obj_hash);
52334 + else
52335 + vfree(s->obj_hash);
52336 + FOR_EACH_SUBJECT_END(s, x)
52337 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52338 + if (s->obj_hash == NULL)
52339 + break;
52340 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52341 + kfree(s->obj_hash);
52342 + else
52343 + vfree(s->obj_hash);
52344 + FOR_EACH_NESTED_SUBJECT_END(s)
52345 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52346 + kfree(r->subj_hash);
52347 + else
52348 + vfree(r->subj_hash);
52349 + r->subj_hash = NULL;
52350 +next_role:
52351 + FOR_EACH_ROLE_END(r)
52352 +
52353 + acl_free_all();
52354 +
52355 + if (acl_role_set.r_hash) {
52356 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52357 + PAGE_SIZE)
52358 + kfree(acl_role_set.r_hash);
52359 + else
52360 + vfree(acl_role_set.r_hash);
52361 + }
52362 + if (name_set.n_hash) {
52363 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52364 + PAGE_SIZE)
52365 + kfree(name_set.n_hash);
52366 + else
52367 + vfree(name_set.n_hash);
52368 + }
52369 +
52370 + if (inodev_set.i_hash) {
52371 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52372 + PAGE_SIZE)
52373 + kfree(inodev_set.i_hash);
52374 + else
52375 + vfree(inodev_set.i_hash);
52376 + }
52377 +
52378 + gr_free_uidset();
52379 +
52380 + memset(&name_set, 0, sizeof (struct name_db));
52381 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52382 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52383 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52384 +
52385 + default_role = NULL;
52386 + role_list = NULL;
52387 +
52388 + return;
52389 +}
52390 +
52391 +static __u32
52392 +count_user_objs(struct acl_object_label *userp)
52393 +{
52394 + struct acl_object_label o_tmp;
52395 + __u32 num = 0;
52396 +
52397 + while (userp) {
52398 + if (copy_from_user(&o_tmp, userp,
52399 + sizeof (struct acl_object_label)))
52400 + break;
52401 +
52402 + userp = o_tmp.prev;
52403 + num++;
52404 + }
52405 +
52406 + return num;
52407 +}
52408 +
52409 +static struct acl_subject_label *
52410 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52411 +
52412 +static int
52413 +copy_user_glob(struct acl_object_label *obj)
52414 +{
52415 + struct acl_object_label *g_tmp, **guser;
52416 + unsigned int len;
52417 + char *tmp;
52418 +
52419 + if (obj->globbed == NULL)
52420 + return 0;
52421 +
52422 + guser = &obj->globbed;
52423 + while (*guser) {
52424 + g_tmp = (struct acl_object_label *)
52425 + acl_alloc(sizeof (struct acl_object_label));
52426 + if (g_tmp == NULL)
52427 + return -ENOMEM;
52428 +
52429 + if (copy_from_user(g_tmp, *guser,
52430 + sizeof (struct acl_object_label)))
52431 + return -EFAULT;
52432 +
52433 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52434 +
52435 + if (!len || len >= PATH_MAX)
52436 + return -EINVAL;
52437 +
52438 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52439 + return -ENOMEM;
52440 +
52441 + if (copy_from_user(tmp, g_tmp->filename, len))
52442 + return -EFAULT;
52443 + tmp[len-1] = '\0';
52444 + g_tmp->filename = tmp;
52445 +
52446 + *guser = g_tmp;
52447 + guser = &(g_tmp->next);
52448 + }
52449 +
52450 + return 0;
52451 +}
52452 +
52453 +static int
52454 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52455 + struct acl_role_label *role)
52456 +{
52457 + struct acl_object_label *o_tmp;
52458 + unsigned int len;
52459 + int ret;
52460 + char *tmp;
52461 +
52462 + while (userp) {
52463 + if ((o_tmp = (struct acl_object_label *)
52464 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52465 + return -ENOMEM;
52466 +
52467 + if (copy_from_user(o_tmp, userp,
52468 + sizeof (struct acl_object_label)))
52469 + return -EFAULT;
52470 +
52471 + userp = o_tmp->prev;
52472 +
52473 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52474 +
52475 + if (!len || len >= PATH_MAX)
52476 + return -EINVAL;
52477 +
52478 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52479 + return -ENOMEM;
52480 +
52481 + if (copy_from_user(tmp, o_tmp->filename, len))
52482 + return -EFAULT;
52483 + tmp[len-1] = '\0';
52484 + o_tmp->filename = tmp;
52485 +
52486 + insert_acl_obj_label(o_tmp, subj);
52487 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52488 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52489 + return -ENOMEM;
52490 +
52491 + ret = copy_user_glob(o_tmp);
52492 + if (ret)
52493 + return ret;
52494 +
52495 + if (o_tmp->nested) {
52496 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52497 + if (IS_ERR(o_tmp->nested))
52498 + return PTR_ERR(o_tmp->nested);
52499 +
52500 + /* insert into nested subject list */
52501 + o_tmp->nested->next = role->hash->first;
52502 + role->hash->first = o_tmp->nested;
52503 + }
52504 + }
52505 +
52506 + return 0;
52507 +}
52508 +
52509 +static __u32
52510 +count_user_subjs(struct acl_subject_label *userp)
52511 +{
52512 + struct acl_subject_label s_tmp;
52513 + __u32 num = 0;
52514 +
52515 + while (userp) {
52516 + if (copy_from_user(&s_tmp, userp,
52517 + sizeof (struct acl_subject_label)))
52518 + break;
52519 +
52520 + userp = s_tmp.prev;
52521 + /* do not count nested subjects against this count, since
52522 + they are not included in the hash table, but are
52523 + attached to objects. We have already counted
52524 + the subjects in userspace for the allocation
52525 + stack
52526 + */
52527 + if (!(s_tmp.mode & GR_NESTED))
52528 + num++;
52529 + }
52530 +
52531 + return num;
52532 +}
52533 +
52534 +static int
52535 +copy_user_allowedips(struct acl_role_label *rolep)
52536 +{
52537 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52538 +
52539 + ruserip = rolep->allowed_ips;
52540 +
52541 + while (ruserip) {
52542 + rlast = rtmp;
52543 +
52544 + if ((rtmp = (struct role_allowed_ip *)
52545 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52546 + return -ENOMEM;
52547 +
52548 + if (copy_from_user(rtmp, ruserip,
52549 + sizeof (struct role_allowed_ip)))
52550 + return -EFAULT;
52551 +
52552 + ruserip = rtmp->prev;
52553 +
52554 + if (!rlast) {
52555 + rtmp->prev = NULL;
52556 + rolep->allowed_ips = rtmp;
52557 + } else {
52558 + rlast->next = rtmp;
52559 + rtmp->prev = rlast;
52560 + }
52561 +
52562 + if (!ruserip)
52563 + rtmp->next = NULL;
52564 + }
52565 +
52566 + return 0;
52567 +}
52568 +
52569 +static int
52570 +copy_user_transitions(struct acl_role_label *rolep)
52571 +{
52572 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52573 +
52574 + unsigned int len;
52575 + char *tmp;
52576 +
52577 + rusertp = rolep->transitions;
52578 +
52579 + while (rusertp) {
52580 + rlast = rtmp;
52581 +
52582 + if ((rtmp = (struct role_transition *)
52583 + acl_alloc(sizeof (struct role_transition))) == NULL)
52584 + return -ENOMEM;
52585 +
52586 + if (copy_from_user(rtmp, rusertp,
52587 + sizeof (struct role_transition)))
52588 + return -EFAULT;
52589 +
52590 + rusertp = rtmp->prev;
52591 +
52592 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52593 +
52594 + if (!len || len >= GR_SPROLE_LEN)
52595 + return -EINVAL;
52596 +
52597 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52598 + return -ENOMEM;
52599 +
52600 + if (copy_from_user(tmp, rtmp->rolename, len))
52601 + return -EFAULT;
52602 + tmp[len-1] = '\0';
52603 + rtmp->rolename = tmp;
52604 +
52605 + if (!rlast) {
52606 + rtmp->prev = NULL;
52607 + rolep->transitions = rtmp;
52608 + } else {
52609 + rlast->next = rtmp;
52610 + rtmp->prev = rlast;
52611 + }
52612 +
52613 + if (!rusertp)
52614 + rtmp->next = NULL;
52615 + }
52616 +
52617 + return 0;
52618 +}
52619 +
52620 +static struct acl_subject_label *
52621 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52622 +{
52623 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52624 + unsigned int len;
52625 + char *tmp;
52626 + __u32 num_objs;
52627 + struct acl_ip_label **i_tmp, *i_utmp2;
52628 + struct gr_hash_struct ghash;
52629 + struct subject_map *subjmap;
52630 + unsigned int i_num;
52631 + int err;
52632 +
52633 + s_tmp = lookup_subject_map(userp);
52634 +
52635 + /* we've already copied this subject into the kernel, just return
52636 + the reference to it, and don't copy it over again
52637 + */
52638 + if (s_tmp)
52639 + return(s_tmp);
52640 +
52641 + if ((s_tmp = (struct acl_subject_label *)
52642 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52643 + return ERR_PTR(-ENOMEM);
52644 +
52645 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52646 + if (subjmap == NULL)
52647 + return ERR_PTR(-ENOMEM);
52648 +
52649 + subjmap->user = userp;
52650 + subjmap->kernel = s_tmp;
52651 + insert_subj_map_entry(subjmap);
52652 +
52653 + if (copy_from_user(s_tmp, userp,
52654 + sizeof (struct acl_subject_label)))
52655 + return ERR_PTR(-EFAULT);
52656 +
52657 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52658 +
52659 + if (!len || len >= PATH_MAX)
52660 + return ERR_PTR(-EINVAL);
52661 +
52662 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52663 + return ERR_PTR(-ENOMEM);
52664 +
52665 + if (copy_from_user(tmp, s_tmp->filename, len))
52666 + return ERR_PTR(-EFAULT);
52667 + tmp[len-1] = '\0';
52668 + s_tmp->filename = tmp;
52669 +
52670 + if (!strcmp(s_tmp->filename, "/"))
52671 + role->root_label = s_tmp;
52672 +
52673 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52674 + return ERR_PTR(-EFAULT);
52675 +
52676 + /* copy user and group transition tables */
52677 +
52678 + if (s_tmp->user_trans_num) {
52679 + uid_t *uidlist;
52680 +
52681 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52682 + if (uidlist == NULL)
52683 + return ERR_PTR(-ENOMEM);
52684 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52685 + return ERR_PTR(-EFAULT);
52686 +
52687 + s_tmp->user_transitions = uidlist;
52688 + }
52689 +
52690 + if (s_tmp->group_trans_num) {
52691 + gid_t *gidlist;
52692 +
52693 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52694 + if (gidlist == NULL)
52695 + return ERR_PTR(-ENOMEM);
52696 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52697 + return ERR_PTR(-EFAULT);
52698 +
52699 + s_tmp->group_transitions = gidlist;
52700 + }
52701 +
52702 + /* set up object hash table */
52703 + num_objs = count_user_objs(ghash.first);
52704 +
52705 + s_tmp->obj_hash_size = num_objs;
52706 + s_tmp->obj_hash =
52707 + (struct acl_object_label **)
52708 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52709 +
52710 + if (!s_tmp->obj_hash)
52711 + return ERR_PTR(-ENOMEM);
52712 +
52713 + memset(s_tmp->obj_hash, 0,
52714 + s_tmp->obj_hash_size *
52715 + sizeof (struct acl_object_label *));
52716 +
52717 + /* add in objects */
52718 + err = copy_user_objs(ghash.first, s_tmp, role);
52719 +
52720 + if (err)
52721 + return ERR_PTR(err);
52722 +
52723 + /* set pointer for parent subject */
52724 + if (s_tmp->parent_subject) {
52725 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52726 +
52727 + if (IS_ERR(s_tmp2))
52728 + return s_tmp2;
52729 +
52730 + s_tmp->parent_subject = s_tmp2;
52731 + }
52732 +
52733 + /* add in ip acls */
52734 +
52735 + if (!s_tmp->ip_num) {
52736 + s_tmp->ips = NULL;
52737 + goto insert;
52738 + }
52739 +
52740 + i_tmp =
52741 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52742 + sizeof (struct acl_ip_label *));
52743 +
52744 + if (!i_tmp)
52745 + return ERR_PTR(-ENOMEM);
52746 +
52747 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52748 + *(i_tmp + i_num) =
52749 + (struct acl_ip_label *)
52750 + acl_alloc(sizeof (struct acl_ip_label));
52751 + if (!*(i_tmp + i_num))
52752 + return ERR_PTR(-ENOMEM);
52753 +
52754 + if (copy_from_user
52755 + (&i_utmp2, s_tmp->ips + i_num,
52756 + sizeof (struct acl_ip_label *)))
52757 + return ERR_PTR(-EFAULT);
52758 +
52759 + if (copy_from_user
52760 + (*(i_tmp + i_num), i_utmp2,
52761 + sizeof (struct acl_ip_label)))
52762 + return ERR_PTR(-EFAULT);
52763 +
52764 + if ((*(i_tmp + i_num))->iface == NULL)
52765 + continue;
52766 +
52767 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52768 + if (!len || len >= IFNAMSIZ)
52769 + return ERR_PTR(-EINVAL);
52770 + tmp = acl_alloc(len);
52771 + if (tmp == NULL)
52772 + return ERR_PTR(-ENOMEM);
52773 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52774 + return ERR_PTR(-EFAULT);
52775 + (*(i_tmp + i_num))->iface = tmp;
52776 + }
52777 +
52778 + s_tmp->ips = i_tmp;
52779 +
52780 +insert:
52781 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52782 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52783 + return ERR_PTR(-ENOMEM);
52784 +
52785 + return s_tmp;
52786 +}
52787 +
52788 +static int
52789 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52790 +{
52791 + struct acl_subject_label s_pre;
52792 + struct acl_subject_label * ret;
52793 + int err;
52794 +
52795 + while (userp) {
52796 + if (copy_from_user(&s_pre, userp,
52797 + sizeof (struct acl_subject_label)))
52798 + return -EFAULT;
52799 +
52800 + /* do not add nested subjects here, add
52801 + while parsing objects
52802 + */
52803 +
52804 + if (s_pre.mode & GR_NESTED) {
52805 + userp = s_pre.prev;
52806 + continue;
52807 + }
52808 +
52809 + ret = do_copy_user_subj(userp, role);
52810 +
52811 + err = PTR_ERR(ret);
52812 + if (IS_ERR(ret))
52813 + return err;
52814 +
52815 + insert_acl_subj_label(ret, role);
52816 +
52817 + userp = s_pre.prev;
52818 + }
52819 +
52820 + return 0;
52821 +}
52822 +
52823 +static int
52824 +copy_user_acl(struct gr_arg *arg)
52825 +{
52826 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52827 + struct sprole_pw *sptmp;
52828 + struct gr_hash_struct *ghash;
52829 + uid_t *domainlist;
52830 + unsigned int r_num;
52831 + unsigned int len;
52832 + char *tmp;
52833 + int err = 0;
52834 + __u16 i;
52835 + __u32 num_subjs;
52836 +
52837 + /* we need a default and kernel role */
52838 + if (arg->role_db.num_roles < 2)
52839 + return -EINVAL;
52840 +
52841 + /* copy special role authentication info from userspace */
52842 +
52843 + num_sprole_pws = arg->num_sprole_pws;
52844 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52845 +
52846 + if (!acl_special_roles) {
52847 + err = -ENOMEM;
52848 + goto cleanup;
52849 + }
52850 +
52851 + for (i = 0; i < num_sprole_pws; i++) {
52852 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52853 + if (!sptmp) {
52854 + err = -ENOMEM;
52855 + goto cleanup;
52856 + }
52857 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52858 + sizeof (struct sprole_pw))) {
52859 + err = -EFAULT;
52860 + goto cleanup;
52861 + }
52862 +
52863 + len =
52864 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52865 +
52866 + if (!len || len >= GR_SPROLE_LEN) {
52867 + err = -EINVAL;
52868 + goto cleanup;
52869 + }
52870 +
52871 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52872 + err = -ENOMEM;
52873 + goto cleanup;
52874 + }
52875 +
52876 + if (copy_from_user(tmp, sptmp->rolename, len)) {
52877 + err = -EFAULT;
52878 + goto cleanup;
52879 + }
52880 + tmp[len-1] = '\0';
52881 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52882 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52883 +#endif
52884 + sptmp->rolename = tmp;
52885 + acl_special_roles[i] = sptmp;
52886 + }
52887 +
52888 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52889 +
52890 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52891 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52892 +
52893 + if (!r_tmp) {
52894 + err = -ENOMEM;
52895 + goto cleanup;
52896 + }
52897 +
52898 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52899 + sizeof (struct acl_role_label *))) {
52900 + err = -EFAULT;
52901 + goto cleanup;
52902 + }
52903 +
52904 + if (copy_from_user(r_tmp, r_utmp2,
52905 + sizeof (struct acl_role_label))) {
52906 + err = -EFAULT;
52907 + goto cleanup;
52908 + }
52909 +
52910 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52911 +
52912 + if (!len || len >= PATH_MAX) {
52913 + err = -EINVAL;
52914 + goto cleanup;
52915 + }
52916 +
52917 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
52918 + err = -ENOMEM;
52919 + goto cleanup;
52920 + }
52921 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
52922 + err = -EFAULT;
52923 + goto cleanup;
52924 + }
52925 + tmp[len-1] = '\0';
52926 + r_tmp->rolename = tmp;
52927 +
52928 + if (!strcmp(r_tmp->rolename, "default")
52929 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52930 + default_role = r_tmp;
52931 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52932 + kernel_role = r_tmp;
52933 + }
52934 +
52935 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
52936 + err = -ENOMEM;
52937 + goto cleanup;
52938 + }
52939 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
52940 + err = -EFAULT;
52941 + goto cleanup;
52942 + }
52943 +
52944 + r_tmp->hash = ghash;
52945 +
52946 + num_subjs = count_user_subjs(r_tmp->hash->first);
52947 +
52948 + r_tmp->subj_hash_size = num_subjs;
52949 + r_tmp->subj_hash =
52950 + (struct acl_subject_label **)
52951 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52952 +
52953 + if (!r_tmp->subj_hash) {
52954 + err = -ENOMEM;
52955 + goto cleanup;
52956 + }
52957 +
52958 + err = copy_user_allowedips(r_tmp);
52959 + if (err)
52960 + goto cleanup;
52961 +
52962 + /* copy domain info */
52963 + if (r_tmp->domain_children != NULL) {
52964 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52965 + if (domainlist == NULL) {
52966 + err = -ENOMEM;
52967 + goto cleanup;
52968 + }
52969 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
52970 + err = -EFAULT;
52971 + goto cleanup;
52972 + }
52973 + r_tmp->domain_children = domainlist;
52974 + }
52975 +
52976 + err = copy_user_transitions(r_tmp);
52977 + if (err)
52978 + goto cleanup;
52979 +
52980 + memset(r_tmp->subj_hash, 0,
52981 + r_tmp->subj_hash_size *
52982 + sizeof (struct acl_subject_label *));
52983 +
52984 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52985 +
52986 + if (err)
52987 + goto cleanup;
52988 +
52989 + /* set nested subject list to null */
52990 + r_tmp->hash->first = NULL;
52991 +
52992 + insert_acl_role_label(r_tmp);
52993 + }
52994 +
52995 + goto return_err;
52996 + cleanup:
52997 + free_variables();
52998 + return_err:
52999 + return err;
53000 +
53001 +}
53002 +
53003 +static int
53004 +gracl_init(struct gr_arg *args)
53005 +{
53006 + int error = 0;
53007 +
53008 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53009 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53010 +
53011 + if (init_variables(args)) {
53012 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53013 + error = -ENOMEM;
53014 + free_variables();
53015 + goto out;
53016 + }
53017 +
53018 + error = copy_user_acl(args);
53019 + free_init_variables();
53020 + if (error) {
53021 + free_variables();
53022 + goto out;
53023 + }
53024 +
53025 + if ((error = gr_set_acls(0))) {
53026 + free_variables();
53027 + goto out;
53028 + }
53029 +
53030 + pax_open_kernel();
53031 + gr_status |= GR_READY;
53032 + pax_close_kernel();
53033 +
53034 + out:
53035 + return error;
53036 +}
53037 +
53038 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53039 +
53040 +static int
53041 +glob_match(const char *p, const char *n)
53042 +{
53043 + char c;
53044 +
53045 + while ((c = *p++) != '\0') {
53046 + switch (c) {
53047 + case '?':
53048 + if (*n == '\0')
53049 + return 1;
53050 + else if (*n == '/')
53051 + return 1;
53052 + break;
53053 + case '\\':
53054 + if (*n != c)
53055 + return 1;
53056 + break;
53057 + case '*':
53058 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53059 + if (*n == '/')
53060 + return 1;
53061 + else if (c == '?') {
53062 + if (*n == '\0')
53063 + return 1;
53064 + else
53065 + ++n;
53066 + }
53067 + }
53068 + if (c == '\0') {
53069 + return 0;
53070 + } else {
53071 + const char *endp;
53072 +
53073 + if ((endp = strchr(n, '/')) == NULL)
53074 + endp = n + strlen(n);
53075 +
53076 + if (c == '[') {
53077 + for (--p; n < endp; ++n)
53078 + if (!glob_match(p, n))
53079 + return 0;
53080 + } else if (c == '/') {
53081 + while (*n != '\0' && *n != '/')
53082 + ++n;
53083 + if (*n == '/' && !glob_match(p, n + 1))
53084 + return 0;
53085 + } else {
53086 + for (--p; n < endp; ++n)
53087 + if (*n == c && !glob_match(p, n))
53088 + return 0;
53089 + }
53090 +
53091 + return 1;
53092 + }
53093 + case '[':
53094 + {
53095 + int not;
53096 + char cold;
53097 +
53098 + if (*n == '\0' || *n == '/')
53099 + return 1;
53100 +
53101 + not = (*p == '!' || *p == '^');
53102 + if (not)
53103 + ++p;
53104 +
53105 + c = *p++;
53106 + for (;;) {
53107 + unsigned char fn = (unsigned char)*n;
53108 +
53109 + if (c == '\0')
53110 + return 1;
53111 + else {
53112 + if (c == fn)
53113 + goto matched;
53114 + cold = c;
53115 + c = *p++;
53116 +
53117 + if (c == '-' && *p != ']') {
53118 + unsigned char cend = *p++;
53119 +
53120 + if (cend == '\0')
53121 + return 1;
53122 +
53123 + if (cold <= fn && fn <= cend)
53124 + goto matched;
53125 +
53126 + c = *p++;
53127 + }
53128 + }
53129 +
53130 + if (c == ']')
53131 + break;
53132 + }
53133 + if (!not)
53134 + return 1;
53135 + break;
53136 + matched:
53137 + while (c != ']') {
53138 + if (c == '\0')
53139 + return 1;
53140 +
53141 + c = *p++;
53142 + }
53143 + if (not)
53144 + return 1;
53145 + }
53146 + break;
53147 + default:
53148 + if (c != *n)
53149 + return 1;
53150 + }
53151 +
53152 + ++n;
53153 + }
53154 +
53155 + if (*n == '\0')
53156 + return 0;
53157 +
53158 + if (*n == '/')
53159 + return 0;
53160 +
53161 + return 1;
53162 +}
53163 +
53164 +static struct acl_object_label *
53165 +chk_glob_label(struct acl_object_label *globbed,
53166 + struct dentry *dentry, struct vfsmount *mnt, char **path)
53167 +{
53168 + struct acl_object_label *tmp;
53169 +
53170 + if (*path == NULL)
53171 + *path = gr_to_filename_nolock(dentry, mnt);
53172 +
53173 + tmp = globbed;
53174 +
53175 + while (tmp) {
53176 + if (!glob_match(tmp->filename, *path))
53177 + return tmp;
53178 + tmp = tmp->next;
53179 + }
53180 +
53181 + return NULL;
53182 +}
53183 +
53184 +static struct acl_object_label *
53185 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53186 + const ino_t curr_ino, const dev_t curr_dev,
53187 + const struct acl_subject_label *subj, char **path, const int checkglob)
53188 +{
53189 + struct acl_subject_label *tmpsubj;
53190 + struct acl_object_label *retval;
53191 + struct acl_object_label *retval2;
53192 +
53193 + tmpsubj = (struct acl_subject_label *) subj;
53194 + read_lock(&gr_inode_lock);
53195 + do {
53196 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53197 + if (retval) {
53198 + if (checkglob && retval->globbed) {
53199 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
53200 + (struct vfsmount *)orig_mnt, path);
53201 + if (retval2)
53202 + retval = retval2;
53203 + }
53204 + break;
53205 + }
53206 + } while ((tmpsubj = tmpsubj->parent_subject));
53207 + read_unlock(&gr_inode_lock);
53208 +
53209 + return retval;
53210 +}
53211 +
53212 +static __inline__ struct acl_object_label *
53213 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53214 + struct dentry *curr_dentry,
53215 + const struct acl_subject_label *subj, char **path, const int checkglob)
53216 +{
53217 + int newglob = checkglob;
53218 + ino_t inode;
53219 + dev_t device;
53220 +
53221 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53222 + as we don't want a / * rule to match instead of the / object
53223 + don't do this for create lookups that call this function though, since they're looking up
53224 + on the parent and thus need globbing checks on all paths
53225 + */
53226 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53227 + newglob = GR_NO_GLOB;
53228 +
53229 + spin_lock(&curr_dentry->d_lock);
53230 + inode = curr_dentry->d_inode->i_ino;
53231 + device = __get_dev(curr_dentry);
53232 + spin_unlock(&curr_dentry->d_lock);
53233 +
53234 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53235 +}
53236 +
53237 +static struct acl_object_label *
53238 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53239 + const struct acl_subject_label *subj, char *path, const int checkglob)
53240 +{
53241 + struct dentry *dentry = (struct dentry *) l_dentry;
53242 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53243 + struct acl_object_label *retval;
53244 + struct dentry *parent;
53245 +
53246 + write_seqlock(&rename_lock);
53247 + br_read_lock(vfsmount_lock);
53248 +
53249 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53250 +#ifdef CONFIG_NET
53251 + mnt == sock_mnt ||
53252 +#endif
53253 +#ifdef CONFIG_HUGETLBFS
53254 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53255 +#endif
53256 + /* ignore Eric Biederman */
53257 + IS_PRIVATE(l_dentry->d_inode))) {
53258 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53259 + goto out;
53260 + }
53261 +
53262 + for (;;) {
53263 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53264 + break;
53265 +
53266 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53267 + if (mnt->mnt_parent == mnt)
53268 + break;
53269 +
53270 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53271 + if (retval != NULL)
53272 + goto out;
53273 +
53274 + dentry = mnt->mnt_mountpoint;
53275 + mnt = mnt->mnt_parent;
53276 + continue;
53277 + }
53278 +
53279 + parent = dentry->d_parent;
53280 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53281 + if (retval != NULL)
53282 + goto out;
53283 +
53284 + dentry = parent;
53285 + }
53286 +
53287 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53288 +
53289 + /* real_root is pinned so we don't have to hold a reference */
53290 + if (retval == NULL)
53291 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53292 +out:
53293 + br_read_unlock(vfsmount_lock);
53294 + write_sequnlock(&rename_lock);
53295 +
53296 + BUG_ON(retval == NULL);
53297 +
53298 + return retval;
53299 +}
53300 +
53301 +static __inline__ struct acl_object_label *
53302 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53303 + const struct acl_subject_label *subj)
53304 +{
53305 + char *path = NULL;
53306 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53307 +}
53308 +
53309 +static __inline__ struct acl_object_label *
53310 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53311 + const struct acl_subject_label *subj)
53312 +{
53313 + char *path = NULL;
53314 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53315 +}
53316 +
53317 +static __inline__ struct acl_object_label *
53318 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53319 + const struct acl_subject_label *subj, char *path)
53320 +{
53321 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53322 +}
53323 +
53324 +static struct acl_subject_label *
53325 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53326 + const struct acl_role_label *role)
53327 +{
53328 + struct dentry *dentry = (struct dentry *) l_dentry;
53329 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53330 + struct acl_subject_label *retval;
53331 + struct dentry *parent;
53332 +
53333 + write_seqlock(&rename_lock);
53334 + br_read_lock(vfsmount_lock);
53335 +
53336 + for (;;) {
53337 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53338 + break;
53339 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53340 + if (mnt->mnt_parent == mnt)
53341 + break;
53342 +
53343 + spin_lock(&dentry->d_lock);
53344 + read_lock(&gr_inode_lock);
53345 + retval =
53346 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53347 + __get_dev(dentry), role);
53348 + read_unlock(&gr_inode_lock);
53349 + spin_unlock(&dentry->d_lock);
53350 + if (retval != NULL)
53351 + goto out;
53352 +
53353 + dentry = mnt->mnt_mountpoint;
53354 + mnt = mnt->mnt_parent;
53355 + continue;
53356 + }
53357 +
53358 + spin_lock(&dentry->d_lock);
53359 + read_lock(&gr_inode_lock);
53360 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53361 + __get_dev(dentry), role);
53362 + read_unlock(&gr_inode_lock);
53363 + parent = dentry->d_parent;
53364 + spin_unlock(&dentry->d_lock);
53365 +
53366 + if (retval != NULL)
53367 + goto out;
53368 +
53369 + dentry = parent;
53370 + }
53371 +
53372 + spin_lock(&dentry->d_lock);
53373 + read_lock(&gr_inode_lock);
53374 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53375 + __get_dev(dentry), role);
53376 + read_unlock(&gr_inode_lock);
53377 + spin_unlock(&dentry->d_lock);
53378 +
53379 + if (unlikely(retval == NULL)) {
53380 + /* real_root is pinned, we don't need to hold a reference */
53381 + read_lock(&gr_inode_lock);
53382 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53383 + __get_dev(real_root.dentry), role);
53384 + read_unlock(&gr_inode_lock);
53385 + }
53386 +out:
53387 + br_read_unlock(vfsmount_lock);
53388 + write_sequnlock(&rename_lock);
53389 +
53390 + BUG_ON(retval == NULL);
53391 +
53392 + return retval;
53393 +}
53394 +
53395 +static void
53396 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53397 +{
53398 + struct task_struct *task = current;
53399 + const struct cred *cred = current_cred();
53400 +
53401 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53402 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53403 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53404 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53405 +
53406 + return;
53407 +}
53408 +
53409 +static void
53410 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53411 +{
53412 + struct task_struct *task = current;
53413 + const struct cred *cred = current_cred();
53414 +
53415 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53416 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53417 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53418 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53419 +
53420 + return;
53421 +}
53422 +
53423 +static void
53424 +gr_log_learn_id_change(const char type, const unsigned int real,
53425 + const unsigned int effective, const unsigned int fs)
53426 +{
53427 + struct task_struct *task = current;
53428 + const struct cred *cred = current_cred();
53429 +
53430 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53431 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53432 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53433 + type, real, effective, fs, &task->signal->saved_ip);
53434 +
53435 + return;
53436 +}
53437 +
53438 +__u32
53439 +gr_check_link(const struct dentry * new_dentry,
53440 + const struct dentry * parent_dentry,
53441 + const struct vfsmount * parent_mnt,
53442 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53443 +{
53444 + struct acl_object_label *obj;
53445 + __u32 oldmode, newmode;
53446 + __u32 needmode;
53447 +
53448 + if (unlikely(!(gr_status & GR_READY)))
53449 + return (GR_CREATE | GR_LINK);
53450 +
53451 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53452 + oldmode = obj->mode;
53453 +
53454 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53455 + oldmode |= (GR_CREATE | GR_LINK);
53456 +
53457 + needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
53458 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53459 + needmode |= GR_SETID | GR_AUDIT_SETID;
53460 +
53461 + newmode =
53462 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
53463 + oldmode | needmode);
53464 +
53465 + needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
53466 + GR_SETID | GR_READ | GR_FIND | GR_DELETE |
53467 + GR_INHERIT | GR_AUDIT_INHERIT);
53468 +
53469 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
53470 + goto bad;
53471 +
53472 + if ((oldmode & needmode) != needmode)
53473 + goto bad;
53474 +
53475 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53476 + if ((newmode & needmode) != needmode)
53477 + goto bad;
53478 +
53479 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53480 + return newmode;
53481 +bad:
53482 + needmode = oldmode;
53483 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53484 + needmode |= GR_SETID;
53485 +
53486 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53487 + gr_log_learn(old_dentry, old_mnt, needmode);
53488 + return (GR_CREATE | GR_LINK);
53489 + } else if (newmode & GR_SUPPRESS)
53490 + return GR_SUPPRESS;
53491 + else
53492 + return 0;
53493 +}
53494 +
53495 +__u32
53496 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53497 + const struct vfsmount * mnt)
53498 +{
53499 + __u32 retval = mode;
53500 + struct acl_subject_label *curracl;
53501 + struct acl_object_label *currobj;
53502 +
53503 + if (unlikely(!(gr_status & GR_READY)))
53504 + return (mode & ~GR_AUDITS);
53505 +
53506 + curracl = current->acl;
53507 +
53508 + currobj = chk_obj_label(dentry, mnt, curracl);
53509 + retval = currobj->mode & mode;
53510 +
53511 + /* if we're opening a specified transfer file for writing
53512 + (e.g. /dev/initctl), then transfer our role to init
53513 + */
53514 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53515 + current->role->roletype & GR_ROLE_PERSIST)) {
53516 + struct task_struct *task = init_pid_ns.child_reaper;
53517 +
53518 + if (task->role != current->role) {
53519 + task->acl_sp_role = 0;
53520 + task->acl_role_id = current->acl_role_id;
53521 + task->role = current->role;
53522 + rcu_read_lock();
53523 + read_lock(&grsec_exec_file_lock);
53524 + gr_apply_subject_to_task(task);
53525 + read_unlock(&grsec_exec_file_lock);
53526 + rcu_read_unlock();
53527 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53528 + }
53529 + }
53530 +
53531 + if (unlikely
53532 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53533 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53534 + __u32 new_mode = mode;
53535 +
53536 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53537 +
53538 + retval = new_mode;
53539 +
53540 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53541 + new_mode |= GR_INHERIT;
53542 +
53543 + if (!(mode & GR_NOLEARN))
53544 + gr_log_learn(dentry, mnt, new_mode);
53545 + }
53546 +
53547 + return retval;
53548 +}
53549 +
53550 +__u32
53551 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53552 + const struct vfsmount * mnt, const __u32 mode)
53553 +{
53554 + struct name_entry *match;
53555 + struct acl_object_label *matchpo;
53556 + struct acl_subject_label *curracl;
53557 + char *path;
53558 + __u32 retval;
53559 +
53560 + if (unlikely(!(gr_status & GR_READY)))
53561 + return (mode & ~GR_AUDITS);
53562 +
53563 + preempt_disable();
53564 + path = gr_to_filename_rbac(new_dentry, mnt);
53565 + match = lookup_name_entry_create(path);
53566 +
53567 + if (!match)
53568 + goto check_parent;
53569 +
53570 + curracl = current->acl;
53571 +
53572 + read_lock(&gr_inode_lock);
53573 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53574 + read_unlock(&gr_inode_lock);
53575 +
53576 + if (matchpo) {
53577 + if ((matchpo->mode & mode) !=
53578 + (mode & ~(GR_AUDITS | GR_SUPPRESS))
53579 + && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53580 + __u32 new_mode = mode;
53581 +
53582 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53583 +
53584 + gr_log_learn(new_dentry, mnt, new_mode);
53585 +
53586 + preempt_enable();
53587 + return new_mode;
53588 + }
53589 + preempt_enable();
53590 + return (matchpo->mode & mode);
53591 + }
53592 +
53593 + check_parent:
53594 + curracl = current->acl;
53595 +
53596 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53597 + retval = matchpo->mode & mode;
53598 +
53599 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53600 + && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53601 + __u32 new_mode = mode;
53602 +
53603 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53604 +
53605 + gr_log_learn(new_dentry, mnt, new_mode);
53606 + preempt_enable();
53607 + return new_mode;
53608 + }
53609 +
53610 + preempt_enable();
53611 + return retval;
53612 +}
53613 +
53614 +int
53615 +gr_check_hidden_task(const struct task_struct *task)
53616 +{
53617 + if (unlikely(!(gr_status & GR_READY)))
53618 + return 0;
53619 +
53620 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53621 + return 1;
53622 +
53623 + return 0;
53624 +}
53625 +
53626 +int
53627 +gr_check_protected_task(const struct task_struct *task)
53628 +{
53629 + if (unlikely(!(gr_status & GR_READY) || !task))
53630 + return 0;
53631 +
53632 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53633 + task->acl != current->acl)
53634 + return 1;
53635 +
53636 + return 0;
53637 +}
53638 +
53639 +int
53640 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53641 +{
53642 + struct task_struct *p;
53643 + int ret = 0;
53644 +
53645 + if (unlikely(!(gr_status & GR_READY) || !pid))
53646 + return ret;
53647 +
53648 + read_lock(&tasklist_lock);
53649 + do_each_pid_task(pid, type, p) {
53650 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53651 + p->acl != current->acl) {
53652 + ret = 1;
53653 + goto out;
53654 + }
53655 + } while_each_pid_task(pid, type, p);
53656 +out:
53657 + read_unlock(&tasklist_lock);
53658 +
53659 + return ret;
53660 +}
53661 +
53662 +void
53663 +gr_copy_label(struct task_struct *tsk)
53664 +{
53665 + tsk->signal->used_accept = 0;
53666 + tsk->acl_sp_role = 0;
53667 + tsk->acl_role_id = current->acl_role_id;
53668 + tsk->acl = current->acl;
53669 + tsk->role = current->role;
53670 + tsk->signal->curr_ip = current->signal->curr_ip;
53671 + tsk->signal->saved_ip = current->signal->saved_ip;
53672 + if (current->exec_file)
53673 + get_file(current->exec_file);
53674 + tsk->exec_file = current->exec_file;
53675 + tsk->is_writable = current->is_writable;
53676 + if (unlikely(current->signal->used_accept)) {
53677 + current->signal->curr_ip = 0;
53678 + current->signal->saved_ip = 0;
53679 + }
53680 +
53681 + return;
53682 +}
53683 +
53684 +static void
53685 +gr_set_proc_res(struct task_struct *task)
53686 +{
53687 + struct acl_subject_label *proc;
53688 + unsigned short i;
53689 +
53690 + proc = task->acl;
53691 +
53692 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53693 + return;
53694 +
53695 + for (i = 0; i < RLIM_NLIMITS; i++) {
53696 + if (!(proc->resmask & (1 << i)))
53697 + continue;
53698 +
53699 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53700 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53701 + }
53702 +
53703 + return;
53704 +}
53705 +
53706 +extern int __gr_process_user_ban(struct user_struct *user);
53707 +
53708 +int
53709 +gr_check_user_change(int real, int effective, int fs)
53710 +{
53711 + unsigned int i;
53712 + __u16 num;
53713 + uid_t *uidlist;
53714 + int curuid;
53715 + int realok = 0;
53716 + int effectiveok = 0;
53717 + int fsok = 0;
53718 +
53719 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53720 + struct user_struct *user;
53721 +
53722 + if (real == -1)
53723 + goto skipit;
53724 +
53725 + user = find_user(real);
53726 + if (user == NULL)
53727 + goto skipit;
53728 +
53729 + if (__gr_process_user_ban(user)) {
53730 + /* for find_user */
53731 + free_uid(user);
53732 + return 1;
53733 + }
53734 +
53735 + /* for find_user */
53736 + free_uid(user);
53737 +
53738 +skipit:
53739 +#endif
53740 +
53741 + if (unlikely(!(gr_status & GR_READY)))
53742 + return 0;
53743 +
53744 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53745 + gr_log_learn_id_change('u', real, effective, fs);
53746 +
53747 + num = current->acl->user_trans_num;
53748 + uidlist = current->acl->user_transitions;
53749 +
53750 + if (uidlist == NULL)
53751 + return 0;
53752 +
53753 + if (real == -1)
53754 + realok = 1;
53755 + if (effective == -1)
53756 + effectiveok = 1;
53757 + if (fs == -1)
53758 + fsok = 1;
53759 +
53760 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53761 + for (i = 0; i < num; i++) {
53762 + curuid = (int)uidlist[i];
53763 + if (real == curuid)
53764 + realok = 1;
53765 + if (effective == curuid)
53766 + effectiveok = 1;
53767 + if (fs == curuid)
53768 + fsok = 1;
53769 + }
53770 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53771 + for (i = 0; i < num; i++) {
53772 + curuid = (int)uidlist[i];
53773 + if (real == curuid)
53774 + break;
53775 + if (effective == curuid)
53776 + break;
53777 + if (fs == curuid)
53778 + break;
53779 + }
53780 + /* not in deny list */
53781 + if (i == num) {
53782 + realok = 1;
53783 + effectiveok = 1;
53784 + fsok = 1;
53785 + }
53786 + }
53787 +
53788 + if (realok && effectiveok && fsok)
53789 + return 0;
53790 + else {
53791 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53792 + return 1;
53793 + }
53794 +}
53795 +
53796 +int
53797 +gr_check_group_change(int real, int effective, int fs)
53798 +{
53799 + unsigned int i;
53800 + __u16 num;
53801 + gid_t *gidlist;
53802 + int curgid;
53803 + int realok = 0;
53804 + int effectiveok = 0;
53805 + int fsok = 0;
53806 +
53807 + if (unlikely(!(gr_status & GR_READY)))
53808 + return 0;
53809 +
53810 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53811 + gr_log_learn_id_change('g', real, effective, fs);
53812 +
53813 + num = current->acl->group_trans_num;
53814 + gidlist = current->acl->group_transitions;
53815 +
53816 + if (gidlist == NULL)
53817 + return 0;
53818 +
53819 + if (real == -1)
53820 + realok = 1;
53821 + if (effective == -1)
53822 + effectiveok = 1;
53823 + if (fs == -1)
53824 + fsok = 1;
53825 +
53826 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53827 + for (i = 0; i < num; i++) {
53828 + curgid = (int)gidlist[i];
53829 + if (real == curgid)
53830 + realok = 1;
53831 + if (effective == curgid)
53832 + effectiveok = 1;
53833 + if (fs == curgid)
53834 + fsok = 1;
53835 + }
53836 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53837 + for (i = 0; i < num; i++) {
53838 + curgid = (int)gidlist[i];
53839 + if (real == curgid)
53840 + break;
53841 + if (effective == curgid)
53842 + break;
53843 + if (fs == curgid)
53844 + break;
53845 + }
53846 + /* not in deny list */
53847 + if (i == num) {
53848 + realok = 1;
53849 + effectiveok = 1;
53850 + fsok = 1;
53851 + }
53852 + }
53853 +
53854 + if (realok && effectiveok && fsok)
53855 + return 0;
53856 + else {
53857 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53858 + return 1;
53859 + }
53860 +}
53861 +
53862 +void
53863 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53864 +{
53865 + struct acl_role_label *role = task->role;
53866 + struct acl_subject_label *subj = NULL;
53867 + struct acl_object_label *obj;
53868 + struct file *filp;
53869 +
53870 + if (unlikely(!(gr_status & GR_READY)))
53871 + return;
53872 +
53873 + filp = task->exec_file;
53874 +
53875 + /* kernel process, we'll give them the kernel role */
53876 + if (unlikely(!filp)) {
53877 + task->role = kernel_role;
53878 + task->acl = kernel_role->root_label;
53879 + return;
53880 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53881 + role = lookup_acl_role_label(task, uid, gid);
53882 +
53883 + /* perform subject lookup in possibly new role
53884 + we can use this result below in the case where role == task->role
53885 + */
53886 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53887 +
53888 + /* if we changed uid/gid, but result in the same role
53889 + and are using inheritance, don't lose the inherited subject
53890 + if current subject is other than what normal lookup
53891 + would result in, we arrived via inheritance, don't
53892 + lose subject
53893 + */
53894 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53895 + (subj == task->acl)))
53896 + task->acl = subj;
53897 +
53898 + task->role = role;
53899 +
53900 + task->is_writable = 0;
53901 +
53902 + /* ignore additional mmap checks for processes that are writable
53903 + by the default ACL */
53904 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53905 + if (unlikely(obj->mode & GR_WRITE))
53906 + task->is_writable = 1;
53907 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53908 + if (unlikely(obj->mode & GR_WRITE))
53909 + task->is_writable = 1;
53910 +
53911 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53912 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53913 +#endif
53914 +
53915 + gr_set_proc_res(task);
53916 +
53917 + return;
53918 +}
53919 +
53920 +int
53921 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53922 + const int unsafe_share)
53923 +{
53924 + struct task_struct *task = current;
53925 + struct acl_subject_label *newacl;
53926 + struct acl_object_label *obj;
53927 + __u32 retmode;
53928 +
53929 + if (unlikely(!(gr_status & GR_READY)))
53930 + return 0;
53931 +
53932 + newacl = chk_subj_label(dentry, mnt, task->role);
53933 +
53934 + task_lock(task);
53935 + if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
53936 + !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53937 + !(task->role->roletype & GR_ROLE_GOD) &&
53938 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53939 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
53940 + task_unlock(task);
53941 + if (unsafe_share)
53942 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53943 + else
53944 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53945 + return -EACCES;
53946 + }
53947 + task_unlock(task);
53948 +
53949 + obj = chk_obj_label(dentry, mnt, task->acl);
53950 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53951 +
53952 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53953 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53954 + if (obj->nested)
53955 + task->acl = obj->nested;
53956 + else
53957 + task->acl = newacl;
53958 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53959 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53960 +
53961 + task->is_writable = 0;
53962 +
53963 + /* ignore additional mmap checks for processes that are writable
53964 + by the default ACL */
53965 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53966 + if (unlikely(obj->mode & GR_WRITE))
53967 + task->is_writable = 1;
53968 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53969 + if (unlikely(obj->mode & GR_WRITE))
53970 + task->is_writable = 1;
53971 +
53972 + gr_set_proc_res(task);
53973 +
53974 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53975 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53976 +#endif
53977 + return 0;
53978 +}
53979 +
53980 +/* always called with valid inodev ptr */
53981 +static void
53982 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53983 +{
53984 + struct acl_object_label *matchpo;
53985 + struct acl_subject_label *matchps;
53986 + struct acl_subject_label *subj;
53987 + struct acl_role_label *role;
53988 + unsigned int x;
53989 +
53990 + FOR_EACH_ROLE_START(role)
53991 + FOR_EACH_SUBJECT_START(role, subj, x)
53992 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53993 + matchpo->mode |= GR_DELETED;
53994 + FOR_EACH_SUBJECT_END(subj,x)
53995 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53996 + if (subj->inode == ino && subj->device == dev)
53997 + subj->mode |= GR_DELETED;
53998 + FOR_EACH_NESTED_SUBJECT_END(subj)
53999 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54000 + matchps->mode |= GR_DELETED;
54001 + FOR_EACH_ROLE_END(role)
54002 +
54003 + inodev->nentry->deleted = 1;
54004 +
54005 + return;
54006 +}
54007 +
54008 +void
54009 +gr_handle_delete(const ino_t ino, const dev_t dev)
54010 +{
54011 + struct inodev_entry *inodev;
54012 +
54013 + if (unlikely(!(gr_status & GR_READY)))
54014 + return;
54015 +
54016 + write_lock(&gr_inode_lock);
54017 + inodev = lookup_inodev_entry(ino, dev);
54018 + if (inodev != NULL)
54019 + do_handle_delete(inodev, ino, dev);
54020 + write_unlock(&gr_inode_lock);
54021 +
54022 + return;
54023 +}
54024 +
54025 +static void
54026 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54027 + const ino_t newinode, const dev_t newdevice,
54028 + struct acl_subject_label *subj)
54029 +{
54030 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54031 + struct acl_object_label *match;
54032 +
54033 + match = subj->obj_hash[index];
54034 +
54035 + while (match && (match->inode != oldinode ||
54036 + match->device != olddevice ||
54037 + !(match->mode & GR_DELETED)))
54038 + match = match->next;
54039 +
54040 + if (match && (match->inode == oldinode)
54041 + && (match->device == olddevice)
54042 + && (match->mode & GR_DELETED)) {
54043 + if (match->prev == NULL) {
54044 + subj->obj_hash[index] = match->next;
54045 + if (match->next != NULL)
54046 + match->next->prev = NULL;
54047 + } else {
54048 + match->prev->next = match->next;
54049 + if (match->next != NULL)
54050 + match->next->prev = match->prev;
54051 + }
54052 + match->prev = NULL;
54053 + match->next = NULL;
54054 + match->inode = newinode;
54055 + match->device = newdevice;
54056 + match->mode &= ~GR_DELETED;
54057 +
54058 + insert_acl_obj_label(match, subj);
54059 + }
54060 +
54061 + return;
54062 +}
54063 +
54064 +static void
54065 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54066 + const ino_t newinode, const dev_t newdevice,
54067 + struct acl_role_label *role)
54068 +{
54069 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54070 + struct acl_subject_label *match;
54071 +
54072 + match = role->subj_hash[index];
54073 +
54074 + while (match && (match->inode != oldinode ||
54075 + match->device != olddevice ||
54076 + !(match->mode & GR_DELETED)))
54077 + match = match->next;
54078 +
54079 + if (match && (match->inode == oldinode)
54080 + && (match->device == olddevice)
54081 + && (match->mode & GR_DELETED)) {
54082 + if (match->prev == NULL) {
54083 + role->subj_hash[index] = match->next;
54084 + if (match->next != NULL)
54085 + match->next->prev = NULL;
54086 + } else {
54087 + match->prev->next = match->next;
54088 + if (match->next != NULL)
54089 + match->next->prev = match->prev;
54090 + }
54091 + match->prev = NULL;
54092 + match->next = NULL;
54093 + match->inode = newinode;
54094 + match->device = newdevice;
54095 + match->mode &= ~GR_DELETED;
54096 +
54097 + insert_acl_subj_label(match, role);
54098 + }
54099 +
54100 + return;
54101 +}
54102 +
54103 +static void
54104 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54105 + const ino_t newinode, const dev_t newdevice)
54106 +{
54107 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54108 + struct inodev_entry *match;
54109 +
54110 + match = inodev_set.i_hash[index];
54111 +
54112 + while (match && (match->nentry->inode != oldinode ||
54113 + match->nentry->device != olddevice || !match->nentry->deleted))
54114 + match = match->next;
54115 +
54116 + if (match && (match->nentry->inode == oldinode)
54117 + && (match->nentry->device == olddevice) &&
54118 + match->nentry->deleted) {
54119 + if (match->prev == NULL) {
54120 + inodev_set.i_hash[index] = match->next;
54121 + if (match->next != NULL)
54122 + match->next->prev = NULL;
54123 + } else {
54124 + match->prev->next = match->next;
54125 + if (match->next != NULL)
54126 + match->next->prev = match->prev;
54127 + }
54128 + match->prev = NULL;
54129 + match->next = NULL;
54130 + match->nentry->inode = newinode;
54131 + match->nentry->device = newdevice;
54132 + match->nentry->deleted = 0;
54133 +
54134 + insert_inodev_entry(match);
54135 + }
54136 +
54137 + return;
54138 +}
54139 +
54140 +static void
54141 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54142 + const struct vfsmount *mnt)
54143 +{
54144 + struct acl_subject_label *subj;
54145 + struct acl_role_label *role;
54146 + unsigned int x;
54147 + ino_t ino = dentry->d_inode->i_ino;
54148 + dev_t dev = __get_dev(dentry);
54149 +
54150 + FOR_EACH_ROLE_START(role)
54151 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54152 +
54153 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54154 + if ((subj->inode == ino) && (subj->device == dev)) {
54155 + subj->inode = ino;
54156 + subj->device = dev;
54157 + }
54158 + FOR_EACH_NESTED_SUBJECT_END(subj)
54159 + FOR_EACH_SUBJECT_START(role, subj, x)
54160 + update_acl_obj_label(matchn->inode, matchn->device,
54161 + ino, dev, subj);
54162 + FOR_EACH_SUBJECT_END(subj,x)
54163 + FOR_EACH_ROLE_END(role)
54164 +
54165 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54166 +
54167 + return;
54168 +}
54169 +
54170 +void
54171 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54172 +{
54173 + struct name_entry *matchn;
54174 +
54175 + if (unlikely(!(gr_status & GR_READY)))
54176 + return;
54177 +
54178 + preempt_disable();
54179 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54180 +
54181 + if (unlikely((unsigned long)matchn)) {
54182 + write_lock(&gr_inode_lock);
54183 + do_handle_create(matchn, dentry, mnt);
54184 + write_unlock(&gr_inode_lock);
54185 + }
54186 + preempt_enable();
54187 +
54188 + return;
54189 +}
54190 +
54191 +void
54192 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54193 + struct dentry *old_dentry,
54194 + struct dentry *new_dentry,
54195 + struct vfsmount *mnt, const __u8 replace)
54196 +{
54197 + struct name_entry *matchn;
54198 + struct inodev_entry *inodev;
54199 + ino_t old_ino = old_dentry->d_inode->i_ino;
54200 + dev_t old_dev = __get_dev(old_dentry);
54201 +
54202 + /* vfs_rename swaps the name and parent link for old_dentry and
54203 + new_dentry
54204 + at this point, old_dentry has the new name, parent link, and inode
54205 + for the renamed file
54206 + if a file is being replaced by a rename, new_dentry has the inode
54207 + and name for the replaced file
54208 + */
54209 +
54210 + if (unlikely(!(gr_status & GR_READY)))
54211 + return;
54212 +
54213 + preempt_disable();
54214 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54215 +
54216 + /* we wouldn't have to check d_inode if it weren't for
54217 + NFS silly-renaming
54218 + */
54219 +
54220 + write_lock(&gr_inode_lock);
54221 + if (unlikely(replace && new_dentry->d_inode)) {
54222 + ino_t new_ino = new_dentry->d_inode->i_ino;
54223 + dev_t new_dev = __get_dev(new_dentry);
54224 +
54225 + inodev = lookup_inodev_entry(new_ino, new_dev);
54226 + if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
54227 + do_handle_delete(inodev, new_ino, new_dev);
54228 + }
54229 +
54230 + inodev = lookup_inodev_entry(old_ino, old_dev);
54231 + if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
54232 + do_handle_delete(inodev, old_ino, old_dev);
54233 +
54234 + if (unlikely((unsigned long)matchn))
54235 + do_handle_create(matchn, old_dentry, mnt);
54236 +
54237 + write_unlock(&gr_inode_lock);
54238 + preempt_enable();
54239 +
54240 + return;
54241 +}
54242 +
54243 +static int
54244 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54245 + unsigned char **sum)
54246 +{
54247 + struct acl_role_label *r;
54248 + struct role_allowed_ip *ipp;
54249 + struct role_transition *trans;
54250 + unsigned int i;
54251 + int found = 0;
54252 + u32 curr_ip = current->signal->curr_ip;
54253 +
54254 + current->signal->saved_ip = curr_ip;
54255 +
54256 + /* check transition table */
54257 +
54258 + for (trans = current->role->transitions; trans; trans = trans->next) {
54259 + if (!strcmp(rolename, trans->rolename)) {
54260 + found = 1;
54261 + break;
54262 + }
54263 + }
54264 +
54265 + if (!found)
54266 + return 0;
54267 +
54268 + /* handle special roles that do not require authentication
54269 + and check ip */
54270 +
54271 + FOR_EACH_ROLE_START(r)
54272 + if (!strcmp(rolename, r->rolename) &&
54273 + (r->roletype & GR_ROLE_SPECIAL)) {
54274 + found = 0;
54275 + if (r->allowed_ips != NULL) {
54276 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54277 + if ((ntohl(curr_ip) & ipp->netmask) ==
54278 + (ntohl(ipp->addr) & ipp->netmask))
54279 + found = 1;
54280 + }
54281 + } else
54282 + found = 2;
54283 + if (!found)
54284 + return 0;
54285 +
54286 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54287 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54288 + *salt = NULL;
54289 + *sum = NULL;
54290 + return 1;
54291 + }
54292 + }
54293 + FOR_EACH_ROLE_END(r)
54294 +
54295 + for (i = 0; i < num_sprole_pws; i++) {
54296 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54297 + *salt = acl_special_roles[i]->salt;
54298 + *sum = acl_special_roles[i]->sum;
54299 + return 1;
54300 + }
54301 + }
54302 +
54303 + return 0;
54304 +}
54305 +
54306 +static void
54307 +assign_special_role(char *rolename)
54308 +{
54309 + struct acl_object_label *obj;
54310 + struct acl_role_label *r;
54311 + struct acl_role_label *assigned = NULL;
54312 + struct task_struct *tsk;
54313 + struct file *filp;
54314 +
54315 + FOR_EACH_ROLE_START(r)
54316 + if (!strcmp(rolename, r->rolename) &&
54317 + (r->roletype & GR_ROLE_SPECIAL)) {
54318 + assigned = r;
54319 + break;
54320 + }
54321 + FOR_EACH_ROLE_END(r)
54322 +
54323 + if (!assigned)
54324 + return;
54325 +
54326 + read_lock(&tasklist_lock);
54327 + read_lock(&grsec_exec_file_lock);
54328 +
54329 + tsk = current->real_parent;
54330 + if (tsk == NULL)
54331 + goto out_unlock;
54332 +
54333 + filp = tsk->exec_file;
54334 + if (filp == NULL)
54335 + goto out_unlock;
54336 +
54337 + tsk->is_writable = 0;
54338 +
54339 + tsk->acl_sp_role = 1;
54340 + tsk->acl_role_id = ++acl_sp_role_value;
54341 + tsk->role = assigned;
54342 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54343 +
54344 + /* ignore additional mmap checks for processes that are writable
54345 + by the default ACL */
54346 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54347 + if (unlikely(obj->mode & GR_WRITE))
54348 + tsk->is_writable = 1;
54349 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54350 + if (unlikely(obj->mode & GR_WRITE))
54351 + tsk->is_writable = 1;
54352 +
54353 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54354 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54355 +#endif
54356 +
54357 +out_unlock:
54358 + read_unlock(&grsec_exec_file_lock);
54359 + read_unlock(&tasklist_lock);
54360 + return;
54361 +}
54362 +
54363 +int gr_check_secure_terminal(struct task_struct *task)
54364 +{
54365 + struct task_struct *p, *p2, *p3;
54366 + struct files_struct *files;
54367 + struct fdtable *fdt;
54368 + struct file *our_file = NULL, *file;
54369 + int i;
54370 +
54371 + if (task->signal->tty == NULL)
54372 + return 1;
54373 +
54374 + files = get_files_struct(task);
54375 + if (files != NULL) {
54376 + rcu_read_lock();
54377 + fdt = files_fdtable(files);
54378 + for (i=0; i < fdt->max_fds; i++) {
54379 + file = fcheck_files(files, i);
54380 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54381 + get_file(file);
54382 + our_file = file;
54383 + }
54384 + }
54385 + rcu_read_unlock();
54386 + put_files_struct(files);
54387 + }
54388 +
54389 + if (our_file == NULL)
54390 + return 1;
54391 +
54392 + read_lock(&tasklist_lock);
54393 + do_each_thread(p2, p) {
54394 + files = get_files_struct(p);
54395 + if (files == NULL ||
54396 + (p->signal && p->signal->tty == task->signal->tty)) {
54397 + if (files != NULL)
54398 + put_files_struct(files);
54399 + continue;
54400 + }
54401 + rcu_read_lock();
54402 + fdt = files_fdtable(files);
54403 + for (i=0; i < fdt->max_fds; i++) {
54404 + file = fcheck_files(files, i);
54405 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54406 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54407 + p3 = task;
54408 + while (p3->pid > 0) {
54409 + if (p3 == p)
54410 + break;
54411 + p3 = p3->real_parent;
54412 + }
54413 + if (p3 == p)
54414 + break;
54415 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54416 + gr_handle_alertkill(p);
54417 + rcu_read_unlock();
54418 + put_files_struct(files);
54419 + read_unlock(&tasklist_lock);
54420 + fput(our_file);
54421 + return 0;
54422 + }
54423 + }
54424 + rcu_read_unlock();
54425 + put_files_struct(files);
54426 + } while_each_thread(p2, p);
54427 + read_unlock(&tasklist_lock);
54428 +
54429 + fput(our_file);
54430 + return 1;
54431 +}
54432 +
54433 +ssize_t
54434 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54435 +{
54436 + struct gr_arg_wrapper uwrap;
54437 + unsigned char *sprole_salt = NULL;
54438 + unsigned char *sprole_sum = NULL;
54439 + int error = sizeof (struct gr_arg_wrapper);
54440 + int error2 = 0;
54441 +
54442 + mutex_lock(&gr_dev_mutex);
54443 +
54444 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54445 + error = -EPERM;
54446 + goto out;
54447 + }
54448 +
54449 + if (count != sizeof (struct gr_arg_wrapper)) {
54450 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54451 + error = -EINVAL;
54452 + goto out;
54453 + }
54454 +
54455 +
54456 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54457 + gr_auth_expires = 0;
54458 + gr_auth_attempts = 0;
54459 + }
54460 +
54461 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54462 + error = -EFAULT;
54463 + goto out;
54464 + }
54465 +
54466 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54467 + error = -EINVAL;
54468 + goto out;
54469 + }
54470 +
54471 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54472 + error = -EFAULT;
54473 + goto out;
54474 + }
54475 +
54476 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54477 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54478 + time_after(gr_auth_expires, get_seconds())) {
54479 + error = -EBUSY;
54480 + goto out;
54481 + }
54482 +
54483 + /* if non-root trying to do anything other than use a special role,
54484 + do not attempt authentication, do not count towards authentication
54485 + locking
54486 + */
54487 +
54488 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54489 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54490 + current_uid()) {
54491 + error = -EPERM;
54492 + goto out;
54493 + }
54494 +
54495 + /* ensure pw and special role name are null terminated */
54496 +
54497 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54498 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54499 +
54500 + /* Okay.
54501 + * We have our enough of the argument structure..(we have yet
54502 + * to copy_from_user the tables themselves) . Copy the tables
54503 + * only if we need them, i.e. for loading operations. */
54504 +
54505 + switch (gr_usermode->mode) {
54506 + case GR_STATUS:
54507 + if (gr_status & GR_READY) {
54508 + error = 1;
54509 + if (!gr_check_secure_terminal(current))
54510 + error = 3;
54511 + } else
54512 + error = 2;
54513 + goto out;
54514 + case GR_SHUTDOWN:
54515 + if ((gr_status & GR_READY)
54516 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54517 + pax_open_kernel();
54518 + gr_status &= ~GR_READY;
54519 + pax_close_kernel();
54520 +
54521 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54522 + free_variables();
54523 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54524 + memset(gr_system_salt, 0, GR_SALT_LEN);
54525 + memset(gr_system_sum, 0, GR_SHA_LEN);
54526 + } else if (gr_status & GR_READY) {
54527 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54528 + error = -EPERM;
54529 + } else {
54530 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54531 + error = -EAGAIN;
54532 + }
54533 + break;
54534 + case GR_ENABLE:
54535 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54536 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54537 + else {
54538 + if (gr_status & GR_READY)
54539 + error = -EAGAIN;
54540 + else
54541 + error = error2;
54542 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54543 + }
54544 + break;
54545 + case GR_RELOAD:
54546 + if (!(gr_status & GR_READY)) {
54547 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54548 + error = -EAGAIN;
54549 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54550 + preempt_disable();
54551 +
54552 + pax_open_kernel();
54553 + gr_status &= ~GR_READY;
54554 + pax_close_kernel();
54555 +
54556 + free_variables();
54557 + if (!(error2 = gracl_init(gr_usermode))) {
54558 + preempt_enable();
54559 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54560 + } else {
54561 + preempt_enable();
54562 + error = error2;
54563 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54564 + }
54565 + } else {
54566 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54567 + error = -EPERM;
54568 + }
54569 + break;
54570 + case GR_SEGVMOD:
54571 + if (unlikely(!(gr_status & GR_READY))) {
54572 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54573 + error = -EAGAIN;
54574 + break;
54575 + }
54576 +
54577 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54578 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54579 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54580 + struct acl_subject_label *segvacl;
54581 + segvacl =
54582 + lookup_acl_subj_label(gr_usermode->segv_inode,
54583 + gr_usermode->segv_device,
54584 + current->role);
54585 + if (segvacl) {
54586 + segvacl->crashes = 0;
54587 + segvacl->expires = 0;
54588 + }
54589 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54590 + gr_remove_uid(gr_usermode->segv_uid);
54591 + }
54592 + } else {
54593 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54594 + error = -EPERM;
54595 + }
54596 + break;
54597 + case GR_SPROLE:
54598 + case GR_SPROLEPAM:
54599 + if (unlikely(!(gr_status & GR_READY))) {
54600 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54601 + error = -EAGAIN;
54602 + break;
54603 + }
54604 +
54605 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54606 + current->role->expires = 0;
54607 + current->role->auth_attempts = 0;
54608 + }
54609 +
54610 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54611 + time_after(current->role->expires, get_seconds())) {
54612 + error = -EBUSY;
54613 + goto out;
54614 + }
54615 +
54616 + if (lookup_special_role_auth
54617 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54618 + && ((!sprole_salt && !sprole_sum)
54619 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54620 + char *p = "";
54621 + assign_special_role(gr_usermode->sp_role);
54622 + read_lock(&tasklist_lock);
54623 + if (current->real_parent)
54624 + p = current->real_parent->role->rolename;
54625 + read_unlock(&tasklist_lock);
54626 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54627 + p, acl_sp_role_value);
54628 + } else {
54629 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54630 + error = -EPERM;
54631 + if(!(current->role->auth_attempts++))
54632 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54633 +
54634 + goto out;
54635 + }
54636 + break;
54637 + case GR_UNSPROLE:
54638 + if (unlikely(!(gr_status & GR_READY))) {
54639 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54640 + error = -EAGAIN;
54641 + break;
54642 + }
54643 +
54644 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54645 + char *p = "";
54646 + int i = 0;
54647 +
54648 + read_lock(&tasklist_lock);
54649 + if (current->real_parent) {
54650 + p = current->real_parent->role->rolename;
54651 + i = current->real_parent->acl_role_id;
54652 + }
54653 + read_unlock(&tasklist_lock);
54654 +
54655 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54656 + gr_set_acls(1);
54657 + } else {
54658 + error = -EPERM;
54659 + goto out;
54660 + }
54661 + break;
54662 + default:
54663 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54664 + error = -EINVAL;
54665 + break;
54666 + }
54667 +
54668 + if (error != -EPERM)
54669 + goto out;
54670 +
54671 + if(!(gr_auth_attempts++))
54672 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54673 +
54674 + out:
54675 + mutex_unlock(&gr_dev_mutex);
54676 + return error;
54677 +}
54678 +
54679 +/* must be called with
54680 + rcu_read_lock();
54681 + read_lock(&tasklist_lock);
54682 + read_lock(&grsec_exec_file_lock);
54683 +*/
54684 +int gr_apply_subject_to_task(struct task_struct *task)
54685 +{
54686 + struct acl_object_label *obj;
54687 + char *tmpname;
54688 + struct acl_subject_label *tmpsubj;
54689 + struct file *filp;
54690 + struct name_entry *nmatch;
54691 +
54692 + filp = task->exec_file;
54693 + if (filp == NULL)
54694 + return 0;
54695 +
54696 + /* the following is to apply the correct subject
54697 + on binaries running when the RBAC system
54698 + is enabled, when the binaries have been
54699 + replaced or deleted since their execution
54700 + -----
54701 + when the RBAC system starts, the inode/dev
54702 + from exec_file will be one the RBAC system
54703 + is unaware of. It only knows the inode/dev
54704 + of the present file on disk, or the absence
54705 + of it.
54706 + */
54707 + preempt_disable();
54708 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54709 +
54710 + nmatch = lookup_name_entry(tmpname);
54711 + preempt_enable();
54712 + tmpsubj = NULL;
54713 + if (nmatch) {
54714 + if (nmatch->deleted)
54715 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54716 + else
54717 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54718 + if (tmpsubj != NULL)
54719 + task->acl = tmpsubj;
54720 + }
54721 + if (tmpsubj == NULL)
54722 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54723 + task->role);
54724 + if (task->acl) {
54725 + struct acl_subject_label *curr;
54726 + curr = task->acl;
54727 +
54728 + task->is_writable = 0;
54729 + /* ignore additional mmap checks for processes that are writable
54730 + by the default ACL */
54731 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54732 + if (unlikely(obj->mode & GR_WRITE))
54733 + task->is_writable = 1;
54734 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54735 + if (unlikely(obj->mode & GR_WRITE))
54736 + task->is_writable = 1;
54737 +
54738 + gr_set_proc_res(task);
54739 +
54740 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54741 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54742 +#endif
54743 + } else {
54744 + return 1;
54745 + }
54746 +
54747 + return 0;
54748 +}
54749 +
54750 +int
54751 +gr_set_acls(const int type)
54752 +{
54753 + struct task_struct *task, *task2;
54754 + struct acl_role_label *role = current->role;
54755 + __u16 acl_role_id = current->acl_role_id;
54756 + const struct cred *cred;
54757 + int ret;
54758 +
54759 + rcu_read_lock();
54760 + read_lock(&tasklist_lock);
54761 + read_lock(&grsec_exec_file_lock);
54762 + do_each_thread(task2, task) {
54763 + /* check to see if we're called from the exit handler,
54764 + if so, only replace ACLs that have inherited the admin
54765 + ACL */
54766 +
54767 + if (type && (task->role != role ||
54768 + task->acl_role_id != acl_role_id))
54769 + continue;
54770 +
54771 + task->acl_role_id = 0;
54772 + task->acl_sp_role = 0;
54773 +
54774 + if (task->exec_file) {
54775 + cred = __task_cred(task);
54776 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54777 + ret = gr_apply_subject_to_task(task);
54778 + if (ret) {
54779 + read_unlock(&grsec_exec_file_lock);
54780 + read_unlock(&tasklist_lock);
54781 + rcu_read_unlock();
54782 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54783 + return ret;
54784 + }
54785 + } else {
54786 + // it's a kernel process
54787 + task->role = kernel_role;
54788 + task->acl = kernel_role->root_label;
54789 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54790 + task->acl->mode &= ~GR_PROCFIND;
54791 +#endif
54792 + }
54793 + } while_each_thread(task2, task);
54794 + read_unlock(&grsec_exec_file_lock);
54795 + read_unlock(&tasklist_lock);
54796 + rcu_read_unlock();
54797 +
54798 + return 0;
54799 +}
54800 +
54801 +void
54802 +gr_learn_resource(const struct task_struct *task,
54803 + const int res, const unsigned long wanted, const int gt)
54804 +{
54805 + struct acl_subject_label *acl;
54806 + const struct cred *cred;
54807 +
54808 + if (unlikely((gr_status & GR_READY) &&
54809 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54810 + goto skip_reslog;
54811 +
54812 +#ifdef CONFIG_GRKERNSEC_RESLOG
54813 + gr_log_resource(task, res, wanted, gt);
54814 +#endif
54815 + skip_reslog:
54816 +
54817 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54818 + return;
54819 +
54820 + acl = task->acl;
54821 +
54822 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54823 + !(acl->resmask & (1 << (unsigned short) res))))
54824 + return;
54825 +
54826 + if (wanted >= acl->res[res].rlim_cur) {
54827 + unsigned long res_add;
54828 +
54829 + res_add = wanted;
54830 + switch (res) {
54831 + case RLIMIT_CPU:
54832 + res_add += GR_RLIM_CPU_BUMP;
54833 + break;
54834 + case RLIMIT_FSIZE:
54835 + res_add += GR_RLIM_FSIZE_BUMP;
54836 + break;
54837 + case RLIMIT_DATA:
54838 + res_add += GR_RLIM_DATA_BUMP;
54839 + break;
54840 + case RLIMIT_STACK:
54841 + res_add += GR_RLIM_STACK_BUMP;
54842 + break;
54843 + case RLIMIT_CORE:
54844 + res_add += GR_RLIM_CORE_BUMP;
54845 + break;
54846 + case RLIMIT_RSS:
54847 + res_add += GR_RLIM_RSS_BUMP;
54848 + break;
54849 + case RLIMIT_NPROC:
54850 + res_add += GR_RLIM_NPROC_BUMP;
54851 + break;
54852 + case RLIMIT_NOFILE:
54853 + res_add += GR_RLIM_NOFILE_BUMP;
54854 + break;
54855 + case RLIMIT_MEMLOCK:
54856 + res_add += GR_RLIM_MEMLOCK_BUMP;
54857 + break;
54858 + case RLIMIT_AS:
54859 + res_add += GR_RLIM_AS_BUMP;
54860 + break;
54861 + case RLIMIT_LOCKS:
54862 + res_add += GR_RLIM_LOCKS_BUMP;
54863 + break;
54864 + case RLIMIT_SIGPENDING:
54865 + res_add += GR_RLIM_SIGPENDING_BUMP;
54866 + break;
54867 + case RLIMIT_MSGQUEUE:
54868 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54869 + break;
54870 + case RLIMIT_NICE:
54871 + res_add += GR_RLIM_NICE_BUMP;
54872 + break;
54873 + case RLIMIT_RTPRIO:
54874 + res_add += GR_RLIM_RTPRIO_BUMP;
54875 + break;
54876 + case RLIMIT_RTTIME:
54877 + res_add += GR_RLIM_RTTIME_BUMP;
54878 + break;
54879 + }
54880 +
54881 + acl->res[res].rlim_cur = res_add;
54882 +
54883 + if (wanted > acl->res[res].rlim_max)
54884 + acl->res[res].rlim_max = res_add;
54885 +
54886 + /* only log the subject filename, since resource logging is supported for
54887 + single-subject learning only */
54888 + rcu_read_lock();
54889 + cred = __task_cred(task);
54890 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54891 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54892 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54893 + "", (unsigned long) res, &task->signal->saved_ip);
54894 + rcu_read_unlock();
54895 + }
54896 +
54897 + return;
54898 +}
54899 +
54900 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54901 +void
54902 +pax_set_initial_flags(struct linux_binprm *bprm)
54903 +{
54904 + struct task_struct *task = current;
54905 + struct acl_subject_label *proc;
54906 + unsigned long flags;
54907 +
54908 + if (unlikely(!(gr_status & GR_READY)))
54909 + return;
54910 +
54911 + flags = pax_get_flags(task);
54912 +
54913 + proc = task->acl;
54914 +
54915 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54916 + flags &= ~MF_PAX_PAGEEXEC;
54917 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54918 + flags &= ~MF_PAX_SEGMEXEC;
54919 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54920 + flags &= ~MF_PAX_RANDMMAP;
54921 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54922 + flags &= ~MF_PAX_EMUTRAMP;
54923 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54924 + flags &= ~MF_PAX_MPROTECT;
54925 +
54926 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54927 + flags |= MF_PAX_PAGEEXEC;
54928 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54929 + flags |= MF_PAX_SEGMEXEC;
54930 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54931 + flags |= MF_PAX_RANDMMAP;
54932 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54933 + flags |= MF_PAX_EMUTRAMP;
54934 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54935 + flags |= MF_PAX_MPROTECT;
54936 +
54937 + pax_set_flags(task, flags);
54938 +
54939 + return;
54940 +}
54941 +#endif
54942 +
54943 +#ifdef CONFIG_SYSCTL
54944 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54945 + system to save 35kb of memory */
54946 +
54947 +/* we modify the passed in filename, but adjust it back before returning */
54948 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54949 +{
54950 + struct name_entry *nmatch;
54951 + char *p, *lastp = NULL;
54952 + struct acl_object_label *obj = NULL, *tmp;
54953 + struct acl_subject_label *tmpsubj;
54954 + char c = '\0';
54955 +
54956 + read_lock(&gr_inode_lock);
54957 +
54958 + p = name + len - 1;
54959 + do {
54960 + nmatch = lookup_name_entry(name);
54961 + if (lastp != NULL)
54962 + *lastp = c;
54963 +
54964 + if (nmatch == NULL)
54965 + goto next_component;
54966 + tmpsubj = current->acl;
54967 + do {
54968 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54969 + if (obj != NULL) {
54970 + tmp = obj->globbed;
54971 + while (tmp) {
54972 + if (!glob_match(tmp->filename, name)) {
54973 + obj = tmp;
54974 + goto found_obj;
54975 + }
54976 + tmp = tmp->next;
54977 + }
54978 + goto found_obj;
54979 + }
54980 + } while ((tmpsubj = tmpsubj->parent_subject));
54981 +next_component:
54982 + /* end case */
54983 + if (p == name)
54984 + break;
54985 +
54986 + while (*p != '/')
54987 + p--;
54988 + if (p == name)
54989 + lastp = p + 1;
54990 + else {
54991 + lastp = p;
54992 + p--;
54993 + }
54994 + c = *lastp;
54995 + *lastp = '\0';
54996 + } while (1);
54997 +found_obj:
54998 + read_unlock(&gr_inode_lock);
54999 + /* obj returned will always be non-null */
55000 + return obj;
55001 +}
55002 +
55003 +/* returns 0 when allowing, non-zero on error
55004 + op of 0 is used for readdir, so we don't log the names of hidden files
55005 +*/
55006 +__u32
55007 +gr_handle_sysctl(const struct ctl_table *table, const int op)
55008 +{
55009 + struct ctl_table *tmp;
55010 + const char *proc_sys = "/proc/sys";
55011 + char *path;
55012 + struct acl_object_label *obj;
55013 + unsigned short len = 0, pos = 0, depth = 0, i;
55014 + __u32 err = 0;
55015 + __u32 mode = 0;
55016 +
55017 + if (unlikely(!(gr_status & GR_READY)))
55018 + return 0;
55019 +
55020 + /* for now, ignore operations on non-sysctl entries if it's not a
55021 + readdir*/
55022 + if (table->child != NULL && op != 0)
55023 + return 0;
55024 +
55025 + mode |= GR_FIND;
55026 + /* it's only a read if it's an entry, read on dirs is for readdir */
55027 + if (op & MAY_READ)
55028 + mode |= GR_READ;
55029 + if (op & MAY_WRITE)
55030 + mode |= GR_WRITE;
55031 +
55032 + preempt_disable();
55033 +
55034 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55035 +
55036 + /* it's only a read/write if it's an actual entry, not a dir
55037 + (which are opened for readdir)
55038 + */
55039 +
55040 + /* convert the requested sysctl entry into a pathname */
55041 +
55042 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55043 + len += strlen(tmp->procname);
55044 + len++;
55045 + depth++;
55046 + }
55047 +
55048 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
55049 + /* deny */
55050 + goto out;
55051 + }
55052 +
55053 + memset(path, 0, PAGE_SIZE);
55054 +
55055 + memcpy(path, proc_sys, strlen(proc_sys));
55056 +
55057 + pos += strlen(proc_sys);
55058 +
55059 + for (; depth > 0; depth--) {
55060 + path[pos] = '/';
55061 + pos++;
55062 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55063 + if (depth == i) {
55064 + memcpy(path + pos, tmp->procname,
55065 + strlen(tmp->procname));
55066 + pos += strlen(tmp->procname);
55067 + }
55068 + i++;
55069 + }
55070 + }
55071 +
55072 + obj = gr_lookup_by_name(path, pos);
55073 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
55074 +
55075 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
55076 + ((err & mode) != mode))) {
55077 + __u32 new_mode = mode;
55078 +
55079 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55080 +
55081 + err = 0;
55082 + gr_log_learn_sysctl(path, new_mode);
55083 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
55084 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
55085 + err = -ENOENT;
55086 + } else if (!(err & GR_FIND)) {
55087 + err = -ENOENT;
55088 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
55089 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
55090 + path, (mode & GR_READ) ? " reading" : "",
55091 + (mode & GR_WRITE) ? " writing" : "");
55092 + err = -EACCES;
55093 + } else if ((err & mode) != mode) {
55094 + err = -EACCES;
55095 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
55096 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
55097 + path, (mode & GR_READ) ? " reading" : "",
55098 + (mode & GR_WRITE) ? " writing" : "");
55099 + err = 0;
55100 + } else
55101 + err = 0;
55102 +
55103 + out:
55104 + preempt_enable();
55105 +
55106 + return err;
55107 +}
55108 +#endif
55109 +
55110 +int
55111 +gr_handle_proc_ptrace(struct task_struct *task)
55112 +{
55113 + struct file *filp;
55114 + struct task_struct *tmp = task;
55115 + struct task_struct *curtemp = current;
55116 + __u32 retmode;
55117 +
55118 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55119 + if (unlikely(!(gr_status & GR_READY)))
55120 + return 0;
55121 +#endif
55122 +
55123 + read_lock(&tasklist_lock);
55124 + read_lock(&grsec_exec_file_lock);
55125 + filp = task->exec_file;
55126 +
55127 + while (tmp->pid > 0) {
55128 + if (tmp == curtemp)
55129 + break;
55130 + tmp = tmp->real_parent;
55131 + }
55132 +
55133 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55134 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55135 + read_unlock(&grsec_exec_file_lock);
55136 + read_unlock(&tasklist_lock);
55137 + return 1;
55138 + }
55139 +
55140 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55141 + if (!(gr_status & GR_READY)) {
55142 + read_unlock(&grsec_exec_file_lock);
55143 + read_unlock(&tasklist_lock);
55144 + return 0;
55145 + }
55146 +#endif
55147 +
55148 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55149 + read_unlock(&grsec_exec_file_lock);
55150 + read_unlock(&tasklist_lock);
55151 +
55152 + if (retmode & GR_NOPTRACE)
55153 + return 1;
55154 +
55155 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55156 + && (current->acl != task->acl || (current->acl != current->role->root_label
55157 + && current->pid != task->pid)))
55158 + return 1;
55159 +
55160 + return 0;
55161 +}
55162 +
55163 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55164 +{
55165 + if (unlikely(!(gr_status & GR_READY)))
55166 + return;
55167 +
55168 + if (!(current->role->roletype & GR_ROLE_GOD))
55169 + return;
55170 +
55171 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55172 + p->role->rolename, gr_task_roletype_to_char(p),
55173 + p->acl->filename);
55174 +}
55175 +
55176 +int
55177 +gr_handle_ptrace(struct task_struct *task, const long request)
55178 +{
55179 + struct task_struct *tmp = task;
55180 + struct task_struct *curtemp = current;
55181 + __u32 retmode;
55182 +
55183 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55184 + if (unlikely(!(gr_status & GR_READY)))
55185 + return 0;
55186 +#endif
55187 +
55188 + read_lock(&tasklist_lock);
55189 + while (tmp->pid > 0) {
55190 + if (tmp == curtemp)
55191 + break;
55192 + tmp = tmp->real_parent;
55193 + }
55194 +
55195 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55196 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55197 + read_unlock(&tasklist_lock);
55198 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55199 + return 1;
55200 + }
55201 + read_unlock(&tasklist_lock);
55202 +
55203 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55204 + if (!(gr_status & GR_READY))
55205 + return 0;
55206 +#endif
55207 +
55208 + read_lock(&grsec_exec_file_lock);
55209 + if (unlikely(!task->exec_file)) {
55210 + read_unlock(&grsec_exec_file_lock);
55211 + return 0;
55212 + }
55213 +
55214 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55215 + read_unlock(&grsec_exec_file_lock);
55216 +
55217 + if (retmode & GR_NOPTRACE) {
55218 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55219 + return 1;
55220 + }
55221 +
55222 + if (retmode & GR_PTRACERD) {
55223 + switch (request) {
55224 + case PTRACE_POKETEXT:
55225 + case PTRACE_POKEDATA:
55226 + case PTRACE_POKEUSR:
55227 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55228 + case PTRACE_SETREGS:
55229 + case PTRACE_SETFPREGS:
55230 +#endif
55231 +#ifdef CONFIG_X86
55232 + case PTRACE_SETFPXREGS:
55233 +#endif
55234 +#ifdef CONFIG_ALTIVEC
55235 + case PTRACE_SETVRREGS:
55236 +#endif
55237 + return 1;
55238 + default:
55239 + return 0;
55240 + }
55241 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55242 + !(current->role->roletype & GR_ROLE_GOD) &&
55243 + (current->acl != task->acl)) {
55244 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55245 + return 1;
55246 + }
55247 +
55248 + return 0;
55249 +}
55250 +
55251 +static int is_writable_mmap(const struct file *filp)
55252 +{
55253 + struct task_struct *task = current;
55254 + struct acl_object_label *obj, *obj2;
55255 +
55256 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55257 + !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode) && (filp->f_path.mnt != shm_mnt || (filp->f_path.dentry->d_inode->i_nlink > 0))) {
55258 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55259 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55260 + task->role->root_label);
55261 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55262 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55263 + return 1;
55264 + }
55265 + }
55266 + return 0;
55267 +}
55268 +
55269 +int
55270 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55271 +{
55272 + __u32 mode;
55273 +
55274 + if (unlikely(!file || !(prot & PROT_EXEC)))
55275 + return 1;
55276 +
55277 + if (is_writable_mmap(file))
55278 + return 0;
55279 +
55280 + mode =
55281 + gr_search_file(file->f_path.dentry,
55282 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55283 + file->f_path.mnt);
55284 +
55285 + if (!gr_tpe_allow(file))
55286 + return 0;
55287 +
55288 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55289 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55290 + return 0;
55291 + } else if (unlikely(!(mode & GR_EXEC))) {
55292 + return 0;
55293 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55294 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55295 + return 1;
55296 + }
55297 +
55298 + return 1;
55299 +}
55300 +
55301 +int
55302 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55303 +{
55304 + __u32 mode;
55305 +
55306 + if (unlikely(!file || !(prot & PROT_EXEC)))
55307 + return 1;
55308 +
55309 + if (is_writable_mmap(file))
55310 + return 0;
55311 +
55312 + mode =
55313 + gr_search_file(file->f_path.dentry,
55314 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55315 + file->f_path.mnt);
55316 +
55317 + if (!gr_tpe_allow(file))
55318 + return 0;
55319 +
55320 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55321 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55322 + return 0;
55323 + } else if (unlikely(!(mode & GR_EXEC))) {
55324 + return 0;
55325 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55326 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55327 + return 1;
55328 + }
55329 +
55330 + return 1;
55331 +}
55332 +
55333 +void
55334 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55335 +{
55336 + unsigned long runtime;
55337 + unsigned long cputime;
55338 + unsigned int wday, cday;
55339 + __u8 whr, chr;
55340 + __u8 wmin, cmin;
55341 + __u8 wsec, csec;
55342 + struct timespec timeval;
55343 +
55344 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55345 + !(task->acl->mode & GR_PROCACCT)))
55346 + return;
55347 +
55348 + do_posix_clock_monotonic_gettime(&timeval);
55349 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55350 + wday = runtime / (3600 * 24);
55351 + runtime -= wday * (3600 * 24);
55352 + whr = runtime / 3600;
55353 + runtime -= whr * 3600;
55354 + wmin = runtime / 60;
55355 + runtime -= wmin * 60;
55356 + wsec = runtime;
55357 +
55358 + cputime = (task->utime + task->stime) / HZ;
55359 + cday = cputime / (3600 * 24);
55360 + cputime -= cday * (3600 * 24);
55361 + chr = cputime / 3600;
55362 + cputime -= chr * 3600;
55363 + cmin = cputime / 60;
55364 + cputime -= cmin * 60;
55365 + csec = cputime;
55366 +
55367 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55368 +
55369 + return;
55370 +}
55371 +
55372 +void gr_set_kernel_label(struct task_struct *task)
55373 +{
55374 + if (gr_status & GR_READY) {
55375 + task->role = kernel_role;
55376 + task->acl = kernel_role->root_label;
55377 + }
55378 + return;
55379 +}
55380 +
55381 +#ifdef CONFIG_TASKSTATS
55382 +int gr_is_taskstats_denied(int pid)
55383 +{
55384 + struct task_struct *task;
55385 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55386 + const struct cred *cred;
55387 +#endif
55388 + int ret = 0;
55389 +
55390 + /* restrict taskstats viewing to un-chrooted root users
55391 + who have the 'view' subject flag if the RBAC system is enabled
55392 + */
55393 +
55394 + rcu_read_lock();
55395 + read_lock(&tasklist_lock);
55396 + task = find_task_by_vpid(pid);
55397 + if (task) {
55398 +#ifdef CONFIG_GRKERNSEC_CHROOT
55399 + if (proc_is_chrooted(task))
55400 + ret = -EACCES;
55401 +#endif
55402 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55403 + cred = __task_cred(task);
55404 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55405 + if (cred->uid != 0)
55406 + ret = -EACCES;
55407 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55408 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55409 + ret = -EACCES;
55410 +#endif
55411 +#endif
55412 + if (gr_status & GR_READY) {
55413 + if (!(task->acl->mode & GR_VIEW))
55414 + ret = -EACCES;
55415 + }
55416 + } else
55417 + ret = -ENOENT;
55418 +
55419 + read_unlock(&tasklist_lock);
55420 + rcu_read_unlock();
55421 +
55422 + return ret;
55423 +}
55424 +#endif
55425 +
55426 +/* AUXV entries are filled via a descendant of search_binary_handler
55427 + after we've already applied the subject for the target
55428 +*/
55429 +int gr_acl_enable_at_secure(void)
55430 +{
55431 + if (unlikely(!(gr_status & GR_READY)))
55432 + return 0;
55433 +
55434 + if (current->acl->mode & GR_ATSECURE)
55435 + return 1;
55436 +
55437 + return 0;
55438 +}
55439 +
55440 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55441 +{
55442 + struct task_struct *task = current;
55443 + struct dentry *dentry = file->f_path.dentry;
55444 + struct vfsmount *mnt = file->f_path.mnt;
55445 + struct acl_object_label *obj, *tmp;
55446 + struct acl_subject_label *subj;
55447 + unsigned int bufsize;
55448 + int is_not_root;
55449 + char *path;
55450 + dev_t dev = __get_dev(dentry);
55451 +
55452 + if (unlikely(!(gr_status & GR_READY)))
55453 + return 1;
55454 +
55455 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55456 + return 1;
55457 +
55458 + /* ignore Eric Biederman */
55459 + if (IS_PRIVATE(dentry->d_inode))
55460 + return 1;
55461 +
55462 + subj = task->acl;
55463 + do {
55464 + obj = lookup_acl_obj_label(ino, dev, subj);
55465 + if (obj != NULL)
55466 + return (obj->mode & GR_FIND) ? 1 : 0;
55467 + } while ((subj = subj->parent_subject));
55468 +
55469 + /* this is purely an optimization since we're looking for an object
55470 + for the directory we're doing a readdir on
55471 + if it's possible for any globbed object to match the entry we're
55472 + filling into the directory, then the object we find here will be
55473 + an anchor point with attached globbed objects
55474 + */
55475 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55476 + if (obj->globbed == NULL)
55477 + return (obj->mode & GR_FIND) ? 1 : 0;
55478 +
55479 + is_not_root = ((obj->filename[0] == '/') &&
55480 + (obj->filename[1] == '\0')) ? 0 : 1;
55481 + bufsize = PAGE_SIZE - namelen - is_not_root;
55482 +
55483 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55484 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55485 + return 1;
55486 +
55487 + preempt_disable();
55488 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55489 + bufsize);
55490 +
55491 + bufsize = strlen(path);
55492 +
55493 + /* if base is "/", don't append an additional slash */
55494 + if (is_not_root)
55495 + *(path + bufsize) = '/';
55496 + memcpy(path + bufsize + is_not_root, name, namelen);
55497 + *(path + bufsize + namelen + is_not_root) = '\0';
55498 +
55499 + tmp = obj->globbed;
55500 + while (tmp) {
55501 + if (!glob_match(tmp->filename, path)) {
55502 + preempt_enable();
55503 + return (tmp->mode & GR_FIND) ? 1 : 0;
55504 + }
55505 + tmp = tmp->next;
55506 + }
55507 + preempt_enable();
55508 + return (obj->mode & GR_FIND) ? 1 : 0;
55509 +}
55510 +
55511 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55512 +EXPORT_SYMBOL(gr_acl_is_enabled);
55513 +#endif
55514 +EXPORT_SYMBOL(gr_learn_resource);
55515 +EXPORT_SYMBOL(gr_set_kernel_label);
55516 +#ifdef CONFIG_SECURITY
55517 +EXPORT_SYMBOL(gr_check_user_change);
55518 +EXPORT_SYMBOL(gr_check_group_change);
55519 +#endif
55520 +
55521 diff -urNp linux-2.6.39.2/grsecurity/gracl_cap.c linux-2.6.39.2/grsecurity/gracl_cap.c
55522 --- linux-2.6.39.2/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
55523 +++ linux-2.6.39.2/grsecurity/gracl_cap.c 2011-05-22 19:41:42.000000000 -0400
55524 @@ -0,0 +1,139 @@
55525 +#include <linux/kernel.h>
55526 +#include <linux/module.h>
55527 +#include <linux/sched.h>
55528 +#include <linux/gracl.h>
55529 +#include <linux/grsecurity.h>
55530 +#include <linux/grinternal.h>
55531 +
55532 +static const char *captab_log[] = {
55533 + "CAP_CHOWN",
55534 + "CAP_DAC_OVERRIDE",
55535 + "CAP_DAC_READ_SEARCH",
55536 + "CAP_FOWNER",
55537 + "CAP_FSETID",
55538 + "CAP_KILL",
55539 + "CAP_SETGID",
55540 + "CAP_SETUID",
55541 + "CAP_SETPCAP",
55542 + "CAP_LINUX_IMMUTABLE",
55543 + "CAP_NET_BIND_SERVICE",
55544 + "CAP_NET_BROADCAST",
55545 + "CAP_NET_ADMIN",
55546 + "CAP_NET_RAW",
55547 + "CAP_IPC_LOCK",
55548 + "CAP_IPC_OWNER",
55549 + "CAP_SYS_MODULE",
55550 + "CAP_SYS_RAWIO",
55551 + "CAP_SYS_CHROOT",
55552 + "CAP_SYS_PTRACE",
55553 + "CAP_SYS_PACCT",
55554 + "CAP_SYS_ADMIN",
55555 + "CAP_SYS_BOOT",
55556 + "CAP_SYS_NICE",
55557 + "CAP_SYS_RESOURCE",
55558 + "CAP_SYS_TIME",
55559 + "CAP_SYS_TTY_CONFIG",
55560 + "CAP_MKNOD",
55561 + "CAP_LEASE",
55562 + "CAP_AUDIT_WRITE",
55563 + "CAP_AUDIT_CONTROL",
55564 + "CAP_SETFCAP",
55565 + "CAP_MAC_OVERRIDE",
55566 + "CAP_MAC_ADMIN",
55567 + "CAP_SYSLOG"
55568 +};
55569 +
55570 +EXPORT_SYMBOL(gr_is_capable);
55571 +EXPORT_SYMBOL(gr_is_capable_nolog);
55572 +
55573 +int
55574 +gr_is_capable(const int cap)
55575 +{
55576 + struct task_struct *task = current;
55577 + const struct cred *cred = current_cred();
55578 + struct acl_subject_label *curracl;
55579 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55580 + kernel_cap_t cap_audit = __cap_empty_set;
55581 +
55582 + if (!gr_acl_is_enabled())
55583 + return 1;
55584 +
55585 + curracl = task->acl;
55586 +
55587 + cap_drop = curracl->cap_lower;
55588 + cap_mask = curracl->cap_mask;
55589 + cap_audit = curracl->cap_invert_audit;
55590 +
55591 + while ((curracl = curracl->parent_subject)) {
55592 + /* if the cap isn't specified in the current computed mask but is specified in the
55593 + current level subject, and is lowered in the current level subject, then add
55594 + it to the set of dropped capabilities
55595 + otherwise, add the current level subject's mask to the current computed mask
55596 + */
55597 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55598 + cap_raise(cap_mask, cap);
55599 + if (cap_raised(curracl->cap_lower, cap))
55600 + cap_raise(cap_drop, cap);
55601 + if (cap_raised(curracl->cap_invert_audit, cap))
55602 + cap_raise(cap_audit, cap);
55603 + }
55604 + }
55605 +
55606 + if (!cap_raised(cap_drop, cap)) {
55607 + if (cap_raised(cap_audit, cap))
55608 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55609 + return 1;
55610 + }
55611 +
55612 + curracl = task->acl;
55613 +
55614 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55615 + && cap_raised(cred->cap_effective, cap)) {
55616 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55617 + task->role->roletype, cred->uid,
55618 + cred->gid, task->exec_file ?
55619 + gr_to_filename(task->exec_file->f_path.dentry,
55620 + task->exec_file->f_path.mnt) : curracl->filename,
55621 + curracl->filename, 0UL,
55622 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55623 + return 1;
55624 + }
55625 +
55626 + if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55627 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55628 + return 0;
55629 +}
55630 +
55631 +int
55632 +gr_is_capable_nolog(const int cap)
55633 +{
55634 + struct acl_subject_label *curracl;
55635 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55636 +
55637 + if (!gr_acl_is_enabled())
55638 + return 1;
55639 +
55640 + curracl = current->acl;
55641 +
55642 + cap_drop = curracl->cap_lower;
55643 + cap_mask = curracl->cap_mask;
55644 +
55645 + while ((curracl = curracl->parent_subject)) {
55646 + /* if the cap isn't specified in the current computed mask but is specified in the
55647 + current level subject, and is lowered in the current level subject, then add
55648 + it to the set of dropped capabilities
55649 + otherwise, add the current level subject's mask to the current computed mask
55650 + */
55651 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55652 + cap_raise(cap_mask, cap);
55653 + if (cap_raised(curracl->cap_lower, cap))
55654 + cap_raise(cap_drop, cap);
55655 + }
55656 + }
55657 +
55658 + if (!cap_raised(cap_drop, cap))
55659 + return 1;
55660 +
55661 + return 0;
55662 +}
55663 +
55664 diff -urNp linux-2.6.39.2/grsecurity/gracl_fs.c linux-2.6.39.2/grsecurity/gracl_fs.c
55665 --- linux-2.6.39.2/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
55666 +++ linux-2.6.39.2/grsecurity/gracl_fs.c 2011-05-22 19:41:42.000000000 -0400
55667 @@ -0,0 +1,431 @@
55668 +#include <linux/kernel.h>
55669 +#include <linux/sched.h>
55670 +#include <linux/types.h>
55671 +#include <linux/fs.h>
55672 +#include <linux/file.h>
55673 +#include <linux/stat.h>
55674 +#include <linux/grsecurity.h>
55675 +#include <linux/grinternal.h>
55676 +#include <linux/gracl.h>
55677 +
55678 +__u32
55679 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55680 + const struct vfsmount * mnt)
55681 +{
55682 + __u32 mode;
55683 +
55684 + if (unlikely(!dentry->d_inode))
55685 + return GR_FIND;
55686 +
55687 + mode =
55688 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55689 +
55690 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55691 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55692 + return mode;
55693 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55694 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55695 + return 0;
55696 + } else if (unlikely(!(mode & GR_FIND)))
55697 + return 0;
55698 +
55699 + return GR_FIND;
55700 +}
55701 +
55702 +__u32
55703 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55704 + const int fmode)
55705 +{
55706 + __u32 reqmode = GR_FIND;
55707 + __u32 mode;
55708 +
55709 + if (unlikely(!dentry->d_inode))
55710 + return reqmode;
55711 +
55712 + if (unlikely(fmode & O_APPEND))
55713 + reqmode |= GR_APPEND;
55714 + else if (unlikely(fmode & FMODE_WRITE))
55715 + reqmode |= GR_WRITE;
55716 + if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55717 + reqmode |= GR_READ;
55718 + if ((fmode & FMODE_GREXEC) && (fmode & __FMODE_EXEC))
55719 + reqmode &= ~GR_READ;
55720 + mode =
55721 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55722 + mnt);
55723 +
55724 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55725 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55726 + reqmode & GR_READ ? " reading" : "",
55727 + reqmode & GR_WRITE ? " writing" : reqmode &
55728 + GR_APPEND ? " appending" : "");
55729 + return reqmode;
55730 + } else
55731 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55732 + {
55733 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55734 + reqmode & GR_READ ? " reading" : "",
55735 + reqmode & GR_WRITE ? " writing" : reqmode &
55736 + GR_APPEND ? " appending" : "");
55737 + return 0;
55738 + } else if (unlikely((mode & reqmode) != reqmode))
55739 + return 0;
55740 +
55741 + return reqmode;
55742 +}
55743 +
55744 +__u32
55745 +gr_acl_handle_creat(const struct dentry * dentry,
55746 + const struct dentry * p_dentry,
55747 + const struct vfsmount * p_mnt, const int fmode,
55748 + const int imode)
55749 +{
55750 + __u32 reqmode = GR_WRITE | GR_CREATE;
55751 + __u32 mode;
55752 +
55753 + if (unlikely(fmode & O_APPEND))
55754 + reqmode |= GR_APPEND;
55755 + if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
55756 + reqmode |= GR_READ;
55757 + if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
55758 + reqmode |= GR_SETID;
55759 +
55760 + mode =
55761 + gr_check_create(dentry, p_dentry, p_mnt,
55762 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55763 +
55764 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55765 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55766 + reqmode & GR_READ ? " reading" : "",
55767 + reqmode & GR_WRITE ? " writing" : reqmode &
55768 + GR_APPEND ? " appending" : "");
55769 + return reqmode;
55770 + } else
55771 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55772 + {
55773 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55774 + reqmode & GR_READ ? " reading" : "",
55775 + reqmode & GR_WRITE ? " writing" : reqmode &
55776 + GR_APPEND ? " appending" : "");
55777 + return 0;
55778 + } else if (unlikely((mode & reqmode) != reqmode))
55779 + return 0;
55780 +
55781 + return reqmode;
55782 +}
55783 +
55784 +__u32
55785 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55786 + const int fmode)
55787 +{
55788 + __u32 mode, reqmode = GR_FIND;
55789 +
55790 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55791 + reqmode |= GR_EXEC;
55792 + if (fmode & S_IWOTH)
55793 + reqmode |= GR_WRITE;
55794 + if (fmode & S_IROTH)
55795 + reqmode |= GR_READ;
55796 +
55797 + mode =
55798 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55799 + mnt);
55800 +
55801 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55802 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55803 + reqmode & GR_READ ? " reading" : "",
55804 + reqmode & GR_WRITE ? " writing" : "",
55805 + reqmode & GR_EXEC ? " executing" : "");
55806 + return reqmode;
55807 + } else
55808 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55809 + {
55810 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55811 + reqmode & GR_READ ? " reading" : "",
55812 + reqmode & GR_WRITE ? " writing" : "",
55813 + reqmode & GR_EXEC ? " executing" : "");
55814 + return 0;
55815 + } else if (unlikely((mode & reqmode) != reqmode))
55816 + return 0;
55817 +
55818 + return reqmode;
55819 +}
55820 +
55821 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55822 +{
55823 + __u32 mode;
55824 +
55825 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55826 +
55827 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55828 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55829 + return mode;
55830 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55831 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55832 + return 0;
55833 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55834 + return 0;
55835 +
55836 + return (reqmode);
55837 +}
55838 +
55839 +__u32
55840 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55841 +{
55842 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55843 +}
55844 +
55845 +__u32
55846 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55847 +{
55848 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55849 +}
55850 +
55851 +__u32
55852 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55853 +{
55854 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55855 +}
55856 +
55857 +__u32
55858 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55859 +{
55860 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55861 +}
55862 +
55863 +__u32
55864 +gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
55865 + mode_t mode)
55866 +{
55867 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55868 + return 1;
55869 +
55870 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55871 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55872 + GR_FCHMOD_ACL_MSG);
55873 + } else {
55874 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
55875 + }
55876 +}
55877 +
55878 +__u32
55879 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55880 + mode_t mode)
55881 +{
55882 + if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
55883 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55884 + GR_CHMOD_ACL_MSG);
55885 + } else {
55886 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55887 + }
55888 +}
55889 +
55890 +__u32
55891 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55892 +{
55893 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55894 +}
55895 +
55896 +__u32
55897 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55898 +{
55899 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55900 +}
55901 +
55902 +__u32
55903 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55904 +{
55905 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55906 +}
55907 +
55908 +__u32
55909 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55910 +{
55911 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55912 + GR_UNIXCONNECT_ACL_MSG);
55913 +}
55914 +
55915 +/* hardlinks require at minimum create permission,
55916 + any additional privilege required is based on the
55917 + privilege of the file being linked to
55918 +*/
55919 +__u32
55920 +gr_acl_handle_link(const struct dentry * new_dentry,
55921 + const struct dentry * parent_dentry,
55922 + const struct vfsmount * parent_mnt,
55923 + const struct dentry * old_dentry,
55924 + const struct vfsmount * old_mnt, const char *to)
55925 +{
55926 + __u32 mode;
55927 + __u32 needmode = GR_CREATE | GR_LINK;
55928 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55929 +
55930 + mode =
55931 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55932 + old_mnt);
55933 +
55934 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55935 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55936 + return mode;
55937 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55938 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55939 + return 0;
55940 + } else if (unlikely((mode & needmode) != needmode))
55941 + return 0;
55942 +
55943 + return 1;
55944 +}
55945 +
55946 +__u32
55947 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55948 + const struct dentry * parent_dentry,
55949 + const struct vfsmount * parent_mnt, const char *from)
55950 +{
55951 + __u32 needmode = GR_WRITE | GR_CREATE;
55952 + __u32 mode;
55953 +
55954 + mode =
55955 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55956 + GR_CREATE | GR_AUDIT_CREATE |
55957 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55958 +
55959 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55960 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55961 + return mode;
55962 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55963 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55964 + return 0;
55965 + } else if (unlikely((mode & needmode) != needmode))
55966 + return 0;
55967 +
55968 + return (GR_WRITE | GR_CREATE);
55969 +}
55970 +
55971 +static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
55972 +{
55973 + __u32 mode;
55974 +
55975 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55976 +
55977 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55978 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55979 + return mode;
55980 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55981 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55982 + return 0;
55983 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55984 + return 0;
55985 +
55986 + return (reqmode);
55987 +}
55988 +
55989 +__u32
55990 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55991 + const struct dentry * parent_dentry,
55992 + const struct vfsmount * parent_mnt,
55993 + const int mode)
55994 +{
55995 + __u32 reqmode = GR_WRITE | GR_CREATE;
55996 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55997 + reqmode |= GR_SETID;
55998 +
55999 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56000 + reqmode, GR_MKNOD_ACL_MSG);
56001 +}
56002 +
56003 +__u32
56004 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56005 + const struct dentry *parent_dentry,
56006 + const struct vfsmount *parent_mnt)
56007 +{
56008 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56009 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56010 +}
56011 +
56012 +#define RENAME_CHECK_SUCCESS(old, new) \
56013 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56014 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56015 +
56016 +int
56017 +gr_acl_handle_rename(struct dentry *new_dentry,
56018 + struct dentry *parent_dentry,
56019 + const struct vfsmount *parent_mnt,
56020 + struct dentry *old_dentry,
56021 + struct inode *old_parent_inode,
56022 + struct vfsmount *old_mnt, const char *newname)
56023 +{
56024 + __u32 comp1, comp2;
56025 + int error = 0;
56026 +
56027 + if (unlikely(!gr_acl_is_enabled()))
56028 + return 0;
56029 +
56030 + if (!new_dentry->d_inode) {
56031 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56032 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56033 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56034 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56035 + GR_DELETE | GR_AUDIT_DELETE |
56036 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56037 + GR_SUPPRESS, old_mnt);
56038 + } else {
56039 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56040 + GR_CREATE | GR_DELETE |
56041 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56042 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56043 + GR_SUPPRESS, parent_mnt);
56044 + comp2 =
56045 + gr_search_file(old_dentry,
56046 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56047 + GR_DELETE | GR_AUDIT_DELETE |
56048 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56049 + }
56050 +
56051 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56052 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56053 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56054 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56055 + && !(comp2 & GR_SUPPRESS)) {
56056 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56057 + error = -EACCES;
56058 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56059 + error = -EACCES;
56060 +
56061 + return error;
56062 +}
56063 +
56064 +void
56065 +gr_acl_handle_exit(void)
56066 +{
56067 + u16 id;
56068 + char *rolename;
56069 + struct file *exec_file;
56070 +
56071 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56072 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56073 + id = current->acl_role_id;
56074 + rolename = current->role->rolename;
56075 + gr_set_acls(1);
56076 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56077 + }
56078 +
56079 + write_lock(&grsec_exec_file_lock);
56080 + exec_file = current->exec_file;
56081 + current->exec_file = NULL;
56082 + write_unlock(&grsec_exec_file_lock);
56083 +
56084 + if (exec_file)
56085 + fput(exec_file);
56086 +}
56087 +
56088 +int
56089 +gr_acl_handle_procpidmem(const struct task_struct *task)
56090 +{
56091 + if (unlikely(!gr_acl_is_enabled()))
56092 + return 0;
56093 +
56094 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56095 + return -EACCES;
56096 +
56097 + return 0;
56098 +}
56099 diff -urNp linux-2.6.39.2/grsecurity/gracl_ip.c linux-2.6.39.2/grsecurity/gracl_ip.c
56100 --- linux-2.6.39.2/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
56101 +++ linux-2.6.39.2/grsecurity/gracl_ip.c 2011-05-22 22:47:31.000000000 -0400
56102 @@ -0,0 +1,381 @@
56103 +#include <linux/kernel.h>
56104 +#include <asm/uaccess.h>
56105 +#include <asm/errno.h>
56106 +#include <net/sock.h>
56107 +#include <linux/file.h>
56108 +#include <linux/fs.h>
56109 +#include <linux/net.h>
56110 +#include <linux/in.h>
56111 +#include <linux/skbuff.h>
56112 +#include <linux/ip.h>
56113 +#include <linux/udp.h>
56114 +#include <linux/types.h>
56115 +#include <linux/sched.h>
56116 +#include <linux/netdevice.h>
56117 +#include <linux/inetdevice.h>
56118 +#include <linux/gracl.h>
56119 +#include <linux/grsecurity.h>
56120 +#include <linux/grinternal.h>
56121 +
56122 +#define GR_BIND 0x01
56123 +#define GR_CONNECT 0x02
56124 +#define GR_INVERT 0x04
56125 +#define GR_BINDOVERRIDE 0x08
56126 +#define GR_CONNECTOVERRIDE 0x10
56127 +#define GR_SOCK_FAMILY 0x20
56128 +
56129 +static const char * gr_protocols[IPPROTO_MAX] = {
56130 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56131 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56132 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56133 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56134 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56135 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56136 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56137 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56138 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56139 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56140 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56141 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56142 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56143 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56144 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56145 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56146 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56147 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56148 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56149 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56150 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56151 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56152 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56153 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56154 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56155 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56156 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56157 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56158 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56159 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56160 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56161 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56162 + };
56163 +
56164 +static const char * gr_socktypes[SOCK_MAX] = {
56165 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56166 + "unknown:7", "unknown:8", "unknown:9", "packet"
56167 + };
56168 +
56169 +static const char * gr_sockfamilies[AF_MAX+1] = {
56170 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56171 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56172 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56173 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56174 + };
56175 +
56176 +const char *
56177 +gr_proto_to_name(unsigned char proto)
56178 +{
56179 + return gr_protocols[proto];
56180 +}
56181 +
56182 +const char *
56183 +gr_socktype_to_name(unsigned char type)
56184 +{
56185 + return gr_socktypes[type];
56186 +}
56187 +
56188 +const char *
56189 +gr_sockfamily_to_name(unsigned char family)
56190 +{
56191 + return gr_sockfamilies[family];
56192 +}
56193 +
56194 +int
56195 +gr_search_socket(const int domain, const int type, const int protocol)
56196 +{
56197 + struct acl_subject_label *curr;
56198 + const struct cred *cred = current_cred();
56199 +
56200 + if (unlikely(!gr_acl_is_enabled()))
56201 + goto exit;
56202 +
56203 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56204 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56205 + goto exit; // let the kernel handle it
56206 +
56207 + curr = current->acl;
56208 +
56209 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56210 + /* the family is allowed, if this is PF_INET allow it only if
56211 + the extra sock type/protocol checks pass */
56212 + if (domain == PF_INET)
56213 + goto inet_check;
56214 + goto exit;
56215 + } else {
56216 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56217 + __u32 fakeip = 0;
56218 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56219 + current->role->roletype, cred->uid,
56220 + cred->gid, current->exec_file ?
56221 + gr_to_filename(current->exec_file->f_path.dentry,
56222 + current->exec_file->f_path.mnt) :
56223 + curr->filename, curr->filename,
56224 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56225 + &current->signal->saved_ip);
56226 + goto exit;
56227 + }
56228 + goto exit_fail;
56229 + }
56230 +
56231 +inet_check:
56232 + /* the rest of this checking is for IPv4 only */
56233 + if (!curr->ips)
56234 + goto exit;
56235 +
56236 + if ((curr->ip_type & (1 << type)) &&
56237 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56238 + goto exit;
56239 +
56240 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56241 + /* we don't place acls on raw sockets , and sometimes
56242 + dgram/ip sockets are opened for ioctl and not
56243 + bind/connect, so we'll fake a bind learn log */
56244 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56245 + __u32 fakeip = 0;
56246 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56247 + current->role->roletype, cred->uid,
56248 + cred->gid, current->exec_file ?
56249 + gr_to_filename(current->exec_file->f_path.dentry,
56250 + current->exec_file->f_path.mnt) :
56251 + curr->filename, curr->filename,
56252 + &fakeip, 0, type,
56253 + protocol, GR_CONNECT, &current->signal->saved_ip);
56254 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56255 + __u32 fakeip = 0;
56256 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56257 + current->role->roletype, cred->uid,
56258 + cred->gid, current->exec_file ?
56259 + gr_to_filename(current->exec_file->f_path.dentry,
56260 + current->exec_file->f_path.mnt) :
56261 + curr->filename, curr->filename,
56262 + &fakeip, 0, type,
56263 + protocol, GR_BIND, &current->signal->saved_ip);
56264 + }
56265 + /* we'll log when they use connect or bind */
56266 + goto exit;
56267 + }
56268 +
56269 +exit_fail:
56270 + if (domain == PF_INET)
56271 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56272 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56273 + else
56274 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56275 + gr_socktype_to_name(type), protocol);
56276 +
56277 + return 0;
56278 +exit:
56279 + return 1;
56280 +}
56281 +
56282 +int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
56283 +{
56284 + if ((ip->mode & mode) &&
56285 + (ip_port >= ip->low) &&
56286 + (ip_port <= ip->high) &&
56287 + ((ntohl(ip_addr) & our_netmask) ==
56288 + (ntohl(our_addr) & our_netmask))
56289 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56290 + && (ip->type & (1 << type))) {
56291 + if (ip->mode & GR_INVERT)
56292 + return 2; // specifically denied
56293 + else
56294 + return 1; // allowed
56295 + }
56296 +
56297 + return 0; // not specifically allowed, may continue parsing
56298 +}
56299 +
56300 +static int
56301 +gr_search_connectbind(const int full_mode, struct sock *sk,
56302 + struct sockaddr_in *addr, const int type)
56303 +{
56304 + char iface[IFNAMSIZ] = {0};
56305 + struct acl_subject_label *curr;
56306 + struct acl_ip_label *ip;
56307 + struct inet_sock *isk;
56308 + struct net_device *dev;
56309 + struct in_device *idev;
56310 + unsigned long i;
56311 + int ret;
56312 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56313 + __u32 ip_addr = 0;
56314 + __u32 our_addr;
56315 + __u32 our_netmask;
56316 + char *p;
56317 + __u16 ip_port = 0;
56318 + const struct cred *cred = current_cred();
56319 +
56320 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56321 + return 0;
56322 +
56323 + curr = current->acl;
56324 + isk = inet_sk(sk);
56325 +
56326 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56327 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56328 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56329 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56330 + struct sockaddr_in saddr;
56331 + int err;
56332 +
56333 + saddr.sin_family = AF_INET;
56334 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56335 + saddr.sin_port = isk->inet_sport;
56336 +
56337 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56338 + if (err)
56339 + return err;
56340 +
56341 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56342 + if (err)
56343 + return err;
56344 + }
56345 +
56346 + if (!curr->ips)
56347 + return 0;
56348 +
56349 + ip_addr = addr->sin_addr.s_addr;
56350 + ip_port = ntohs(addr->sin_port);
56351 +
56352 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56353 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56354 + current->role->roletype, cred->uid,
56355 + cred->gid, current->exec_file ?
56356 + gr_to_filename(current->exec_file->f_path.dentry,
56357 + current->exec_file->f_path.mnt) :
56358 + curr->filename, curr->filename,
56359 + &ip_addr, ip_port, type,
56360 + sk->sk_protocol, mode, &current->signal->saved_ip);
56361 + return 0;
56362 + }
56363 +
56364 + for (i = 0; i < curr->ip_num; i++) {
56365 + ip = *(curr->ips + i);
56366 + if (ip->iface != NULL) {
56367 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56368 + p = strchr(iface, ':');
56369 + if (p != NULL)
56370 + *p = '\0';
56371 + dev = dev_get_by_name(sock_net(sk), iface);
56372 + if (dev == NULL)
56373 + continue;
56374 + idev = in_dev_get(dev);
56375 + if (idev == NULL) {
56376 + dev_put(dev);
56377 + continue;
56378 + }
56379 + rcu_read_lock();
56380 + for_ifa(idev) {
56381 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56382 + our_addr = ifa->ifa_address;
56383 + our_netmask = 0xffffffff;
56384 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56385 + if (ret == 1) {
56386 + rcu_read_unlock();
56387 + in_dev_put(idev);
56388 + dev_put(dev);
56389 + return 0;
56390 + } else if (ret == 2) {
56391 + rcu_read_unlock();
56392 + in_dev_put(idev);
56393 + dev_put(dev);
56394 + goto denied;
56395 + }
56396 + }
56397 + } endfor_ifa(idev);
56398 + rcu_read_unlock();
56399 + in_dev_put(idev);
56400 + dev_put(dev);
56401 + } else {
56402 + our_addr = ip->addr;
56403 + our_netmask = ip->netmask;
56404 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56405 + if (ret == 1)
56406 + return 0;
56407 + else if (ret == 2)
56408 + goto denied;
56409 + }
56410 + }
56411 +
56412 +denied:
56413 + if (mode == GR_BIND)
56414 + gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
56415 + else if (mode == GR_CONNECT)
56416 + gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, &ip_addr, ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
56417 +
56418 + return -EACCES;
56419 +}
56420 +
56421 +int
56422 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56423 +{
56424 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56425 +}
56426 +
56427 +int
56428 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56429 +{
56430 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56431 +}
56432 +
56433 +int gr_search_listen(struct socket *sock)
56434 +{
56435 + struct sock *sk = sock->sk;
56436 + struct sockaddr_in addr;
56437 +
56438 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56439 + addr.sin_port = inet_sk(sk)->inet_sport;
56440 +
56441 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56442 +}
56443 +
56444 +int gr_search_accept(struct socket *sock)
56445 +{
56446 + struct sock *sk = sock->sk;
56447 + struct sockaddr_in addr;
56448 +
56449 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56450 + addr.sin_port = inet_sk(sk)->inet_sport;
56451 +
56452 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56453 +}
56454 +
56455 +int
56456 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56457 +{
56458 + if (addr)
56459 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56460 + else {
56461 + struct sockaddr_in sin;
56462 + const struct inet_sock *inet = inet_sk(sk);
56463 +
56464 + sin.sin_addr.s_addr = inet->inet_daddr;
56465 + sin.sin_port = inet->inet_dport;
56466 +
56467 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56468 + }
56469 +}
56470 +
56471 +int
56472 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56473 +{
56474 + struct sockaddr_in sin;
56475 +
56476 + if (unlikely(skb->len < sizeof (struct udphdr)))
56477 + return 0; // skip this packet
56478 +
56479 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56480 + sin.sin_port = udp_hdr(skb)->source;
56481 +
56482 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56483 +}
56484 diff -urNp linux-2.6.39.2/grsecurity/gracl_learn.c linux-2.6.39.2/grsecurity/gracl_learn.c
56485 --- linux-2.6.39.2/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
56486 +++ linux-2.6.39.2/grsecurity/gracl_learn.c 2011-05-22 22:47:45.000000000 -0400
56487 @@ -0,0 +1,210 @@
56488 +#include <linux/kernel.h>
56489 +#include <linux/mm.h>
56490 +#include <linux/sched.h>
56491 +#include <linux/poll.h>
56492 +#include <linux/string.h>
56493 +#include <linux/file.h>
56494 +#include <linux/types.h>
56495 +#include <linux/vmalloc.h>
56496 +#include <linux/grinternal.h>
56497 +
56498 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56499 + size_t count, loff_t *ppos);
56500 +extern int gr_acl_is_enabled(void);
56501 +
56502 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56503 +static int gr_learn_attached;
56504 +
56505 +/* use a 512k buffer */
56506 +#define LEARN_BUFFER_SIZE (512 * 1024)
56507 +
56508 +static DEFINE_SPINLOCK(gr_learn_lock);
56509 +static DEFINE_MUTEX(gr_learn_user_mutex);
56510 +
56511 +/* we need to maintain two buffers, so that the kernel context of grlearn
56512 + uses a semaphore around the userspace copying, and the other kernel contexts
56513 + use a spinlock when copying into the buffer, since they cannot sleep
56514 +*/
56515 +static char *learn_buffer;
56516 +static char *learn_buffer_user;
56517 +static int learn_buffer_len;
56518 +static int learn_buffer_user_len;
56519 +
56520 +static ssize_t
56521 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56522 +{
56523 + DECLARE_WAITQUEUE(wait, current);
56524 + ssize_t retval = 0;
56525 +
56526 + add_wait_queue(&learn_wait, &wait);
56527 + set_current_state(TASK_INTERRUPTIBLE);
56528 + do {
56529 + mutex_lock(&gr_learn_user_mutex);
56530 + spin_lock(&gr_learn_lock);
56531 + if (learn_buffer_len)
56532 + break;
56533 + spin_unlock(&gr_learn_lock);
56534 + mutex_unlock(&gr_learn_user_mutex);
56535 + if (file->f_flags & O_NONBLOCK) {
56536 + retval = -EAGAIN;
56537 + goto out;
56538 + }
56539 + if (signal_pending(current)) {
56540 + retval = -ERESTARTSYS;
56541 + goto out;
56542 + }
56543 +
56544 + schedule();
56545 + } while (1);
56546 +
56547 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56548 + learn_buffer_user_len = learn_buffer_len;
56549 + retval = learn_buffer_len;
56550 + learn_buffer_len = 0;
56551 +
56552 + spin_unlock(&gr_learn_lock);
56553 +
56554 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56555 + retval = -EFAULT;
56556 +
56557 + mutex_unlock(&gr_learn_user_mutex);
56558 +out:
56559 + set_current_state(TASK_RUNNING);
56560 + remove_wait_queue(&learn_wait, &wait);
56561 + return retval;
56562 +}
56563 +
56564 +static unsigned int
56565 +poll_learn(struct file * file, poll_table * wait)
56566 +{
56567 + poll_wait(file, &learn_wait, wait);
56568 +
56569 + if (learn_buffer_len)
56570 + return (POLLIN | POLLRDNORM);
56571 +
56572 + return 0;
56573 +}
56574 +
56575 +void
56576 +gr_clear_learn_entries(void)
56577 +{
56578 + char *tmp;
56579 +
56580 + mutex_lock(&gr_learn_user_mutex);
56581 + if (learn_buffer != NULL) {
56582 + spin_lock(&gr_learn_lock);
56583 + tmp = learn_buffer;
56584 + learn_buffer = NULL;
56585 + spin_unlock(&gr_learn_lock);
56586 + vfree(learn_buffer);
56587 + }
56588 + if (learn_buffer_user != NULL) {
56589 + vfree(learn_buffer_user);
56590 + learn_buffer_user = NULL;
56591 + }
56592 + learn_buffer_len = 0;
56593 + mutex_unlock(&gr_learn_user_mutex);
56594 +
56595 + return;
56596 +}
56597 +
56598 +void
56599 +gr_add_learn_entry(const char *fmt, ...)
56600 +{
56601 + va_list args;
56602 + unsigned int len;
56603 +
56604 + if (!gr_learn_attached)
56605 + return;
56606 +
56607 + spin_lock(&gr_learn_lock);
56608 +
56609 + /* leave a gap at the end so we know when it's "full" but don't have to
56610 + compute the exact length of the string we're trying to append
56611 + */
56612 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56613 + spin_unlock(&gr_learn_lock);
56614 + wake_up_interruptible(&learn_wait);
56615 + return;
56616 + }
56617 + if (learn_buffer == NULL) {
56618 + spin_unlock(&gr_learn_lock);
56619 + return;
56620 + }
56621 +
56622 + va_start(args, fmt);
56623 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56624 + va_end(args);
56625 +
56626 + learn_buffer_len += len + 1;
56627 +
56628 + spin_unlock(&gr_learn_lock);
56629 + wake_up_interruptible(&learn_wait);
56630 +
56631 + return;
56632 +}
56633 +
56634 +static int
56635 +open_learn(struct inode *inode, struct file *file)
56636 +{
56637 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56638 + return -EBUSY;
56639 + if (file->f_mode & FMODE_READ) {
56640 + int retval = 0;
56641 + mutex_lock(&gr_learn_user_mutex);
56642 + if (learn_buffer == NULL)
56643 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56644 + if (learn_buffer_user == NULL)
56645 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56646 + if (learn_buffer == NULL) {
56647 + retval = -ENOMEM;
56648 + goto out_error;
56649 + }
56650 + if (learn_buffer_user == NULL) {
56651 + retval = -ENOMEM;
56652 + goto out_error;
56653 + }
56654 + learn_buffer_len = 0;
56655 + learn_buffer_user_len = 0;
56656 + gr_learn_attached = 1;
56657 +out_error:
56658 + mutex_unlock(&gr_learn_user_mutex);
56659 + return retval;
56660 + }
56661 + return 0;
56662 +}
56663 +
56664 +static int
56665 +close_learn(struct inode *inode, struct file *file)
56666 +{
56667 + char *tmp;
56668 +
56669 + if (file->f_mode & FMODE_READ) {
56670 + mutex_lock(&gr_learn_user_mutex);
56671 + if (learn_buffer != NULL) {
56672 + spin_lock(&gr_learn_lock);
56673 + tmp = learn_buffer;
56674 + learn_buffer = NULL;
56675 + spin_unlock(&gr_learn_lock);
56676 + vfree(tmp);
56677 + }
56678 + if (learn_buffer_user != NULL) {
56679 + vfree(learn_buffer_user);
56680 + learn_buffer_user = NULL;
56681 + }
56682 + learn_buffer_len = 0;
56683 + learn_buffer_user_len = 0;
56684 + gr_learn_attached = 0;
56685 + mutex_unlock(&gr_learn_user_mutex);
56686 + }
56687 +
56688 + return 0;
56689 +}
56690 +
56691 +const struct file_operations grsec_fops = {
56692 + .read = read_learn,
56693 + .write = write_grsec_handler,
56694 + .open = open_learn,
56695 + .release = close_learn,
56696 + .poll = poll_learn,
56697 +};
56698 diff -urNp linux-2.6.39.2/grsecurity/gracl_res.c linux-2.6.39.2/grsecurity/gracl_res.c
56699 --- linux-2.6.39.2/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
56700 +++ linux-2.6.39.2/grsecurity/gracl_res.c 2011-05-22 19:41:42.000000000 -0400
56701 @@ -0,0 +1,68 @@
56702 +#include <linux/kernel.h>
56703 +#include <linux/sched.h>
56704 +#include <linux/gracl.h>
56705 +#include <linux/grinternal.h>
56706 +
56707 +static const char *restab_log[] = {
56708 + [RLIMIT_CPU] = "RLIMIT_CPU",
56709 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56710 + [RLIMIT_DATA] = "RLIMIT_DATA",
56711 + [RLIMIT_STACK] = "RLIMIT_STACK",
56712 + [RLIMIT_CORE] = "RLIMIT_CORE",
56713 + [RLIMIT_RSS] = "RLIMIT_RSS",
56714 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56715 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56716 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56717 + [RLIMIT_AS] = "RLIMIT_AS",
56718 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56719 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56720 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56721 + [RLIMIT_NICE] = "RLIMIT_NICE",
56722 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56723 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56724 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56725 +};
56726 +
56727 +void
56728 +gr_log_resource(const struct task_struct *task,
56729 + const int res, const unsigned long wanted, const int gt)
56730 +{
56731 + const struct cred *cred;
56732 + unsigned long rlim;
56733 +
56734 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56735 + return;
56736 +
56737 + // not yet supported resource
56738 + if (unlikely(!restab_log[res]))
56739 + return;
56740 +
56741 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56742 + rlim = task_rlimit_max(task, res);
56743 + else
56744 + rlim = task_rlimit(task, res);
56745 +
56746 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56747 + return;
56748 +
56749 + rcu_read_lock();
56750 + cred = __task_cred(task);
56751 +
56752 + if (res == RLIMIT_NPROC &&
56753 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56754 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56755 + goto out_rcu_unlock;
56756 + else if (res == RLIMIT_MEMLOCK &&
56757 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56758 + goto out_rcu_unlock;
56759 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56760 + goto out_rcu_unlock;
56761 + rcu_read_unlock();
56762 +
56763 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56764 +
56765 + return;
56766 +out_rcu_unlock:
56767 + rcu_read_unlock();
56768 + return;
56769 +}
56770 diff -urNp linux-2.6.39.2/grsecurity/gracl_segv.c linux-2.6.39.2/grsecurity/gracl_segv.c
56771 --- linux-2.6.39.2/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
56772 +++ linux-2.6.39.2/grsecurity/gracl_segv.c 2011-05-22 22:47:39.000000000 -0400
56773 @@ -0,0 +1,299 @@
56774 +#include <linux/kernel.h>
56775 +#include <linux/mm.h>
56776 +#include <asm/uaccess.h>
56777 +#include <asm/errno.h>
56778 +#include <asm/mman.h>
56779 +#include <net/sock.h>
56780 +#include <linux/file.h>
56781 +#include <linux/fs.h>
56782 +#include <linux/net.h>
56783 +#include <linux/in.h>
56784 +#include <linux/slab.h>
56785 +#include <linux/types.h>
56786 +#include <linux/sched.h>
56787 +#include <linux/timer.h>
56788 +#include <linux/gracl.h>
56789 +#include <linux/grsecurity.h>
56790 +#include <linux/grinternal.h>
56791 +
56792 +static struct crash_uid *uid_set;
56793 +static unsigned short uid_used;
56794 +static DEFINE_SPINLOCK(gr_uid_lock);
56795 +extern rwlock_t gr_inode_lock;
56796 +extern struct acl_subject_label *
56797 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56798 + struct acl_role_label *role);
56799 +
56800 +#ifdef CONFIG_BTRFS_FS
56801 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56802 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56803 +#endif
56804 +
56805 +static inline dev_t __get_dev(const struct dentry *dentry)
56806 +{
56807 +#ifdef CONFIG_BTRFS_FS
56808 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56809 + return get_btrfs_dev_from_inode(dentry->d_inode);
56810 + else
56811 +#endif
56812 + return dentry->d_inode->i_sb->s_dev;
56813 +}
56814 +
56815 +int
56816 +gr_init_uidset(void)
56817 +{
56818 + uid_set =
56819 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56820 + uid_used = 0;
56821 +
56822 + return uid_set ? 1 : 0;
56823 +}
56824 +
56825 +void
56826 +gr_free_uidset(void)
56827 +{
56828 + if (uid_set)
56829 + kfree(uid_set);
56830 +
56831 + return;
56832 +}
56833 +
56834 +int
56835 +gr_find_uid(const uid_t uid)
56836 +{
56837 + struct crash_uid *tmp = uid_set;
56838 + uid_t buid;
56839 + int low = 0, high = uid_used - 1, mid;
56840 +
56841 + while (high >= low) {
56842 + mid = (low + high) >> 1;
56843 + buid = tmp[mid].uid;
56844 + if (buid == uid)
56845 + return mid;
56846 + if (buid > uid)
56847 + high = mid - 1;
56848 + if (buid < uid)
56849 + low = mid + 1;
56850 + }
56851 +
56852 + return -1;
56853 +}
56854 +
56855 +static __inline__ void
56856 +gr_insertsort(void)
56857 +{
56858 + unsigned short i, j;
56859 + struct crash_uid index;
56860 +
56861 + for (i = 1; i < uid_used; i++) {
56862 + index = uid_set[i];
56863 + j = i;
56864 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56865 + uid_set[j] = uid_set[j - 1];
56866 + j--;
56867 + }
56868 + uid_set[j] = index;
56869 + }
56870 +
56871 + return;
56872 +}
56873 +
56874 +static __inline__ void
56875 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56876 +{
56877 + int loc;
56878 +
56879 + if (uid_used == GR_UIDTABLE_MAX)
56880 + return;
56881 +
56882 + loc = gr_find_uid(uid);
56883 +
56884 + if (loc >= 0) {
56885 + uid_set[loc].expires = expires;
56886 + return;
56887 + }
56888 +
56889 + uid_set[uid_used].uid = uid;
56890 + uid_set[uid_used].expires = expires;
56891 + uid_used++;
56892 +
56893 + gr_insertsort();
56894 +
56895 + return;
56896 +}
56897 +
56898 +void
56899 +gr_remove_uid(const unsigned short loc)
56900 +{
56901 + unsigned short i;
56902 +
56903 + for (i = loc + 1; i < uid_used; i++)
56904 + uid_set[i - 1] = uid_set[i];
56905 +
56906 + uid_used--;
56907 +
56908 + return;
56909 +}
56910 +
56911 +int
56912 +gr_check_crash_uid(const uid_t uid)
56913 +{
56914 + int loc;
56915 + int ret = 0;
56916 +
56917 + if (unlikely(!gr_acl_is_enabled()))
56918 + return 0;
56919 +
56920 + spin_lock(&gr_uid_lock);
56921 + loc = gr_find_uid(uid);
56922 +
56923 + if (loc < 0)
56924 + goto out_unlock;
56925 +
56926 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56927 + gr_remove_uid(loc);
56928 + else
56929 + ret = 1;
56930 +
56931 +out_unlock:
56932 + spin_unlock(&gr_uid_lock);
56933 + return ret;
56934 +}
56935 +
56936 +static __inline__ int
56937 +proc_is_setxid(const struct cred *cred)
56938 +{
56939 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56940 + cred->uid != cred->fsuid)
56941 + return 1;
56942 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56943 + cred->gid != cred->fsgid)
56944 + return 1;
56945 +
56946 + return 0;
56947 +}
56948 +
56949 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56950 +
56951 +void
56952 +gr_handle_crash(struct task_struct *task, const int sig)
56953 +{
56954 + struct acl_subject_label *curr;
56955 + struct acl_subject_label *curr2;
56956 + struct task_struct *tsk, *tsk2;
56957 + const struct cred *cred;
56958 + const struct cred *cred2;
56959 +
56960 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56961 + return;
56962 +
56963 + if (unlikely(!gr_acl_is_enabled()))
56964 + return;
56965 +
56966 + curr = task->acl;
56967 +
56968 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56969 + return;
56970 +
56971 + if (time_before_eq(curr->expires, get_seconds())) {
56972 + curr->expires = 0;
56973 + curr->crashes = 0;
56974 + }
56975 +
56976 + curr->crashes++;
56977 +
56978 + if (!curr->expires)
56979 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56980 +
56981 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56982 + time_after(curr->expires, get_seconds())) {
56983 + rcu_read_lock();
56984 + cred = __task_cred(task);
56985 + if (cred->uid && proc_is_setxid(cred)) {
56986 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56987 + spin_lock(&gr_uid_lock);
56988 + gr_insert_uid(cred->uid, curr->expires);
56989 + spin_unlock(&gr_uid_lock);
56990 + curr->expires = 0;
56991 + curr->crashes = 0;
56992 + read_lock(&tasklist_lock);
56993 + do_each_thread(tsk2, tsk) {
56994 + cred2 = __task_cred(tsk);
56995 + if (tsk != task && cred2->uid == cred->uid)
56996 + gr_fake_force_sig(SIGKILL, tsk);
56997 + } while_each_thread(tsk2, tsk);
56998 + read_unlock(&tasklist_lock);
56999 + } else {
57000 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57001 + read_lock(&tasklist_lock);
57002 + do_each_thread(tsk2, tsk) {
57003 + if (likely(tsk != task)) {
57004 + curr2 = tsk->acl;
57005 +
57006 + if (curr2->device == curr->device &&
57007 + curr2->inode == curr->inode)
57008 + gr_fake_force_sig(SIGKILL, tsk);
57009 + }
57010 + } while_each_thread(tsk2, tsk);
57011 + read_unlock(&tasklist_lock);
57012 + }
57013 + rcu_read_unlock();
57014 + }
57015 +
57016 + return;
57017 +}
57018 +
57019 +int
57020 +gr_check_crash_exec(const struct file *filp)
57021 +{
57022 + struct acl_subject_label *curr;
57023 +
57024 + if (unlikely(!gr_acl_is_enabled()))
57025 + return 0;
57026 +
57027 + read_lock(&gr_inode_lock);
57028 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57029 + __get_dev(filp->f_path.dentry),
57030 + current->role);
57031 + read_unlock(&gr_inode_lock);
57032 +
57033 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57034 + (!curr->crashes && !curr->expires))
57035 + return 0;
57036 +
57037 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57038 + time_after(curr->expires, get_seconds()))
57039 + return 1;
57040 + else if (time_before_eq(curr->expires, get_seconds())) {
57041 + curr->crashes = 0;
57042 + curr->expires = 0;
57043 + }
57044 +
57045 + return 0;
57046 +}
57047 +
57048 +void
57049 +gr_handle_alertkill(struct task_struct *task)
57050 +{
57051 + struct acl_subject_label *curracl;
57052 + __u32 curr_ip;
57053 + struct task_struct *p, *p2;
57054 +
57055 + if (unlikely(!gr_acl_is_enabled()))
57056 + return;
57057 +
57058 + curracl = task->acl;
57059 + curr_ip = task->signal->curr_ip;
57060 +
57061 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57062 + read_lock(&tasklist_lock);
57063 + do_each_thread(p2, p) {
57064 + if (p->signal->curr_ip == curr_ip)
57065 + gr_fake_force_sig(SIGKILL, p);
57066 + } while_each_thread(p2, p);
57067 + read_unlock(&tasklist_lock);
57068 + } else if (curracl->mode & GR_KILLPROC)
57069 + gr_fake_force_sig(SIGKILL, task);
57070 +
57071 + return;
57072 +}
57073 diff -urNp linux-2.6.39.2/grsecurity/gracl_shm.c linux-2.6.39.2/grsecurity/gracl_shm.c
57074 --- linux-2.6.39.2/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
57075 +++ linux-2.6.39.2/grsecurity/gracl_shm.c 2011-05-22 19:41:42.000000000 -0400
57076 @@ -0,0 +1,40 @@
57077 +#include <linux/kernel.h>
57078 +#include <linux/mm.h>
57079 +#include <linux/sched.h>
57080 +#include <linux/file.h>
57081 +#include <linux/ipc.h>
57082 +#include <linux/gracl.h>
57083 +#include <linux/grsecurity.h>
57084 +#include <linux/grinternal.h>
57085 +
57086 +int
57087 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57088 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57089 +{
57090 + struct task_struct *task;
57091 +
57092 + if (!gr_acl_is_enabled())
57093 + return 1;
57094 +
57095 + rcu_read_lock();
57096 + read_lock(&tasklist_lock);
57097 +
57098 + task = find_task_by_vpid(shm_cprid);
57099 +
57100 + if (unlikely(!task))
57101 + task = find_task_by_vpid(shm_lapid);
57102 +
57103 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57104 + (task->pid == shm_lapid)) &&
57105 + (task->acl->mode & GR_PROTSHM) &&
57106 + (task->acl != current->acl))) {
57107 + read_unlock(&tasklist_lock);
57108 + rcu_read_unlock();
57109 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57110 + return 0;
57111 + }
57112 + read_unlock(&tasklist_lock);
57113 + rcu_read_unlock();
57114 +
57115 + return 1;
57116 +}
57117 diff -urNp linux-2.6.39.2/grsecurity/grsec_chdir.c linux-2.6.39.2/grsecurity/grsec_chdir.c
57118 --- linux-2.6.39.2/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
57119 +++ linux-2.6.39.2/grsecurity/grsec_chdir.c 2011-05-22 19:41:42.000000000 -0400
57120 @@ -0,0 +1,19 @@
57121 +#include <linux/kernel.h>
57122 +#include <linux/sched.h>
57123 +#include <linux/fs.h>
57124 +#include <linux/file.h>
57125 +#include <linux/grsecurity.h>
57126 +#include <linux/grinternal.h>
57127 +
57128 +void
57129 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57130 +{
57131 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57132 + if ((grsec_enable_chdir && grsec_enable_group &&
57133 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57134 + !grsec_enable_group)) {
57135 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57136 + }
57137 +#endif
57138 + return;
57139 +}
57140 diff -urNp linux-2.6.39.2/grsecurity/grsec_chroot.c linux-2.6.39.2/grsecurity/grsec_chroot.c
57141 --- linux-2.6.39.2/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
57142 +++ linux-2.6.39.2/grsecurity/grsec_chroot.c 2011-06-20 19:44:48.000000000 -0400
57143 @@ -0,0 +1,355 @@
57144 +#include <linux/kernel.h>
57145 +#include <linux/module.h>
57146 +#include <linux/sched.h>
57147 +#include <linux/file.h>
57148 +#include <linux/fs.h>
57149 +#include <linux/mount.h>
57150 +#include <linux/types.h>
57151 +#include <linux/pid_namespace.h>
57152 +#include <linux/grsecurity.h>
57153 +#include <linux/grinternal.h>
57154 +
57155 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57156 +{
57157 +#ifdef CONFIG_GRKERNSEC
57158 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57159 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
57160 + task->gr_is_chrooted = 1;
57161 + else
57162 + task->gr_is_chrooted = 0;
57163 +
57164 + task->gr_chroot_dentry = path->dentry;
57165 +#endif
57166 + return;
57167 +}
57168 +
57169 +void gr_clear_chroot_entries(struct task_struct *task)
57170 +{
57171 +#ifdef CONFIG_GRKERNSEC
57172 + task->gr_is_chrooted = 0;
57173 + task->gr_chroot_dentry = NULL;
57174 +#endif
57175 + return;
57176 +}
57177 +
57178 +int
57179 +gr_handle_chroot_unix(struct pid *pid)
57180 +{
57181 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57182 + struct task_struct *p;
57183 +
57184 + if (unlikely(!grsec_enable_chroot_unix))
57185 + return 1;
57186 +
57187 + if (likely(!proc_is_chrooted(current)))
57188 + return 1;
57189 +
57190 + rcu_read_lock();
57191 + read_lock(&tasklist_lock);
57192 + p = pid_task(pid, PIDTYPE_PID);
57193 + if (unlikely(p && !have_same_root(current, p))) {
57194 + read_unlock(&tasklist_lock);
57195 + rcu_read_unlock();
57196 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57197 + return 0;
57198 + }
57199 + read_unlock(&tasklist_lock);
57200 + rcu_read_unlock();
57201 +#endif
57202 + return 1;
57203 +}
57204 +
57205 +int
57206 +gr_handle_chroot_nice(void)
57207 +{
57208 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57209 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57210 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57211 + return -EPERM;
57212 + }
57213 +#endif
57214 + return 0;
57215 +}
57216 +
57217 +int
57218 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57219 +{
57220 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57221 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57222 + && proc_is_chrooted(current)) {
57223 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57224 + return -EACCES;
57225 + }
57226 +#endif
57227 + return 0;
57228 +}
57229 +
57230 +int
57231 +gr_handle_chroot_rawio(const struct inode *inode)
57232 +{
57233 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57234 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57235 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57236 + return 1;
57237 +#endif
57238 + return 0;
57239 +}
57240 +
57241 +int
57242 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57243 +{
57244 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57245 + struct task_struct *p;
57246 + int ret = 0;
57247 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57248 + return ret;
57249 +
57250 + read_lock(&tasklist_lock);
57251 + do_each_pid_task(pid, type, p) {
57252 + if (!have_same_root(current, p)) {
57253 + ret = 1;
57254 + goto out;
57255 + }
57256 + } while_each_pid_task(pid, type, p);
57257 +out:
57258 + read_unlock(&tasklist_lock);
57259 + return ret;
57260 +#endif
57261 + return 0;
57262 +}
57263 +
57264 +int
57265 +gr_pid_is_chrooted(struct task_struct *p)
57266 +{
57267 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57268 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57269 + return 0;
57270 +
57271 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57272 + !have_same_root(current, p)) {
57273 + return 1;
57274 + }
57275 +#endif
57276 + return 0;
57277 +}
57278 +
57279 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57280 +
57281 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57282 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57283 +{
57284 + struct path path, currentroot;
57285 + int ret = 0;
57286 +
57287 + path.dentry = (struct dentry *)u_dentry;
57288 + path.mnt = (struct vfsmount *)u_mnt;
57289 + get_fs_root(current->fs, &currentroot);
57290 + if (path_is_under(&path, &currentroot))
57291 + ret = 1;
57292 + path_put(&currentroot);
57293 +
57294 + return ret;
57295 +}
57296 +#endif
57297 +
57298 +int
57299 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57300 +{
57301 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57302 + if (!grsec_enable_chroot_fchdir)
57303 + return 1;
57304 +
57305 + if (!proc_is_chrooted(current))
57306 + return 1;
57307 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57308 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57309 + return 0;
57310 + }
57311 +#endif
57312 + return 1;
57313 +}
57314 +
57315 +int
57316 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57317 + const time_t shm_createtime)
57318 +{
57319 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57320 + struct pid *pid = NULL;
57321 + time_t starttime;
57322 +
57323 + if (unlikely(!grsec_enable_chroot_shmat))
57324 + return 1;
57325 +
57326 + if (likely(!proc_is_chrooted(current)))
57327 + return 1;
57328 +
57329 + rcu_read_lock();
57330 + read_lock(&tasklist_lock);
57331 +
57332 + pid = find_vpid(shm_cprid);
57333 + if (pid) {
57334 + struct task_struct *p;
57335 + p = pid_task(pid, PIDTYPE_PID);
57336 + if (p == NULL)
57337 + goto unlock;
57338 + starttime = p->start_time.tv_sec;
57339 + if (unlikely(!have_same_root(current, p) &&
57340 + time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
57341 + read_unlock(&tasklist_lock);
57342 + rcu_read_unlock();
57343 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57344 + return 0;
57345 + }
57346 + } else {
57347 + pid = find_vpid(shm_lapid);
57348 + if (pid) {
57349 + struct task_struct *p;
57350 + p = pid_task(pid, PIDTYPE_PID);
57351 + if (p == NULL)
57352 + goto unlock;
57353 + if (unlikely(!have_same_root(current, p))) {
57354 + read_unlock(&tasklist_lock);
57355 + rcu_read_unlock();
57356 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57357 + return 0;
57358 + }
57359 + }
57360 + }
57361 +unlock:
57362 + read_unlock(&tasklist_lock);
57363 + rcu_read_unlock();
57364 +#endif
57365 + return 1;
57366 +}
57367 +
57368 +void
57369 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57370 +{
57371 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57372 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57373 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57374 +#endif
57375 + return;
57376 +}
57377 +
57378 +int
57379 +gr_handle_chroot_mknod(const struct dentry *dentry,
57380 + const struct vfsmount *mnt, const int mode)
57381 +{
57382 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57383 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57384 + proc_is_chrooted(current)) {
57385 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57386 + return -EPERM;
57387 + }
57388 +#endif
57389 + return 0;
57390 +}
57391 +
57392 +int
57393 +gr_handle_chroot_mount(const struct dentry *dentry,
57394 + const struct vfsmount *mnt, const char *dev_name)
57395 +{
57396 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57397 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57398 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57399 + return -EPERM;
57400 + }
57401 +#endif
57402 + return 0;
57403 +}
57404 +
57405 +int
57406 +gr_handle_chroot_pivot(void)
57407 +{
57408 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57409 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57410 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57411 + return -EPERM;
57412 + }
57413 +#endif
57414 + return 0;
57415 +}
57416 +
57417 +int
57418 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57419 +{
57420 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57421 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57422 + !gr_is_outside_chroot(dentry, mnt)) {
57423 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57424 + return -EPERM;
57425 + }
57426 +#endif
57427 + return 0;
57428 +}
57429 +
57430 +int
57431 +gr_handle_chroot_caps(struct path *path)
57432 +{
57433 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57434 + if (grsec_enable_chroot_caps && current->pid > 1 && current->fs != NULL &&
57435 + (init_task.fs->root.dentry != path->dentry) &&
57436 + (current->nsproxy->mnt_ns->root->mnt_root != path->dentry)) {
57437 +
57438 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57439 + const struct cred *old = current_cred();
57440 + struct cred *new = prepare_creds();
57441 + if (new == NULL)
57442 + return 1;
57443 +
57444 + new->cap_permitted = cap_drop(old->cap_permitted,
57445 + chroot_caps);
57446 + new->cap_inheritable = cap_drop(old->cap_inheritable,
57447 + chroot_caps);
57448 + new->cap_effective = cap_drop(old->cap_effective,
57449 + chroot_caps);
57450 +
57451 + commit_creds(new);
57452 +
57453 + return 0;
57454 + }
57455 +#endif
57456 + return 0;
57457 +}
57458 +
57459 +int
57460 +gr_handle_chroot_sysctl(const int op)
57461 +{
57462 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57463 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57464 + proc_is_chrooted(current))
57465 + return -EACCES;
57466 +#endif
57467 + return 0;
57468 +}
57469 +
57470 +void
57471 +gr_handle_chroot_chdir(struct path *path)
57472 +{
57473 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57474 + if (grsec_enable_chroot_chdir)
57475 + set_fs_pwd(current->fs, path);
57476 +#endif
57477 + return;
57478 +}
57479 +
57480 +int
57481 +gr_handle_chroot_chmod(const struct dentry *dentry,
57482 + const struct vfsmount *mnt, const int mode)
57483 +{
57484 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57485 + /* allow chmod +s on directories, but not files */
57486 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57487 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57488 + proc_is_chrooted(current)) {
57489 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57490 + return -EPERM;
57491 + }
57492 +#endif
57493 + return 0;
57494 +}
57495 +
57496 +#ifdef CONFIG_SECURITY
57497 +EXPORT_SYMBOL(gr_handle_chroot_caps);
57498 +#endif
57499 diff -urNp linux-2.6.39.2/grsecurity/grsec_disabled.c linux-2.6.39.2/grsecurity/grsec_disabled.c
57500 --- linux-2.6.39.2/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
57501 +++ linux-2.6.39.2/grsecurity/grsec_disabled.c 2011-05-22 19:41:42.000000000 -0400
57502 @@ -0,0 +1,447 @@
57503 +#include <linux/kernel.h>
57504 +#include <linux/module.h>
57505 +#include <linux/sched.h>
57506 +#include <linux/file.h>
57507 +#include <linux/fs.h>
57508 +#include <linux/kdev_t.h>
57509 +#include <linux/net.h>
57510 +#include <linux/in.h>
57511 +#include <linux/ip.h>
57512 +#include <linux/skbuff.h>
57513 +#include <linux/sysctl.h>
57514 +
57515 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57516 +void
57517 +pax_set_initial_flags(struct linux_binprm *bprm)
57518 +{
57519 + return;
57520 +}
57521 +#endif
57522 +
57523 +#ifdef CONFIG_SYSCTL
57524 +__u32
57525 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57526 +{
57527 + return 0;
57528 +}
57529 +#endif
57530 +
57531 +#ifdef CONFIG_TASKSTATS
57532 +int gr_is_taskstats_denied(int pid)
57533 +{
57534 + return 0;
57535 +}
57536 +#endif
57537 +
57538 +int
57539 +gr_acl_is_enabled(void)
57540 +{
57541 + return 0;
57542 +}
57543 +
57544 +int
57545 +gr_handle_rawio(const struct inode *inode)
57546 +{
57547 + return 0;
57548 +}
57549 +
57550 +void
57551 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57552 +{
57553 + return;
57554 +}
57555 +
57556 +int
57557 +gr_handle_ptrace(struct task_struct *task, const long request)
57558 +{
57559 + return 0;
57560 +}
57561 +
57562 +int
57563 +gr_handle_proc_ptrace(struct task_struct *task)
57564 +{
57565 + return 0;
57566 +}
57567 +
57568 +void
57569 +gr_learn_resource(const struct task_struct *task,
57570 + const int res, const unsigned long wanted, const int gt)
57571 +{
57572 + return;
57573 +}
57574 +
57575 +int
57576 +gr_set_acls(const int type)
57577 +{
57578 + return 0;
57579 +}
57580 +
57581 +int
57582 +gr_check_hidden_task(const struct task_struct *tsk)
57583 +{
57584 + return 0;
57585 +}
57586 +
57587 +int
57588 +gr_check_protected_task(const struct task_struct *task)
57589 +{
57590 + return 0;
57591 +}
57592 +
57593 +int
57594 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57595 +{
57596 + return 0;
57597 +}
57598 +
57599 +void
57600 +gr_copy_label(struct task_struct *tsk)
57601 +{
57602 + return;
57603 +}
57604 +
57605 +void
57606 +gr_set_pax_flags(struct task_struct *task)
57607 +{
57608 + return;
57609 +}
57610 +
57611 +int
57612 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57613 + const int unsafe_share)
57614 +{
57615 + return 0;
57616 +}
57617 +
57618 +void
57619 +gr_handle_delete(const ino_t ino, const dev_t dev)
57620 +{
57621 + return;
57622 +}
57623 +
57624 +void
57625 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57626 +{
57627 + return;
57628 +}
57629 +
57630 +void
57631 +gr_handle_crash(struct task_struct *task, const int sig)
57632 +{
57633 + return;
57634 +}
57635 +
57636 +int
57637 +gr_check_crash_exec(const struct file *filp)
57638 +{
57639 + return 0;
57640 +}
57641 +
57642 +int
57643 +gr_check_crash_uid(const uid_t uid)
57644 +{
57645 + return 0;
57646 +}
57647 +
57648 +void
57649 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57650 + struct dentry *old_dentry,
57651 + struct dentry *new_dentry,
57652 + struct vfsmount *mnt, const __u8 replace)
57653 +{
57654 + return;
57655 +}
57656 +
57657 +int
57658 +gr_search_socket(const int family, const int type, const int protocol)
57659 +{
57660 + return 1;
57661 +}
57662 +
57663 +int
57664 +gr_search_connectbind(const int mode, const struct socket *sock,
57665 + const struct sockaddr_in *addr)
57666 +{
57667 + return 0;
57668 +}
57669 +
57670 +int
57671 +gr_is_capable(const int cap)
57672 +{
57673 + return 1;
57674 +}
57675 +
57676 +int
57677 +gr_is_capable_nolog(const int cap)
57678 +{
57679 + return 1;
57680 +}
57681 +
57682 +void
57683 +gr_handle_alertkill(struct task_struct *task)
57684 +{
57685 + return;
57686 +}
57687 +
57688 +__u32
57689 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57690 +{
57691 + return 1;
57692 +}
57693 +
57694 +__u32
57695 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57696 + const struct vfsmount * mnt)
57697 +{
57698 + return 1;
57699 +}
57700 +
57701 +__u32
57702 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57703 + const int fmode)
57704 +{
57705 + return 1;
57706 +}
57707 +
57708 +__u32
57709 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57710 +{
57711 + return 1;
57712 +}
57713 +
57714 +__u32
57715 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57716 +{
57717 + return 1;
57718 +}
57719 +
57720 +int
57721 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57722 + unsigned int *vm_flags)
57723 +{
57724 + return 1;
57725 +}
57726 +
57727 +__u32
57728 +gr_acl_handle_truncate(const struct dentry * dentry,
57729 + const struct vfsmount * mnt)
57730 +{
57731 + return 1;
57732 +}
57733 +
57734 +__u32
57735 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57736 +{
57737 + return 1;
57738 +}
57739 +
57740 +__u32
57741 +gr_acl_handle_access(const struct dentry * dentry,
57742 + const struct vfsmount * mnt, const int fmode)
57743 +{
57744 + return 1;
57745 +}
57746 +
57747 +__u32
57748 +gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
57749 + mode_t mode)
57750 +{
57751 + return 1;
57752 +}
57753 +
57754 +__u32
57755 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57756 + mode_t mode)
57757 +{
57758 + return 1;
57759 +}
57760 +
57761 +__u32
57762 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57763 +{
57764 + return 1;
57765 +}
57766 +
57767 +__u32
57768 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57769 +{
57770 + return 1;
57771 +}
57772 +
57773 +void
57774 +grsecurity_init(void)
57775 +{
57776 + return;
57777 +}
57778 +
57779 +__u32
57780 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57781 + const struct dentry * parent_dentry,
57782 + const struct vfsmount * parent_mnt,
57783 + const int mode)
57784 +{
57785 + return 1;
57786 +}
57787 +
57788 +__u32
57789 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57790 + const struct dentry * parent_dentry,
57791 + const struct vfsmount * parent_mnt)
57792 +{
57793 + return 1;
57794 +}
57795 +
57796 +__u32
57797 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57798 + const struct dentry * parent_dentry,
57799 + const struct vfsmount * parent_mnt, const char *from)
57800 +{
57801 + return 1;
57802 +}
57803 +
57804 +__u32
57805 +gr_acl_handle_link(const struct dentry * new_dentry,
57806 + const struct dentry * parent_dentry,
57807 + const struct vfsmount * parent_mnt,
57808 + const struct dentry * old_dentry,
57809 + const struct vfsmount * old_mnt, const char *to)
57810 +{
57811 + return 1;
57812 +}
57813 +
57814 +int
57815 +gr_acl_handle_rename(const struct dentry *new_dentry,
57816 + const struct dentry *parent_dentry,
57817 + const struct vfsmount *parent_mnt,
57818 + const struct dentry *old_dentry,
57819 + const struct inode *old_parent_inode,
57820 + const struct vfsmount *old_mnt, const char *newname)
57821 +{
57822 + return 0;
57823 +}
57824 +
57825 +int
57826 +gr_acl_handle_filldir(const struct file *file, const char *name,
57827 + const int namelen, const ino_t ino)
57828 +{
57829 + return 1;
57830 +}
57831 +
57832 +int
57833 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57834 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57835 +{
57836 + return 1;
57837 +}
57838 +
57839 +int
57840 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57841 +{
57842 + return 0;
57843 +}
57844 +
57845 +int
57846 +gr_search_accept(const struct socket *sock)
57847 +{
57848 + return 0;
57849 +}
57850 +
57851 +int
57852 +gr_search_listen(const struct socket *sock)
57853 +{
57854 + return 0;
57855 +}
57856 +
57857 +int
57858 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57859 +{
57860 + return 0;
57861 +}
57862 +
57863 +__u32
57864 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57865 +{
57866 + return 1;
57867 +}
57868 +
57869 +__u32
57870 +gr_acl_handle_creat(const struct dentry * dentry,
57871 + const struct dentry * p_dentry,
57872 + const struct vfsmount * p_mnt, const int fmode,
57873 + const int imode)
57874 +{
57875 + return 1;
57876 +}
57877 +
57878 +void
57879 +gr_acl_handle_exit(void)
57880 +{
57881 + return;
57882 +}
57883 +
57884 +int
57885 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57886 +{
57887 + return 1;
57888 +}
57889 +
57890 +void
57891 +gr_set_role_label(const uid_t uid, const gid_t gid)
57892 +{
57893 + return;
57894 +}
57895 +
57896 +int
57897 +gr_acl_handle_procpidmem(const struct task_struct *task)
57898 +{
57899 + return 0;
57900 +}
57901 +
57902 +int
57903 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57904 +{
57905 + return 0;
57906 +}
57907 +
57908 +int
57909 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57910 +{
57911 + return 0;
57912 +}
57913 +
57914 +void
57915 +gr_set_kernel_label(struct task_struct *task)
57916 +{
57917 + return;
57918 +}
57919 +
57920 +int
57921 +gr_check_user_change(int real, int effective, int fs)
57922 +{
57923 + return 0;
57924 +}
57925 +
57926 +int
57927 +gr_check_group_change(int real, int effective, int fs)
57928 +{
57929 + return 0;
57930 +}
57931 +
57932 +int gr_acl_enable_at_secure(void)
57933 +{
57934 + return 0;
57935 +}
57936 +
57937 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57938 +{
57939 + return dentry->d_inode->i_sb->s_dev;
57940 +}
57941 +
57942 +EXPORT_SYMBOL(gr_is_capable);
57943 +EXPORT_SYMBOL(gr_is_capable_nolog);
57944 +EXPORT_SYMBOL(gr_learn_resource);
57945 +EXPORT_SYMBOL(gr_set_kernel_label);
57946 +#ifdef CONFIG_SECURITY
57947 +EXPORT_SYMBOL(gr_check_user_change);
57948 +EXPORT_SYMBOL(gr_check_group_change);
57949 +#endif
57950 diff -urNp linux-2.6.39.2/grsecurity/grsec_exec.c linux-2.6.39.2/grsecurity/grsec_exec.c
57951 --- linux-2.6.39.2/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
57952 +++ linux-2.6.39.2/grsecurity/grsec_exec.c 2011-05-22 22:41:29.000000000 -0400
57953 @@ -0,0 +1,146 @@
57954 +#include <linux/kernel.h>
57955 +#include <linux/sched.h>
57956 +#include <linux/file.h>
57957 +#include <linux/binfmts.h>
57958 +#include <linux/fs.h>
57959 +#include <linux/types.h>
57960 +#include <linux/grdefs.h>
57961 +#include <linux/grinternal.h>
57962 +#include <linux/capability.h>
57963 +#include <linux/compat.h>
57964 +
57965 +#include <asm/uaccess.h>
57966 +
57967 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57968 +static char gr_exec_arg_buf[132];
57969 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57970 +#endif
57971 +
57972 +int
57973 +gr_handle_nproc(void)
57974 +{
57975 +#ifdef CONFIG_GRKERNSEC_EXECVE
57976 + const struct cred *cred = current_cred();
57977 + if (grsec_enable_execve && cred->user &&
57978 + (atomic_read(&cred->user->processes) > rlimit(RLIMIT_NPROC)) &&
57979 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
57980 + gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
57981 + return -EAGAIN;
57982 + }
57983 +#endif
57984 + return 0;
57985 +}
57986 +
57987 +void
57988 +gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
57989 +{
57990 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57991 + char *grarg = gr_exec_arg_buf;
57992 + unsigned int i, x, execlen = 0;
57993 + char c;
57994 +
57995 + if (!((grsec_enable_execlog && grsec_enable_group &&
57996 + in_group_p(grsec_audit_gid))
57997 + || (grsec_enable_execlog && !grsec_enable_group)))
57998 + return;
57999 +
58000 + mutex_lock(&gr_exec_arg_mutex);
58001 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58002 +
58003 + if (unlikely(argv == NULL))
58004 + goto log;
58005 +
58006 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58007 + const char __user *p;
58008 + unsigned int len;
58009 +
58010 + if (copy_from_user(&p, argv + i, sizeof(p)))
58011 + goto log;
58012 + if (!p)
58013 + goto log;
58014 + len = strnlen_user(p, 128 - execlen);
58015 + if (len > 128 - execlen)
58016 + len = 128 - execlen;
58017 + else if (len > 0)
58018 + len--;
58019 + if (copy_from_user(grarg + execlen, p, len))
58020 + goto log;
58021 +
58022 + /* rewrite unprintable characters */
58023 + for (x = 0; x < len; x++) {
58024 + c = *(grarg + execlen + x);
58025 + if (c < 32 || c > 126)
58026 + *(grarg + execlen + x) = ' ';
58027 + }
58028 +
58029 + execlen += len;
58030 + *(grarg + execlen) = ' ';
58031 + *(grarg + execlen + 1) = '\0';
58032 + execlen++;
58033 + }
58034 +
58035 + log:
58036 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58037 + bprm->file->f_path.mnt, grarg);
58038 + mutex_unlock(&gr_exec_arg_mutex);
58039 +#endif
58040 + return;
58041 +}
58042 +
58043 +#ifdef CONFIG_COMPAT
58044 +void
58045 +gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
58046 +{
58047 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58048 + char *grarg = gr_exec_arg_buf;
58049 + unsigned int i, x, execlen = 0;
58050 + char c;
58051 +
58052 + if (!((grsec_enable_execlog && grsec_enable_group &&
58053 + in_group_p(grsec_audit_gid))
58054 + || (grsec_enable_execlog && !grsec_enable_group)))
58055 + return;
58056 +
58057 + mutex_lock(&gr_exec_arg_mutex);
58058 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58059 +
58060 + if (unlikely(argv == NULL))
58061 + goto log;
58062 +
58063 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58064 + compat_uptr_t p;
58065 + unsigned int len;
58066 +
58067 + if (get_user(p, argv + i))
58068 + goto log;
58069 + len = strnlen_user(compat_ptr(p), 128 - execlen);
58070 + if (len > 128 - execlen)
58071 + len = 128 - execlen;
58072 + else if (len > 0)
58073 + len--;
58074 + else
58075 + goto log;
58076 + if (copy_from_user(grarg + execlen, compat_ptr(p), len))
58077 + goto log;
58078 +
58079 + /* rewrite unprintable characters */
58080 + for (x = 0; x < len; x++) {
58081 + c = *(grarg + execlen + x);
58082 + if (c < 32 || c > 126)
58083 + *(grarg + execlen + x) = ' ';
58084 + }
58085 +
58086 + execlen += len;
58087 + *(grarg + execlen) = ' ';
58088 + *(grarg + execlen + 1) = '\0';
58089 + execlen++;
58090 + }
58091 +
58092 + log:
58093 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58094 + bprm->file->f_path.mnt, grarg);
58095 + mutex_unlock(&gr_exec_arg_mutex);
58096 +#endif
58097 + return;
58098 +}
58099 +#endif
58100 diff -urNp linux-2.6.39.2/grsecurity/grsec_fifo.c linux-2.6.39.2/grsecurity/grsec_fifo.c
58101 --- linux-2.6.39.2/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
58102 +++ linux-2.6.39.2/grsecurity/grsec_fifo.c 2011-05-22 19:41:42.000000000 -0400
58103 @@ -0,0 +1,24 @@
58104 +#include <linux/kernel.h>
58105 +#include <linux/sched.h>
58106 +#include <linux/fs.h>
58107 +#include <linux/file.h>
58108 +#include <linux/grinternal.h>
58109 +
58110 +int
58111 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58112 + const struct dentry *dir, const int flag, const int acc_mode)
58113 +{
58114 +#ifdef CONFIG_GRKERNSEC_FIFO
58115 + const struct cred *cred = current_cred();
58116 +
58117 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58118 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58119 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58120 + (cred->fsuid != dentry->d_inode->i_uid)) {
58121 + if (!inode_permission(dentry->d_inode, acc_mode))
58122 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58123 + return -EACCES;
58124 + }
58125 +#endif
58126 + return 0;
58127 +}
58128 diff -urNp linux-2.6.39.2/grsecurity/grsec_fork.c linux-2.6.39.2/grsecurity/grsec_fork.c
58129 --- linux-2.6.39.2/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
58130 +++ linux-2.6.39.2/grsecurity/grsec_fork.c 2011-05-22 19:41:42.000000000 -0400
58131 @@ -0,0 +1,23 @@
58132 +#include <linux/kernel.h>
58133 +#include <linux/sched.h>
58134 +#include <linux/grsecurity.h>
58135 +#include <linux/grinternal.h>
58136 +#include <linux/errno.h>
58137 +
58138 +void
58139 +gr_log_forkfail(const int retval)
58140 +{
58141 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58142 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58143 + switch (retval) {
58144 + case -EAGAIN:
58145 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58146 + break;
58147 + case -ENOMEM:
58148 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58149 + break;
58150 + }
58151 + }
58152 +#endif
58153 + return;
58154 +}
58155 diff -urNp linux-2.6.39.2/grsecurity/grsec_init.c linux-2.6.39.2/grsecurity/grsec_init.c
58156 --- linux-2.6.39.2/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
58157 +++ linux-2.6.39.2/grsecurity/grsec_init.c 2011-05-22 22:47:15.000000000 -0400
58158 @@ -0,0 +1,269 @@
58159 +#include <linux/kernel.h>
58160 +#include <linux/sched.h>
58161 +#include <linux/mm.h>
58162 +#include <linux/gracl.h>
58163 +#include <linux/slab.h>
58164 +#include <linux/vmalloc.h>
58165 +#include <linux/percpu.h>
58166 +#include <linux/module.h>
58167 +
58168 +int grsec_enable_link;
58169 +int grsec_enable_dmesg;
58170 +int grsec_enable_harden_ptrace;
58171 +int grsec_enable_fifo;
58172 +int grsec_enable_execve;
58173 +int grsec_enable_execlog;
58174 +int grsec_enable_signal;
58175 +int grsec_enable_forkfail;
58176 +int grsec_enable_audit_ptrace;
58177 +int grsec_enable_time;
58178 +int grsec_enable_audit_textrel;
58179 +int grsec_enable_group;
58180 +int grsec_audit_gid;
58181 +int grsec_enable_chdir;
58182 +int grsec_enable_mount;
58183 +int grsec_enable_rofs;
58184 +int grsec_enable_chroot_findtask;
58185 +int grsec_enable_chroot_mount;
58186 +int grsec_enable_chroot_shmat;
58187 +int grsec_enable_chroot_fchdir;
58188 +int grsec_enable_chroot_double;
58189 +int grsec_enable_chroot_pivot;
58190 +int grsec_enable_chroot_chdir;
58191 +int grsec_enable_chroot_chmod;
58192 +int grsec_enable_chroot_mknod;
58193 +int grsec_enable_chroot_nice;
58194 +int grsec_enable_chroot_execlog;
58195 +int grsec_enable_chroot_caps;
58196 +int grsec_enable_chroot_sysctl;
58197 +int grsec_enable_chroot_unix;
58198 +int grsec_enable_tpe;
58199 +int grsec_tpe_gid;
58200 +int grsec_enable_blackhole;
58201 +#ifdef CONFIG_IPV6_MODULE
58202 +EXPORT_SYMBOL(grsec_enable_blackhole);
58203 +#endif
58204 +int grsec_lastack_retries;
58205 +int grsec_enable_tpe_all;
58206 +int grsec_enable_tpe_invert;
58207 +int grsec_enable_socket_all;
58208 +int grsec_socket_all_gid;
58209 +int grsec_enable_socket_client;
58210 +int grsec_socket_client_gid;
58211 +int grsec_enable_socket_server;
58212 +int grsec_socket_server_gid;
58213 +int grsec_resource_logging;
58214 +int grsec_disable_privio;
58215 +int grsec_enable_log_rwxmaps;
58216 +int grsec_lock;
58217 +
58218 +DEFINE_SPINLOCK(grsec_alert_lock);
58219 +unsigned long grsec_alert_wtime = 0;
58220 +unsigned long grsec_alert_fyet = 0;
58221 +
58222 +DEFINE_SPINLOCK(grsec_audit_lock);
58223 +
58224 +DEFINE_RWLOCK(grsec_exec_file_lock);
58225 +
58226 +char *gr_shared_page[4];
58227 +
58228 +char *gr_alert_log_fmt;
58229 +char *gr_audit_log_fmt;
58230 +char *gr_alert_log_buf;
58231 +char *gr_audit_log_buf;
58232 +
58233 +extern struct gr_arg *gr_usermode;
58234 +extern unsigned char *gr_system_salt;
58235 +extern unsigned char *gr_system_sum;
58236 +
58237 +void __init
58238 +grsecurity_init(void)
58239 +{
58240 + int j;
58241 + /* create the per-cpu shared pages */
58242 +
58243 +#ifdef CONFIG_X86
58244 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58245 +#endif
58246 +
58247 + for (j = 0; j < 4; j++) {
58248 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58249 + if (gr_shared_page[j] == NULL) {
58250 + panic("Unable to allocate grsecurity shared page");
58251 + return;
58252 + }
58253 + }
58254 +
58255 + /* allocate log buffers */
58256 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58257 + if (!gr_alert_log_fmt) {
58258 + panic("Unable to allocate grsecurity alert log format buffer");
58259 + return;
58260 + }
58261 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58262 + if (!gr_audit_log_fmt) {
58263 + panic("Unable to allocate grsecurity audit log format buffer");
58264 + return;
58265 + }
58266 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58267 + if (!gr_alert_log_buf) {
58268 + panic("Unable to allocate grsecurity alert log buffer");
58269 + return;
58270 + }
58271 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58272 + if (!gr_audit_log_buf) {
58273 + panic("Unable to allocate grsecurity audit log buffer");
58274 + return;
58275 + }
58276 +
58277 + /* allocate memory for authentication structure */
58278 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58279 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58280 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58281 +
58282 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58283 + panic("Unable to allocate grsecurity authentication structure");
58284 + return;
58285 + }
58286 +
58287 +
58288 +#ifdef CONFIG_GRKERNSEC_IO
58289 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58290 + grsec_disable_privio = 1;
58291 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58292 + grsec_disable_privio = 1;
58293 +#else
58294 + grsec_disable_privio = 0;
58295 +#endif
58296 +#endif
58297 +
58298 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58299 + /* for backward compatibility, tpe_invert always defaults to on if
58300 + enabled in the kernel
58301 + */
58302 + grsec_enable_tpe_invert = 1;
58303 +#endif
58304 +
58305 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58306 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58307 + grsec_lock = 1;
58308 +#endif
58309 +
58310 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58311 + grsec_enable_audit_textrel = 1;
58312 +#endif
58313 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58314 + grsec_enable_log_rwxmaps = 1;
58315 +#endif
58316 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58317 + grsec_enable_group = 1;
58318 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58319 +#endif
58320 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58321 + grsec_enable_chdir = 1;
58322 +#endif
58323 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58324 + grsec_enable_harden_ptrace = 1;
58325 +#endif
58326 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58327 + grsec_enable_mount = 1;
58328 +#endif
58329 +#ifdef CONFIG_GRKERNSEC_LINK
58330 + grsec_enable_link = 1;
58331 +#endif
58332 +#ifdef CONFIG_GRKERNSEC_DMESG
58333 + grsec_enable_dmesg = 1;
58334 +#endif
58335 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58336 + grsec_enable_blackhole = 1;
58337 + grsec_lastack_retries = 4;
58338 +#endif
58339 +#ifdef CONFIG_GRKERNSEC_FIFO
58340 + grsec_enable_fifo = 1;
58341 +#endif
58342 +#ifdef CONFIG_GRKERNSEC_EXECVE
58343 + grsec_enable_execve = 1;
58344 +#endif
58345 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58346 + grsec_enable_execlog = 1;
58347 +#endif
58348 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58349 + grsec_enable_signal = 1;
58350 +#endif
58351 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58352 + grsec_enable_forkfail = 1;
58353 +#endif
58354 +#ifdef CONFIG_GRKERNSEC_TIME
58355 + grsec_enable_time = 1;
58356 +#endif
58357 +#ifdef CONFIG_GRKERNSEC_RESLOG
58358 + grsec_resource_logging = 1;
58359 +#endif
58360 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58361 + grsec_enable_chroot_findtask = 1;
58362 +#endif
58363 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58364 + grsec_enable_chroot_unix = 1;
58365 +#endif
58366 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58367 + grsec_enable_chroot_mount = 1;
58368 +#endif
58369 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58370 + grsec_enable_chroot_fchdir = 1;
58371 +#endif
58372 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58373 + grsec_enable_chroot_shmat = 1;
58374 +#endif
58375 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58376 + grsec_enable_audit_ptrace = 1;
58377 +#endif
58378 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58379 + grsec_enable_chroot_double = 1;
58380 +#endif
58381 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58382 + grsec_enable_chroot_pivot = 1;
58383 +#endif
58384 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58385 + grsec_enable_chroot_chdir = 1;
58386 +#endif
58387 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58388 + grsec_enable_chroot_chmod = 1;
58389 +#endif
58390 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58391 + grsec_enable_chroot_mknod = 1;
58392 +#endif
58393 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58394 + grsec_enable_chroot_nice = 1;
58395 +#endif
58396 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58397 + grsec_enable_chroot_execlog = 1;
58398 +#endif
58399 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58400 + grsec_enable_chroot_caps = 1;
58401 +#endif
58402 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58403 + grsec_enable_chroot_sysctl = 1;
58404 +#endif
58405 +#ifdef CONFIG_GRKERNSEC_TPE
58406 + grsec_enable_tpe = 1;
58407 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58408 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58409 + grsec_enable_tpe_all = 1;
58410 +#endif
58411 +#endif
58412 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58413 + grsec_enable_socket_all = 1;
58414 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58415 +#endif
58416 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58417 + grsec_enable_socket_client = 1;
58418 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58419 +#endif
58420 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58421 + grsec_enable_socket_server = 1;
58422 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58423 +#endif
58424 +#endif
58425 +
58426 + return;
58427 +}
58428 diff -urNp linux-2.6.39.2/grsecurity/grsec_link.c linux-2.6.39.2/grsecurity/grsec_link.c
58429 --- linux-2.6.39.2/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
58430 +++ linux-2.6.39.2/grsecurity/grsec_link.c 2011-05-22 19:41:42.000000000 -0400
58431 @@ -0,0 +1,43 @@
58432 +#include <linux/kernel.h>
58433 +#include <linux/sched.h>
58434 +#include <linux/fs.h>
58435 +#include <linux/file.h>
58436 +#include <linux/grinternal.h>
58437 +
58438 +int
58439 +gr_handle_follow_link(const struct inode *parent,
58440 + const struct inode *inode,
58441 + const struct dentry *dentry, const struct vfsmount *mnt)
58442 +{
58443 +#ifdef CONFIG_GRKERNSEC_LINK
58444 + const struct cred *cred = current_cred();
58445 +
58446 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58447 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58448 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58449 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58450 + return -EACCES;
58451 + }
58452 +#endif
58453 + return 0;
58454 +}
58455 +
58456 +int
58457 +gr_handle_hardlink(const struct dentry *dentry,
58458 + const struct vfsmount *mnt,
58459 + struct inode *inode, const int mode, const char *to)
58460 +{
58461 +#ifdef CONFIG_GRKERNSEC_LINK
58462 + const struct cred *cred = current_cred();
58463 +
58464 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58465 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58466 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58467 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58468 + !capable(CAP_FOWNER) && cred->uid) {
58469 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58470 + return -EPERM;
58471 + }
58472 +#endif
58473 + return 0;
58474 +}
58475 diff -urNp linux-2.6.39.2/grsecurity/grsec_log.c linux-2.6.39.2/grsecurity/grsec_log.c
58476 --- linux-2.6.39.2/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
58477 +++ linux-2.6.39.2/grsecurity/grsec_log.c 2011-05-22 19:41:42.000000000 -0400
58478 @@ -0,0 +1,310 @@
58479 +#include <linux/kernel.h>
58480 +#include <linux/sched.h>
58481 +#include <linux/file.h>
58482 +#include <linux/tty.h>
58483 +#include <linux/fs.h>
58484 +#include <linux/grinternal.h>
58485 +
58486 +#ifdef CONFIG_TREE_PREEMPT_RCU
58487 +#define DISABLE_PREEMPT() preempt_disable()
58488 +#define ENABLE_PREEMPT() preempt_enable()
58489 +#else
58490 +#define DISABLE_PREEMPT()
58491 +#define ENABLE_PREEMPT()
58492 +#endif
58493 +
58494 +#define BEGIN_LOCKS(x) \
58495 + DISABLE_PREEMPT(); \
58496 + rcu_read_lock(); \
58497 + read_lock(&tasklist_lock); \
58498 + read_lock(&grsec_exec_file_lock); \
58499 + if (x != GR_DO_AUDIT) \
58500 + spin_lock(&grsec_alert_lock); \
58501 + else \
58502 + spin_lock(&grsec_audit_lock)
58503 +
58504 +#define END_LOCKS(x) \
58505 + if (x != GR_DO_AUDIT) \
58506 + spin_unlock(&grsec_alert_lock); \
58507 + else \
58508 + spin_unlock(&grsec_audit_lock); \
58509 + read_unlock(&grsec_exec_file_lock); \
58510 + read_unlock(&tasklist_lock); \
58511 + rcu_read_unlock(); \
58512 + ENABLE_PREEMPT(); \
58513 + if (x == GR_DONT_AUDIT) \
58514 + gr_handle_alertkill(current)
58515 +
58516 +enum {
58517 + FLOODING,
58518 + NO_FLOODING
58519 +};
58520 +
58521 +extern char *gr_alert_log_fmt;
58522 +extern char *gr_audit_log_fmt;
58523 +extern char *gr_alert_log_buf;
58524 +extern char *gr_audit_log_buf;
58525 +
58526 +static int gr_log_start(int audit)
58527 +{
58528 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58529 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58530 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58531 +
58532 + if (audit == GR_DO_AUDIT)
58533 + goto set_fmt;
58534 +
58535 + if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
58536 + grsec_alert_wtime = jiffies;
58537 + grsec_alert_fyet = 0;
58538 + } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58539 + grsec_alert_fyet++;
58540 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58541 + grsec_alert_wtime = jiffies;
58542 + grsec_alert_fyet++;
58543 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58544 + return FLOODING;
58545 + } else return FLOODING;
58546 +
58547 +set_fmt:
58548 + memset(buf, 0, PAGE_SIZE);
58549 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58550 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58551 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58552 + } else if (current->signal->curr_ip) {
58553 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58554 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58555 + } else if (gr_acl_is_enabled()) {
58556 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58557 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58558 + } else {
58559 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58560 + strcpy(buf, fmt);
58561 + }
58562 +
58563 + return NO_FLOODING;
58564 +}
58565 +
58566 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58567 + __attribute__ ((format (printf, 2, 0)));
58568 +
58569 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58570 +{
58571 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58572 + unsigned int len = strlen(buf);
58573 +
58574 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58575 +
58576 + return;
58577 +}
58578 +
58579 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58580 + __attribute__ ((format (printf, 2, 3)));
58581 +
58582 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58583 +{
58584 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58585 + unsigned int len = strlen(buf);
58586 + va_list ap;
58587 +
58588 + va_start(ap, msg);
58589 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58590 + va_end(ap);
58591 +
58592 + return;
58593 +}
58594 +
58595 +static void gr_log_end(int audit)
58596 +{
58597 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58598 + unsigned int len = strlen(buf);
58599 +
58600 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58601 + printk("%s\n", buf);
58602 +
58603 + return;
58604 +}
58605 +
58606 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58607 +{
58608 + int logtype;
58609 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58610 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58611 + void *voidptr = NULL;
58612 + int num1 = 0, num2 = 0;
58613 + unsigned long ulong1 = 0, ulong2 = 0;
58614 + struct dentry *dentry = NULL;
58615 + struct vfsmount *mnt = NULL;
58616 + struct file *file = NULL;
58617 + struct task_struct *task = NULL;
58618 + const struct cred *cred, *pcred;
58619 + va_list ap;
58620 +
58621 + BEGIN_LOCKS(audit);
58622 + logtype = gr_log_start(audit);
58623 + if (logtype == FLOODING) {
58624 + END_LOCKS(audit);
58625 + return;
58626 + }
58627 + va_start(ap, argtypes);
58628 + switch (argtypes) {
58629 + case GR_TTYSNIFF:
58630 + task = va_arg(ap, struct task_struct *);
58631 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
58632 + break;
58633 + case GR_SYSCTL_HIDDEN:
58634 + str1 = va_arg(ap, char *);
58635 + gr_log_middle_varargs(audit, msg, result, str1);
58636 + break;
58637 + case GR_RBAC:
58638 + dentry = va_arg(ap, struct dentry *);
58639 + mnt = va_arg(ap, struct vfsmount *);
58640 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58641 + break;
58642 + case GR_RBAC_STR:
58643 + dentry = va_arg(ap, struct dentry *);
58644 + mnt = va_arg(ap, struct vfsmount *);
58645 + str1 = va_arg(ap, char *);
58646 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58647 + break;
58648 + case GR_STR_RBAC:
58649 + str1 = va_arg(ap, char *);
58650 + dentry = va_arg(ap, struct dentry *);
58651 + mnt = va_arg(ap, struct vfsmount *);
58652 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58653 + break;
58654 + case GR_RBAC_MODE2:
58655 + dentry = va_arg(ap, struct dentry *);
58656 + mnt = va_arg(ap, struct vfsmount *);
58657 + str1 = va_arg(ap, char *);
58658 + str2 = va_arg(ap, char *);
58659 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58660 + break;
58661 + case GR_RBAC_MODE3:
58662 + dentry = va_arg(ap, struct dentry *);
58663 + mnt = va_arg(ap, struct vfsmount *);
58664 + str1 = va_arg(ap, char *);
58665 + str2 = va_arg(ap, char *);
58666 + str3 = va_arg(ap, char *);
58667 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58668 + break;
58669 + case GR_FILENAME:
58670 + dentry = va_arg(ap, struct dentry *);
58671 + mnt = va_arg(ap, struct vfsmount *);
58672 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58673 + break;
58674 + case GR_STR_FILENAME:
58675 + str1 = va_arg(ap, char *);
58676 + dentry = va_arg(ap, struct dentry *);
58677 + mnt = va_arg(ap, struct vfsmount *);
58678 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58679 + break;
58680 + case GR_FILENAME_STR:
58681 + dentry = va_arg(ap, struct dentry *);
58682 + mnt = va_arg(ap, struct vfsmount *);
58683 + str1 = va_arg(ap, char *);
58684 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58685 + break;
58686 + case GR_FILENAME_TWO_INT:
58687 + dentry = va_arg(ap, struct dentry *);
58688 + mnt = va_arg(ap, struct vfsmount *);
58689 + num1 = va_arg(ap, int);
58690 + num2 = va_arg(ap, int);
58691 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58692 + break;
58693 + case GR_FILENAME_TWO_INT_STR:
58694 + dentry = va_arg(ap, struct dentry *);
58695 + mnt = va_arg(ap, struct vfsmount *);
58696 + num1 = va_arg(ap, int);
58697 + num2 = va_arg(ap, int);
58698 + str1 = va_arg(ap, char *);
58699 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58700 + break;
58701 + case GR_TEXTREL:
58702 + file = va_arg(ap, struct file *);
58703 + ulong1 = va_arg(ap, unsigned long);
58704 + ulong2 = va_arg(ap, unsigned long);
58705 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58706 + break;
58707 + case GR_PTRACE:
58708 + task = va_arg(ap, struct task_struct *);
58709 + gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task->pid);
58710 + break;
58711 + case GR_RESOURCE:
58712 + task = va_arg(ap, struct task_struct *);
58713 + cred = __task_cred(task);
58714 + pcred = __task_cred(task->real_parent);
58715 + ulong1 = va_arg(ap, unsigned long);
58716 + str1 = va_arg(ap, char *);
58717 + ulong2 = va_arg(ap, unsigned long);
58718 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58719 + break;
58720 + case GR_CAP:
58721 + task = va_arg(ap, struct task_struct *);
58722 + cred = __task_cred(task);
58723 + pcred = __task_cred(task->real_parent);
58724 + str1 = va_arg(ap, char *);
58725 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58726 + break;
58727 + case GR_SIG:
58728 + str1 = va_arg(ap, char *);
58729 + voidptr = va_arg(ap, void *);
58730 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58731 + break;
58732 + case GR_SIG2:
58733 + task = va_arg(ap, struct task_struct *);
58734 + cred = __task_cred(task);
58735 + pcred = __task_cred(task->real_parent);
58736 + num1 = va_arg(ap, int);
58737 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58738 + break;
58739 + case GR_CRASH1:
58740 + task = va_arg(ap, struct task_struct *);
58741 + cred = __task_cred(task);
58742 + pcred = __task_cred(task->real_parent);
58743 + ulong1 = va_arg(ap, unsigned long);
58744 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
58745 + break;
58746 + case GR_CRASH2:
58747 + task = va_arg(ap, struct task_struct *);
58748 + cred = __task_cred(task);
58749 + pcred = __task_cred(task->real_parent);
58750 + ulong1 = va_arg(ap, unsigned long);
58751 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
58752 + break;
58753 + case GR_RWXMAP:
58754 + file = va_arg(ap, struct file *);
58755 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58756 + break;
58757 + case GR_PSACCT:
58758 + {
58759 + unsigned int wday, cday;
58760 + __u8 whr, chr;
58761 + __u8 wmin, cmin;
58762 + __u8 wsec, csec;
58763 + char cur_tty[64] = { 0 };
58764 + char parent_tty[64] = { 0 };
58765 +
58766 + task = va_arg(ap, struct task_struct *);
58767 + wday = va_arg(ap, unsigned int);
58768 + cday = va_arg(ap, unsigned int);
58769 + whr = va_arg(ap, int);
58770 + chr = va_arg(ap, int);
58771 + wmin = va_arg(ap, int);
58772 + cmin = va_arg(ap, int);
58773 + wsec = va_arg(ap, int);
58774 + csec = va_arg(ap, int);
58775 + ulong1 = va_arg(ap, unsigned long);
58776 + cred = __task_cred(task);
58777 + pcred = __task_cred(task->real_parent);
58778 +
58779 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
58780 + }
58781 + break;
58782 + default:
58783 + gr_log_middle(audit, msg, ap);
58784 + }
58785 + va_end(ap);
58786 + gr_log_end(audit);
58787 + END_LOCKS(audit);
58788 +}
58789 diff -urNp linux-2.6.39.2/grsecurity/grsec_mem.c linux-2.6.39.2/grsecurity/grsec_mem.c
58790 --- linux-2.6.39.2/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
58791 +++ linux-2.6.39.2/grsecurity/grsec_mem.c 2011-05-22 19:41:42.000000000 -0400
58792 @@ -0,0 +1,33 @@
58793 +#include <linux/kernel.h>
58794 +#include <linux/sched.h>
58795 +#include <linux/mm.h>
58796 +#include <linux/mman.h>
58797 +#include <linux/grinternal.h>
58798 +
58799 +void
58800 +gr_handle_ioperm(void)
58801 +{
58802 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58803 + return;
58804 +}
58805 +
58806 +void
58807 +gr_handle_iopl(void)
58808 +{
58809 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58810 + return;
58811 +}
58812 +
58813 +void
58814 +gr_handle_mem_readwrite(u64 from, u64 to)
58815 +{
58816 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58817 + return;
58818 +}
58819 +
58820 +void
58821 +gr_handle_vm86(void)
58822 +{
58823 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58824 + return;
58825 +}
58826 diff -urNp linux-2.6.39.2/grsecurity/grsec_mount.c linux-2.6.39.2/grsecurity/grsec_mount.c
58827 --- linux-2.6.39.2/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
58828 +++ linux-2.6.39.2/grsecurity/grsec_mount.c 2011-06-20 19:46:18.000000000 -0400
58829 @@ -0,0 +1,62 @@
58830 +#include <linux/kernel.h>
58831 +#include <linux/sched.h>
58832 +#include <linux/mount.h>
58833 +#include <linux/grsecurity.h>
58834 +#include <linux/grinternal.h>
58835 +
58836 +void
58837 +gr_log_remount(const char *devname, const int retval)
58838 +{
58839 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58840 + if (grsec_enable_mount && (retval >= 0))
58841 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58842 +#endif
58843 + return;
58844 +}
58845 +
58846 +void
58847 +gr_log_unmount(const char *devname, const int retval)
58848 +{
58849 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58850 + if (grsec_enable_mount && (retval >= 0))
58851 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58852 +#endif
58853 + return;
58854 +}
58855 +
58856 +void
58857 +gr_log_mount(const char *from, const char *to, const int retval)
58858 +{
58859 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58860 + if (grsec_enable_mount && (retval >= 0))
58861 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58862 +#endif
58863 + return;
58864 +}
58865 +
58866 +int
58867 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58868 +{
58869 +#ifdef CONFIG_GRKERNSEC_ROFS
58870 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58871 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58872 + return -EPERM;
58873 + } else
58874 + return 0;
58875 +#endif
58876 + return 0;
58877 +}
58878 +
58879 +int
58880 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58881 +{
58882 +#ifdef CONFIG_GRKERNSEC_ROFS
58883 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58884 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58885 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58886 + return -EPERM;
58887 + } else
58888 + return 0;
58889 +#endif
58890 + return 0;
58891 +}
58892 diff -urNp linux-2.6.39.2/grsecurity/grsec_pax.c linux-2.6.39.2/grsecurity/grsec_pax.c
58893 --- linux-2.6.39.2/grsecurity/grsec_pax.c 1969-12-31 19:00:00.000000000 -0500
58894 +++ linux-2.6.39.2/grsecurity/grsec_pax.c 2011-05-22 19:41:42.000000000 -0400
58895 @@ -0,0 +1,36 @@
58896 +#include <linux/kernel.h>
58897 +#include <linux/sched.h>
58898 +#include <linux/mm.h>
58899 +#include <linux/file.h>
58900 +#include <linux/grinternal.h>
58901 +#include <linux/grsecurity.h>
58902 +
58903 +void
58904 +gr_log_textrel(struct vm_area_struct * vma)
58905 +{
58906 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58907 + if (grsec_enable_audit_textrel)
58908 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58909 +#endif
58910 + return;
58911 +}
58912 +
58913 +void
58914 +gr_log_rwxmmap(struct file *file)
58915 +{
58916 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58917 + if (grsec_enable_log_rwxmaps)
58918 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58919 +#endif
58920 + return;
58921 +}
58922 +
58923 +void
58924 +gr_log_rwxmprotect(struct file *file)
58925 +{
58926 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58927 + if (grsec_enable_log_rwxmaps)
58928 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58929 +#endif
58930 + return;
58931 +}
58932 diff -urNp linux-2.6.39.2/grsecurity/grsec_ptrace.c linux-2.6.39.2/grsecurity/grsec_ptrace.c
58933 --- linux-2.6.39.2/grsecurity/grsec_ptrace.c 1969-12-31 19:00:00.000000000 -0500
58934 +++ linux-2.6.39.2/grsecurity/grsec_ptrace.c 2011-05-22 19:41:42.000000000 -0400
58935 @@ -0,0 +1,14 @@
58936 +#include <linux/kernel.h>
58937 +#include <linux/sched.h>
58938 +#include <linux/grinternal.h>
58939 +#include <linux/grsecurity.h>
58940 +
58941 +void
58942 +gr_audit_ptrace(struct task_struct *task)
58943 +{
58944 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58945 + if (grsec_enable_audit_ptrace)
58946 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58947 +#endif
58948 + return;
58949 +}
58950 diff -urNp linux-2.6.39.2/grsecurity/grsec_sig.c linux-2.6.39.2/grsecurity/grsec_sig.c
58951 --- linux-2.6.39.2/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
58952 +++ linux-2.6.39.2/grsecurity/grsec_sig.c 2011-05-22 19:41:42.000000000 -0400
58953 @@ -0,0 +1,203 @@
58954 +#include <linux/kernel.h>
58955 +#include <linux/sched.h>
58956 +#include <linux/delay.h>
58957 +#include <linux/grsecurity.h>
58958 +#include <linux/grinternal.h>
58959 +#include <linux/hardirq.h>
58960 +
58961 +char *signames[] = {
58962 + [SIGSEGV] = "Segmentation fault",
58963 + [SIGILL] = "Illegal instruction",
58964 + [SIGABRT] = "Abort",
58965 + [SIGBUS] = "Invalid alignment/Bus error"
58966 +};
58967 +
58968 +void
58969 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58970 +{
58971 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58972 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58973 + (sig == SIGABRT) || (sig == SIGBUS))) {
58974 + if (t->pid == current->pid) {
58975 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58976 + } else {
58977 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58978 + }
58979 + }
58980 +#endif
58981 + return;
58982 +}
58983 +
58984 +int
58985 +gr_handle_signal(const struct task_struct *p, const int sig)
58986 +{
58987 +#ifdef CONFIG_GRKERNSEC
58988 + if (current->pid > 1 && gr_check_protected_task(p)) {
58989 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58990 + return -EPERM;
58991 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58992 + return -EPERM;
58993 + }
58994 +#endif
58995 + return 0;
58996 +}
58997 +
58998 +#ifdef CONFIG_GRKERNSEC
58999 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59000 +
59001 +int gr_fake_force_sig(int sig, struct task_struct *t)
59002 +{
59003 + unsigned long int flags;
59004 + int ret, blocked, ignored;
59005 + struct k_sigaction *action;
59006 +
59007 + spin_lock_irqsave(&t->sighand->siglock, flags);
59008 + action = &t->sighand->action[sig-1];
59009 + ignored = action->sa.sa_handler == SIG_IGN;
59010 + blocked = sigismember(&t->blocked, sig);
59011 + if (blocked || ignored) {
59012 + action->sa.sa_handler = SIG_DFL;
59013 + if (blocked) {
59014 + sigdelset(&t->blocked, sig);
59015 + recalc_sigpending_and_wake(t);
59016 + }
59017 + }
59018 + if (action->sa.sa_handler == SIG_DFL)
59019 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59020 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59021 +
59022 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59023 +
59024 + return ret;
59025 +}
59026 +#endif
59027 +
59028 +#ifdef CONFIG_GRKERNSEC_BRUTE
59029 +#define GR_USER_BAN_TIME (15 * 60)
59030 +
59031 +static int __get_dumpable(unsigned long mm_flags)
59032 +{
59033 + int ret;
59034 +
59035 + ret = mm_flags & MMF_DUMPABLE_MASK;
59036 + return (ret >= 2) ? 2 : ret;
59037 +}
59038 +#endif
59039 +
59040 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59041 +{
59042 +#ifdef CONFIG_GRKERNSEC_BRUTE
59043 + uid_t uid = 0;
59044 +
59045 + rcu_read_lock();
59046 + read_lock(&tasklist_lock);
59047 + read_lock(&grsec_exec_file_lock);
59048 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59049 + p->real_parent->brute = 1;
59050 + else {
59051 + const struct cred *cred = __task_cred(p), *cred2;
59052 + struct task_struct *tsk, *tsk2;
59053 +
59054 + if (!__get_dumpable(mm_flags) && cred->uid) {
59055 + struct user_struct *user;
59056 +
59057 + uid = cred->uid;
59058 +
59059 + /* this is put upon execution past expiration */
59060 + user = find_user(uid);
59061 + if (user == NULL)
59062 + goto unlock;
59063 + user->banned = 1;
59064 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59065 + if (user->ban_expires == ~0UL)
59066 + user->ban_expires--;
59067 +
59068 + do_each_thread(tsk2, tsk) {
59069 + cred2 = __task_cred(tsk);
59070 + if (tsk != p && cred2->uid == uid)
59071 + gr_fake_force_sig(SIGKILL, tsk);
59072 + } while_each_thread(tsk2, tsk);
59073 + }
59074 + }
59075 +unlock:
59076 + read_unlock(&grsec_exec_file_lock);
59077 + read_unlock(&tasklist_lock);
59078 + rcu_read_unlock();
59079 +
59080 + if (uid)
59081 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59082 +
59083 +#endif
59084 + return;
59085 +}
59086 +
59087 +void gr_handle_brute_check(void)
59088 +{
59089 +#ifdef CONFIG_GRKERNSEC_BRUTE
59090 + if (current->brute)
59091 + msleep(30 * 1000);
59092 +#endif
59093 + return;
59094 +}
59095 +
59096 +void gr_handle_kernel_exploit(void)
59097 +{
59098 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59099 + const struct cred *cred;
59100 + struct task_struct *tsk, *tsk2;
59101 + struct user_struct *user;
59102 + uid_t uid;
59103 +
59104 + if (in_irq() || in_serving_softirq() || in_nmi())
59105 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59106 +
59107 + uid = current_uid();
59108 +
59109 + if (uid == 0)
59110 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59111 + else {
59112 + /* kill all the processes of this user, hold a reference
59113 + to their creds struct, and prevent them from creating
59114 + another process until system reset
59115 + */
59116 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59117 + /* we intentionally leak this ref */
59118 + user = get_uid(current->cred->user);
59119 + if (user) {
59120 + user->banned = 1;
59121 + user->ban_expires = ~0UL;
59122 + }
59123 +
59124 + read_lock(&tasklist_lock);
59125 + do_each_thread(tsk2, tsk) {
59126 + cred = __task_cred(tsk);
59127 + if (cred->uid == uid)
59128 + gr_fake_force_sig(SIGKILL, tsk);
59129 + } while_each_thread(tsk2, tsk);
59130 + read_unlock(&tasklist_lock);
59131 + }
59132 +#endif
59133 +}
59134 +
59135 +int __gr_process_user_ban(struct user_struct *user)
59136 +{
59137 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59138 + if (unlikely(user->banned)) {
59139 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59140 + user->banned = 0;
59141 + user->ban_expires = 0;
59142 + free_uid(user);
59143 + } else
59144 + return -EPERM;
59145 + }
59146 +#endif
59147 + return 0;
59148 +}
59149 +
59150 +int gr_process_user_ban(void)
59151 +{
59152 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59153 + return __gr_process_user_ban(current->cred->user);
59154 +#endif
59155 + return 0;
59156 +}
59157 diff -urNp linux-2.6.39.2/grsecurity/grsec_sock.c linux-2.6.39.2/grsecurity/grsec_sock.c
59158 --- linux-2.6.39.2/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
59159 +++ linux-2.6.39.2/grsecurity/grsec_sock.c 2011-05-22 20:29:21.000000000 -0400
59160 @@ -0,0 +1,244 @@
59161 +#include <linux/kernel.h>
59162 +#include <linux/module.h>
59163 +#include <linux/sched.h>
59164 +#include <linux/file.h>
59165 +#include <linux/net.h>
59166 +#include <linux/in.h>
59167 +#include <linux/ip.h>
59168 +#include <net/sock.h>
59169 +#include <net/inet_sock.h>
59170 +#include <linux/grsecurity.h>
59171 +#include <linux/grinternal.h>
59172 +#include <linux/gracl.h>
59173 +
59174 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59175 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59176 +
59177 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59178 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59179 +
59180 +#ifdef CONFIG_UNIX_MODULE
59181 +EXPORT_SYMBOL(gr_acl_handle_unix);
59182 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59183 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59184 +EXPORT_SYMBOL(gr_handle_create);
59185 +#endif
59186 +
59187 +#ifdef CONFIG_GRKERNSEC
59188 +#define gr_conn_table_size 32749
59189 +struct conn_table_entry {
59190 + struct conn_table_entry *next;
59191 + struct signal_struct *sig;
59192 +};
59193 +
59194 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59195 +DEFINE_SPINLOCK(gr_conn_table_lock);
59196 +
59197 +extern const char * gr_socktype_to_name(unsigned char type);
59198 +extern const char * gr_proto_to_name(unsigned char proto);
59199 +extern const char * gr_sockfamily_to_name(unsigned char family);
59200 +
59201 +static __inline__ int
59202 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59203 +{
59204 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59205 +}
59206 +
59207 +static __inline__ int
59208 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59209 + __u16 sport, __u16 dport)
59210 +{
59211 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59212 + sig->gr_sport == sport && sig->gr_dport == dport))
59213 + return 1;
59214 + else
59215 + return 0;
59216 +}
59217 +
59218 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59219 +{
59220 + struct conn_table_entry **match;
59221 + unsigned int index;
59222 +
59223 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59224 + sig->gr_sport, sig->gr_dport,
59225 + gr_conn_table_size);
59226 +
59227 + newent->sig = sig;
59228 +
59229 + match = &gr_conn_table[index];
59230 + newent->next = *match;
59231 + *match = newent;
59232 +
59233 + return;
59234 +}
59235 +
59236 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59237 +{
59238 + struct conn_table_entry *match, *last = NULL;
59239 + unsigned int index;
59240 +
59241 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59242 + sig->gr_sport, sig->gr_dport,
59243 + gr_conn_table_size);
59244 +
59245 + match = gr_conn_table[index];
59246 + while (match && !conn_match(match->sig,
59247 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59248 + sig->gr_dport)) {
59249 + last = match;
59250 + match = match->next;
59251 + }
59252 +
59253 + if (match) {
59254 + if (last)
59255 + last->next = match->next;
59256 + else
59257 + gr_conn_table[index] = NULL;
59258 + kfree(match);
59259 + }
59260 +
59261 + return;
59262 +}
59263 +
59264 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59265 + __u16 sport, __u16 dport)
59266 +{
59267 + struct conn_table_entry *match;
59268 + unsigned int index;
59269 +
59270 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59271 +
59272 + match = gr_conn_table[index];
59273 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59274 + match = match->next;
59275 +
59276 + if (match)
59277 + return match->sig;
59278 + else
59279 + return NULL;
59280 +}
59281 +
59282 +#endif
59283 +
59284 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59285 +{
59286 +#ifdef CONFIG_GRKERNSEC
59287 + struct signal_struct *sig = task->signal;
59288 + struct conn_table_entry *newent;
59289 +
59290 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59291 + if (newent == NULL)
59292 + return;
59293 + /* no bh lock needed since we are called with bh disabled */
59294 + spin_lock(&gr_conn_table_lock);
59295 + gr_del_task_from_ip_table_nolock(sig);
59296 + sig->gr_saddr = inet->inet_rcv_saddr;
59297 + sig->gr_daddr = inet->inet_daddr;
59298 + sig->gr_sport = inet->inet_sport;
59299 + sig->gr_dport = inet->inet_dport;
59300 + gr_add_to_task_ip_table_nolock(sig, newent);
59301 + spin_unlock(&gr_conn_table_lock);
59302 +#endif
59303 + return;
59304 +}
59305 +
59306 +void gr_del_task_from_ip_table(struct task_struct *task)
59307 +{
59308 +#ifdef CONFIG_GRKERNSEC
59309 + spin_lock_bh(&gr_conn_table_lock);
59310 + gr_del_task_from_ip_table_nolock(task->signal);
59311 + spin_unlock_bh(&gr_conn_table_lock);
59312 +#endif
59313 + return;
59314 +}
59315 +
59316 +void
59317 +gr_attach_curr_ip(const struct sock *sk)
59318 +{
59319 +#ifdef CONFIG_GRKERNSEC
59320 + struct signal_struct *p, *set;
59321 + const struct inet_sock *inet = inet_sk(sk);
59322 +
59323 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59324 + return;
59325 +
59326 + set = current->signal;
59327 +
59328 + spin_lock_bh(&gr_conn_table_lock);
59329 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59330 + inet->inet_dport, inet->inet_sport);
59331 + if (unlikely(p != NULL)) {
59332 + set->curr_ip = p->curr_ip;
59333 + set->used_accept = 1;
59334 + gr_del_task_from_ip_table_nolock(p);
59335 + spin_unlock_bh(&gr_conn_table_lock);
59336 + return;
59337 + }
59338 + spin_unlock_bh(&gr_conn_table_lock);
59339 +
59340 + set->curr_ip = inet->inet_daddr;
59341 + set->used_accept = 1;
59342 +#endif
59343 + return;
59344 +}
59345 +
59346 +int
59347 +gr_handle_sock_all(const int family, const int type, const int protocol)
59348 +{
59349 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59350 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59351 + (family != AF_UNIX)) {
59352 + if (family == AF_INET)
59353 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59354 + else
59355 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59356 + return -EACCES;
59357 + }
59358 +#endif
59359 + return 0;
59360 +}
59361 +
59362 +int
59363 +gr_handle_sock_server(const struct sockaddr *sck)
59364 +{
59365 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59366 + if (grsec_enable_socket_server &&
59367 + in_group_p(grsec_socket_server_gid) &&
59368 + sck && (sck->sa_family != AF_UNIX) &&
59369 + (sck->sa_family != AF_LOCAL)) {
59370 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59371 + return -EACCES;
59372 + }
59373 +#endif
59374 + return 0;
59375 +}
59376 +
59377 +int
59378 +gr_handle_sock_server_other(const struct sock *sck)
59379 +{
59380 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59381 + if (grsec_enable_socket_server &&
59382 + in_group_p(grsec_socket_server_gid) &&
59383 + sck && (sck->sk_family != AF_UNIX) &&
59384 + (sck->sk_family != AF_LOCAL)) {
59385 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59386 + return -EACCES;
59387 + }
59388 +#endif
59389 + return 0;
59390 +}
59391 +
59392 +int
59393 +gr_handle_sock_client(const struct sockaddr *sck)
59394 +{
59395 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59396 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59397 + sck && (sck->sa_family != AF_UNIX) &&
59398 + (sck->sa_family != AF_LOCAL)) {
59399 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59400 + return -EACCES;
59401 + }
59402 +#endif
59403 + return 0;
59404 +}
59405 diff -urNp linux-2.6.39.2/grsecurity/grsec_sysctl.c linux-2.6.39.2/grsecurity/grsec_sysctl.c
59406 --- linux-2.6.39.2/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
59407 +++ linux-2.6.39.2/grsecurity/grsec_sysctl.c 2011-05-22 19:41:42.000000000 -0400
59408 @@ -0,0 +1,433 @@
59409 +#include <linux/kernel.h>
59410 +#include <linux/sched.h>
59411 +#include <linux/sysctl.h>
59412 +#include <linux/grsecurity.h>
59413 +#include <linux/grinternal.h>
59414 +
59415 +int
59416 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59417 +{
59418 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59419 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59420 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59421 + return -EACCES;
59422 + }
59423 +#endif
59424 + return 0;
59425 +}
59426 +
59427 +#ifdef CONFIG_GRKERNSEC_ROFS
59428 +static int __maybe_unused one = 1;
59429 +#endif
59430 +
59431 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59432 +struct ctl_table grsecurity_table[] = {
59433 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59434 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59435 +#ifdef CONFIG_GRKERNSEC_IO
59436 + {
59437 + .procname = "disable_priv_io",
59438 + .data = &grsec_disable_privio,
59439 + .maxlen = sizeof(int),
59440 + .mode = 0600,
59441 + .proc_handler = &proc_dointvec,
59442 + },
59443 +#endif
59444 +#endif
59445 +#ifdef CONFIG_GRKERNSEC_LINK
59446 + {
59447 + .procname = "linking_restrictions",
59448 + .data = &grsec_enable_link,
59449 + .maxlen = sizeof(int),
59450 + .mode = 0600,
59451 + .proc_handler = &proc_dointvec,
59452 + },
59453 +#endif
59454 +#ifdef CONFIG_GRKERNSEC_FIFO
59455 + {
59456 + .procname = "fifo_restrictions",
59457 + .data = &grsec_enable_fifo,
59458 + .maxlen = sizeof(int),
59459 + .mode = 0600,
59460 + .proc_handler = &proc_dointvec,
59461 + },
59462 +#endif
59463 +#ifdef CONFIG_GRKERNSEC_EXECVE
59464 + {
59465 + .procname = "execve_limiting",
59466 + .data = &grsec_enable_execve,
59467 + .maxlen = sizeof(int),
59468 + .mode = 0600,
59469 + .proc_handler = &proc_dointvec,
59470 + },
59471 +#endif
59472 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59473 + {
59474 + .procname = "ip_blackhole",
59475 + .data = &grsec_enable_blackhole,
59476 + .maxlen = sizeof(int),
59477 + .mode = 0600,
59478 + .proc_handler = &proc_dointvec,
59479 + },
59480 + {
59481 + .procname = "lastack_retries",
59482 + .data = &grsec_lastack_retries,
59483 + .maxlen = sizeof(int),
59484 + .mode = 0600,
59485 + .proc_handler = &proc_dointvec,
59486 + },
59487 +#endif
59488 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59489 + {
59490 + .procname = "exec_logging",
59491 + .data = &grsec_enable_execlog,
59492 + .maxlen = sizeof(int),
59493 + .mode = 0600,
59494 + .proc_handler = &proc_dointvec,
59495 + },
59496 +#endif
59497 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59498 + {
59499 + .procname = "rwxmap_logging",
59500 + .data = &grsec_enable_log_rwxmaps,
59501 + .maxlen = sizeof(int),
59502 + .mode = 0600,
59503 + .proc_handler = &proc_dointvec,
59504 + },
59505 +#endif
59506 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59507 + {
59508 + .procname = "signal_logging",
59509 + .data = &grsec_enable_signal,
59510 + .maxlen = sizeof(int),
59511 + .mode = 0600,
59512 + .proc_handler = &proc_dointvec,
59513 + },
59514 +#endif
59515 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59516 + {
59517 + .procname = "forkfail_logging",
59518 + .data = &grsec_enable_forkfail,
59519 + .maxlen = sizeof(int),
59520 + .mode = 0600,
59521 + .proc_handler = &proc_dointvec,
59522 + },
59523 +#endif
59524 +#ifdef CONFIG_GRKERNSEC_TIME
59525 + {
59526 + .procname = "timechange_logging",
59527 + .data = &grsec_enable_time,
59528 + .maxlen = sizeof(int),
59529 + .mode = 0600,
59530 + .proc_handler = &proc_dointvec,
59531 + },
59532 +#endif
59533 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59534 + {
59535 + .procname = "chroot_deny_shmat",
59536 + .data = &grsec_enable_chroot_shmat,
59537 + .maxlen = sizeof(int),
59538 + .mode = 0600,
59539 + .proc_handler = &proc_dointvec,
59540 + },
59541 +#endif
59542 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59543 + {
59544 + .procname = "chroot_deny_unix",
59545 + .data = &grsec_enable_chroot_unix,
59546 + .maxlen = sizeof(int),
59547 + .mode = 0600,
59548 + .proc_handler = &proc_dointvec,
59549 + },
59550 +#endif
59551 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59552 + {
59553 + .procname = "chroot_deny_mount",
59554 + .data = &grsec_enable_chroot_mount,
59555 + .maxlen = sizeof(int),
59556 + .mode = 0600,
59557 + .proc_handler = &proc_dointvec,
59558 + },
59559 +#endif
59560 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59561 + {
59562 + .procname = "chroot_deny_fchdir",
59563 + .data = &grsec_enable_chroot_fchdir,
59564 + .maxlen = sizeof(int),
59565 + .mode = 0600,
59566 + .proc_handler = &proc_dointvec,
59567 + },
59568 +#endif
59569 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59570 + {
59571 + .procname = "chroot_deny_chroot",
59572 + .data = &grsec_enable_chroot_double,
59573 + .maxlen = sizeof(int),
59574 + .mode = 0600,
59575 + .proc_handler = &proc_dointvec,
59576 + },
59577 +#endif
59578 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59579 + {
59580 + .procname = "chroot_deny_pivot",
59581 + .data = &grsec_enable_chroot_pivot,
59582 + .maxlen = sizeof(int),
59583 + .mode = 0600,
59584 + .proc_handler = &proc_dointvec,
59585 + },
59586 +#endif
59587 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59588 + {
59589 + .procname = "chroot_enforce_chdir",
59590 + .data = &grsec_enable_chroot_chdir,
59591 + .maxlen = sizeof(int),
59592 + .mode = 0600,
59593 + .proc_handler = &proc_dointvec,
59594 + },
59595 +#endif
59596 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59597 + {
59598 + .procname = "chroot_deny_chmod",
59599 + .data = &grsec_enable_chroot_chmod,
59600 + .maxlen = sizeof(int),
59601 + .mode = 0600,
59602 + .proc_handler = &proc_dointvec,
59603 + },
59604 +#endif
59605 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59606 + {
59607 + .procname = "chroot_deny_mknod",
59608 + .data = &grsec_enable_chroot_mknod,
59609 + .maxlen = sizeof(int),
59610 + .mode = 0600,
59611 + .proc_handler = &proc_dointvec,
59612 + },
59613 +#endif
59614 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59615 + {
59616 + .procname = "chroot_restrict_nice",
59617 + .data = &grsec_enable_chroot_nice,
59618 + .maxlen = sizeof(int),
59619 + .mode = 0600,
59620 + .proc_handler = &proc_dointvec,
59621 + },
59622 +#endif
59623 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59624 + {
59625 + .procname = "chroot_execlog",
59626 + .data = &grsec_enable_chroot_execlog,
59627 + .maxlen = sizeof(int),
59628 + .mode = 0600,
59629 + .proc_handler = &proc_dointvec,
59630 + },
59631 +#endif
59632 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59633 + {
59634 + .procname = "chroot_caps",
59635 + .data = &grsec_enable_chroot_caps,
59636 + .maxlen = sizeof(int),
59637 + .mode = 0600,
59638 + .proc_handler = &proc_dointvec,
59639 + },
59640 +#endif
59641 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59642 + {
59643 + .procname = "chroot_deny_sysctl",
59644 + .data = &grsec_enable_chroot_sysctl,
59645 + .maxlen = sizeof(int),
59646 + .mode = 0600,
59647 + .proc_handler = &proc_dointvec,
59648 + },
59649 +#endif
59650 +#ifdef CONFIG_GRKERNSEC_TPE
59651 + {
59652 + .procname = "tpe",
59653 + .data = &grsec_enable_tpe,
59654 + .maxlen = sizeof(int),
59655 + .mode = 0600,
59656 + .proc_handler = &proc_dointvec,
59657 + },
59658 + {
59659 + .procname = "tpe_gid",
59660 + .data = &grsec_tpe_gid,
59661 + .maxlen = sizeof(int),
59662 + .mode = 0600,
59663 + .proc_handler = &proc_dointvec,
59664 + },
59665 +#endif
59666 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59667 + {
59668 + .procname = "tpe_invert",
59669 + .data = &grsec_enable_tpe_invert,
59670 + .maxlen = sizeof(int),
59671 + .mode = 0600,
59672 + .proc_handler = &proc_dointvec,
59673 + },
59674 +#endif
59675 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59676 + {
59677 + .procname = "tpe_restrict_all",
59678 + .data = &grsec_enable_tpe_all,
59679 + .maxlen = sizeof(int),
59680 + .mode = 0600,
59681 + .proc_handler = &proc_dointvec,
59682 + },
59683 +#endif
59684 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59685 + {
59686 + .procname = "socket_all",
59687 + .data = &grsec_enable_socket_all,
59688 + .maxlen = sizeof(int),
59689 + .mode = 0600,
59690 + .proc_handler = &proc_dointvec,
59691 + },
59692 + {
59693 + .procname = "socket_all_gid",
59694 + .data = &grsec_socket_all_gid,
59695 + .maxlen = sizeof(int),
59696 + .mode = 0600,
59697 + .proc_handler = &proc_dointvec,
59698 + },
59699 +#endif
59700 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59701 + {
59702 + .procname = "socket_client",
59703 + .data = &grsec_enable_socket_client,
59704 + .maxlen = sizeof(int),
59705 + .mode = 0600,
59706 + .proc_handler = &proc_dointvec,
59707 + },
59708 + {
59709 + .procname = "socket_client_gid",
59710 + .data = &grsec_socket_client_gid,
59711 + .maxlen = sizeof(int),
59712 + .mode = 0600,
59713 + .proc_handler = &proc_dointvec,
59714 + },
59715 +#endif
59716 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59717 + {
59718 + .procname = "socket_server",
59719 + .data = &grsec_enable_socket_server,
59720 + .maxlen = sizeof(int),
59721 + .mode = 0600,
59722 + .proc_handler = &proc_dointvec,
59723 + },
59724 + {
59725 + .procname = "socket_server_gid",
59726 + .data = &grsec_socket_server_gid,
59727 + .maxlen = sizeof(int),
59728 + .mode = 0600,
59729 + .proc_handler = &proc_dointvec,
59730 + },
59731 +#endif
59732 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59733 + {
59734 + .procname = "audit_group",
59735 + .data = &grsec_enable_group,
59736 + .maxlen = sizeof(int),
59737 + .mode = 0600,
59738 + .proc_handler = &proc_dointvec,
59739 + },
59740 + {
59741 + .procname = "audit_gid",
59742 + .data = &grsec_audit_gid,
59743 + .maxlen = sizeof(int),
59744 + .mode = 0600,
59745 + .proc_handler = &proc_dointvec,
59746 + },
59747 +#endif
59748 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59749 + {
59750 + .procname = "audit_chdir",
59751 + .data = &grsec_enable_chdir,
59752 + .maxlen = sizeof(int),
59753 + .mode = 0600,
59754 + .proc_handler = &proc_dointvec,
59755 + },
59756 +#endif
59757 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59758 + {
59759 + .procname = "audit_mount",
59760 + .data = &grsec_enable_mount,
59761 + .maxlen = sizeof(int),
59762 + .mode = 0600,
59763 + .proc_handler = &proc_dointvec,
59764 + },
59765 +#endif
59766 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59767 + {
59768 + .procname = "audit_textrel",
59769 + .data = &grsec_enable_audit_textrel,
59770 + .maxlen = sizeof(int),
59771 + .mode = 0600,
59772 + .proc_handler = &proc_dointvec,
59773 + },
59774 +#endif
59775 +#ifdef CONFIG_GRKERNSEC_DMESG
59776 + {
59777 + .procname = "dmesg",
59778 + .data = &grsec_enable_dmesg,
59779 + .maxlen = sizeof(int),
59780 + .mode = 0600,
59781 + .proc_handler = &proc_dointvec,
59782 + },
59783 +#endif
59784 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59785 + {
59786 + .procname = "chroot_findtask",
59787 + .data = &grsec_enable_chroot_findtask,
59788 + .maxlen = sizeof(int),
59789 + .mode = 0600,
59790 + .proc_handler = &proc_dointvec,
59791 + },
59792 +#endif
59793 +#ifdef CONFIG_GRKERNSEC_RESLOG
59794 + {
59795 + .procname = "resource_logging",
59796 + .data = &grsec_resource_logging,
59797 + .maxlen = sizeof(int),
59798 + .mode = 0600,
59799 + .proc_handler = &proc_dointvec,
59800 + },
59801 +#endif
59802 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59803 + {
59804 + .procname = "audit_ptrace",
59805 + .data = &grsec_enable_audit_ptrace,
59806 + .maxlen = sizeof(int),
59807 + .mode = 0600,
59808 + .proc_handler = &proc_dointvec,
59809 + },
59810 +#endif
59811 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59812 + {
59813 + .procname = "harden_ptrace",
59814 + .data = &grsec_enable_harden_ptrace,
59815 + .maxlen = sizeof(int),
59816 + .mode = 0600,
59817 + .proc_handler = &proc_dointvec,
59818 + },
59819 +#endif
59820 + {
59821 + .procname = "grsec_lock",
59822 + .data = &grsec_lock,
59823 + .maxlen = sizeof(int),
59824 + .mode = 0600,
59825 + .proc_handler = &proc_dointvec,
59826 + },
59827 +#endif
59828 +#ifdef CONFIG_GRKERNSEC_ROFS
59829 + {
59830 + .procname = "romount_protect",
59831 + .data = &grsec_enable_rofs,
59832 + .maxlen = sizeof(int),
59833 + .mode = 0600,
59834 + .proc_handler = &proc_dointvec_minmax,
59835 + .extra1 = &one,
59836 + .extra2 = &one,
59837 + },
59838 +#endif
59839 + { }
59840 +};
59841 +#endif
59842 diff -urNp linux-2.6.39.2/grsecurity/grsec_time.c linux-2.6.39.2/grsecurity/grsec_time.c
59843 --- linux-2.6.39.2/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
59844 +++ linux-2.6.39.2/grsecurity/grsec_time.c 2011-05-22 19:41:42.000000000 -0400
59845 @@ -0,0 +1,16 @@
59846 +#include <linux/kernel.h>
59847 +#include <linux/sched.h>
59848 +#include <linux/grinternal.h>
59849 +#include <linux/module.h>
59850 +
59851 +void
59852 +gr_log_timechange(void)
59853 +{
59854 +#ifdef CONFIG_GRKERNSEC_TIME
59855 + if (grsec_enable_time)
59856 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59857 +#endif
59858 + return;
59859 +}
59860 +
59861 +EXPORT_SYMBOL(gr_log_timechange);
59862 diff -urNp linux-2.6.39.2/grsecurity/grsec_tpe.c linux-2.6.39.2/grsecurity/grsec_tpe.c
59863 --- linux-2.6.39.2/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
59864 +++ linux-2.6.39.2/grsecurity/grsec_tpe.c 2011-05-22 19:41:42.000000000 -0400
59865 @@ -0,0 +1,39 @@
59866 +#include <linux/kernel.h>
59867 +#include <linux/sched.h>
59868 +#include <linux/file.h>
59869 +#include <linux/fs.h>
59870 +#include <linux/grinternal.h>
59871 +
59872 +extern int gr_acl_tpe_check(void);
59873 +
59874 +int
59875 +gr_tpe_allow(const struct file *file)
59876 +{
59877 +#ifdef CONFIG_GRKERNSEC
59878 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59879 + const struct cred *cred = current_cred();
59880 +
59881 + if (cred->uid && ((grsec_enable_tpe &&
59882 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59883 + ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
59884 + (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
59885 +#else
59886 + in_group_p(grsec_tpe_gid)
59887 +#endif
59888 + ) || gr_acl_tpe_check()) &&
59889 + (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
59890 + (inode->i_mode & S_IWOTH))))) {
59891 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59892 + return 0;
59893 + }
59894 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59895 + if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
59896 + ((inode->i_uid && (inode->i_uid != cred->uid)) ||
59897 + (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
59898 + gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
59899 + return 0;
59900 + }
59901 +#endif
59902 +#endif
59903 + return 1;
59904 +}
59905 diff -urNp linux-2.6.39.2/grsecurity/grsum.c linux-2.6.39.2/grsecurity/grsum.c
59906 --- linux-2.6.39.2/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
59907 +++ linux-2.6.39.2/grsecurity/grsum.c 2011-05-22 19:41:42.000000000 -0400
59908 @@ -0,0 +1,61 @@
59909 +#include <linux/err.h>
59910 +#include <linux/kernel.h>
59911 +#include <linux/sched.h>
59912 +#include <linux/mm.h>
59913 +#include <linux/scatterlist.h>
59914 +#include <linux/crypto.h>
59915 +#include <linux/gracl.h>
59916 +
59917 +
59918 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59919 +#error "crypto and sha256 must be built into the kernel"
59920 +#endif
59921 +
59922 +int
59923 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59924 +{
59925 + char *p;
59926 + struct crypto_hash *tfm;
59927 + struct hash_desc desc;
59928 + struct scatterlist sg;
59929 + unsigned char temp_sum[GR_SHA_LEN];
59930 + volatile int retval = 0;
59931 + volatile int dummy = 0;
59932 + unsigned int i;
59933 +
59934 + sg_init_table(&sg, 1);
59935 +
59936 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59937 + if (IS_ERR(tfm)) {
59938 + /* should never happen, since sha256 should be built in */
59939 + return 1;
59940 + }
59941 +
59942 + desc.tfm = tfm;
59943 + desc.flags = 0;
59944 +
59945 + crypto_hash_init(&desc);
59946 +
59947 + p = salt;
59948 + sg_set_buf(&sg, p, GR_SALT_LEN);
59949 + crypto_hash_update(&desc, &sg, sg.length);
59950 +
59951 + p = entry->pw;
59952 + sg_set_buf(&sg, p, strlen(p));
59953 +
59954 + crypto_hash_update(&desc, &sg, sg.length);
59955 +
59956 + crypto_hash_final(&desc, temp_sum);
59957 +
59958 + memset(entry->pw, 0, GR_PW_LEN);
59959 +
59960 + for (i = 0; i < GR_SHA_LEN; i++)
59961 + if (sum[i] != temp_sum[i])
59962 + retval = 1;
59963 + else
59964 + dummy = 1; // waste a cycle
59965 +
59966 + crypto_free_hash(tfm);
59967 +
59968 + return retval;
59969 +}
59970 diff -urNp linux-2.6.39.2/grsecurity/Kconfig linux-2.6.39.2/grsecurity/Kconfig
59971 --- linux-2.6.39.2/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
59972 +++ linux-2.6.39.2/grsecurity/Kconfig 2011-06-13 21:34:34.000000000 -0400
59973 @@ -0,0 +1,1045 @@
59974 +#
59975 +# grecurity configuration
59976 +#
59977 +
59978 +menu "Grsecurity"
59979 +
59980 +config GRKERNSEC
59981 + bool "Grsecurity"
59982 + select CRYPTO
59983 + select CRYPTO_SHA256
59984 + help
59985 + If you say Y here, you will be able to configure many features
59986 + that will enhance the security of your system. It is highly
59987 + recommended that you say Y here and read through the help
59988 + for each option so that you fully understand the features and
59989 + can evaluate their usefulness for your machine.
59990 +
59991 +choice
59992 + prompt "Security Level"
59993 + depends on GRKERNSEC
59994 + default GRKERNSEC_CUSTOM
59995 +
59996 +config GRKERNSEC_LOW
59997 + bool "Low"
59998 + select GRKERNSEC_LINK
59999 + select GRKERNSEC_FIFO
60000 + select GRKERNSEC_EXECVE
60001 + select GRKERNSEC_RANDNET
60002 + select GRKERNSEC_DMESG
60003 + select GRKERNSEC_CHROOT
60004 + select GRKERNSEC_CHROOT_CHDIR
60005 +
60006 + help
60007 + If you choose this option, several of the grsecurity options will
60008 + be enabled that will give you greater protection against a number
60009 + of attacks, while assuring that none of your software will have any
60010 + conflicts with the additional security measures. If you run a lot
60011 + of unusual software, or you are having problems with the higher
60012 + security levels, you should say Y here. With this option, the
60013 + following features are enabled:
60014 +
60015 + - Linking restrictions
60016 + - FIFO restrictions
60017 + - Enforcing RLIMIT_NPROC on execve
60018 + - Restricted dmesg
60019 + - Enforced chdir("/") on chroot
60020 + - Runtime module disabling
60021 +
60022 +config GRKERNSEC_MEDIUM
60023 + bool "Medium"
60024 + select PAX
60025 + select PAX_EI_PAX
60026 + select PAX_PT_PAX_FLAGS
60027 + select PAX_HAVE_ACL_FLAGS
60028 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
60029 + select GRKERNSEC_CHROOT
60030 + select GRKERNSEC_CHROOT_SYSCTL
60031 + select GRKERNSEC_LINK
60032 + select GRKERNSEC_FIFO
60033 + select GRKERNSEC_EXECVE
60034 + select GRKERNSEC_DMESG
60035 + select GRKERNSEC_RANDNET
60036 + select GRKERNSEC_FORKFAIL
60037 + select GRKERNSEC_TIME
60038 + select GRKERNSEC_SIGNAL
60039 + select GRKERNSEC_CHROOT
60040 + select GRKERNSEC_CHROOT_UNIX
60041 + select GRKERNSEC_CHROOT_MOUNT
60042 + select GRKERNSEC_CHROOT_PIVOT
60043 + select GRKERNSEC_CHROOT_DOUBLE
60044 + select GRKERNSEC_CHROOT_CHDIR
60045 + select GRKERNSEC_CHROOT_MKNOD
60046 + select GRKERNSEC_PROC
60047 + select GRKERNSEC_PROC_USERGROUP
60048 + select PAX_RANDUSTACK
60049 + select PAX_ASLR
60050 + select PAX_RANDMMAP
60051 + select PAX_REFCOUNT if (X86 || SPARC64)
60052 + select PAX_USERCOPY if ((X86 || SPARC32 || SPARC64 || PPC) && (SLAB || SLUB || SLOB))
60053 +
60054 + help
60055 + If you say Y here, several features in addition to those included
60056 + in the low additional security level will be enabled. These
60057 + features provide even more security to your system, though in rare
60058 + cases they may be incompatible with very old or poorly written
60059 + software. If you enable this option, make sure that your auth
60060 + service (identd) is running as gid 1001. With this option,
60061 + the following features (in addition to those provided in the
60062 + low additional security level) will be enabled:
60063 +
60064 + - Failed fork logging
60065 + - Time change logging
60066 + - Signal logging
60067 + - Deny mounts in chroot
60068 + - Deny double chrooting
60069 + - Deny sysctl writes in chroot
60070 + - Deny mknod in chroot
60071 + - Deny access to abstract AF_UNIX sockets out of chroot
60072 + - Deny pivot_root in chroot
60073 + - Denied writes of /dev/kmem, /dev/mem, and /dev/port
60074 + - /proc restrictions with special GID set to 10 (usually wheel)
60075 + - Address Space Layout Randomization (ASLR)
60076 + - Prevent exploitation of most refcount overflows
60077 + - Bounds checking of copying between the kernel and userland
60078 +
60079 +config GRKERNSEC_HIGH
60080 + bool "High"
60081 + select GRKERNSEC_LINK
60082 + select GRKERNSEC_FIFO
60083 + select GRKERNSEC_EXECVE
60084 + select GRKERNSEC_DMESG
60085 + select GRKERNSEC_FORKFAIL
60086 + select GRKERNSEC_TIME
60087 + select GRKERNSEC_SIGNAL
60088 + select GRKERNSEC_CHROOT
60089 + select GRKERNSEC_CHROOT_SHMAT
60090 + select GRKERNSEC_CHROOT_UNIX
60091 + select GRKERNSEC_CHROOT_MOUNT
60092 + select GRKERNSEC_CHROOT_FCHDIR
60093 + select GRKERNSEC_CHROOT_PIVOT
60094 + select GRKERNSEC_CHROOT_DOUBLE
60095 + select GRKERNSEC_CHROOT_CHDIR
60096 + select GRKERNSEC_CHROOT_MKNOD
60097 + select GRKERNSEC_CHROOT_CAPS
60098 + select GRKERNSEC_CHROOT_SYSCTL
60099 + select GRKERNSEC_CHROOT_FINDTASK
60100 + select GRKERNSEC_SYSFS_RESTRICT
60101 + select GRKERNSEC_PROC
60102 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
60103 + select GRKERNSEC_HIDESYM
60104 + select GRKERNSEC_BRUTE
60105 + select GRKERNSEC_PROC_USERGROUP
60106 + select GRKERNSEC_KMEM
60107 + select GRKERNSEC_RESLOG
60108 + select GRKERNSEC_RANDNET
60109 + select GRKERNSEC_PROC_ADD
60110 + select GRKERNSEC_CHROOT_CHMOD
60111 + select GRKERNSEC_CHROOT_NICE
60112 + select GRKERNSEC_AUDIT_MOUNT
60113 + select GRKERNSEC_MODHARDEN if (MODULES)
60114 + select GRKERNSEC_HARDEN_PTRACE
60115 + select GRKERNSEC_VM86 if (X86_32)
60116 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC32 || SPARC64)
60117 + select PAX
60118 + select PAX_RANDUSTACK
60119 + select PAX_ASLR
60120 + select PAX_RANDMMAP
60121 + select PAX_NOEXEC
60122 + select PAX_MPROTECT
60123 + select PAX_EI_PAX
60124 + select PAX_PT_PAX_FLAGS
60125 + select PAX_HAVE_ACL_FLAGS
60126 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
60127 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
60128 + select PAX_RANDKSTACK if (X86_TSC && X86)
60129 + select PAX_SEGMEXEC if (X86_32)
60130 + select PAX_PAGEEXEC
60131 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC32 || SPARC64)
60132 + select PAX_EMUTRAMP if (PARISC)
60133 + select PAX_EMUSIGRT if (PARISC)
60134 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
60135 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
60136 + select PAX_REFCOUNT if (X86 || SPARC64)
60137 + select PAX_USERCOPY if ((X86 || PPC || SPARC32 || SPARC64) && (SLAB || SLUB || SLOB))
60138 + help
60139 + If you say Y here, many of the features of grsecurity will be
60140 + enabled, which will protect you against many kinds of attacks
60141 + against your system. The heightened security comes at a cost
60142 + of an increased chance of incompatibilities with rare software
60143 + on your machine. Since this security level enables PaX, you should
60144 + view <http://pax.grsecurity.net> and read about the PaX
60145 + project. While you are there, download chpax and run it on
60146 + binaries that cause problems with PaX. Also remember that
60147 + since the /proc restrictions are enabled, you must run your
60148 + identd as gid 1001. This security level enables the following
60149 + features in addition to those listed in the low and medium
60150 + security levels:
60151 +
60152 + - Additional /proc restrictions
60153 + - Chmod restrictions in chroot
60154 + - No signals, ptrace, or viewing of processes outside of chroot
60155 + - Capability restrictions in chroot
60156 + - Deny fchdir out of chroot
60157 + - Priority restrictions in chroot
60158 + - Segmentation-based implementation of PaX
60159 + - Mprotect restrictions
60160 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
60161 + - Kernel stack randomization
60162 + - Mount/unmount/remount logging
60163 + - Kernel symbol hiding
60164 + - Prevention of memory exhaustion-based exploits
60165 + - Hardening of module auto-loading
60166 + - Ptrace restrictions
60167 + - Restricted vm86 mode
60168 + - Restricted sysfs/debugfs
60169 + - Active kernel exploit response
60170 +
60171 +config GRKERNSEC_CUSTOM
60172 + bool "Custom"
60173 + help
60174 + If you say Y here, you will be able to configure every grsecurity
60175 + option, which allows you to enable many more features that aren't
60176 + covered in the basic security levels. These additional features
60177 + include TPE, socket restrictions, and the sysctl system for
60178 + grsecurity. It is advised that you read through the help for
60179 + each option to determine its usefulness in your situation.
60180 +
60181 +endchoice
60182 +
60183 +menu "Address Space Protection"
60184 +depends on GRKERNSEC
60185 +
60186 +config GRKERNSEC_KMEM
60187 + bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
60188 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60189 + help
60190 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60191 + be written to via mmap or otherwise to modify the running kernel.
60192 + /dev/port will also not be allowed to be opened. If you have module
60193 + support disabled, enabling this will close up four ways that are
60194 + currently used to insert malicious code into the running kernel.
60195 + Even with all these features enabled, we still highly recommend that
60196 + you use the RBAC system, as it is still possible for an attacker to
60197 + modify the running kernel through privileged I/O granted by ioperm/iopl.
60198 + If you are not using XFree86, you may be able to stop this additional
60199 + case by enabling the 'Disable privileged I/O' option. Though nothing
60200 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60201 + but only to video memory, which is the only writing we allow in this
60202 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60203 + not be allowed to mprotect it with PROT_WRITE later.
60204 + It is highly recommended that you say Y here if you meet all the
60205 + conditions above.
60206 +
60207 +config GRKERNSEC_VM86
60208 + bool "Restrict VM86 mode"
60209 + depends on X86_32
60210 +
60211 + help
60212 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60213 + make use of a special execution mode on 32bit x86 processors called
60214 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60215 + video cards and will still work with this option enabled. The purpose
60216 + of the option is to prevent exploitation of emulation errors in
60217 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
60218 + Nearly all users should be able to enable this option.
60219 +
60220 +config GRKERNSEC_IO
60221 + bool "Disable privileged I/O"
60222 + depends on X86
60223 + select RTC_CLASS
60224 + select RTC_INTF_DEV
60225 + select RTC_DRV_CMOS
60226 +
60227 + help
60228 + If you say Y here, all ioperm and iopl calls will return an error.
60229 + Ioperm and iopl can be used to modify the running kernel.
60230 + Unfortunately, some programs need this access to operate properly,
60231 + the most notable of which are XFree86 and hwclock. hwclock can be
60232 + remedied by having RTC support in the kernel, so real-time
60233 + clock support is enabled if this option is enabled, to ensure
60234 + that hwclock operates correctly. XFree86 still will not
60235 + operate correctly with this option enabled, so DO NOT CHOOSE Y
60236 + IF YOU USE XFree86. If you use XFree86 and you still want to
60237 + protect your kernel against modification, use the RBAC system.
60238 +
60239 +config GRKERNSEC_PROC_MEMMAP
60240 + bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
60241 + default y if (PAX_NOEXEC || PAX_ASLR)
60242 + depends on PAX_NOEXEC || PAX_ASLR
60243 + help
60244 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60245 + give no information about the addresses of its mappings if
60246 + PaX features that rely on random addresses are enabled on the task.
60247 + If you use PaX it is greatly recommended that you say Y here as it
60248 + closes up a hole that makes the full ASLR useless for suid
60249 + binaries.
60250 +
60251 +config GRKERNSEC_BRUTE
60252 + bool "Deter exploit bruteforcing"
60253 + help
60254 + If you say Y here, attempts to bruteforce exploits against forking
60255 + daemons such as apache or sshd, as well as against suid/sgid binaries
60256 + will be deterred. When a child of a forking daemon is killed by PaX
60257 + or crashes due to an illegal instruction or other suspicious signal,
60258 + the parent process will be delayed 30 seconds upon every subsequent
60259 + fork until the administrator is able to assess the situation and
60260 + restart the daemon.
60261 + In the suid/sgid case, the attempt is logged, the user has all their
60262 + processes terminated, and they are prevented from executing any further
60263 + processes for 15 minutes.
60264 + It is recommended that you also enable signal logging in the auditing
60265 + section so that logs are generated when a process triggers a suspicious
60266 + signal.
60267 +
60268 +config GRKERNSEC_MODHARDEN
60269 + bool "Harden module auto-loading"
60270 + depends on MODULES
60271 + help
60272 + If you say Y here, module auto-loading in response to use of some
60273 + feature implemented by an unloaded module will be restricted to
60274 + root users. Enabling this option helps defend against attacks
60275 + by unprivileged users who abuse the auto-loading behavior to
60276 + cause a vulnerable module to load that is then exploited.
60277 +
60278 + If this option prevents a legitimate use of auto-loading for a
60279 + non-root user, the administrator can execute modprobe manually
60280 + with the exact name of the module mentioned in the alert log.
60281 + Alternatively, the administrator can add the module to the list
60282 + of modules loaded at boot by modifying init scripts.
60283 +
60284 + Modification of init scripts will most likely be needed on
60285 + Ubuntu servers with encrypted home directory support enabled,
60286 + as the first non-root user logging in will cause the ecb(aes),
60287 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60288 +
60289 +config GRKERNSEC_HIDESYM
60290 + bool "Hide kernel symbols"
60291 + help
60292 + If you say Y here, getting information on loaded modules, and
60293 + displaying all kernel symbols through a syscall will be restricted
60294 + to users with CAP_SYS_MODULE. For software compatibility reasons,
60295 + /proc/kallsyms will be restricted to the root user. The RBAC
60296 + system can hide that entry even from root.
60297 +
60298 + This option also prevents leaking of kernel addresses through
60299 + several /proc entries.
60300 +
60301 + Note that this option is only effective provided the following
60302 + conditions are met:
60303 + 1) The kernel using grsecurity is not precompiled by some distribution
60304 + 2) You have also enabled GRKERNSEC_DMESG
60305 + 3) You are using the RBAC system and hiding other files such as your
60306 + kernel image and System.map. Alternatively, enabling this option
60307 + causes the permissions on /boot, /lib/modules, and the kernel
60308 + source directory to change at compile time to prevent
60309 + reading by non-root users.
60310 + If the above conditions are met, this option will aid in providing a
60311 + useful protection against local kernel exploitation of overflows
60312 + and arbitrary read/write vulnerabilities.
60313 +
60314 +config GRKERNSEC_KERN_LOCKOUT
60315 + bool "Active kernel exploit response"
60316 + depends on X86 || ARM || PPC || SPARC32 || SPARC64
60317 + help
60318 + If you say Y here, when a PaX alert is triggered due to suspicious
60319 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60320 + or an OOPs occurs due to bad memory accesses, instead of just
60321 + terminating the offending process (and potentially allowing
60322 + a subsequent exploit from the same user), we will take one of two
60323 + actions:
60324 + If the user was root, we will panic the system
60325 + If the user was non-root, we will log the attempt, terminate
60326 + all processes owned by the user, then prevent them from creating
60327 + any new processes until the system is restarted
60328 + This deters repeated kernel exploitation/bruteforcing attempts
60329 + and is useful for later forensics.
60330 +
60331 +endmenu
60332 +menu "Role Based Access Control Options"
60333 +depends on GRKERNSEC
60334 +
60335 +config GRKERNSEC_RBAC_DEBUG
60336 + bool
60337 +
60338 +config GRKERNSEC_NO_RBAC
60339 + bool "Disable RBAC system"
60340 + help
60341 + If you say Y here, the /dev/grsec device will be removed from the kernel,
60342 + preventing the RBAC system from being enabled. You should only say Y
60343 + here if you have no intention of using the RBAC system, so as to prevent
60344 + an attacker with root access from misusing the RBAC system to hide files
60345 + and processes when loadable module support and /dev/[k]mem have been
60346 + locked down.
60347 +
60348 +config GRKERNSEC_ACL_HIDEKERN
60349 + bool "Hide kernel processes"
60350 + help
60351 + If you say Y here, all kernel threads will be hidden to all
60352 + processes but those whose subject has the "view hidden processes"
60353 + flag.
60354 +
60355 +config GRKERNSEC_ACL_MAXTRIES
60356 + int "Maximum tries before password lockout"
60357 + default 3
60358 + help
60359 + This option enforces the maximum number of times a user can attempt
60360 + to authorize themselves with the grsecurity RBAC system before being
60361 + denied the ability to attempt authorization again for a specified time.
60362 + The lower the number, the harder it will be to brute-force a password.
60363 +
60364 +config GRKERNSEC_ACL_TIMEOUT
60365 + int "Time to wait after max password tries, in seconds"
60366 + default 30
60367 + help
60368 + This option specifies the time the user must wait after attempting to
60369 + authorize to the RBAC system with the maximum number of invalid
60370 + passwords. The higher the number, the harder it will be to brute-force
60371 + a password.
60372 +
60373 +endmenu
60374 +menu "Filesystem Protections"
60375 +depends on GRKERNSEC
60376 +
60377 +config GRKERNSEC_PROC
60378 + bool "Proc restrictions"
60379 + help
60380 + If you say Y here, the permissions of the /proc filesystem
60381 + will be altered to enhance system security and privacy. You MUST
60382 + choose either a user only restriction or a user and group restriction.
60383 + Depending upon the option you choose, you can either restrict users to
60384 + see only the processes they themselves run, or choose a group that can
60385 + view all processes and files normally restricted to root if you choose
60386 + the "restrict to user only" option. NOTE: If you're running identd as
60387 + a non-root user, you will have to run it as the group you specify here.
60388 +
60389 +config GRKERNSEC_PROC_USER
60390 + bool "Restrict /proc to user only"
60391 + depends on GRKERNSEC_PROC
60392 + help
60393 + If you say Y here, non-root users will only be able to view their own
60394 + processes, and restricts them from viewing network-related information,
60395 + and viewing kernel symbol and module information.
60396 +
60397 +config GRKERNSEC_PROC_USERGROUP
60398 + bool "Allow special group"
60399 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
60400 + help
60401 + If you say Y here, you will be able to select a group that will be
60402 + able to view all processes and network-related information. If you've
60403 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
60404 + remain hidden. This option is useful if you want to run identd as
60405 + a non-root user.
60406 +
60407 +config GRKERNSEC_PROC_GID
60408 + int "GID for special group"
60409 + depends on GRKERNSEC_PROC_USERGROUP
60410 + default 1001
60411 +
60412 +config GRKERNSEC_PROC_ADD
60413 + bool "Additional restrictions"
60414 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
60415 + help
60416 + If you say Y here, additional restrictions will be placed on
60417 + /proc that keep normal users from viewing device information and
60418 + slabinfo information that could be useful for exploits.
60419 +
60420 +config GRKERNSEC_LINK
60421 + bool "Linking restrictions"
60422 + help
60423 + If you say Y here, /tmp race exploits will be prevented, since users
60424 + will no longer be able to follow symlinks owned by other users in
60425 + world-writable +t directories (e.g. /tmp), unless the owner of the
60426 + symlink is the owner of the directory. users will also not be
60427 + able to hardlink to files they do not own. If the sysctl option is
60428 + enabled, a sysctl option with name "linking_restrictions" is created.
60429 +
60430 +config GRKERNSEC_FIFO
60431 + bool "FIFO restrictions"
60432 + help
60433 + If you say Y here, users will not be able to write to FIFOs they don't
60434 + own in world-writable +t directories (e.g. /tmp), unless the owner of
60435 + the FIFO is the same owner of the directory it's held in. If the sysctl
60436 + option is enabled, a sysctl option with name "fifo_restrictions" is
60437 + created.
60438 +
60439 +config GRKERNSEC_SYSFS_RESTRICT
60440 + bool "Sysfs/debugfs restriction"
60441 + depends on SYSFS
60442 + help
60443 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
60444 + any filesystem normally mounted under it (e.g. debugfs) will only
60445 + be accessible by root. These filesystems generally provide access
60446 + to hardware and debug information that isn't appropriate for unprivileged
60447 + users of the system. Sysfs and debugfs have also become a large source
60448 + of new vulnerabilities, ranging from infoleaks to local compromise.
60449 + There has been very little oversight with an eye toward security involved
60450 + in adding new exporters of information to these filesystems, so their
60451 + use is discouraged.
60452 + This option is equivalent to a chmod 0700 of the mount paths.
60453 +
60454 +config GRKERNSEC_ROFS
60455 + bool "Runtime read-only mount protection"
60456 + help
60457 + If you say Y here, a sysctl option with name "romount_protect" will
60458 + be created. By setting this option to 1 at runtime, filesystems
60459 + will be protected in the following ways:
60460 + * No new writable mounts will be allowed
60461 + * Existing read-only mounts won't be able to be remounted read/write
60462 + * Write operations will be denied on all block devices
60463 + This option acts independently of grsec_lock: once it is set to 1,
60464 + it cannot be turned off. Therefore, please be mindful of the resulting
60465 + behavior if this option is enabled in an init script on a read-only
60466 + filesystem. This feature is mainly intended for secure embedded systems.
60467 +
60468 +config GRKERNSEC_CHROOT
60469 + bool "Chroot jail restrictions"
60470 + help
60471 + If you say Y here, you will be able to choose several options that will
60472 + make breaking out of a chrooted jail much more difficult. If you
60473 + encounter no software incompatibilities with the following options, it
60474 + is recommended that you enable each one.
60475 +
60476 +config GRKERNSEC_CHROOT_MOUNT
60477 + bool "Deny mounts"
60478 + depends on GRKERNSEC_CHROOT
60479 + help
60480 + If you say Y here, processes inside a chroot will not be able to
60481 + mount or remount filesystems. If the sysctl option is enabled, a
60482 + sysctl option with name "chroot_deny_mount" is created.
60483 +
60484 +config GRKERNSEC_CHROOT_DOUBLE
60485 + bool "Deny double-chroots"
60486 + depends on GRKERNSEC_CHROOT
60487 + help
60488 + If you say Y here, processes inside a chroot will not be able to chroot
60489 + again outside the chroot. This is a widely used method of breaking
60490 + out of a chroot jail and should not be allowed. If the sysctl
60491 + option is enabled, a sysctl option with name
60492 + "chroot_deny_chroot" is created.
60493 +
60494 +config GRKERNSEC_CHROOT_PIVOT
60495 + bool "Deny pivot_root in chroot"
60496 + depends on GRKERNSEC_CHROOT
60497 + help
60498 + If you say Y here, processes inside a chroot will not be able to use
60499 + a function called pivot_root() that was introduced in Linux 2.3.41. It
60500 + works similar to chroot in that it changes the root filesystem. This
60501 + function could be misused in a chrooted process to attempt to break out
60502 + of the chroot, and therefore should not be allowed. If the sysctl
60503 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
60504 + created.
60505 +
60506 +config GRKERNSEC_CHROOT_CHDIR
60507 + bool "Enforce chdir(\"/\") on all chroots"
60508 + depends on GRKERNSEC_CHROOT
60509 + help
60510 + If you say Y here, the current working directory of all newly-chrooted
60511 + applications will be set to the the root directory of the chroot.
60512 + The man page on chroot(2) states:
60513 + Note that this call does not change the current working
60514 + directory, so that `.' can be outside the tree rooted at
60515 + `/'. In particular, the super-user can escape from a
60516 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
60517 +
60518 + It is recommended that you say Y here, since it's not known to break
60519 + any software. If the sysctl option is enabled, a sysctl option with
60520 + name "chroot_enforce_chdir" is created.
60521 +
60522 +config GRKERNSEC_CHROOT_CHMOD
60523 + bool "Deny (f)chmod +s"
60524 + depends on GRKERNSEC_CHROOT
60525 + help
60526 + If you say Y here, processes inside a chroot will not be able to chmod
60527 + or fchmod files to make them have suid or sgid bits. This protects
60528 + against another published method of breaking a chroot. If the sysctl
60529 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
60530 + created.
60531 +
60532 +config GRKERNSEC_CHROOT_FCHDIR
60533 + bool "Deny fchdir out of chroot"
60534 + depends on GRKERNSEC_CHROOT
60535 + help
60536 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
60537 + to a file descriptor of the chrooting process that points to a directory
60538 + outside the filesystem will be stopped. If the sysctl option
60539 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
60540 +
60541 +config GRKERNSEC_CHROOT_MKNOD
60542 + bool "Deny mknod"
60543 + depends on GRKERNSEC_CHROOT
60544 + help
60545 + If you say Y here, processes inside a chroot will not be allowed to
60546 + mknod. The problem with using mknod inside a chroot is that it
60547 + would allow an attacker to create a device entry that is the same
60548 + as one on the physical root of your system, which could range from
60549 + anything from the console device to a device for your harddrive (which
60550 + they could then use to wipe the drive or steal data). It is recommended
60551 + that you say Y here, unless you run into software incompatibilities.
60552 + If the sysctl option is enabled, a sysctl option with name
60553 + "chroot_deny_mknod" is created.
60554 +
60555 +config GRKERNSEC_CHROOT_SHMAT
60556 + bool "Deny shmat() out of chroot"
60557 + depends on GRKERNSEC_CHROOT
60558 + help
60559 + If you say Y here, processes inside a chroot will not be able to attach
60560 + to shared memory segments that were created outside of the chroot jail.
60561 + It is recommended that you say Y here. If the sysctl option is enabled,
60562 + a sysctl option with name "chroot_deny_shmat" is created.
60563 +
60564 +config GRKERNSEC_CHROOT_UNIX
60565 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
60566 + depends on GRKERNSEC_CHROOT
60567 + help
60568 + If you say Y here, processes inside a chroot will not be able to
60569 + connect to abstract (meaning not belonging to a filesystem) Unix
60570 + domain sockets that were bound outside of a chroot. It is recommended
60571 + that you say Y here. If the sysctl option is enabled, a sysctl option
60572 + with name "chroot_deny_unix" is created.
60573 +
60574 +config GRKERNSEC_CHROOT_FINDTASK
60575 + bool "Protect outside processes"
60576 + depends on GRKERNSEC_CHROOT
60577 + help
60578 + If you say Y here, processes inside a chroot will not be able to
60579 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
60580 + getsid, or view any process outside of the chroot. If the sysctl
60581 + option is enabled, a sysctl option with name "chroot_findtask" is
60582 + created.
60583 +
60584 +config GRKERNSEC_CHROOT_NICE
60585 + bool "Restrict priority changes"
60586 + depends on GRKERNSEC_CHROOT
60587 + help
60588 + If you say Y here, processes inside a chroot will not be able to raise
60589 + the priority of processes in the chroot, or alter the priority of
60590 + processes outside the chroot. This provides more security than simply
60591 + removing CAP_SYS_NICE from the process' capability set. If the
60592 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
60593 + is created.
60594 +
60595 +config GRKERNSEC_CHROOT_SYSCTL
60596 + bool "Deny sysctl writes"
60597 + depends on GRKERNSEC_CHROOT
60598 + help
60599 + If you say Y here, an attacker in a chroot will not be able to
60600 + write to sysctl entries, either by sysctl(2) or through a /proc
60601 + interface. It is strongly recommended that you say Y here. If the
60602 + sysctl option is enabled, a sysctl option with name
60603 + "chroot_deny_sysctl" is created.
60604 +
60605 +config GRKERNSEC_CHROOT_CAPS
60606 + bool "Capability restrictions"
60607 + depends on GRKERNSEC_CHROOT
60608 + help
60609 + If you say Y here, the capabilities on all root processes within a
60610 + chroot jail will be lowered to stop module insertion, raw i/o,
60611 + system and net admin tasks, rebooting the system, modifying immutable
60612 + files, modifying IPC owned by another, and changing the system time.
60613 + This is left an option because it can break some apps. Disable this
60614 + if your chrooted apps are having problems performing those kinds of
60615 + tasks. If the sysctl option is enabled, a sysctl option with
60616 + name "chroot_caps" is created.
60617 +
60618 +endmenu
60619 +menu "Kernel Auditing"
60620 +depends on GRKERNSEC
60621 +
60622 +config GRKERNSEC_AUDIT_GROUP
60623 + bool "Single group for auditing"
60624 + help
60625 + If you say Y here, the exec, chdir, and (un)mount logging features
60626 + will only operate on a group you specify. This option is recommended
60627 + if you only want to watch certain users instead of having a large
60628 + amount of logs from the entire system. If the sysctl option is enabled,
60629 + a sysctl option with name "audit_group" is created.
60630 +
60631 +config GRKERNSEC_AUDIT_GID
60632 + int "GID for auditing"
60633 + depends on GRKERNSEC_AUDIT_GROUP
60634 + default 1007
60635 +
60636 +config GRKERNSEC_EXECLOG
60637 + bool "Exec logging"
60638 + help
60639 + If you say Y here, all execve() calls will be logged (since the
60640 + other exec*() calls are frontends to execve(), all execution
60641 + will be logged). Useful for shell-servers that like to keep track
60642 + of their users. If the sysctl option is enabled, a sysctl option with
60643 + name "exec_logging" is created.
60644 + WARNING: This option when enabled will produce a LOT of logs, especially
60645 + on an active system.
60646 +
60647 +config GRKERNSEC_RESLOG
60648 + bool "Resource logging"
60649 + help
60650 + If you say Y here, all attempts to overstep resource limits will
60651 + be logged with the resource name, the requested size, and the current
60652 + limit. It is highly recommended that you say Y here. If the sysctl
60653 + option is enabled, a sysctl option with name "resource_logging" is
60654 + created. If the RBAC system is enabled, the sysctl value is ignored.
60655 +
60656 +config GRKERNSEC_CHROOT_EXECLOG
60657 + bool "Log execs within chroot"
60658 + help
60659 + If you say Y here, all executions inside a chroot jail will be logged
60660 + to syslog. This can cause a large amount of logs if certain
60661 + applications (eg. djb's daemontools) are installed on the system, and
60662 + is therefore left as an option. If the sysctl option is enabled, a
60663 + sysctl option with name "chroot_execlog" is created.
60664 +
60665 +config GRKERNSEC_AUDIT_PTRACE
60666 + bool "Ptrace logging"
60667 + help
60668 + If you say Y here, all attempts to attach to a process via ptrace
60669 + will be logged. If the sysctl option is enabled, a sysctl option
60670 + with name "audit_ptrace" is created.
60671 +
60672 +config GRKERNSEC_AUDIT_CHDIR
60673 + bool "Chdir logging"
60674 + help
60675 + If you say Y here, all chdir() calls will be logged. If the sysctl
60676 + option is enabled, a sysctl option with name "audit_chdir" is created.
60677 +
60678 +config GRKERNSEC_AUDIT_MOUNT
60679 + bool "(Un)Mount logging"
60680 + help
60681 + If you say Y here, all mounts and unmounts will be logged. If the
60682 + sysctl option is enabled, a sysctl option with name "audit_mount" is
60683 + created.
60684 +
60685 +config GRKERNSEC_SIGNAL
60686 + bool "Signal logging"
60687 + help
60688 + If you say Y here, certain important signals will be logged, such as
60689 + SIGSEGV, which will as a result inform you of when a error in a program
60690 + occurred, which in some cases could mean a possible exploit attempt.
60691 + If the sysctl option is enabled, a sysctl option with name
60692 + "signal_logging" is created.
60693 +
60694 +config GRKERNSEC_FORKFAIL
60695 + bool "Fork failure logging"
60696 + help
60697 + If you say Y here, all failed fork() attempts will be logged.
60698 + This could suggest a fork bomb, or someone attempting to overstep
60699 + their process limit. If the sysctl option is enabled, a sysctl option
60700 + with name "forkfail_logging" is created.
60701 +
60702 +config GRKERNSEC_TIME
60703 + bool "Time change logging"
60704 + help
60705 + If you say Y here, any changes of the system clock will be logged.
60706 + If the sysctl option is enabled, a sysctl option with name
60707 + "timechange_logging" is created.
60708 +
60709 +config GRKERNSEC_PROC_IPADDR
60710 + bool "/proc/<pid>/ipaddr support"
60711 + help
60712 + If you say Y here, a new entry will be added to each /proc/<pid>
60713 + directory that contains the IP address of the person using the task.
60714 + The IP is carried across local TCP and AF_UNIX stream sockets.
60715 + This information can be useful for IDS/IPSes to perform remote response
60716 + to a local attack. The entry is readable by only the owner of the
60717 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
60718 + the RBAC system), and thus does not create privacy concerns.
60719 +
60720 +config GRKERNSEC_RWXMAP_LOG
60721 + bool 'Denied RWX mmap/mprotect logging'
60722 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
60723 + help
60724 + If you say Y here, calls to mmap() and mprotect() with explicit
60725 + usage of PROT_WRITE and PROT_EXEC together will be logged when
60726 + denied by the PAX_MPROTECT feature. If the sysctl option is
60727 + enabled, a sysctl option with name "rwxmap_logging" is created.
60728 +
60729 +config GRKERNSEC_AUDIT_TEXTREL
60730 + bool 'ELF text relocations logging (READ HELP)'
60731 + depends on PAX_MPROTECT
60732 + help
60733 + If you say Y here, text relocations will be logged with the filename
60734 + of the offending library or binary. The purpose of the feature is
60735 + to help Linux distribution developers get rid of libraries and
60736 + binaries that need text relocations which hinder the future progress
60737 + of PaX. Only Linux distribution developers should say Y here, and
60738 + never on a production machine, as this option creates an information
60739 + leak that could aid an attacker in defeating the randomization of
60740 + a single memory region. If the sysctl option is enabled, a sysctl
60741 + option with name "audit_textrel" is created.
60742 +
60743 +endmenu
60744 +
60745 +menu "Executable Protections"
60746 +depends on GRKERNSEC
60747 +
60748 +config GRKERNSEC_EXECVE
60749 + bool "Enforce RLIMIT_NPROC on execs"
60750 + help
60751 + If you say Y here, users with a resource limit on processes will
60752 + have the value checked during execve() calls. The current system
60753 + only checks the system limit during fork() calls. If the sysctl option
60754 + is enabled, a sysctl option with name "execve_limiting" is created.
60755 +
60756 +config GRKERNSEC_DMESG
60757 + bool "Dmesg(8) restriction"
60758 + help
60759 + If you say Y here, non-root users will not be able to use dmesg(8)
60760 + to view up to the last 4kb of messages in the kernel's log buffer.
60761 + The kernel's log buffer often contains kernel addresses and other
60762 + identifying information useful to an attacker in fingerprinting a
60763 + system for a targeted exploit.
60764 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
60765 + created.
60766 +
60767 +config GRKERNSEC_HARDEN_PTRACE
60768 + bool "Deter ptrace-based process snooping"
60769 + help
60770 + If you say Y here, TTY sniffers and other malicious monitoring
60771 + programs implemented through ptrace will be defeated. If you
60772 + have been using the RBAC system, this option has already been
60773 + enabled for several years for all users, with the ability to make
60774 + fine-grained exceptions.
60775 +
60776 + This option only affects the ability of non-root users to ptrace
60777 + processes that are not a descendent of the ptracing process.
60778 + This means that strace ./binary and gdb ./binary will still work,
60779 + but attaching to arbitrary processes will not. If the sysctl
60780 + option is enabled, a sysctl option with name "harden_ptrace" is
60781 + created.
60782 +
60783 +config GRKERNSEC_TPE
60784 + bool "Trusted Path Execution (TPE)"
60785 + help
60786 + If you say Y here, you will be able to choose a gid to add to the
60787 + supplementary groups of users you want to mark as "untrusted."
60788 + These users will not be able to execute any files that are not in
60789 + root-owned directories writable only by root. If the sysctl option
60790 + is enabled, a sysctl option with name "tpe" is created.
60791 +
60792 +config GRKERNSEC_TPE_ALL
60793 + bool "Partially restrict all non-root users"
60794 + depends on GRKERNSEC_TPE
60795 + help
60796 + If you say Y here, all non-root users will be covered under
60797 + a weaker TPE restriction. This is separate from, and in addition to,
60798 + the main TPE options that you have selected elsewhere. Thus, if a
60799 + "trusted" GID is chosen, this restriction applies to even that GID.
60800 + Under this restriction, all non-root users will only be allowed to
60801 + execute files in directories they own that are not group or
60802 + world-writable, or in directories owned by root and writable only by
60803 + root. If the sysctl option is enabled, a sysctl option with name
60804 + "tpe_restrict_all" is created.
60805 +
60806 +config GRKERNSEC_TPE_INVERT
60807 + bool "Invert GID option"
60808 + depends on GRKERNSEC_TPE
60809 + help
60810 + If you say Y here, the group you specify in the TPE configuration will
60811 + decide what group TPE restrictions will be *disabled* for. This
60812 + option is useful if you want TPE restrictions to be applied to most
60813 + users on the system. If the sysctl option is enabled, a sysctl option
60814 + with name "tpe_invert" is created. Unlike other sysctl options, this
60815 + entry will default to on for backward-compatibility.
60816 +
60817 +config GRKERNSEC_TPE_GID
60818 + int "GID for untrusted users"
60819 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
60820 + default 1005
60821 + help
60822 + Setting this GID determines what group TPE restrictions will be
60823 + *enabled* for. If the sysctl option is enabled, a sysctl option
60824 + with name "tpe_gid" is created.
60825 +
60826 +config GRKERNSEC_TPE_GID
60827 + int "GID for trusted users"
60828 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
60829 + default 1005
60830 + help
60831 + Setting this GID determines what group TPE restrictions will be
60832 + *disabled* for. If the sysctl option is enabled, a sysctl option
60833 + with name "tpe_gid" is created.
60834 +
60835 +endmenu
60836 +menu "Network Protections"
60837 +depends on GRKERNSEC
60838 +
60839 +config GRKERNSEC_RANDNET
60840 + bool "Larger entropy pools"
60841 + help
60842 + If you say Y here, the entropy pools used for many features of Linux
60843 + and grsecurity will be doubled in size. Since several grsecurity
60844 + features use additional randomness, it is recommended that you say Y
60845 + here. Saying Y here has a similar effect as modifying
60846 + /proc/sys/kernel/random/poolsize.
60847 +
60848 +config GRKERNSEC_BLACKHOLE
60849 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
60850 + help
60851 + If you say Y here, neither TCP resets nor ICMP
60852 + destination-unreachable packets will be sent in response to packets
60853 + sent to ports for which no associated listening process exists.
60854 + This feature supports both IPV4 and IPV6 and exempts the
60855 + loopback interface from blackholing. Enabling this feature
60856 + makes a host more resilient to DoS attacks and reduces network
60857 + visibility against scanners.
60858 +
60859 + The blackhole feature as-implemented is equivalent to the FreeBSD
60860 + blackhole feature, as it prevents RST responses to all packets, not
60861 + just SYNs. Under most application behavior this causes no
60862 + problems, but applications (like haproxy) may not close certain
60863 + connections in a way that cleanly terminates them on the remote
60864 + end, leaving the remote host in LAST_ACK state. Because of this
60865 + side-effect and to prevent intentional LAST_ACK DoSes, this
60866 + feature also adds automatic mitigation against such attacks.
60867 + The mitigation drastically reduces the amount of time a socket
60868 + can spend in LAST_ACK state. If you're using haproxy and not
60869 + all servers it connects to have this option enabled, consider
60870 + disabling this feature on the haproxy host.
60871 +
60872 + If the sysctl option is enabled, two sysctl options with names
60873 + "ip_blackhole" and "lastack_retries" will be created.
60874 + While "ip_blackhole" takes the standard zero/non-zero on/off
60875 + toggle, "lastack_retries" uses the same kinds of values as
60876 + "tcp_retries1" and "tcp_retries2". The default value of 4
60877 + prevents a socket from lasting more than 45 seconds in LAST_ACK
60878 + state.
60879 +
60880 +config GRKERNSEC_SOCKET
60881 + bool "Socket restrictions"
60882 + help
60883 + If you say Y here, you will be able to choose from several options.
60884 + If you assign a GID on your system and add it to the supplementary
60885 + groups of users you want to restrict socket access to, this patch
60886 + will perform up to three things, based on the option(s) you choose.
60887 +
60888 +config GRKERNSEC_SOCKET_ALL
60889 + bool "Deny any sockets to group"
60890 + depends on GRKERNSEC_SOCKET
60891 + help
60892 + If you say Y here, you will be able to choose a GID of whose users will
60893 + be unable to connect to other hosts from your machine or run server
60894 + applications from your machine. If the sysctl option is enabled, a
60895 + sysctl option with name "socket_all" is created.
60896 +
60897 +config GRKERNSEC_SOCKET_ALL_GID
60898 + int "GID to deny all sockets for"
60899 + depends on GRKERNSEC_SOCKET_ALL
60900 + default 1004
60901 + help
60902 + Here you can choose the GID to disable socket access for. Remember to
60903 + add the users you want socket access disabled for to the GID
60904 + specified here. If the sysctl option is enabled, a sysctl option
60905 + with name "socket_all_gid" is created.
60906 +
60907 +config GRKERNSEC_SOCKET_CLIENT
60908 + bool "Deny client sockets to group"
60909 + depends on GRKERNSEC_SOCKET
60910 + help
60911 + If you say Y here, you will be able to choose a GID of whose users will
60912 + be unable to connect to other hosts from your machine, but will be
60913 + able to run servers. If this option is enabled, all users in the group
60914 + you specify will have to use passive mode when initiating ftp transfers
60915 + from the shell on your machine. If the sysctl option is enabled, a
60916 + sysctl option with name "socket_client" is created.
60917 +
60918 +config GRKERNSEC_SOCKET_CLIENT_GID
60919 + int "GID to deny client sockets for"
60920 + depends on GRKERNSEC_SOCKET_CLIENT
60921 + default 1003
60922 + help
60923 + Here you can choose the GID to disable client socket access for.
60924 + Remember to add the users you want client socket access disabled for to
60925 + the GID specified here. If the sysctl option is enabled, a sysctl
60926 + option with name "socket_client_gid" is created.
60927 +
60928 +config GRKERNSEC_SOCKET_SERVER
60929 + bool "Deny server sockets to group"
60930 + depends on GRKERNSEC_SOCKET
60931 + help
60932 + If you say Y here, you will be able to choose a GID of whose users will
60933 + be unable to run server applications from your machine. If the sysctl
60934 + option is enabled, a sysctl option with name "socket_server" is created.
60935 +
60936 +config GRKERNSEC_SOCKET_SERVER_GID
60937 + int "GID to deny server sockets for"
60938 + depends on GRKERNSEC_SOCKET_SERVER
60939 + default 1002
60940 + help
60941 + Here you can choose the GID to disable server socket access for.
60942 + Remember to add the users you want server socket access disabled for to
60943 + the GID specified here. If the sysctl option is enabled, a sysctl
60944 + option with name "socket_server_gid" is created.
60945 +
60946 +endmenu
60947 +menu "Sysctl support"
60948 +depends on GRKERNSEC && SYSCTL
60949 +
60950 +config GRKERNSEC_SYSCTL
60951 + bool "Sysctl support"
60952 + help
60953 + If you say Y here, you will be able to change the options that
60954 + grsecurity runs with at bootup, without having to recompile your
60955 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
60956 + to enable (1) or disable (0) various features. All the sysctl entries
60957 + are mutable until the "grsec_lock" entry is set to a non-zero value.
60958 + All features enabled in the kernel configuration are disabled at boot
60959 + if you do not say Y to the "Turn on features by default" option.
60960 + All options should be set at startup, and the grsec_lock entry should
60961 + be set to a non-zero value after all the options are set.
60962 + *THIS IS EXTREMELY IMPORTANT*
60963 +
60964 +config GRKERNSEC_SYSCTL_DISTRO
60965 + bool "Extra sysctl support for distro makers (READ HELP)"
60966 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
60967 + help
60968 + If you say Y here, additional sysctl options will be created
60969 + for features that affect processes running as root. Therefore,
60970 + it is critical when using this option that the grsec_lock entry be
60971 + enabled after boot. Only distros with prebuilt kernel packages
60972 + with this option enabled that can ensure grsec_lock is enabled
60973 + after boot should use this option.
60974 + *Failure to set grsec_lock after boot makes all grsec features
60975 + this option covers useless*
60976 +
60977 + Currently this option creates the following sysctl entries:
60978 + "Disable Privileged I/O": "disable_priv_io"
60979 +
60980 +config GRKERNSEC_SYSCTL_ON
60981 + bool "Turn on features by default"
60982 + depends on GRKERNSEC_SYSCTL
60983 + help
60984 + If you say Y here, instead of having all features enabled in the
60985 + kernel configuration disabled at boot time, the features will be
60986 + enabled at boot time. It is recommended you say Y here unless
60987 + there is some reason you would want all sysctl-tunable features to
60988 + be disabled by default. As mentioned elsewhere, it is important
60989 + to enable the grsec_lock entry once you have finished modifying
60990 + the sysctl entries.
60991 +
60992 +endmenu
60993 +menu "Logging Options"
60994 +depends on GRKERNSEC
60995 +
60996 +config GRKERNSEC_FLOODTIME
60997 + int "Seconds in between log messages (minimum)"
60998 + default 10
60999 + help
61000 + This option allows you to enforce the number of seconds between
61001 + grsecurity log messages. The default should be suitable for most
61002 + people, however, if you choose to change it, choose a value small enough
61003 + to allow informative logs to be produced, but large enough to
61004 + prevent flooding.
61005 +
61006 +config GRKERNSEC_FLOODBURST
61007 + int "Number of messages in a burst (maximum)"
61008 + default 4
61009 + help
61010 + This option allows you to choose the maximum number of messages allowed
61011 + within the flood time interval you chose in a separate option. The
61012 + default should be suitable for most people, however if you find that
61013 + many of your logs are being interpreted as flooding, you may want to
61014 + raise this value.
61015 +
61016 +endmenu
61017 +
61018 +endmenu
61019 diff -urNp linux-2.6.39.2/grsecurity/Makefile linux-2.6.39.2/grsecurity/Makefile
61020 --- linux-2.6.39.2/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
61021 +++ linux-2.6.39.2/grsecurity/Makefile 2011-05-24 20:26:54.000000000 -0400
61022 @@ -0,0 +1,33 @@
61023 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
61024 +# during 2001-2009 it has been completely redesigned by Brad Spengler
61025 +# into an RBAC system
61026 +#
61027 +# All code in this directory and various hooks inserted throughout the kernel
61028 +# are copyright Brad Spengler - Open Source Security, Inc., and released
61029 +# under the GPL v2 or higher
61030 +
61031 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
61032 + grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
61033 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
61034 +
61035 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
61036 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
61037 + gracl_learn.o grsec_log.o
61038 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
61039 +
61040 +ifdef CONFIG_NET
61041 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
61042 +endif
61043 +
61044 +ifndef CONFIG_GRKERNSEC
61045 +obj-y += grsec_disabled.o
61046 +endif
61047 +
61048 +ifdef CONFIG_GRKERNSEC_HIDESYM
61049 +extra-y := grsec_hidesym.o
61050 +$(obj)/grsec_hidesym.o:
61051 + @-chmod -f 500 /boot
61052 + @-chmod -f 500 /lib/modules
61053 + @-chmod -f 700 .
61054 + @echo ' grsec: protected kernel image paths'
61055 +endif
61056 diff -urNp linux-2.6.39.2/include/acpi/acpi_drivers.h linux-2.6.39.2/include/acpi/acpi_drivers.h
61057 --- linux-2.6.39.2/include/acpi/acpi_drivers.h 2011-05-19 00:06:34.000000000 -0400
61058 +++ linux-2.6.39.2/include/acpi/acpi_drivers.h 2011-05-22 19:36:32.000000000 -0400
61059 @@ -119,8 +119,8 @@ void pci_acpi_crs_quirks(void);
61060 Dock Station
61061 -------------------------------------------------------------------------- */
61062 struct acpi_dock_ops {
61063 - acpi_notify_handler handler;
61064 - acpi_notify_handler uevent;
61065 + const acpi_notify_handler handler;
61066 + const acpi_notify_handler uevent;
61067 };
61068
61069 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
61070 @@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle ha
61071 extern int register_dock_notifier(struct notifier_block *nb);
61072 extern void unregister_dock_notifier(struct notifier_block *nb);
61073 extern int register_hotplug_dock_device(acpi_handle handle,
61074 - struct acpi_dock_ops *ops,
61075 + const struct acpi_dock_ops *ops,
61076 void *context);
61077 extern void unregister_hotplug_dock_device(acpi_handle handle);
61078 #else
61079 @@ -144,7 +144,7 @@ static inline void unregister_dock_notif
61080 {
61081 }
61082 static inline int register_hotplug_dock_device(acpi_handle handle,
61083 - struct acpi_dock_ops *ops,
61084 + const struct acpi_dock_ops *ops,
61085 void *context)
61086 {
61087 return -ENODEV;
61088 diff -urNp linux-2.6.39.2/include/acpi/processor.h linux-2.6.39.2/include/acpi/processor.h
61089 --- linux-2.6.39.2/include/acpi/processor.h 2011-05-19 00:06:34.000000000 -0400
61090 +++ linux-2.6.39.2/include/acpi/processor.h 2011-05-22 19:36:32.000000000 -0400
61091 @@ -344,7 +344,7 @@ extern struct cpuidle_driver acpi_idle_d
61092
61093 /* in processor_thermal.c */
61094 int acpi_processor_get_limit_info(struct acpi_processor *pr);
61095 -extern struct thermal_cooling_device_ops processor_cooling_ops;
61096 +extern const struct thermal_cooling_device_ops processor_cooling_ops;
61097 #ifdef CONFIG_CPU_FREQ
61098 void acpi_thermal_cpufreq_init(void);
61099 void acpi_thermal_cpufreq_exit(void);
61100 diff -urNp linux-2.6.39.2/include/asm-generic/atomic-long.h linux-2.6.39.2/include/asm-generic/atomic-long.h
61101 --- linux-2.6.39.2/include/asm-generic/atomic-long.h 2011-05-19 00:06:34.000000000 -0400
61102 +++ linux-2.6.39.2/include/asm-generic/atomic-long.h 2011-05-22 19:36:32.000000000 -0400
61103 @@ -22,6 +22,12 @@
61104
61105 typedef atomic64_t atomic_long_t;
61106
61107 +#ifdef CONFIG_PAX_REFCOUNT
61108 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
61109 +#else
61110 +typedef atomic64_t atomic_long_unchecked_t;
61111 +#endif
61112 +
61113 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
61114
61115 static inline long atomic_long_read(atomic_long_t *l)
61116 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atom
61117 return (long)atomic64_read(v);
61118 }
61119
61120 +#ifdef CONFIG_PAX_REFCOUNT
61121 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61122 +{
61123 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61124 +
61125 + return (long)atomic64_read_unchecked(v);
61126 +}
61127 +#endif
61128 +
61129 static inline void atomic_long_set(atomic_long_t *l, long i)
61130 {
61131 atomic64_t *v = (atomic64_t *)l;
61132 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomi
61133 atomic64_set(v, i);
61134 }
61135
61136 +#ifdef CONFIG_PAX_REFCOUNT
61137 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61138 +{
61139 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61140 +
61141 + atomic64_set_unchecked(v, i);
61142 +}
61143 +#endif
61144 +
61145 static inline void atomic_long_inc(atomic_long_t *l)
61146 {
61147 atomic64_t *v = (atomic64_t *)l;
61148 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomi
61149 atomic64_inc(v);
61150 }
61151
61152 +#ifdef CONFIG_PAX_REFCOUNT
61153 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61154 +{
61155 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61156 +
61157 + atomic64_inc_unchecked(v);
61158 +}
61159 +#endif
61160 +
61161 static inline void atomic_long_dec(atomic_long_t *l)
61162 {
61163 atomic64_t *v = (atomic64_t *)l;
61164 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomi
61165 atomic64_dec(v);
61166 }
61167
61168 +#ifdef CONFIG_PAX_REFCOUNT
61169 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61170 +{
61171 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61172 +
61173 + atomic64_dec_unchecked(v);
61174 +}
61175 +#endif
61176 +
61177 static inline void atomic_long_add(long i, atomic_long_t *l)
61178 {
61179 atomic64_t *v = (atomic64_t *)l;
61180 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long
61181 atomic64_add(i, v);
61182 }
61183
61184 +#ifdef CONFIG_PAX_REFCOUNT
61185 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61186 +{
61187 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61188 +
61189 + atomic64_add_unchecked(i, v);
61190 +}
61191 +#endif
61192 +
61193 static inline void atomic_long_sub(long i, atomic_long_t *l)
61194 {
61195 atomic64_t *v = (atomic64_t *)l;
61196 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long
61197 atomic64_sub(i, v);
61198 }
61199
61200 +#ifdef CONFIG_PAX_REFCOUNT
61201 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61202 +{
61203 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61204 +
61205 + atomic64_sub_unchecked(i, v);
61206 +}
61207 +#endif
61208 +
61209 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61210 {
61211 atomic64_t *v = (atomic64_t *)l;
61212 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_retur
61213 return (long)atomic64_inc_return(v);
61214 }
61215
61216 +#ifdef CONFIG_PAX_REFCOUNT
61217 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61218 +{
61219 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
61220 +
61221 + return (long)atomic64_inc_return_unchecked(v);
61222 +}
61223 +#endif
61224 +
61225 static inline long atomic_long_dec_return(atomic_long_t *l)
61226 {
61227 atomic64_t *v = (atomic64_t *)l;
61228 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unles
61229
61230 typedef atomic_t atomic_long_t;
61231
61232 +#ifdef CONFIG_PAX_REFCOUNT
61233 +typedef atomic_unchecked_t atomic_long_unchecked_t;
61234 +#else
61235 +typedef atomic_t atomic_long_unchecked_t;
61236 +#endif
61237 +
61238 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
61239 static inline long atomic_long_read(atomic_long_t *l)
61240 {
61241 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atom
61242 return (long)atomic_read(v);
61243 }
61244
61245 +#ifdef CONFIG_PAX_REFCOUNT
61246 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
61247 +{
61248 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61249 +
61250 + return (long)atomic_read_unchecked(v);
61251 +}
61252 +#endif
61253 +
61254 static inline void atomic_long_set(atomic_long_t *l, long i)
61255 {
61256 atomic_t *v = (atomic_t *)l;
61257 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomi
61258 atomic_set(v, i);
61259 }
61260
61261 +#ifdef CONFIG_PAX_REFCOUNT
61262 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
61263 +{
61264 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61265 +
61266 + atomic_set_unchecked(v, i);
61267 +}
61268 +#endif
61269 +
61270 static inline void atomic_long_inc(atomic_long_t *l)
61271 {
61272 atomic_t *v = (atomic_t *)l;
61273 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomi
61274 atomic_inc(v);
61275 }
61276
61277 +#ifdef CONFIG_PAX_REFCOUNT
61278 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
61279 +{
61280 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61281 +
61282 + atomic_inc_unchecked(v);
61283 +}
61284 +#endif
61285 +
61286 static inline void atomic_long_dec(atomic_long_t *l)
61287 {
61288 atomic_t *v = (atomic_t *)l;
61289 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomi
61290 atomic_dec(v);
61291 }
61292
61293 +#ifdef CONFIG_PAX_REFCOUNT
61294 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
61295 +{
61296 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61297 +
61298 + atomic_dec_unchecked(v);
61299 +}
61300 +#endif
61301 +
61302 static inline void atomic_long_add(long i, atomic_long_t *l)
61303 {
61304 atomic_t *v = (atomic_t *)l;
61305 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long
61306 atomic_add(i, v);
61307 }
61308
61309 +#ifdef CONFIG_PAX_REFCOUNT
61310 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
61311 +{
61312 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61313 +
61314 + atomic_add_unchecked(i, v);
61315 +}
61316 +#endif
61317 +
61318 static inline void atomic_long_sub(long i, atomic_long_t *l)
61319 {
61320 atomic_t *v = (atomic_t *)l;
61321 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long
61322 atomic_sub(i, v);
61323 }
61324
61325 +#ifdef CONFIG_PAX_REFCOUNT
61326 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
61327 +{
61328 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61329 +
61330 + atomic_sub_unchecked(i, v);
61331 +}
61332 +#endif
61333 +
61334 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
61335 {
61336 atomic_t *v = (atomic_t *)l;
61337 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_retur
61338 return (long)atomic_inc_return(v);
61339 }
61340
61341 +#ifdef CONFIG_PAX_REFCOUNT
61342 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
61343 +{
61344 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
61345 +
61346 + return (long)atomic_inc_return_unchecked(v);
61347 +}
61348 +#endif
61349 +
61350 static inline long atomic_long_dec_return(atomic_long_t *l)
61351 {
61352 atomic_t *v = (atomic_t *)l;
61353 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unles
61354
61355 #endif /* BITS_PER_LONG == 64 */
61356
61357 +#ifdef CONFIG_PAX_REFCOUNT
61358 +static inline void pax_refcount_needs_these_functions(void)
61359 +{
61360 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
61361 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
61362 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
61363 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
61364 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
61365 + atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
61366 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
61367 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
61368 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
61369 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
61370 + atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
61371 +
61372 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
61373 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
61374 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
61375 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
61376 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
61377 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
61378 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
61379 +}
61380 +#else
61381 +#define atomic_read_unchecked(v) atomic_read(v)
61382 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
61383 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
61384 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
61385 +#define atomic_inc_unchecked(v) atomic_inc(v)
61386 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
61387 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
61388 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
61389 +#define atomic_dec_unchecked(v) atomic_dec(v)
61390 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
61391 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
61392 +
61393 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
61394 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
61395 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
61396 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
61397 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
61398 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
61399 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
61400 +#endif
61401 +
61402 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
61403 diff -urNp linux-2.6.39.2/include/asm-generic/cache.h linux-2.6.39.2/include/asm-generic/cache.h
61404 --- linux-2.6.39.2/include/asm-generic/cache.h 2011-05-19 00:06:34.000000000 -0400
61405 +++ linux-2.6.39.2/include/asm-generic/cache.h 2011-05-22 19:36:32.000000000 -0400
61406 @@ -6,7 +6,7 @@
61407 * cache lines need to provide their own cache.h.
61408 */
61409
61410 -#define L1_CACHE_SHIFT 5
61411 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61412 +#define L1_CACHE_SHIFT 5U
61413 +#define L1_CACHE_BYTES (1U << L1_CACHE_SHIFT)
61414
61415 #endif /* __ASM_GENERIC_CACHE_H */
61416 diff -urNp linux-2.6.39.2/include/asm-generic/dma-mapping-common.h linux-2.6.39.2/include/asm-generic/dma-mapping-common.h
61417 --- linux-2.6.39.2/include/asm-generic/dma-mapping-common.h 2011-05-19 00:06:34.000000000 -0400
61418 +++ linux-2.6.39.2/include/asm-generic/dma-mapping-common.h 2011-05-22 19:36:32.000000000 -0400
61419 @@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_
61420 enum dma_data_direction dir,
61421 struct dma_attrs *attrs)
61422 {
61423 - struct dma_map_ops *ops = get_dma_ops(dev);
61424 + const struct dma_map_ops *ops = get_dma_ops(dev);
61425 dma_addr_t addr;
61426
61427 kmemcheck_mark_initialized(ptr, size);
61428 @@ -30,7 +30,7 @@ static inline void dma_unmap_single_attr
61429 enum dma_data_direction dir,
61430 struct dma_attrs *attrs)
61431 {
61432 - struct dma_map_ops *ops = get_dma_ops(dev);
61433 + const struct dma_map_ops *ops = get_dma_ops(dev);
61434
61435 BUG_ON(!valid_dma_direction(dir));
61436 if (ops->unmap_page)
61437 @@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struc
61438 int nents, enum dma_data_direction dir,
61439 struct dma_attrs *attrs)
61440 {
61441 - struct dma_map_ops *ops = get_dma_ops(dev);
61442 + const struct dma_map_ops *ops = get_dma_ops(dev);
61443 int i, ents;
61444 struct scatterlist *s;
61445
61446 @@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(st
61447 int nents, enum dma_data_direction dir,
61448 struct dma_attrs *attrs)
61449 {
61450 - struct dma_map_ops *ops = get_dma_ops(dev);
61451 + const struct dma_map_ops *ops = get_dma_ops(dev);
61452
61453 BUG_ON(!valid_dma_direction(dir));
61454 debug_dma_unmap_sg(dev, sg, nents, dir);
61455 @@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(st
61456 size_t offset, size_t size,
61457 enum dma_data_direction dir)
61458 {
61459 - struct dma_map_ops *ops = get_dma_ops(dev);
61460 + const struct dma_map_ops *ops = get_dma_ops(dev);
61461 dma_addr_t addr;
61462
61463 kmemcheck_mark_initialized(page_address(page) + offset, size);
61464 @@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(st
61465 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
61466 size_t size, enum dma_data_direction dir)
61467 {
61468 - struct dma_map_ops *ops = get_dma_ops(dev);
61469 + const struct dma_map_ops *ops = get_dma_ops(dev);
61470
61471 BUG_ON(!valid_dma_direction(dir));
61472 if (ops->unmap_page)
61473 @@ -97,7 +97,7 @@ static inline void dma_sync_single_for_c
61474 size_t size,
61475 enum dma_data_direction dir)
61476 {
61477 - struct dma_map_ops *ops = get_dma_ops(dev);
61478 + const struct dma_map_ops *ops = get_dma_ops(dev);
61479
61480 BUG_ON(!valid_dma_direction(dir));
61481 if (ops->sync_single_for_cpu)
61482 @@ -109,7 +109,7 @@ static inline void dma_sync_single_for_d
61483 dma_addr_t addr, size_t size,
61484 enum dma_data_direction dir)
61485 {
61486 - struct dma_map_ops *ops = get_dma_ops(dev);
61487 + const struct dma_map_ops *ops = get_dma_ops(dev);
61488
61489 BUG_ON(!valid_dma_direction(dir));
61490 if (ops->sync_single_for_device)
61491 @@ -139,7 +139,7 @@ static inline void
61492 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
61493 int nelems, enum dma_data_direction dir)
61494 {
61495 - struct dma_map_ops *ops = get_dma_ops(dev);
61496 + const struct dma_map_ops *ops = get_dma_ops(dev);
61497
61498 BUG_ON(!valid_dma_direction(dir));
61499 if (ops->sync_sg_for_cpu)
61500 @@ -151,7 +151,7 @@ static inline void
61501 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
61502 int nelems, enum dma_data_direction dir)
61503 {
61504 - struct dma_map_ops *ops = get_dma_ops(dev);
61505 + const struct dma_map_ops *ops = get_dma_ops(dev);
61506
61507 BUG_ON(!valid_dma_direction(dir));
61508 if (ops->sync_sg_for_device)
61509 diff -urNp linux-2.6.39.2/include/asm-generic/int-l64.h linux-2.6.39.2/include/asm-generic/int-l64.h
61510 --- linux-2.6.39.2/include/asm-generic/int-l64.h 2011-05-19 00:06:34.000000000 -0400
61511 +++ linux-2.6.39.2/include/asm-generic/int-l64.h 2011-05-22 19:36:32.000000000 -0400
61512 @@ -46,6 +46,8 @@ typedef unsigned int u32;
61513 typedef signed long s64;
61514 typedef unsigned long u64;
61515
61516 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
61517 +
61518 #define S8_C(x) x
61519 #define U8_C(x) x ## U
61520 #define S16_C(x) x
61521 diff -urNp linux-2.6.39.2/include/asm-generic/int-ll64.h linux-2.6.39.2/include/asm-generic/int-ll64.h
61522 --- linux-2.6.39.2/include/asm-generic/int-ll64.h 2011-05-19 00:06:34.000000000 -0400
61523 +++ linux-2.6.39.2/include/asm-generic/int-ll64.h 2011-05-22 19:36:32.000000000 -0400
61524 @@ -51,6 +51,8 @@ typedef unsigned int u32;
61525 typedef signed long long s64;
61526 typedef unsigned long long u64;
61527
61528 +typedef unsigned long long intoverflow_t;
61529 +
61530 #define S8_C(x) x
61531 #define U8_C(x) x ## U
61532 #define S16_C(x) x
61533 diff -urNp linux-2.6.39.2/include/asm-generic/kmap_types.h linux-2.6.39.2/include/asm-generic/kmap_types.h
61534 --- linux-2.6.39.2/include/asm-generic/kmap_types.h 2011-05-19 00:06:34.000000000 -0400
61535 +++ linux-2.6.39.2/include/asm-generic/kmap_types.h 2011-05-22 19:36:32.000000000 -0400
61536 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
61537 KMAP_D(17) KM_NMI,
61538 KMAP_D(18) KM_NMI_PTE,
61539 KMAP_D(19) KM_KDB,
61540 +KMAP_D(20) KM_CLEARPAGE,
61541 /*
61542 * Remember to update debug_kmap_atomic() when adding new kmap types!
61543 */
61544 -KMAP_D(20) KM_TYPE_NR
61545 +KMAP_D(21) KM_TYPE_NR
61546 };
61547
61548 #undef KMAP_D
61549 diff -urNp linux-2.6.39.2/include/asm-generic/pgtable.h linux-2.6.39.2/include/asm-generic/pgtable.h
61550 --- linux-2.6.39.2/include/asm-generic/pgtable.h 2011-05-19 00:06:34.000000000 -0400
61551 +++ linux-2.6.39.2/include/asm-generic/pgtable.h 2011-05-22 19:36:32.000000000 -0400
61552 @@ -447,6 +447,14 @@ static inline int pmd_write(pmd_t pmd)
61553 #endif /* __HAVE_ARCH_PMD_WRITE */
61554 #endif
61555
61556 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61557 +static inline unsigned long pax_open_kernel(void) { return 0; }
61558 +#endif
61559 +
61560 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61561 +static inline unsigned long pax_close_kernel(void) { return 0; }
61562 +#endif
61563 +
61564 #endif /* !__ASSEMBLY__ */
61565
61566 #endif /* _ASM_GENERIC_PGTABLE_H */
61567 diff -urNp linux-2.6.39.2/include/asm-generic/pgtable-nopmd.h linux-2.6.39.2/include/asm-generic/pgtable-nopmd.h
61568 --- linux-2.6.39.2/include/asm-generic/pgtable-nopmd.h 2011-05-19 00:06:34.000000000 -0400
61569 +++ linux-2.6.39.2/include/asm-generic/pgtable-nopmd.h 2011-05-22 19:36:32.000000000 -0400
61570 @@ -1,14 +1,19 @@
61571 #ifndef _PGTABLE_NOPMD_H
61572 #define _PGTABLE_NOPMD_H
61573
61574 -#ifndef __ASSEMBLY__
61575 -
61576 #include <asm-generic/pgtable-nopud.h>
61577
61578 -struct mm_struct;
61579 -
61580 #define __PAGETABLE_PMD_FOLDED
61581
61582 +#define PMD_SHIFT PUD_SHIFT
61583 +#define PTRS_PER_PMD 1
61584 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61585 +#define PMD_MASK (~(PMD_SIZE-1))
61586 +
61587 +#ifndef __ASSEMBLY__
61588 +
61589 +struct mm_struct;
61590 +
61591 /*
61592 * Having the pmd type consist of a pud gets the size right, and allows
61593 * us to conceptually access the pud entry that this pmd is folded into
61594 @@ -16,11 +21,6 @@ struct mm_struct;
61595 */
61596 typedef struct { pud_t pud; } pmd_t;
61597
61598 -#define PMD_SHIFT PUD_SHIFT
61599 -#define PTRS_PER_PMD 1
61600 -#define PMD_SIZE (1UL << PMD_SHIFT)
61601 -#define PMD_MASK (~(PMD_SIZE-1))
61602 -
61603 /*
61604 * The "pud_xxx()" functions here are trivial for a folded two-level
61605 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61606 diff -urNp linux-2.6.39.2/include/asm-generic/pgtable-nopud.h linux-2.6.39.2/include/asm-generic/pgtable-nopud.h
61607 --- linux-2.6.39.2/include/asm-generic/pgtable-nopud.h 2011-05-19 00:06:34.000000000 -0400
61608 +++ linux-2.6.39.2/include/asm-generic/pgtable-nopud.h 2011-05-22 19:36:32.000000000 -0400
61609 @@ -1,10 +1,15 @@
61610 #ifndef _PGTABLE_NOPUD_H
61611 #define _PGTABLE_NOPUD_H
61612
61613 -#ifndef __ASSEMBLY__
61614 -
61615 #define __PAGETABLE_PUD_FOLDED
61616
61617 +#define PUD_SHIFT PGDIR_SHIFT
61618 +#define PTRS_PER_PUD 1
61619 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61620 +#define PUD_MASK (~(PUD_SIZE-1))
61621 +
61622 +#ifndef __ASSEMBLY__
61623 +
61624 /*
61625 * Having the pud type consist of a pgd gets the size right, and allows
61626 * us to conceptually access the pgd entry that this pud is folded into
61627 @@ -12,11 +17,6 @@
61628 */
61629 typedef struct { pgd_t pgd; } pud_t;
61630
61631 -#define PUD_SHIFT PGDIR_SHIFT
61632 -#define PTRS_PER_PUD 1
61633 -#define PUD_SIZE (1UL << PUD_SHIFT)
61634 -#define PUD_MASK (~(PUD_SIZE-1))
61635 -
61636 /*
61637 * The "pgd_xxx()" functions here are trivial for a folded two-level
61638 * setup: the pud is never bad, and a pud always exists (as it's folded
61639 diff -urNp linux-2.6.39.2/include/asm-generic/vmlinux.lds.h linux-2.6.39.2/include/asm-generic/vmlinux.lds.h
61640 --- linux-2.6.39.2/include/asm-generic/vmlinux.lds.h 2011-05-19 00:06:34.000000000 -0400
61641 +++ linux-2.6.39.2/include/asm-generic/vmlinux.lds.h 2011-05-22 19:36:32.000000000 -0400
61642 @@ -213,6 +213,7 @@
61643 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61644 VMLINUX_SYMBOL(__start_rodata) = .; \
61645 *(.rodata) *(.rodata.*) \
61646 + *(.data..read_only) \
61647 *(__vermagic) /* Kernel version magic */ \
61648 . = ALIGN(8); \
61649 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61650 @@ -707,14 +708,15 @@
61651 * section in the linker script will go there too. @phdr should have
61652 * a leading colon.
61653 *
61654 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61655 + * Note that this macros defines per_cpu_load as an absolute symbol.
61656 * If there is no need to put the percpu section at a predetermined
61657 * address, use PERCPU().
61658 */
61659 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61660 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61661 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61662 + per_cpu_load = .; \
61663 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61664 - LOAD_OFFSET) { \
61665 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61666 VMLINUX_SYMBOL(__per_cpu_start) = .; \
61667 *(.data..percpu..first) \
61668 . = ALIGN(PAGE_SIZE); \
61669 @@ -726,7 +728,7 @@
61670 *(.data..percpu..shared_aligned) \
61671 VMLINUX_SYMBOL(__per_cpu_end) = .; \
61672 } phdr \
61673 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61674 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61675
61676 /**
61677 * PERCPU - define output section for percpu area, simple version
61678 diff -urNp linux-2.6.39.2/include/drm/drmP.h linux-2.6.39.2/include/drm/drmP.h
61679 --- linux-2.6.39.2/include/drm/drmP.h 2011-05-19 00:06:34.000000000 -0400
61680 +++ linux-2.6.39.2/include/drm/drmP.h 2011-05-22 19:41:42.000000000 -0400
61681 @@ -73,6 +73,7 @@
61682 #include <linux/workqueue.h>
61683 #include <linux/poll.h>
61684 #include <asm/pgalloc.h>
61685 +#include <asm/local.h>
61686 #include "drm.h"
61687
61688 #include <linux/idr.h>
61689 @@ -908,7 +909,7 @@ struct drm_driver {
61690 uint32_t handle);
61691
61692 /* Driver private ops for this object */
61693 - struct vm_operations_struct *gem_vm_ops;
61694 + const struct vm_operations_struct *gem_vm_ops;
61695
61696 int major;
61697 int minor;
61698 @@ -1023,7 +1024,7 @@ struct drm_device {
61699
61700 /** \name Usage Counters */
61701 /*@{ */
61702 - int open_count; /**< Outstanding files open */
61703 + local_t open_count; /**< Outstanding files open */
61704 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61705 atomic_t vma_count; /**< Outstanding vma areas open */
61706 int buf_use; /**< Buffers in use -- cannot alloc */
61707 @@ -1034,7 +1035,7 @@ struct drm_device {
61708 /*@{ */
61709 unsigned long counters;
61710 enum drm_stat_type types[15];
61711 - atomic_t counts[15];
61712 + atomic_unchecked_t counts[15];
61713 /*@} */
61714
61715 struct list_head filelist;
61716 diff -urNp linux-2.6.39.2/include/linux/a.out.h linux-2.6.39.2/include/linux/a.out.h
61717 --- linux-2.6.39.2/include/linux/a.out.h 2011-05-19 00:06:34.000000000 -0400
61718 +++ linux-2.6.39.2/include/linux/a.out.h 2011-05-22 19:36:32.000000000 -0400
61719 @@ -39,6 +39,14 @@ enum machine_type {
61720 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61721 };
61722
61723 +/* Constants for the N_FLAGS field */
61724 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61725 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61726 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61727 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61728 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61729 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61730 +
61731 #if !defined (N_MAGIC)
61732 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61733 #endif
61734 diff -urNp linux-2.6.39.2/include/linux/atmdev.h linux-2.6.39.2/include/linux/atmdev.h
61735 --- linux-2.6.39.2/include/linux/atmdev.h 2011-05-19 00:06:34.000000000 -0400
61736 +++ linux-2.6.39.2/include/linux/atmdev.h 2011-05-22 19:36:32.000000000 -0400
61737 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61738 #endif
61739
61740 struct k_atm_aal_stats {
61741 -#define __HANDLE_ITEM(i) atomic_t i
61742 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61743 __AAL_STAT_ITEMS
61744 #undef __HANDLE_ITEM
61745 };
61746 diff -urNp linux-2.6.39.2/include/linux/binfmts.h linux-2.6.39.2/include/linux/binfmts.h
61747 --- linux-2.6.39.2/include/linux/binfmts.h 2011-05-19 00:06:34.000000000 -0400
61748 +++ linux-2.6.39.2/include/linux/binfmts.h 2011-05-22 19:36:32.000000000 -0400
61749 @@ -92,6 +92,7 @@ struct linux_binfmt {
61750 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61751 int (*load_shlib)(struct file *);
61752 int (*core_dump)(struct coredump_params *cprm);
61753 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61754 unsigned long min_coredump; /* minimal dump size */
61755 };
61756
61757 diff -urNp linux-2.6.39.2/include/linux/blkdev.h linux-2.6.39.2/include/linux/blkdev.h
61758 --- linux-2.6.39.2/include/linux/blkdev.h 2011-06-03 00:04:14.000000000 -0400
61759 +++ linux-2.6.39.2/include/linux/blkdev.h 2011-06-03 00:32:08.000000000 -0400
61760 @@ -1292,22 +1292,22 @@ queue_max_integrity_segments(struct requ
61761 #endif /* CONFIG_BLK_DEV_INTEGRITY */
61762
61763 struct block_device_operations {
61764 - int (*open) (struct block_device *, fmode_t);
61765 - int (*release) (struct gendisk *, fmode_t);
61766 - int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61767 - int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61768 - int (*direct_access) (struct block_device *, sector_t,
61769 + int (* const open) (struct block_device *, fmode_t);
61770 + int (* const release) (struct gendisk *, fmode_t);
61771 + int (* const ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61772 + int (* const compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
61773 + int (* const direct_access) (struct block_device *, sector_t,
61774 void **, unsigned long *);
61775 - unsigned int (*check_events) (struct gendisk *disk,
61776 + unsigned int (* const check_events) (struct gendisk *disk,
61777 unsigned int clearing);
61778 /* ->media_changed() is DEPRECATED, use ->check_events() instead */
61779 - int (*media_changed) (struct gendisk *);
61780 - void (*unlock_native_capacity) (struct gendisk *);
61781 - int (*revalidate_disk) (struct gendisk *);
61782 - int (*getgeo)(struct block_device *, struct hd_geometry *);
61783 + int (* const media_changed) (struct gendisk *);
61784 + void (* const unlock_native_capacity) (struct gendisk *);
61785 + int (* const revalidate_disk) (struct gendisk *);
61786 + int (* const getgeo)(struct block_device *, struct hd_geometry *);
61787 /* this callback is with swap_lock and sometimes page table lock held */
61788 - void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61789 - struct module *owner;
61790 + void (* const swap_slot_free_notify) (struct block_device *, unsigned long);
61791 + struct module * const owner;
61792 };
61793
61794 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61795 diff -urNp linux-2.6.39.2/include/linux/blktrace_api.h linux-2.6.39.2/include/linux/blktrace_api.h
61796 --- linux-2.6.39.2/include/linux/blktrace_api.h 2011-05-19 00:06:34.000000000 -0400
61797 +++ linux-2.6.39.2/include/linux/blktrace_api.h 2011-05-22 19:36:32.000000000 -0400
61798 @@ -161,7 +161,7 @@ struct blk_trace {
61799 struct dentry *dir;
61800 struct dentry *dropped_file;
61801 struct dentry *msg_file;
61802 - atomic_t dropped;
61803 + atomic_unchecked_t dropped;
61804 };
61805
61806 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61807 diff -urNp linux-2.6.39.2/include/linux/byteorder/little_endian.h linux-2.6.39.2/include/linux/byteorder/little_endian.h
61808 --- linux-2.6.39.2/include/linux/byteorder/little_endian.h 2011-05-19 00:06:34.000000000 -0400
61809 +++ linux-2.6.39.2/include/linux/byteorder/little_endian.h 2011-05-22 19:36:32.000000000 -0400
61810 @@ -42,51 +42,51 @@
61811
61812 static inline __le64 __cpu_to_le64p(const __u64 *p)
61813 {
61814 - return (__force __le64)*p;
61815 + return (__force const __le64)*p;
61816 }
61817 static inline __u64 __le64_to_cpup(const __le64 *p)
61818 {
61819 - return (__force __u64)*p;
61820 + return (__force const __u64)*p;
61821 }
61822 static inline __le32 __cpu_to_le32p(const __u32 *p)
61823 {
61824 - return (__force __le32)*p;
61825 + return (__force const __le32)*p;
61826 }
61827 static inline __u32 __le32_to_cpup(const __le32 *p)
61828 {
61829 - return (__force __u32)*p;
61830 + return (__force const __u32)*p;
61831 }
61832 static inline __le16 __cpu_to_le16p(const __u16 *p)
61833 {
61834 - return (__force __le16)*p;
61835 + return (__force const __le16)*p;
61836 }
61837 static inline __u16 __le16_to_cpup(const __le16 *p)
61838 {
61839 - return (__force __u16)*p;
61840 + return (__force const __u16)*p;
61841 }
61842 static inline __be64 __cpu_to_be64p(const __u64 *p)
61843 {
61844 - return (__force __be64)__swab64p(p);
61845 + return (__force const __be64)__swab64p(p);
61846 }
61847 static inline __u64 __be64_to_cpup(const __be64 *p)
61848 {
61849 - return __swab64p((__u64 *)p);
61850 + return __swab64p((const __u64 *)p);
61851 }
61852 static inline __be32 __cpu_to_be32p(const __u32 *p)
61853 {
61854 - return (__force __be32)__swab32p(p);
61855 + return (__force const __be32)__swab32p(p);
61856 }
61857 static inline __u32 __be32_to_cpup(const __be32 *p)
61858 {
61859 - return __swab32p((__u32 *)p);
61860 + return __swab32p((const __u32 *)p);
61861 }
61862 static inline __be16 __cpu_to_be16p(const __u16 *p)
61863 {
61864 - return (__force __be16)__swab16p(p);
61865 + return (__force const __be16)__swab16p(p);
61866 }
61867 static inline __u16 __be16_to_cpup(const __be16 *p)
61868 {
61869 - return __swab16p((__u16 *)p);
61870 + return __swab16p((const __u16 *)p);
61871 }
61872 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61873 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61874 diff -urNp linux-2.6.39.2/include/linux/cache.h linux-2.6.39.2/include/linux/cache.h
61875 --- linux-2.6.39.2/include/linux/cache.h 2011-05-19 00:06:34.000000000 -0400
61876 +++ linux-2.6.39.2/include/linux/cache.h 2011-05-22 19:36:32.000000000 -0400
61877 @@ -16,6 +16,10 @@
61878 #define __read_mostly
61879 #endif
61880
61881 +#ifndef __read_only
61882 +#define __read_only __read_mostly
61883 +#endif
61884 +
61885 #ifndef ____cacheline_aligned
61886 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61887 #endif
61888 diff -urNp linux-2.6.39.2/include/linux/capability.h linux-2.6.39.2/include/linux/capability.h
61889 --- linux-2.6.39.2/include/linux/capability.h 2011-05-19 00:06:34.000000000 -0400
61890 +++ linux-2.6.39.2/include/linux/capability.h 2011-05-22 21:02:47.000000000 -0400
61891 @@ -547,6 +547,9 @@ extern bool capable(int cap);
61892 extern bool ns_capable(struct user_namespace *ns, int cap);
61893 extern bool task_ns_capable(struct task_struct *t, int cap);
61894 extern bool nsown_capable(int cap);
61895 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
61896 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61897 +extern bool capable_nolog(int cap);
61898
61899 /* audit system wants to get cap info from files as well */
61900 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61901 diff -urNp linux-2.6.39.2/include/linux/compiler-gcc4.h linux-2.6.39.2/include/linux/compiler-gcc4.h
61902 --- linux-2.6.39.2/include/linux/compiler-gcc4.h 2011-05-19 00:06:34.000000000 -0400
61903 +++ linux-2.6.39.2/include/linux/compiler-gcc4.h 2011-05-22 19:36:32.000000000 -0400
61904 @@ -46,6 +46,11 @@
61905 #define __noclone __attribute__((__noclone__))
61906
61907 #endif
61908 +
61909 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61910 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61911 +#define __bos0(ptr) __bos((ptr), 0)
61912 +#define __bos1(ptr) __bos((ptr), 1)
61913 #endif
61914
61915 #if __GNUC_MINOR__ > 0
61916 diff -urNp linux-2.6.39.2/include/linux/compiler.h linux-2.6.39.2/include/linux/compiler.h
61917 --- linux-2.6.39.2/include/linux/compiler.h 2011-05-19 00:06:34.000000000 -0400
61918 +++ linux-2.6.39.2/include/linux/compiler.h 2011-05-22 19:36:32.000000000 -0400
61919 @@ -273,6 +273,22 @@ void ftrace_likely_update(struct ftrace_
61920 #define __cold
61921 #endif
61922
61923 +#ifndef __alloc_size
61924 +#define __alloc_size
61925 +#endif
61926 +
61927 +#ifndef __bos
61928 +#define __bos
61929 +#endif
61930 +
61931 +#ifndef __bos0
61932 +#define __bos0
61933 +#endif
61934 +
61935 +#ifndef __bos1
61936 +#define __bos1
61937 +#endif
61938 +
61939 /* Simple shorthand for a section definition */
61940 #ifndef __section
61941 # define __section(S) __attribute__ ((__section__(#S)))
61942 @@ -306,6 +322,7 @@ void ftrace_likely_update(struct ftrace_
61943 * use is to mediate communication between process-level code and irq/NMI
61944 * handlers, all running on the same CPU.
61945 */
61946 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61947 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61948 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61949
61950 #endif /* __LINUX_COMPILER_H */
61951 diff -urNp linux-2.6.39.2/include/linux/concap.h linux-2.6.39.2/include/linux/concap.h
61952 --- linux-2.6.39.2/include/linux/concap.h 2011-05-19 00:06:34.000000000 -0400
61953 +++ linux-2.6.39.2/include/linux/concap.h 2011-05-22 19:36:32.000000000 -0400
61954 @@ -30,7 +30,7 @@ struct concap_device_ops;
61955 struct concap_proto{
61956 struct net_device *net_dev; /* net device using our service */
61957 struct concap_device_ops *dops; /* callbacks provided by device */
61958 - struct concap_proto_ops *pops; /* callbacks provided by us */
61959 + const struct concap_proto_ops *pops; /* callbacks provided by us */
61960 spinlock_t lock;
61961 int flags;
61962 void *proto_data; /* protocol specific private data, to
61963 diff -urNp linux-2.6.39.2/include/linux/configfs.h linux-2.6.39.2/include/linux/configfs.h
61964 --- linux-2.6.39.2/include/linux/configfs.h 2011-05-19 00:06:34.000000000 -0400
61965 +++ linux-2.6.39.2/include/linux/configfs.h 2011-05-22 19:36:32.000000000 -0400
61966 @@ -82,7 +82,7 @@ extern void config_item_put(struct confi
61967 struct config_item_type {
61968 struct module *ct_owner;
61969 struct configfs_item_operations *ct_item_ops;
61970 - struct configfs_group_operations *ct_group_ops;
61971 + const struct configfs_group_operations *ct_group_ops;
61972 struct configfs_attribute **ct_attrs;
61973 };
61974
61975 diff -urNp linux-2.6.39.2/include/linux/cpuset.h linux-2.6.39.2/include/linux/cpuset.h
61976 --- linux-2.6.39.2/include/linux/cpuset.h 2011-05-19 00:06:34.000000000 -0400
61977 +++ linux-2.6.39.2/include/linux/cpuset.h 2011-05-22 19:36:32.000000000 -0400
61978 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void
61979 * nodemask.
61980 */
61981 smp_mb();
61982 - --ACCESS_ONCE(current->mems_allowed_change_disable);
61983 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61984 }
61985
61986 static inline void set_mems_allowed(nodemask_t nodemask)
61987 diff -urNp linux-2.6.39.2/include/linux/dca.h linux-2.6.39.2/include/linux/dca.h
61988 --- linux-2.6.39.2/include/linux/dca.h 2011-05-19 00:06:34.000000000 -0400
61989 +++ linux-2.6.39.2/include/linux/dca.h 2011-05-22 19:36:32.000000000 -0400
61990 @@ -34,7 +34,7 @@ void dca_unregister_notify(struct notifi
61991
61992 struct dca_provider {
61993 struct list_head node;
61994 - struct dca_ops *ops;
61995 + const struct dca_ops *ops;
61996 struct device *cd;
61997 int id;
61998 };
61999 @@ -53,7 +53,7 @@ struct dca_ops {
62000 int (*dev_managed) (struct dca_provider *, struct device *);
62001 };
62002
62003 -struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size);
62004 +struct dca_provider *alloc_dca_provider(const struct dca_ops *ops, int priv_size);
62005 void free_dca_provider(struct dca_provider *dca);
62006 int register_dca_provider(struct dca_provider *dca, struct device *dev);
62007 void unregister_dca_provider(struct dca_provider *dca, struct device *dev);
62008 diff -urNp linux-2.6.39.2/include/linux/decompress/mm.h linux-2.6.39.2/include/linux/decompress/mm.h
62009 --- linux-2.6.39.2/include/linux/decompress/mm.h 2011-05-19 00:06:34.000000000 -0400
62010 +++ linux-2.6.39.2/include/linux/decompress/mm.h 2011-05-22 19:36:33.000000000 -0400
62011 @@ -77,7 +77,7 @@ static void free(void *where)
62012 * warnings when not needed (indeed large_malloc / large_free are not
62013 * needed by inflate */
62014
62015 -#define malloc(a) kmalloc(a, GFP_KERNEL)
62016 +#define malloc(a) kmalloc((a), GFP_KERNEL)
62017 #define free(a) kfree(a)
62018
62019 #define large_malloc(a) vmalloc(a)
62020 diff -urNp linux-2.6.39.2/include/linux/dma-mapping.h linux-2.6.39.2/include/linux/dma-mapping.h
62021 --- linux-2.6.39.2/include/linux/dma-mapping.h 2011-05-19 00:06:34.000000000 -0400
62022 +++ linux-2.6.39.2/include/linux/dma-mapping.h 2011-05-22 19:36:33.000000000 -0400
62023 @@ -16,40 +16,40 @@ enum dma_data_direction {
62024 };
62025
62026 struct dma_map_ops {
62027 - void* (*alloc_coherent)(struct device *dev, size_t size,
62028 + void* (* const alloc_coherent)(struct device *dev, size_t size,
62029 dma_addr_t *dma_handle, gfp_t gfp);
62030 - void (*free_coherent)(struct device *dev, size_t size,
62031 + void (* const free_coherent)(struct device *dev, size_t size,
62032 void *vaddr, dma_addr_t dma_handle);
62033 - dma_addr_t (*map_page)(struct device *dev, struct page *page,
62034 + dma_addr_t (* const map_page)(struct device *dev, struct page *page,
62035 unsigned long offset, size_t size,
62036 enum dma_data_direction dir,
62037 struct dma_attrs *attrs);
62038 - void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
62039 + void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
62040 size_t size, enum dma_data_direction dir,
62041 struct dma_attrs *attrs);
62042 - int (*map_sg)(struct device *dev, struct scatterlist *sg,
62043 + int (* const map_sg)(struct device *dev, struct scatterlist *sg,
62044 int nents, enum dma_data_direction dir,
62045 struct dma_attrs *attrs);
62046 - void (*unmap_sg)(struct device *dev,
62047 + void (* const unmap_sg)(struct device *dev,
62048 struct scatterlist *sg, int nents,
62049 enum dma_data_direction dir,
62050 struct dma_attrs *attrs);
62051 - void (*sync_single_for_cpu)(struct device *dev,
62052 + void (* const sync_single_for_cpu)(struct device *dev,
62053 dma_addr_t dma_handle, size_t size,
62054 enum dma_data_direction dir);
62055 - void (*sync_single_for_device)(struct device *dev,
62056 + void (* const sync_single_for_device)(struct device *dev,
62057 dma_addr_t dma_handle, size_t size,
62058 enum dma_data_direction dir);
62059 - void (*sync_sg_for_cpu)(struct device *dev,
62060 + void (* const sync_sg_for_cpu)(struct device *dev,
62061 struct scatterlist *sg, int nents,
62062 enum dma_data_direction dir);
62063 - void (*sync_sg_for_device)(struct device *dev,
62064 + void (* const sync_sg_for_device)(struct device *dev,
62065 struct scatterlist *sg, int nents,
62066 enum dma_data_direction dir);
62067 - int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
62068 - int (*dma_supported)(struct device *dev, u64 mask);
62069 - int (*set_dma_mask)(struct device *dev, u64 mask);
62070 - int is_phys;
62071 + int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
62072 + int (* const dma_supported)(struct device *dev, u64 mask);
62073 + int (* set_dma_mask)(struct device *dev, u64 mask);
62074 + const int is_phys;
62075 };
62076
62077 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
62078 diff -urNp linux-2.6.39.2/include/linux/elf.h linux-2.6.39.2/include/linux/elf.h
62079 --- linux-2.6.39.2/include/linux/elf.h 2011-05-19 00:06:34.000000000 -0400
62080 +++ linux-2.6.39.2/include/linux/elf.h 2011-05-22 19:36:33.000000000 -0400
62081 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
62082 #define PT_GNU_EH_FRAME 0x6474e550
62083
62084 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
62085 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
62086 +
62087 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
62088 +
62089 +/* Constants for the e_flags field */
62090 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
62091 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
62092 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
62093 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
62094 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
62095 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
62096
62097 /*
62098 * Extended Numbering
62099 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
62100 #define DT_DEBUG 21
62101 #define DT_TEXTREL 22
62102 #define DT_JMPREL 23
62103 +#define DT_FLAGS 30
62104 + #define DF_TEXTREL 0x00000004
62105 #define DT_ENCODING 32
62106 #define OLD_DT_LOOS 0x60000000
62107 #define DT_LOOS 0x6000000d
62108 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
62109 #define PF_W 0x2
62110 #define PF_X 0x1
62111
62112 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
62113 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
62114 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
62115 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
62116 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
62117 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
62118 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
62119 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
62120 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
62121 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
62122 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
62123 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
62124 +
62125 typedef struct elf32_phdr{
62126 Elf32_Word p_type;
62127 Elf32_Off p_offset;
62128 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
62129 #define EI_OSABI 7
62130 #define EI_PAD 8
62131
62132 +#define EI_PAX 14
62133 +
62134 #define ELFMAG0 0x7f /* EI_MAG */
62135 #define ELFMAG1 'E'
62136 #define ELFMAG2 'L'
62137 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
62138 #define elf_note elf32_note
62139 #define elf_addr_t Elf32_Off
62140 #define Elf_Half Elf32_Half
62141 +#define elf_dyn Elf32_Dyn
62142
62143 #else
62144
62145 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
62146 #define elf_note elf64_note
62147 #define elf_addr_t Elf64_Off
62148 #define Elf_Half Elf64_Half
62149 +#define elf_dyn Elf64_Dyn
62150
62151 #endif
62152
62153 diff -urNp linux-2.6.39.2/include/linux/enclosure.h linux-2.6.39.2/include/linux/enclosure.h
62154 --- linux-2.6.39.2/include/linux/enclosure.h 2011-05-19 00:06:34.000000000 -0400
62155 +++ linux-2.6.39.2/include/linux/enclosure.h 2011-05-22 19:36:33.000000000 -0400
62156 @@ -98,7 +98,7 @@ struct enclosure_device {
62157 void *scratch;
62158 struct list_head node;
62159 struct device edev;
62160 - struct enclosure_component_callbacks *cb;
62161 + const struct enclosure_component_callbacks *cb;
62162 int components;
62163 struct enclosure_component component[0];
62164 };
62165 diff -urNp linux-2.6.39.2/include/linux/fscache-cache.h linux-2.6.39.2/include/linux/fscache-cache.h
62166 --- linux-2.6.39.2/include/linux/fscache-cache.h 2011-05-19 00:06:34.000000000 -0400
62167 +++ linux-2.6.39.2/include/linux/fscache-cache.h 2011-05-22 19:36:33.000000000 -0400
62168 @@ -113,7 +113,7 @@ struct fscache_operation {
62169 #endif
62170 };
62171
62172 -extern atomic_t fscache_op_debug_id;
62173 +extern atomic_unchecked_t fscache_op_debug_id;
62174 extern void fscache_op_work_func(struct work_struct *work);
62175
62176 extern void fscache_enqueue_operation(struct fscache_operation *);
62177 @@ -133,7 +133,7 @@ static inline void fscache_operation_ini
62178 {
62179 INIT_WORK(&op->work, fscache_op_work_func);
62180 atomic_set(&op->usage, 1);
62181 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62182 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62183 op->processor = processor;
62184 op->release = release;
62185 INIT_LIST_HEAD(&op->pend_link);
62186 diff -urNp linux-2.6.39.2/include/linux/fs.h linux-2.6.39.2/include/linux/fs.h
62187 --- linux-2.6.39.2/include/linux/fs.h 2011-05-19 00:06:34.000000000 -0400
62188 +++ linux-2.6.39.2/include/linux/fs.h 2011-05-22 19:41:42.000000000 -0400
62189 @@ -108,6 +108,11 @@ struct inodes_stat_t {
62190 /* File was opened by fanotify and shouldn't generate fanotify events */
62191 #define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
62192
62193 +/* Hack for grsec so as not to require read permission simply to execute
62194 + * a binary
62195 + */
62196 +#define FMODE_GREXEC ((__force fmode_t)0x2000000)
62197 +
62198 /*
62199 * The below are the various read and write types that we support. Some of
62200 * them include behavioral modifiers that send information down to the
62201 @@ -575,41 +580,41 @@ typedef int (*read_actor_t)(read_descrip
62202 unsigned long, unsigned long);
62203
62204 struct address_space_operations {
62205 - int (*writepage)(struct page *page, struct writeback_control *wbc);
62206 - int (*readpage)(struct file *, struct page *);
62207 + int (* const writepage)(struct page *page, struct writeback_control *wbc);
62208 + int (* const readpage)(struct file *, struct page *);
62209
62210 /* Write back some dirty pages from this mapping. */
62211 - int (*writepages)(struct address_space *, struct writeback_control *);
62212 + int (* const writepages)(struct address_space *, struct writeback_control *);
62213
62214 /* Set a page dirty. Return true if this dirtied it */
62215 - int (*set_page_dirty)(struct page *page);
62216 + int (* const set_page_dirty)(struct page *page);
62217
62218 - int (*readpages)(struct file *filp, struct address_space *mapping,
62219 + int (* const readpages)(struct file *filp, struct address_space *mapping,
62220 struct list_head *pages, unsigned nr_pages);
62221
62222 - int (*write_begin)(struct file *, struct address_space *mapping,
62223 + int (* const write_begin)(struct file *, struct address_space *mapping,
62224 loff_t pos, unsigned len, unsigned flags,
62225 struct page **pagep, void **fsdata);
62226 - int (*write_end)(struct file *, struct address_space *mapping,
62227 + int (* const write_end)(struct file *, struct address_space *mapping,
62228 loff_t pos, unsigned len, unsigned copied,
62229 struct page *page, void *fsdata);
62230
62231 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
62232 - sector_t (*bmap)(struct address_space *, sector_t);
62233 - void (*invalidatepage) (struct page *, unsigned long);
62234 - int (*releasepage) (struct page *, gfp_t);
62235 - void (*freepage)(struct page *);
62236 - ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
62237 + sector_t (* const bmap)(struct address_space *, sector_t);
62238 + void (* const invalidatepage) (struct page *, unsigned long);
62239 + int (* const releasepage) (struct page *, gfp_t);
62240 + void (* const freepage)(struct page *);
62241 + ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
62242 loff_t offset, unsigned long nr_segs);
62243 - int (*get_xip_mem)(struct address_space *, pgoff_t, int,
62244 + int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
62245 void **, unsigned long *);
62246 /* migrate the contents of a page to the specified target */
62247 - int (*migratepage) (struct address_space *,
62248 + int (* const migratepage) (struct address_space *,
62249 struct page *, struct page *);
62250 - int (*launder_page) (struct page *);
62251 - int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
62252 + int (* const launder_page) (struct page *);
62253 + int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
62254 unsigned long);
62255 - int (*error_remove_page)(struct address_space *, struct page *);
62256 + int (* const error_remove_page)(struct address_space *, struct page *);
62257 };
62258
62259 extern const struct address_space_operations empty_aops;
62260 @@ -1060,17 +1065,17 @@ static inline int file_check_writeable(s
62261 typedef struct files_struct *fl_owner_t;
62262
62263 struct file_lock_operations {
62264 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
62265 - void (*fl_release_private)(struct file_lock *);
62266 + void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
62267 + void (* const fl_release_private)(struct file_lock *);
62268 };
62269
62270 struct lock_manager_operations {
62271 - int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
62272 - void (*fl_notify)(struct file_lock *); /* unblock callback */
62273 - int (*fl_grant)(struct file_lock *, struct file_lock *, int);
62274 - void (*fl_release_private)(struct file_lock *);
62275 - void (*fl_break)(struct file_lock *);
62276 - int (*fl_change)(struct file_lock **, int);
62277 + int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
62278 + void (* const fl_notify)(struct file_lock *); /* unblock callback */
62279 + int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
62280 + void (* const fl_release_private)(struct file_lock *);
62281 + void (* const fl_break)(struct file_lock *);
62282 + int (* const fl_change)(struct file_lock **, int);
62283 };
62284
62285 struct lock_manager {
62286 @@ -1611,31 +1616,31 @@ extern ssize_t vfs_writev(struct file *,
62287 unsigned long, loff_t *);
62288
62289 struct super_operations {
62290 - struct inode *(*alloc_inode)(struct super_block *sb);
62291 - void (*destroy_inode)(struct inode *);
62292 + struct inode *(* const alloc_inode)(struct super_block *sb);
62293 + void (* const destroy_inode)(struct inode *);
62294
62295 - void (*dirty_inode) (struct inode *);
62296 - int (*write_inode) (struct inode *, struct writeback_control *wbc);
62297 - int (*drop_inode) (struct inode *);
62298 - void (*evict_inode) (struct inode *);
62299 - void (*put_super) (struct super_block *);
62300 - void (*write_super) (struct super_block *);
62301 - int (*sync_fs)(struct super_block *sb, int wait);
62302 - int (*freeze_fs) (struct super_block *);
62303 - int (*unfreeze_fs) (struct super_block *);
62304 - int (*statfs) (struct dentry *, struct kstatfs *);
62305 - int (*remount_fs) (struct super_block *, int *, char *);
62306 - void (*umount_begin) (struct super_block *);
62307 -
62308 - int (*show_options)(struct seq_file *, struct vfsmount *);
62309 - int (*show_devname)(struct seq_file *, struct vfsmount *);
62310 - int (*show_path)(struct seq_file *, struct vfsmount *);
62311 - int (*show_stats)(struct seq_file *, struct vfsmount *);
62312 + void (* const dirty_inode) (struct inode *);
62313 + int (* const write_inode) (struct inode *, struct writeback_control *wbc);
62314 + int (* const drop_inode) (struct inode *);
62315 + void (* const evict_inode) (struct inode *);
62316 + void (* const put_super) (struct super_block *);
62317 + void (* const write_super) (struct super_block *);
62318 + int (* const sync_fs)(struct super_block *sb, int wait);
62319 + int (* const freeze_fs) (struct super_block *);
62320 + int (* const unfreeze_fs) (struct super_block *);
62321 + int (* const statfs) (struct dentry *, struct kstatfs *);
62322 + int (* const remount_fs) (struct super_block *, int *, char *);
62323 + void (* const umount_begin) (struct super_block *);
62324 +
62325 + int (* const show_options)(struct seq_file *, struct vfsmount *);
62326 + int (* const show_devname)(struct seq_file *, struct vfsmount *);
62327 + int (* const show_path)(struct seq_file *, struct vfsmount *);
62328 + int (* const show_stats)(struct seq_file *, struct vfsmount *);
62329 #ifdef CONFIG_QUOTA
62330 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
62331 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62332 + ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
62333 + ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
62334 #endif
62335 - int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62336 + int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
62337 };
62338
62339 /*
62340 diff -urNp linux-2.6.39.2/include/linux/fs_struct.h linux-2.6.39.2/include/linux/fs_struct.h
62341 --- linux-2.6.39.2/include/linux/fs_struct.h 2011-05-19 00:06:34.000000000 -0400
62342 +++ linux-2.6.39.2/include/linux/fs_struct.h 2011-05-22 19:36:33.000000000 -0400
62343 @@ -6,7 +6,7 @@
62344 #include <linux/seqlock.h>
62345
62346 struct fs_struct {
62347 - int users;
62348 + atomic_t users;
62349 spinlock_t lock;
62350 seqcount_t seq;
62351 int umask;
62352 diff -urNp linux-2.6.39.2/include/linux/ftrace_event.h linux-2.6.39.2/include/linux/ftrace_event.h
62353 --- linux-2.6.39.2/include/linux/ftrace_event.h 2011-05-19 00:06:34.000000000 -0400
62354 +++ linux-2.6.39.2/include/linux/ftrace_event.h 2011-05-22 19:36:33.000000000 -0400
62355 @@ -235,7 +235,7 @@ extern int trace_define_field(struct ftr
62356 extern int trace_add_event_call(struct ftrace_event_call *call);
62357 extern void trace_remove_event_call(struct ftrace_event_call *call);
62358
62359 -#define is_signed_type(type) (((type)(-1)) < 0)
62360 +#define is_signed_type(type) (((type)(-1)) < (type)1)
62361
62362 int trace_set_clr_event(const char *system, const char *event, int set);
62363
62364 diff -urNp linux-2.6.39.2/include/linux/ftrace.h linux-2.6.39.2/include/linux/ftrace.h
62365 --- linux-2.6.39.2/include/linux/ftrace.h 2011-05-19 00:06:34.000000000 -0400
62366 +++ linux-2.6.39.2/include/linux/ftrace.h 2011-05-22 19:36:33.000000000 -0400
62367 @@ -140,7 +140,7 @@ extern void
62368 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
62369 void *data);
62370 extern void
62371 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
62372 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops);
62373 extern void unregister_ftrace_function_probe_all(char *glob);
62374
62375 extern int ftrace_text_reserved(void *start, void *end);
62376 diff -urNp linux-2.6.39.2/include/linux/genhd.h linux-2.6.39.2/include/linux/genhd.h
62377 --- linux-2.6.39.2/include/linux/genhd.h 2011-06-03 00:04:14.000000000 -0400
62378 +++ linux-2.6.39.2/include/linux/genhd.h 2011-06-03 00:32:08.000000000 -0400
62379 @@ -184,7 +184,7 @@ struct gendisk {
62380 struct kobject *slave_dir;
62381
62382 struct timer_rand_state *random;
62383 - atomic_t sync_io; /* RAID */
62384 + atomic_unchecked_t sync_io; /* RAID */
62385 struct disk_events *ev;
62386 #ifdef CONFIG_BLK_DEV_INTEGRITY
62387 struct blk_integrity *integrity;
62388 diff -urNp linux-2.6.39.2/include/linux/gracl.h linux-2.6.39.2/include/linux/gracl.h
62389 --- linux-2.6.39.2/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
62390 +++ linux-2.6.39.2/include/linux/gracl.h 2011-05-22 19:41:42.000000000 -0400
62391 @@ -0,0 +1,317 @@
62392 +#ifndef GR_ACL_H
62393 +#define GR_ACL_H
62394 +
62395 +#include <linux/grdefs.h>
62396 +#include <linux/resource.h>
62397 +#include <linux/capability.h>
62398 +#include <linux/dcache.h>
62399 +#include <asm/resource.h>
62400 +
62401 +/* Major status information */
62402 +
62403 +#define GR_VERSION "grsecurity 2.2.2"
62404 +#define GRSECURITY_VERSION 0x2202
62405 +
62406 +enum {
62407 + GR_SHUTDOWN = 0,
62408 + GR_ENABLE = 1,
62409 + GR_SPROLE = 2,
62410 + GR_RELOAD = 3,
62411 + GR_SEGVMOD = 4,
62412 + GR_STATUS = 5,
62413 + GR_UNSPROLE = 6,
62414 + GR_PASSSET = 7,
62415 + GR_SPROLEPAM = 8,
62416 +};
62417 +
62418 +/* Password setup definitions
62419 + * kernel/grhash.c */
62420 +enum {
62421 + GR_PW_LEN = 128,
62422 + GR_SALT_LEN = 16,
62423 + GR_SHA_LEN = 32,
62424 +};
62425 +
62426 +enum {
62427 + GR_SPROLE_LEN = 64,
62428 +};
62429 +
62430 +enum {
62431 + GR_NO_GLOB = 0,
62432 + GR_REG_GLOB,
62433 + GR_CREATE_GLOB
62434 +};
62435 +
62436 +#define GR_NLIMITS 32
62437 +
62438 +/* Begin Data Structures */
62439 +
62440 +struct sprole_pw {
62441 + unsigned char *rolename;
62442 + unsigned char salt[GR_SALT_LEN];
62443 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
62444 +};
62445 +
62446 +struct name_entry {
62447 + __u32 key;
62448 + ino_t inode;
62449 + dev_t device;
62450 + char *name;
62451 + __u16 len;
62452 + __u8 deleted;
62453 + struct name_entry *prev;
62454 + struct name_entry *next;
62455 +};
62456 +
62457 +struct inodev_entry {
62458 + struct name_entry *nentry;
62459 + struct inodev_entry *prev;
62460 + struct inodev_entry *next;
62461 +};
62462 +
62463 +struct acl_role_db {
62464 + struct acl_role_label **r_hash;
62465 + __u32 r_size;
62466 +};
62467 +
62468 +struct inodev_db {
62469 + struct inodev_entry **i_hash;
62470 + __u32 i_size;
62471 +};
62472 +
62473 +struct name_db {
62474 + struct name_entry **n_hash;
62475 + __u32 n_size;
62476 +};
62477 +
62478 +struct crash_uid {
62479 + uid_t uid;
62480 + unsigned long expires;
62481 +};
62482 +
62483 +struct gr_hash_struct {
62484 + void **table;
62485 + void **nametable;
62486 + void *first;
62487 + __u32 table_size;
62488 + __u32 used_size;
62489 + int type;
62490 +};
62491 +
62492 +/* Userspace Grsecurity ACL data structures */
62493 +
62494 +struct acl_subject_label {
62495 + char *filename;
62496 + ino_t inode;
62497 + dev_t device;
62498 + __u32 mode;
62499 + kernel_cap_t cap_mask;
62500 + kernel_cap_t cap_lower;
62501 + kernel_cap_t cap_invert_audit;
62502 +
62503 + struct rlimit res[GR_NLIMITS];
62504 + __u32 resmask;
62505 +
62506 + __u8 user_trans_type;
62507 + __u8 group_trans_type;
62508 + uid_t *user_transitions;
62509 + gid_t *group_transitions;
62510 + __u16 user_trans_num;
62511 + __u16 group_trans_num;
62512 +
62513 + __u32 sock_families[2];
62514 + __u32 ip_proto[8];
62515 + __u32 ip_type;
62516 + struct acl_ip_label **ips;
62517 + __u32 ip_num;
62518 + __u32 inaddr_any_override;
62519 +
62520 + __u32 crashes;
62521 + unsigned long expires;
62522 +
62523 + struct acl_subject_label *parent_subject;
62524 + struct gr_hash_struct *hash;
62525 + struct acl_subject_label *prev;
62526 + struct acl_subject_label *next;
62527 +
62528 + struct acl_object_label **obj_hash;
62529 + __u32 obj_hash_size;
62530 + __u16 pax_flags;
62531 +};
62532 +
62533 +struct role_allowed_ip {
62534 + __u32 addr;
62535 + __u32 netmask;
62536 +
62537 + struct role_allowed_ip *prev;
62538 + struct role_allowed_ip *next;
62539 +};
62540 +
62541 +struct role_transition {
62542 + char *rolename;
62543 +
62544 + struct role_transition *prev;
62545 + struct role_transition *next;
62546 +};
62547 +
62548 +struct acl_role_label {
62549 + char *rolename;
62550 + uid_t uidgid;
62551 + __u16 roletype;
62552 +
62553 + __u16 auth_attempts;
62554 + unsigned long expires;
62555 +
62556 + struct acl_subject_label *root_label;
62557 + struct gr_hash_struct *hash;
62558 +
62559 + struct acl_role_label *prev;
62560 + struct acl_role_label *next;
62561 +
62562 + struct role_transition *transitions;
62563 + struct role_allowed_ip *allowed_ips;
62564 + uid_t *domain_children;
62565 + __u16 domain_child_num;
62566 +
62567 + struct acl_subject_label **subj_hash;
62568 + __u32 subj_hash_size;
62569 +};
62570 +
62571 +struct user_acl_role_db {
62572 + struct acl_role_label **r_table;
62573 + __u32 num_pointers; /* Number of allocations to track */
62574 + __u32 num_roles; /* Number of roles */
62575 + __u32 num_domain_children; /* Number of domain children */
62576 + __u32 num_subjects; /* Number of subjects */
62577 + __u32 num_objects; /* Number of objects */
62578 +};
62579 +
62580 +struct acl_object_label {
62581 + char *filename;
62582 + ino_t inode;
62583 + dev_t device;
62584 + __u32 mode;
62585 +
62586 + struct acl_subject_label *nested;
62587 + struct acl_object_label *globbed;
62588 +
62589 + /* next two structures not used */
62590 +
62591 + struct acl_object_label *prev;
62592 + struct acl_object_label *next;
62593 +};
62594 +
62595 +struct acl_ip_label {
62596 + char *iface;
62597 + __u32 addr;
62598 + __u32 netmask;
62599 + __u16 low, high;
62600 + __u8 mode;
62601 + __u32 type;
62602 + __u32 proto[8];
62603 +
62604 + /* next two structures not used */
62605 +
62606 + struct acl_ip_label *prev;
62607 + struct acl_ip_label *next;
62608 +};
62609 +
62610 +struct gr_arg {
62611 + struct user_acl_role_db role_db;
62612 + unsigned char pw[GR_PW_LEN];
62613 + unsigned char salt[GR_SALT_LEN];
62614 + unsigned char sum[GR_SHA_LEN];
62615 + unsigned char sp_role[GR_SPROLE_LEN];
62616 + struct sprole_pw *sprole_pws;
62617 + dev_t segv_device;
62618 + ino_t segv_inode;
62619 + uid_t segv_uid;
62620 + __u16 num_sprole_pws;
62621 + __u16 mode;
62622 +};
62623 +
62624 +struct gr_arg_wrapper {
62625 + struct gr_arg *arg;
62626 + __u32 version;
62627 + __u32 size;
62628 +};
62629 +
62630 +struct subject_map {
62631 + struct acl_subject_label *user;
62632 + struct acl_subject_label *kernel;
62633 + struct subject_map *prev;
62634 + struct subject_map *next;
62635 +};
62636 +
62637 +struct acl_subj_map_db {
62638 + struct subject_map **s_hash;
62639 + __u32 s_size;
62640 +};
62641 +
62642 +/* End Data Structures Section */
62643 +
62644 +/* Hash functions generated by empirical testing by Brad Spengler
62645 + Makes good use of the low bits of the inode. Generally 0-1 times
62646 + in loop for successful match. 0-3 for unsuccessful match.
62647 + Shift/add algorithm with modulus of table size and an XOR*/
62648 +
62649 +static __inline__ unsigned int
62650 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62651 +{
62652 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62653 +}
62654 +
62655 + static __inline__ unsigned int
62656 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62657 +{
62658 + return ((const unsigned long)userp % sz);
62659 +}
62660 +
62661 +static __inline__ unsigned int
62662 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62663 +{
62664 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62665 +}
62666 +
62667 +static __inline__ unsigned int
62668 +nhash(const char *name, const __u16 len, const unsigned int sz)
62669 +{
62670 + return full_name_hash((const unsigned char *)name, len) % sz;
62671 +}
62672 +
62673 +#define FOR_EACH_ROLE_START(role) \
62674 + role = role_list; \
62675 + while (role) {
62676 +
62677 +#define FOR_EACH_ROLE_END(role) \
62678 + role = role->prev; \
62679 + }
62680 +
62681 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62682 + subj = NULL; \
62683 + iter = 0; \
62684 + while (iter < role->subj_hash_size) { \
62685 + if (subj == NULL) \
62686 + subj = role->subj_hash[iter]; \
62687 + if (subj == NULL) { \
62688 + iter++; \
62689 + continue; \
62690 + }
62691 +
62692 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62693 + subj = subj->next; \
62694 + if (subj == NULL) \
62695 + iter++; \
62696 + }
62697 +
62698 +
62699 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62700 + subj = role->hash->first; \
62701 + while (subj != NULL) {
62702 +
62703 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62704 + subj = subj->next; \
62705 + }
62706 +
62707 +#endif
62708 +
62709 diff -urNp linux-2.6.39.2/include/linux/gralloc.h linux-2.6.39.2/include/linux/gralloc.h
62710 --- linux-2.6.39.2/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
62711 +++ linux-2.6.39.2/include/linux/gralloc.h 2011-05-22 19:41:42.000000000 -0400
62712 @@ -0,0 +1,9 @@
62713 +#ifndef __GRALLOC_H
62714 +#define __GRALLOC_H
62715 +
62716 +void acl_free_all(void);
62717 +int acl_alloc_stack_init(unsigned long size);
62718 +void *acl_alloc(unsigned long len);
62719 +void *acl_alloc_num(unsigned long num, unsigned long len);
62720 +
62721 +#endif
62722 diff -urNp linux-2.6.39.2/include/linux/grdefs.h linux-2.6.39.2/include/linux/grdefs.h
62723 --- linux-2.6.39.2/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
62724 +++ linux-2.6.39.2/include/linux/grdefs.h 2011-06-11 16:24:51.000000000 -0400
62725 @@ -0,0 +1,140 @@
62726 +#ifndef GRDEFS_H
62727 +#define GRDEFS_H
62728 +
62729 +/* Begin grsecurity status declarations */
62730 +
62731 +enum {
62732 + GR_READY = 0x01,
62733 + GR_STATUS_INIT = 0x00 // disabled state
62734 +};
62735 +
62736 +/* Begin ACL declarations */
62737 +
62738 +/* Role flags */
62739 +
62740 +enum {
62741 + GR_ROLE_USER = 0x0001,
62742 + GR_ROLE_GROUP = 0x0002,
62743 + GR_ROLE_DEFAULT = 0x0004,
62744 + GR_ROLE_SPECIAL = 0x0008,
62745 + GR_ROLE_AUTH = 0x0010,
62746 + GR_ROLE_NOPW = 0x0020,
62747 + GR_ROLE_GOD = 0x0040,
62748 + GR_ROLE_LEARN = 0x0080,
62749 + GR_ROLE_TPE = 0x0100,
62750 + GR_ROLE_DOMAIN = 0x0200,
62751 + GR_ROLE_PAM = 0x0400,
62752 + GR_ROLE_PERSIST = 0x0800
62753 +};
62754 +
62755 +/* ACL Subject and Object mode flags */
62756 +enum {
62757 + GR_DELETED = 0x80000000
62758 +};
62759 +
62760 +/* ACL Object-only mode flags */
62761 +enum {
62762 + GR_READ = 0x00000001,
62763 + GR_APPEND = 0x00000002,
62764 + GR_WRITE = 0x00000004,
62765 + GR_EXEC = 0x00000008,
62766 + GR_FIND = 0x00000010,
62767 + GR_INHERIT = 0x00000020,
62768 + GR_SETID = 0x00000040,
62769 + GR_CREATE = 0x00000080,
62770 + GR_DELETE = 0x00000100,
62771 + GR_LINK = 0x00000200,
62772 + GR_AUDIT_READ = 0x00000400,
62773 + GR_AUDIT_APPEND = 0x00000800,
62774 + GR_AUDIT_WRITE = 0x00001000,
62775 + GR_AUDIT_EXEC = 0x00002000,
62776 + GR_AUDIT_FIND = 0x00004000,
62777 + GR_AUDIT_INHERIT= 0x00008000,
62778 + GR_AUDIT_SETID = 0x00010000,
62779 + GR_AUDIT_CREATE = 0x00020000,
62780 + GR_AUDIT_DELETE = 0x00040000,
62781 + GR_AUDIT_LINK = 0x00080000,
62782 + GR_PTRACERD = 0x00100000,
62783 + GR_NOPTRACE = 0x00200000,
62784 + GR_SUPPRESS = 0x00400000,
62785 + GR_NOLEARN = 0x00800000,
62786 + GR_INIT_TRANSFER= 0x01000000
62787 +};
62788 +
62789 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62790 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62791 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62792 +
62793 +/* ACL subject-only mode flags */
62794 +enum {
62795 + GR_KILL = 0x00000001,
62796 + GR_VIEW = 0x00000002,
62797 + GR_PROTECTED = 0x00000004,
62798 + GR_LEARN = 0x00000008,
62799 + GR_OVERRIDE = 0x00000010,
62800 + /* just a placeholder, this mode is only used in userspace */
62801 + GR_DUMMY = 0x00000020,
62802 + GR_PROTSHM = 0x00000040,
62803 + GR_KILLPROC = 0x00000080,
62804 + GR_KILLIPPROC = 0x00000100,
62805 + /* just a placeholder, this mode is only used in userspace */
62806 + GR_NOTROJAN = 0x00000200,
62807 + GR_PROTPROCFD = 0x00000400,
62808 + GR_PROCACCT = 0x00000800,
62809 + GR_RELAXPTRACE = 0x00001000,
62810 + GR_NESTED = 0x00002000,
62811 + GR_INHERITLEARN = 0x00004000,
62812 + GR_PROCFIND = 0x00008000,
62813 + GR_POVERRIDE = 0x00010000,
62814 + GR_KERNELAUTH = 0x00020000,
62815 + GR_ATSECURE = 0x00040000,
62816 + GR_SHMEXEC = 0x00080000
62817 +};
62818 +
62819 +enum {
62820 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62821 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62822 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62823 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62824 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62825 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62826 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62827 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62828 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62829 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62830 +};
62831 +
62832 +enum {
62833 + GR_ID_USER = 0x01,
62834 + GR_ID_GROUP = 0x02,
62835 +};
62836 +
62837 +enum {
62838 + GR_ID_ALLOW = 0x01,
62839 + GR_ID_DENY = 0x02,
62840 +};
62841 +
62842 +#define GR_CRASH_RES 31
62843 +#define GR_UIDTABLE_MAX 500
62844 +
62845 +/* begin resource learning section */
62846 +enum {
62847 + GR_RLIM_CPU_BUMP = 60,
62848 + GR_RLIM_FSIZE_BUMP = 50000,
62849 + GR_RLIM_DATA_BUMP = 10000,
62850 + GR_RLIM_STACK_BUMP = 1000,
62851 + GR_RLIM_CORE_BUMP = 10000,
62852 + GR_RLIM_RSS_BUMP = 500000,
62853 + GR_RLIM_NPROC_BUMP = 1,
62854 + GR_RLIM_NOFILE_BUMP = 5,
62855 + GR_RLIM_MEMLOCK_BUMP = 50000,
62856 + GR_RLIM_AS_BUMP = 500000,
62857 + GR_RLIM_LOCKS_BUMP = 2,
62858 + GR_RLIM_SIGPENDING_BUMP = 5,
62859 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62860 + GR_RLIM_NICE_BUMP = 1,
62861 + GR_RLIM_RTPRIO_BUMP = 1,
62862 + GR_RLIM_RTTIME_BUMP = 1000000
62863 +};
62864 +
62865 +#endif
62866 diff -urNp linux-2.6.39.2/include/linux/grinternal.h linux-2.6.39.2/include/linux/grinternal.h
62867 --- linux-2.6.39.2/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
62868 +++ linux-2.6.39.2/include/linux/grinternal.h 2011-05-22 19:41:42.000000000 -0400
62869 @@ -0,0 +1,219 @@
62870 +#ifndef __GRINTERNAL_H
62871 +#define __GRINTERNAL_H
62872 +
62873 +#ifdef CONFIG_GRKERNSEC
62874 +
62875 +#include <linux/fs.h>
62876 +#include <linux/mnt_namespace.h>
62877 +#include <linux/nsproxy.h>
62878 +#include <linux/gracl.h>
62879 +#include <linux/grdefs.h>
62880 +#include <linux/grmsg.h>
62881 +
62882 +void gr_add_learn_entry(const char *fmt, ...)
62883 + __attribute__ ((format (printf, 1, 2)));
62884 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62885 + const struct vfsmount *mnt);
62886 +__u32 gr_check_create(const struct dentry *new_dentry,
62887 + const struct dentry *parent,
62888 + const struct vfsmount *mnt, const __u32 mode);
62889 +int gr_check_protected_task(const struct task_struct *task);
62890 +__u32 to_gr_audit(const __u32 reqmode);
62891 +int gr_set_acls(const int type);
62892 +int gr_apply_subject_to_task(struct task_struct *task);
62893 +int gr_acl_is_enabled(void);
62894 +char gr_roletype_to_char(void);
62895 +
62896 +void gr_handle_alertkill(struct task_struct *task);
62897 +char *gr_to_filename(const struct dentry *dentry,
62898 + const struct vfsmount *mnt);
62899 +char *gr_to_filename1(const struct dentry *dentry,
62900 + const struct vfsmount *mnt);
62901 +char *gr_to_filename2(const struct dentry *dentry,
62902 + const struct vfsmount *mnt);
62903 +char *gr_to_filename3(const struct dentry *dentry,
62904 + const struct vfsmount *mnt);
62905 +
62906 +extern int grsec_enable_harden_ptrace;
62907 +extern int grsec_enable_link;
62908 +extern int grsec_enable_fifo;
62909 +extern int grsec_enable_execve;
62910 +extern int grsec_enable_shm;
62911 +extern int grsec_enable_execlog;
62912 +extern int grsec_enable_signal;
62913 +extern int grsec_enable_audit_ptrace;
62914 +extern int grsec_enable_forkfail;
62915 +extern int grsec_enable_time;
62916 +extern int grsec_enable_rofs;
62917 +extern int grsec_enable_chroot_shmat;
62918 +extern int grsec_enable_chroot_findtask;
62919 +extern int grsec_enable_chroot_mount;
62920 +extern int grsec_enable_chroot_double;
62921 +extern int grsec_enable_chroot_pivot;
62922 +extern int grsec_enable_chroot_chdir;
62923 +extern int grsec_enable_chroot_chmod;
62924 +extern int grsec_enable_chroot_mknod;
62925 +extern int grsec_enable_chroot_fchdir;
62926 +extern int grsec_enable_chroot_nice;
62927 +extern int grsec_enable_chroot_execlog;
62928 +extern int grsec_enable_chroot_caps;
62929 +extern int grsec_enable_chroot_sysctl;
62930 +extern int grsec_enable_chroot_unix;
62931 +extern int grsec_enable_tpe;
62932 +extern int grsec_tpe_gid;
62933 +extern int grsec_enable_tpe_all;
62934 +extern int grsec_enable_tpe_invert;
62935 +extern int grsec_enable_socket_all;
62936 +extern int grsec_socket_all_gid;
62937 +extern int grsec_enable_socket_client;
62938 +extern int grsec_socket_client_gid;
62939 +extern int grsec_enable_socket_server;
62940 +extern int grsec_socket_server_gid;
62941 +extern int grsec_audit_gid;
62942 +extern int grsec_enable_group;
62943 +extern int grsec_enable_audit_textrel;
62944 +extern int grsec_enable_log_rwxmaps;
62945 +extern int grsec_enable_mount;
62946 +extern int grsec_enable_chdir;
62947 +extern int grsec_resource_logging;
62948 +extern int grsec_enable_blackhole;
62949 +extern int grsec_lastack_retries;
62950 +extern int grsec_lock;
62951 +
62952 +extern spinlock_t grsec_alert_lock;
62953 +extern unsigned long grsec_alert_wtime;
62954 +extern unsigned long grsec_alert_fyet;
62955 +
62956 +extern spinlock_t grsec_audit_lock;
62957 +
62958 +extern rwlock_t grsec_exec_file_lock;
62959 +
62960 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62961 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62962 + (tsk)->exec_file->f_vfsmnt) : "/")
62963 +
62964 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62965 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62966 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62967 +
62968 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62969 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62970 + (tsk)->exec_file->f_vfsmnt) : "/")
62971 +
62972 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62973 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62974 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62975 +
62976 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62977 +
62978 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62979 +
62980 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62981 + (task)->pid, (cred)->uid, \
62982 + (cred)->euid, (cred)->gid, (cred)->egid, \
62983 + gr_parent_task_fullpath(task), \
62984 + (task)->real_parent->comm, (task)->real_parent->pid, \
62985 + (pcred)->uid, (pcred)->euid, \
62986 + (pcred)->gid, (pcred)->egid
62987 +
62988 +#define GR_CHROOT_CAPS {{ \
62989 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62990 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62991 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62992 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62993 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62994 + CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
62995 +
62996 +#define security_learn(normal_msg,args...) \
62997 +({ \
62998 + read_lock(&grsec_exec_file_lock); \
62999 + gr_add_learn_entry(normal_msg "\n", ## args); \
63000 + read_unlock(&grsec_exec_file_lock); \
63001 +})
63002 +
63003 +enum {
63004 + GR_DO_AUDIT,
63005 + GR_DONT_AUDIT,
63006 + /* used for non-audit messages that we shouldn't kill the task on */
63007 + GR_DONT_AUDIT_GOOD
63008 +};
63009 +
63010 +enum {
63011 + GR_TTYSNIFF,
63012 + GR_RBAC,
63013 + GR_RBAC_STR,
63014 + GR_STR_RBAC,
63015 + GR_RBAC_MODE2,
63016 + GR_RBAC_MODE3,
63017 + GR_FILENAME,
63018 + GR_SYSCTL_HIDDEN,
63019 + GR_NOARGS,
63020 + GR_ONE_INT,
63021 + GR_ONE_INT_TWO_STR,
63022 + GR_ONE_STR,
63023 + GR_STR_INT,
63024 + GR_TWO_STR_INT,
63025 + GR_TWO_INT,
63026 + GR_TWO_U64,
63027 + GR_THREE_INT,
63028 + GR_FIVE_INT_TWO_STR,
63029 + GR_TWO_STR,
63030 + GR_THREE_STR,
63031 + GR_FOUR_STR,
63032 + GR_STR_FILENAME,
63033 + GR_FILENAME_STR,
63034 + GR_FILENAME_TWO_INT,
63035 + GR_FILENAME_TWO_INT_STR,
63036 + GR_TEXTREL,
63037 + GR_PTRACE,
63038 + GR_RESOURCE,
63039 + GR_CAP,
63040 + GR_SIG,
63041 + GR_SIG2,
63042 + GR_CRASH1,
63043 + GR_CRASH2,
63044 + GR_PSACCT,
63045 + GR_RWXMAP
63046 +};
63047 +
63048 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63049 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63050 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63051 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63052 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63053 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63054 +#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
63055 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63056 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63057 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63058 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63059 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63060 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63061 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63062 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63063 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63064 +#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
63065 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63066 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63067 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63068 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63069 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63070 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63071 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63072 +#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
63073 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63074 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63075 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63076 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63077 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63078 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63079 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63080 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
63081 +#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
63082 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
63083 +
63084 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
63085 +
63086 +#endif
63087 +
63088 +#endif
63089 diff -urNp linux-2.6.39.2/include/linux/grmsg.h linux-2.6.39.2/include/linux/grmsg.h
63090 --- linux-2.6.39.2/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
63091 +++ linux-2.6.39.2/include/linux/grmsg.h 2011-05-22 19:41:42.000000000 -0400
63092 @@ -0,0 +1,108 @@
63093 +#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
63094 +#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%pI4 TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
63095 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
63096 +#define GR_STOPMOD_MSG "denied modification of module state by "
63097 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
63098 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
63099 +#define GR_IOPERM_MSG "denied use of ioperm() by "
63100 +#define GR_IOPL_MSG "denied use of iopl() by "
63101 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
63102 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
63103 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
63104 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
63105 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
63106 +#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%pI4"
63107 +#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%pI4"
63108 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
63109 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
63110 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
63111 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
63112 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
63113 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
63114 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
63115 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
63116 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
63117 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
63118 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
63119 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
63120 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
63121 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
63122 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
63123 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
63124 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
63125 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
63126 +#define GR_NPROC_MSG "denied overstep of process limit by "
63127 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
63128 +#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
63129 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
63130 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
63131 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
63132 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
63133 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
63134 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
63135 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
63136 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
63137 +#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
63138 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
63139 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
63140 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
63141 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
63142 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
63143 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
63144 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
63145 +#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
63146 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
63147 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
63148 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
63149 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
63150 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
63151 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
63152 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
63153 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
63154 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
63155 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
63156 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
63157 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
63158 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
63159 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
63160 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
63161 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
63162 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
63163 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
63164 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
63165 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
63166 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
63167 +#define GR_NICE_CHROOT_MSG "denied priority change by "
63168 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
63169 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
63170 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
63171 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
63172 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
63173 +#define GR_TIME_MSG "time set by "
63174 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
63175 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
63176 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
63177 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
63178 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
63179 +#define GR_BIND_MSG "denied bind() by "
63180 +#define GR_CONNECT_MSG "denied connect() by "
63181 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
63182 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
63183 +#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%pI4\t%u\t%u\t%u\t%u\t%pI4"
63184 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
63185 +#define GR_CAP_ACL_MSG "use of %s denied for "
63186 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
63187 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
63188 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
63189 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
63190 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
63191 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
63192 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
63193 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
63194 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
63195 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
63196 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
63197 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
63198 +#define GR_VM86_MSG "denied use of vm86 by "
63199 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
63200 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
63201 diff -urNp linux-2.6.39.2/include/linux/grsecurity.h linux-2.6.39.2/include/linux/grsecurity.h
63202 --- linux-2.6.39.2/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
63203 +++ linux-2.6.39.2/include/linux/grsecurity.h 2011-05-22 19:41:42.000000000 -0400
63204 @@ -0,0 +1,212 @@
63205 +#ifndef GR_SECURITY_H
63206 +#define GR_SECURITY_H
63207 +#include <linux/fs.h>
63208 +#include <linux/fs_struct.h>
63209 +#include <linux/binfmts.h>
63210 +#include <linux/gracl.h>
63211 +#include <linux/compat.h>
63212 +
63213 +/* notify of brain-dead configs */
63214 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
63215 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
63216 +#endif
63217 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63218 +#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63219 +#endif
63220 +#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
63221 +#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
63222 +#endif
63223 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
63224 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
63225 +#endif
63226 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
63227 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
63228 +#endif
63229 +
63230 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
63231 +void gr_handle_brute_check(void);
63232 +void gr_handle_kernel_exploit(void);
63233 +int gr_process_user_ban(void);
63234 +
63235 +char gr_roletype_to_char(void);
63236 +
63237 +int gr_acl_enable_at_secure(void);
63238 +
63239 +int gr_check_user_change(int real, int effective, int fs);
63240 +int gr_check_group_change(int real, int effective, int fs);
63241 +
63242 +void gr_del_task_from_ip_table(struct task_struct *p);
63243 +
63244 +int gr_pid_is_chrooted(struct task_struct *p);
63245 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
63246 +int gr_handle_chroot_nice(void);
63247 +int gr_handle_chroot_sysctl(const int op);
63248 +int gr_handle_chroot_setpriority(struct task_struct *p,
63249 + const int niceval);
63250 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
63251 +int gr_handle_chroot_chroot(const struct dentry *dentry,
63252 + const struct vfsmount *mnt);
63253 +int gr_handle_chroot_caps(struct path *path);
63254 +void gr_handle_chroot_chdir(struct path *path);
63255 +int gr_handle_chroot_chmod(const struct dentry *dentry,
63256 + const struct vfsmount *mnt, const int mode);
63257 +int gr_handle_chroot_mknod(const struct dentry *dentry,
63258 + const struct vfsmount *mnt, const int mode);
63259 +int gr_handle_chroot_mount(const struct dentry *dentry,
63260 + const struct vfsmount *mnt,
63261 + const char *dev_name);
63262 +int gr_handle_chroot_pivot(void);
63263 +int gr_handle_chroot_unix(struct pid *pid);
63264 +
63265 +int gr_handle_rawio(const struct inode *inode);
63266 +int gr_handle_nproc(void);
63267 +
63268 +void gr_handle_ioperm(void);
63269 +void gr_handle_iopl(void);
63270 +
63271 +int gr_tpe_allow(const struct file *file);
63272 +
63273 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
63274 +void gr_clear_chroot_entries(struct task_struct *task);
63275 +
63276 +void gr_log_forkfail(const int retval);
63277 +void gr_log_timechange(void);
63278 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
63279 +void gr_log_chdir(const struct dentry *dentry,
63280 + const struct vfsmount *mnt);
63281 +void gr_log_chroot_exec(const struct dentry *dentry,
63282 + const struct vfsmount *mnt);
63283 +void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
63284 +#ifdef CONFIG_COMPAT
63285 +void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
63286 +#endif
63287 +void gr_log_remount(const char *devname, const int retval);
63288 +void gr_log_unmount(const char *devname, const int retval);
63289 +void gr_log_mount(const char *from, const char *to, const int retval);
63290 +void gr_log_textrel(struct vm_area_struct *vma);
63291 +void gr_log_rwxmmap(struct file *file);
63292 +void gr_log_rwxmprotect(struct file *file);
63293 +
63294 +int gr_handle_follow_link(const struct inode *parent,
63295 + const struct inode *inode,
63296 + const struct dentry *dentry,
63297 + const struct vfsmount *mnt);
63298 +int gr_handle_fifo(const struct dentry *dentry,
63299 + const struct vfsmount *mnt,
63300 + const struct dentry *dir, const int flag,
63301 + const int acc_mode);
63302 +int gr_handle_hardlink(const struct dentry *dentry,
63303 + const struct vfsmount *mnt,
63304 + struct inode *inode,
63305 + const int mode, const char *to);
63306 +
63307 +int gr_is_capable(const int cap);
63308 +int gr_is_capable_nolog(const int cap);
63309 +void gr_learn_resource(const struct task_struct *task, const int limit,
63310 + const unsigned long wanted, const int gt);
63311 +void gr_copy_label(struct task_struct *tsk);
63312 +void gr_handle_crash(struct task_struct *task, const int sig);
63313 +int gr_handle_signal(const struct task_struct *p, const int sig);
63314 +int gr_check_crash_uid(const uid_t uid);
63315 +int gr_check_protected_task(const struct task_struct *task);
63316 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
63317 +int gr_acl_handle_mmap(const struct file *file,
63318 + const unsigned long prot);
63319 +int gr_acl_handle_mprotect(const struct file *file,
63320 + const unsigned long prot);
63321 +int gr_check_hidden_task(const struct task_struct *tsk);
63322 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
63323 + const struct vfsmount *mnt);
63324 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
63325 + const struct vfsmount *mnt);
63326 +__u32 gr_acl_handle_access(const struct dentry *dentry,
63327 + const struct vfsmount *mnt, const int fmode);
63328 +__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
63329 + const struct vfsmount *mnt, mode_t mode);
63330 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
63331 + const struct vfsmount *mnt, mode_t mode);
63332 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
63333 + const struct vfsmount *mnt);
63334 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
63335 + const struct vfsmount *mnt);
63336 +int gr_handle_ptrace(struct task_struct *task, const long request);
63337 +int gr_handle_proc_ptrace(struct task_struct *task);
63338 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
63339 + const struct vfsmount *mnt);
63340 +int gr_check_crash_exec(const struct file *filp);
63341 +int gr_acl_is_enabled(void);
63342 +void gr_set_kernel_label(struct task_struct *task);
63343 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
63344 + const gid_t gid);
63345 +int gr_set_proc_label(const struct dentry *dentry,
63346 + const struct vfsmount *mnt,
63347 + const int unsafe_share);
63348 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
63349 + const struct vfsmount *mnt);
63350 +__u32 gr_acl_handle_open(const struct dentry *dentry,
63351 + const struct vfsmount *mnt, const int fmode);
63352 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
63353 + const struct dentry *p_dentry,
63354 + const struct vfsmount *p_mnt, const int fmode,
63355 + const int imode);
63356 +void gr_handle_create(const struct dentry *dentry,
63357 + const struct vfsmount *mnt);
63358 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
63359 + const struct dentry *parent_dentry,
63360 + const struct vfsmount *parent_mnt,
63361 + const int mode);
63362 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
63363 + const struct dentry *parent_dentry,
63364 + const struct vfsmount *parent_mnt);
63365 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
63366 + const struct vfsmount *mnt);
63367 +void gr_handle_delete(const ino_t ino, const dev_t dev);
63368 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
63369 + const struct vfsmount *mnt);
63370 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
63371 + const struct dentry *parent_dentry,
63372 + const struct vfsmount *parent_mnt,
63373 + const char *from);
63374 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
63375 + const struct dentry *parent_dentry,
63376 + const struct vfsmount *parent_mnt,
63377 + const struct dentry *old_dentry,
63378 + const struct vfsmount *old_mnt, const char *to);
63379 +int gr_acl_handle_rename(struct dentry *new_dentry,
63380 + struct dentry *parent_dentry,
63381 + const struct vfsmount *parent_mnt,
63382 + struct dentry *old_dentry,
63383 + struct inode *old_parent_inode,
63384 + struct vfsmount *old_mnt, const char *newname);
63385 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63386 + struct dentry *old_dentry,
63387 + struct dentry *new_dentry,
63388 + struct vfsmount *mnt, const __u8 replace);
63389 +__u32 gr_check_link(const struct dentry *new_dentry,
63390 + const struct dentry *parent_dentry,
63391 + const struct vfsmount *parent_mnt,
63392 + const struct dentry *old_dentry,
63393 + const struct vfsmount *old_mnt);
63394 +int gr_acl_handle_filldir(const struct file *file, const char *name,
63395 + const unsigned int namelen, const ino_t ino);
63396 +
63397 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
63398 + const struct vfsmount *mnt);
63399 +void gr_acl_handle_exit(void);
63400 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
63401 +int gr_acl_handle_procpidmem(const struct task_struct *task);
63402 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
63403 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
63404 +void gr_audit_ptrace(struct task_struct *task);
63405 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
63406 +
63407 +#ifdef CONFIG_GRKERNSEC
63408 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
63409 +void gr_handle_vm86(void);
63410 +void gr_handle_mem_readwrite(u64 from, u64 to);
63411 +
63412 +extern int grsec_enable_dmesg;
63413 +extern int grsec_disable_privio;
63414 +#endif
63415 +
63416 +#endif
63417 diff -urNp linux-2.6.39.2/include/linux/grsock.h linux-2.6.39.2/include/linux/grsock.h
63418 --- linux-2.6.39.2/include/linux/grsock.h 1969-12-31 19:00:00.000000000 -0500
63419 +++ linux-2.6.39.2/include/linux/grsock.h 2011-05-22 19:41:42.000000000 -0400
63420 @@ -0,0 +1,19 @@
63421 +#ifndef __GRSOCK_H
63422 +#define __GRSOCK_H
63423 +
63424 +extern void gr_attach_curr_ip(const struct sock *sk);
63425 +extern int gr_handle_sock_all(const int family, const int type,
63426 + const int protocol);
63427 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63428 +extern int gr_handle_sock_server_other(const struct sock *sck);
63429 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63430 +extern int gr_search_connect(struct socket * sock,
63431 + struct sockaddr_in * addr);
63432 +extern int gr_search_bind(struct socket * sock,
63433 + struct sockaddr_in * addr);
63434 +extern int gr_search_listen(struct socket * sock);
63435 +extern int gr_search_accept(struct socket * sock);
63436 +extern int gr_search_socket(const int domain, const int type,
63437 + const int protocol);
63438 +
63439 +#endif
63440 diff -urNp linux-2.6.39.2/include/linux/highmem.h linux-2.6.39.2/include/linux/highmem.h
63441 --- linux-2.6.39.2/include/linux/highmem.h 2011-05-19 00:06:34.000000000 -0400
63442 +++ linux-2.6.39.2/include/linux/highmem.h 2011-05-22 19:36:33.000000000 -0400
63443 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct
63444 kunmap_atomic(kaddr, KM_USER0);
63445 }
63446
63447 +static inline void sanitize_highpage(struct page *page)
63448 +{
63449 + void *kaddr;
63450 + unsigned long flags;
63451 +
63452 + local_irq_save(flags);
63453 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
63454 + clear_page(kaddr);
63455 + kunmap_atomic(kaddr, KM_CLEARPAGE);
63456 + local_irq_restore(flags);
63457 +}
63458 +
63459 static inline void zero_user_segments(struct page *page,
63460 unsigned start1, unsigned end1,
63461 unsigned start2, unsigned end2)
63462 diff -urNp linux-2.6.39.2/include/linux/i2o.h linux-2.6.39.2/include/linux/i2o.h
63463 --- linux-2.6.39.2/include/linux/i2o.h 2011-05-19 00:06:34.000000000 -0400
63464 +++ linux-2.6.39.2/include/linux/i2o.h 2011-05-22 19:36:33.000000000 -0400
63465 @@ -564,7 +564,7 @@ struct i2o_controller {
63466 struct i2o_device *exec; /* Executive */
63467 #if BITS_PER_LONG == 64
63468 spinlock_t context_list_lock; /* lock for context_list */
63469 - atomic_t context_list_counter; /* needed for unique contexts */
63470 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63471 struct list_head context_list; /* list of context id's
63472 and pointers */
63473 #endif
63474 diff -urNp linux-2.6.39.2/include/linux/if_phonet.h linux-2.6.39.2/include/linux/if_phonet.h
63475 --- linux-2.6.39.2/include/linux/if_phonet.h 2011-05-19 00:06:34.000000000 -0400
63476 +++ linux-2.6.39.2/include/linux/if_phonet.h 2011-05-22 19:36:33.000000000 -0400
63477 @@ -13,7 +13,7 @@
63478 #define PHONET_DEV_MTU PHONET_MAX_MTU
63479
63480 #ifdef __KERNEL__
63481 -extern struct header_ops phonet_header_ops;
63482 +extern const struct header_ops phonet_header_ops;
63483 #endif
63484
63485 #endif
63486 diff -urNp linux-2.6.39.2/include/linux/init.h linux-2.6.39.2/include/linux/init.h
63487 --- linux-2.6.39.2/include/linux/init.h 2011-05-19 00:06:34.000000000 -0400
63488 +++ linux-2.6.39.2/include/linux/init.h 2011-05-22 19:36:33.000000000 -0400
63489 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cm
63490
63491 /* Each module must use one module_init(). */
63492 #define module_init(initfn) \
63493 - static inline initcall_t __inittest(void) \
63494 + static inline __used initcall_t __inittest(void) \
63495 { return initfn; } \
63496 int init_module(void) __attribute__((alias(#initfn)));
63497
63498 /* This is only required if you want to be unloadable. */
63499 #define module_exit(exitfn) \
63500 - static inline exitcall_t __exittest(void) \
63501 + static inline __used exitcall_t __exittest(void) \
63502 { return exitfn; } \
63503 void cleanup_module(void) __attribute__((alias(#exitfn)));
63504
63505 diff -urNp linux-2.6.39.2/include/linux/init_task.h linux-2.6.39.2/include/linux/init_task.h
63506 --- linux-2.6.39.2/include/linux/init_task.h 2011-05-19 00:06:34.000000000 -0400
63507 +++ linux-2.6.39.2/include/linux/init_task.h 2011-05-22 19:36:33.000000000 -0400
63508 @@ -83,6 +83,12 @@ extern struct group_info init_groups;
63509 #define INIT_IDS
63510 #endif
63511
63512 +#ifdef CONFIG_X86
63513 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63514 +#else
63515 +#define INIT_TASK_THREAD_INFO
63516 +#endif
63517 +
63518 /*
63519 * Because of the reduced scope of CAP_SETPCAP when filesystem
63520 * capabilities are in effect, it is safe to allow CAP_SETPCAP to
63521 @@ -163,6 +169,7 @@ extern struct cred init_cred;
63522 RCU_INIT_POINTER(.cred, &init_cred), \
63523 .comm = "swapper", \
63524 .thread = INIT_THREAD, \
63525 + INIT_TASK_THREAD_INFO \
63526 .fs = &init_fs, \
63527 .files = &init_files, \
63528 .signal = &init_signals, \
63529 diff -urNp linux-2.6.39.2/include/linux/interrupt.h linux-2.6.39.2/include/linux/interrupt.h
63530 --- linux-2.6.39.2/include/linux/interrupt.h 2011-05-19 00:06:34.000000000 -0400
63531 +++ linux-2.6.39.2/include/linux/interrupt.h 2011-05-22 19:36:33.000000000 -0400
63532 @@ -422,7 +422,7 @@ enum
63533 /* map softirq index to softirq name. update 'softirq_to_name' in
63534 * kernel/softirq.c when adding a new softirq.
63535 */
63536 -extern char *softirq_to_name[NR_SOFTIRQS];
63537 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63538
63539 /* softirq mask and active fields moved to irq_cpustat_t in
63540 * asm/hardirq.h to get better cache usage. KAO
63541 @@ -430,12 +430,12 @@ extern char *softirq_to_name[NR_SOFTIRQS
63542
63543 struct softirq_action
63544 {
63545 - void (*action)(struct softirq_action *);
63546 + void (*action)(void);
63547 };
63548
63549 asmlinkage void do_softirq(void);
63550 asmlinkage void __do_softirq(void);
63551 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63552 +extern void open_softirq(int nr, void (*action)(void));
63553 extern void softirq_init(void);
63554 static inline void __raise_softirq_irqoff(unsigned int nr)
63555 {
63556 diff -urNp linux-2.6.39.2/include/linux/iommu.h linux-2.6.39.2/include/linux/iommu.h
63557 --- linux-2.6.39.2/include/linux/iommu.h 2011-05-19 00:06:34.000000000 -0400
63558 +++ linux-2.6.39.2/include/linux/iommu.h 2011-05-22 19:36:33.000000000 -0400
63559 @@ -49,7 +49,7 @@ struct iommu_ops {
63560
63561 #ifdef CONFIG_IOMMU_API
63562
63563 -extern void register_iommu(struct iommu_ops *ops);
63564 +extern void register_iommu(const struct iommu_ops *ops);
63565 extern bool iommu_found(void);
63566 extern struct iommu_domain *iommu_domain_alloc(void);
63567 extern void iommu_domain_free(struct iommu_domain *domain);
63568 diff -urNp linux-2.6.39.2/include/linux/ipmi.h linux-2.6.39.2/include/linux/ipmi.h
63569 --- linux-2.6.39.2/include/linux/ipmi.h 2011-05-19 00:06:34.000000000 -0400
63570 +++ linux-2.6.39.2/include/linux/ipmi.h 2011-05-22 19:36:33.000000000 -0400
63571 @@ -282,7 +282,7 @@ struct ipmi_user_hndl {
63572
63573 /* Create a new user of the IPMI layer on the given interface number. */
63574 int ipmi_create_user(unsigned int if_num,
63575 - struct ipmi_user_hndl *handler,
63576 + const struct ipmi_user_hndl *handler,
63577 void *handler_data,
63578 ipmi_user_t *user);
63579
63580 diff -urNp linux-2.6.39.2/include/linux/kallsyms.h linux-2.6.39.2/include/linux/kallsyms.h
63581 --- linux-2.6.39.2/include/linux/kallsyms.h 2011-05-19 00:06:34.000000000 -0400
63582 +++ linux-2.6.39.2/include/linux/kallsyms.h 2011-05-22 22:52:54.000000000 -0400
63583 @@ -15,7 +15,8 @@
63584
63585 struct module;
63586
63587 -#ifdef CONFIG_KALLSYMS
63588 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63589 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63590 /* Lookup the address for a symbol. Returns 0 if not found. */
63591 unsigned long kallsyms_lookup_name(const char *name);
63592
63593 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(un
63594 /* Stupid that this does nothing, but I didn't create this mess. */
63595 #define __print_symbol(fmt, addr)
63596 #endif /*CONFIG_KALLSYMS*/
63597 +#else /* when included by kallsyms.c, vsnprintf.c, or
63598 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63599 +extern void __print_symbol(const char *fmt, unsigned long address);
63600 +extern int sprint_backtrace(char *buffer, unsigned long address);
63601 +extern int sprint_symbol(char *buffer, unsigned long address);
63602 +const char *kallsyms_lookup(unsigned long addr,
63603 + unsigned long *symbolsize,
63604 + unsigned long *offset,
63605 + char **modname, char *namebuf);
63606 +#endif
63607
63608 /* This macro allows us to keep printk typechecking */
63609 static void __check_printsym_format(const char *fmt, ...)
63610 diff -urNp linux-2.6.39.2/include/linux/kgdb.h linux-2.6.39.2/include/linux/kgdb.h
63611 --- linux-2.6.39.2/include/linux/kgdb.h 2011-05-19 00:06:34.000000000 -0400
63612 +++ linux-2.6.39.2/include/linux/kgdb.h 2011-05-22 19:36:33.000000000 -0400
63613 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63614 extern int kgdb_io_module_registered;
63615
63616 extern atomic_t kgdb_setting_breakpoint;
63617 -extern atomic_t kgdb_cpu_doing_single_step;
63618 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63619
63620 extern struct task_struct *kgdb_usethread;
63621 extern struct task_struct *kgdb_contthread;
63622 @@ -269,22 +269,22 @@ struct kgdb_arch {
63623 */
63624 struct kgdb_io {
63625 const char *name;
63626 - int (*read_char) (void);
63627 - void (*write_char) (u8);
63628 - void (*flush) (void);
63629 - int (*init) (void);
63630 - void (*pre_exception) (void);
63631 - void (*post_exception) (void);
63632 + int (* const read_char) (void);
63633 + void (* const write_char) (u8);
63634 + void (* const flush) (void);
63635 + int (* const init) (void);
63636 + void (* const pre_exception) (void);
63637 + void (* const post_exception) (void);
63638 int is_console;
63639 };
63640
63641 -extern struct kgdb_arch arch_kgdb_ops;
63642 +extern const struct kgdb_arch arch_kgdb_ops;
63643
63644 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
63645
63646 -extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
63647 -extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
63648 -extern struct kgdb_io *dbg_io_ops;
63649 +extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
63650 +extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
63651 +extern const struct kgdb_io *dbg_io_ops;
63652
63653 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
63654 extern char *kgdb_mem2hex(char *mem, char *buf, int count);
63655 diff -urNp linux-2.6.39.2/include/linux/kmod.h linux-2.6.39.2/include/linux/kmod.h
63656 --- linux-2.6.39.2/include/linux/kmod.h 2011-05-19 00:06:34.000000000 -0400
63657 +++ linux-2.6.39.2/include/linux/kmod.h 2011-05-22 19:41:42.000000000 -0400
63658 @@ -33,6 +33,8 @@ extern char modprobe_path[]; /* for sysc
63659 * usually useless though. */
63660 extern int __request_module(bool wait, const char *name, ...) \
63661 __attribute__((format(printf, 2, 3)));
63662 +extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
63663 + __attribute__((format(printf, 3, 4)));
63664 #define request_module(mod...) __request_module(true, mod)
63665 #define request_module_nowait(mod...) __request_module(false, mod)
63666 #define try_then_request_module(x, mod...) \
63667 diff -urNp linux-2.6.39.2/include/linux/kvm_host.h linux-2.6.39.2/include/linux/kvm_host.h
63668 --- linux-2.6.39.2/include/linux/kvm_host.h 2011-05-19 00:06:34.000000000 -0400
63669 +++ linux-2.6.39.2/include/linux/kvm_host.h 2011-05-22 19:36:33.000000000 -0400
63670 @@ -302,7 +302,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vc
63671 void vcpu_load(struct kvm_vcpu *vcpu);
63672 void vcpu_put(struct kvm_vcpu *vcpu);
63673
63674 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63675 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63676 struct module *module);
63677 void kvm_exit(void);
63678
63679 @@ -442,7 +442,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(
63680 struct kvm_guest_debug *dbg);
63681 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63682
63683 -int kvm_arch_init(void *opaque);
63684 +int kvm_arch_init(const void *opaque);
63685 void kvm_arch_exit(void);
63686
63687 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63688 diff -urNp linux-2.6.39.2/include/linux/lapb.h linux-2.6.39.2/include/linux/lapb.h
63689 --- linux-2.6.39.2/include/linux/lapb.h 2011-05-19 00:06:34.000000000 -0400
63690 +++ linux-2.6.39.2/include/linux/lapb.h 2011-05-22 19:36:33.000000000 -0400
63691 @@ -44,7 +44,7 @@ struct lapb_parms_struct {
63692 unsigned int mode;
63693 };
63694
63695 -extern int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks);
63696 +extern int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks);
63697 extern int lapb_unregister(struct net_device *dev);
63698 extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms);
63699 extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
63700 diff -urNp linux-2.6.39.2/include/linux/lcd.h linux-2.6.39.2/include/linux/lcd.h
63701 --- linux-2.6.39.2/include/linux/lcd.h 2011-05-19 00:06:34.000000000 -0400
63702 +++ linux-2.6.39.2/include/linux/lcd.h 2011-05-22 19:36:33.000000000 -0400
63703 @@ -60,7 +60,7 @@ struct lcd_device {
63704 points to something in the body of that driver, it is also invalid. */
63705 struct mutex ops_lock;
63706 /* If this is NULL, the backing module is unloaded */
63707 - struct lcd_ops *ops;
63708 + const struct lcd_ops *ops;
63709 /* Serialise access to set_power method */
63710 struct mutex update_lock;
63711 /* The framebuffer notifier block */
63712 @@ -101,7 +101,7 @@ static inline void lcd_set_power(struct
63713 }
63714
63715 extern struct lcd_device *lcd_device_register(const char *name,
63716 - struct device *parent, void *devdata, struct lcd_ops *ops);
63717 + struct device *parent, void *devdata, const struct lcd_ops *ops);
63718 extern void lcd_device_unregister(struct lcd_device *ld);
63719
63720 #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
63721 diff -urNp linux-2.6.39.2/include/linux/libata.h linux-2.6.39.2/include/linux/libata.h
63722 --- linux-2.6.39.2/include/linux/libata.h 2011-05-19 00:06:34.000000000 -0400
63723 +++ linux-2.6.39.2/include/linux/libata.h 2011-05-22 19:36:33.000000000 -0400
63724 @@ -524,11 +524,11 @@ struct ata_ioports {
63725
63726 struct ata_host {
63727 spinlock_t lock;
63728 - struct device *dev;
63729 + struct device *dev;
63730 void __iomem * const *iomap;
63731 unsigned int n_ports;
63732 void *private_data;
63733 - struct ata_port_operations *ops;
63734 + const struct ata_port_operations *ops;
63735 unsigned long flags;
63736
63737 struct mutex eh_mutex;
63738 @@ -719,7 +719,7 @@ struct ata_link {
63739
63740 struct ata_port {
63741 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
63742 - struct ata_port_operations *ops;
63743 + const struct ata_port_operations *ops;
63744 spinlock_t *lock;
63745 /* Flags owned by the EH context. Only EH should touch these once the
63746 port is active */
63747 @@ -907,7 +907,7 @@ struct ata_port_info {
63748 unsigned long pio_mask;
63749 unsigned long mwdma_mask;
63750 unsigned long udma_mask;
63751 - struct ata_port_operations *port_ops;
63752 + const struct ata_port_operations *port_ops;
63753 void *private_data;
63754 };
63755
63756 @@ -931,7 +931,7 @@ extern const unsigned long sata_deb_timi
63757 extern const unsigned long sata_deb_timing_hotplug[];
63758 extern const unsigned long sata_deb_timing_long[];
63759
63760 -extern struct ata_port_operations ata_dummy_port_ops;
63761 +extern const struct ata_port_operations ata_dummy_port_ops;
63762 extern const struct ata_port_info ata_dummy_port_info;
63763
63764 static inline const unsigned long *
63765 @@ -977,7 +977,7 @@ extern int ata_host_activate(struct ata_
63766 struct scsi_host_template *sht);
63767 extern void ata_host_detach(struct ata_host *host);
63768 extern void ata_host_init(struct ata_host *, struct device *,
63769 - unsigned long, struct ata_port_operations *);
63770 + unsigned long, const struct ata_port_operations *);
63771 extern int ata_scsi_detect(struct scsi_host_template *sht);
63772 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
63773 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
63774 diff -urNp linux-2.6.39.2/include/linux/lockd/bind.h linux-2.6.39.2/include/linux/lockd/bind.h
63775 --- linux-2.6.39.2/include/linux/lockd/bind.h 2011-05-19 00:06:34.000000000 -0400
63776 +++ linux-2.6.39.2/include/linux/lockd/bind.h 2011-05-22 19:36:33.000000000 -0400
63777 @@ -23,13 +23,13 @@ struct svc_rqst;
63778 * This is the set of functions for lockd->nfsd communication
63779 */
63780 struct nlmsvc_binding {
63781 - __be32 (*fopen)(struct svc_rqst *,
63782 + __be32 (* const fopen)(struct svc_rqst *,
63783 struct nfs_fh *,
63784 struct file **);
63785 - void (*fclose)(struct file *);
63786 + void (* const fclose)(struct file *);
63787 };
63788
63789 -extern struct nlmsvc_binding * nlmsvc_ops;
63790 +extern const struct nlmsvc_binding * nlmsvc_ops;
63791
63792 /*
63793 * Similar to nfs_client_initdata, but without the NFS-specific
63794 diff -urNp linux-2.6.39.2/include/linux/mfd/abx500.h linux-2.6.39.2/include/linux/mfd/abx500.h
63795 --- linux-2.6.39.2/include/linux/mfd/abx500.h 2011-05-19 00:06:34.000000000 -0400
63796 +++ linux-2.6.39.2/include/linux/mfd/abx500.h 2011-05-22 19:36:33.000000000 -0400
63797 @@ -227,6 +227,6 @@ struct abx500_ops {
63798 int (*startup_irq_enabled) (struct device *, unsigned int);
63799 };
63800
63801 -int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63802 +int abx500_register_ops(struct device *core_dev, const struct abx500_ops *ops);
63803 void abx500_remove_ops(struct device *dev);
63804 #endif
63805 diff -urNp linux-2.6.39.2/include/linux/mm.h linux-2.6.39.2/include/linux/mm.h
63806 --- linux-2.6.39.2/include/linux/mm.h 2011-05-19 00:06:34.000000000 -0400
63807 +++ linux-2.6.39.2/include/linux/mm.h 2011-05-22 19:36:33.000000000 -0400
63808 @@ -113,7 +113,14 @@ extern unsigned int kobjsize(const void
63809
63810 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63811 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63812 +
63813 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63814 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63815 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63816 +#else
63817 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63818 +#endif
63819 +
63820 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63821 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63822
63823 @@ -1010,34 +1017,6 @@ int set_page_dirty(struct page *page);
63824 int set_page_dirty_lock(struct page *page);
63825 int clear_page_dirty_for_io(struct page *page);
63826
63827 -/* Is the vma a continuation of the stack vma above it? */
63828 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63829 -{
63830 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63831 -}
63832 -
63833 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63834 - unsigned long addr)
63835 -{
63836 - return (vma->vm_flags & VM_GROWSDOWN) &&
63837 - (vma->vm_start == addr) &&
63838 - !vma_growsdown(vma->vm_prev, addr);
63839 -}
63840 -
63841 -/* Is the vma a continuation of the stack vma below it? */
63842 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63843 -{
63844 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63845 -}
63846 -
63847 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63848 - unsigned long addr)
63849 -{
63850 - return (vma->vm_flags & VM_GROWSUP) &&
63851 - (vma->vm_end == addr) &&
63852 - !vma_growsup(vma->vm_next, addr);
63853 -}
63854 -
63855 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63856 unsigned long old_addr, struct vm_area_struct *new_vma,
63857 unsigned long new_addr, unsigned long len);
63858 @@ -1189,6 +1168,15 @@ struct shrinker {
63859 extern void register_shrinker(struct shrinker *);
63860 extern void unregister_shrinker(struct shrinker *);
63861
63862 +#ifdef CONFIG_MMU
63863 +pgprot_t vm_get_page_prot(unsigned long vm_flags);
63864 +#else
63865 +static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63866 +{
63867 + return __pgprot(0);
63868 +}
63869 +#endif
63870 +
63871 int vma_wants_writenotify(struct vm_area_struct *vma);
63872
63873 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63874 @@ -1476,6 +1464,7 @@ out:
63875 }
63876
63877 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63878 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63879
63880 extern unsigned long do_brk(unsigned long, unsigned long);
63881
63882 @@ -1532,6 +1521,10 @@ extern struct vm_area_struct * find_vma(
63883 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63884 struct vm_area_struct **pprev);
63885
63886 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63887 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63888 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63889 +
63890 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63891 NULL if none. Assume start_addr < end_addr. */
63892 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63893 @@ -1548,15 +1541,6 @@ static inline unsigned long vma_pages(st
63894 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63895 }
63896
63897 -#ifdef CONFIG_MMU
63898 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63899 -#else
63900 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63901 -{
63902 - return __pgprot(0);
63903 -}
63904 -#endif
63905 -
63906 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63907 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63908 unsigned long pfn, unsigned long size, pgprot_t);
63909 @@ -1668,7 +1652,7 @@ extern int unpoison_memory(unsigned long
63910 extern int sysctl_memory_failure_early_kill;
63911 extern int sysctl_memory_failure_recovery;
63912 extern void shake_page(struct page *p, int access);
63913 -extern atomic_long_t mce_bad_pages;
63914 +extern atomic_long_unchecked_t mce_bad_pages;
63915 extern int soft_offline_page(struct page *page, int flags);
63916
63917 extern void dump_page(struct page *page);
63918 @@ -1682,5 +1666,11 @@ extern void copy_user_huge_page(struct p
63919 unsigned int pages_per_huge_page);
63920 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
63921
63922 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63923 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63924 +#else
63925 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63926 +#endif
63927 +
63928 #endif /* __KERNEL__ */
63929 #endif /* _LINUX_MM_H */
63930 diff -urNp linux-2.6.39.2/include/linux/mm_types.h linux-2.6.39.2/include/linux/mm_types.h
63931 --- linux-2.6.39.2/include/linux/mm_types.h 2011-05-19 00:06:34.000000000 -0400
63932 +++ linux-2.6.39.2/include/linux/mm_types.h 2011-05-22 19:36:33.000000000 -0400
63933 @@ -183,6 +183,8 @@ struct vm_area_struct {
63934 #ifdef CONFIG_NUMA
63935 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63936 #endif
63937 +
63938 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63939 };
63940
63941 struct core_thread {
63942 @@ -317,6 +319,24 @@ struct mm_struct {
63943 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63944 pgtable_t pmd_huge_pte; /* protected by page_table_lock */
63945 #endif
63946 +
63947 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63948 + unsigned long pax_flags;
63949 +#endif
63950 +
63951 +#ifdef CONFIG_PAX_DLRESOLVE
63952 + unsigned long call_dl_resolve;
63953 +#endif
63954 +
63955 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63956 + unsigned long call_syscall;
63957 +#endif
63958 +
63959 +#ifdef CONFIG_PAX_ASLR
63960 + unsigned long delta_mmap; /* randomized offset */
63961 + unsigned long delta_stack; /* randomized offset */
63962 +#endif
63963 +
63964 };
63965
63966 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
63967 diff -urNp linux-2.6.39.2/include/linux/mmu_notifier.h linux-2.6.39.2/include/linux/mmu_notifier.h
63968 --- linux-2.6.39.2/include/linux/mmu_notifier.h 2011-05-19 00:06:34.000000000 -0400
63969 +++ linux-2.6.39.2/include/linux/mmu_notifier.h 2011-05-22 19:36:33.000000000 -0400
63970 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destr
63971 */
63972 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63973 ({ \
63974 - pte_t __pte; \
63975 + pte_t ___pte; \
63976 struct vm_area_struct *___vma = __vma; \
63977 unsigned long ___address = __address; \
63978 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63979 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63980 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63981 - __pte; \
63982 + ___pte; \
63983 })
63984
63985 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63986 diff -urNp linux-2.6.39.2/include/linux/mmzone.h linux-2.6.39.2/include/linux/mmzone.h
63987 --- linux-2.6.39.2/include/linux/mmzone.h 2011-05-19 00:06:34.000000000 -0400
63988 +++ linux-2.6.39.2/include/linux/mmzone.h 2011-05-22 19:36:33.000000000 -0400
63989 @@ -355,7 +355,7 @@ struct zone {
63990 unsigned long flags; /* zone flags, see below */
63991
63992 /* Zone statistics */
63993 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63994 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63995
63996 /*
63997 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63998 diff -urNp linux-2.6.39.2/include/linux/mod_devicetable.h linux-2.6.39.2/include/linux/mod_devicetable.h
63999 --- linux-2.6.39.2/include/linux/mod_devicetable.h 2011-05-19 00:06:34.000000000 -0400
64000 +++ linux-2.6.39.2/include/linux/mod_devicetable.h 2011-05-22 19:36:33.000000000 -0400
64001 @@ -12,7 +12,7 @@
64002 typedef unsigned long kernel_ulong_t;
64003 #endif
64004
64005 -#define PCI_ANY_ID (~0)
64006 +#define PCI_ANY_ID ((__u16)~0)
64007
64008 struct pci_device_id {
64009 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
64010 @@ -131,7 +131,7 @@ struct usb_device_id {
64011 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
64012 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
64013
64014 -#define HID_ANY_ID (~0)
64015 +#define HID_ANY_ID (~0U)
64016
64017 struct hid_device_id {
64018 __u16 bus;
64019 diff -urNp linux-2.6.39.2/include/linux/module.h linux-2.6.39.2/include/linux/module.h
64020 --- linux-2.6.39.2/include/linux/module.h 2011-05-19 00:06:34.000000000 -0400
64021 +++ linux-2.6.39.2/include/linux/module.h 2011-05-22 19:36:33.000000000 -0400
64022 @@ -324,19 +324,16 @@ struct module
64023 int (*init)(void);
64024
64025 /* If this is non-NULL, vfree after init() returns */
64026 - void *module_init;
64027 + void *module_init_rx, *module_init_rw;
64028
64029 /* Here is the actual code + data, vfree'd on unload. */
64030 - void *module_core;
64031 + void *module_core_rx, *module_core_rw;
64032
64033 /* Here are the sizes of the init and core sections */
64034 - unsigned int init_size, core_size;
64035 + unsigned int init_size_rw, core_size_rw;
64036
64037 /* The size of the executable code in each section. */
64038 - unsigned int init_text_size, core_text_size;
64039 -
64040 - /* Size of RO sections of the module (text+rodata) */
64041 - unsigned int init_ro_size, core_ro_size;
64042 + unsigned int init_size_rx, core_size_rx;
64043
64044 /* Arch-specific module values */
64045 struct mod_arch_specific arch;
64046 @@ -441,16 +438,46 @@ bool is_module_address(unsigned long add
64047 bool is_module_percpu_address(unsigned long addr);
64048 bool is_module_text_address(unsigned long addr);
64049
64050 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
64051 +{
64052 +
64053 +#ifdef CONFIG_PAX_KERNEXEC
64054 + if (ktla_ktva(addr) >= (unsigned long)start &&
64055 + ktla_ktva(addr) < (unsigned long)start + size)
64056 + return 1;
64057 +#endif
64058 +
64059 + return ((void *)addr >= start && (void *)addr < start + size);
64060 +}
64061 +
64062 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
64063 +{
64064 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
64065 +}
64066 +
64067 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
64068 +{
64069 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
64070 +}
64071 +
64072 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
64073 +{
64074 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
64075 +}
64076 +
64077 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
64078 +{
64079 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
64080 +}
64081 +
64082 static inline int within_module_core(unsigned long addr, struct module *mod)
64083 {
64084 - return (unsigned long)mod->module_core <= addr &&
64085 - addr < (unsigned long)mod->module_core + mod->core_size;
64086 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
64087 }
64088
64089 static inline int within_module_init(unsigned long addr, struct module *mod)
64090 {
64091 - return (unsigned long)mod->module_init <= addr &&
64092 - addr < (unsigned long)mod->module_init + mod->init_size;
64093 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
64094 }
64095
64096 /* Search for module by name: must hold module_mutex. */
64097 diff -urNp linux-2.6.39.2/include/linux/moduleloader.h linux-2.6.39.2/include/linux/moduleloader.h
64098 --- linux-2.6.39.2/include/linux/moduleloader.h 2011-05-19 00:06:34.000000000 -0400
64099 +++ linux-2.6.39.2/include/linux/moduleloader.h 2011-05-22 19:36:33.000000000 -0400
64100 @@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(st
64101 sections. Returns NULL on failure. */
64102 void *module_alloc(unsigned long size);
64103
64104 +#ifdef CONFIG_PAX_KERNEXEC
64105 +void *module_alloc_exec(unsigned long size);
64106 +#else
64107 +#define module_alloc_exec(x) module_alloc(x)
64108 +#endif
64109 +
64110 /* Free memory returned from module_alloc. */
64111 void module_free(struct module *mod, void *module_region);
64112
64113 +#ifdef CONFIG_PAX_KERNEXEC
64114 +void module_free_exec(struct module *mod, void *module_region);
64115 +#else
64116 +#define module_free_exec(x, y) module_free((x), (y))
64117 +#endif
64118 +
64119 /* Apply the given relocation to the (simplified) ELF. Return -error
64120 or 0. */
64121 int apply_relocate(Elf_Shdr *sechdrs,
64122 diff -urNp linux-2.6.39.2/include/linux/moduleparam.h linux-2.6.39.2/include/linux/moduleparam.h
64123 --- linux-2.6.39.2/include/linux/moduleparam.h 2011-05-19 00:06:34.000000000 -0400
64124 +++ linux-2.6.39.2/include/linux/moduleparam.h 2011-05-22 19:36:33.000000000 -0400
64125 @@ -255,7 +255,7 @@ static inline void __kernel_param_unlock
64126 * @len is usually just sizeof(string).
64127 */
64128 #define module_param_string(name, string, len, perm) \
64129 - static const struct kparam_string __param_string_##name \
64130 + static const struct kparam_string __param_string_##name __used \
64131 = { len, string }; \
64132 __module_param_call(MODULE_PARAM_PREFIX, name, \
64133 &param_ops_string, \
64134 @@ -285,48 +285,48 @@ static inline void destroy_params(const
64135 #define __param_check(name, p, type) \
64136 static inline type *__check_##name(void) { return(p); }
64137
64138 -extern struct kernel_param_ops param_ops_byte;
64139 +extern const struct kernel_param_ops param_ops_byte;
64140 extern int param_set_byte(const char *val, const struct kernel_param *kp);
64141 extern int param_get_byte(char *buffer, const struct kernel_param *kp);
64142 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
64143
64144 -extern struct kernel_param_ops param_ops_short;
64145 +extern const struct kernel_param_ops param_ops_short;
64146 extern int param_set_short(const char *val, const struct kernel_param *kp);
64147 extern int param_get_short(char *buffer, const struct kernel_param *kp);
64148 #define param_check_short(name, p) __param_check(name, p, short)
64149
64150 -extern struct kernel_param_ops param_ops_ushort;
64151 +extern const struct kernel_param_ops param_ops_ushort;
64152 extern int param_set_ushort(const char *val, const struct kernel_param *kp);
64153 extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
64154 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
64155
64156 -extern struct kernel_param_ops param_ops_int;
64157 +extern const struct kernel_param_ops param_ops_int;
64158 extern int param_set_int(const char *val, const struct kernel_param *kp);
64159 extern int param_get_int(char *buffer, const struct kernel_param *kp);
64160 #define param_check_int(name, p) __param_check(name, p, int)
64161
64162 -extern struct kernel_param_ops param_ops_uint;
64163 +extern const struct kernel_param_ops param_ops_uint;
64164 extern int param_set_uint(const char *val, const struct kernel_param *kp);
64165 extern int param_get_uint(char *buffer, const struct kernel_param *kp);
64166 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
64167
64168 -extern struct kernel_param_ops param_ops_long;
64169 +extern const struct kernel_param_ops param_ops_long;
64170 extern int param_set_long(const char *val, const struct kernel_param *kp);
64171 extern int param_get_long(char *buffer, const struct kernel_param *kp);
64172 #define param_check_long(name, p) __param_check(name, p, long)
64173
64174 -extern struct kernel_param_ops param_ops_ulong;
64175 +extern const struct kernel_param_ops param_ops_ulong;
64176 extern int param_set_ulong(const char *val, const struct kernel_param *kp);
64177 extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
64178 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
64179
64180 -extern struct kernel_param_ops param_ops_charp;
64181 +extern const struct kernel_param_ops param_ops_charp;
64182 extern int param_set_charp(const char *val, const struct kernel_param *kp);
64183 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
64184 #define param_check_charp(name, p) __param_check(name, p, char *)
64185
64186 /* For historical reasons "bool" parameters can be (unsigned) "int". */
64187 -extern struct kernel_param_ops param_ops_bool;
64188 +extern const struct kernel_param_ops param_ops_bool;
64189 extern int param_set_bool(const char *val, const struct kernel_param *kp);
64190 extern int param_get_bool(char *buffer, const struct kernel_param *kp);
64191 #define param_check_bool(name, p) \
64192 @@ -337,7 +337,7 @@ extern int param_get_bool(char *buffer,
64193 !__same_type((p), int *)); \
64194 }
64195
64196 -extern struct kernel_param_ops param_ops_invbool;
64197 +extern const struct kernel_param_ops param_ops_invbool;
64198 extern int param_set_invbool(const char *val, const struct kernel_param *kp);
64199 extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
64200 #define param_check_invbool(name, p) __param_check(name, p, bool)
64201 @@ -370,7 +370,7 @@ extern int param_get_invbool(char *buffe
64202 * module_param_named() for why this might be necessary.
64203 */
64204 #define module_param_array_named(name, array, type, nump, perm) \
64205 - static const struct kparam_array __param_arr_##name \
64206 + static const struct kparam_array __param_arr_##name __used \
64207 = { ARRAY_SIZE(array), nump, &param_ops_##type, \
64208 sizeof(array[0]), array }; \
64209 __module_param_call(MODULE_PARAM_PREFIX, name, \
64210 @@ -379,9 +379,9 @@ extern int param_get_invbool(char *buffe
64211 __same_type(array[0], bool), perm); \
64212 __MODULE_PARM_TYPE(name, "array of " #type)
64213
64214 -extern struct kernel_param_ops param_array_ops;
64215 +extern const struct kernel_param_ops param_array_ops;
64216
64217 -extern struct kernel_param_ops param_ops_string;
64218 +extern const struct kernel_param_ops param_ops_string;
64219 extern int param_set_copystring(const char *val, const struct kernel_param *);
64220 extern int param_get_string(char *buffer, const struct kernel_param *kp);
64221
64222 diff -urNp linux-2.6.39.2/include/linux/mutex.h linux-2.6.39.2/include/linux/mutex.h
64223 --- linux-2.6.39.2/include/linux/mutex.h 2011-05-19 00:06:34.000000000 -0400
64224 +++ linux-2.6.39.2/include/linux/mutex.h 2011-05-22 19:36:33.000000000 -0400
64225 @@ -51,7 +51,7 @@ struct mutex {
64226 spinlock_t wait_lock;
64227 struct list_head wait_list;
64228 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
64229 - struct thread_info *owner;
64230 + struct task_struct *owner;
64231 #endif
64232 #ifdef CONFIG_DEBUG_MUTEXES
64233 const char *name;
64234 diff -urNp linux-2.6.39.2/include/linux/namei.h linux-2.6.39.2/include/linux/namei.h
64235 --- linux-2.6.39.2/include/linux/namei.h 2011-05-19 00:06:34.000000000 -0400
64236 +++ linux-2.6.39.2/include/linux/namei.h 2011-05-22 19:36:33.000000000 -0400
64237 @@ -24,7 +24,7 @@ struct nameidata {
64238 unsigned seq;
64239 int last_type;
64240 unsigned depth;
64241 - char *saved_names[MAX_NESTED_LINKS + 1];
64242 + const char *saved_names[MAX_NESTED_LINKS + 1];
64243
64244 /* Intent data */
64245 union {
64246 @@ -91,12 +91,12 @@ extern int follow_up(struct path *);
64247 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
64248 extern void unlock_rename(struct dentry *, struct dentry *);
64249
64250 -static inline void nd_set_link(struct nameidata *nd, char *path)
64251 +static inline void nd_set_link(struct nameidata *nd, const char *path)
64252 {
64253 nd->saved_names[nd->depth] = path;
64254 }
64255
64256 -static inline char *nd_get_link(struct nameidata *nd)
64257 +static inline const char *nd_get_link(const struct nameidata *nd)
64258 {
64259 return nd->saved_names[nd->depth];
64260 }
64261 diff -urNp linux-2.6.39.2/include/linux/netfilter/xt_gradm.h linux-2.6.39.2/include/linux/netfilter/xt_gradm.h
64262 --- linux-2.6.39.2/include/linux/netfilter/xt_gradm.h 1969-12-31 19:00:00.000000000 -0500
64263 +++ linux-2.6.39.2/include/linux/netfilter/xt_gradm.h 2011-05-22 19:41:42.000000000 -0400
64264 @@ -0,0 +1,9 @@
64265 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
64266 +#define _LINUX_NETFILTER_XT_GRADM_H 1
64267 +
64268 +struct xt_gradm_mtinfo {
64269 + __u16 flags;
64270 + __u16 invflags;
64271 +};
64272 +
64273 +#endif
64274 diff -urNp linux-2.6.39.2/include/linux/oprofile.h linux-2.6.39.2/include/linux/oprofile.h
64275 --- linux-2.6.39.2/include/linux/oprofile.h 2011-05-19 00:06:34.000000000 -0400
64276 +++ linux-2.6.39.2/include/linux/oprofile.h 2011-05-22 19:36:33.000000000 -0400
64277 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super
64278 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
64279 char const * name, ulong * val);
64280
64281 -/** Create a file for read-only access to an atomic_t. */
64282 +/** Create a file for read-only access to an atomic_unchecked_t. */
64283 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
64284 - char const * name, atomic_t * val);
64285 + char const * name, atomic_unchecked_t * val);
64286
64287 /** create a directory */
64288 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
64289 diff -urNp linux-2.6.39.2/include/linux/padata.h linux-2.6.39.2/include/linux/padata.h
64290 --- linux-2.6.39.2/include/linux/padata.h 2011-05-19 00:06:34.000000000 -0400
64291 +++ linux-2.6.39.2/include/linux/padata.h 2011-05-22 19:36:33.000000000 -0400
64292 @@ -129,7 +129,7 @@ struct parallel_data {
64293 struct padata_instance *pinst;
64294 struct padata_parallel_queue __percpu *pqueue;
64295 struct padata_serial_queue __percpu *squeue;
64296 - atomic_t seq_nr;
64297 + atomic_unchecked_t seq_nr;
64298 atomic_t reorder_objects;
64299 atomic_t refcnt;
64300 unsigned int max_seq_nr;
64301 diff -urNp linux-2.6.39.2/include/linux/pci.h linux-2.6.39.2/include/linux/pci.h
64302 --- linux-2.6.39.2/include/linux/pci.h 2011-05-19 00:06:34.000000000 -0400
64303 +++ linux-2.6.39.2/include/linux/pci.h 2011-05-22 19:36:33.000000000 -0400
64304 @@ -411,7 +411,7 @@ struct pci_bus {
64305 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
64306 struct list_head resources; /* address space routed to this bus */
64307
64308 - struct pci_ops *ops; /* configuration access functions */
64309 + const struct pci_ops *ops; /* configuration access functions */
64310 void *sysdata; /* hook for sys-specific extension */
64311 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
64312
64313 @@ -550,7 +550,7 @@ struct pci_driver {
64314 int (*resume_early) (struct pci_dev *dev);
64315 int (*resume) (struct pci_dev *dev); /* Device woken up */
64316 void (*shutdown) (struct pci_dev *dev);
64317 - struct pci_error_handlers *err_handler;
64318 + const struct pci_error_handlers *err_handler;
64319 struct device_driver driver;
64320 struct pci_dynids dynids;
64321 };
64322 @@ -639,7 +639,7 @@ void pcibios_scan_specific_bus(int busn)
64323 extern struct pci_bus *pci_find_bus(int domain, int busnr);
64324 void pci_bus_add_devices(const struct pci_bus *bus);
64325 struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
64326 - struct pci_ops *ops, void *sysdata);
64327 + const struct pci_ops *ops, void *sysdata);
64328 static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
64329 void *sysdata)
64330 {
64331 @@ -650,7 +650,7 @@ static inline struct pci_bus * __devinit
64332 return root_bus;
64333 }
64334 struct pci_bus *pci_create_bus(struct device *parent, int bus,
64335 - struct pci_ops *ops, void *sysdata);
64336 + const struct pci_ops *ops, void *sysdata);
64337 struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
64338 int busnr);
64339 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
64340 @@ -727,7 +727,7 @@ int pci_bus_write_config_word(struct pci
64341 int where, u16 val);
64342 int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
64343 int where, u32 val);
64344 -struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
64345 +const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct pci_ops *ops);
64346
64347 static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
64348 {
64349 diff -urNp linux-2.6.39.2/include/linux/perf_event.h linux-2.6.39.2/include/linux/perf_event.h
64350 --- linux-2.6.39.2/include/linux/perf_event.h 2011-05-19 00:06:34.000000000 -0400
64351 +++ linux-2.6.39.2/include/linux/perf_event.h 2011-05-22 19:36:33.000000000 -0400
64352 @@ -759,8 +759,8 @@ struct perf_event {
64353
64354 enum perf_event_active_state state;
64355 unsigned int attach_state;
64356 - local64_t count;
64357 - atomic64_t child_count;
64358 + local64_t count; /* PaX: fix it one day */
64359 + atomic64_unchecked_t child_count;
64360
64361 /*
64362 * These are the total time in nanoseconds that the event
64363 @@ -811,8 +811,8 @@ struct perf_event {
64364 * These accumulate total time (in nanoseconds) that children
64365 * events have been enabled and running, respectively.
64366 */
64367 - atomic64_t child_total_time_enabled;
64368 - atomic64_t child_total_time_running;
64369 + atomic64_unchecked_t child_total_time_enabled;
64370 + atomic64_unchecked_t child_total_time_running;
64371
64372 /*
64373 * Protect attach/detach and child_list:
64374 @@ -1090,9 +1090,9 @@ void perf_event_task_sched_out(struct ta
64375 }
64376
64377 extern void perf_event_mmap(struct vm_area_struct *vma);
64378 -extern struct perf_guest_info_callbacks *perf_guest_cbs;
64379 -extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64380 -extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
64381 +extern const struct perf_guest_info_callbacks *perf_guest_cbs;
64382 +extern int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64383 +extern int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *callbacks);
64384
64385 extern void perf_event_comm(struct task_struct *tsk);
64386 extern void perf_event_fork(struct task_struct *tsk);
64387 diff -urNp linux-2.6.39.2/include/linux/pipe_fs_i.h linux-2.6.39.2/include/linux/pipe_fs_i.h
64388 --- linux-2.6.39.2/include/linux/pipe_fs_i.h 2011-05-19 00:06:34.000000000 -0400
64389 +++ linux-2.6.39.2/include/linux/pipe_fs_i.h 2011-05-22 19:36:33.000000000 -0400
64390 @@ -46,9 +46,9 @@ struct pipe_buffer {
64391 struct pipe_inode_info {
64392 wait_queue_head_t wait;
64393 unsigned int nrbufs, curbuf, buffers;
64394 - unsigned int readers;
64395 - unsigned int writers;
64396 - unsigned int waiting_writers;
64397 + atomic_t readers;
64398 + atomic_t writers;
64399 + atomic_t waiting_writers;
64400 unsigned int r_counter;
64401 unsigned int w_counter;
64402 struct page *tmp_page;
64403 diff -urNp linux-2.6.39.2/include/linux/pm.h linux-2.6.39.2/include/linux/pm.h
64404 --- linux-2.6.39.2/include/linux/pm.h 2011-05-19 00:06:34.000000000 -0400
64405 +++ linux-2.6.39.2/include/linux/pm.h 2011-05-22 19:36:33.000000000 -0400
64406 @@ -268,7 +268,7 @@ const struct dev_pm_ops name = { \
64407 * runtime PM, make the pm member point to generic_subsys_pm_ops.
64408 */
64409 #ifdef CONFIG_PM
64410 -extern struct dev_pm_ops generic_subsys_pm_ops;
64411 +extern const struct dev_pm_ops generic_subsys_pm_ops;
64412 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
64413 #else
64414 #define GENERIC_SUBSYS_PM_OPS NULL
64415 @@ -471,7 +471,7 @@ extern void update_pm_runtime_accounting
64416 * subsystem-level and driver-level callbacks.
64417 */
64418 struct dev_power_domain {
64419 - struct dev_pm_ops ops;
64420 + const struct dev_pm_ops ops;
64421 };
64422
64423 /*
64424 diff -urNp linux-2.6.39.2/include/linux/pm_runtime.h linux-2.6.39.2/include/linux/pm_runtime.h
64425 --- linux-2.6.39.2/include/linux/pm_runtime.h 2011-05-19 00:06:34.000000000 -0400
64426 +++ linux-2.6.39.2/include/linux/pm_runtime.h 2011-05-22 19:36:33.000000000 -0400
64427 @@ -94,7 +94,7 @@ static inline bool pm_runtime_callbacks_
64428
64429 static inline void pm_runtime_mark_last_busy(struct device *dev)
64430 {
64431 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
64432 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
64433 }
64434
64435 #else /* !CONFIG_PM_RUNTIME */
64436 diff -urNp linux-2.6.39.2/include/linux/poison.h linux-2.6.39.2/include/linux/poison.h
64437 --- linux-2.6.39.2/include/linux/poison.h 2011-05-19 00:06:34.000000000 -0400
64438 +++ linux-2.6.39.2/include/linux/poison.h 2011-05-22 19:36:33.000000000 -0400
64439 @@ -19,8 +19,8 @@
64440 * under normal circumstances, used to verify that nobody uses
64441 * non-initialized list entries.
64442 */
64443 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64444 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64445 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64446 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64447
64448 /********** include/linux/timer.h **********/
64449 /*
64450 diff -urNp linux-2.6.39.2/include/linux/posix-timers.h linux-2.6.39.2/include/linux/posix-timers.h
64451 --- linux-2.6.39.2/include/linux/posix-timers.h 2011-05-19 00:06:34.000000000 -0400
64452 +++ linux-2.6.39.2/include/linux/posix-timers.h 2011-05-22 19:36:33.000000000 -0400
64453 @@ -102,10 +102,10 @@ struct k_clock {
64454 struct itimerspec * cur_setting);
64455 };
64456
64457 -extern struct k_clock clock_posix_cpu;
64458 -extern struct k_clock clock_posix_dynamic;
64459 +extern const struct k_clock clock_posix_cpu;
64460 +extern const struct k_clock clock_posix_dynamic;
64461
64462 -void posix_timers_register_clock(const clockid_t clock_id, struct k_clock *new_clock);
64463 +void posix_timers_register_clock(const clockid_t clock_id, const struct k_clock *new_clock);
64464
64465 /* function to call to trigger timer event */
64466 int posix_timer_event(struct k_itimer *timr, int si_private);
64467 diff -urNp linux-2.6.39.2/include/linux/proc_fs.h linux-2.6.39.2/include/linux/proc_fs.h
64468 --- linux-2.6.39.2/include/linux/proc_fs.h 2011-05-19 00:06:34.000000000 -0400
64469 +++ linux-2.6.39.2/include/linux/proc_fs.h 2011-05-22 19:41:42.000000000 -0400
64470 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *pro
64471 return proc_create_data(name, mode, parent, proc_fops, NULL);
64472 }
64473
64474 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
64475 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64476 +{
64477 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64478 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64479 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64480 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64481 +#else
64482 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64483 +#endif
64484 +}
64485 +
64486 +
64487 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64488 mode_t mode, struct proc_dir_entry *base,
64489 read_proc_t *read_proc, void * data)
64490 diff -urNp linux-2.6.39.2/include/linux/ptrace.h linux-2.6.39.2/include/linux/ptrace.h
64491 --- linux-2.6.39.2/include/linux/ptrace.h 2011-05-19 00:06:34.000000000 -0400
64492 +++ linux-2.6.39.2/include/linux/ptrace.h 2011-05-22 19:41:42.000000000 -0400
64493 @@ -115,10 +115,10 @@ extern void __ptrace_unlink(struct task_
64494 extern void exit_ptrace(struct task_struct *tracer);
64495 #define PTRACE_MODE_READ 1
64496 #define PTRACE_MODE_ATTACH 2
64497 -/* Returns 0 on success, -errno on denial. */
64498 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
64499 /* Returns true on success, false on denial. */
64500 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
64501 +/* Returns true on success, false on denial. */
64502 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
64503
64504 static inline int ptrace_reparented(struct task_struct *child)
64505 {
64506 diff -urNp linux-2.6.39.2/include/linux/random.h linux-2.6.39.2/include/linux/random.h
64507 --- linux-2.6.39.2/include/linux/random.h 2011-05-19 00:06:34.000000000 -0400
64508 +++ linux-2.6.39.2/include/linux/random.h 2011-05-22 19:36:33.000000000 -0400
64509 @@ -80,12 +80,17 @@ void srandom32(u32 seed);
64510
64511 u32 prandom32(struct rnd_state *);
64512
64513 +static inline unsigned long pax_get_random_long(void)
64514 +{
64515 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64516 +}
64517 +
64518 /*
64519 * Handle minimum values for seeds
64520 */
64521 static inline u32 __seed(u32 x, u32 m)
64522 {
64523 - return (x < m) ? x + m : x;
64524 + return (x <= m) ? x + m + 1 : x;
64525 }
64526
64527 /**
64528 diff -urNp linux-2.6.39.2/include/linux/reboot.h linux-2.6.39.2/include/linux/reboot.h
64529 --- linux-2.6.39.2/include/linux/reboot.h 2011-05-19 00:06:34.000000000 -0400
64530 +++ linux-2.6.39.2/include/linux/reboot.h 2011-05-22 19:36:33.000000000 -0400
64531 @@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(st
64532 * Architecture-specific implementations of sys_reboot commands.
64533 */
64534
64535 -extern void machine_restart(char *cmd);
64536 -extern void machine_halt(void);
64537 -extern void machine_power_off(void);
64538 +extern void machine_restart(char *cmd) __noreturn;
64539 +extern void machine_halt(void) __noreturn;
64540 +extern void machine_power_off(void) __noreturn;
64541
64542 extern void machine_shutdown(void);
64543 struct pt_regs;
64544 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struc
64545 */
64546
64547 extern void kernel_restart_prepare(char *cmd);
64548 -extern void kernel_restart(char *cmd);
64549 -extern void kernel_halt(void);
64550 -extern void kernel_power_off(void);
64551 +extern void kernel_restart(char *cmd) __noreturn;
64552 +extern void kernel_halt(void) __noreturn;
64553 +extern void kernel_power_off(void) __noreturn;
64554
64555 extern int C_A_D; /* for sysctl */
64556 void ctrl_alt_del(void);
64557 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
64558 * Emergency restart, callable from an interrupt handler.
64559 */
64560
64561 -extern void emergency_restart(void);
64562 +extern void emergency_restart(void) __noreturn;
64563 #include <asm/emergency-restart.h>
64564
64565 #endif
64566 diff -urNp linux-2.6.39.2/include/linux/reiserfs_fs.h linux-2.6.39.2/include/linux/reiserfs_fs.h
64567 --- linux-2.6.39.2/include/linux/reiserfs_fs.h 2011-05-19 00:06:34.000000000 -0400
64568 +++ linux-2.6.39.2/include/linux/reiserfs_fs.h 2011-05-22 19:36:33.000000000 -0400
64569 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset
64570 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64571
64572 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64573 -#define get_generation(s) atomic_read (&fs_generation(s))
64574 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64575 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64576 #define __fs_changed(gen,s) (gen != get_generation (s))
64577 #define fs_changed(gen,s) \
64578 @@ -1618,24 +1618,24 @@ static inline struct super_block *sb_fro
64579 */
64580
64581 struct item_operations {
64582 - int (*bytes_number) (struct item_head * ih, int block_size);
64583 - void (*decrement_key) (struct cpu_key *);
64584 - int (*is_left_mergeable) (struct reiserfs_key * ih,
64585 + int (* const bytes_number) (struct item_head * ih, int block_size);
64586 + void (* const decrement_key) (struct cpu_key *);
64587 + int (* const is_left_mergeable) (struct reiserfs_key * ih,
64588 unsigned long bsize);
64589 - void (*print_item) (struct item_head *, char *item);
64590 - void (*check_item) (struct item_head *, char *item);
64591 + void (* const print_item) (struct item_head *, char *item);
64592 + void (* const check_item) (struct item_head *, char *item);
64593
64594 - int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64595 + int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
64596 int is_affected, int insert_size);
64597 - int (*check_left) (struct virtual_item * vi, int free,
64598 + int (* const check_left) (struct virtual_item * vi, int free,
64599 int start_skip, int end_skip);
64600 - int (*check_right) (struct virtual_item * vi, int free);
64601 - int (*part_size) (struct virtual_item * vi, int from, int to);
64602 - int (*unit_num) (struct virtual_item * vi);
64603 - void (*print_vi) (struct virtual_item * vi);
64604 + int (* const check_right) (struct virtual_item * vi, int free);
64605 + int (* const part_size) (struct virtual_item * vi, int from, int to);
64606 + int (* const unit_num) (struct virtual_item * vi);
64607 + void (* const print_vi) (struct virtual_item * vi);
64608 };
64609
64610 -extern struct item_operations *item_ops[TYPE_ANY + 1];
64611 +extern const struct item_operations * const item_ops[TYPE_ANY + 1];
64612
64613 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
64614 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
64615 diff -urNp linux-2.6.39.2/include/linux/reiserfs_fs_sb.h linux-2.6.39.2/include/linux/reiserfs_fs_sb.h
64616 --- linux-2.6.39.2/include/linux/reiserfs_fs_sb.h 2011-05-19 00:06:34.000000000 -0400
64617 +++ linux-2.6.39.2/include/linux/reiserfs_fs_sb.h 2011-05-22 19:36:33.000000000 -0400
64618 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64619 /* Comment? -Hans */
64620 wait_queue_head_t s_wait;
64621 /* To be obsoleted soon by per buffer seals.. -Hans */
64622 - atomic_t s_generation_counter; // increased by one every time the
64623 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64624 // tree gets re-balanced
64625 unsigned long s_properties; /* File system properties. Currently holds
64626 on-disk FS format */
64627 diff -urNp linux-2.6.39.2/include/linux/rmap.h linux-2.6.39.2/include/linux/rmap.h
64628 --- linux-2.6.39.2/include/linux/rmap.h 2011-05-19 00:06:34.000000000 -0400
64629 +++ linux-2.6.39.2/include/linux/rmap.h 2011-05-22 19:36:33.000000000 -0400
64630 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struc
64631 void anon_vma_init(void); /* create anon_vma_cachep */
64632 int anon_vma_prepare(struct vm_area_struct *);
64633 void unlink_anon_vmas(struct vm_area_struct *);
64634 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64635 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64636 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64637 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64638 void __anon_vma_link(struct vm_area_struct *);
64639
64640 static inline void anon_vma_merge(struct vm_area_struct *vma,
64641 diff -urNp linux-2.6.39.2/include/linux/sched.h linux-2.6.39.2/include/linux/sched.h
64642 --- linux-2.6.39.2/include/linux/sched.h 2011-05-19 00:06:34.000000000 -0400
64643 +++ linux-2.6.39.2/include/linux/sched.h 2011-06-03 23:34:26.000000000 -0400
64644 @@ -100,6 +100,7 @@ struct bio_list;
64645 struct fs_struct;
64646 struct perf_event_context;
64647 struct blk_plug;
64648 +struct linux_binprm;
64649
64650 /*
64651 * List of flags we want to share for kernel threads,
64652 @@ -360,7 +361,7 @@ extern signed long schedule_timeout_inte
64653 extern signed long schedule_timeout_killable(signed long timeout);
64654 extern signed long schedule_timeout_uninterruptible(signed long timeout);
64655 asmlinkage void schedule(void);
64656 -extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
64657 +extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
64658
64659 struct nsproxy;
64660 struct user_namespace;
64661 @@ -381,10 +382,13 @@ struct user_namespace;
64662 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64663
64664 extern int sysctl_max_map_count;
64665 +extern unsigned long sysctl_heap_stack_gap;
64666
64667 #include <linux/aio.h>
64668
64669 #ifdef CONFIG_MMU
64670 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64671 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64672 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64673 extern unsigned long
64674 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64675 @@ -629,6 +633,17 @@ struct signal_struct {
64676 #ifdef CONFIG_TASKSTATS
64677 struct taskstats *stats;
64678 #endif
64679 +
64680 +#ifdef CONFIG_GRKERNSEC
64681 + u32 curr_ip;
64682 + u32 saved_ip;
64683 + u32 gr_saddr;
64684 + u32 gr_daddr;
64685 + u16 gr_sport;
64686 + u16 gr_dport;
64687 + u8 used_accept:1;
64688 +#endif
64689 +
64690 #ifdef CONFIG_AUDIT
64691 unsigned audit_tty;
64692 struct tty_audit_buf *tty_audit_buf;
64693 @@ -701,6 +716,11 @@ struct user_struct {
64694 struct key *session_keyring; /* UID's default session keyring */
64695 #endif
64696
64697 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64698 + unsigned int banned;
64699 + unsigned long ban_expires;
64700 +#endif
64701 +
64702 /* Hash table maintenance information */
64703 struct hlist_node uidhash_node;
64704 uid_t uid;
64705 @@ -1310,8 +1330,8 @@ struct task_struct {
64706 struct list_head thread_group;
64707
64708 struct completion *vfork_done; /* for vfork() */
64709 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64710 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64711 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64712 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64713
64714 cputime_t utime, stime, utimescaled, stimescaled;
64715 cputime_t gtime;
64716 @@ -1327,13 +1347,6 @@ struct task_struct {
64717 struct task_cputime cputime_expires;
64718 struct list_head cpu_timers[3];
64719
64720 -/* process credentials */
64721 - const struct cred __rcu *real_cred; /* objective and real subjective task
64722 - * credentials (COW) */
64723 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64724 - * credentials (COW) */
64725 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64726 -
64727 char comm[TASK_COMM_LEN]; /* executable name excluding path
64728 - access with [gs]et_task_comm (which lock
64729 it with task_lock())
64730 @@ -1350,8 +1363,16 @@ struct task_struct {
64731 #endif
64732 /* CPU-specific state of this task */
64733 struct thread_struct thread;
64734 +/* thread_info moved to task_struct */
64735 +#ifdef CONFIG_X86
64736 + struct thread_info tinfo;
64737 +#endif
64738 /* filesystem information */
64739 struct fs_struct *fs;
64740 +
64741 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64742 + * credentials (COW) */
64743 +
64744 /* open file information */
64745 struct files_struct *files;
64746 /* namespaces */
64747 @@ -1398,6 +1419,11 @@ struct task_struct {
64748 struct rt_mutex_waiter *pi_blocked_on;
64749 #endif
64750
64751 +/* process credentials */
64752 + const struct cred __rcu *real_cred; /* objective and real subjective task
64753 + * credentials (COW) */
64754 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64755 +
64756 #ifdef CONFIG_DEBUG_MUTEXES
64757 /* mutex deadlock detection */
64758 struct mutex_waiter *blocked_on;
64759 @@ -1508,6 +1534,21 @@ struct task_struct {
64760 unsigned long default_timer_slack_ns;
64761
64762 struct list_head *scm_work_list;
64763 +
64764 +#ifdef CONFIG_GRKERNSEC
64765 + /* grsecurity */
64766 + struct dentry *gr_chroot_dentry;
64767 + struct acl_subject_label *acl;
64768 + struct acl_role_label *role;
64769 + struct file *exec_file;
64770 + u16 acl_role_id;
64771 + /* is this the task that authenticated to the special role */
64772 + u8 acl_sp_role;
64773 + u8 is_writable;
64774 + u8 brute;
64775 + u8 gr_is_chrooted;
64776 +#endif
64777 +
64778 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64779 /* Index of current stored address in ret_stack */
64780 int curr_ret_stack;
64781 @@ -1542,6 +1583,57 @@ struct task_struct {
64782 #endif
64783 };
64784
64785 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64786 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64787 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64788 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64789 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64790 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64791 +
64792 +#ifdef CONFIG_PAX_SOFTMODE
64793 +extern unsigned int pax_softmode;
64794 +#endif
64795 +
64796 +extern int pax_check_flags(unsigned long *);
64797 +
64798 +/* if tsk != current then task_lock must be held on it */
64799 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64800 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64801 +{
64802 + if (likely(tsk->mm))
64803 + return tsk->mm->pax_flags;
64804 + else
64805 + return 0UL;
64806 +}
64807 +
64808 +/* if tsk != current then task_lock must be held on it */
64809 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64810 +{
64811 + if (likely(tsk->mm)) {
64812 + tsk->mm->pax_flags = flags;
64813 + return 0;
64814 + }
64815 + return -EINVAL;
64816 +}
64817 +#endif
64818 +
64819 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64820 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64821 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64822 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64823 +#endif
64824 +
64825 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64826 +void pax_report_insns(void *pc, void *sp);
64827 +void pax_report_refcount_overflow(struct pt_regs *regs);
64828 +void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64829 +
64830 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
64831 +extern void pax_track_stack(void);
64832 +#else
64833 +static inline void pax_track_stack(void) {}
64834 +#endif
64835 +
64836 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64837 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64838
64839 @@ -2009,7 +2101,9 @@ void yield(void);
64840 extern struct exec_domain default_exec_domain;
64841
64842 union thread_union {
64843 +#ifndef CONFIG_X86
64844 struct thread_info thread_info;
64845 +#endif
64846 unsigned long stack[THREAD_SIZE/sizeof(long)];
64847 };
64848
64849 @@ -2179,7 +2273,7 @@ extern void __cleanup_sighand(struct sig
64850 extern void exit_itimers(struct signal_struct *);
64851 extern void flush_itimer_signals(void);
64852
64853 -extern NORET_TYPE void do_group_exit(int);
64854 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
64855
64856 extern void daemonize(const char *, ...);
64857 extern int allow_signal(int);
64858 @@ -2320,13 +2414,17 @@ static inline unsigned long *end_of_stac
64859
64860 #endif
64861
64862 -static inline int object_is_on_stack(void *obj)
64863 +static inline int object_starts_on_stack(void *obj)
64864 {
64865 - void *stack = task_stack_page(current);
64866 + const void *stack = task_stack_page(current);
64867
64868 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64869 }
64870
64871 +#ifdef CONFIG_PAX_USERCOPY
64872 +extern int object_is_on_stack(const void *obj, unsigned long len);
64873 +#endif
64874 +
64875 extern void thread_info_cache_init(void);
64876
64877 #ifdef CONFIG_DEBUG_STACK_USAGE
64878 diff -urNp linux-2.6.39.2/include/linux/screen_info.h linux-2.6.39.2/include/linux/screen_info.h
64879 --- linux-2.6.39.2/include/linux/screen_info.h 2011-05-19 00:06:34.000000000 -0400
64880 +++ linux-2.6.39.2/include/linux/screen_info.h 2011-05-22 19:36:33.000000000 -0400
64881 @@ -43,7 +43,8 @@ struct screen_info {
64882 __u16 pages; /* 0x32 */
64883 __u16 vesa_attributes; /* 0x34 */
64884 __u32 capabilities; /* 0x36 */
64885 - __u8 _reserved[6]; /* 0x3a */
64886 + __u16 vesapm_size; /* 0x3a */
64887 + __u8 _reserved[4]; /* 0x3c */
64888 } __attribute__((packed));
64889
64890 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64891 diff -urNp linux-2.6.39.2/include/linux/security.h linux-2.6.39.2/include/linux/security.h
64892 --- linux-2.6.39.2/include/linux/security.h 2011-05-19 00:06:34.000000000 -0400
64893 +++ linux-2.6.39.2/include/linux/security.h 2011-05-22 19:41:42.000000000 -0400
64894 @@ -36,6 +36,7 @@
64895 #include <linux/key.h>
64896 #include <linux/xfrm.h>
64897 #include <linux/slab.h>
64898 +#include <linux/grsecurity.h>
64899 #include <net/flow.h>
64900
64901 /* Maximum number of letters for an LSM name string */
64902 diff -urNp linux-2.6.39.2/include/linux/shm.h linux-2.6.39.2/include/linux/shm.h
64903 --- linux-2.6.39.2/include/linux/shm.h 2011-05-19 00:06:34.000000000 -0400
64904 +++ linux-2.6.39.2/include/linux/shm.h 2011-05-22 19:41:42.000000000 -0400
64905 @@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
64906 pid_t shm_cprid;
64907 pid_t shm_lprid;
64908 struct user_struct *mlock_user;
64909 +#ifdef CONFIG_GRKERNSEC
64910 + time_t shm_createtime;
64911 + pid_t shm_lapid;
64912 +#endif
64913 };
64914
64915 /* shm_mode upper byte flags */
64916 diff -urNp linux-2.6.39.2/include/linux/skbuff.h linux-2.6.39.2/include/linux/skbuff.h
64917 --- linux-2.6.39.2/include/linux/skbuff.h 2011-05-19 00:06:34.000000000 -0400
64918 +++ linux-2.6.39.2/include/linux/skbuff.h 2011-05-22 19:36:33.000000000 -0400
64919 @@ -592,7 +592,7 @@ static inline struct skb_shared_hwtstamp
64920 */
64921 static inline int skb_queue_empty(const struct sk_buff_head *list)
64922 {
64923 - return list->next == (struct sk_buff *)list;
64924 + return list->next == (const struct sk_buff *)list;
64925 }
64926
64927 /**
64928 @@ -605,7 +605,7 @@ static inline int skb_queue_empty(const
64929 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64930 const struct sk_buff *skb)
64931 {
64932 - return skb->next == (struct sk_buff *)list;
64933 + return skb->next == (const struct sk_buff *)list;
64934 }
64935
64936 /**
64937 @@ -618,7 +618,7 @@ static inline bool skb_queue_is_last(con
64938 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64939 const struct sk_buff *skb)
64940 {
64941 - return skb->prev == (struct sk_buff *)list;
64942 + return skb->prev == (const struct sk_buff *)list;
64943 }
64944
64945 /**
64946 @@ -1435,7 +1435,7 @@ static inline int pskb_network_may_pull(
64947 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64948 */
64949 #ifndef NET_SKB_PAD
64950 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64951 +#define NET_SKB_PAD max(_AC(32,U), L1_CACHE_BYTES)
64952 #endif
64953
64954 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64955 diff -urNp linux-2.6.39.2/include/linux/slab_def.h linux-2.6.39.2/include/linux/slab_def.h
64956 --- linux-2.6.39.2/include/linux/slab_def.h 2011-05-19 00:06:34.000000000 -0400
64957 +++ linux-2.6.39.2/include/linux/slab_def.h 2011-05-22 19:36:33.000000000 -0400
64958 @@ -96,10 +96,10 @@ struct kmem_cache {
64959 unsigned long node_allocs;
64960 unsigned long node_frees;
64961 unsigned long node_overflow;
64962 - atomic_t allochit;
64963 - atomic_t allocmiss;
64964 - atomic_t freehit;
64965 - atomic_t freemiss;
64966 + atomic_unchecked_t allochit;
64967 + atomic_unchecked_t allocmiss;
64968 + atomic_unchecked_t freehit;
64969 + atomic_unchecked_t freemiss;
64970
64971 /*
64972 * If debugging is enabled, then the allocator can add additional
64973 diff -urNp linux-2.6.39.2/include/linux/slab.h linux-2.6.39.2/include/linux/slab.h
64974 --- linux-2.6.39.2/include/linux/slab.h 2011-05-19 00:06:34.000000000 -0400
64975 +++ linux-2.6.39.2/include/linux/slab.h 2011-05-23 17:07:00.000000000 -0400
64976 @@ -11,12 +11,20 @@
64977
64978 #include <linux/gfp.h>
64979 #include <linux/types.h>
64980 +#include <linux/err.h>
64981
64982 /*
64983 * Flags to pass to kmem_cache_create().
64984 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64985 */
64986 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64987 +
64988 +#ifdef CONFIG_PAX_USERCOPY
64989 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64990 +#else
64991 +#define SLAB_USERCOPY 0x00000000UL
64992 +#endif
64993 +
64994 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64995 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64996 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64997 @@ -87,10 +95,13 @@
64998 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64999 * Both make kfree a no-op.
65000 */
65001 -#define ZERO_SIZE_PTR ((void *)16)
65002 +#define ZERO_SIZE_PTR \
65003 +({ \
65004 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65005 + (void *)(-MAX_ERRNO-1L); \
65006 +})
65007
65008 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65009 - (unsigned long)ZERO_SIZE_PTR)
65010 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65011
65012 /*
65013 * struct kmem_cache related prototypes
65014 @@ -141,6 +152,7 @@ void * __must_check krealloc(const void
65015 void kfree(const void *);
65016 void kzfree(const void *);
65017 size_t ksize(const void *);
65018 +void check_object_size(const void *ptr, unsigned long n, bool to);
65019
65020 /*
65021 * Allocator specific definitions. These are mainly used to establish optimized
65022 @@ -333,4 +345,59 @@ static inline void *kzalloc_node(size_t
65023
65024 void __init kmem_cache_init_late(void);
65025
65026 +#define kmalloc(x, y) \
65027 +({ \
65028 + void *___retval; \
65029 + intoverflow_t ___x = (intoverflow_t)x; \
65030 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
65031 + ___retval = NULL; \
65032 + else \
65033 + ___retval = kmalloc((size_t)___x, (y)); \
65034 + ___retval; \
65035 +})
65036 +
65037 +#define kmalloc_node(x, y, z) \
65038 +({ \
65039 + void *___retval; \
65040 + intoverflow_t ___x = (intoverflow_t)x; \
65041 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
65042 + ___retval = NULL; \
65043 + else \
65044 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
65045 + ___retval; \
65046 +})
65047 +
65048 +#define kzalloc(x, y) \
65049 +({ \
65050 + void *___retval; \
65051 + intoverflow_t ___x = (intoverflow_t)x; \
65052 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
65053 + ___retval = NULL; \
65054 + else \
65055 + ___retval = kzalloc((size_t)___x, (y)); \
65056 + ___retval; \
65057 +})
65058 +
65059 +#define __krealloc(x, y, z) \
65060 +({ \
65061 + void *___retval; \
65062 + intoverflow_t ___y = (intoverflow_t)y; \
65063 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
65064 + ___retval = NULL; \
65065 + else \
65066 + ___retval = __krealloc((x), (size_t)___y, (z)); \
65067 + ___retval; \
65068 +})
65069 +
65070 +#define krealloc(x, y, z) \
65071 +({ \
65072 + void *___retval; \
65073 + intoverflow_t ___y = (intoverflow_t)y; \
65074 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
65075 + ___retval = NULL; \
65076 + else \
65077 + ___retval = krealloc((x), (size_t)___y, (z)); \
65078 + ___retval; \
65079 +})
65080 +
65081 #endif /* _LINUX_SLAB_H */
65082 diff -urNp linux-2.6.39.2/include/linux/slub_def.h linux-2.6.39.2/include/linux/slub_def.h
65083 --- linux-2.6.39.2/include/linux/slub_def.h 2011-05-19 00:06:34.000000000 -0400
65084 +++ linux-2.6.39.2/include/linux/slub_def.h 2011-05-22 19:36:33.000000000 -0400
65085 @@ -84,7 +84,7 @@ struct kmem_cache {
65086 struct kmem_cache_order_objects max;
65087 struct kmem_cache_order_objects min;
65088 gfp_t allocflags; /* gfp flags to use on each alloc */
65089 - int refcount; /* Refcount for slab cache destroy */
65090 + atomic_t refcount; /* Refcount for slab cache destroy */
65091 void (*ctor)(void *);
65092 int inuse; /* Offset to metadata */
65093 int align; /* Alignment */
65094 diff -urNp linux-2.6.39.2/include/linux/sonet.h linux-2.6.39.2/include/linux/sonet.h
65095 --- linux-2.6.39.2/include/linux/sonet.h 2011-05-19 00:06:34.000000000 -0400
65096 +++ linux-2.6.39.2/include/linux/sonet.h 2011-05-22 19:36:33.000000000 -0400
65097 @@ -61,7 +61,7 @@ struct sonet_stats {
65098 #include <asm/atomic.h>
65099
65100 struct k_sonet_stats {
65101 -#define __HANDLE_ITEM(i) atomic_t i
65102 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
65103 __SONET_ITEMS
65104 #undef __HANDLE_ITEM
65105 };
65106 diff -urNp linux-2.6.39.2/include/linux/ssb/ssb_driver_gige.h linux-2.6.39.2/include/linux/ssb/ssb_driver_gige.h
65107 --- linux-2.6.39.2/include/linux/ssb/ssb_driver_gige.h 2011-05-19 00:06:34.000000000 -0400
65108 +++ linux-2.6.39.2/include/linux/ssb/ssb_driver_gige.h 2011-05-22 19:36:33.000000000 -0400
65109 @@ -44,7 +44,7 @@ struct ssb_gige {
65110
65111 /* The PCI controller device. */
65112 struct pci_controller pci_controller;
65113 - struct pci_ops pci_ops;
65114 + const struct pci_ops pci_ops;
65115 struct resource mem_resource;
65116 struct resource io_resource;
65117 };
65118 diff -urNp linux-2.6.39.2/include/linux/sunrpc/clnt.h linux-2.6.39.2/include/linux/sunrpc/clnt.h
65119 --- linux-2.6.39.2/include/linux/sunrpc/clnt.h 2011-05-19 00:06:34.000000000 -0400
65120 +++ linux-2.6.39.2/include/linux/sunrpc/clnt.h 2011-05-22 19:36:33.000000000 -0400
65121 @@ -169,9 +169,9 @@ static inline unsigned short rpc_get_por
65122 {
65123 switch (sap->sa_family) {
65124 case AF_INET:
65125 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
65126 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
65127 case AF_INET6:
65128 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
65129 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
65130 }
65131 return 0;
65132 }
65133 @@ -204,7 +204,7 @@ static inline bool __rpc_cmp_addr4(const
65134 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
65135 const struct sockaddr *src)
65136 {
65137 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
65138 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
65139 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
65140
65141 dsin->sin_family = ssin->sin_family;
65142 @@ -301,7 +301,7 @@ static inline u32 rpc_get_scope_id(const
65143 if (sa->sa_family != AF_INET6)
65144 return 0;
65145
65146 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
65147 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
65148 }
65149
65150 #endif /* __KERNEL__ */
65151 diff -urNp linux-2.6.39.2/include/linux/sunrpc/svc_rdma.h linux-2.6.39.2/include/linux/sunrpc/svc_rdma.h
65152 --- linux-2.6.39.2/include/linux/sunrpc/svc_rdma.h 2011-05-19 00:06:34.000000000 -0400
65153 +++ linux-2.6.39.2/include/linux/sunrpc/svc_rdma.h 2011-05-22 19:36:33.000000000 -0400
65154 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
65155 extern unsigned int svcrdma_max_requests;
65156 extern unsigned int svcrdma_max_req_size;
65157
65158 -extern atomic_t rdma_stat_recv;
65159 -extern atomic_t rdma_stat_read;
65160 -extern atomic_t rdma_stat_write;
65161 -extern atomic_t rdma_stat_sq_starve;
65162 -extern atomic_t rdma_stat_rq_starve;
65163 -extern atomic_t rdma_stat_rq_poll;
65164 -extern atomic_t rdma_stat_rq_prod;
65165 -extern atomic_t rdma_stat_sq_poll;
65166 -extern atomic_t rdma_stat_sq_prod;
65167 +extern atomic_unchecked_t rdma_stat_recv;
65168 +extern atomic_unchecked_t rdma_stat_read;
65169 +extern atomic_unchecked_t rdma_stat_write;
65170 +extern atomic_unchecked_t rdma_stat_sq_starve;
65171 +extern atomic_unchecked_t rdma_stat_rq_starve;
65172 +extern atomic_unchecked_t rdma_stat_rq_poll;
65173 +extern atomic_unchecked_t rdma_stat_rq_prod;
65174 +extern atomic_unchecked_t rdma_stat_sq_poll;
65175 +extern atomic_unchecked_t rdma_stat_sq_prod;
65176
65177 #define RPCRDMA_VERSION 1
65178
65179 diff -urNp linux-2.6.39.2/include/linux/suspend.h linux-2.6.39.2/include/linux/suspend.h
65180 --- linux-2.6.39.2/include/linux/suspend.h 2011-05-19 00:06:34.000000000 -0400
65181 +++ linux-2.6.39.2/include/linux/suspend.h 2011-05-22 19:36:33.000000000 -0400
65182 @@ -106,15 +106,15 @@ typedef int __bitwise suspend_state_t;
65183 * which require special recovery actions in that situation.
65184 */
65185 struct platform_suspend_ops {
65186 - int (*valid)(suspend_state_t state);
65187 - int (*begin)(suspend_state_t state);
65188 - int (*prepare)(void);
65189 - int (*prepare_late)(void);
65190 - int (*enter)(suspend_state_t state);
65191 - void (*wake)(void);
65192 - void (*finish)(void);
65193 - void (*end)(void);
65194 - void (*recover)(void);
65195 + int (* const valid)(suspend_state_t state);
65196 + int (* const begin)(suspend_state_t state);
65197 + int (* const prepare)(void);
65198 + int (* const prepare_late)(void);
65199 + int (* const enter)(suspend_state_t state);
65200 + void (* const wake)(void);
65201 + void (* const finish)(void);
65202 + void (* const end)(void);
65203 + void (* const recover)(void);
65204 };
65205
65206 #ifdef CONFIG_SUSPEND
65207 @@ -217,16 +217,16 @@ extern void mark_free_pages(struct zone
65208 * platforms which require special recovery actions in that situation.
65209 */
65210 struct platform_hibernation_ops {
65211 - int (*begin)(void);
65212 - void (*end)(void);
65213 - int (*pre_snapshot)(void);
65214 - void (*finish)(void);
65215 - int (*prepare)(void);
65216 - int (*enter)(void);
65217 - void (*leave)(void);
65218 - int (*pre_restore)(void);
65219 - void (*restore_cleanup)(void);
65220 - void (*recover)(void);
65221 + int (* const begin)(void);
65222 + void (* const end)(void);
65223 + int (* const pre_snapshot)(void);
65224 + void (* const finish)(void);
65225 + int (* const prepare)(void);
65226 + int (* const enter)(void);
65227 + void (* const leave)(void);
65228 + int (* const pre_restore)(void);
65229 + void (* const restore_cleanup)(void);
65230 + void (* const recover)(void);
65231 };
65232
65233 #ifdef CONFIG_HIBERNATION
65234 diff -urNp linux-2.6.39.2/include/linux/sysctl.h linux-2.6.39.2/include/linux/sysctl.h
65235 --- linux-2.6.39.2/include/linux/sysctl.h 2011-05-19 00:06:34.000000000 -0400
65236 +++ linux-2.6.39.2/include/linux/sysctl.h 2011-05-22 19:41:42.000000000 -0400
65237 @@ -155,7 +155,11 @@ enum
65238 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
65239 };
65240
65241 -
65242 +#ifdef CONFIG_PAX_SOFTMODE
65243 +enum {
65244 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
65245 +};
65246 +#endif
65247
65248 /* CTL_VM names: */
65249 enum
65250 @@ -967,6 +971,8 @@ typedef int proc_handler (struct ctl_tab
65251
65252 extern int proc_dostring(struct ctl_table *, int,
65253 void __user *, size_t *, loff_t *);
65254 +extern int proc_dostring_modpriv(struct ctl_table *, int,
65255 + void __user *, size_t *, loff_t *);
65256 extern int proc_dointvec(struct ctl_table *, int,
65257 void __user *, size_t *, loff_t *);
65258 extern int proc_dointvec_minmax(struct ctl_table *, int,
65259 diff -urNp linux-2.6.39.2/include/linux/sysfs.h linux-2.6.39.2/include/linux/sysfs.h
65260 --- linux-2.6.39.2/include/linux/sysfs.h 2011-05-19 00:06:34.000000000 -0400
65261 +++ linux-2.6.39.2/include/linux/sysfs.h 2011-05-22 19:36:33.000000000 -0400
65262 @@ -110,8 +110,8 @@ struct bin_attribute {
65263 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
65264
65265 struct sysfs_ops {
65266 - ssize_t (*show)(struct kobject *, struct attribute *,char *);
65267 - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
65268 + ssize_t (* const show)(struct kobject *, struct attribute *,char *);
65269 + ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
65270 };
65271
65272 struct sysfs_dirent;
65273 diff -urNp linux-2.6.39.2/include/linux/tty.h linux-2.6.39.2/include/linux/tty.h
65274 --- linux-2.6.39.2/include/linux/tty.h 2011-05-19 00:06:34.000000000 -0400
65275 +++ linux-2.6.39.2/include/linux/tty.h 2011-05-22 19:36:33.000000000 -0400
65276 @@ -13,6 +13,7 @@
65277 #include <linux/tty_driver.h>
65278 #include <linux/tty_ldisc.h>
65279 #include <linux/mutex.h>
65280 +#include <linux/poll.h>
65281
65282 #include <asm/system.h>
65283
65284 @@ -466,7 +467,6 @@ extern int tty_perform_flush(struct tty_
65285 extern dev_t tty_devnum(struct tty_struct *tty);
65286 extern void proc_clear_tty(struct task_struct *p);
65287 extern struct tty_struct *get_current_tty(void);
65288 -extern void tty_default_fops(struct file_operations *fops);
65289 extern struct tty_struct *alloc_tty_struct(void);
65290 extern int tty_add_file(struct tty_struct *tty, struct file *file);
65291 extern void free_tty_struct(struct tty_struct *tty);
65292 @@ -529,6 +529,18 @@ extern void tty_ldisc_begin(void);
65293 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
65294 extern void tty_ldisc_enable(struct tty_struct *tty);
65295
65296 +/* tty_io.c */
65297 +extern ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
65298 +extern ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
65299 +extern unsigned int tty_poll(struct file *, poll_table *);
65300 +#ifdef CONFIG_COMPAT
65301 +extern long tty_compat_ioctl(struct file *file, unsigned int cmd,
65302 + unsigned long arg);
65303 +#else
65304 +#define tty_compat_ioctl NULL
65305 +#endif
65306 +extern int tty_release(struct inode *, struct file *);
65307 +extern int tty_fasync(int fd, struct file *filp, int on);
65308
65309 /* n_tty.c */
65310 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
65311 diff -urNp linux-2.6.39.2/include/linux/tty_ldisc.h linux-2.6.39.2/include/linux/tty_ldisc.h
65312 --- linux-2.6.39.2/include/linux/tty_ldisc.h 2011-05-19 00:06:34.000000000 -0400
65313 +++ linux-2.6.39.2/include/linux/tty_ldisc.h 2011-05-22 19:36:33.000000000 -0400
65314 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
65315
65316 struct module *owner;
65317
65318 - int refcount;
65319 + atomic_t refcount;
65320 };
65321
65322 struct tty_ldisc {
65323 diff -urNp linux-2.6.39.2/include/linux/types.h linux-2.6.39.2/include/linux/types.h
65324 --- linux-2.6.39.2/include/linux/types.h 2011-05-19 00:06:34.000000000 -0400
65325 +++ linux-2.6.39.2/include/linux/types.h 2011-05-22 19:36:33.000000000 -0400
65326 @@ -213,10 +213,26 @@ typedef struct {
65327 int counter;
65328 } atomic_t;
65329
65330 +#ifdef CONFIG_PAX_REFCOUNT
65331 +typedef struct {
65332 + int counter;
65333 +} atomic_unchecked_t;
65334 +#else
65335 +typedef atomic_t atomic_unchecked_t;
65336 +#endif
65337 +
65338 #ifdef CONFIG_64BIT
65339 typedef struct {
65340 long counter;
65341 } atomic64_t;
65342 +
65343 +#ifdef CONFIG_PAX_REFCOUNT
65344 +typedef struct {
65345 + long counter;
65346 +} atomic64_unchecked_t;
65347 +#else
65348 +typedef atomic64_t atomic64_unchecked_t;
65349 +#endif
65350 #endif
65351
65352 struct list_head {
65353 diff -urNp linux-2.6.39.2/include/linux/uaccess.h linux-2.6.39.2/include/linux/uaccess.h
65354 --- linux-2.6.39.2/include/linux/uaccess.h 2011-05-19 00:06:34.000000000 -0400
65355 +++ linux-2.6.39.2/include/linux/uaccess.h 2011-05-22 19:36:33.000000000 -0400
65356 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
65357 long ret; \
65358 mm_segment_t old_fs = get_fs(); \
65359 \
65360 - set_fs(KERNEL_DS); \
65361 pagefault_disable(); \
65362 + set_fs(KERNEL_DS); \
65363 ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
65364 - pagefault_enable(); \
65365 set_fs(old_fs); \
65366 + pagefault_enable(); \
65367 ret; \
65368 })
65369
65370 @@ -93,8 +93,8 @@ static inline unsigned long __copy_from_
65371 * Safely read from address @src to the buffer at @dst. If a kernel fault
65372 * happens, handle that and return -EFAULT.
65373 */
65374 -extern long probe_kernel_read(void *dst, void *src, size_t size);
65375 -extern long __probe_kernel_read(void *dst, void *src, size_t size);
65376 +extern long probe_kernel_read(void *dst, const void *src, size_t size);
65377 +extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65378
65379 /*
65380 * probe_kernel_write(): safely attempt to write to a location
65381 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *ds
65382 * Safely write to address @dst from the buffer at @src. If a kernel fault
65383 * happens, handle that and return -EFAULT.
65384 */
65385 -extern long notrace probe_kernel_write(void *dst, void *src, size_t size);
65386 -extern long notrace __probe_kernel_write(void *dst, void *src, size_t size);
65387 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65388 +extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65389
65390 #endif /* __LINUX_UACCESS_H__ */
65391 diff -urNp linux-2.6.39.2/include/linux/unaligned/access_ok.h linux-2.6.39.2/include/linux/unaligned/access_ok.h
65392 --- linux-2.6.39.2/include/linux/unaligned/access_ok.h 2011-05-19 00:06:34.000000000 -0400
65393 +++ linux-2.6.39.2/include/linux/unaligned/access_ok.h 2011-05-22 19:36:33.000000000 -0400
65394 @@ -6,32 +6,32 @@
65395
65396 static inline u16 get_unaligned_le16(const void *p)
65397 {
65398 - return le16_to_cpup((__le16 *)p);
65399 + return le16_to_cpup((const __le16 *)p);
65400 }
65401
65402 static inline u32 get_unaligned_le32(const void *p)
65403 {
65404 - return le32_to_cpup((__le32 *)p);
65405 + return le32_to_cpup((const __le32 *)p);
65406 }
65407
65408 static inline u64 get_unaligned_le64(const void *p)
65409 {
65410 - return le64_to_cpup((__le64 *)p);
65411 + return le64_to_cpup((const __le64 *)p);
65412 }
65413
65414 static inline u16 get_unaligned_be16(const void *p)
65415 {
65416 - return be16_to_cpup((__be16 *)p);
65417 + return be16_to_cpup((const __be16 *)p);
65418 }
65419
65420 static inline u32 get_unaligned_be32(const void *p)
65421 {
65422 - return be32_to_cpup((__be32 *)p);
65423 + return be32_to_cpup((const __be32 *)p);
65424 }
65425
65426 static inline u64 get_unaligned_be64(const void *p)
65427 {
65428 - return be64_to_cpup((__be64 *)p);
65429 + return be64_to_cpup((const __be64 *)p);
65430 }
65431
65432 static inline void put_unaligned_le16(u16 val, void *p)
65433 diff -urNp linux-2.6.39.2/include/linux/usb/hcd.h linux-2.6.39.2/include/linux/usb/hcd.h
65434 --- linux-2.6.39.2/include/linux/usb/hcd.h 2011-05-19 00:06:34.000000000 -0400
65435 +++ linux-2.6.39.2/include/linux/usb/hcd.h 2011-05-22 19:36:33.000000000 -0400
65436 @@ -615,7 +615,7 @@ struct usb_mon_operations {
65437 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
65438 };
65439
65440 -extern struct usb_mon_operations *mon_ops;
65441 +extern const struct usb_mon_operations *mon_ops;
65442
65443 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
65444 {
65445 @@ -637,7 +637,7 @@ static inline void usbmon_urb_complete(s
65446 (*mon_ops->urb_complete)(bus, urb, status);
65447 }
65448
65449 -int usb_mon_register(struct usb_mon_operations *ops);
65450 +int usb_mon_register(const struct usb_mon_operations *ops);
65451 void usb_mon_deregister(void);
65452
65453 #else
65454 diff -urNp linux-2.6.39.2/include/linux/usb/intel_mid_otg.h linux-2.6.39.2/include/linux/usb/intel_mid_otg.h
65455 --- linux-2.6.39.2/include/linux/usb/intel_mid_otg.h 2011-05-19 00:06:34.000000000 -0400
65456 +++ linux-2.6.39.2/include/linux/usb/intel_mid_otg.h 2011-05-22 19:36:33.000000000 -0400
65457 @@ -115,7 +115,7 @@ struct intel_mid_otg_xceiv {
65458 void __iomem *base;
65459
65460 /* ops to access ulpi */
65461 - struct iotg_ulpi_access_ops ulpi_ops;
65462 + const struct iotg_ulpi_access_ops ulpi_ops;
65463
65464 /* atomic notifier for interrupt context */
65465 struct atomic_notifier_head iotg_notifier;
65466 diff -urNp linux-2.6.39.2/include/linux/usb/ulpi.h linux-2.6.39.2/include/linux/usb/ulpi.h
65467 --- linux-2.6.39.2/include/linux/usb/ulpi.h 2011-05-19 00:06:34.000000000 -0400
65468 +++ linux-2.6.39.2/include/linux/usb/ulpi.h 2011-05-22 19:36:33.000000000 -0400
65469 @@ -186,7 +186,7 @@ struct otg_transceiver *otg_ulpi_create(
65470
65471 #ifdef CONFIG_USB_ULPI_VIEWPORT
65472 /* access ops for controllers with a viewport register */
65473 -extern struct otg_io_access_ops ulpi_viewport_access_ops;
65474 +extern const struct otg_io_access_ops ulpi_viewport_access_ops;
65475 #endif
65476
65477 #endif /* __LINUX_USB_ULPI_H */
65478 diff -urNp linux-2.6.39.2/include/linux/vga_switcheroo.h linux-2.6.39.2/include/linux/vga_switcheroo.h
65479 --- linux-2.6.39.2/include/linux/vga_switcheroo.h 2011-05-19 00:06:34.000000000 -0400
65480 +++ linux-2.6.39.2/include/linux/vga_switcheroo.h 2011-05-22 19:36:33.000000000 -0400
65481 @@ -39,7 +39,7 @@ int vga_switcheroo_register_client(struc
65482 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
65483 struct fb_info *info);
65484
65485 -int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
65486 +int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
65487 void vga_switcheroo_unregister_handler(void);
65488
65489 int vga_switcheroo_process_delayed_switch(void);
65490 @@ -52,7 +52,7 @@ static inline int vga_switcheroo_registe
65491 void (*reprobe)(struct pci_dev *dev),
65492 bool (*can_switch)(struct pci_dev *dev)) { return 0; }
65493 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
65494 -static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
65495 +static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
65496 static inline void vga_switcheroo_unregister_handler(void) {}
65497 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
65498
65499 diff -urNp linux-2.6.39.2/include/linux/virtio.h linux-2.6.39.2/include/linux/virtio.h
65500 --- linux-2.6.39.2/include/linux/virtio.h 2011-05-19 00:06:34.000000000 -0400
65501 +++ linux-2.6.39.2/include/linux/virtio.h 2011-05-22 19:36:33.000000000 -0400
65502 @@ -102,7 +102,7 @@ struct virtio_device {
65503 int index;
65504 struct device dev;
65505 struct virtio_device_id id;
65506 - struct virtio_config_ops *config;
65507 + const struct virtio_config_ops *config;
65508 struct list_head vqs;
65509 /* Note that this is a Linux set_bit-style bitmap. */
65510 unsigned long features[1];
65511 diff -urNp linux-2.6.39.2/include/linux/vmalloc.h linux-2.6.39.2/include/linux/vmalloc.h
65512 --- linux-2.6.39.2/include/linux/vmalloc.h 2011-05-19 00:06:34.000000000 -0400
65513 +++ linux-2.6.39.2/include/linux/vmalloc.h 2011-05-22 19:36:33.000000000 -0400
65514 @@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
65515 #define VM_MAP 0x00000004 /* vmap()ed pages */
65516 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65517 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65518 +
65519 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65520 +#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
65521 +#endif
65522 +
65523 /* bits [20..32] reserved for arch specific ioremap internals */
65524
65525 /*
65526 @@ -155,4 +160,103 @@ pcpu_free_vm_areas(struct vm_struct **vm
65527 # endif
65528 #endif
65529
65530 +#define vmalloc(x) \
65531 +({ \
65532 + void *___retval; \
65533 + intoverflow_t ___x = (intoverflow_t)x; \
65534 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
65535 + ___retval = NULL; \
65536 + else \
65537 + ___retval = vmalloc((unsigned long)___x); \
65538 + ___retval; \
65539 +})
65540 +
65541 +#define vzalloc(x) \
65542 +({ \
65543 + void *___retval; \
65544 + intoverflow_t ___x = (intoverflow_t)x; \
65545 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
65546 + ___retval = NULL; \
65547 + else \
65548 + ___retval = vzalloc((unsigned long)___x); \
65549 + ___retval; \
65550 +})
65551 +
65552 +#define __vmalloc(x, y, z) \
65553 +({ \
65554 + void *___retval; \
65555 + intoverflow_t ___x = (intoverflow_t)x; \
65556 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
65557 + ___retval = NULL; \
65558 + else \
65559 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
65560 + ___retval; \
65561 +})
65562 +
65563 +#define vmalloc_user(x) \
65564 +({ \
65565 + void *___retval; \
65566 + intoverflow_t ___x = (intoverflow_t)x; \
65567 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
65568 + ___retval = NULL; \
65569 + else \
65570 + ___retval = vmalloc_user((unsigned long)___x); \
65571 + ___retval; \
65572 +})
65573 +
65574 +#define vmalloc_exec(x) \
65575 +({ \
65576 + void *___retval; \
65577 + intoverflow_t ___x = (intoverflow_t)x; \
65578 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
65579 + ___retval = NULL; \
65580 + else \
65581 + ___retval = vmalloc_exec((unsigned long)___x); \
65582 + ___retval; \
65583 +})
65584 +
65585 +#define vmalloc_node(x, y) \
65586 +({ \
65587 + void *___retval; \
65588 + intoverflow_t ___x = (intoverflow_t)x; \
65589 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
65590 + ___retval = NULL; \
65591 + else \
65592 + ___retval = vmalloc_node((unsigned long)___x, (y));\
65593 + ___retval; \
65594 +})
65595 +
65596 +#define vzalloc_node(x, y) \
65597 +({ \
65598 + void *___retval; \
65599 + intoverflow_t ___x = (intoverflow_t)x; \
65600 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
65601 + ___retval = NULL; \
65602 + else \
65603 + ___retval = vzalloc_node((unsigned long)___x, (y));\
65604 + ___retval; \
65605 +})
65606 +
65607 +#define vmalloc_32(x) \
65608 +({ \
65609 + void *___retval; \
65610 + intoverflow_t ___x = (intoverflow_t)x; \
65611 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
65612 + ___retval = NULL; \
65613 + else \
65614 + ___retval = vmalloc_32((unsigned long)___x); \
65615 + ___retval; \
65616 +})
65617 +
65618 +#define vmalloc_32_user(x) \
65619 +({ \
65620 +void *___retval; \
65621 + intoverflow_t ___x = (intoverflow_t)x; \
65622 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
65623 + ___retval = NULL; \
65624 + else \
65625 + ___retval = vmalloc_32_user((unsigned long)___x);\
65626 + ___retval; \
65627 +})
65628 +
65629 #endif /* _LINUX_VMALLOC_H */
65630 diff -urNp linux-2.6.39.2/include/linux/vmstat.h linux-2.6.39.2/include/linux/vmstat.h
65631 --- linux-2.6.39.2/include/linux/vmstat.h 2011-05-19 00:06:34.000000000 -0400
65632 +++ linux-2.6.39.2/include/linux/vmstat.h 2011-05-22 19:36:33.000000000 -0400
65633 @@ -147,18 +147,18 @@ static inline void vm_events_fold_cpu(in
65634 /*
65635 * Zone based page accounting with per cpu differentials.
65636 */
65637 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65638 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65639
65640 static inline void zone_page_state_add(long x, struct zone *zone,
65641 enum zone_stat_item item)
65642 {
65643 - atomic_long_add(x, &zone->vm_stat[item]);
65644 - atomic_long_add(x, &vm_stat[item]);
65645 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65646 + atomic_long_add_unchecked(x, &vm_stat[item]);
65647 }
65648
65649 static inline unsigned long global_page_state(enum zone_stat_item item)
65650 {
65651 - long x = atomic_long_read(&vm_stat[item]);
65652 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65653 #ifdef CONFIG_SMP
65654 if (x < 0)
65655 x = 0;
65656 @@ -169,7 +169,7 @@ static inline unsigned long global_page_
65657 static inline unsigned long zone_page_state(struct zone *zone,
65658 enum zone_stat_item item)
65659 {
65660 - long x = atomic_long_read(&zone->vm_stat[item]);
65661 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65662 #ifdef CONFIG_SMP
65663 if (x < 0)
65664 x = 0;
65665 @@ -186,7 +186,7 @@ static inline unsigned long zone_page_st
65666 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65667 enum zone_stat_item item)
65668 {
65669 - long x = atomic_long_read(&zone->vm_stat[item]);
65670 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65671
65672 #ifdef CONFIG_SMP
65673 int cpu;
65674 @@ -280,8 +280,8 @@ static inline void __mod_zone_page_state
65675
65676 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65677 {
65678 - atomic_long_inc(&zone->vm_stat[item]);
65679 - atomic_long_inc(&vm_stat[item]);
65680 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65681 + atomic_long_inc_unchecked(&vm_stat[item]);
65682 }
65683
65684 static inline void __inc_zone_page_state(struct page *page,
65685 @@ -292,8 +292,8 @@ static inline void __inc_zone_page_state
65686
65687 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65688 {
65689 - atomic_long_dec(&zone->vm_stat[item]);
65690 - atomic_long_dec(&vm_stat[item]);
65691 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65692 + atomic_long_dec_unchecked(&vm_stat[item]);
65693 }
65694
65695 static inline void __dec_zone_page_state(struct page *page,
65696 diff -urNp linux-2.6.39.2/include/media/saa7146_vv.h linux-2.6.39.2/include/media/saa7146_vv.h
65697 --- linux-2.6.39.2/include/media/saa7146_vv.h 2011-05-19 00:06:34.000000000 -0400
65698 +++ linux-2.6.39.2/include/media/saa7146_vv.h 2011-05-22 19:36:33.000000000 -0400
65699 @@ -202,13 +202,13 @@ void saa7146_set_gpio(struct saa7146_dev
65700
65701 /* from saa7146_video.c */
65702 extern const struct v4l2_ioctl_ops saa7146_video_ioctl_ops;
65703 -extern struct saa7146_use_ops saa7146_video_uops;
65704 +extern const struct saa7146_use_ops saa7146_video_uops;
65705 int saa7146_start_preview(struct saa7146_fh *fh);
65706 int saa7146_stop_preview(struct saa7146_fh *fh);
65707 long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg);
65708
65709 /* from saa7146_vbi.c */
65710 -extern struct saa7146_use_ops saa7146_vbi_uops;
65711 +extern const struct saa7146_use_ops saa7146_vbi_uops;
65712
65713 /* resource management functions */
65714 int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit);
65715 diff -urNp linux-2.6.39.2/include/media/v4l2-device.h linux-2.6.39.2/include/media/v4l2-device.h
65716 --- linux-2.6.39.2/include/media/v4l2-device.h 2011-05-19 00:06:34.000000000 -0400
65717 +++ linux-2.6.39.2/include/media/v4l2-device.h 2011-05-22 19:36:33.000000000 -0400
65718 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(st
65719 this function returns 0. If the name ends with a digit (e.g. cx18),
65720 then the name will be set to cx18-0 since cx180 looks really odd. */
65721 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
65722 - atomic_t *instance);
65723 + atomic_unchecked_t *instance);
65724
65725 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
65726 Since the parent disappears this ensures that v4l2_dev doesn't have an
65727 diff -urNp linux-2.6.39.2/include/net/caif/cfctrl.h linux-2.6.39.2/include/net/caif/cfctrl.h
65728 --- linux-2.6.39.2/include/net/caif/cfctrl.h 2011-05-19 00:06:34.000000000 -0400
65729 +++ linux-2.6.39.2/include/net/caif/cfctrl.h 2011-05-22 19:36:33.000000000 -0400
65730 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65731 struct cfctrl {
65732 struct cfsrvl serv;
65733 struct cfctrl_rsp res;
65734 - atomic_t req_seq_no;
65735 - atomic_t rsp_seq_no;
65736 + atomic_unchecked_t req_seq_no;
65737 + atomic_unchecked_t rsp_seq_no;
65738 struct list_head list;
65739 /* Protects from simultaneous access to first_req list */
65740 spinlock_t info_list_lock;
65741 diff -urNp linux-2.6.39.2/include/net/flow.h linux-2.6.39.2/include/net/flow.h
65742 --- linux-2.6.39.2/include/net/flow.h 2011-05-19 00:06:34.000000000 -0400
65743 +++ linux-2.6.39.2/include/net/flow.h 2011-05-22 19:36:33.000000000 -0400
65744 @@ -167,6 +167,6 @@ extern struct flow_cache_object *flow_ca
65745 u8 dir, flow_resolve_t resolver, void *ctx);
65746
65747 extern void flow_cache_flush(void);
65748 -extern atomic_t flow_cache_genid;
65749 +extern atomic_unchecked_t flow_cache_genid;
65750
65751 #endif
65752 diff -urNp linux-2.6.39.2/include/net/inetpeer.h linux-2.6.39.2/include/net/inetpeer.h
65753 --- linux-2.6.39.2/include/net/inetpeer.h 2011-05-19 00:06:34.000000000 -0400
65754 +++ linux-2.6.39.2/include/net/inetpeer.h 2011-05-22 19:36:33.000000000 -0400
65755 @@ -43,8 +43,8 @@ struct inet_peer {
65756 */
65757 union {
65758 struct {
65759 - atomic_t rid; /* Frag reception counter */
65760 - atomic_t ip_id_count; /* IP ID for the next packet */
65761 + atomic_unchecked_t rid; /* Frag reception counter */
65762 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65763 __u32 tcp_ts;
65764 __u32 tcp_ts_stamp;
65765 u32 metrics[RTAX_MAX];
65766 @@ -108,7 +108,7 @@ static inline __u16 inet_getid(struct in
65767 {
65768 more++;
65769 inet_peer_refcheck(p);
65770 - return atomic_add_return(more, &p->ip_id_count) - more;
65771 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
65772 }
65773
65774 #endif /* _NET_INETPEER_H */
65775 diff -urNp linux-2.6.39.2/include/net/ip_fib.h linux-2.6.39.2/include/net/ip_fib.h
65776 --- linux-2.6.39.2/include/net/ip_fib.h 2011-05-19 00:06:34.000000000 -0400
65777 +++ linux-2.6.39.2/include/net/ip_fib.h 2011-05-22 19:36:33.000000000 -0400
65778 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(s
65779
65780 #define FIB_RES_SADDR(net, res) \
65781 ((FIB_RES_NH(res).nh_saddr_genid == \
65782 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65783 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65784 FIB_RES_NH(res).nh_saddr : \
65785 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65786 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65787 diff -urNp linux-2.6.39.2/include/net/ip_vs.h linux-2.6.39.2/include/net/ip_vs.h
65788 --- linux-2.6.39.2/include/net/ip_vs.h 2011-05-19 00:06:34.000000000 -0400
65789 +++ linux-2.6.39.2/include/net/ip_vs.h 2011-05-22 19:36:33.000000000 -0400
65790 @@ -512,7 +512,7 @@ struct ip_vs_conn {
65791 struct ip_vs_conn *control; /* Master control connection */
65792 atomic_t n_control; /* Number of controlled ones */
65793 struct ip_vs_dest *dest; /* real server */
65794 - atomic_t in_pkts; /* incoming packet counter */
65795 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65796
65797 /* packet transmitter for different forwarding methods. If it
65798 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65799 @@ -650,7 +650,7 @@ struct ip_vs_dest {
65800 __be16 port; /* port number of the server */
65801 union nf_inet_addr addr; /* IP address of the server */
65802 volatile unsigned flags; /* dest status flags */
65803 - atomic_t conn_flags; /* flags to copy to conn */
65804 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65805 atomic_t weight; /* server weight */
65806
65807 atomic_t refcnt; /* reference counter */
65808 diff -urNp linux-2.6.39.2/include/net/irda/ircomm_tty.h linux-2.6.39.2/include/net/irda/ircomm_tty.h
65809 --- linux-2.6.39.2/include/net/irda/ircomm_tty.h 2011-05-19 00:06:34.000000000 -0400
65810 +++ linux-2.6.39.2/include/net/irda/ircomm_tty.h 2011-05-22 19:36:33.000000000 -0400
65811 @@ -35,6 +35,7 @@
65812 #include <linux/termios.h>
65813 #include <linux/timer.h>
65814 #include <linux/tty.h> /* struct tty_struct */
65815 +#include <asm/local.h>
65816
65817 #include <net/irda/irias_object.h>
65818 #include <net/irda/ircomm_core.h>
65819 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65820 unsigned short close_delay;
65821 unsigned short closing_wait; /* time to wait before closing */
65822
65823 - int open_count;
65824 - int blocked_open; /* # of blocked opens */
65825 + local_t open_count;
65826 + local_t blocked_open; /* # of blocked opens */
65827
65828 /* Protect concurent access to :
65829 * o self->open_count
65830 diff -urNp linux-2.6.39.2/include/net/iucv/af_iucv.h linux-2.6.39.2/include/net/iucv/af_iucv.h
65831 --- linux-2.6.39.2/include/net/iucv/af_iucv.h 2011-05-19 00:06:34.000000000 -0400
65832 +++ linux-2.6.39.2/include/net/iucv/af_iucv.h 2011-05-22 19:36:33.000000000 -0400
65833 @@ -87,7 +87,7 @@ struct iucv_sock {
65834 struct iucv_sock_list {
65835 struct hlist_head head;
65836 rwlock_t lock;
65837 - atomic_t autobind_name;
65838 + atomic_unchecked_t autobind_name;
65839 };
65840
65841 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65842 diff -urNp linux-2.6.39.2/include/net/neighbour.h linux-2.6.39.2/include/net/neighbour.h
65843 --- linux-2.6.39.2/include/net/neighbour.h 2011-05-19 00:06:34.000000000 -0400
65844 +++ linux-2.6.39.2/include/net/neighbour.h 2011-05-22 19:36:33.000000000 -0400
65845 @@ -118,12 +118,12 @@ struct neighbour {
65846
65847 struct neigh_ops {
65848 int family;
65849 - void (*solicit)(struct neighbour *, struct sk_buff*);
65850 - void (*error_report)(struct neighbour *, struct sk_buff*);
65851 - int (*output)(struct sk_buff*);
65852 - int (*connected_output)(struct sk_buff*);
65853 - int (*hh_output)(struct sk_buff*);
65854 - int (*queue_xmit)(struct sk_buff*);
65855 + void (* const solicit)(struct neighbour *, struct sk_buff*);
65856 + void (* const error_report)(struct neighbour *, struct sk_buff*);
65857 + int (* const output)(struct sk_buff*);
65858 + int (* const connected_output)(struct sk_buff*);
65859 + int (* const hh_output)(struct sk_buff*);
65860 + int (* const queue_xmit)(struct sk_buff*);
65861 };
65862
65863 struct pneigh_entry {
65864 diff -urNp linux-2.6.39.2/include/net/netfilter/nf_conntrack_ecache.h linux-2.6.39.2/include/net/netfilter/nf_conntrack_ecache.h
65865 --- linux-2.6.39.2/include/net/netfilter/nf_conntrack_ecache.h 2011-05-19 00:06:34.000000000 -0400
65866 +++ linux-2.6.39.2/include/net/netfilter/nf_conntrack_ecache.h 2011-05-22 19:36:33.000000000 -0400
65867 @@ -95,7 +95,7 @@ nf_conntrack_eventmask_report(unsigned i
65868 int report)
65869 {
65870 int ret = 0;
65871 - struct nf_ct_event_notifier *notify;
65872 + const struct nf_ct_event_notifier *notify;
65873 struct nf_conntrack_ecache *e;
65874
65875 rcu_read_lock();
65876 @@ -174,7 +174,7 @@ nf_ct_expect_event_report(enum ip_conntr
65877 u32 pid,
65878 int report)
65879 {
65880 - struct nf_exp_event_notifier *notify;
65881 + const struct nf_exp_event_notifier *notify;
65882 struct nf_conntrack_ecache *e;
65883
65884 rcu_read_lock();
65885 diff -urNp linux-2.6.39.2/include/net/netlink.h linux-2.6.39.2/include/net/netlink.h
65886 --- linux-2.6.39.2/include/net/netlink.h 2011-05-19 00:06:34.000000000 -0400
65887 +++ linux-2.6.39.2/include/net/netlink.h 2011-05-22 19:36:33.000000000 -0400
65888 @@ -562,7 +562,7 @@ static inline void *nlmsg_get_pos(struct
65889 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65890 {
65891 if (mark)
65892 - skb_trim(skb, (unsigned char *) mark - skb->data);
65893 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65894 }
65895
65896 /**
65897 diff -urNp linux-2.6.39.2/include/net/netns/ipv4.h linux-2.6.39.2/include/net/netns/ipv4.h
65898 --- linux-2.6.39.2/include/net/netns/ipv4.h 2011-05-19 00:06:34.000000000 -0400
65899 +++ linux-2.6.39.2/include/net/netns/ipv4.h 2011-05-22 19:36:33.000000000 -0400
65900 @@ -54,8 +54,8 @@ struct netns_ipv4 {
65901 int sysctl_rt_cache_rebuild_count;
65902 int current_rt_cache_rebuild_count;
65903
65904 - atomic_t rt_genid;
65905 - atomic_t dev_addr_genid;
65906 + atomic_unchecked_t rt_genid;
65907 + atomic_unchecked_t dev_addr_genid;
65908
65909 #ifdef CONFIG_IP_MROUTE
65910 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65911 diff -urNp linux-2.6.39.2/include/net/sctp/sctp.h linux-2.6.39.2/include/net/sctp/sctp.h
65912 --- linux-2.6.39.2/include/net/sctp/sctp.h 2011-05-19 00:06:34.000000000 -0400
65913 +++ linux-2.6.39.2/include/net/sctp/sctp.h 2011-05-22 19:36:33.000000000 -0400
65914 @@ -316,9 +316,9 @@ do { \
65915
65916 #else /* SCTP_DEBUG */
65917
65918 -#define SCTP_DEBUG_PRINTK(whatever...)
65919 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65920 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65921 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65922 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65923 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65924 #define SCTP_ENABLE_DEBUG
65925 #define SCTP_DISABLE_DEBUG
65926 #define SCTP_ASSERT(expr, str, func)
65927 diff -urNp linux-2.6.39.2/include/net/sock.h linux-2.6.39.2/include/net/sock.h
65928 --- linux-2.6.39.2/include/net/sock.h 2011-05-19 00:06:34.000000000 -0400
65929 +++ linux-2.6.39.2/include/net/sock.h 2011-05-22 19:36:33.000000000 -0400
65930 @@ -277,7 +277,7 @@ struct sock {
65931 #ifdef CONFIG_RPS
65932 __u32 sk_rxhash;
65933 #endif
65934 - atomic_t sk_drops;
65935 + atomic_unchecked_t sk_drops;
65936 int sk_rcvbuf;
65937
65938 struct sk_filter __rcu *sk_filter;
65939 diff -urNp linux-2.6.39.2/include/net/tcp.h linux-2.6.39.2/include/net/tcp.h
65940 --- linux-2.6.39.2/include/net/tcp.h 2011-05-19 00:06:34.000000000 -0400
65941 +++ linux-2.6.39.2/include/net/tcp.h 2011-05-22 19:36:33.000000000 -0400
65942 @@ -1374,7 +1374,7 @@ enum tcp_seq_states {
65943 struct tcp_seq_afinfo {
65944 char *name;
65945 sa_family_t family;
65946 - struct file_operations seq_fops;
65947 + struct file_operations seq_fops; /* cannot be const */
65948 struct seq_operations seq_ops;
65949 };
65950
65951 diff -urNp linux-2.6.39.2/include/net/udp.h linux-2.6.39.2/include/net/udp.h
65952 --- linux-2.6.39.2/include/net/udp.h 2011-05-19 00:06:34.000000000 -0400
65953 +++ linux-2.6.39.2/include/net/udp.h 2011-05-22 19:36:33.000000000 -0400
65954 @@ -234,7 +234,7 @@ struct udp_seq_afinfo {
65955 char *name;
65956 sa_family_t family;
65957 struct udp_table *udp_table;
65958 - struct file_operations seq_fops;
65959 + struct file_operations seq_fops; /* cannot be const */
65960 struct seq_operations seq_ops;
65961 };
65962
65963 diff -urNp linux-2.6.39.2/include/net/xfrm.h linux-2.6.39.2/include/net/xfrm.h
65964 --- linux-2.6.39.2/include/net/xfrm.h 2011-05-19 00:06:34.000000000 -0400
65965 +++ linux-2.6.39.2/include/net/xfrm.h 2011-05-22 19:36:33.000000000 -0400
65966 @@ -505,7 +505,7 @@ struct xfrm_policy {
65967 struct timer_list timer;
65968
65969 struct flow_cache_object flo;
65970 - atomic_t genid;
65971 + atomic_unchecked_t genid;
65972 u32 priority;
65973 u32 index;
65974 struct xfrm_mark mark;
65975 diff -urNp linux-2.6.39.2/include/pcmcia/ss.h linux-2.6.39.2/include/pcmcia/ss.h
65976 --- linux-2.6.39.2/include/pcmcia/ss.h 2011-05-19 00:06:34.000000000 -0400
65977 +++ linux-2.6.39.2/include/pcmcia/ss.h 2011-05-22 19:36:33.000000000 -0400
65978 @@ -241,9 +241,9 @@ struct pcmcia_socket {
65979 * "select PCCARD_NONSTATIC" in Kconfig.
65980 *
65981 */
65982 -extern struct pccard_resource_ops pccard_static_ops;
65983 +extern const struct pccard_resource_ops pccard_static_ops;
65984 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
65985 -extern struct pccard_resource_ops pccard_iodyn_ops;
65986 +extern const struct pccard_resource_ops pccard_iodyn_ops;
65987 extern struct pccard_resource_ops pccard_nonstatic_ops;
65988 #else
65989 /* If PCMCIA is not used, but only CARDBUS, these functions are not used
65990 diff -urNp linux-2.6.39.2/include/rdma/ib_verbs.h linux-2.6.39.2/include/rdma/ib_verbs.h
65991 --- linux-2.6.39.2/include/rdma/ib_verbs.h 2011-05-19 00:06:34.000000000 -0400
65992 +++ linux-2.6.39.2/include/rdma/ib_verbs.h 2011-05-22 19:36:33.000000000 -0400
65993 @@ -1149,7 +1149,7 @@ struct ib_device {
65994 struct ib_mad *in_mad,
65995 struct ib_mad *out_mad);
65996
65997 - struct ib_dma_mapping_ops *dma_ops;
65998 + const struct ib_dma_mapping_ops *dma_ops;
65999
66000 struct module *owner;
66001 struct device dev;
66002 diff -urNp linux-2.6.39.2/include/scsi/libfc.h linux-2.6.39.2/include/scsi/libfc.h
66003 --- linux-2.6.39.2/include/scsi/libfc.h 2011-05-19 00:06:34.000000000 -0400
66004 +++ linux-2.6.39.2/include/scsi/libfc.h 2011-05-22 19:36:33.000000000 -0400
66005 @@ -202,7 +202,7 @@ struct fc_rport_priv {
66006 struct mutex rp_mutex;
66007 struct delayed_work retry_work;
66008 enum fc_rport_event event;
66009 - struct fc_rport_operations *ops;
66010 + const struct fc_rport_operations *ops;
66011 struct list_head peers;
66012 struct work_struct event_work;
66013 u32 supported_classes;
66014 diff -urNp linux-2.6.39.2/include/scsi/scsi_device.h linux-2.6.39.2/include/scsi/scsi_device.h
66015 --- linux-2.6.39.2/include/scsi/scsi_device.h 2011-05-19 00:06:34.000000000 -0400
66016 +++ linux-2.6.39.2/include/scsi/scsi_device.h 2011-05-22 19:36:33.000000000 -0400
66017 @@ -161,9 +161,9 @@ struct scsi_device {
66018 unsigned int max_device_blocked; /* what device_blocked counts down from */
66019 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
66020
66021 - atomic_t iorequest_cnt;
66022 - atomic_t iodone_cnt;
66023 - atomic_t ioerr_cnt;
66024 + atomic_unchecked_t iorequest_cnt;
66025 + atomic_unchecked_t iodone_cnt;
66026 + atomic_unchecked_t ioerr_cnt;
66027
66028 struct device sdev_gendev,
66029 sdev_dev;
66030 diff -urNp linux-2.6.39.2/include/sound/ac97_codec.h linux-2.6.39.2/include/sound/ac97_codec.h
66031 --- linux-2.6.39.2/include/sound/ac97_codec.h 2011-05-19 00:06:34.000000000 -0400
66032 +++ linux-2.6.39.2/include/sound/ac97_codec.h 2011-05-22 19:36:33.000000000 -0400
66033 @@ -424,15 +424,15 @@
66034 struct snd_ac97;
66035
66036 struct snd_ac97_build_ops {
66037 - int (*build_3d) (struct snd_ac97 *ac97);
66038 - int (*build_specific) (struct snd_ac97 *ac97);
66039 - int (*build_spdif) (struct snd_ac97 *ac97);
66040 - int (*build_post_spdif) (struct snd_ac97 *ac97);
66041 + int (* const build_3d) (struct snd_ac97 *ac97);
66042 + int (* const build_specific) (struct snd_ac97 *ac97);
66043 + int (* const build_spdif) (struct snd_ac97 *ac97);
66044 + int (* const build_post_spdif) (struct snd_ac97 *ac97);
66045 #ifdef CONFIG_PM
66046 - void (*suspend) (struct snd_ac97 *ac97);
66047 - void (*resume) (struct snd_ac97 *ac97);
66048 + void (* const suspend) (struct snd_ac97 *ac97);
66049 + void (* const resume) (struct snd_ac97 *ac97);
66050 #endif
66051 - void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
66052 + void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
66053 };
66054
66055 struct snd_ac97_bus_ops {
66056 @@ -446,7 +446,7 @@ struct snd_ac97_bus_ops {
66057
66058 struct snd_ac97_bus {
66059 /* -- lowlevel (hardware) driver specific -- */
66060 - struct snd_ac97_bus_ops *ops;
66061 + const struct snd_ac97_bus_ops *ops;
66062 void *private_data;
66063 void (*private_free) (struct snd_ac97_bus *bus);
66064 /* --- */
66065 @@ -556,7 +556,7 @@ static inline int ac97_can_spdif(struct
66066
66067 /* functions */
66068 /* create new AC97 bus */
66069 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
66070 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
66071 void *private_data, struct snd_ac97_bus **rbus);
66072 /* create mixer controls */
66073 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
66074 diff -urNp linux-2.6.39.2/include/sound/core.h linux-2.6.39.2/include/sound/core.h
66075 --- linux-2.6.39.2/include/sound/core.h 2011-05-19 00:06:34.000000000 -0400
66076 +++ linux-2.6.39.2/include/sound/core.h 2011-05-22 19:36:33.000000000 -0400
66077 @@ -88,7 +88,7 @@ struct snd_device {
66078 snd_device_state_t state; /* state of the device */
66079 snd_device_type_t type; /* device type */
66080 void *device_data; /* device structure */
66081 - struct snd_device_ops *ops; /* operations */
66082 + const struct snd_device_ops *ops; /* operations */
66083 };
66084
66085 #define snd_device(n) list_entry(n, struct snd_device, list)
66086 @@ -301,7 +301,7 @@ int snd_card_file_remove(struct snd_card
66087 /* device.c */
66088
66089 int snd_device_new(struct snd_card *card, snd_device_type_t type,
66090 - void *device_data, struct snd_device_ops *ops);
66091 + void *device_data, const struct snd_device_ops *ops);
66092 int snd_device_register(struct snd_card *card, void *device_data);
66093 int snd_device_register_all(struct snd_card *card);
66094 int snd_device_disconnect(struct snd_card *card, void *device_data);
66095 diff -urNp linux-2.6.39.2/include/sound/pcm.h linux-2.6.39.2/include/sound/pcm.h
66096 --- linux-2.6.39.2/include/sound/pcm.h 2011-05-19 00:06:34.000000000 -0400
66097 +++ linux-2.6.39.2/include/sound/pcm.h 2011-05-22 19:36:33.000000000 -0400
66098 @@ -379,7 +379,7 @@ struct snd_pcm_substream {
66099 unsigned int dma_buf_id;
66100 size_t dma_max;
66101 /* -- hardware operations -- */
66102 - struct snd_pcm_ops *ops;
66103 + const struct snd_pcm_ops *ops;
66104 /* -- runtime information -- */
66105 struct snd_pcm_runtime *runtime;
66106 /* -- timer section -- */
66107 @@ -845,7 +845,7 @@ const unsigned char *snd_pcm_format_sile
66108 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
66109 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
66110
66111 -void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
66112 +void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, const struct snd_pcm_ops *ops);
66113 void snd_pcm_set_sync(struct snd_pcm_substream *substream);
66114 int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
66115 int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
66116 diff -urNp linux-2.6.39.2/include/sound/rawmidi.h linux-2.6.39.2/include/sound/rawmidi.h
66117 --- linux-2.6.39.2/include/sound/rawmidi.h 2011-05-19 00:06:34.000000000 -0400
66118 +++ linux-2.6.39.2/include/sound/rawmidi.h 2011-05-22 19:36:33.000000000 -0400
66119 @@ -100,7 +100,7 @@ struct snd_rawmidi_substream {
66120 struct snd_rawmidi_runtime *runtime;
66121 struct pid *pid;
66122 /* hardware layer */
66123 - struct snd_rawmidi_ops *ops;
66124 + const struct snd_rawmidi_ops *ops;
66125 };
66126
66127 struct snd_rawmidi_file {
66128 @@ -127,7 +127,7 @@ struct snd_rawmidi {
66129 int ossreg;
66130 #endif
66131
66132 - struct snd_rawmidi_global_ops *ops;
66133 + const struct snd_rawmidi_global_ops *ops;
66134
66135 struct snd_rawmidi_str streams[2];
66136
66137 @@ -151,7 +151,7 @@ int snd_rawmidi_new(struct snd_card *car
66138 int output_count, int input_count,
66139 struct snd_rawmidi **rmidi);
66140 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
66141 - struct snd_rawmidi_ops *ops);
66142 + const struct snd_rawmidi_ops *ops);
66143
66144 /* callbacks */
66145
66146 diff -urNp linux-2.6.39.2/include/sound/seq_device.h linux-2.6.39.2/include/sound/seq_device.h
66147 --- linux-2.6.39.2/include/sound/seq_device.h 2011-05-19 00:06:34.000000000 -0400
66148 +++ linux-2.6.39.2/include/sound/seq_device.h 2011-05-22 19:36:33.000000000 -0400
66149 @@ -69,7 +69,7 @@ struct snd_seq_dev_ops {
66150 */
66151 void snd_seq_device_load_drivers(void);
66152 int snd_seq_device_new(struct snd_card *card, int device, char *id, int argsize, struct snd_seq_device **result);
66153 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry, int argsize);
66154 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry, int argsize);
66155 int snd_seq_device_unregister_driver(char *id);
66156
66157 #define SNDRV_SEQ_DEVICE_ARGPTR(dev) (void *)((char *)(dev) + sizeof(struct snd_seq_device))
66158 diff -urNp linux-2.6.39.2/include/sound/snd_wavefront.h linux-2.6.39.2/include/sound/snd_wavefront.h
66159 --- linux-2.6.39.2/include/sound/snd_wavefront.h 2011-05-19 00:06:34.000000000 -0400
66160 +++ linux-2.6.39.2/include/sound/snd_wavefront.h 2011-05-22 19:36:33.000000000 -0400
66161 @@ -37,8 +37,8 @@ struct _snd_wavefront_midi {
66162 #define MPU_ACK 0xFE
66163 #define UART_MODE_ON 0x3F
66164
66165 -extern struct snd_rawmidi_ops snd_wavefront_midi_output;
66166 -extern struct snd_rawmidi_ops snd_wavefront_midi_input;
66167 +extern const struct snd_rawmidi_ops snd_wavefront_midi_output;
66168 +extern const struct snd_rawmidi_ops snd_wavefront_midi_input;
66169
66170 extern void snd_wavefront_midi_enable_virtual (snd_wavefront_card_t *);
66171 extern void snd_wavefront_midi_disable_virtual (snd_wavefront_card_t *);
66172 diff -urNp linux-2.6.39.2/include/sound/soc.h linux-2.6.39.2/include/sound/soc.h
66173 --- linux-2.6.39.2/include/sound/soc.h 2011-05-19 00:06:34.000000000 -0400
66174 +++ linux-2.6.39.2/include/sound/soc.h 2011-05-22 19:36:33.000000000 -0400
66175 @@ -245,7 +245,7 @@ struct snd_soc_jack_gpio;
66176
66177 typedef int (*hw_write_t)(void *,const char* ,int);
66178
66179 -extern struct snd_ac97_bus_ops soc_ac97_ops;
66180 +extern const struct snd_ac97_bus_ops soc_ac97_ops;
66181
66182 enum snd_soc_control_type {
66183 SND_SOC_CUSTOM,
66184 diff -urNp linux-2.6.39.2/include/sound/ymfpci.h linux-2.6.39.2/include/sound/ymfpci.h
66185 --- linux-2.6.39.2/include/sound/ymfpci.h 2011-05-19 00:06:34.000000000 -0400
66186 +++ linux-2.6.39.2/include/sound/ymfpci.h 2011-05-22 19:36:33.000000000 -0400
66187 @@ -358,7 +358,7 @@ struct snd_ymfpci {
66188 spinlock_t reg_lock;
66189 spinlock_t voice_lock;
66190 wait_queue_head_t interrupt_sleep;
66191 - atomic_t interrupt_sleep_count;
66192 + atomic_unchecked_t interrupt_sleep_count;
66193 struct snd_info_entry *proc_entry;
66194 const struct firmware *dsp_microcode;
66195 const struct firmware *controller_microcode;
66196 diff -urNp linux-2.6.39.2/include/target/target_core_base.h linux-2.6.39.2/include/target/target_core_base.h
66197 --- linux-2.6.39.2/include/target/target_core_base.h 2011-06-03 00:04:14.000000000 -0400
66198 +++ linux-2.6.39.2/include/target/target_core_base.h 2011-06-03 00:32:08.000000000 -0400
66199 @@ -432,8 +432,8 @@ struct se_transport_task {
66200 atomic_t t_task_cdbs_left;
66201 atomic_t t_task_cdbs_ex_left;
66202 atomic_t t_task_cdbs_timeout_left;
66203 - atomic_t t_task_cdbs_sent;
66204 - atomic_t t_transport_aborted;
66205 + atomic_unchecked_t t_task_cdbs_sent;
66206 + atomic_unchecked_t t_transport_aborted;
66207 atomic_t t_transport_active;
66208 atomic_t t_transport_complete;
66209 atomic_t t_transport_queue_active;
66210 @@ -774,7 +774,7 @@ struct se_device {
66211 atomic_t active_cmds;
66212 atomic_t simple_cmds;
66213 atomic_t depth_left;
66214 - atomic_t dev_ordered_id;
66215 + atomic_unchecked_t dev_ordered_id;
66216 atomic_t dev_tur_active;
66217 atomic_t execute_tasks;
66218 atomic_t dev_status_thr_count;
66219 diff -urNp linux-2.6.39.2/include/trace/events/irq.h linux-2.6.39.2/include/trace/events/irq.h
66220 --- linux-2.6.39.2/include/trace/events/irq.h 2011-05-19 00:06:34.000000000 -0400
66221 +++ linux-2.6.39.2/include/trace/events/irq.h 2011-05-22 19:36:33.000000000 -0400
66222 @@ -36,7 +36,7 @@ struct softirq_action;
66223 */
66224 TRACE_EVENT(irq_handler_entry,
66225
66226 - TP_PROTO(int irq, struct irqaction *action),
66227 + TP_PROTO(int irq, const struct irqaction *action),
66228
66229 TP_ARGS(irq, action),
66230
66231 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
66232 */
66233 TRACE_EVENT(irq_handler_exit,
66234
66235 - TP_PROTO(int irq, struct irqaction *action, int ret),
66236 + TP_PROTO(int irq, const struct irqaction *action, int ret),
66237
66238 TP_ARGS(irq, action, ret),
66239
66240 diff -urNp linux-2.6.39.2/include/video/udlfb.h linux-2.6.39.2/include/video/udlfb.h
66241 --- linux-2.6.39.2/include/video/udlfb.h 2011-05-19 00:06:34.000000000 -0400
66242 +++ linux-2.6.39.2/include/video/udlfb.h 2011-05-22 19:36:33.000000000 -0400
66243 @@ -51,10 +51,10 @@ struct dlfb_data {
66244 int base8;
66245 u32 pseudo_palette[256];
66246 /* blit-only rendering path metrics, exposed through sysfs */
66247 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66248 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66249 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66250 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66251 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66252 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66253 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66254 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66255 };
66256
66257 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66258 diff -urNp linux-2.6.39.2/include/video/uvesafb.h linux-2.6.39.2/include/video/uvesafb.h
66259 --- linux-2.6.39.2/include/video/uvesafb.h 2011-05-19 00:06:34.000000000 -0400
66260 +++ linux-2.6.39.2/include/video/uvesafb.h 2011-05-22 19:36:33.000000000 -0400
66261 @@ -177,6 +177,7 @@ struct uvesafb_par {
66262 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66263 u8 pmi_setpal; /* PMI for palette changes */
66264 u16 *pmi_base; /* protected mode interface location */
66265 + u8 *pmi_code; /* protected mode code location */
66266 void *pmi_start;
66267 void *pmi_pal;
66268 u8 *vbe_state_orig; /*
66269 diff -urNp linux-2.6.39.2/init/do_mounts.c linux-2.6.39.2/init/do_mounts.c
66270 --- linux-2.6.39.2/init/do_mounts.c 2011-05-19 00:06:34.000000000 -0400
66271 +++ linux-2.6.39.2/init/do_mounts.c 2011-05-22 19:36:33.000000000 -0400
66272 @@ -287,7 +287,7 @@ static void __init get_fs_names(char *pa
66273
66274 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66275 {
66276 - int err = sys_mount(name, "/root", fs, flags, data);
66277 + int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
66278 if (err)
66279 return err;
66280
66281 @@ -383,18 +383,18 @@ void __init change_floppy(char *fmt, ...
66282 va_start(args, fmt);
66283 vsprintf(buf, fmt, args);
66284 va_end(args);
66285 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66286 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66287 if (fd >= 0) {
66288 sys_ioctl(fd, FDEJECT, 0);
66289 sys_close(fd);
66290 }
66291 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66292 - fd = sys_open("/dev/console", O_RDWR, 0);
66293 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66294 if (fd >= 0) {
66295 sys_ioctl(fd, TCGETS, (long)&termios);
66296 termios.c_lflag &= ~ICANON;
66297 sys_ioctl(fd, TCSETSF, (long)&termios);
66298 - sys_read(fd, &c, 1);
66299 + sys_read(fd, (char __user *)&c, 1);
66300 termios.c_lflag |= ICANON;
66301 sys_ioctl(fd, TCSETSF, (long)&termios);
66302 sys_close(fd);
66303 @@ -488,6 +488,6 @@ void __init prepare_namespace(void)
66304 mount_root();
66305 out:
66306 devtmpfs_mount("dev");
66307 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66308 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66309 sys_chroot((const char __user __force *)".");
66310 }
66311 diff -urNp linux-2.6.39.2/init/do_mounts.h linux-2.6.39.2/init/do_mounts.h
66312 --- linux-2.6.39.2/init/do_mounts.h 2011-05-19 00:06:34.000000000 -0400
66313 +++ linux-2.6.39.2/init/do_mounts.h 2011-05-22 19:36:33.000000000 -0400
66314 @@ -15,15 +15,15 @@ extern int root_mountflags;
66315
66316 static inline int create_dev(char *name, dev_t dev)
66317 {
66318 - sys_unlink(name);
66319 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66320 + sys_unlink((__force char __user *)name);
66321 + return sys_mknod((__force char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
66322 }
66323
66324 #if BITS_PER_LONG == 32
66325 static inline u32 bstat(char *name)
66326 {
66327 struct stat64 stat;
66328 - if (sys_stat64(name, &stat) != 0)
66329 + if (sys_stat64((__force char __user *)name, (__force struct stat64 __user *)&stat) != 0)
66330 return 0;
66331 if (!S_ISBLK(stat.st_mode))
66332 return 0;
66333 diff -urNp linux-2.6.39.2/init/do_mounts_initrd.c linux-2.6.39.2/init/do_mounts_initrd.c
66334 --- linux-2.6.39.2/init/do_mounts_initrd.c 2011-05-19 00:06:34.000000000 -0400
66335 +++ linux-2.6.39.2/init/do_mounts_initrd.c 2011-05-22 19:36:33.000000000 -0400
66336 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
66337 create_dev("/dev/root.old", Root_RAM0);
66338 /* mount initrd on rootfs' /root */
66339 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66340 - sys_mkdir("/old", 0700);
66341 - root_fd = sys_open("/", 0, 0);
66342 - old_fd = sys_open("/old", 0, 0);
66343 + sys_mkdir((__force const char __user *)"/old", 0700);
66344 + root_fd = sys_open((__force const char __user *)"/", 0, 0);
66345 + old_fd = sys_open((__force const char __user *)"/old", 0, 0);
66346 /* move initrd over / and chdir/chroot in initrd root */
66347 - sys_chdir("/root");
66348 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66349 - sys_chroot(".");
66350 + sys_chdir((__force const char __user *)"/root");
66351 + sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
66352 + sys_chroot((__force const char __user *)".");
66353
66354 /*
66355 * In case that a resume from disk is carried out by linuxrc or one of
66356 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
66357
66358 /* move initrd to rootfs' /old */
66359 sys_fchdir(old_fd);
66360 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66361 + sys_mount((__force char __user *)"/", (__force char __user *)".", NULL, MS_MOVE, NULL);
66362 /* switch root and cwd back to / of rootfs */
66363 sys_fchdir(root_fd);
66364 - sys_chroot(".");
66365 + sys_chroot((__force const char __user *)".");
66366 sys_close(old_fd);
66367 sys_close(root_fd);
66368
66369 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66370 - sys_chdir("/old");
66371 + sys_chdir((__force const char __user *)"/old");
66372 return;
66373 }
66374
66375 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
66376 mount_root();
66377
66378 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66379 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66380 + error = sys_mount((__force char __user *)"/old", (__force char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
66381 if (!error)
66382 printk("okay\n");
66383 else {
66384 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66385 + int fd = sys_open((__force const char __user *)"/dev/root.old", O_RDWR, 0);
66386 if (error == -ENOENT)
66387 printk("/initrd does not exist. Ignored.\n");
66388 else
66389 printk("failed\n");
66390 printk(KERN_NOTICE "Unmounting old root\n");
66391 - sys_umount("/old", MNT_DETACH);
66392 + sys_umount((__force char __user *)"/old", MNT_DETACH);
66393 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66394 if (fd < 0) {
66395 error = fd;
66396 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66397 * mounted in the normal path.
66398 */
66399 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66400 - sys_unlink("/initrd.image");
66401 + sys_unlink((__force const char __user *)"/initrd.image");
66402 handle_initrd();
66403 return 1;
66404 }
66405 }
66406 - sys_unlink("/initrd.image");
66407 + sys_unlink((__force const char __user *)"/initrd.image");
66408 return 0;
66409 }
66410 diff -urNp linux-2.6.39.2/init/do_mounts_md.c linux-2.6.39.2/init/do_mounts_md.c
66411 --- linux-2.6.39.2/init/do_mounts_md.c 2011-05-19 00:06:34.000000000 -0400
66412 +++ linux-2.6.39.2/init/do_mounts_md.c 2011-05-22 19:36:33.000000000 -0400
66413 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66414 partitioned ? "_d" : "", minor,
66415 md_setup_args[ent].device_names);
66416
66417 - fd = sys_open(name, 0, 0);
66418 + fd = sys_open((__force char __user *)name, 0, 0);
66419 if (fd < 0) {
66420 printk(KERN_ERR "md: open failed - cannot start "
66421 "array %s\n", name);
66422 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66423 * array without it
66424 */
66425 sys_close(fd);
66426 - fd = sys_open(name, 0, 0);
66427 + fd = sys_open((__force char __user *)name, 0, 0);
66428 sys_ioctl(fd, BLKRRPART, 0);
66429 }
66430 sys_close(fd);
66431 diff -urNp linux-2.6.39.2/init/initramfs.c linux-2.6.39.2/init/initramfs.c
66432 --- linux-2.6.39.2/init/initramfs.c 2011-05-19 00:06:34.000000000 -0400
66433 +++ linux-2.6.39.2/init/initramfs.c 2011-05-22 19:36:33.000000000 -0400
66434 @@ -74,7 +74,7 @@ static void __init free_hash(void)
66435 }
66436 }
66437
66438 -static long __init do_utime(char __user *filename, time_t mtime)
66439 +static long __init do_utime(__force char __user *filename, time_t mtime)
66440 {
66441 struct timespec t[2];
66442
66443 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
66444 struct dir_entry *de, *tmp;
66445 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66446 list_del(&de->list);
66447 - do_utime(de->name, de->mtime);
66448 + do_utime((__force char __user *)de->name, de->mtime);
66449 kfree(de->name);
66450 kfree(de);
66451 }
66452 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
66453 if (nlink >= 2) {
66454 char *old = find_link(major, minor, ino, mode, collected);
66455 if (old)
66456 - return (sys_link(old, collected) < 0) ? -1 : 1;
66457 + return (sys_link((__force char __user *)old, (__force char __user *)collected) < 0) ? -1 : 1;
66458 }
66459 return 0;
66460 }
66461 @@ -280,11 +280,11 @@ static void __init clean_path(char *path
66462 {
66463 struct stat st;
66464
66465 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66466 + if (!sys_newlstat((__force char __user *)path, (__force struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
66467 if (S_ISDIR(st.st_mode))
66468 - sys_rmdir(path);
66469 + sys_rmdir((__force char __user *)path);
66470 else
66471 - sys_unlink(path);
66472 + sys_unlink((__force char __user *)path);
66473 }
66474 }
66475
66476 @@ -305,7 +305,7 @@ static int __init do_name(void)
66477 int openflags = O_WRONLY|O_CREAT;
66478 if (ml != 1)
66479 openflags |= O_TRUNC;
66480 - wfd = sys_open(collected, openflags, mode);
66481 + wfd = sys_open((__force char __user *)collected, openflags, mode);
66482
66483 if (wfd >= 0) {
66484 sys_fchown(wfd, uid, gid);
66485 @@ -317,17 +317,17 @@ static int __init do_name(void)
66486 }
66487 }
66488 } else if (S_ISDIR(mode)) {
66489 - sys_mkdir(collected, mode);
66490 - sys_chown(collected, uid, gid);
66491 - sys_chmod(collected, mode);
66492 + sys_mkdir((__force char __user *)collected, mode);
66493 + sys_chown((__force char __user *)collected, uid, gid);
66494 + sys_chmod((__force char __user *)collected, mode);
66495 dir_add(collected, mtime);
66496 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66497 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66498 if (maybe_link() == 0) {
66499 - sys_mknod(collected, mode, rdev);
66500 - sys_chown(collected, uid, gid);
66501 - sys_chmod(collected, mode);
66502 - do_utime(collected, mtime);
66503 + sys_mknod((__force char __user *)collected, mode, rdev);
66504 + sys_chown((__force char __user *)collected, uid, gid);
66505 + sys_chmod((__force char __user *)collected, mode);
66506 + do_utime((__force char __user *)collected, mtime);
66507 }
66508 }
66509 return 0;
66510 @@ -336,15 +336,15 @@ static int __init do_name(void)
66511 static int __init do_copy(void)
66512 {
66513 if (count >= body_len) {
66514 - sys_write(wfd, victim, body_len);
66515 + sys_write(wfd, (__force char __user *)victim, body_len);
66516 sys_close(wfd);
66517 - do_utime(vcollected, mtime);
66518 + do_utime((__force char __user *)vcollected, mtime);
66519 kfree(vcollected);
66520 eat(body_len);
66521 state = SkipIt;
66522 return 0;
66523 } else {
66524 - sys_write(wfd, victim, count);
66525 + sys_write(wfd, (__force char __user *)victim, count);
66526 body_len -= count;
66527 eat(count);
66528 return 1;
66529 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
66530 {
66531 collected[N_ALIGN(name_len) + body_len] = '\0';
66532 clean_path(collected, 0);
66533 - sys_symlink(collected + N_ALIGN(name_len), collected);
66534 - sys_lchown(collected, uid, gid);
66535 - do_utime(collected, mtime);
66536 + sys_symlink((__force char __user *)collected + N_ALIGN(name_len), (__force char __user *)collected);
66537 + sys_lchown((__force char __user *)collected, uid, gid);
66538 + do_utime((__force char __user *)collected, mtime);
66539 state = SkipIt;
66540 next_state = Reset;
66541 return 0;
66542 diff -urNp linux-2.6.39.2/init/Kconfig linux-2.6.39.2/init/Kconfig
66543 --- linux-2.6.39.2/init/Kconfig 2011-05-19 00:06:34.000000000 -0400
66544 +++ linux-2.6.39.2/init/Kconfig 2011-05-22 19:36:33.000000000 -0400
66545 @@ -1202,7 +1202,7 @@ config SLUB_DEBUG
66546
66547 config COMPAT_BRK
66548 bool "Disable heap randomization"
66549 - default y
66550 + default n
66551 help
66552 Randomizing heap placement makes heap exploits harder, but it
66553 also breaks ancient binaries (including anything libc5 based).
66554 diff -urNp linux-2.6.39.2/init/main.c linux-2.6.39.2/init/main.c
66555 --- linux-2.6.39.2/init/main.c 2011-06-03 00:04:14.000000000 -0400
66556 +++ linux-2.6.39.2/init/main.c 2011-06-03 00:32:08.000000000 -0400
66557 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void)
66558 extern void tc_init(void);
66559 #endif
66560
66561 +extern void grsecurity_init(void);
66562 +
66563 /*
66564 * Debug helper: via this flag we know that we are in 'early bootup code'
66565 * where only the boot processor is running with IRQ disabled. This means
66566 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char
66567
66568 __setup("reset_devices", set_reset_devices);
66569
66570 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66571 +extern char pax_enter_kernel_user[];
66572 +extern char pax_exit_kernel_user[];
66573 +extern pgdval_t clone_pgd_mask;
66574 +#endif
66575 +
66576 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66577 +static int __init setup_pax_nouderef(char *str)
66578 +{
66579 +#ifdef CONFIG_X86_32
66580 + unsigned int cpu;
66581 + struct desc_struct *gdt;
66582 +
66583 + for (cpu = 0; cpu < NR_CPUS; cpu++) {
66584 + gdt = get_cpu_gdt_table(cpu);
66585 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66586 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66587 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66588 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66589 + }
66590 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66591 +#else
66592 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66593 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66594 + clone_pgd_mask = ~(pgdval_t)0UL;
66595 +#endif
66596 +
66597 + return 0;
66598 +}
66599 +early_param("pax_nouderef", setup_pax_nouderef);
66600 +#endif
66601 +
66602 +#ifdef CONFIG_PAX_SOFTMODE
66603 +unsigned int pax_softmode;
66604 +
66605 +static int __init setup_pax_softmode(char *str)
66606 +{
66607 + get_option(&str, &pax_softmode);
66608 + return 1;
66609 +}
66610 +__setup("pax_softmode=", setup_pax_softmode);
66611 +#endif
66612 +
66613 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66614 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66615 static const char *panic_later, *panic_param;
66616 @@ -663,6 +708,7 @@ int __init_or_module do_one_initcall(ini
66617 {
66618 int count = preempt_count();
66619 int ret;
66620 + const char *msg1 = "", *msg2 = "";
66621
66622 if (initcall_debug)
66623 ret = do_one_initcall_debug(fn);
66624 @@ -675,15 +721,15 @@ int __init_or_module do_one_initcall(ini
66625 sprintf(msgbuf, "error code %d ", ret);
66626
66627 if (preempt_count() != count) {
66628 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66629 + msg1 = " preemption imbalance";
66630 preempt_count() = count;
66631 }
66632 if (irqs_disabled()) {
66633 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66634 + msg2 = " disabled interrupts";
66635 local_irq_enable();
66636 }
66637 - if (msgbuf[0]) {
66638 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66639 + if (msgbuf[0] || *msg1 || *msg2) {
66640 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66641 }
66642
66643 return ret;
66644 @@ -801,7 +847,7 @@ static int __init kernel_init(void * unu
66645 do_basic_setup();
66646
66647 /* Open the /dev/console on the rootfs, this should never fail */
66648 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66649 + if (sys_open((__force const char __user *) "/dev/console", O_RDWR, 0) < 0)
66650 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66651
66652 (void) sys_dup(0);
66653 @@ -814,11 +860,13 @@ static int __init kernel_init(void * unu
66654 if (!ramdisk_execute_command)
66655 ramdisk_execute_command = "/init";
66656
66657 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66658 + if (sys_access((__force const char __user *) ramdisk_execute_command, 0) != 0) {
66659 ramdisk_execute_command = NULL;
66660 prepare_namespace();
66661 }
66662
66663 + grsecurity_init();
66664 +
66665 /*
66666 * Ok, we have completed the initial bootup, and
66667 * we're essentially up and running. Get rid of the
66668 diff -urNp linux-2.6.39.2/ipc/mqueue.c linux-2.6.39.2/ipc/mqueue.c
66669 --- linux-2.6.39.2/ipc/mqueue.c 2011-05-19 00:06:34.000000000 -0400
66670 +++ linux-2.6.39.2/ipc/mqueue.c 2011-05-22 19:41:42.000000000 -0400
66671 @@ -154,6 +154,7 @@ static struct inode *mqueue_get_inode(st
66672 mq_bytes = (mq_msg_tblsz +
66673 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66674
66675 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66676 spin_lock(&mq_lock);
66677 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66678 u->mq_bytes + mq_bytes >
66679 diff -urNp linux-2.6.39.2/ipc/sem.c linux-2.6.39.2/ipc/sem.c
66680 --- linux-2.6.39.2/ipc/sem.c 2011-05-19 00:06:34.000000000 -0400
66681 +++ linux-2.6.39.2/ipc/sem.c 2011-05-22 19:36:33.000000000 -0400
66682 @@ -854,6 +854,8 @@ static int semctl_main(struct ipc_namesp
66683 int nsems;
66684 struct list_head tasks;
66685
66686 + pax_track_stack();
66687 +
66688 sma = sem_lock_check(ns, semid);
66689 if (IS_ERR(sma))
66690 return PTR_ERR(sma);
66691 @@ -1301,6 +1303,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid,
66692 struct ipc_namespace *ns;
66693 struct list_head tasks;
66694
66695 + pax_track_stack();
66696 +
66697 ns = current->nsproxy->ipc_ns;
66698
66699 if (nsops < 1 || semid < 0)
66700 diff -urNp linux-2.6.39.2/ipc/shm.c linux-2.6.39.2/ipc/shm.c
66701 --- linux-2.6.39.2/ipc/shm.c 2011-05-19 00:06:34.000000000 -0400
66702 +++ linux-2.6.39.2/ipc/shm.c 2011-05-22 19:41:42.000000000 -0400
66703 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_name
66704 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66705 #endif
66706
66707 +#ifdef CONFIG_GRKERNSEC
66708 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66709 + const time_t shm_createtime, const uid_t cuid,
66710 + const int shmid);
66711 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66712 + const time_t shm_createtime);
66713 +#endif
66714 +
66715 void shm_init_ns(struct ipc_namespace *ns)
66716 {
66717 ns->shm_ctlmax = SHMMAX;
66718 @@ -401,6 +409,14 @@ static int newseg(struct ipc_namespace *
66719 shp->shm_lprid = 0;
66720 shp->shm_atim = shp->shm_dtim = 0;
66721 shp->shm_ctim = get_seconds();
66722 +#ifdef CONFIG_GRKERNSEC
66723 + {
66724 + struct timespec timeval;
66725 + do_posix_clock_monotonic_gettime(&timeval);
66726 +
66727 + shp->shm_createtime = timeval.tv_sec;
66728 + }
66729 +#endif
66730 shp->shm_segsz = size;
66731 shp->shm_nattch = 0;
66732 shp->shm_file = file;
66733 @@ -762,8 +778,6 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int,
66734 case SHM_LOCK:
66735 case SHM_UNLOCK:
66736 {
66737 - struct file *uninitialized_var(shm_file);
66738 -
66739 lru_add_drain_all(); /* drain pagevecs to lru lists */
66740
66741 shp = shm_lock_check(ns, shmid);
66742 @@ -896,9 +910,21 @@ long do_shmat(int shmid, char __user *sh
66743 if (err)
66744 goto out_unlock;
66745
66746 +#ifdef CONFIG_GRKERNSEC
66747 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66748 + shp->shm_perm.cuid, shmid) ||
66749 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66750 + err = -EACCES;
66751 + goto out_unlock;
66752 + }
66753 +#endif
66754 +
66755 path = shp->shm_file->f_path;
66756 path_get(&path);
66757 shp->shm_nattch++;
66758 +#ifdef CONFIG_GRKERNSEC
66759 + shp->shm_lapid = current->pid;
66760 +#endif
66761 size = i_size_read(path.dentry->d_inode);
66762 shm_unlock(shp);
66763
66764 diff -urNp linux-2.6.39.2/kernel/acct.c linux-2.6.39.2/kernel/acct.c
66765 --- linux-2.6.39.2/kernel/acct.c 2011-05-19 00:06:34.000000000 -0400
66766 +++ linux-2.6.39.2/kernel/acct.c 2011-05-22 19:36:33.000000000 -0400
66767 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_a
66768 */
66769 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66770 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66771 - file->f_op->write(file, (char *)&ac,
66772 + file->f_op->write(file, (__force char __user *)&ac,
66773 sizeof(acct_t), &file->f_pos);
66774 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66775 set_fs(fs);
66776 diff -urNp linux-2.6.39.2/kernel/audit.c linux-2.6.39.2/kernel/audit.c
66777 --- linux-2.6.39.2/kernel/audit.c 2011-05-19 00:06:34.000000000 -0400
66778 +++ linux-2.6.39.2/kernel/audit.c 2011-05-22 19:36:33.000000000 -0400
66779 @@ -112,7 +112,7 @@ u32 audit_sig_sid = 0;
66780 3) suppressed due to audit_rate_limit
66781 4) suppressed due to audit_backlog_limit
66782 */
66783 -static atomic_t audit_lost = ATOMIC_INIT(0);
66784 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66785
66786 /* The netlink socket. */
66787 static struct sock *audit_sock;
66788 @@ -234,7 +234,7 @@ void audit_log_lost(const char *message)
66789 unsigned long now;
66790 int print;
66791
66792 - atomic_inc(&audit_lost);
66793 + atomic_inc_unchecked(&audit_lost);
66794
66795 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66796
66797 @@ -253,7 +253,7 @@ void audit_log_lost(const char *message)
66798 printk(KERN_WARNING
66799 "audit: audit_lost=%d audit_rate_limit=%d "
66800 "audit_backlog_limit=%d\n",
66801 - atomic_read(&audit_lost),
66802 + atomic_read_unchecked(&audit_lost),
66803 audit_rate_limit,
66804 audit_backlog_limit);
66805 audit_panic(message);
66806 @@ -686,7 +686,7 @@ static int audit_receive_msg(struct sk_b
66807 status_set.pid = audit_pid;
66808 status_set.rate_limit = audit_rate_limit;
66809 status_set.backlog_limit = audit_backlog_limit;
66810 - status_set.lost = atomic_read(&audit_lost);
66811 + status_set.lost = atomic_read_unchecked(&audit_lost);
66812 status_set.backlog = skb_queue_len(&audit_skb_queue);
66813 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66814 &status_set, sizeof(status_set));
66815 diff -urNp linux-2.6.39.2/kernel/auditsc.c linux-2.6.39.2/kernel/auditsc.c
66816 --- linux-2.6.39.2/kernel/auditsc.c 2011-05-19 00:06:34.000000000 -0400
66817 +++ linux-2.6.39.2/kernel/auditsc.c 2011-05-22 19:36:33.000000000 -0400
66818 @@ -2111,7 +2111,7 @@ int auditsc_get_stamp(struct audit_conte
66819 }
66820
66821 /* global counter which is incremented every time something logs in */
66822 -static atomic_t session_id = ATOMIC_INIT(0);
66823 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66824
66825 /**
66826 * audit_set_loginuid - set a task's audit_context loginuid
66827 @@ -2124,7 +2124,7 @@ static atomic_t session_id = ATOMIC_INIT
66828 */
66829 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
66830 {
66831 - unsigned int sessionid = atomic_inc_return(&session_id);
66832 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
66833 struct audit_context *context = task->audit_context;
66834
66835 if (context && context->in_syscall) {
66836 diff -urNp linux-2.6.39.2/kernel/capability.c linux-2.6.39.2/kernel/capability.c
66837 --- linux-2.6.39.2/kernel/capability.c 2011-05-19 00:06:34.000000000 -0400
66838 +++ linux-2.6.39.2/kernel/capability.c 2011-05-22 21:02:23.000000000 -0400
66839 @@ -206,6 +206,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_
66840 * before modification is attempted and the application
66841 * fails.
66842 */
66843 + if (tocopy > ARRAY_SIZE(kdata))
66844 + return -EFAULT;
66845 +
66846 if (copy_to_user(dataptr, kdata, tocopy
66847 * sizeof(struct __user_cap_data_struct))) {
66848 return -EFAULT;
66849 @@ -378,7 +381,7 @@ bool ns_capable(struct user_namespace *n
66850 BUG();
66851 }
66852
66853 - if (security_capable(ns, current_cred(), cap) == 0) {
66854 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
66855 current->flags |= PF_SUPERPRIV;
66856 return true;
66857 }
66858 @@ -386,6 +389,27 @@ bool ns_capable(struct user_namespace *n
66859 }
66860 EXPORT_SYMBOL(ns_capable);
66861
66862 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66863 +{
66864 + if (unlikely(!cap_valid(cap))) {
66865 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66866 + BUG();
66867 + }
66868 +
66869 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
66870 + current->flags |= PF_SUPERPRIV;
66871 + return true;
66872 + }
66873 + return false;
66874 +}
66875 +EXPORT_SYMBOL(ns_capable_nolog);
66876 +
66877 +bool capable_nolog(int cap)
66878 +{
66879 + return ns_capable_nolog(&init_user_ns, cap);
66880 +}
66881 +EXPORT_SYMBOL(capable_nolog);
66882 +
66883 /**
66884 * task_ns_capable - Determine whether current task has a superior
66885 * capability targeted at a specific task's user namespace.
66886 @@ -400,6 +424,12 @@ bool task_ns_capable(struct task_struct
66887 }
66888 EXPORT_SYMBOL(task_ns_capable);
66889
66890 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
66891 +{
66892 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
66893 +}
66894 +EXPORT_SYMBOL(task_ns_capable_nolog);
66895 +
66896 /**
66897 * nsown_capable - Check superior capability to one's own user_ns
66898 * @cap: The capability in question
66899 diff -urNp linux-2.6.39.2/kernel/cgroup.c linux-2.6.39.2/kernel/cgroup.c
66900 --- linux-2.6.39.2/kernel/cgroup.c 2011-05-19 00:06:34.000000000 -0400
66901 +++ linux-2.6.39.2/kernel/cgroup.c 2011-05-22 19:36:33.000000000 -0400
66902 @@ -598,6 +598,8 @@ static struct css_set *find_css_set(
66903 struct hlist_head *hhead;
66904 struct cg_cgroup_link *link;
66905
66906 + pax_track_stack();
66907 +
66908 /* First see if we already have a cgroup group that matches
66909 * the desired set */
66910 read_lock(&css_set_lock);
66911 diff -urNp linux-2.6.39.2/kernel/compat.c linux-2.6.39.2/kernel/compat.c
66912 --- linux-2.6.39.2/kernel/compat.c 2011-05-19 00:06:34.000000000 -0400
66913 +++ linux-2.6.39.2/kernel/compat.c 2011-05-22 19:41:42.000000000 -0400
66914 @@ -13,6 +13,7 @@
66915
66916 #include <linux/linkage.h>
66917 #include <linux/compat.h>
66918 +#include <linux/module.h>
66919 #include <linux/errno.h>
66920 #include <linux/time.h>
66921 #include <linux/signal.h>
66922 diff -urNp linux-2.6.39.2/kernel/configs.c linux-2.6.39.2/kernel/configs.c
66923 --- linux-2.6.39.2/kernel/configs.c 2011-05-19 00:06:34.000000000 -0400
66924 +++ linux-2.6.39.2/kernel/configs.c 2011-05-22 19:41:42.000000000 -0400
66925 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66926 struct proc_dir_entry *entry;
66927
66928 /* create the current config file */
66929 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66930 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66931 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66932 + &ikconfig_file_ops);
66933 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66934 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66935 + &ikconfig_file_ops);
66936 +#endif
66937 +#else
66938 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66939 &ikconfig_file_ops);
66940 +#endif
66941 +
66942 if (!entry)
66943 return -ENOMEM;
66944
66945 diff -urNp linux-2.6.39.2/kernel/cred.c linux-2.6.39.2/kernel/cred.c
66946 --- linux-2.6.39.2/kernel/cred.c 2011-05-19 00:06:34.000000000 -0400
66947 +++ linux-2.6.39.2/kernel/cred.c 2011-05-22 19:41:42.000000000 -0400
66948 @@ -158,6 +158,8 @@ static void put_cred_rcu(struct rcu_head
66949 */
66950 void __put_cred(struct cred *cred)
66951 {
66952 + pax_track_stack();
66953 +
66954 kdebug("__put_cred(%p{%d,%d})", cred,
66955 atomic_read(&cred->usage),
66956 read_cred_subscribers(cred));
66957 @@ -182,6 +184,8 @@ void exit_creds(struct task_struct *tsk)
66958 {
66959 struct cred *cred;
66960
66961 + pax_track_stack();
66962 +
66963 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
66964 atomic_read(&tsk->cred->usage),
66965 read_cred_subscribers(tsk->cred));
66966 @@ -220,6 +224,8 @@ const struct cred *get_task_cred(struct
66967 {
66968 const struct cred *cred;
66969
66970 + pax_track_stack();
66971 +
66972 rcu_read_lock();
66973
66974 do {
66975 @@ -239,6 +245,8 @@ struct cred *cred_alloc_blank(void)
66976 {
66977 struct cred *new;
66978
66979 + pax_track_stack();
66980 +
66981 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
66982 if (!new)
66983 return NULL;
66984 @@ -287,6 +295,8 @@ struct cred *prepare_creds(void)
66985 const struct cred *old;
66986 struct cred *new;
66987
66988 + pax_track_stack();
66989 +
66990 validate_process_creds();
66991
66992 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
66993 @@ -333,6 +343,8 @@ struct cred *prepare_exec_creds(void)
66994 struct thread_group_cred *tgcred = NULL;
66995 struct cred *new;
66996
66997 + pax_track_stack();
66998 +
66999 #ifdef CONFIG_KEYS
67000 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
67001 if (!tgcred)
67002 @@ -385,6 +397,8 @@ int copy_creds(struct task_struct *p, un
67003 struct cred *new;
67004 int ret;
67005
67006 + pax_track_stack();
67007 +
67008 if (
67009 #ifdef CONFIG_KEYS
67010 !p->cred->thread_keyring &&
67011 @@ -475,6 +489,8 @@ int commit_creds(struct cred *new)
67012 struct task_struct *task = current;
67013 const struct cred *old = task->real_cred;
67014
67015 + pax_track_stack();
67016 +
67017 kdebug("commit_creds(%p{%d,%d})", new,
67018 atomic_read(&new->usage),
67019 read_cred_subscribers(new));
67020 @@ -489,6 +505,8 @@ int commit_creds(struct cred *new)
67021
67022 get_cred(new); /* we will require a ref for the subj creds too */
67023
67024 + gr_set_role_label(task, new->uid, new->gid);
67025 +
67026 /* dumpability changes */
67027 if (old->euid != new->euid ||
67028 old->egid != new->egid ||
67029 @@ -551,6 +569,8 @@ EXPORT_SYMBOL(commit_creds);
67030 */
67031 void abort_creds(struct cred *new)
67032 {
67033 + pax_track_stack();
67034 +
67035 kdebug("abort_creds(%p{%d,%d})", new,
67036 atomic_read(&new->usage),
67037 read_cred_subscribers(new));
67038 @@ -574,6 +594,8 @@ const struct cred *override_creds(const
67039 {
67040 const struct cred *old = current->cred;
67041
67042 + pax_track_stack();
67043 +
67044 kdebug("override_creds(%p{%d,%d})", new,
67045 atomic_read(&new->usage),
67046 read_cred_subscribers(new));
67047 @@ -603,6 +625,8 @@ void revert_creds(const struct cred *old
67048 {
67049 const struct cred *override = current->cred;
67050
67051 + pax_track_stack();
67052 +
67053 kdebug("revert_creds(%p{%d,%d})", old,
67054 atomic_read(&old->usage),
67055 read_cred_subscribers(old));
67056 @@ -649,6 +673,8 @@ struct cred *prepare_kernel_cred(struct
67057 const struct cred *old;
67058 struct cred *new;
67059
67060 + pax_track_stack();
67061 +
67062 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
67063 if (!new)
67064 return NULL;
67065 @@ -703,6 +729,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
67066 */
67067 int set_security_override(struct cred *new, u32 secid)
67068 {
67069 + pax_track_stack();
67070 +
67071 return security_kernel_act_as(new, secid);
67072 }
67073 EXPORT_SYMBOL(set_security_override);
67074 @@ -722,6 +750,8 @@ int set_security_override_from_ctx(struc
67075 u32 secid;
67076 int ret;
67077
67078 + pax_track_stack();
67079 +
67080 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
67081 if (ret < 0)
67082 return ret;
67083 diff -urNp linux-2.6.39.2/kernel/debug/debug_core.c linux-2.6.39.2/kernel/debug/debug_core.c
67084 --- linux-2.6.39.2/kernel/debug/debug_core.c 2011-05-19 00:06:34.000000000 -0400
67085 +++ linux-2.6.39.2/kernel/debug/debug_core.c 2011-05-22 19:36:33.000000000 -0400
67086 @@ -72,7 +72,7 @@ int kgdb_io_module_registered;
67087 /* Guard for recursive entry */
67088 static int exception_level;
67089
67090 -struct kgdb_io *dbg_io_ops;
67091 +const struct kgdb_io *dbg_io_ops;
67092 static DEFINE_SPINLOCK(kgdb_registration_lock);
67093
67094 /* kgdb console driver is loaded */
67095 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_loc
67096 */
67097 static atomic_t masters_in_kgdb;
67098 static atomic_t slaves_in_kgdb;
67099 -static atomic_t kgdb_break_tasklet_var;
67100 +static atomic_unchecked_t kgdb_break_tasklet_var;
67101 atomic_t kgdb_setting_breakpoint;
67102
67103 struct task_struct *kgdb_usethread;
67104 @@ -129,7 +129,7 @@ int kgdb_single_step;
67105 static pid_t kgdb_sstep_pid;
67106
67107 /* to keep track of the CPU which is doing the single stepping*/
67108 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67109 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67110
67111 /*
67112 * If you are debugging a problem where roundup (the collection of
67113 @@ -542,7 +542,7 @@ return_normal:
67114 * kernel will only try for the value of sstep_tries before
67115 * giving up and continuing on.
67116 */
67117 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67118 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67119 (kgdb_info[cpu].task &&
67120 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67121 atomic_set(&kgdb_active, -1);
67122 @@ -636,8 +636,8 @@ cpu_master_loop:
67123 }
67124
67125 kgdb_restore:
67126 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67127 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67128 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67129 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67130 if (kgdb_info[sstep_cpu].task)
67131 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67132 else
67133 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(vo
67134 static void kgdb_tasklet_bpt(unsigned long ing)
67135 {
67136 kgdb_breakpoint();
67137 - atomic_set(&kgdb_break_tasklet_var, 0);
67138 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67139 }
67140
67141 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67142
67143 void kgdb_schedule_breakpoint(void)
67144 {
67145 - if (atomic_read(&kgdb_break_tasklet_var) ||
67146 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67147 atomic_read(&kgdb_active) != -1 ||
67148 atomic_read(&kgdb_setting_breakpoint))
67149 return;
67150 - atomic_inc(&kgdb_break_tasklet_var);
67151 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67152 tasklet_schedule(&kgdb_tasklet_breakpoint);
67153 }
67154 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67155 @@ -864,7 +864,7 @@ static void kgdb_initial_breakpoint(void
67156 *
67157 * Register it with the KGDB core.
67158 */
67159 -int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops)
67160 +int kgdb_register_io_module(const struct kgdb_io *new_dbg_io_ops)
67161 {
67162 int err;
67163
67164 @@ -909,7 +909,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_modul
67165 *
67166 * Unregister it with the KGDB core.
67167 */
67168 -void kgdb_unregister_io_module(struct kgdb_io *old_dbg_io_ops)
67169 +void kgdb_unregister_io_module(const struct kgdb_io *old_dbg_io_ops)
67170 {
67171 BUG_ON(kgdb_connected);
67172
67173 diff -urNp linux-2.6.39.2/kernel/debug/kdb/kdb_main.c linux-2.6.39.2/kernel/debug/kdb/kdb_main.c
67174 --- linux-2.6.39.2/kernel/debug/kdb/kdb_main.c 2011-05-19 00:06:34.000000000 -0400
67175 +++ linux-2.6.39.2/kernel/debug/kdb/kdb_main.c 2011-05-22 19:36:33.000000000 -0400
67176 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const cha
67177 list_for_each_entry(mod, kdb_modules, list) {
67178
67179 kdb_printf("%-20s%8u 0x%p ", mod->name,
67180 - mod->core_size, (void *)mod);
67181 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67182 #ifdef CONFIG_MODULE_UNLOAD
67183 kdb_printf("%4d ", module_refcount(mod));
67184 #endif
67185 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const cha
67186 kdb_printf(" (Loading)");
67187 else
67188 kdb_printf(" (Live)");
67189 - kdb_printf(" 0x%p", mod->module_core);
67190 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67191
67192 #ifdef CONFIG_MODULE_UNLOAD
67193 {
67194 diff -urNp linux-2.6.39.2/kernel/exit.c linux-2.6.39.2/kernel/exit.c
67195 --- linux-2.6.39.2/kernel/exit.c 2011-05-19 00:06:34.000000000 -0400
67196 +++ linux-2.6.39.2/kernel/exit.c 2011-05-22 20:02:30.000000000 -0400
67197 @@ -57,6 +57,10 @@
67198 #include <asm/pgtable.h>
67199 #include <asm/mmu_context.h>
67200
67201 +#ifdef CONFIG_GRKERNSEC
67202 +extern rwlock_t grsec_exec_file_lock;
67203 +#endif
67204 +
67205 static void exit_mm(struct task_struct * tsk);
67206
67207 static void __unhash_process(struct task_struct *p, bool group_dead)
67208 @@ -169,6 +173,8 @@ void release_task(struct task_struct * p
67209 struct task_struct *leader;
67210 int zap_leader;
67211 repeat:
67212 + gr_del_task_from_ip_table(p);
67213 +
67214 tracehook_prepare_release_task(p);
67215 /* don't need to get the RCU readlock here - the process is dead and
67216 * can't be modifying its own credentials. But shut RCU-lockdep up */
67217 @@ -338,11 +344,22 @@ static void reparent_to_kthreadd(void)
67218 {
67219 write_lock_irq(&tasklist_lock);
67220
67221 +#ifdef CONFIG_GRKERNSEC
67222 + write_lock(&grsec_exec_file_lock);
67223 + if (current->exec_file) {
67224 + fput(current->exec_file);
67225 + current->exec_file = NULL;
67226 + }
67227 + write_unlock(&grsec_exec_file_lock);
67228 +#endif
67229 +
67230 ptrace_unlink(current);
67231 /* Reparent to init */
67232 current->real_parent = current->parent = kthreadd_task;
67233 list_move_tail(&current->sibling, &current->real_parent->children);
67234
67235 + gr_set_kernel_label(current);
67236 +
67237 /* Set the exit signal to SIGCHLD so we signal init on exit */
67238 current->exit_signal = SIGCHLD;
67239
67240 @@ -394,7 +411,7 @@ int allow_signal(int sig)
67241 * know it'll be handled, so that they don't get converted to
67242 * SIGKILL or just silently dropped.
67243 */
67244 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67245 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67246 recalc_sigpending();
67247 spin_unlock_irq(&current->sighand->siglock);
67248 return 0;
67249 @@ -430,6 +447,17 @@ void daemonize(const char *name, ...)
67250 vsnprintf(current->comm, sizeof(current->comm), name, args);
67251 va_end(args);
67252
67253 +#ifdef CONFIG_GRKERNSEC
67254 + write_lock(&grsec_exec_file_lock);
67255 + if (current->exec_file) {
67256 + fput(current->exec_file);
67257 + current->exec_file = NULL;
67258 + }
67259 + write_unlock(&grsec_exec_file_lock);
67260 +#endif
67261 +
67262 + gr_set_kernel_label(current);
67263 +
67264 /*
67265 * If we were started as result of loading a module, close all of the
67266 * user space pages. We don't need them, and if we didn't close them
67267 @@ -905,15 +933,8 @@ NORET_TYPE void do_exit(long code)
67268 struct task_struct *tsk = current;
67269 int group_dead;
67270
67271 - profile_task_exit(tsk);
67272 -
67273 - WARN_ON(atomic_read(&tsk->fs_excl));
67274 - WARN_ON(blk_needs_flush_plug(tsk));
67275 -
67276 if (unlikely(in_interrupt()))
67277 panic("Aiee, killing interrupt handler!");
67278 - if (unlikely(!tsk->pid))
67279 - panic("Attempted to kill the idle task!");
67280
67281 /*
67282 * If do_exit is called because this processes oopsed, it's possible
67283 @@ -924,6 +945,14 @@ NORET_TYPE void do_exit(long code)
67284 */
67285 set_fs(USER_DS);
67286
67287 + profile_task_exit(tsk);
67288 +
67289 + WARN_ON(atomic_read(&tsk->fs_excl));
67290 + WARN_ON(blk_needs_flush_plug(tsk));
67291 +
67292 + if (unlikely(!tsk->pid))
67293 + panic("Attempted to kill the idle task!");
67294 +
67295 tracehook_report_exit(&code);
67296
67297 validate_creds_for_do_exit(tsk);
67298 @@ -984,6 +1013,9 @@ NORET_TYPE void do_exit(long code)
67299 tsk->exit_code = code;
67300 taskstats_exit(tsk, group_dead);
67301
67302 + gr_acl_handle_psacct(tsk, code);
67303 + gr_acl_handle_exit();
67304 +
67305 exit_mm(tsk);
67306
67307 if (group_dead)
67308 diff -urNp linux-2.6.39.2/kernel/fork.c linux-2.6.39.2/kernel/fork.c
67309 --- linux-2.6.39.2/kernel/fork.c 2011-05-19 00:06:34.000000000 -0400
67310 +++ linux-2.6.39.2/kernel/fork.c 2011-05-22 19:41:42.000000000 -0400
67311 @@ -287,7 +287,7 @@ static struct task_struct *dup_task_stru
67312 *stackend = STACK_END_MAGIC; /* for overflow detection */
67313
67314 #ifdef CONFIG_CC_STACKPROTECTOR
67315 - tsk->stack_canary = get_random_int();
67316 + tsk->stack_canary = pax_get_random_long();
67317 #endif
67318
67319 /* One for us, one for whoever does the "release_task()" (usually parent) */
67320 @@ -309,13 +309,78 @@ out:
67321 }
67322
67323 #ifdef CONFIG_MMU
67324 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67325 +{
67326 + struct vm_area_struct *tmp;
67327 + unsigned long charge;
67328 + struct mempolicy *pol;
67329 + struct file *file;
67330 +
67331 + charge = 0;
67332 + if (mpnt->vm_flags & VM_ACCOUNT) {
67333 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67334 + if (security_vm_enough_memory(len))
67335 + goto fail_nomem;
67336 + charge = len;
67337 + }
67338 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67339 + if (!tmp)
67340 + goto fail_nomem;
67341 + *tmp = *mpnt;
67342 + tmp->vm_mm = mm;
67343 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67344 + pol = mpol_dup(vma_policy(mpnt));
67345 + if (IS_ERR(pol))
67346 + goto fail_nomem_policy;
67347 + vma_set_policy(tmp, pol);
67348 + if (anon_vma_fork(tmp, mpnt))
67349 + goto fail_nomem_anon_vma_fork;
67350 + tmp->vm_flags &= ~VM_LOCKED;
67351 + tmp->vm_next = tmp->vm_prev = NULL;
67352 + tmp->vm_mirror = NULL;
67353 + file = tmp->vm_file;
67354 + if (file) {
67355 + struct inode *inode = file->f_path.dentry->d_inode;
67356 + struct address_space *mapping = file->f_mapping;
67357 +
67358 + get_file(file);
67359 + if (tmp->vm_flags & VM_DENYWRITE)
67360 + atomic_dec(&inode->i_writecount);
67361 + spin_lock(&mapping->i_mmap_lock);
67362 + if (tmp->vm_flags & VM_SHARED)
67363 + mapping->i_mmap_writable++;
67364 + tmp->vm_truncate_count = mpnt->vm_truncate_count;
67365 + flush_dcache_mmap_lock(mapping);
67366 + /* insert tmp into the share list, just after mpnt */
67367 + vma_prio_tree_add(tmp, mpnt);
67368 + flush_dcache_mmap_unlock(mapping);
67369 + spin_unlock(&mapping->i_mmap_lock);
67370 + }
67371 +
67372 + /*
67373 + * Clear hugetlb-related page reserves for children. This only
67374 + * affects MAP_PRIVATE mappings. Faults generated by the child
67375 + * are not guaranteed to succeed, even if read-only
67376 + */
67377 + if (is_vm_hugetlb_page(tmp))
67378 + reset_vma_resv_huge_pages(tmp);
67379 +
67380 + return tmp;
67381 +
67382 +fail_nomem_anon_vma_fork:
67383 + mpol_put(pol);
67384 +fail_nomem_policy:
67385 + kmem_cache_free(vm_area_cachep, tmp);
67386 +fail_nomem:
67387 + vm_unacct_memory(charge);
67388 + return NULL;
67389 +}
67390 +
67391 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67392 {
67393 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67394 struct rb_node **rb_link, *rb_parent;
67395 int retval;
67396 - unsigned long charge;
67397 - struct mempolicy *pol;
67398
67399 down_write(&oldmm->mmap_sem);
67400 flush_cache_dup_mm(oldmm);
67401 @@ -327,8 +392,8 @@ static int dup_mmap(struct mm_struct *mm
67402 mm->locked_vm = 0;
67403 mm->mmap = NULL;
67404 mm->mmap_cache = NULL;
67405 - mm->free_area_cache = oldmm->mmap_base;
67406 - mm->cached_hole_size = ~0UL;
67407 + mm->free_area_cache = oldmm->free_area_cache;
67408 + mm->cached_hole_size = oldmm->cached_hole_size;
67409 mm->map_count = 0;
67410 cpumask_clear(mm_cpumask(mm));
67411 mm->mm_rb = RB_ROOT;
67412 @@ -344,8 +409,6 @@ static int dup_mmap(struct mm_struct *mm
67413
67414 prev = NULL;
67415 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67416 - struct file *file;
67417 -
67418 if (mpnt->vm_flags & VM_DONTCOPY) {
67419 long pages = vma_pages(mpnt);
67420 mm->total_vm -= pages;
67421 @@ -353,56 +416,13 @@ static int dup_mmap(struct mm_struct *mm
67422 -pages);
67423 continue;
67424 }
67425 - charge = 0;
67426 - if (mpnt->vm_flags & VM_ACCOUNT) {
67427 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67428 - if (security_vm_enough_memory(len))
67429 - goto fail_nomem;
67430 - charge = len;
67431 - }
67432 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67433 - if (!tmp)
67434 - goto fail_nomem;
67435 - *tmp = *mpnt;
67436 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67437 - pol = mpol_dup(vma_policy(mpnt));
67438 - retval = PTR_ERR(pol);
67439 - if (IS_ERR(pol))
67440 - goto fail_nomem_policy;
67441 - vma_set_policy(tmp, pol);
67442 - tmp->vm_mm = mm;
67443 - if (anon_vma_fork(tmp, mpnt))
67444 - goto fail_nomem_anon_vma_fork;
67445 - tmp->vm_flags &= ~VM_LOCKED;
67446 - tmp->vm_next = tmp->vm_prev = NULL;
67447 - file = tmp->vm_file;
67448 - if (file) {
67449 - struct inode *inode = file->f_path.dentry->d_inode;
67450 - struct address_space *mapping = file->f_mapping;
67451 -
67452 - get_file(file);
67453 - if (tmp->vm_flags & VM_DENYWRITE)
67454 - atomic_dec(&inode->i_writecount);
67455 - spin_lock(&mapping->i_mmap_lock);
67456 - if (tmp->vm_flags & VM_SHARED)
67457 - mapping->i_mmap_writable++;
67458 - tmp->vm_truncate_count = mpnt->vm_truncate_count;
67459 - flush_dcache_mmap_lock(mapping);
67460 - /* insert tmp into the share list, just after mpnt */
67461 - vma_prio_tree_add(tmp, mpnt);
67462 - flush_dcache_mmap_unlock(mapping);
67463 - spin_unlock(&mapping->i_mmap_lock);
67464 + tmp = dup_vma(mm, mpnt);
67465 + if (!tmp) {
67466 + retval = -ENOMEM;
67467 + goto out;
67468 }
67469
67470 /*
67471 - * Clear hugetlb-related page reserves for children. This only
67472 - * affects MAP_PRIVATE mappings. Faults generated by the child
67473 - * are not guaranteed to succeed, even if read-only
67474 - */
67475 - if (is_vm_hugetlb_page(tmp))
67476 - reset_vma_resv_huge_pages(tmp);
67477 -
67478 - /*
67479 * Link in the new vma and copy the page table entries.
67480 */
67481 *pprev = tmp;
67482 @@ -423,6 +443,31 @@ static int dup_mmap(struct mm_struct *mm
67483 if (retval)
67484 goto out;
67485 }
67486 +
67487 +#ifdef CONFIG_PAX_SEGMEXEC
67488 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67489 + struct vm_area_struct *mpnt_m;
67490 +
67491 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67492 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67493 +
67494 + if (!mpnt->vm_mirror)
67495 + continue;
67496 +
67497 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67498 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67499 + mpnt->vm_mirror = mpnt_m;
67500 + } else {
67501 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67502 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67503 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67504 + mpnt->vm_mirror->vm_mirror = mpnt;
67505 + }
67506 + }
67507 + BUG_ON(mpnt_m);
67508 + }
67509 +#endif
67510 +
67511 /* a new mm has just been created */
67512 arch_dup_mmap(oldmm, mm);
67513 retval = 0;
67514 @@ -431,14 +476,6 @@ out:
67515 flush_tlb_mm(oldmm);
67516 up_write(&oldmm->mmap_sem);
67517 return retval;
67518 -fail_nomem_anon_vma_fork:
67519 - mpol_put(pol);
67520 -fail_nomem_policy:
67521 - kmem_cache_free(vm_area_cachep, tmp);
67522 -fail_nomem:
67523 - retval = -ENOMEM;
67524 - vm_unacct_memory(charge);
67525 - goto out;
67526 }
67527
67528 static inline int mm_alloc_pgd(struct mm_struct * mm)
67529 @@ -785,13 +822,14 @@ static int copy_fs(unsigned long clone_f
67530 spin_unlock(&fs->lock);
67531 return -EAGAIN;
67532 }
67533 - fs->users++;
67534 + atomic_inc(&fs->users);
67535 spin_unlock(&fs->lock);
67536 return 0;
67537 }
67538 tsk->fs = copy_fs_struct(fs);
67539 if (!tsk->fs)
67540 return -ENOMEM;
67541 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67542 return 0;
67543 }
67544
67545 @@ -1049,10 +1087,13 @@ static struct task_struct *copy_process(
67546 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67547 #endif
67548 retval = -EAGAIN;
67549 +
67550 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67551 +
67552 if (atomic_read(&p->real_cred->user->processes) >=
67553 task_rlimit(p, RLIMIT_NPROC)) {
67554 - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67555 - p->real_cred->user != INIT_USER)
67556 + if (p->real_cred->user != INIT_USER &&
67557 + !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE))
67558 goto bad_fork_free;
67559 }
67560
67561 @@ -1200,6 +1241,8 @@ static struct task_struct *copy_process(
67562 goto bad_fork_free_pid;
67563 }
67564
67565 + gr_copy_label(p);
67566 +
67567 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67568 /*
67569 * Clear TID on mm_release()?
67570 @@ -1360,6 +1403,8 @@ bad_fork_cleanup_count:
67571 bad_fork_free:
67572 free_task(p);
67573 fork_out:
67574 + gr_log_forkfail(retval);
67575 +
67576 return ERR_PTR(retval);
67577 }
67578
67579 @@ -1448,6 +1493,8 @@ long do_fork(unsigned long clone_flags,
67580 if (clone_flags & CLONE_PARENT_SETTID)
67581 put_user(nr, parent_tidptr);
67582
67583 + gr_handle_brute_check();
67584 +
67585 if (clone_flags & CLONE_VFORK) {
67586 p->vfork_done = &vfork;
67587 init_completion(&vfork);
67588 @@ -1549,7 +1596,7 @@ static int unshare_fs(unsigned long unsh
67589 return 0;
67590
67591 /* don't need lock here; in the worst case we'll do useless copy */
67592 - if (fs->users == 1)
67593 + if (atomic_read(&fs->users) == 1)
67594 return 0;
67595
67596 *new_fsp = copy_fs_struct(fs);
67597 @@ -1636,7 +1683,8 @@ SYSCALL_DEFINE1(unshare, unsigned long,
67598 fs = current->fs;
67599 spin_lock(&fs->lock);
67600 current->fs = new_fs;
67601 - if (--fs->users)
67602 + gr_set_chroot_entries(current, &current->fs->root);
67603 + if (atomic_dec_return(&fs->users))
67604 new_fs = NULL;
67605 else
67606 new_fs = fs;
67607 diff -urNp linux-2.6.39.2/kernel/futex.c linux-2.6.39.2/kernel/futex.c
67608 --- linux-2.6.39.2/kernel/futex.c 2011-05-19 00:06:34.000000000 -0400
67609 +++ linux-2.6.39.2/kernel/futex.c 2011-05-22 22:41:57.000000000 -0400
67610 @@ -54,6 +54,7 @@
67611 #include <linux/mount.h>
67612 #include <linux/pagemap.h>
67613 #include <linux/syscalls.h>
67614 +#include <linux/ptrace.h>
67615 #include <linux/signal.h>
67616 #include <linux/module.h>
67617 #include <linux/magic.h>
67618 @@ -236,6 +237,11 @@ get_futex_key(u32 __user *uaddr, int fsh
67619 struct page *page, *page_head;
67620 int err;
67621
67622 +#ifdef CONFIG_PAX_SEGMEXEC
67623 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67624 + return -EFAULT;
67625 +#endif
67626 +
67627 /*
67628 * The futex address must be "naturally" aligned.
67629 */
67630 @@ -1833,6 +1839,8 @@ static int futex_wait(u32 __user *uaddr,
67631 struct futex_q q = futex_q_init;
67632 int ret;
67633
67634 + pax_track_stack();
67635 +
67636 if (!bitset)
67637 return -EINVAL;
67638 q.bitset = bitset;
67639 @@ -2229,6 +2237,8 @@ static int futex_wait_requeue_pi(u32 __u
67640 struct futex_q q = futex_q_init;
67641 int res, ret;
67642
67643 + pax_track_stack();
67644 +
67645 if (!bitset)
67646 return -EINVAL;
67647
67648 @@ -2401,7 +2411,9 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67649 {
67650 struct robust_list_head __user *head;
67651 unsigned long ret;
67652 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67653 const struct cred *cred = current_cred(), *pcred;
67654 +#endif
67655
67656 if (!futex_cmpxchg_enabled)
67657 return -ENOSYS;
67658 @@ -2417,6 +2429,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67659 if (!p)
67660 goto err_unlock;
67661 ret = -EPERM;
67662 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67663 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67664 + goto err_unlock;
67665 +#else
67666 pcred = __task_cred(p);
67667 /* If victim is in different user_ns, then uids are not
67668 comparable, so we must have CAP_SYS_PTRACE */
67669 @@ -2431,6 +2447,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pi
67670 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67671 goto err_unlock;
67672 ok:
67673 +#endif
67674 head = p->robust_list;
67675 rcu_read_unlock();
67676 }
67677 @@ -2682,6 +2699,7 @@ static int __init futex_init(void)
67678 {
67679 u32 curval;
67680 int i;
67681 + mm_segment_t oldfs;
67682
67683 /*
67684 * This will fail and we want it. Some arch implementations do
67685 @@ -2693,8 +2711,11 @@ static int __init futex_init(void)
67686 * implementation, the non-functional ones will return
67687 * -ENOSYS.
67688 */
67689 + oldfs = get_fs();
67690 + set_fs(USER_DS);
67691 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67692 futex_cmpxchg_enabled = 1;
67693 + set_fs(oldfs);
67694
67695 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67696 plist_head_init(&futex_queues[i].chain, &futex_queues[i].lock);
67697 diff -urNp linux-2.6.39.2/kernel/futex_compat.c linux-2.6.39.2/kernel/futex_compat.c
67698 --- linux-2.6.39.2/kernel/futex_compat.c 2011-05-19 00:06:34.000000000 -0400
67699 +++ linux-2.6.39.2/kernel/futex_compat.c 2011-05-22 22:42:09.000000000 -0400
67700 @@ -10,6 +10,7 @@
67701 #include <linux/compat.h>
67702 #include <linux/nsproxy.h>
67703 #include <linux/futex.h>
67704 +#include <linux/ptrace.h>
67705
67706 #include <asm/uaccess.h>
67707
67708 @@ -136,7 +137,10 @@ compat_sys_get_robust_list(int pid, comp
67709 {
67710 struct compat_robust_list_head __user *head;
67711 unsigned long ret;
67712 - const struct cred *cred = current_cred(), *pcred;
67713 +#ifndef CONFIG_GRKERNSEC_PROC_MEMMAP
67714 + const struct cred *cred = current_cred();
67715 + const struct cred *pcred;
67716 +#endif
67717
67718 if (!futex_cmpxchg_enabled)
67719 return -ENOSYS;
67720 @@ -152,6 +156,10 @@ compat_sys_get_robust_list(int pid, comp
67721 if (!p)
67722 goto err_unlock;
67723 ret = -EPERM;
67724 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67725 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
67726 + goto err_unlock;
67727 +#else
67728 pcred = __task_cred(p);
67729 /* If victim is in different user_ns, then uids are not
67730 comparable, so we must have CAP_SYS_PTRACE */
67731 @@ -166,6 +174,7 @@ compat_sys_get_robust_list(int pid, comp
67732 !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE))
67733 goto err_unlock;
67734 ok:
67735 +#endif
67736 head = p->compat_robust_list;
67737 rcu_read_unlock();
67738 }
67739 diff -urNp linux-2.6.39.2/kernel/gcov/base.c linux-2.6.39.2/kernel/gcov/base.c
67740 --- linux-2.6.39.2/kernel/gcov/base.c 2011-05-19 00:06:34.000000000 -0400
67741 +++ linux-2.6.39.2/kernel/gcov/base.c 2011-05-22 19:36:33.000000000 -0400
67742 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67743 }
67744
67745 #ifdef CONFIG_MODULES
67746 -static inline int within(void *addr, void *start, unsigned long size)
67747 -{
67748 - return ((addr >= start) && (addr < start + size));
67749 -}
67750 -
67751 /* Update list and generate events when modules are unloaded. */
67752 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67753 void *data)
67754 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct n
67755 prev = NULL;
67756 /* Remove entries located in module from linked list. */
67757 for (info = gcov_info_head; info; info = info->next) {
67758 - if (within(info, mod->module_core, mod->core_size)) {
67759 + if (within_module_core_rw((unsigned long)info, mod)) {
67760 if (prev)
67761 prev->next = info->next;
67762 else
67763 diff -urNp linux-2.6.39.2/kernel/hrtimer.c linux-2.6.39.2/kernel/hrtimer.c
67764 --- linux-2.6.39.2/kernel/hrtimer.c 2011-05-19 00:06:34.000000000 -0400
67765 +++ linux-2.6.39.2/kernel/hrtimer.c 2011-05-22 19:36:33.000000000 -0400
67766 @@ -1383,7 +1383,7 @@ void hrtimer_peek_ahead_timers(void)
67767 local_irq_restore(flags);
67768 }
67769
67770 -static void run_hrtimer_softirq(struct softirq_action *h)
67771 +static void run_hrtimer_softirq(void)
67772 {
67773 hrtimer_peek_ahead_timers();
67774 }
67775 diff -urNp linux-2.6.39.2/kernel/irq/manage.c linux-2.6.39.2/kernel/irq/manage.c
67776 --- linux-2.6.39.2/kernel/irq/manage.c 2011-05-19 00:06:34.000000000 -0400
67777 +++ linux-2.6.39.2/kernel/irq/manage.c 2011-06-13 17:09:06.000000000 -0400
67778 @@ -491,6 +491,9 @@ int irq_set_irq_wake(unsigned int irq, u
67779 struct irq_desc *desc = irq_get_desc_buslock(irq, &flags);
67780 int ret = 0;
67781
67782 + if (!desc)
67783 + return -EINVAL;
67784 +
67785 /* wakeup-capable irqs can be shared between drivers that
67786 * don't need to have the same sleep mode behaviors.
67787 */
67788 diff -urNp linux-2.6.39.2/kernel/jump_label.c linux-2.6.39.2/kernel/jump_label.c
67789 --- linux-2.6.39.2/kernel/jump_label.c 2011-05-19 00:06:34.000000000 -0400
67790 +++ linux-2.6.39.2/kernel/jump_label.c 2011-05-22 19:36:33.000000000 -0400
67791 @@ -49,6 +49,17 @@ void jump_label_unlock(void)
67792 mutex_unlock(&jump_label_mutex);
67793 }
67794
67795 +static void jump_label_swap(void *a, void *b, int size)
67796 +{
67797 + struct jump_entry t;
67798 +
67799 + t = *(struct jump_entry *)a;
67800 + pax_open_kernel();
67801 + *(struct jump_entry *)a = *(struct jump_entry *)b;
67802 + *(struct jump_entry *)b = t;
67803 + pax_close_kernel();
67804 +}
67805 +
67806 static int jump_label_cmp(const void *a, const void *b)
67807 {
67808 const struct jump_entry *jea = a;
67809 @@ -70,7 +81,7 @@ sort_jump_label_entries(struct jump_entr
67810
67811 size = (((unsigned long)stop - (unsigned long)start)
67812 / sizeof(struct jump_entry));
67813 - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67814 + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, jump_label_swap);
67815 }
67816
67817 static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
67818 @@ -407,8 +418,11 @@ static void remove_jump_label_module_ini
67819 count = e_module->nr_entries;
67820 iter = e_module->table;
67821 while (count--) {
67822 - if (within_module_init(iter->code, mod))
67823 + if (within_module_init(iter->code, mod)) {
67824 + pax_open_kernel();
67825 iter->key = 0;
67826 + pax_close_kernel();
67827 + }
67828 iter++;
67829 }
67830 }
67831 diff -urNp linux-2.6.39.2/kernel/kallsyms.c linux-2.6.39.2/kernel/kallsyms.c
67832 --- linux-2.6.39.2/kernel/kallsyms.c 2011-05-19 00:06:34.000000000 -0400
67833 +++ linux-2.6.39.2/kernel/kallsyms.c 2011-05-22 19:41:42.000000000 -0400
67834 @@ -11,6 +11,9 @@
67835 * Changed the compression method from stem compression to "table lookup"
67836 * compression (see scripts/kallsyms.c for a more complete description)
67837 */
67838 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67839 +#define __INCLUDED_BY_HIDESYM 1
67840 +#endif
67841 #include <linux/kallsyms.h>
67842 #include <linux/module.h>
67843 #include <linux/init.h>
67844 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_mark
67845
67846 static inline int is_kernel_inittext(unsigned long addr)
67847 {
67848 + if (system_state != SYSTEM_BOOTING)
67849 + return 0;
67850 +
67851 if (addr >= (unsigned long)_sinittext
67852 && addr <= (unsigned long)_einittext)
67853 return 1;
67854 return 0;
67855 }
67856
67857 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67858 +#ifdef CONFIG_MODULES
67859 +static inline int is_module_text(unsigned long addr)
67860 +{
67861 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67862 + return 1;
67863 +
67864 + addr = ktla_ktva(addr);
67865 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67866 +}
67867 +#else
67868 +static inline int is_module_text(unsigned long addr)
67869 +{
67870 + return 0;
67871 +}
67872 +#endif
67873 +#endif
67874 +
67875 static inline int is_kernel_text(unsigned long addr)
67876 {
67877 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67878 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigne
67879
67880 static inline int is_kernel(unsigned long addr)
67881 {
67882 +
67883 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67884 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67885 + return 1;
67886 +
67887 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67888 +#else
67889 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67890 +#endif
67891 +
67892 return 1;
67893 return in_gate_area_no_mm(addr);
67894 }
67895
67896 static int is_ksym_addr(unsigned long addr)
67897 {
67898 +
67899 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67900 + if (is_module_text(addr))
67901 + return 0;
67902 +#endif
67903 +
67904 if (all_var)
67905 return is_kernel(addr);
67906
67907 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(st
67908
67909 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67910 {
67911 - iter->name[0] = '\0';
67912 iter->nameoff = get_symbol_offset(new_pos);
67913 iter->pos = new_pos;
67914 }
67915 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, vo
67916 {
67917 struct kallsym_iter *iter = m->private;
67918
67919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67920 + if (current_uid())
67921 + return 0;
67922 +#endif
67923 +
67924 /* Some debugging symbols have no name. Ignore them. */
67925 if (!iter->name[0])
67926 return 0;
67927 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *i
67928 struct kallsym_iter *iter;
67929 int ret;
67930
67931 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67932 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67933 if (!iter)
67934 return -ENOMEM;
67935 reset_iter(iter, 0);
67936 diff -urNp linux-2.6.39.2/kernel/kmod.c linux-2.6.39.2/kernel/kmod.c
67937 --- linux-2.6.39.2/kernel/kmod.c 2011-05-19 00:06:34.000000000 -0400
67938 +++ linux-2.6.39.2/kernel/kmod.c 2011-05-22 19:41:42.000000000 -0400
67939 @@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sb
67940 * If module auto-loading support is disabled then this function
67941 * becomes a no-operation.
67942 */
67943 -int __request_module(bool wait, const char *fmt, ...)
67944 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67945 {
67946 - va_list args;
67947 char module_name[MODULE_NAME_LEN];
67948 unsigned int max_modprobes;
67949 int ret;
67950 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67951 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67952 static char *envp[] = { "HOME=/",
67953 "TERM=linux",
67954 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67955 @@ -80,9 +79,7 @@ int __request_module(bool wait, const ch
67956 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67957 static int kmod_loop_msg;
67958
67959 - va_start(args, fmt);
67960 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67961 - va_end(args);
67962 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67963 if (ret >= MODULE_NAME_LEN)
67964 return -ENAMETOOLONG;
67965
67966 @@ -90,6 +87,20 @@ int __request_module(bool wait, const ch
67967 if (ret)
67968 return ret;
67969
67970 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67971 + if (!current_uid()) {
67972 + /* hack to workaround consolekit/udisks stupidity */
67973 + read_lock(&tasklist_lock);
67974 + if (!strcmp(current->comm, "mount") &&
67975 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67976 + read_unlock(&tasklist_lock);
67977 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67978 + return -EPERM;
67979 + }
67980 + read_unlock(&tasklist_lock);
67981 + }
67982 +#endif
67983 +
67984 /* If modprobe needs a service that is in a module, we get a recursive
67985 * loop. Limit the number of running kmod threads to max_threads/2 or
67986 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67987 @@ -123,6 +134,47 @@ int __request_module(bool wait, const ch
67988 atomic_dec(&kmod_concurrent);
67989 return ret;
67990 }
67991 +
67992 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67993 +{
67994 + va_list args;
67995 + int ret;
67996 +
67997 + va_start(args, fmt);
67998 + ret = ____request_module(wait, module_param, fmt, args);
67999 + va_end(args);
68000 +
68001 + return ret;
68002 +}
68003 +
68004 +int __request_module(bool wait, const char *fmt, ...)
68005 +{
68006 + va_list args;
68007 + int ret;
68008 +
68009 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68010 + if (current_uid()) {
68011 + char module_param[MODULE_NAME_LEN];
68012 +
68013 + memset(module_param, 0, sizeof(module_param));
68014 +
68015 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68016 +
68017 + va_start(args, fmt);
68018 + ret = ____request_module(wait, module_param, fmt, args);
68019 + va_end(args);
68020 +
68021 + return ret;
68022 + }
68023 +#endif
68024 +
68025 + va_start(args, fmt);
68026 + ret = ____request_module(wait, NULL, fmt, args);
68027 + va_end(args);
68028 +
68029 + return ret;
68030 +}
68031 +
68032 EXPORT_SYMBOL(__request_module);
68033 #endif /* CONFIG_MODULES */
68034
68035 diff -urNp linux-2.6.39.2/kernel/kprobes.c linux-2.6.39.2/kernel/kprobes.c
68036 --- linux-2.6.39.2/kernel/kprobes.c 2011-05-19 00:06:34.000000000 -0400
68037 +++ linux-2.6.39.2/kernel/kprobes.c 2011-05-22 19:36:33.000000000 -0400
68038 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_
68039 * kernel image and loaded module images reside. This is required
68040 * so x86_64 can correctly handle the %rip-relative fixups.
68041 */
68042 - kip->insns = module_alloc(PAGE_SIZE);
68043 + kip->insns = module_alloc_exec(PAGE_SIZE);
68044 if (!kip->insns) {
68045 kfree(kip);
68046 return NULL;
68047 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(st
68048 */
68049 if (!list_is_singular(&kip->list)) {
68050 list_del(&kip->list);
68051 - module_free(NULL, kip->insns);
68052 + module_free_exec(NULL, kip->insns);
68053 kfree(kip);
68054 }
68055 return 1;
68056 @@ -1936,7 +1936,7 @@ static int __init init_kprobes(void)
68057 {
68058 int i, err = 0;
68059 unsigned long offset = 0, size = 0;
68060 - char *modname, namebuf[128];
68061 + char *modname, namebuf[KSYM_NAME_LEN];
68062 const char *symbol_name;
68063 void *addr;
68064 struct kprobe_blackpoint *kb;
68065 @@ -2062,7 +2062,7 @@ static int __kprobes show_kprobe_addr(st
68066 const char *sym = NULL;
68067 unsigned int i = *(loff_t *) v;
68068 unsigned long offset = 0;
68069 - char *modname, namebuf[128];
68070 + char *modname, namebuf[KSYM_NAME_LEN];
68071
68072 head = &kprobe_table[i];
68073 preempt_disable();
68074 diff -urNp linux-2.6.39.2/kernel/lockdep.c linux-2.6.39.2/kernel/lockdep.c
68075 --- linux-2.6.39.2/kernel/lockdep.c 2011-06-25 12:55:23.000000000 -0400
68076 +++ linux-2.6.39.2/kernel/lockdep.c 2011-06-25 13:00:28.000000000 -0400
68077 @@ -571,6 +571,10 @@ static int static_obj(void *obj)
68078 end = (unsigned long) &_end,
68079 addr = (unsigned long) obj;
68080
68081 +#ifdef CONFIG_PAX_KERNEXEC
68082 + start = ktla_ktva(start);
68083 +#endif
68084 +
68085 /*
68086 * static variable?
68087 */
68088 @@ -706,6 +710,7 @@ register_lock_class(struct lockdep_map *
68089 if (!static_obj(lock->key)) {
68090 debug_locks_off();
68091 printk("INFO: trying to register non-static key.\n");
68092 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68093 printk("the code is fine but needs lockdep annotation.\n");
68094 printk("turning off the locking correctness validator.\n");
68095 dump_stack();
68096 @@ -2752,7 +2757,7 @@ static int __lock_acquire(struct lockdep
68097 if (!class)
68098 return 0;
68099 }
68100 - atomic_inc((atomic_t *)&class->ops);
68101 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68102 if (very_verbose(class)) {
68103 printk("\nacquire class [%p] %s", class->key, class->name);
68104 if (class->name_version > 1)
68105 diff -urNp linux-2.6.39.2/kernel/lockdep_proc.c linux-2.6.39.2/kernel/lockdep_proc.c
68106 --- linux-2.6.39.2/kernel/lockdep_proc.c 2011-05-19 00:06:34.000000000 -0400
68107 +++ linux-2.6.39.2/kernel/lockdep_proc.c 2011-05-22 19:36:33.000000000 -0400
68108 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, v
68109
68110 static void print_name(struct seq_file *m, struct lock_class *class)
68111 {
68112 - char str[128];
68113 + char str[KSYM_NAME_LEN];
68114 const char *name = class->name;
68115
68116 if (!name) {
68117 diff -urNp linux-2.6.39.2/kernel/module.c linux-2.6.39.2/kernel/module.c
68118 --- linux-2.6.39.2/kernel/module.c 2011-05-19 00:06:34.000000000 -0400
68119 +++ linux-2.6.39.2/kernel/module.c 2011-05-22 19:41:42.000000000 -0400
68120 @@ -57,6 +57,7 @@
68121 #include <linux/kmemleak.h>
68122 #include <linux/jump_label.h>
68123 #include <linux/pfn.h>
68124 +#include <linux/grsecurity.h>
68125
68126 #define CREATE_TRACE_POINTS
68127 #include <trace/events/module.h>
68128 @@ -118,7 +119,8 @@ static BLOCKING_NOTIFIER_HEAD(module_not
68129
68130 /* Bounds of module allocation, for speeding __module_address.
68131 * Protected by module_mutex. */
68132 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68133 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68134 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68135
68136 int register_module_notifier(struct notifier_block * nb)
68137 {
68138 @@ -282,7 +284,7 @@ bool each_symbol(bool (*fn)(const struct
68139 return true;
68140
68141 list_for_each_entry_rcu(mod, &modules, list) {
68142 - struct symsearch arr[] = {
68143 + struct symsearch modarr[] = {
68144 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68145 NOT_GPL_ONLY, false },
68146 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68147 @@ -304,7 +306,7 @@ bool each_symbol(bool (*fn)(const struct
68148 #endif
68149 };
68150
68151 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68152 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68153 return true;
68154 }
68155 return false;
68156 @@ -415,7 +417,7 @@ static inline void __percpu *mod_percpu(
68157 static int percpu_modalloc(struct module *mod,
68158 unsigned long size, unsigned long align)
68159 {
68160 - if (align > PAGE_SIZE) {
68161 + if (align-1 >= PAGE_SIZE) {
68162 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68163 mod->name, align, PAGE_SIZE);
68164 align = PAGE_SIZE;
68165 @@ -1143,7 +1145,7 @@ resolve_symbol_wait(struct module *mod,
68166 */
68167 #ifdef CONFIG_SYSFS
68168
68169 -#ifdef CONFIG_KALLSYMS
68170 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68171 static inline bool sect_empty(const Elf_Shdr *sect)
68172 {
68173 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68174 @@ -1612,17 +1614,17 @@ void unset_section_ro_nx(struct module *
68175 {
68176 unsigned long total_pages;
68177
68178 - if (mod->module_core == module_region) {
68179 + if (mod->module_core_rx == module_region) {
68180 /* Set core as NX+RW */
68181 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_core, mod->core_size);
68182 - set_memory_nx((unsigned long)mod->module_core, total_pages);
68183 - set_memory_rw((unsigned long)mod->module_core, total_pages);
68184 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_core_rx, mod->core_size_rx);
68185 + set_memory_nx((unsigned long)mod->module_core_rx, total_pages);
68186 + set_memory_rw((unsigned long)mod->module_core_rx, total_pages);
68187
68188 - } else if (mod->module_init == module_region) {
68189 + } else if (mod->module_init_rx == module_region) {
68190 /* Set init as NX+RW */
68191 - total_pages = MOD_NUMBER_OF_PAGES(mod->module_init, mod->init_size);
68192 - set_memory_nx((unsigned long)mod->module_init, total_pages);
68193 - set_memory_rw((unsigned long)mod->module_init, total_pages);
68194 + total_pages = MOD_NUMBER_OF_PAGES(mod->module_init_rx, mod->init_size_rx);
68195 + set_memory_nx((unsigned long)mod->module_init_rx, total_pages);
68196 + set_memory_rw((unsigned long)mod->module_init_rx, total_pages);
68197 }
68198 }
68199
68200 @@ -1633,14 +1635,14 @@ void set_all_modules_text_rw()
68201
68202 mutex_lock(&module_mutex);
68203 list_for_each_entry_rcu(mod, &modules, list) {
68204 - if ((mod->module_core) && (mod->core_text_size)) {
68205 - set_page_attributes(mod->module_core,
68206 - mod->module_core + mod->core_text_size,
68207 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68208 + set_page_attributes(mod->module_core_rx,
68209 + mod->module_core_rx + mod->core_size_rx,
68210 set_memory_rw);
68211 }
68212 - if ((mod->module_init) && (mod->init_text_size)) {
68213 - set_page_attributes(mod->module_init,
68214 - mod->module_init + mod->init_text_size,
68215 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68216 + set_page_attributes(mod->module_init_rx,
68217 + mod->module_init_rx + mod->init_size_rx,
68218 set_memory_rw);
68219 }
68220 }
68221 @@ -1654,14 +1656,14 @@ void set_all_modules_text_ro()
68222
68223 mutex_lock(&module_mutex);
68224 list_for_each_entry_rcu(mod, &modules, list) {
68225 - if ((mod->module_core) && (mod->core_text_size)) {
68226 - set_page_attributes(mod->module_core,
68227 - mod->module_core + mod->core_text_size,
68228 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68229 + set_page_attributes(mod->module_core_rx,
68230 + mod->module_core_rx + mod->core_size_rx,
68231 set_memory_ro);
68232 }
68233 - if ((mod->module_init) && (mod->init_text_size)) {
68234 - set_page_attributes(mod->module_init,
68235 - mod->module_init + mod->init_text_size,
68236 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68237 + set_page_attributes(mod->module_init_rx,
68238 + mod->module_init_rx + mod->init_size_rx,
68239 set_memory_ro);
68240 }
68241 }
68242 @@ -1696,17 +1698,20 @@ static void free_module(struct module *m
68243 destroy_params(mod->kp, mod->num_kp);
68244
68245 /* This may be NULL, but that's OK */
68246 - unset_section_ro_nx(mod, mod->module_init);
68247 - module_free(mod, mod->module_init);
68248 + unset_section_ro_nx(mod, mod->module_init_rx);
68249 + module_free(mod, mod->module_init_rw);
68250 + module_free_exec(mod, mod->module_init_rx);
68251 kfree(mod->args);
68252 percpu_modfree(mod);
68253
68254 /* Free lock-classes: */
68255 - lockdep_free_key_range(mod->module_core, mod->core_size);
68256 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68257 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68258
68259 /* Finally, free the core (containing the module structure) */
68260 - unset_section_ro_nx(mod, mod->module_core);
68261 - module_free(mod, mod->module_core);
68262 + unset_section_ro_nx(mod, mod->module_core_rx);
68263 + module_free_exec(mod, mod->module_core_rx);
68264 + module_free(mod, mod->module_core_rw);
68265
68266 #ifdef CONFIG_MPU
68267 update_protections(current->mm);
68268 @@ -1775,10 +1780,31 @@ static int simplify_symbols(struct modul
68269 unsigned int i;
68270 int ret = 0;
68271 const struct kernel_symbol *ksym;
68272 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68273 + int is_fs_load = 0;
68274 + int register_filesystem_found = 0;
68275 + char *p;
68276 +
68277 + p = strstr(mod->args, "grsec_modharden_fs");
68278 + if (p) {
68279 + char *endptr = p + strlen("grsec_modharden_fs");
68280 + /* copy \0 as well */
68281 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68282 + is_fs_load = 1;
68283 + }
68284 +#endif
68285
68286 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68287 const char *name = info->strtab + sym[i].st_name;
68288
68289 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68290 + /* it's a real shame this will never get ripped and copied
68291 + upstream! ;(
68292 + */
68293 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68294 + register_filesystem_found = 1;
68295 +#endif
68296 +
68297 switch (sym[i].st_shndx) {
68298 case SHN_COMMON:
68299 /* We compiled with -fno-common. These are not
68300 @@ -1799,7 +1825,9 @@ static int simplify_symbols(struct modul
68301 ksym = resolve_symbol_wait(mod, info, name);
68302 /* Ok if resolved. */
68303 if (ksym && !IS_ERR(ksym)) {
68304 + pax_open_kernel();
68305 sym[i].st_value = ksym->value;
68306 + pax_close_kernel();
68307 break;
68308 }
68309
68310 @@ -1818,11 +1846,20 @@ static int simplify_symbols(struct modul
68311 secbase = (unsigned long)mod_percpu(mod);
68312 else
68313 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68314 + pax_open_kernel();
68315 sym[i].st_value += secbase;
68316 + pax_close_kernel();
68317 break;
68318 }
68319 }
68320
68321 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68322 + if (is_fs_load && !register_filesystem_found) {
68323 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68324 + ret = -EPERM;
68325 + }
68326 +#endif
68327 +
68328 return ret;
68329 }
68330
68331 @@ -1906,22 +1943,12 @@ static void layout_sections(struct modul
68332 || s->sh_entsize != ~0UL
68333 || strstarts(sname, ".init"))
68334 continue;
68335 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68336 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68337 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68338 + else
68339 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68340 DEBUGP("\t%s\n", name);
68341 }
68342 - switch (m) {
68343 - case 0: /* executable */
68344 - mod->core_size = debug_align(mod->core_size);
68345 - mod->core_text_size = mod->core_size;
68346 - break;
68347 - case 1: /* RO: text and ro-data */
68348 - mod->core_size = debug_align(mod->core_size);
68349 - mod->core_ro_size = mod->core_size;
68350 - break;
68351 - case 3: /* whole core */
68352 - mod->core_size = debug_align(mod->core_size);
68353 - break;
68354 - }
68355 }
68356
68357 DEBUGP("Init section allocation order:\n");
68358 @@ -1935,23 +1962,13 @@ static void layout_sections(struct modul
68359 || s->sh_entsize != ~0UL
68360 || !strstarts(sname, ".init"))
68361 continue;
68362 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68363 - | INIT_OFFSET_MASK);
68364 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68365 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68366 + else
68367 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68368 + s->sh_entsize |= INIT_OFFSET_MASK;
68369 DEBUGP("\t%s\n", sname);
68370 }
68371 - switch (m) {
68372 - case 0: /* executable */
68373 - mod->init_size = debug_align(mod->init_size);
68374 - mod->init_text_size = mod->init_size;
68375 - break;
68376 - case 1: /* RO: text and ro-data */
68377 - mod->init_size = debug_align(mod->init_size);
68378 - mod->init_ro_size = mod->init_size;
68379 - break;
68380 - case 3: /* whole init */
68381 - mod->init_size = debug_align(mod->init_size);
68382 - break;
68383 - }
68384 }
68385 }
68386
68387 @@ -2119,7 +2136,7 @@ static void layout_symtab(struct module
68388
68389 /* Put symbol section at end of init part of module. */
68390 symsect->sh_flags |= SHF_ALLOC;
68391 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68392 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68393 info->index.sym) | INIT_OFFSET_MASK;
68394 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
68395
68396 @@ -2136,19 +2153,19 @@ static void layout_symtab(struct module
68397 }
68398
68399 /* Append room for core symbols at end of core part. */
68400 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68401 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68402 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68403 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68404
68405 /* Put string table section at end of init part of module. */
68406 strsect->sh_flags |= SHF_ALLOC;
68407 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68408 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68409 info->index.str) | INIT_OFFSET_MASK;
68410 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
68411
68412 /* Append room for core symbols' strings at end of core part. */
68413 - info->stroffs = mod->core_size;
68414 + info->stroffs = mod->core_size_rx;
68415 __set_bit(0, info->strmap);
68416 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
68417 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
68418 }
68419
68420 static void add_kallsyms(struct module *mod, const struct load_info *info)
68421 @@ -2164,11 +2181,13 @@ static void add_kallsyms(struct module *
68422 /* Make sure we get permanent strtab: don't use info->strtab. */
68423 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68424
68425 + pax_open_kernel();
68426 +
68427 /* Set types up while we still have access to sections. */
68428 for (i = 0; i < mod->num_symtab; i++)
68429 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68430
68431 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68432 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68433 src = mod->symtab;
68434 *dst = *src;
68435 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
68436 @@ -2181,10 +2200,12 @@ static void add_kallsyms(struct module *
68437 }
68438 mod->core_num_syms = ndst;
68439
68440 - mod->core_strtab = s = mod->module_core + info->stroffs;
68441 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68442 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
68443 if (test_bit(i, info->strmap))
68444 *++s = mod->strtab[i];
68445 +
68446 + pax_close_kernel();
68447 }
68448 #else
68449 static inline void layout_symtab(struct module *mod, struct load_info *info)
68450 @@ -2213,17 +2234,33 @@ static void dynamic_debug_remove(struct
68451 ddebug_remove_module(debug->modname);
68452 }
68453
68454 -static void *module_alloc_update_bounds(unsigned long size)
68455 +static void *module_alloc_update_bounds_rw(unsigned long size)
68456 {
68457 void *ret = module_alloc(size);
68458
68459 if (ret) {
68460 mutex_lock(&module_mutex);
68461 /* Update module bounds. */
68462 - if ((unsigned long)ret < module_addr_min)
68463 - module_addr_min = (unsigned long)ret;
68464 - if ((unsigned long)ret + size > module_addr_max)
68465 - module_addr_max = (unsigned long)ret + size;
68466 + if ((unsigned long)ret < module_addr_min_rw)
68467 + module_addr_min_rw = (unsigned long)ret;
68468 + if ((unsigned long)ret + size > module_addr_max_rw)
68469 + module_addr_max_rw = (unsigned long)ret + size;
68470 + mutex_unlock(&module_mutex);
68471 + }
68472 + return ret;
68473 +}
68474 +
68475 +static void *module_alloc_update_bounds_rx(unsigned long size)
68476 +{
68477 + void *ret = module_alloc_exec(size);
68478 +
68479 + if (ret) {
68480 + mutex_lock(&module_mutex);
68481 + /* Update module bounds. */
68482 + if ((unsigned long)ret < module_addr_min_rx)
68483 + module_addr_min_rx = (unsigned long)ret;
68484 + if ((unsigned long)ret + size > module_addr_max_rx)
68485 + module_addr_max_rx = (unsigned long)ret + size;
68486 mutex_unlock(&module_mutex);
68487 }
68488 return ret;
68489 @@ -2516,7 +2553,7 @@ static int move_module(struct module *mo
68490 void *ptr;
68491
68492 /* Do the allocs. */
68493 - ptr = module_alloc_update_bounds(mod->core_size);
68494 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68495 /*
68496 * The pointer to this block is stored in the module structure
68497 * which is inside the block. Just mark it as not being a
68498 @@ -2526,23 +2563,50 @@ static int move_module(struct module *mo
68499 if (!ptr)
68500 return -ENOMEM;
68501
68502 - memset(ptr, 0, mod->core_size);
68503 - mod->module_core = ptr;
68504 + memset(ptr, 0, mod->core_size_rw);
68505 + mod->module_core_rw = ptr;
68506
68507 - ptr = module_alloc_update_bounds(mod->init_size);
68508 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68509 /*
68510 * The pointer to this block is stored in the module structure
68511 * which is inside the block. This block doesn't need to be
68512 * scanned as it contains data and code that will be freed
68513 * after the module is initialized.
68514 */
68515 - kmemleak_ignore(ptr);
68516 - if (!ptr && mod->init_size) {
68517 - module_free(mod, mod->module_core);
68518 + kmemleak_not_leak(ptr);
68519 + if (!ptr && mod->init_size_rw) {
68520 + module_free(mod, mod->module_core_rw);
68521 return -ENOMEM;
68522 }
68523 - memset(ptr, 0, mod->init_size);
68524 - mod->module_init = ptr;
68525 + memset(ptr, 0, mod->init_size_rw);
68526 + mod->module_init_rw = ptr;
68527 +
68528 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68529 + kmemleak_not_leak(ptr);
68530 + if (!ptr) {
68531 + module_free(mod, mod->module_init_rw);
68532 + module_free(mod, mod->module_core_rw);
68533 + return -ENOMEM;
68534 + }
68535 +
68536 + pax_open_kernel();
68537 + memset(ptr, 0, mod->core_size_rx);
68538 + pax_close_kernel();
68539 + mod->module_core_rx = ptr;
68540 +
68541 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68542 + kmemleak_not_leak(ptr);
68543 + if (!ptr && mod->init_size_rx) {
68544 + module_free_exec(mod, mod->module_core_rx);
68545 + module_free(mod, mod->module_init_rw);
68546 + module_free(mod, mod->module_core_rw);
68547 + return -ENOMEM;
68548 + }
68549 +
68550 + pax_open_kernel();
68551 + memset(ptr, 0, mod->init_size_rx);
68552 + pax_close_kernel();
68553 + mod->module_init_rx = ptr;
68554
68555 /* Transfer each section which specifies SHF_ALLOC */
68556 DEBUGP("final section addresses:\n");
68557 @@ -2553,16 +2617,45 @@ static int move_module(struct module *mo
68558 if (!(shdr->sh_flags & SHF_ALLOC))
68559 continue;
68560
68561 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68562 - dest = mod->module_init
68563 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68564 - else
68565 - dest = mod->module_core + shdr->sh_entsize;
68566 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68567 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68568 + dest = mod->module_init_rw
68569 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68570 + else
68571 + dest = mod->module_init_rx
68572 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68573 + } else {
68574 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68575 + dest = mod->module_core_rw + shdr->sh_entsize;
68576 + else
68577 + dest = mod->module_core_rx + shdr->sh_entsize;
68578 + }
68579 +
68580 + if (shdr->sh_type != SHT_NOBITS) {
68581 +
68582 +#ifdef CONFIG_PAX_KERNEXEC
68583 +#ifdef CONFIG_X86_64
68584 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68585 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68586 +#endif
68587 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68588 + pax_open_kernel();
68589 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68590 + pax_close_kernel();
68591 + } else
68592 +#endif
68593
68594 - if (shdr->sh_type != SHT_NOBITS)
68595 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68596 + }
68597 /* Update sh_addr to point to copy in image. */
68598 - shdr->sh_addr = (unsigned long)dest;
68599 +
68600 +#ifdef CONFIG_PAX_KERNEXEC
68601 + if (shdr->sh_flags & SHF_EXECINSTR)
68602 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68603 + else
68604 +#endif
68605 +
68606 + shdr->sh_addr = (unsigned long)dest;
68607 DEBUGP("\t0x%lx %s\n",
68608 shdr->sh_addr, info->secstrings + shdr->sh_name);
68609 }
68610 @@ -2613,12 +2706,12 @@ static void flush_module_icache(const st
68611 * Do it before processing of module parameters, so the module
68612 * can provide parameter accessor functions of its own.
68613 */
68614 - if (mod->module_init)
68615 - flush_icache_range((unsigned long)mod->module_init,
68616 - (unsigned long)mod->module_init
68617 - + mod->init_size);
68618 - flush_icache_range((unsigned long)mod->module_core,
68619 - (unsigned long)mod->module_core + mod->core_size);
68620 + if (mod->module_init_rx)
68621 + flush_icache_range((unsigned long)mod->module_init_rx,
68622 + (unsigned long)mod->module_init_rx
68623 + + mod->init_size_rx);
68624 + flush_icache_range((unsigned long)mod->module_core_rx,
68625 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68626
68627 set_fs(old_fs);
68628 }
68629 @@ -2690,8 +2783,10 @@ static void module_deallocate(struct mod
68630 {
68631 kfree(info->strmap);
68632 percpu_modfree(mod);
68633 - module_free(mod, mod->module_init);
68634 - module_free(mod, mod->module_core);
68635 + module_free_exec(mod, mod->module_init_rx);
68636 + module_free_exec(mod, mod->module_core_rx);
68637 + module_free(mod, mod->module_init_rw);
68638 + module_free(mod, mod->module_core_rw);
68639 }
68640
68641 static int post_relocation(struct module *mod, const struct load_info *info)
68642 @@ -2748,9 +2843,38 @@ static struct module *load_module(void _
68643 if (err)
68644 goto free_unload;
68645
68646 + /* Now copy in args */
68647 + mod->args = strndup_user(uargs, ~0UL >> 1);
68648 + if (IS_ERR(mod->args)) {
68649 + err = PTR_ERR(mod->args);
68650 + goto free_unload;
68651 + }
68652 +
68653 /* Set up MODINFO_ATTR fields */
68654 setup_modinfo(mod, &info);
68655
68656 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68657 + {
68658 + char *p, *p2;
68659 +
68660 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68661 + printk(KERN_ALERT "grsec: denied auto-loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%.64s instead.", mod->name);
68662 + err = -EPERM;
68663 + goto free_modinfo;
68664 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68665 + p += strlen("grsec_modharden_normal");
68666 + p2 = strstr(p, "_");
68667 + if (p2) {
68668 + *p2 = '\0';
68669 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68670 + *p2 = '_';
68671 + }
68672 + err = -EPERM;
68673 + goto free_modinfo;
68674 + }
68675 + }
68676 +#endif
68677 +
68678 /* Fix up syms, so that st_value is a pointer to location. */
68679 err = simplify_symbols(mod, &info);
68680 if (err < 0)
68681 @@ -2766,13 +2890,6 @@ static struct module *load_module(void _
68682
68683 flush_module_icache(mod);
68684
68685 - /* Now copy in args */
68686 - mod->args = strndup_user(uargs, ~0UL >> 1);
68687 - if (IS_ERR(mod->args)) {
68688 - err = PTR_ERR(mod->args);
68689 - goto free_arch_cleanup;
68690 - }
68691 -
68692 /* Mark state as coming so strong_try_module_get() ignores us. */
68693 mod->state = MODULE_STATE_COMING;
68694
68695 @@ -2832,11 +2949,10 @@ static struct module *load_module(void _
68696 unlock:
68697 mutex_unlock(&module_mutex);
68698 synchronize_sched();
68699 - kfree(mod->args);
68700 - free_arch_cleanup:
68701 module_arch_cleanup(mod);
68702 free_modinfo:
68703 free_modinfo(mod);
68704 + kfree(mod->args);
68705 free_unload:
68706 module_unload_free(mod);
68707 free_module:
68708 @@ -2877,16 +2993,16 @@ SYSCALL_DEFINE3(init_module, void __user
68709 MODULE_STATE_COMING, mod);
68710
68711 /* Set RO and NX regions for core */
68712 - set_section_ro_nx(mod->module_core,
68713 - mod->core_text_size,
68714 - mod->core_ro_size,
68715 - mod->core_size);
68716 + set_section_ro_nx(mod->module_core_rx,
68717 + mod->core_size_rx,
68718 + mod->core_size_rx,
68719 + mod->core_size_rx);
68720
68721 /* Set RO and NX regions for init */
68722 - set_section_ro_nx(mod->module_init,
68723 - mod->init_text_size,
68724 - mod->init_ro_size,
68725 - mod->init_size);
68726 + set_section_ro_nx(mod->module_init_rx,
68727 + mod->init_size_rx,
68728 + mod->init_size_rx,
68729 + mod->init_size_rx);
68730
68731 do_mod_ctors(mod);
68732 /* Start the module */
68733 @@ -2931,11 +3047,13 @@ SYSCALL_DEFINE3(init_module, void __user
68734 mod->symtab = mod->core_symtab;
68735 mod->strtab = mod->core_strtab;
68736 #endif
68737 - unset_section_ro_nx(mod, mod->module_init);
68738 - module_free(mod, mod->module_init);
68739 - mod->module_init = NULL;
68740 - mod->init_size = 0;
68741 - mod->init_text_size = 0;
68742 + unset_section_ro_nx(mod, mod->module_init_rx);
68743 + module_free(mod, mod->module_init_rw);
68744 + module_free_exec(mod, mod->module_init_rx);
68745 + mod->module_init_rw = NULL;
68746 + mod->module_init_rx = NULL;
68747 + mod->init_size_rw = 0;
68748 + mod->init_size_rx = 0;
68749 mutex_unlock(&module_mutex);
68750
68751 return 0;
68752 @@ -2966,10 +3084,16 @@ static const char *get_ksymbol(struct mo
68753 unsigned long nextval;
68754
68755 /* At worse, next value is at end of module */
68756 - if (within_module_init(addr, mod))
68757 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68758 + if (within_module_init_rx(addr, mod))
68759 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68760 + else if (within_module_init_rw(addr, mod))
68761 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68762 + else if (within_module_core_rx(addr, mod))
68763 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68764 + else if (within_module_core_rw(addr, mod))
68765 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68766 else
68767 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68768 + return NULL;
68769
68770 /* Scan for closest preceding symbol, and next symbol. (ELF
68771 starts real symbols at 1). */
68772 @@ -3215,7 +3339,7 @@ static int m_show(struct seq_file *m, vo
68773 char buf[8];
68774
68775 seq_printf(m, "%s %u",
68776 - mod->name, mod->init_size + mod->core_size);
68777 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68778 print_unload_info(m, mod);
68779
68780 /* Informative for users. */
68781 @@ -3224,7 +3348,7 @@ static int m_show(struct seq_file *m, vo
68782 mod->state == MODULE_STATE_COMING ? "Loading":
68783 "Live");
68784 /* Used by oprofile and other similar tools. */
68785 - seq_printf(m, " 0x%pK", mod->module_core);
68786 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68787
68788 /* Taints info */
68789 if (mod->taints)
68790 @@ -3260,7 +3384,17 @@ static const struct file_operations proc
68791
68792 static int __init proc_modules_init(void)
68793 {
68794 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68795 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68796 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68797 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68798 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68799 +#else
68800 proc_create("modules", 0, NULL, &proc_modules_operations);
68801 +#endif
68802 +#else
68803 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68804 +#endif
68805 return 0;
68806 }
68807 module_init(proc_modules_init);
68808 @@ -3319,12 +3453,12 @@ struct module *__module_address(unsigned
68809 {
68810 struct module *mod;
68811
68812 - if (addr < module_addr_min || addr > module_addr_max)
68813 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68814 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68815 return NULL;
68816
68817 list_for_each_entry_rcu(mod, &modules, list)
68818 - if (within_module_core(addr, mod)
68819 - || within_module_init(addr, mod))
68820 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68821 return mod;
68822 return NULL;
68823 }
68824 @@ -3358,11 +3492,20 @@ bool is_module_text_address(unsigned lon
68825 */
68826 struct module *__module_text_address(unsigned long addr)
68827 {
68828 - struct module *mod = __module_address(addr);
68829 + struct module *mod;
68830 +
68831 +#ifdef CONFIG_X86_32
68832 + addr = ktla_ktva(addr);
68833 +#endif
68834 +
68835 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68836 + return NULL;
68837 +
68838 + mod = __module_address(addr);
68839 +
68840 if (mod) {
68841 /* Make sure it's within the text section. */
68842 - if (!within(addr, mod->module_init, mod->init_text_size)
68843 - && !within(addr, mod->module_core, mod->core_text_size))
68844 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68845 mod = NULL;
68846 }
68847 return mod;
68848 diff -urNp linux-2.6.39.2/kernel/mutex.c linux-2.6.39.2/kernel/mutex.c
68849 --- linux-2.6.39.2/kernel/mutex.c 2011-05-19 00:06:34.000000000 -0400
68850 +++ linux-2.6.39.2/kernel/mutex.c 2011-05-22 19:36:33.000000000 -0400
68851 @@ -160,7 +160,7 @@ __mutex_lock_common(struct mutex *lock,
68852 */
68853
68854 for (;;) {
68855 - struct thread_info *owner;
68856 + struct task_struct *owner;
68857
68858 /*
68859 * If we own the BKL, then don't spin. The owner of
68860 @@ -205,7 +205,7 @@ __mutex_lock_common(struct mutex *lock,
68861 spin_lock_mutex(&lock->wait_lock, flags);
68862
68863 debug_mutex_lock_common(lock, &waiter);
68864 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68865 + debug_mutex_add_waiter(lock, &waiter, task);
68866
68867 /* add waiting tasks to the end of the waitqueue (FIFO): */
68868 list_add_tail(&waiter.list, &lock->wait_list);
68869 @@ -234,8 +234,7 @@ __mutex_lock_common(struct mutex *lock,
68870 * TASK_UNINTERRUPTIBLE case.)
68871 */
68872 if (unlikely(signal_pending_state(state, task))) {
68873 - mutex_remove_waiter(lock, &waiter,
68874 - task_thread_info(task));
68875 + mutex_remove_waiter(lock, &waiter, task);
68876 mutex_release(&lock->dep_map, 1, ip);
68877 spin_unlock_mutex(&lock->wait_lock, flags);
68878
68879 @@ -256,7 +255,7 @@ __mutex_lock_common(struct mutex *lock,
68880 done:
68881 lock_acquired(&lock->dep_map, ip);
68882 /* got the lock - rejoice! */
68883 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68884 + mutex_remove_waiter(lock, &waiter, task);
68885 mutex_set_owner(lock);
68886
68887 /* set it to 0 if there are no waiters left: */
68888 diff -urNp linux-2.6.39.2/kernel/mutex-debug.c linux-2.6.39.2/kernel/mutex-debug.c
68889 --- linux-2.6.39.2/kernel/mutex-debug.c 2011-05-19 00:06:34.000000000 -0400
68890 +++ linux-2.6.39.2/kernel/mutex-debug.c 2011-05-22 19:36:33.000000000 -0400
68891 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mute
68892 }
68893
68894 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68895 - struct thread_info *ti)
68896 + struct task_struct *task)
68897 {
68898 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68899
68900 /* Mark the current thread as blocked on the lock: */
68901 - ti->task->blocked_on = waiter;
68902 + task->blocked_on = waiter;
68903 }
68904
68905 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68906 - struct thread_info *ti)
68907 + struct task_struct *task)
68908 {
68909 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68910 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68911 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68912 - ti->task->blocked_on = NULL;
68913 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68914 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68915 + task->blocked_on = NULL;
68916
68917 list_del_init(&waiter->list);
68918 waiter->task = NULL;
68919 @@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lo
68920 return;
68921
68922 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
68923 - DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
68924 + DEBUG_LOCKS_WARN_ON(lock->owner != current);
68925 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
68926 mutex_clear_owner(lock);
68927 }
68928 diff -urNp linux-2.6.39.2/kernel/mutex-debug.h linux-2.6.39.2/kernel/mutex-debug.h
68929 --- linux-2.6.39.2/kernel/mutex-debug.h 2011-05-19 00:06:34.000000000 -0400
68930 +++ linux-2.6.39.2/kernel/mutex-debug.h 2011-05-22 19:36:33.000000000 -0400
68931 @@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(stru
68932 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68933 extern void debug_mutex_add_waiter(struct mutex *lock,
68934 struct mutex_waiter *waiter,
68935 - struct thread_info *ti);
68936 + struct task_struct *task);
68937 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68938 - struct thread_info *ti);
68939 + struct task_struct *task);
68940 extern void debug_mutex_unlock(struct mutex *lock);
68941 extern void debug_mutex_init(struct mutex *lock, const char *name,
68942 struct lock_class_key *key);
68943
68944 static inline void mutex_set_owner(struct mutex *lock)
68945 {
68946 - lock->owner = current_thread_info();
68947 + lock->owner = current;
68948 }
68949
68950 static inline void mutex_clear_owner(struct mutex *lock)
68951 diff -urNp linux-2.6.39.2/kernel/mutex.h linux-2.6.39.2/kernel/mutex.h
68952 --- linux-2.6.39.2/kernel/mutex.h 2011-05-19 00:06:34.000000000 -0400
68953 +++ linux-2.6.39.2/kernel/mutex.h 2011-05-22 19:36:33.000000000 -0400
68954 @@ -19,7 +19,7 @@
68955 #ifdef CONFIG_SMP
68956 static inline void mutex_set_owner(struct mutex *lock)
68957 {
68958 - lock->owner = current_thread_info();
68959 + lock->owner = current;
68960 }
68961
68962 static inline void mutex_clear_owner(struct mutex *lock)
68963 diff -urNp linux-2.6.39.2/kernel/padata.c linux-2.6.39.2/kernel/padata.c
68964 --- linux-2.6.39.2/kernel/padata.c 2011-05-19 00:06:34.000000000 -0400
68965 +++ linux-2.6.39.2/kernel/padata.c 2011-05-22 19:36:33.000000000 -0400
68966 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_ins
68967 padata->pd = pd;
68968 padata->cb_cpu = cb_cpu;
68969
68970 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68971 - atomic_set(&pd->seq_nr, -1);
68972 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68973 + atomic_set_unchecked(&pd->seq_nr, -1);
68974
68975 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68976 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68977
68978 target_cpu = padata_cpu_hash(padata);
68979 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68980 @@ -444,7 +444,7 @@ static struct parallel_data *padata_allo
68981 padata_init_pqueues(pd);
68982 padata_init_squeues(pd);
68983 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68984 - atomic_set(&pd->seq_nr, -1);
68985 + atomic_set_unchecked(&pd->seq_nr, -1);
68986 atomic_set(&pd->reorder_objects, 0);
68987 atomic_set(&pd->refcnt, 0);
68988 pd->pinst = pinst;
68989 diff -urNp linux-2.6.39.2/kernel/panic.c linux-2.6.39.2/kernel/panic.c
68990 --- linux-2.6.39.2/kernel/panic.c 2011-05-19 00:06:34.000000000 -0400
68991 +++ linux-2.6.39.2/kernel/panic.c 2011-05-22 19:41:42.000000000 -0400
68992 @@ -369,7 +369,7 @@ static void warn_slowpath_common(const c
68993 const char *board;
68994
68995 printk(KERN_WARNING "------------[ cut here ]------------\n");
68996 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68997 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68998 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68999 if (board)
69000 printk(KERN_WARNING "Hardware name: %s\n", board);
69001 @@ -424,7 +424,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69002 */
69003 void __stack_chk_fail(void)
69004 {
69005 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69006 + dump_stack();
69007 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69008 __builtin_return_address(0));
69009 }
69010 EXPORT_SYMBOL(__stack_chk_fail);
69011 diff -urNp linux-2.6.39.2/kernel/params.c linux-2.6.39.2/kernel/params.c
69012 --- linux-2.6.39.2/kernel/params.c 2011-05-19 00:06:34.000000000 -0400
69013 +++ linux-2.6.39.2/kernel/params.c 2011-05-22 19:36:33.000000000 -0400
69014 @@ -234,7 +234,7 @@ int parse_args(const char *name,
69015 { \
69016 return sprintf(buffer, format, *((type *)kp->arg)); \
69017 } \
69018 - struct kernel_param_ops param_ops_##name = { \
69019 + const struct kernel_param_ops param_ops_##name = { \
69020 .set = param_set_##name, \
69021 .get = param_get_##name, \
69022 }; \
69023 @@ -286,7 +286,7 @@ static void param_free_charp(void *arg)
69024 maybe_kfree_parameter(*((char **)arg));
69025 }
69026
69027 -struct kernel_param_ops param_ops_charp = {
69028 +const struct kernel_param_ops param_ops_charp = {
69029 .set = param_set_charp,
69030 .get = param_get_charp,
69031 .free = param_free_charp,
69032 @@ -334,7 +334,7 @@ int param_get_bool(char *buffer, const s
69033 }
69034 EXPORT_SYMBOL(param_get_bool);
69035
69036 -struct kernel_param_ops param_ops_bool = {
69037 +const struct kernel_param_ops param_ops_bool = {
69038 .set = param_set_bool,
69039 .get = param_get_bool,
69040 };
69041 @@ -362,7 +362,7 @@ int param_get_invbool(char *buffer, cons
69042 }
69043 EXPORT_SYMBOL(param_get_invbool);
69044
69045 -struct kernel_param_ops param_ops_invbool = {
69046 +const struct kernel_param_ops param_ops_invbool = {
69047 .set = param_set_invbool,
69048 .get = param_get_invbool,
69049 };
69050 @@ -460,7 +460,7 @@ static void param_array_free(void *arg)
69051 arr->ops->free(arr->elem + arr->elemsize * i);
69052 }
69053
69054 -struct kernel_param_ops param_array_ops = {
69055 +const struct kernel_param_ops param_array_ops = {
69056 .set = param_array_set,
69057 .get = param_array_get,
69058 .free = param_array_free,
69059 @@ -488,7 +488,7 @@ int param_get_string(char *buffer, const
69060 }
69061 EXPORT_SYMBOL(param_get_string);
69062
69063 -struct kernel_param_ops param_ops_string = {
69064 +const struct kernel_param_ops param_ops_string = {
69065 .set = param_set_copystring,
69066 .get = param_get_string,
69067 };
69068 diff -urNp linux-2.6.39.2/kernel/perf_event.c linux-2.6.39.2/kernel/perf_event.c
69069 --- linux-2.6.39.2/kernel/perf_event.c 2011-05-19 00:06:34.000000000 -0400
69070 +++ linux-2.6.39.2/kernel/perf_event.c 2011-05-22 19:36:33.000000000 -0400
69071 @@ -170,7 +170,7 @@ int perf_proc_update_handler(struct ctl_
69072 return 0;
69073 }
69074
69075 -static atomic64_t perf_event_id;
69076 +static atomic64_unchecked_t perf_event_id;
69077
69078 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69079 enum event_type_t event_type);
69080 @@ -2496,7 +2496,7 @@ static void __perf_event_read(void *info
69081
69082 static inline u64 perf_event_count(struct perf_event *event)
69083 {
69084 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69085 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69086 }
69087
69088 static u64 perf_event_read(struct perf_event *event)
69089 @@ -3031,9 +3031,9 @@ u64 perf_event_read_value(struct perf_ev
69090 mutex_lock(&event->child_mutex);
69091 total += perf_event_read(event);
69092 *enabled += event->total_time_enabled +
69093 - atomic64_read(&event->child_total_time_enabled);
69094 + atomic64_read_unchecked(&event->child_total_time_enabled);
69095 *running += event->total_time_running +
69096 - atomic64_read(&event->child_total_time_running);
69097 + atomic64_read_unchecked(&event->child_total_time_running);
69098
69099 list_for_each_entry(child, &event->child_list, child_list) {
69100 total += perf_event_read(child);
69101 @@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct p
69102 userpg->offset -= local64_read(&event->hw.prev_count);
69103
69104 userpg->time_enabled = event->total_time_enabled +
69105 - atomic64_read(&event->child_total_time_enabled);
69106 + atomic64_read_unchecked(&event->child_total_time_enabled);
69107
69108 userpg->time_running = event->total_time_running +
69109 - atomic64_read(&event->child_total_time_running);
69110 + atomic64_read_unchecked(&event->child_total_time_running);
69111
69112 barrier();
69113 ++userpg->lock;
69114 @@ -3884,16 +3884,16 @@ static void perf_pending_event(struct ir
69115 * Later on, we might change it to a list if there is
69116 * another virtualization implementation supporting the callbacks.
69117 */
69118 -struct perf_guest_info_callbacks *perf_guest_cbs;
69119 +const struct perf_guest_info_callbacks *perf_guest_cbs;
69120
69121 -int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69122 +int perf_register_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69123 {
69124 perf_guest_cbs = cbs;
69125 return 0;
69126 }
69127 EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
69128
69129 -int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
69130 +int perf_unregister_guest_info_callbacks(const struct perf_guest_info_callbacks *cbs)
69131 {
69132 perf_guest_cbs = NULL;
69133 return 0;
69134 @@ -4196,11 +4196,11 @@ static void perf_output_read_one(struct
69135 values[n++] = perf_event_count(event);
69136 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69137 values[n++] = enabled +
69138 - atomic64_read(&event->child_total_time_enabled);
69139 + atomic64_read_unchecked(&event->child_total_time_enabled);
69140 }
69141 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69142 values[n++] = running +
69143 - atomic64_read(&event->child_total_time_running);
69144 + atomic64_read_unchecked(&event->child_total_time_running);
69145 }
69146 if (read_format & PERF_FORMAT_ID)
69147 values[n++] = primary_event_id(event);
69148 @@ -6201,7 +6201,7 @@ perf_event_alloc(struct perf_event_attr
69149 event->parent = parent_event;
69150
69151 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69152 - event->id = atomic64_inc_return(&perf_event_id);
69153 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69154
69155 event->state = PERF_EVENT_STATE_INACTIVE;
69156
69157 @@ -6724,10 +6724,10 @@ static void sync_child_event(struct perf
69158 /*
69159 * Add back the child's count to the parent's count:
69160 */
69161 - atomic64_add(child_val, &parent_event->child_count);
69162 - atomic64_add(child_event->total_time_enabled,
69163 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69164 + atomic64_add_unchecked(child_event->total_time_enabled,
69165 &parent_event->child_total_time_enabled);
69166 - atomic64_add(child_event->total_time_running,
69167 + atomic64_add_unchecked(child_event->total_time_running,
69168 &parent_event->child_total_time_running);
69169
69170 /*
69171 diff -urNp linux-2.6.39.2/kernel/pid.c linux-2.6.39.2/kernel/pid.c
69172 --- linux-2.6.39.2/kernel/pid.c 2011-05-19 00:06:34.000000000 -0400
69173 +++ linux-2.6.39.2/kernel/pid.c 2011-05-22 19:41:42.000000000 -0400
69174 @@ -33,6 +33,7 @@
69175 #include <linux/rculist.h>
69176 #include <linux/bootmem.h>
69177 #include <linux/hash.h>
69178 +#include <linux/security.h>
69179 #include <linux/pid_namespace.h>
69180 #include <linux/init_task.h>
69181 #include <linux/syscalls.h>
69182 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
69183
69184 int pid_max = PID_MAX_DEFAULT;
69185
69186 -#define RESERVED_PIDS 300
69187 +#define RESERVED_PIDS 500
69188
69189 int pid_max_min = RESERVED_PIDS + 1;
69190 int pid_max_max = PID_MAX_LIMIT;
69191 @@ -419,8 +420,15 @@ EXPORT_SYMBOL(pid_task);
69192 */
69193 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69194 {
69195 + struct task_struct *task;
69196 +
69197 rcu_lockdep_assert(rcu_read_lock_held());
69198 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69199 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69200 +
69201 + if (gr_pid_is_chrooted(task))
69202 + return NULL;
69203 +
69204 + return task;
69205 }
69206
69207 struct task_struct *find_task_by_vpid(pid_t vnr)
69208 diff -urNp linux-2.6.39.2/kernel/posix-cpu-timers.c linux-2.6.39.2/kernel/posix-cpu-timers.c
69209 --- linux-2.6.39.2/kernel/posix-cpu-timers.c 2011-05-19 00:06:34.000000000 -0400
69210 +++ linux-2.6.39.2/kernel/posix-cpu-timers.c 2011-05-22 19:41:42.000000000 -0400
69211 @@ -6,6 +6,7 @@
69212 #include <linux/posix-timers.h>
69213 #include <linux/errno.h>
69214 #include <linux/math64.h>
69215 +#include <linux/security.h>
69216 #include <asm/uaccess.h>
69217 #include <linux/kernel_stat.h>
69218 #include <trace/events/timer.h>
69219 @@ -1590,7 +1591,7 @@ static int thread_cpu_timer_create(struc
69220 return posix_cpu_timer_create(timer);
69221 }
69222
69223 -struct k_clock clock_posix_cpu = {
69224 +const struct k_clock clock_posix_cpu = {
69225 .clock_getres = posix_cpu_clock_getres,
69226 .clock_set = posix_cpu_clock_set,
69227 .clock_get = posix_cpu_clock_get,
69228 @@ -1604,14 +1605,14 @@ struct k_clock clock_posix_cpu = {
69229
69230 static __init int init_posix_cpu_timers(void)
69231 {
69232 - struct k_clock process = {
69233 + const struct k_clock process = {
69234 .clock_getres = process_cpu_clock_getres,
69235 .clock_get = process_cpu_clock_get,
69236 .timer_create = process_cpu_timer_create,
69237 .nsleep = process_cpu_nsleep,
69238 .nsleep_restart = process_cpu_nsleep_restart,
69239 };
69240 - struct k_clock thread = {
69241 + const struct k_clock thread = {
69242 .clock_getres = thread_cpu_clock_getres,
69243 .clock_get = thread_cpu_clock_get,
69244 .timer_create = thread_cpu_timer_create,
69245 diff -urNp linux-2.6.39.2/kernel/posix-timers.c linux-2.6.39.2/kernel/posix-timers.c
69246 --- linux-2.6.39.2/kernel/posix-timers.c 2011-05-19 00:06:34.000000000 -0400
69247 +++ linux-2.6.39.2/kernel/posix-timers.c 2011-05-22 20:13:41.000000000 -0400
69248 @@ -43,6 +43,7 @@
69249 #include <linux/idr.h>
69250 #include <linux/posix-clock.h>
69251 #include <linux/posix-timers.h>
69252 +#include <linux/grsecurity.h>
69253 #include <linux/syscalls.h>
69254 #include <linux/wait.h>
69255 #include <linux/workqueue.h>
69256 @@ -227,7 +228,7 @@ static int posix_get_boottime(const cloc
69257 */
69258 static __init int init_posix_timers(void)
69259 {
69260 - struct k_clock clock_realtime = {
69261 + const struct k_clock clock_realtime = {
69262 .clock_getres = hrtimer_get_res,
69263 .clock_get = posix_clock_realtime_get,
69264 .clock_set = posix_clock_realtime_set,
69265 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void
69266 .timer_get = common_timer_get,
69267 .timer_del = common_timer_del,
69268 };
69269 - struct k_clock clock_monotonic = {
69270 + const struct k_clock clock_monotonic = {
69271 .clock_getres = hrtimer_get_res,
69272 .clock_get = posix_ktime_get_ts,
69273 .nsleep = common_nsleep,
69274 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void
69275 .timer_get = common_timer_get,
69276 .timer_del = common_timer_del,
69277 };
69278 - struct k_clock clock_monotonic_raw = {
69279 + const struct k_clock clock_monotonic_raw = {
69280 .clock_getres = hrtimer_get_res,
69281 .clock_get = posix_get_monotonic_raw,
69282 };
69283 - struct k_clock clock_realtime_coarse = {
69284 + const struct k_clock clock_realtime_coarse = {
69285 .clock_getres = posix_get_coarse_res,
69286 .clock_get = posix_get_realtime_coarse,
69287 };
69288 - struct k_clock clock_monotonic_coarse = {
69289 + const struct k_clock clock_monotonic_coarse = {
69290 .clock_getres = posix_get_coarse_res,
69291 .clock_get = posix_get_monotonic_coarse,
69292 };
69293 - struct k_clock clock_boottime = {
69294 + const struct k_clock clock_boottime = {
69295 .clock_getres = hrtimer_get_res,
69296 .clock_get = posix_get_boottime,
69297 .nsleep = common_nsleep,
69298 @@ -272,6 +273,8 @@ static __init int init_posix_timers(void
69299 .timer_del = common_timer_del,
69300 };
69301
69302 + pax_track_stack();
69303 +
69304 posix_timers_register_clock(CLOCK_REALTIME, &clock_realtime);
69305 posix_timers_register_clock(CLOCK_MONOTONIC, &clock_monotonic);
69306 posix_timers_register_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
69307 @@ -454,7 +457,7 @@ static struct pid *good_sigevent(sigeven
69308 }
69309
69310 void posix_timers_register_clock(const clockid_t clock_id,
69311 - struct k_clock *new_clock)
69312 + const struct k_clock *new_clock)
69313 {
69314 if ((unsigned) clock_id >= MAX_CLOCKS) {
69315 printk(KERN_WARNING "POSIX clock register failed for clock_id %d\n",
69316 @@ -506,7 +509,7 @@ static void release_posix_timer(struct k
69317 kmem_cache_free(posix_timers_cache, tmr);
69318 }
69319
69320 -static struct k_clock *clockid_to_kclock(const clockid_t id)
69321 +static const struct k_clock *clockid_to_kclock(const clockid_t id)
69322 {
69323 if (id < 0)
69324 return (id & CLOCKFD_MASK) == CLOCKFD ?
69325 @@ -529,7 +532,7 @@ SYSCALL_DEFINE3(timer_create, const cloc
69326 struct sigevent __user *, timer_event_spec,
69327 timer_t __user *, created_timer_id)
69328 {
69329 - struct k_clock *kc = clockid_to_kclock(which_clock);
69330 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69331 struct k_itimer *new_timer;
69332 int error, new_timer_id;
69333 sigevent_t event;
69334 @@ -714,7 +717,7 @@ SYSCALL_DEFINE2(timer_gettime, timer_t,
69335 {
69336 struct itimerspec cur_setting;
69337 struct k_itimer *timr;
69338 - struct k_clock *kc;
69339 + const struct k_clock *kc;
69340 unsigned long flags;
69341 int ret = 0;
69342
69343 @@ -822,7 +825,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
69344 int error = 0;
69345 unsigned long flag;
69346 struct itimerspec *rtn = old_setting ? &old_spec : NULL;
69347 - struct k_clock *kc;
69348 + const struct k_clock *kc;
69349
69350 if (!new_setting)
69351 return -EINVAL;
69352 @@ -868,7 +871,7 @@ static int common_timer_del(struct k_iti
69353
69354 static inline int timer_delete_hook(struct k_itimer *timer)
69355 {
69356 - struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69357 + const struct k_clock *kc = clockid_to_kclock(timer->it_clock);
69358
69359 if (WARN_ON_ONCE(!kc || !kc->timer_del))
69360 return -EINVAL;
69361 @@ -947,7 +950,7 @@ void exit_itimers(struct signal_struct *
69362 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69363 const struct timespec __user *, tp)
69364 {
69365 - struct k_clock *kc = clockid_to_kclock(which_clock);
69366 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69367 struct timespec new_tp;
69368
69369 if (!kc || !kc->clock_set)
69370 @@ -956,13 +959,20 @@ SYSCALL_DEFINE2(clock_settime, const clo
69371 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69372 return -EFAULT;
69373
69374 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69375 + have their clock_set fptr set to a nosettime dummy function
69376 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69377 + call common_clock_set, which calls do_sys_settimeofday, which
69378 + we hook
69379 + */
69380 +
69381 return kc->clock_set(which_clock, &new_tp);
69382 }
69383
69384 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
69385 struct timespec __user *,tp)
69386 {
69387 - struct k_clock *kc = clockid_to_kclock(which_clock);
69388 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69389 struct timespec kernel_tp;
69390 int error;
69391
69392 @@ -980,7 +990,7 @@ SYSCALL_DEFINE2(clock_gettime, const clo
69393 SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock,
69394 struct timex __user *, utx)
69395 {
69396 - struct k_clock *kc = clockid_to_kclock(which_clock);
69397 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69398 struct timex ktx;
69399 int err;
69400
69401 @@ -1003,7 +1013,7 @@ SYSCALL_DEFINE2(clock_adjtime, const clo
69402 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock,
69403 struct timespec __user *, tp)
69404 {
69405 - struct k_clock *kc = clockid_to_kclock(which_clock);
69406 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69407 struct timespec rtn_tp;
69408 int error;
69409
69410 @@ -1033,7 +1043,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69411 const struct timespec __user *, rqtp,
69412 struct timespec __user *, rmtp)
69413 {
69414 - struct k_clock *kc = clockid_to_kclock(which_clock);
69415 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69416 struct timespec t;
69417
69418 if (!kc)
69419 @@ -1057,7 +1067,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const c
69420 long clock_nanosleep_restart(struct restart_block *restart_block)
69421 {
69422 clockid_t which_clock = restart_block->nanosleep.index;
69423 - struct k_clock *kc = clockid_to_kclock(which_clock);
69424 + const struct k_clock *kc = clockid_to_kclock(which_clock);
69425
69426 if (WARN_ON_ONCE(!kc || !kc->nsleep_restart))
69427 return -EINVAL;
69428 diff -urNp linux-2.6.39.2/kernel/power/poweroff.c linux-2.6.39.2/kernel/power/poweroff.c
69429 --- linux-2.6.39.2/kernel/power/poweroff.c 2011-05-19 00:06:34.000000000 -0400
69430 +++ linux-2.6.39.2/kernel/power/poweroff.c 2011-05-22 19:36:33.000000000 -0400
69431 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
69432 .enable_mask = SYSRQ_ENABLE_BOOT,
69433 };
69434
69435 -static int pm_sysrq_init(void)
69436 +static int __init pm_sysrq_init(void)
69437 {
69438 register_sysrq_key('o', &sysrq_poweroff_op);
69439 return 0;
69440 diff -urNp linux-2.6.39.2/kernel/power/process.c linux-2.6.39.2/kernel/power/process.c
69441 --- linux-2.6.39.2/kernel/power/process.c 2011-05-19 00:06:34.000000000 -0400
69442 +++ linux-2.6.39.2/kernel/power/process.c 2011-05-22 19:36:33.000000000 -0400
69443 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_
69444 u64 elapsed_csecs64;
69445 unsigned int elapsed_csecs;
69446 bool wakeup = false;
69447 + bool timedout = false;
69448
69449 do_gettimeofday(&start);
69450
69451 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_
69452
69453 while (true) {
69454 todo = 0;
69455 + if (time_after(jiffies, end_time))
69456 + timedout = true;
69457 read_lock(&tasklist_lock);
69458 do_each_thread(g, p) {
69459 if (frozen(p) || !freezable(p))
69460 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_
69461 * try_to_stop() after schedule() in ptrace/signal
69462 * stop sees TIF_FREEZE.
69463 */
69464 - if (!task_is_stopped_or_traced(p) &&
69465 - !freezer_should_skip(p))
69466 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69467 todo++;
69468 + if (timedout) {
69469 + printk(KERN_ERR "Task refusing to freeze:\n");
69470 + sched_show_task(p);
69471 + }
69472 + }
69473 } while_each_thread(g, p);
69474 read_unlock(&tasklist_lock);
69475
69476 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_
69477 todo += wq_busy;
69478 }
69479
69480 - if (!todo || time_after(jiffies, end_time))
69481 + if (!todo || timedout)
69482 break;
69483
69484 if (pm_wakeup_pending()) {
69485 diff -urNp linux-2.6.39.2/kernel/printk.c linux-2.6.39.2/kernel/printk.c
69486 --- linux-2.6.39.2/kernel/printk.c 2011-05-19 00:06:34.000000000 -0400
69487 +++ linux-2.6.39.2/kernel/printk.c 2011-05-22 19:41:42.000000000 -0400
69488 @@ -284,12 +284,17 @@ static int check_syslog_permissions(int
69489 if (from_file && type != SYSLOG_ACTION_OPEN)
69490 return 0;
69491
69492 +#ifdef CONFIG_GRKERNSEC_DMESG
69493 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69494 + return -EPERM;
69495 +#endif
69496 +
69497 if (syslog_action_restricted(type)) {
69498 if (capable(CAP_SYSLOG))
69499 return 0;
69500 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
69501 if (capable(CAP_SYS_ADMIN)) {
69502 - WARN_ONCE(1, "Attempt to access syslog with CAP_SYS_ADMIN "
69503 + printk_once(KERN_WARNING "Attempt to access syslog with CAP_SYS_ADMIN "
69504 "but no CAP_SYSLOG (deprecated).\n");
69505 return 0;
69506 }
69507 diff -urNp linux-2.6.39.2/kernel/profile.c linux-2.6.39.2/kernel/profile.c
69508 --- linux-2.6.39.2/kernel/profile.c 2011-05-19 00:06:34.000000000 -0400
69509 +++ linux-2.6.39.2/kernel/profile.c 2011-05-22 19:36:33.000000000 -0400
69510 @@ -39,7 +39,7 @@ struct profile_hit {
69511 /* Oprofile timer tick hook */
69512 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69513
69514 -static atomic_t *prof_buffer;
69515 +static atomic_unchecked_t *prof_buffer;
69516 static unsigned long prof_len, prof_shift;
69517
69518 int prof_on __read_mostly;
69519 @@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
69520 hits[i].pc = 0;
69521 continue;
69522 }
69523 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69524 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69525 hits[i].hits = hits[i].pc = 0;
69526 }
69527 }
69528 @@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc,
69529 * Add the current hit(s) and flush the write-queue out
69530 * to the global buffer:
69531 */
69532 - atomic_add(nr_hits, &prof_buffer[pc]);
69533 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69534 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69535 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69536 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69537 hits[i].pc = hits[i].hits = 0;
69538 }
69539 out:
69540 @@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc,
69541 if (prof_on != type || !prof_buffer)
69542 return;
69543 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69544 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69545 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69546 }
69547 #endif /* !CONFIG_SMP */
69548 EXPORT_SYMBOL_GPL(profile_hits);
69549 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __u
69550 return -EFAULT;
69551 buf++; p++; count--; read++;
69552 }
69553 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69554 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69555 if (copy_to_user(buf, (void *)pnt, count))
69556 return -EFAULT;
69557 read += count;
69558 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file
69559 }
69560 #endif
69561 profile_discard_flip_buffers();
69562 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69563 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69564 return count;
69565 }
69566
69567 diff -urNp linux-2.6.39.2/kernel/ptrace.c linux-2.6.39.2/kernel/ptrace.c
69568 --- linux-2.6.39.2/kernel/ptrace.c 2011-05-19 00:06:34.000000000 -0400
69569 +++ linux-2.6.39.2/kernel/ptrace.c 2011-05-23 17:07:00.000000000 -0400
69570 @@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_stru
69571 return ret;
69572 }
69573
69574 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
69575 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
69576 + unsigned int log)
69577 {
69578 const struct cred *cred = current_cred(), *tcred;
69579
69580 @@ -143,7 +144,8 @@ int __ptrace_may_access(struct task_stru
69581 cred->gid == tcred->sgid &&
69582 cred->gid == tcred->gid))
69583 goto ok;
69584 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
69585 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
69586 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
69587 goto ok;
69588 rcu_read_unlock();
69589 return -EPERM;
69590 @@ -152,7 +154,9 @@ ok:
69591 smp_rmb();
69592 if (task->mm)
69593 dumpable = get_dumpable(task->mm);
69594 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
69595 + if (!dumpable &&
69596 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
69597 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
69598 return -EPERM;
69599
69600 return security_ptrace_access_check(task, mode);
69601 @@ -162,7 +166,16 @@ bool ptrace_may_access(struct task_struc
69602 {
69603 int err;
69604 task_lock(task);
69605 - err = __ptrace_may_access(task, mode);
69606 + err = __ptrace_may_access(task, mode, 0);
69607 + task_unlock(task);
69608 + return !err;
69609 +}
69610 +
69611 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
69612 +{
69613 + int err;
69614 + task_lock(task);
69615 + err = __ptrace_may_access(task, mode, 1);
69616 task_unlock(task);
69617 return !err;
69618 }
69619 @@ -189,7 +202,7 @@ static int ptrace_attach(struct task_str
69620 goto out;
69621
69622 task_lock(task);
69623 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
69624 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
69625 task_unlock(task);
69626 if (retval)
69627 goto unlock_creds;
69628 @@ -202,7 +215,7 @@ static int ptrace_attach(struct task_str
69629 goto unlock_tasklist;
69630
69631 task->ptrace = PT_PTRACED;
69632 - if (task_ns_capable(task, CAP_SYS_PTRACE))
69633 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
69634 task->ptrace |= PT_PTRACE_CAP;
69635
69636 __ptrace_link(task, current);
69637 @@ -362,6 +375,8 @@ int ptrace_readdata(struct task_struct *
69638 {
69639 int copied = 0;
69640
69641 + pax_track_stack();
69642 +
69643 while (len > 0) {
69644 char buf[128];
69645 int this_len, retval;
69646 @@ -373,7 +388,7 @@ int ptrace_readdata(struct task_struct *
69647 break;
69648 return -EIO;
69649 }
69650 - if (copy_to_user(dst, buf, retval))
69651 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69652 return -EFAULT;
69653 copied += retval;
69654 src += retval;
69655 @@ -387,6 +402,8 @@ int ptrace_writedata(struct task_struct
69656 {
69657 int copied = 0;
69658
69659 + pax_track_stack();
69660 +
69661 while (len > 0) {
69662 char buf[128];
69663 int this_len, retval;
69664 @@ -569,9 +586,11 @@ int ptrace_request(struct task_struct *c
69665 {
69666 int ret = -EIO;
69667 siginfo_t siginfo;
69668 - void __user *datavp = (void __user *) data;
69669 + void __user *datavp = (__force void __user *) data;
69670 unsigned long __user *datalp = datavp;
69671
69672 + pax_track_stack();
69673 +
69674 switch (request) {
69675 case PTRACE_PEEKTEXT:
69676 case PTRACE_PEEKDATA:
69677 @@ -717,14 +736,21 @@ SYSCALL_DEFINE4(ptrace, long, request, l
69678 goto out;
69679 }
69680
69681 + if (gr_handle_ptrace(child, request)) {
69682 + ret = -EPERM;
69683 + goto out_put_task_struct;
69684 + }
69685 +
69686 if (request == PTRACE_ATTACH) {
69687 ret = ptrace_attach(child);
69688 /*
69689 * Some architectures need to do book-keeping after
69690 * a ptrace attach.
69691 */
69692 - if (!ret)
69693 + if (!ret) {
69694 arch_ptrace_attach(child);
69695 + gr_audit_ptrace(child);
69696 + }
69697 goto out_put_task_struct;
69698 }
69699
69700 @@ -749,7 +775,7 @@ int generic_ptrace_peekdata(struct task_
69701 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69702 if (copied != sizeof(tmp))
69703 return -EIO;
69704 - return put_user(tmp, (unsigned long __user *)data);
69705 + return put_user(tmp, (__force unsigned long __user *)data);
69706 }
69707
69708 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69709 @@ -772,6 +798,8 @@ int compat_ptrace_request(struct task_st
69710 siginfo_t siginfo;
69711 int ret;
69712
69713 + pax_track_stack();
69714 +
69715 switch (request) {
69716 case PTRACE_PEEKTEXT:
69717 case PTRACE_PEEKDATA:
69718 @@ -859,14 +887,21 @@ asmlinkage long compat_sys_ptrace(compat
69719 goto out;
69720 }
69721
69722 + if (gr_handle_ptrace(child, request)) {
69723 + ret = -EPERM;
69724 + goto out_put_task_struct;
69725 + }
69726 +
69727 if (request == PTRACE_ATTACH) {
69728 ret = ptrace_attach(child);
69729 /*
69730 * Some architectures need to do book-keeping after
69731 * a ptrace attach.
69732 */
69733 - if (!ret)
69734 + if (!ret) {
69735 arch_ptrace_attach(child);
69736 + gr_audit_ptrace(child);
69737 + }
69738 goto out_put_task_struct;
69739 }
69740
69741 diff -urNp linux-2.6.39.2/kernel/rcutorture.c linux-2.6.39.2/kernel/rcutorture.c
69742 --- linux-2.6.39.2/kernel/rcutorture.c 2011-05-19 00:06:34.000000000 -0400
69743 +++ linux-2.6.39.2/kernel/rcutorture.c 2011-05-22 19:36:33.000000000 -0400
69744 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_
69745 { 0 };
69746 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69747 { 0 };
69748 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69749 -static atomic_t n_rcu_torture_alloc;
69750 -static atomic_t n_rcu_torture_alloc_fail;
69751 -static atomic_t n_rcu_torture_free;
69752 -static atomic_t n_rcu_torture_mberror;
69753 -static atomic_t n_rcu_torture_error;
69754 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69755 +static atomic_unchecked_t n_rcu_torture_alloc;
69756 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69757 +static atomic_unchecked_t n_rcu_torture_free;
69758 +static atomic_unchecked_t n_rcu_torture_mberror;
69759 +static atomic_unchecked_t n_rcu_torture_error;
69760 static long n_rcu_torture_boost_ktrerror;
69761 static long n_rcu_torture_boost_rterror;
69762 static long n_rcu_torture_boost_allocerror;
69763 @@ -225,11 +225,11 @@ rcu_torture_alloc(void)
69764
69765 spin_lock_bh(&rcu_torture_lock);
69766 if (list_empty(&rcu_torture_freelist)) {
69767 - atomic_inc(&n_rcu_torture_alloc_fail);
69768 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69769 spin_unlock_bh(&rcu_torture_lock);
69770 return NULL;
69771 }
69772 - atomic_inc(&n_rcu_torture_alloc);
69773 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69774 p = rcu_torture_freelist.next;
69775 list_del_init(p);
69776 spin_unlock_bh(&rcu_torture_lock);
69777 @@ -242,7 +242,7 @@ rcu_torture_alloc(void)
69778 static void
69779 rcu_torture_free(struct rcu_torture *p)
69780 {
69781 - atomic_inc(&n_rcu_torture_free);
69782 + atomic_inc_unchecked(&n_rcu_torture_free);
69783 spin_lock_bh(&rcu_torture_lock);
69784 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69785 spin_unlock_bh(&rcu_torture_lock);
69786 @@ -362,7 +362,7 @@ rcu_torture_cb(struct rcu_head *p)
69787 i = rp->rtort_pipe_count;
69788 if (i > RCU_TORTURE_PIPE_LEN)
69789 i = RCU_TORTURE_PIPE_LEN;
69790 - atomic_inc(&rcu_torture_wcount[i]);
69791 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69792 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69793 rp->rtort_mbtest = 0;
69794 rcu_torture_free(rp);
69795 @@ -409,7 +409,7 @@ static void rcu_sync_torture_deferred_fr
69796 i = rp->rtort_pipe_count;
69797 if (i > RCU_TORTURE_PIPE_LEN)
69798 i = RCU_TORTURE_PIPE_LEN;
69799 - atomic_inc(&rcu_torture_wcount[i]);
69800 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69801 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69802 rp->rtort_mbtest = 0;
69803 list_del(&rp->rtort_free);
69804 @@ -882,7 +882,7 @@ rcu_torture_writer(void *arg)
69805 i = old_rp->rtort_pipe_count;
69806 if (i > RCU_TORTURE_PIPE_LEN)
69807 i = RCU_TORTURE_PIPE_LEN;
69808 - atomic_inc(&rcu_torture_wcount[i]);
69809 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69810 old_rp->rtort_pipe_count++;
69811 cur_ops->deferred_free(old_rp);
69812 }
69813 @@ -951,7 +951,7 @@ static void rcu_torture_timer(unsigned l
69814 return;
69815 }
69816 if (p->rtort_mbtest == 0)
69817 - atomic_inc(&n_rcu_torture_mberror);
69818 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69819 spin_lock(&rand_lock);
69820 cur_ops->read_delay(&rand);
69821 n_rcu_torture_timers++;
69822 @@ -1013,7 +1013,7 @@ rcu_torture_reader(void *arg)
69823 continue;
69824 }
69825 if (p->rtort_mbtest == 0)
69826 - atomic_inc(&n_rcu_torture_mberror);
69827 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69828 cur_ops->read_delay(&rand);
69829 preempt_disable();
69830 pipe_count = p->rtort_pipe_count;
69831 @@ -1072,10 +1072,10 @@ rcu_torture_printk(char *page)
69832 rcu_torture_current,
69833 rcu_torture_current_version,
69834 list_empty(&rcu_torture_freelist),
69835 - atomic_read(&n_rcu_torture_alloc),
69836 - atomic_read(&n_rcu_torture_alloc_fail),
69837 - atomic_read(&n_rcu_torture_free),
69838 - atomic_read(&n_rcu_torture_mberror),
69839 + atomic_read_unchecked(&n_rcu_torture_alloc),
69840 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69841 + atomic_read_unchecked(&n_rcu_torture_free),
69842 + atomic_read_unchecked(&n_rcu_torture_mberror),
69843 n_rcu_torture_boost_ktrerror,
69844 n_rcu_torture_boost_rterror,
69845 n_rcu_torture_boost_allocerror,
69846 @@ -1083,7 +1083,7 @@ rcu_torture_printk(char *page)
69847 n_rcu_torture_boost_failure,
69848 n_rcu_torture_boosts,
69849 n_rcu_torture_timers);
69850 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69851 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69852 n_rcu_torture_boost_ktrerror != 0 ||
69853 n_rcu_torture_boost_rterror != 0 ||
69854 n_rcu_torture_boost_allocerror != 0 ||
69855 @@ -1093,7 +1093,7 @@ rcu_torture_printk(char *page)
69856 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69857 if (i > 1) {
69858 cnt += sprintf(&page[cnt], "!!! ");
69859 - atomic_inc(&n_rcu_torture_error);
69860 + atomic_inc_unchecked(&n_rcu_torture_error);
69861 WARN_ON_ONCE(1);
69862 }
69863 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69864 @@ -1107,7 +1107,7 @@ rcu_torture_printk(char *page)
69865 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69866 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69867 cnt += sprintf(&page[cnt], " %d",
69868 - atomic_read(&rcu_torture_wcount[i]));
69869 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69870 }
69871 cnt += sprintf(&page[cnt], "\n");
69872 if (cur_ops->stats)
69873 @@ -1415,7 +1415,7 @@ rcu_torture_cleanup(void)
69874
69875 if (cur_ops->cleanup)
69876 cur_ops->cleanup();
69877 - if (atomic_read(&n_rcu_torture_error))
69878 + if (atomic_read_unchecked(&n_rcu_torture_error))
69879 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69880 else
69881 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69882 @@ -1479,11 +1479,11 @@ rcu_torture_init(void)
69883
69884 rcu_torture_current = NULL;
69885 rcu_torture_current_version = 0;
69886 - atomic_set(&n_rcu_torture_alloc, 0);
69887 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69888 - atomic_set(&n_rcu_torture_free, 0);
69889 - atomic_set(&n_rcu_torture_mberror, 0);
69890 - atomic_set(&n_rcu_torture_error, 0);
69891 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69892 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69893 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69894 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69895 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69896 n_rcu_torture_boost_ktrerror = 0;
69897 n_rcu_torture_boost_rterror = 0;
69898 n_rcu_torture_boost_allocerror = 0;
69899 @@ -1491,7 +1491,7 @@ rcu_torture_init(void)
69900 n_rcu_torture_boost_failure = 0;
69901 n_rcu_torture_boosts = 0;
69902 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69903 - atomic_set(&rcu_torture_wcount[i], 0);
69904 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69905 for_each_possible_cpu(cpu) {
69906 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69907 per_cpu(rcu_torture_count, cpu)[i] = 0;
69908 diff -urNp linux-2.6.39.2/kernel/rcutree.c linux-2.6.39.2/kernel/rcutree.c
69909 --- linux-2.6.39.2/kernel/rcutree.c 2011-05-19 00:06:34.000000000 -0400
69910 +++ linux-2.6.39.2/kernel/rcutree.c 2011-05-22 19:36:33.000000000 -0400
69911 @@ -1389,7 +1389,7 @@ __rcu_process_callbacks(struct rcu_state
69912 /*
69913 * Do softirq processing for the current CPU.
69914 */
69915 -static void rcu_process_callbacks(struct softirq_action *unused)
69916 +static void rcu_process_callbacks(void)
69917 {
69918 /*
69919 * Memory references from any prior RCU read-side critical sections
69920 diff -urNp linux-2.6.39.2/kernel/rcutree_plugin.h linux-2.6.39.2/kernel/rcutree_plugin.h
69921 --- linux-2.6.39.2/kernel/rcutree_plugin.h 2011-05-19 00:06:34.000000000 -0400
69922 +++ linux-2.6.39.2/kernel/rcutree_plugin.h 2011-05-22 19:36:33.000000000 -0400
69923 @@ -730,7 +730,7 @@ void synchronize_rcu_expedited(void)
69924
69925 /* Clean up and exit. */
69926 smp_mb(); /* ensure expedited GP seen before counter increment. */
69927 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69928 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69929 unlock_mb_ret:
69930 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69931 mb_ret:
69932 @@ -1025,8 +1025,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expe
69933
69934 #else /* #ifndef CONFIG_SMP */
69935
69936 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69937 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69938 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69939 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69940
69941 static int synchronize_sched_expedited_cpu_stop(void *data)
69942 {
69943 @@ -1081,7 +1081,7 @@ void synchronize_sched_expedited(void)
69944 int firstsnap, s, snap, trycount = 0;
69945
69946 /* Note that atomic_inc_return() implies full memory barrier. */
69947 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69948 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69949 get_online_cpus();
69950
69951 /*
69952 @@ -1102,7 +1102,7 @@ void synchronize_sched_expedited(void)
69953 }
69954
69955 /* Check to see if someone else did our work for us. */
69956 - s = atomic_read(&sync_sched_expedited_done);
69957 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69958 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69959 smp_mb(); /* ensure test happens before caller kfree */
69960 return;
69961 @@ -1117,7 +1117,7 @@ void synchronize_sched_expedited(void)
69962 * grace period works for us.
69963 */
69964 get_online_cpus();
69965 - snap = atomic_read(&sync_sched_expedited_started) - 1;
69966 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
69967 smp_mb(); /* ensure read is before try_stop_cpus(). */
69968 }
69969
69970 @@ -1128,12 +1128,12 @@ void synchronize_sched_expedited(void)
69971 * than we did beat us to the punch.
69972 */
69973 do {
69974 - s = atomic_read(&sync_sched_expedited_done);
69975 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69976 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69977 smp_mb(); /* ensure test happens before caller kfree */
69978 break;
69979 }
69980 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69981 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69982
69983 put_online_cpus();
69984 }
69985 diff -urNp linux-2.6.39.2/kernel/relay.c linux-2.6.39.2/kernel/relay.c
69986 --- linux-2.6.39.2/kernel/relay.c 2011-05-19 00:06:34.000000000 -0400
69987 +++ linux-2.6.39.2/kernel/relay.c 2011-05-22 19:36:33.000000000 -0400
69988 @@ -1236,6 +1236,8 @@ static ssize_t subbuf_splice_actor(struc
69989 };
69990 ssize_t ret;
69991
69992 + pax_track_stack();
69993 +
69994 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
69995 return 0;
69996 if (splice_grow_spd(pipe, &spd))
69997 diff -urNp linux-2.6.39.2/kernel/resource.c linux-2.6.39.2/kernel/resource.c
69998 --- linux-2.6.39.2/kernel/resource.c 2011-05-19 00:06:34.000000000 -0400
69999 +++ linux-2.6.39.2/kernel/resource.c 2011-05-22 19:41:42.000000000 -0400
70000 @@ -133,8 +133,18 @@ static const struct file_operations proc
70001
70002 static int __init ioresources_init(void)
70003 {
70004 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70005 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70006 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70007 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70008 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70009 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70010 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70011 +#endif
70012 +#else
70013 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70014 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70015 +#endif
70016 return 0;
70017 }
70018 __initcall(ioresources_init);
70019 diff -urNp linux-2.6.39.2/kernel/rtmutex-tester.c linux-2.6.39.2/kernel/rtmutex-tester.c
70020 --- linux-2.6.39.2/kernel/rtmutex-tester.c 2011-05-19 00:06:34.000000000 -0400
70021 +++ linux-2.6.39.2/kernel/rtmutex-tester.c 2011-05-22 19:36:33.000000000 -0400
70022 @@ -20,7 +20,7 @@
70023 #define MAX_RT_TEST_MUTEXES 8
70024
70025 static spinlock_t rttest_lock;
70026 -static atomic_t rttest_event;
70027 +static atomic_unchecked_t rttest_event;
70028
70029 struct test_thread_data {
70030 int opcode;
70031 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_
70032
70033 case RTTEST_LOCKCONT:
70034 td->mutexes[td->opdata] = 1;
70035 - td->event = atomic_add_return(1, &rttest_event);
70036 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70037 return 0;
70038
70039 case RTTEST_RESET:
70040 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_
70041 return 0;
70042
70043 case RTTEST_RESETEVENT:
70044 - atomic_set(&rttest_event, 0);
70045 + atomic_set_unchecked(&rttest_event, 0);
70046 return 0;
70047
70048 default:
70049 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_
70050 return ret;
70051
70052 td->mutexes[id] = 1;
70053 - td->event = atomic_add_return(1, &rttest_event);
70054 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70055 rt_mutex_lock(&mutexes[id]);
70056 - td->event = atomic_add_return(1, &rttest_event);
70057 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70058 td->mutexes[id] = 4;
70059 return 0;
70060
70061 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_
70062 return ret;
70063
70064 td->mutexes[id] = 1;
70065 - td->event = atomic_add_return(1, &rttest_event);
70066 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70067 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70068 - td->event = atomic_add_return(1, &rttest_event);
70069 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70070 td->mutexes[id] = ret ? 0 : 4;
70071 return ret ? -EINTR : 0;
70072
70073 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_
70074 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70075 return ret;
70076
70077 - td->event = atomic_add_return(1, &rttest_event);
70078 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70079 rt_mutex_unlock(&mutexes[id]);
70080 - td->event = atomic_add_return(1, &rttest_event);
70081 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70082 td->mutexes[id] = 0;
70083 return 0;
70084
70085 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mu
70086 break;
70087
70088 td->mutexes[dat] = 2;
70089 - td->event = atomic_add_return(1, &rttest_event);
70090 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70091 break;
70092
70093 default:
70094 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mu
70095 return;
70096
70097 td->mutexes[dat] = 3;
70098 - td->event = atomic_add_return(1, &rttest_event);
70099 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70100 break;
70101
70102 case RTTEST_LOCKNOWAIT:
70103 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mu
70104 return;
70105
70106 td->mutexes[dat] = 1;
70107 - td->event = atomic_add_return(1, &rttest_event);
70108 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70109 return;
70110
70111 default:
70112 diff -urNp linux-2.6.39.2/kernel/sched_autogroup.c linux-2.6.39.2/kernel/sched_autogroup.c
70113 --- linux-2.6.39.2/kernel/sched_autogroup.c 2011-05-19 00:06:34.000000000 -0400
70114 +++ linux-2.6.39.2/kernel/sched_autogroup.c 2011-05-22 19:36:33.000000000 -0400
70115 @@ -7,7 +7,7 @@
70116
70117 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70118 static struct autogroup autogroup_default;
70119 -static atomic_t autogroup_seq_nr;
70120 +static atomic_unchecked_t autogroup_seq_nr;
70121
70122 static void __init autogroup_init(struct task_struct *init_task)
70123 {
70124 @@ -78,7 +78,7 @@ static inline struct autogroup *autogrou
70125
70126 kref_init(&ag->kref);
70127 init_rwsem(&ag->lock);
70128 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70129 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70130 ag->tg = tg;
70131 #ifdef CONFIG_RT_GROUP_SCHED
70132 /*
70133 diff -urNp linux-2.6.39.2/kernel/sched.c linux-2.6.39.2/kernel/sched.c
70134 --- linux-2.6.39.2/kernel/sched.c 2011-05-19 00:06:34.000000000 -0400
70135 +++ linux-2.6.39.2/kernel/sched.c 2011-05-23 17:07:00.000000000 -0400
70136 @@ -4078,6 +4078,8 @@ asmlinkage void __sched schedule(void)
70137 struct rq *rq;
70138 int cpu;
70139
70140 + pax_track_stack();
70141 +
70142 need_resched:
70143 preempt_disable();
70144 cpu = smp_processor_id();
70145 @@ -4165,7 +4167,7 @@ EXPORT_SYMBOL(schedule);
70146 * Look out! "owner" is an entirely speculative pointer
70147 * access and not reliable.
70148 */
70149 -int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
70150 +int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
70151 {
70152 unsigned int cpu;
70153 struct rq *rq;
70154 @@ -4179,10 +4181,10 @@ int mutex_spin_on_owner(struct mutex *lo
70155 * DEBUG_PAGEALLOC could have unmapped it if
70156 * the mutex owner just released it and exited.
70157 */
70158 - if (probe_kernel_address(&owner->cpu, cpu))
70159 + if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
70160 return 0;
70161 #else
70162 - cpu = owner->cpu;
70163 + cpu = task_thread_info(owner)->cpu;
70164 #endif
70165
70166 /*
70167 @@ -4219,7 +4221,7 @@ int mutex_spin_on_owner(struct mutex *lo
70168 /*
70169 * Is that owner really running on that cpu?
70170 */
70171 - if (task_thread_info(rq->curr) != owner || need_resched())
70172 + if (rq->curr != owner || need_resched())
70173 return 0;
70174
70175 arch_mutex_cpu_relax();
70176 @@ -4778,6 +4780,8 @@ int can_nice(const struct task_struct *p
70177 /* convert nice value [19,-20] to rlimit style value [1,40] */
70178 int nice_rlim = 20 - nice;
70179
70180 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70181 +
70182 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70183 capable(CAP_SYS_NICE));
70184 }
70185 @@ -4811,7 +4815,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70186 if (nice > 19)
70187 nice = 19;
70188
70189 - if (increment < 0 && !can_nice(current, nice))
70190 + if (increment < 0 && (!can_nice(current, nice) ||
70191 + gr_handle_chroot_nice()))
70192 return -EPERM;
70193
70194 retval = security_task_setnice(current, nice);
70195 @@ -4957,6 +4962,7 @@ recheck:
70196 unsigned long rlim_rtprio =
70197 task_rlimit(p, RLIMIT_RTPRIO);
70198
70199 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70200 /* can't set/change the rt policy */
70201 if (policy != p->policy && !rlim_rtprio)
70202 return -EPERM;
70203 @@ -7164,7 +7170,7 @@ static void init_sched_groups_power(int
70204 long power;
70205 int weight;
70206
70207 - WARN_ON(!sd || !sd->groups);
70208 + BUG_ON(!sd || !sd->groups);
70209
70210 if (cpu != group_first_cpu(sd->groups))
70211 return;
70212 diff -urNp linux-2.6.39.2/kernel/sched_fair.c linux-2.6.39.2/kernel/sched_fair.c
70213 --- linux-2.6.39.2/kernel/sched_fair.c 2011-05-19 00:06:34.000000000 -0400
70214 +++ linux-2.6.39.2/kernel/sched_fair.c 2011-05-22 19:36:33.000000000 -0400
70215 @@ -3999,7 +3999,7 @@ static void nohz_idle_balance(int this_c
70216 * run_rebalance_domains is triggered when needed from the scheduler tick.
70217 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70218 */
70219 -static void run_rebalance_domains(struct softirq_action *h)
70220 +static void run_rebalance_domains(void)
70221 {
70222 int this_cpu = smp_processor_id();
70223 struct rq *this_rq = cpu_rq(this_cpu);
70224 diff -urNp linux-2.6.39.2/kernel/signal.c linux-2.6.39.2/kernel/signal.c
70225 --- linux-2.6.39.2/kernel/signal.c 2011-05-19 00:06:34.000000000 -0400
70226 +++ linux-2.6.39.2/kernel/signal.c 2011-05-23 17:07:00.000000000 -0400
70227 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cache
70228
70229 int print_fatal_signals __read_mostly;
70230
70231 -static void __user *sig_handler(struct task_struct *t, int sig)
70232 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70233 {
70234 return t->sighand->action[sig - 1].sa.sa_handler;
70235 }
70236
70237 -static int sig_handler_ignored(void __user *handler, int sig)
70238 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70239 {
70240 /* Is it explicitly or implicitly ignored? */
70241 return handler == SIG_IGN ||
70242 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __us
70243 static int sig_task_ignored(struct task_struct *t, int sig,
70244 int from_ancestor_ns)
70245 {
70246 - void __user *handler;
70247 + __sighandler_t handler;
70248
70249 handler = sig_handler(t, sig);
70250
70251 @@ -243,6 +243,9 @@ __sigqueue_alloc(int sig, struct task_st
70252 atomic_inc(&user->sigpending);
70253 rcu_read_unlock();
70254
70255 + if (!override_rlimit)
70256 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70257 +
70258 if (override_rlimit ||
70259 atomic_read(&user->sigpending) <=
70260 task_rlimit(t, RLIMIT_SIGPENDING)) {
70261 @@ -367,7 +370,7 @@ flush_signal_handlers(struct task_struct
70262
70263 int unhandled_signal(struct task_struct *tsk, int sig)
70264 {
70265 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70266 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70267 if (is_global_init(tsk))
70268 return 1;
70269 if (handler != SIG_IGN && handler != SIG_DFL)
70270 @@ -693,6 +696,9 @@ static int check_kill_permission(int sig
70271 }
70272 }
70273
70274 + if (gr_handle_signal(t, sig))
70275 + return -EPERM;
70276 +
70277 return security_task_kill(t, info, sig, 0);
70278 }
70279
70280 @@ -1041,7 +1047,7 @@ __group_send_sig_info(int sig, struct si
70281 return send_signal(sig, info, p, 1);
70282 }
70283
70284 -static int
70285 +int
70286 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70287 {
70288 return send_signal(sig, info, t, 0);
70289 @@ -1078,6 +1084,7 @@ force_sig_info(int sig, struct siginfo *
70290 unsigned long int flags;
70291 int ret, blocked, ignored;
70292 struct k_sigaction *action;
70293 + int is_unhandled = 0;
70294
70295 spin_lock_irqsave(&t->sighand->siglock, flags);
70296 action = &t->sighand->action[sig-1];
70297 @@ -1092,9 +1099,18 @@ force_sig_info(int sig, struct siginfo *
70298 }
70299 if (action->sa.sa_handler == SIG_DFL)
70300 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70301 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70302 + is_unhandled = 1;
70303 ret = specific_send_sig_info(sig, info, t);
70304 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70305
70306 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70307 + normal operation */
70308 + if (is_unhandled) {
70309 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70310 + gr_handle_crash(t, sig);
70311 + }
70312 +
70313 return ret;
70314 }
70315
70316 @@ -1153,8 +1169,11 @@ int group_send_sig_info(int sig, struct
70317 ret = check_kill_permission(sig, info, p);
70318 rcu_read_unlock();
70319
70320 - if (!ret && sig)
70321 + if (!ret && sig) {
70322 ret = do_send_sig_info(sig, info, p, true);
70323 + if (!ret)
70324 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70325 + }
70326
70327 return ret;
70328 }
70329 @@ -1718,6 +1737,8 @@ void ptrace_notify(int exit_code)
70330 {
70331 siginfo_t info;
70332
70333 + pax_track_stack();
70334 +
70335 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
70336
70337 memset(&info, 0, sizeof info);
70338 diff -urNp linux-2.6.39.2/kernel/smp.c linux-2.6.39.2/kernel/smp.c
70339 --- linux-2.6.39.2/kernel/smp.c 2011-05-19 00:06:34.000000000 -0400
70340 +++ linux-2.6.39.2/kernel/smp.c 2011-05-22 19:36:33.000000000 -0400
70341 @@ -583,22 +583,22 @@ int smp_call_function(smp_call_func_t fu
70342 }
70343 EXPORT_SYMBOL(smp_call_function);
70344
70345 -void ipi_call_lock(void)
70346 +void ipi_call_lock(void) __acquires(call_function.lock)
70347 {
70348 raw_spin_lock(&call_function.lock);
70349 }
70350
70351 -void ipi_call_unlock(void)
70352 +void ipi_call_unlock(void) __releases(call_function.lock)
70353 {
70354 raw_spin_unlock(&call_function.lock);
70355 }
70356
70357 -void ipi_call_lock_irq(void)
70358 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
70359 {
70360 raw_spin_lock_irq(&call_function.lock);
70361 }
70362
70363 -void ipi_call_unlock_irq(void)
70364 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
70365 {
70366 raw_spin_unlock_irq(&call_function.lock);
70367 }
70368 diff -urNp linux-2.6.39.2/kernel/softirq.c linux-2.6.39.2/kernel/softirq.c
70369 --- linux-2.6.39.2/kernel/softirq.c 2011-05-19 00:06:34.000000000 -0400
70370 +++ linux-2.6.39.2/kernel/softirq.c 2011-05-22 19:36:33.000000000 -0400
70371 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec
70372
70373 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70374
70375 -char *softirq_to_name[NR_SOFTIRQS] = {
70376 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70377 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70378 "TASKLET", "SCHED", "HRTIMER", "RCU"
70379 };
70380 @@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
70381
70382 asmlinkage void __do_softirq(void)
70383 {
70384 - struct softirq_action *h;
70385 + const struct softirq_action *h;
70386 __u32 pending;
70387 int max_restart = MAX_SOFTIRQ_RESTART;
70388 int cpu;
70389 @@ -235,7 +235,7 @@ restart:
70390 kstat_incr_softirqs_this_cpu(vec_nr);
70391
70392 trace_softirq_entry(vec_nr);
70393 - h->action(h);
70394 + h->action();
70395 trace_softirq_exit(vec_nr);
70396 if (unlikely(prev_count != preempt_count())) {
70397 printk(KERN_ERR "huh, entered softirq %u %s %p"
70398 @@ -377,7 +377,7 @@ void raise_softirq(unsigned int nr)
70399 local_irq_restore(flags);
70400 }
70401
70402 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70403 +void open_softirq(int nr, void (*action)(void))
70404 {
70405 softirq_vec[nr].action = action;
70406 }
70407 @@ -433,7 +433,7 @@ void __tasklet_hi_schedule_first(struct
70408
70409 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70410
70411 -static void tasklet_action(struct softirq_action *a)
70412 +static void tasklet_action(void)
70413 {
70414 struct tasklet_struct *list;
70415
70416 @@ -468,7 +468,7 @@ static void tasklet_action(struct softir
70417 }
70418 }
70419
70420 -static void tasklet_hi_action(struct softirq_action *a)
70421 +static void tasklet_hi_action(void)
70422 {
70423 struct tasklet_struct *list;
70424
70425 diff -urNp linux-2.6.39.2/kernel/sys.c linux-2.6.39.2/kernel/sys.c
70426 --- linux-2.6.39.2/kernel/sys.c 2011-05-19 00:06:34.000000000 -0400
70427 +++ linux-2.6.39.2/kernel/sys.c 2011-05-22 21:08:10.000000000 -0400
70428 @@ -154,6 +154,12 @@ static int set_one_prio(struct task_stru
70429 error = -EACCES;
70430 goto out;
70431 }
70432 +
70433 + if (gr_handle_chroot_setpriority(p, niceval)) {
70434 + error = -EACCES;
70435 + goto out;
70436 + }
70437 +
70438 no_nice = security_task_setnice(p, niceval);
70439 if (no_nice) {
70440 error = no_nice;
70441 @@ -538,6 +544,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, g
70442 goto error;
70443 }
70444
70445 + if (gr_check_group_change(new->gid, new->egid, -1))
70446 + goto error;
70447 +
70448 if (rgid != (gid_t) -1 ||
70449 (egid != (gid_t) -1 && egid != old->gid))
70450 new->sgid = new->egid;
70451 @@ -567,6 +576,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70452 old = current_cred();
70453
70454 retval = -EPERM;
70455 +
70456 + if (gr_check_group_change(gid, gid, gid))
70457 + goto error;
70458 +
70459 if (nsown_capable(CAP_SETGID))
70460 new->gid = new->egid = new->sgid = new->fsgid = gid;
70461 else if (gid == old->gid || gid == old->sgid)
70462 @@ -647,6 +660,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, u
70463 goto error;
70464 }
70465
70466 + if (gr_check_user_change(new->uid, new->euid, -1))
70467 + goto error;
70468 +
70469 if (new->uid != old->uid) {
70470 retval = set_user(new);
70471 if (retval < 0)
70472 @@ -691,6 +707,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70473 old = current_cred();
70474
70475 retval = -EPERM;
70476 +
70477 + if (gr_check_crash_uid(uid))
70478 + goto error;
70479 + if (gr_check_user_change(uid, uid, uid))
70480 + goto error;
70481 +
70482 if (nsown_capable(CAP_SETUID)) {
70483 new->suid = new->uid = uid;
70484 if (uid != old->uid) {
70485 @@ -745,6 +767,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid,
70486 goto error;
70487 }
70488
70489 + if (gr_check_user_change(ruid, euid, -1))
70490 + goto error;
70491 +
70492 if (ruid != (uid_t) -1) {
70493 new->uid = ruid;
70494 if (ruid != old->uid) {
70495 @@ -809,6 +834,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid,
70496 goto error;
70497 }
70498
70499 + if (gr_check_group_change(rgid, egid, -1))
70500 + goto error;
70501 +
70502 if (rgid != (gid_t) -1)
70503 new->gid = rgid;
70504 if (egid != (gid_t) -1)
70505 @@ -855,6 +883,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70506 old = current_cred();
70507 old_fsuid = old->fsuid;
70508
70509 + if (gr_check_user_change(-1, -1, uid))
70510 + goto error;
70511 +
70512 if (uid == old->uid || uid == old->euid ||
70513 uid == old->suid || uid == old->fsuid ||
70514 nsown_capable(CAP_SETUID)) {
70515 @@ -865,6 +896,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70516 }
70517 }
70518
70519 +error:
70520 abort_creds(new);
70521 return old_fsuid;
70522
70523 @@ -891,12 +923,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70524 if (gid == old->gid || gid == old->egid ||
70525 gid == old->sgid || gid == old->fsgid ||
70526 nsown_capable(CAP_SETGID)) {
70527 + if (gr_check_group_change(-1, -1, gid))
70528 + goto error;
70529 +
70530 if (gid != old_fsgid) {
70531 new->fsgid = gid;
70532 goto change_okay;
70533 }
70534 }
70535
70536 +error:
70537 abort_creds(new);
70538 return old_fsgid;
70539
70540 @@ -1643,7 +1679,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
70541 error = get_dumpable(me->mm);
70542 break;
70543 case PR_SET_DUMPABLE:
70544 - if (arg2 < 0 || arg2 > 1) {
70545 + if (arg2 > 1) {
70546 error = -EINVAL;
70547 break;
70548 }
70549 diff -urNp linux-2.6.39.2/kernel/sysctl.c linux-2.6.39.2/kernel/sysctl.c
70550 --- linux-2.6.39.2/kernel/sysctl.c 2011-05-19 00:06:34.000000000 -0400
70551 +++ linux-2.6.39.2/kernel/sysctl.c 2011-05-22 20:23:10.000000000 -0400
70552 @@ -84,6 +84,13 @@
70553
70554
70555 #if defined(CONFIG_SYSCTL)
70556 +#include <linux/grsecurity.h>
70557 +#include <linux/grinternal.h>
70558 +
70559 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70560 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70561 + const int op);
70562 +extern int gr_handle_chroot_sysctl(const int op);
70563
70564 /* External variables not in a header file. */
70565 extern int sysctl_overcommit_memory;
70566 @@ -196,6 +203,7 @@ static int sysrq_sysctl_handler(ctl_tabl
70567 }
70568
70569 #endif
70570 +extern struct ctl_table grsecurity_table[];
70571
70572 static struct ctl_table root_table[];
70573 static struct ctl_table_root sysctl_table_root;
70574 @@ -225,6 +233,20 @@ extern struct ctl_table epoll_table[];
70575 int sysctl_legacy_va_layout;
70576 #endif
70577
70578 +#ifdef CONFIG_PAX_SOFTMODE
70579 +static ctl_table pax_table[] = {
70580 + {
70581 + .procname = "softmode",
70582 + .data = &pax_softmode,
70583 + .maxlen = sizeof(unsigned int),
70584 + .mode = 0600,
70585 + .proc_handler = &proc_dointvec,
70586 + },
70587 +
70588 + { }
70589 +};
70590 +#endif
70591 +
70592 /* The default sysctl tables: */
70593
70594 static struct ctl_table root_table[] = {
70595 @@ -271,6 +293,22 @@ static int max_extfrag_threshold = 1000;
70596 #endif
70597
70598 static struct ctl_table kern_table[] = {
70599 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70600 + {
70601 + .procname = "grsecurity",
70602 + .mode = 0500,
70603 + .child = grsecurity_table,
70604 + },
70605 +#endif
70606 +
70607 +#ifdef CONFIG_PAX_SOFTMODE
70608 + {
70609 + .procname = "pax",
70610 + .mode = 0500,
70611 + .child = pax_table,
70612 + },
70613 +#endif
70614 +
70615 {
70616 .procname = "sched_child_runs_first",
70617 .data = &sysctl_sched_child_runs_first,
70618 @@ -545,7 +583,7 @@ static struct ctl_table kern_table[] = {
70619 .data = &modprobe_path,
70620 .maxlen = KMOD_PATH_LEN,
70621 .mode = 0644,
70622 - .proc_handler = proc_dostring,
70623 + .proc_handler = proc_dostring_modpriv,
70624 },
70625 {
70626 .procname = "modules_disabled",
70627 @@ -707,16 +745,20 @@ static struct ctl_table kern_table[] = {
70628 .extra1 = &zero,
70629 .extra2 = &one,
70630 },
70631 +#endif
70632 {
70633 .procname = "kptr_restrict",
70634 .data = &kptr_restrict,
70635 .maxlen = sizeof(int),
70636 .mode = 0644,
70637 .proc_handler = proc_dmesg_restrict,
70638 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70639 + .extra1 = &two,
70640 +#else
70641 .extra1 = &zero,
70642 +#endif
70643 .extra2 = &two,
70644 },
70645 -#endif
70646 {
70647 .procname = "ngroups_max",
70648 .data = &ngroups_max,
70649 @@ -1189,6 +1231,13 @@ static struct ctl_table vm_table[] = {
70650 .proc_handler = proc_dointvec_minmax,
70651 .extra1 = &zero,
70652 },
70653 + {
70654 + .procname = "heap_stack_gap",
70655 + .data = &sysctl_heap_stack_gap,
70656 + .maxlen = sizeof(sysctl_heap_stack_gap),
70657 + .mode = 0644,
70658 + .proc_handler = proc_doulongvec_minmax,
70659 + },
70660 #else
70661 {
70662 .procname = "nr_trim_pages",
70663 @@ -1698,6 +1747,17 @@ static int test_perm(int mode, int op)
70664 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70665 {
70666 int mode;
70667 + int error;
70668 +
70669 + if (table->parent != NULL && table->parent->procname != NULL &&
70670 + table->procname != NULL &&
70671 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70672 + return -EACCES;
70673 + if (gr_handle_chroot_sysctl(op))
70674 + return -EACCES;
70675 + error = gr_handle_sysctl(table, op);
70676 + if (error)
70677 + return error;
70678
70679 if (root->permissions)
70680 mode = root->permissions(root, current->nsproxy, table);
70681 @@ -2102,6 +2162,16 @@ int proc_dostring(struct ctl_table *tabl
70682 buffer, lenp, ppos);
70683 }
70684
70685 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70686 + void __user *buffer, size_t *lenp, loff_t *ppos)
70687 +{
70688 + if (write && !capable(CAP_SYS_MODULE))
70689 + return -EPERM;
70690 +
70691 + return _proc_do_string(table->data, table->maxlen, write,
70692 + buffer, lenp, ppos);
70693 +}
70694 +
70695 static size_t proc_skip_spaces(char **buf)
70696 {
70697 size_t ret;
70698 @@ -2207,6 +2277,8 @@ static int proc_put_long(void __user **b
70699 len = strlen(tmp);
70700 if (len > *size)
70701 len = *size;
70702 + if (len > sizeof(tmp))
70703 + len = sizeof(tmp);
70704 if (copy_to_user(*buf, tmp, len))
70705 return -EFAULT;
70706 *size -= len;
70707 @@ -2523,8 +2595,11 @@ static int __do_proc_doulongvec_minmax(v
70708 *i = val;
70709 } else {
70710 val = convdiv * (*i) / convmul;
70711 - if (!first)
70712 + if (!first) {
70713 err = proc_put_char(&buffer, &left, '\t');
70714 + if (err)
70715 + break;
70716 + }
70717 err = proc_put_long(&buffer, &left, val, false);
70718 if (err)
70719 break;
70720 @@ -2919,6 +2994,12 @@ int proc_dostring(struct ctl_table *tabl
70721 return -ENOSYS;
70722 }
70723
70724 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70725 + void __user *buffer, size_t *lenp, loff_t *ppos)
70726 +{
70727 + return -ENOSYS;
70728 +}
70729 +
70730 int proc_dointvec(struct ctl_table *table, int write,
70731 void __user *buffer, size_t *lenp, loff_t *ppos)
70732 {
70733 @@ -2975,6 +3056,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70734 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70735 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70736 EXPORT_SYMBOL(proc_dostring);
70737 +EXPORT_SYMBOL(proc_dostring_modpriv);
70738 EXPORT_SYMBOL(proc_doulongvec_minmax);
70739 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70740 EXPORT_SYMBOL(register_sysctl_table);
70741 diff -urNp linux-2.6.39.2/kernel/sysctl_check.c linux-2.6.39.2/kernel/sysctl_check.c
70742 --- linux-2.6.39.2/kernel/sysctl_check.c 2011-05-19 00:06:34.000000000 -0400
70743 +++ linux-2.6.39.2/kernel/sysctl_check.c 2011-05-22 19:41:42.000000000 -0400
70744 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *n
70745 set_fail(&fail, table, "Directory with extra2");
70746 } else {
70747 if ((table->proc_handler == proc_dostring) ||
70748 + (table->proc_handler == proc_dostring_modpriv) ||
70749 (table->proc_handler == proc_dointvec) ||
70750 (table->proc_handler == proc_dointvec_minmax) ||
70751 (table->proc_handler == proc_dointvec_jiffies) ||
70752 diff -urNp linux-2.6.39.2/kernel/taskstats.c linux-2.6.39.2/kernel/taskstats.c
70753 --- linux-2.6.39.2/kernel/taskstats.c 2011-05-19 00:06:34.000000000 -0400
70754 +++ linux-2.6.39.2/kernel/taskstats.c 2011-05-22 19:41:42.000000000 -0400
70755 @@ -27,9 +27,12 @@
70756 #include <linux/cgroup.h>
70757 #include <linux/fs.h>
70758 #include <linux/file.h>
70759 +#include <linux/grsecurity.h>
70760 #include <net/genetlink.h>
70761 #include <asm/atomic.h>
70762
70763 +extern int gr_is_taskstats_denied(int pid);
70764 +
70765 /*
70766 * Maximum length of a cpumask that can be specified in
70767 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70768 @@ -549,6 +552,9 @@ err:
70769
70770 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70771 {
70772 + if (gr_is_taskstats_denied(current->pid))
70773 + return -EACCES;
70774 +
70775 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70776 return cmd_attr_register_cpumask(info);
70777 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70778 diff -urNp linux-2.6.39.2/kernel/time/posix-clock.c linux-2.6.39.2/kernel/time/posix-clock.c
70779 --- linux-2.6.39.2/kernel/time/posix-clock.c 2011-05-19 00:06:34.000000000 -0400
70780 +++ linux-2.6.39.2/kernel/time/posix-clock.c 2011-05-22 19:36:33.000000000 -0400
70781 @@ -433,7 +433,7 @@ static int pc_timer_settime(struct k_iti
70782 return err;
70783 }
70784
70785 -struct k_clock clock_posix_dynamic = {
70786 +const struct k_clock clock_posix_dynamic = {
70787 .clock_getres = pc_clock_getres,
70788 .clock_set = pc_clock_settime,
70789 .clock_get = pc_clock_gettime,
70790 diff -urNp linux-2.6.39.2/kernel/time/tick-broadcast.c linux-2.6.39.2/kernel/time/tick-broadcast.c
70791 --- linux-2.6.39.2/kernel/time/tick-broadcast.c 2011-05-19 00:06:34.000000000 -0400
70792 +++ linux-2.6.39.2/kernel/time/tick-broadcast.c 2011-05-22 19:36:33.000000000 -0400
70793 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct cl
70794 * then clear the broadcast bit.
70795 */
70796 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70797 - int cpu = smp_processor_id();
70798 + cpu = smp_processor_id();
70799
70800 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70801 tick_broadcast_clear_oneshot(cpu);
70802 diff -urNp linux-2.6.39.2/kernel/time/timekeeping.c linux-2.6.39.2/kernel/time/timekeeping.c
70803 --- linux-2.6.39.2/kernel/time/timekeeping.c 2011-05-19 00:06:34.000000000 -0400
70804 +++ linux-2.6.39.2/kernel/time/timekeeping.c 2011-05-22 20:40:50.000000000 -0400
70805 @@ -14,6 +14,7 @@
70806 #include <linux/init.h>
70807 #include <linux/mm.h>
70808 #include <linux/sched.h>
70809 +#include <linux/grsecurity.h>
70810 #include <linux/syscore_ops.h>
70811 #include <linux/clocksource.h>
70812 #include <linux/jiffies.h>
70813 @@ -361,6 +362,8 @@ int do_settimeofday(const struct timespe
70814 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70815 return -EINVAL;
70816
70817 + gr_log_timechange();
70818 +
70819 write_seqlock_irqsave(&xtime_lock, flags);
70820
70821 timekeeping_forward_now();
70822 diff -urNp linux-2.6.39.2/kernel/time/timer_list.c linux-2.6.39.2/kernel/time/timer_list.c
70823 --- linux-2.6.39.2/kernel/time/timer_list.c 2011-05-19 00:06:34.000000000 -0400
70824 +++ linux-2.6.39.2/kernel/time/timer_list.c 2011-05-22 19:41:42.000000000 -0400
70825 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base,
70826
70827 static void print_name_offset(struct seq_file *m, void *sym)
70828 {
70829 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70830 + SEQ_printf(m, "<%p>", NULL);
70831 +#else
70832 char symname[KSYM_NAME_LEN];
70833
70834 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70835 SEQ_printf(m, "<%pK>", sym);
70836 else
70837 SEQ_printf(m, "%s", symname);
70838 +#endif
70839 }
70840
70841 static void
70842 @@ -112,7 +116,11 @@ next_one:
70843 static void
70844 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70845 {
70846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70847 + SEQ_printf(m, " .base: %p\n", NULL);
70848 +#else
70849 SEQ_printf(m, " .base: %pK\n", base);
70850 +#endif
70851 SEQ_printf(m, " .index: %d\n",
70852 base->index);
70853 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70854 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs
70855 {
70856 struct proc_dir_entry *pe;
70857
70858 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70859 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70860 +#else
70861 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70862 +#endif
70863 if (!pe)
70864 return -ENOMEM;
70865 return 0;
70866 diff -urNp linux-2.6.39.2/kernel/time/timer_stats.c linux-2.6.39.2/kernel/time/timer_stats.c
70867 --- linux-2.6.39.2/kernel/time/timer_stats.c 2011-05-19 00:06:34.000000000 -0400
70868 +++ linux-2.6.39.2/kernel/time/timer_stats.c 2011-05-22 19:41:42.000000000 -0400
70869 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70870 static unsigned long nr_entries;
70871 static struct entry entries[MAX_ENTRIES];
70872
70873 -static atomic_t overflow_count;
70874 +static atomic_unchecked_t overflow_count;
70875
70876 /*
70877 * The entries are in a hash-table, for fast lookup:
70878 @@ -140,7 +140,7 @@ static void reset_entries(void)
70879 nr_entries = 0;
70880 memset(entries, 0, sizeof(entries));
70881 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70882 - atomic_set(&overflow_count, 0);
70883 + atomic_set_unchecked(&overflow_count, 0);
70884 }
70885
70886 static struct entry *alloc_entry(void)
70887 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *time
70888 if (likely(entry))
70889 entry->count++;
70890 else
70891 - atomic_inc(&overflow_count);
70892 + atomic_inc_unchecked(&overflow_count);
70893
70894 out_unlock:
70895 raw_spin_unlock_irqrestore(lock, flags);
70896 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *time
70897
70898 static void print_name_offset(struct seq_file *m, unsigned long addr)
70899 {
70900 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70901 + seq_printf(m, "<%p>", NULL);
70902 +#else
70903 char symname[KSYM_NAME_LEN];
70904
70905 if (lookup_symbol_name(addr, symname) < 0)
70906 seq_printf(m, "<%p>", (void *)addr);
70907 else
70908 seq_printf(m, "%s", symname);
70909 +#endif
70910 }
70911
70912 static int tstats_show(struct seq_file *m, void *v)
70913 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *
70914
70915 seq_puts(m, "Timer Stats Version: v0.2\n");
70916 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70917 - if (atomic_read(&overflow_count))
70918 + if (atomic_read_unchecked(&overflow_count))
70919 seq_printf(m, "Overflow: %d entries\n",
70920 - atomic_read(&overflow_count));
70921 + atomic_read_unchecked(&overflow_count));
70922
70923 for (i = 0; i < nr_entries; i++) {
70924 entry = entries + i;
70925 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(voi
70926 {
70927 struct proc_dir_entry *pe;
70928
70929 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70930 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70931 +#else
70932 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70933 +#endif
70934 if (!pe)
70935 return -ENOMEM;
70936 return 0;
70937 diff -urNp linux-2.6.39.2/kernel/time.c linux-2.6.39.2/kernel/time.c
70938 --- linux-2.6.39.2/kernel/time.c 2011-05-19 00:06:34.000000000 -0400
70939 +++ linux-2.6.39.2/kernel/time.c 2011-05-22 19:41:42.000000000 -0400
70940 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct tim
70941 return error;
70942
70943 if (tz) {
70944 + /* we log in do_settimeofday called below, so don't log twice
70945 + */
70946 + if (!tv)
70947 + gr_log_timechange();
70948 +
70949 /* SMP safe, global irq locking makes it work. */
70950 sys_tz = *tz;
70951 update_vsyscall_tz();
70952 diff -urNp linux-2.6.39.2/kernel/timer.c linux-2.6.39.2/kernel/timer.c
70953 --- linux-2.6.39.2/kernel/timer.c 2011-05-19 00:06:34.000000000 -0400
70954 +++ linux-2.6.39.2/kernel/timer.c 2011-05-22 19:36:33.000000000 -0400
70955 @@ -1305,7 +1305,7 @@ void update_process_times(int user_tick)
70956 /*
70957 * This function runs timers and the timer-tq in bottom half context.
70958 */
70959 -static void run_timer_softirq(struct softirq_action *h)
70960 +static void run_timer_softirq(void)
70961 {
70962 struct tvec_base *base = __this_cpu_read(tvec_bases);
70963
70964 diff -urNp linux-2.6.39.2/kernel/trace/blktrace.c linux-2.6.39.2/kernel/trace/blktrace.c
70965 --- linux-2.6.39.2/kernel/trace/blktrace.c 2011-05-19 00:06:34.000000000 -0400
70966 +++ linux-2.6.39.2/kernel/trace/blktrace.c 2011-05-22 19:36:33.000000000 -0400
70967 @@ -321,7 +321,7 @@ static ssize_t blk_dropped_read(struct f
70968 struct blk_trace *bt = filp->private_data;
70969 char buf[16];
70970
70971 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70972 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70973
70974 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70975 }
70976 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(str
70977 return 1;
70978
70979 bt = buf->chan->private_data;
70980 - atomic_inc(&bt->dropped);
70981 + atomic_inc_unchecked(&bt->dropped);
70982 return 0;
70983 }
70984
70985 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_qu
70986
70987 bt->dir = dir;
70988 bt->dev = dev;
70989 - atomic_set(&bt->dropped, 0);
70990 + atomic_set_unchecked(&bt->dropped, 0);
70991
70992 ret = -EIO;
70993 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70994 diff -urNp linux-2.6.39.2/kernel/trace/ftrace.c linux-2.6.39.2/kernel/trace/ftrace.c
70995 --- linux-2.6.39.2/kernel/trace/ftrace.c 2011-06-03 00:04:14.000000000 -0400
70996 +++ linux-2.6.39.2/kernel/trace/ftrace.c 2011-06-03 00:32:08.000000000 -0400
70997 @@ -1107,13 +1107,18 @@ ftrace_code_disable(struct module *mod,
70998
70999 ip = rec->ip;
71000
71001 + ret = ftrace_arch_code_modify_prepare();
71002 + FTRACE_WARN_ON(ret);
71003 + if (ret)
71004 + return 0;
71005 +
71006 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71007 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71008 if (ret) {
71009 ftrace_bug(ret, ip);
71010 rec->flags |= FTRACE_FL_FAILED;
71011 - return 0;
71012 }
71013 - return 1;
71014 + return ret ? 0 : 1;
71015 }
71016
71017 /*
71018 @@ -2011,7 +2016,7 @@ static void ftrace_free_entry_rcu(struct
71019
71020 int
71021 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71022 - void *data)
71023 + void *data)
71024 {
71025 struct ftrace_func_probe *entry;
71026 struct ftrace_page *pg;
71027 @@ -2083,7 +2088,7 @@ enum {
71028 };
71029
71030 static void
71031 -__unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71032 +__unregister_ftrace_function_probe(char *glob, const struct ftrace_probe_ops *ops,
71033 void *data, int flags)
71034 {
71035 struct ftrace_func_probe *entry;
71036 @@ -2144,7 +2149,7 @@ unregister_ftrace_function_probe(char *g
71037 }
71038
71039 void
71040 -unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
71041 +unregister_ftrace_function_probe_func(char *glob, const struct ftrace_probe_ops *ops)
71042 {
71043 __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC);
71044 }
71045 diff -urNp linux-2.6.39.2/kernel/trace/trace.c linux-2.6.39.2/kernel/trace/trace.c
71046 --- linux-2.6.39.2/kernel/trace/trace.c 2011-05-19 00:06:34.000000000 -0400
71047 +++ linux-2.6.39.2/kernel/trace/trace.c 2011-05-22 19:36:33.000000000 -0400
71048 @@ -3330,6 +3330,8 @@ static ssize_t tracing_splice_read_pipe(
71049 size_t rem;
71050 unsigned int i;
71051
71052 + pax_track_stack();
71053 +
71054 if (splice_grow_spd(pipe, &spd))
71055 return -ENOMEM;
71056
71057 @@ -3813,6 +3815,8 @@ tracing_buffers_splice_read(struct file
71058 int entries, size, i;
71059 size_t ret;
71060
71061 + pax_track_stack();
71062 +
71063 if (splice_grow_spd(pipe, &spd))
71064 return -ENOMEM;
71065
71066 @@ -3981,10 +3985,9 @@ static const struct file_operations trac
71067 };
71068 #endif
71069
71070 -static struct dentry *d_tracer;
71071 -
71072 struct dentry *tracing_init_dentry(void)
71073 {
71074 + static struct dentry *d_tracer;
71075 static int once;
71076
71077 if (d_tracer)
71078 @@ -4004,10 +4007,9 @@ struct dentry *tracing_init_dentry(void)
71079 return d_tracer;
71080 }
71081
71082 -static struct dentry *d_percpu;
71083 -
71084 struct dentry *tracing_dentry_percpu(void)
71085 {
71086 + static struct dentry *d_percpu;
71087 static int once;
71088 struct dentry *d_tracer;
71089
71090 diff -urNp linux-2.6.39.2/kernel/trace/trace_events.c linux-2.6.39.2/kernel/trace/trace_events.c
71091 --- linux-2.6.39.2/kernel/trace/trace_events.c 2011-05-19 00:06:34.000000000 -0400
71092 +++ linux-2.6.39.2/kernel/trace/trace_events.c 2011-05-22 19:36:33.000000000 -0400
71093 @@ -1241,10 +1241,10 @@ static LIST_HEAD(ftrace_module_file_list
71094 struct ftrace_module_file_ops {
71095 struct list_head list;
71096 struct module *mod;
71097 - struct file_operations id;
71098 - struct file_operations enable;
71099 - struct file_operations format;
71100 - struct file_operations filter;
71101 + struct file_operations id; /* cannot be const, see trace_create_file_ops() */
71102 + struct file_operations enable; /* cannot be const, see trace_create_file_ops() */
71103 + struct file_operations format; /* cannot be const, see trace_create_file_ops() */
71104 + struct file_operations filter; /* cannot be const, see trace_create_file_ops() */
71105 };
71106
71107 static struct ftrace_module_file_ops *
71108 diff -urNp linux-2.6.39.2/kernel/trace/trace_functions.c linux-2.6.39.2/kernel/trace/trace_functions.c
71109 --- linux-2.6.39.2/kernel/trace/trace_functions.c 2011-05-19 00:06:34.000000000 -0400
71110 +++ linux-2.6.39.2/kernel/trace/trace_functions.c 2011-05-22 19:36:33.000000000 -0400
71111 @@ -308,7 +308,7 @@ ftrace_trace_onoff_print(struct seq_file
71112 static int
71113 ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
71114 {
71115 - struct ftrace_probe_ops *ops;
71116 + const struct ftrace_probe_ops *ops;
71117
71118 /* we register both traceon and traceoff to this callback */
71119 if (strcmp(cmd, "traceon") == 0)
71120 diff -urNp linux-2.6.39.2/kernel/trace/trace_mmiotrace.c linux-2.6.39.2/kernel/trace/trace_mmiotrace.c
71121 --- linux-2.6.39.2/kernel/trace/trace_mmiotrace.c 2011-05-19 00:06:34.000000000 -0400
71122 +++ linux-2.6.39.2/kernel/trace/trace_mmiotrace.c 2011-05-22 19:36:33.000000000 -0400
71123 @@ -24,7 +24,7 @@ struct header_iter {
71124 static struct trace_array *mmio_trace_array;
71125 static bool overrun_detected;
71126 static unsigned long prev_overruns;
71127 -static atomic_t dropped_count;
71128 +static atomic_unchecked_t dropped_count;
71129
71130 static void mmio_reset_data(struct trace_array *tr)
71131 {
71132 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iter
71133
71134 static unsigned long count_overruns(struct trace_iterator *iter)
71135 {
71136 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71137 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71138 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71139
71140 if (over > prev_overruns)
71141 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct
71142 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71143 sizeof(*entry), 0, pc);
71144 if (!event) {
71145 - atomic_inc(&dropped_count);
71146 + atomic_inc_unchecked(&dropped_count);
71147 return;
71148 }
71149 entry = ring_buffer_event_data(event);
71150 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct
71151 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71152 sizeof(*entry), 0, pc);
71153 if (!event) {
71154 - atomic_inc(&dropped_count);
71155 + atomic_inc_unchecked(&dropped_count);
71156 return;
71157 }
71158 entry = ring_buffer_event_data(event);
71159 diff -urNp linux-2.6.39.2/kernel/trace/trace_output.c linux-2.6.39.2/kernel/trace/trace_output.c
71160 --- linux-2.6.39.2/kernel/trace/trace_output.c 2011-05-19 00:06:34.000000000 -0400
71161 +++ linux-2.6.39.2/kernel/trace/trace_output.c 2011-05-22 19:36:33.000000000 -0400
71162 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s,
71163
71164 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71165 if (!IS_ERR(p)) {
71166 - p = mangle_path(s->buffer + s->len, p, "\n");
71167 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71168 if (p) {
71169 s->len = p - s->buffer;
71170 return 1;
71171 diff -urNp linux-2.6.39.2/kernel/trace/trace_stack.c linux-2.6.39.2/kernel/trace/trace_stack.c
71172 --- linux-2.6.39.2/kernel/trace/trace_stack.c 2011-05-19 00:06:34.000000000 -0400
71173 +++ linux-2.6.39.2/kernel/trace/trace_stack.c 2011-05-22 19:36:33.000000000 -0400
71174 @@ -50,7 +50,7 @@ static inline void check_stack(void)
71175 return;
71176
71177 /* we do not handle interrupt stacks yet */
71178 - if (!object_is_on_stack(&this_size))
71179 + if (!object_starts_on_stack(&this_size))
71180 return;
71181
71182 local_irq_save(flags);
71183 diff -urNp linux-2.6.39.2/kernel/trace/trace_workqueue.c linux-2.6.39.2/kernel/trace/trace_workqueue.c
71184 --- linux-2.6.39.2/kernel/trace/trace_workqueue.c 2011-05-19 00:06:34.000000000 -0400
71185 +++ linux-2.6.39.2/kernel/trace/trace_workqueue.c 2011-05-22 19:36:33.000000000 -0400
71186 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
71187 int cpu;
71188 pid_t pid;
71189 /* Can be inserted from interrupt or user context, need to be atomic */
71190 - atomic_t inserted;
71191 + atomic_unchecked_t inserted;
71192 /*
71193 * Don't need to be atomic, works are serialized in a single workqueue thread
71194 * on a single CPU.
71195 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
71196 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
71197 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
71198 if (node->pid == wq_thread->pid) {
71199 - atomic_inc(&node->inserted);
71200 + atomic_inc_unchecked(&node->inserted);
71201 goto found;
71202 }
71203 }
71204 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct se
71205 tsk = get_pid_task(pid, PIDTYPE_PID);
71206 if (tsk) {
71207 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
71208 - atomic_read(&cws->inserted), cws->executed,
71209 + atomic_read_unchecked(&cws->inserted), cws->executed,
71210 tsk->comm);
71211 put_task_struct(tsk);
71212 }
71213 diff -urNp linux-2.6.39.2/lib/bug.c linux-2.6.39.2/lib/bug.c
71214 --- linux-2.6.39.2/lib/bug.c 2011-05-19 00:06:34.000000000 -0400
71215 +++ linux-2.6.39.2/lib/bug.c 2011-05-22 19:36:33.000000000 -0400
71216 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned l
71217 return BUG_TRAP_TYPE_NONE;
71218
71219 bug = find_bug(bugaddr);
71220 + if (!bug)
71221 + return BUG_TRAP_TYPE_NONE;
71222
71223 file = NULL;
71224 line = 0;
71225 diff -urNp linux-2.6.39.2/lib/debugobjects.c linux-2.6.39.2/lib/debugobjects.c
71226 --- linux-2.6.39.2/lib/debugobjects.c 2011-05-19 00:06:34.000000000 -0400
71227 +++ linux-2.6.39.2/lib/debugobjects.c 2011-05-22 19:36:33.000000000 -0400
71228 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(voi
71229 if (limit > 4)
71230 return;
71231
71232 - is_on_stack = object_is_on_stack(addr);
71233 + is_on_stack = object_starts_on_stack(addr);
71234 if (is_on_stack == onstack)
71235 return;
71236
71237 diff -urNp linux-2.6.39.2/lib/dma-debug.c linux-2.6.39.2/lib/dma-debug.c
71238 --- linux-2.6.39.2/lib/dma-debug.c 2011-05-19 00:06:34.000000000 -0400
71239 +++ linux-2.6.39.2/lib/dma-debug.c 2011-05-22 19:36:33.000000000 -0400
71240 @@ -862,7 +862,7 @@ out:
71241
71242 static void check_for_stack(struct device *dev, void *addr)
71243 {
71244 - if (object_is_on_stack(addr))
71245 + if (object_starts_on_stack(addr))
71246 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71247 "stack [addr=%p]\n", addr);
71248 }
71249 diff -urNp linux-2.6.39.2/lib/inflate.c linux-2.6.39.2/lib/inflate.c
71250 --- linux-2.6.39.2/lib/inflate.c 2011-05-19 00:06:34.000000000 -0400
71251 +++ linux-2.6.39.2/lib/inflate.c 2011-05-22 19:36:33.000000000 -0400
71252 @@ -269,7 +269,7 @@ static void free(void *where)
71253 malloc_ptr = free_mem_ptr;
71254 }
71255 #else
71256 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71257 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71258 #define free(a) kfree(a)
71259 #endif
71260
71261 diff -urNp linux-2.6.39.2/lib/Kconfig.debug linux-2.6.39.2/lib/Kconfig.debug
71262 --- linux-2.6.39.2/lib/Kconfig.debug 2011-05-19 00:06:34.000000000 -0400
71263 +++ linux-2.6.39.2/lib/Kconfig.debug 2011-05-22 19:41:42.000000000 -0400
71264 @@ -1078,6 +1078,7 @@ config LATENCYTOP
71265 depends on DEBUG_KERNEL
71266 depends on STACKTRACE_SUPPORT
71267 depends on PROC_FS
71268 + depends on !GRKERNSEC_HIDESYM
71269 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE
71270 select KALLSYMS
71271 select KALLSYMS_ALL
71272 diff -urNp linux-2.6.39.2/lib/kref.c linux-2.6.39.2/lib/kref.c
71273 --- linux-2.6.39.2/lib/kref.c 2011-05-19 00:06:34.000000000 -0400
71274 +++ linux-2.6.39.2/lib/kref.c 2011-05-22 19:36:33.000000000 -0400
71275 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
71276 */
71277 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
71278 {
71279 - WARN_ON(release == NULL);
71280 + BUG_ON(release == NULL);
71281 WARN_ON(release == (void (*)(struct kref *))kfree);
71282
71283 if (atomic_dec_and_test(&kref->refcount)) {
71284 diff -urNp linux-2.6.39.2/lib/radix-tree.c linux-2.6.39.2/lib/radix-tree.c
71285 --- linux-2.6.39.2/lib/radix-tree.c 2011-05-19 00:06:34.000000000 -0400
71286 +++ linux-2.6.39.2/lib/radix-tree.c 2011-05-22 19:36:33.000000000 -0400
71287 @@ -80,7 +80,7 @@ struct radix_tree_preload {
71288 int nr;
71289 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71290 };
71291 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71292 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71293
71294 static inline void *ptr_to_indirect(void *ptr)
71295 {
71296 diff -urNp linux-2.6.39.2/lib/vsprintf.c linux-2.6.39.2/lib/vsprintf.c
71297 --- linux-2.6.39.2/lib/vsprintf.c 2011-05-19 00:06:34.000000000 -0400
71298 +++ linux-2.6.39.2/lib/vsprintf.c 2011-05-22 20:54:59.000000000 -0400
71299 @@ -16,6 +16,9 @@
71300 * - scnprintf and vscnprintf
71301 */
71302
71303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71304 +#define __INCLUDED_BY_HIDESYM 1
71305 +#endif
71306 #include <stdarg.h>
71307 #include <linux/module.h>
71308 #include <linux/types.h>
71309 @@ -435,7 +438,7 @@ char *symbol_string(char *buf, char *end
71310 char sym[KSYM_SYMBOL_LEN];
71311 if (ext == 'B')
71312 sprint_backtrace(sym, value);
71313 - else if (ext != 'f' && ext != 's')
71314 + else if (ext != 'f' && ext != 's' && ext != 'a')
71315 sprint_symbol(sym, value);
71316 else
71317 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71318 @@ -797,7 +800,11 @@ char *uuid_string(char *buf, char *end,
71319 return string(buf, end, uuid, spec);
71320 }
71321
71322 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71323 +int kptr_restrict __read_mostly = 2;
71324 +#else
71325 int kptr_restrict __read_mostly;
71326 +#endif
71327
71328 /*
71329 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71330 @@ -811,6 +818,8 @@ int kptr_restrict __read_mostly;
71331 * - 'S' For symbolic direct pointers with offset
71332 * - 's' For symbolic direct pointers without offset
71333 * - 'B' For backtraced symbolic direct pointers with offset
71334 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71335 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71336 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71337 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71338 * - 'M' For a 6-byte MAC address, it prints the address in the
71339 @@ -855,12 +864,12 @@ char *pointer(const char *fmt, char *buf
71340 {
71341 if (!ptr && *fmt != 'K') {
71342 /*
71343 - * Print (null) with the same width as a pointer so it makes
71344 + * Print (nil) with the same width as a pointer so it makes
71345 * tabular output look nice.
71346 */
71347 if (spec.field_width == -1)
71348 spec.field_width = 2 * sizeof(void *);
71349 - return string(buf, end, "(null)", spec);
71350 + return string(buf, end, "(nil)", spec);
71351 }
71352
71353 switch (*fmt) {
71354 @@ -870,6 +879,13 @@ char *pointer(const char *fmt, char *buf
71355 /* Fallthrough */
71356 case 'S':
71357 case 's':
71358 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71359 + break;
71360 +#else
71361 + return symbol_string(buf, end, ptr, spec, *fmt);
71362 +#endif
71363 + case 'A':
71364 + case 'a':
71365 case 'B':
71366 return symbol_string(buf, end, ptr, spec, *fmt);
71367 case 'R':
71368 @@ -1632,11 +1648,11 @@ int bstr_printf(char *buf, size_t size,
71369 typeof(type) value; \
71370 if (sizeof(type) == 8) { \
71371 args = PTR_ALIGN(args, sizeof(u32)); \
71372 - *(u32 *)&value = *(u32 *)args; \
71373 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71374 + *(u32 *)&value = *(const u32 *)args; \
71375 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71376 } else { \
71377 args = PTR_ALIGN(args, sizeof(type)); \
71378 - value = *(typeof(type) *)args; \
71379 + value = *(const typeof(type) *)args; \
71380 } \
71381 args += sizeof(type); \
71382 value; \
71383 @@ -1699,7 +1715,7 @@ int bstr_printf(char *buf, size_t size,
71384 case FORMAT_TYPE_STR: {
71385 const char *str_arg = args;
71386 args += strlen(str_arg) + 1;
71387 - str = string(str, end, (char *)str_arg, spec);
71388 + str = string(str, end, str_arg, spec);
71389 break;
71390 }
71391
71392 diff -urNp linux-2.6.39.2/localversion-grsec linux-2.6.39.2/localversion-grsec
71393 --- linux-2.6.39.2/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
71394 +++ linux-2.6.39.2/localversion-grsec 2011-05-22 19:41:42.000000000 -0400
71395 @@ -0,0 +1 @@
71396 +-grsec
71397 diff -urNp linux-2.6.39.2/Makefile linux-2.6.39.2/Makefile
71398 --- linux-2.6.39.2/Makefile 2011-06-25 12:55:22.000000000 -0400
71399 +++ linux-2.6.39.2/Makefile 2011-06-25 13:00:25.000000000 -0400
71400 @@ -237,8 +237,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
71401
71402 HOSTCC = gcc
71403 HOSTCXX = g++
71404 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
71405 -HOSTCXXFLAGS = -O2
71406 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
71407 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
71408 +HOSTCXXFLAGS = -O2 -fno-delete-null-pointer-checks
71409
71410 # Decide whether to build built-in, modular, or both.
71411 # Normally, just do built-in.
71412 @@ -356,10 +357,12 @@ LINUXINCLUDE := -I$(srctree)/arch/$(h
71413 KBUILD_CPPFLAGS := -D__KERNEL__
71414
71415 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
71416 + -W -Wno-unused-parameter -Wno-missing-field-initializers \
71417 -fno-strict-aliasing -fno-common \
71418 -Werror-implicit-function-declaration \
71419 -Wno-format-security \
71420 -fno-delete-null-pointer-checks
71421 +KBUILD_CFLAGS += $(call cc-option, -Wno-empty-body)
71422 KBUILD_AFLAGS_KERNEL :=
71423 KBUILD_CFLAGS_KERNEL :=
71424 KBUILD_AFLAGS := -D__ASSEMBLY__
71425 @@ -685,7 +688,7 @@ export mod_strip_cmd
71426
71427
71428 ifeq ($(KBUILD_EXTMOD),)
71429 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
71430 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
71431
71432 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
71433 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
71434 @@ -931,7 +934,19 @@ include/config/kernel.release: include/c
71435 # version.h and scripts_basic is processed / created.
71436
71437 # Listed in dependency order
71438 -PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
71439 +PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 pax-plugin
71440 +
71441 +ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71442 +KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0405, -fplugin=$(objtree)/tools/gcc/pax_plugin.so -fplugin-arg-pax_plugin-track-lowest-sp=100)
71443 +endif
71444 +pax-plugin:
71445 +ifneq (,$(findstring pax_plugin, $(KBUILD_CFLAGS)))
71446 + $(Q)$(MAKE) $(build)=tools/gcc
71447 +else
71448 +ifeq ($(CONFIG_PAX_MEMORY_STACKLEAK),y)
71449 + $(Q)echo "warning, your gcc does not support plugins, PAX_MEMORY_STACKLEAK will be less secure"
71450 +endif
71451 +endif
71452
71453 # prepare3 is used to check if we are building in a separate output directory,
71454 # and if so do:
71455 @@ -947,7 +962,7 @@ ifneq ($(KBUILD_SRC),)
71456 endif
71457
71458 # prepare2 creates a makefile if using a separate output directory
71459 -prepare2: prepare3 outputmakefile
71460 +prepare2: prepare3 outputmakefile pax-plugin
71461
71462 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
71463 include/config/auto.conf
71464 diff -urNp linux-2.6.39.2/mm/filemap.c linux-2.6.39.2/mm/filemap.c
71465 --- linux-2.6.39.2/mm/filemap.c 2011-05-19 00:06:34.000000000 -0400
71466 +++ linux-2.6.39.2/mm/filemap.c 2011-05-22 19:41:42.000000000 -0400
71467 @@ -1724,7 +1724,7 @@ int generic_file_mmap(struct file * file
71468 struct address_space *mapping = file->f_mapping;
71469
71470 if (!mapping->a_ops->readpage)
71471 - return -ENOEXEC;
71472 + return -ENODEV;
71473 file_accessed(file);
71474 vma->vm_ops = &generic_file_vm_ops;
71475 vma->vm_flags |= VM_CAN_NONLINEAR;
71476 @@ -2120,6 +2120,7 @@ inline int generic_write_checks(struct f
71477 *pos = i_size_read(inode);
71478
71479 if (limit != RLIM_INFINITY) {
71480 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71481 if (*pos >= limit) {
71482 send_sig(SIGXFSZ, current, 0);
71483 return -EFBIG;
71484 diff -urNp linux-2.6.39.2/mm/fremap.c linux-2.6.39.2/mm/fremap.c
71485 --- linux-2.6.39.2/mm/fremap.c 2011-05-19 00:06:34.000000000 -0400
71486 +++ linux-2.6.39.2/mm/fremap.c 2011-05-22 19:36:33.000000000 -0400
71487 @@ -156,6 +156,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71488 retry:
71489 vma = find_vma(mm, start);
71490
71491 +#ifdef CONFIG_PAX_SEGMEXEC
71492 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71493 + goto out;
71494 +#endif
71495 +
71496 /*
71497 * Make sure the vma is shared, that it supports prefaulting,
71498 * and that the remapped range is valid and fully within
71499 @@ -224,7 +229,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
71500 /*
71501 * drop PG_Mlocked flag for over-mapped range
71502 */
71503 - unsigned int saved_flags = vma->vm_flags;
71504 + unsigned long saved_flags = vma->vm_flags;
71505 munlock_vma_pages_range(vma, start, start + size);
71506 vma->vm_flags = saved_flags;
71507 }
71508 diff -urNp linux-2.6.39.2/mm/highmem.c linux-2.6.39.2/mm/highmem.c
71509 --- linux-2.6.39.2/mm/highmem.c 2011-05-19 00:06:34.000000000 -0400
71510 +++ linux-2.6.39.2/mm/highmem.c 2011-05-22 19:36:33.000000000 -0400
71511 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71512 * So no dangers, even with speculative execution.
71513 */
71514 page = pte_page(pkmap_page_table[i]);
71515 + pax_open_kernel();
71516 pte_clear(&init_mm, (unsigned long)page_address(page),
71517 &pkmap_page_table[i]);
71518 -
71519 + pax_close_kernel();
71520 set_page_address(page, NULL);
71521 need_flush = 1;
71522 }
71523 @@ -186,9 +187,11 @@ start:
71524 }
71525 }
71526 vaddr = PKMAP_ADDR(last_pkmap_nr);
71527 +
71528 + pax_open_kernel();
71529 set_pte_at(&init_mm, vaddr,
71530 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71531 -
71532 + pax_close_kernel();
71533 pkmap_count[last_pkmap_nr] = 1;
71534 set_page_address(page, (void *)vaddr);
71535
71536 diff -urNp linux-2.6.39.2/mm/huge_memory.c linux-2.6.39.2/mm/huge_memory.c
71537 --- linux-2.6.39.2/mm/huge_memory.c 2011-05-19 00:06:34.000000000 -0400
71538 +++ linux-2.6.39.2/mm/huge_memory.c 2011-05-22 19:36:33.000000000 -0400
71539 @@ -702,7 +702,7 @@ out:
71540 * run pte_offset_map on the pmd, if an huge pmd could
71541 * materialize from under us from a different thread.
71542 */
71543 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71544 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71545 return VM_FAULT_OOM;
71546 /* if an huge pmd materialized from under us just retry later */
71547 if (unlikely(pmd_trans_huge(*pmd)))
71548 diff -urNp linux-2.6.39.2/mm/hugetlb.c linux-2.6.39.2/mm/hugetlb.c
71549 --- linux-2.6.39.2/mm/hugetlb.c 2011-06-25 12:55:23.000000000 -0400
71550 +++ linux-2.6.39.2/mm/hugetlb.c 2011-06-25 13:00:28.000000000 -0400
71551 @@ -2331,6 +2331,27 @@ static int unmap_ref_private(struct mm_s
71552 return 1;
71553 }
71554
71555 +#ifdef CONFIG_PAX_SEGMEXEC
71556 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71557 +{
71558 + struct mm_struct *mm = vma->vm_mm;
71559 + struct vm_area_struct *vma_m;
71560 + unsigned long address_m;
71561 + pte_t *ptep_m;
71562 +
71563 + vma_m = pax_find_mirror_vma(vma);
71564 + if (!vma_m)
71565 + return;
71566 +
71567 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71568 + address_m = address + SEGMEXEC_TASK_SIZE;
71569 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71570 + get_page(page_m);
71571 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71572 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71573 +}
71574 +#endif
71575 +
71576 /*
71577 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71578 */
71579 @@ -2432,6 +2453,11 @@ retry_avoidcopy:
71580 make_huge_pte(vma, new_page, 1));
71581 page_remove_rmap(old_page);
71582 hugepage_add_new_anon_rmap(new_page, vma, address);
71583 +
71584 +#ifdef CONFIG_PAX_SEGMEXEC
71585 + pax_mirror_huge_pte(vma, address, new_page);
71586 +#endif
71587 +
71588 /* Make the old page be freed below */
71589 new_page = old_page;
71590 mmu_notifier_invalidate_range_end(mm,
71591 @@ -2583,6 +2609,10 @@ retry:
71592 && (vma->vm_flags & VM_SHARED)));
71593 set_huge_pte_at(mm, address, ptep, new_pte);
71594
71595 +#ifdef CONFIG_PAX_SEGMEXEC
71596 + pax_mirror_huge_pte(vma, address, page);
71597 +#endif
71598 +
71599 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71600 /* Optimization, do the COW without a second fault */
71601 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71602 @@ -2612,6 +2642,10 @@ int hugetlb_fault(struct mm_struct *mm,
71603 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71604 struct hstate *h = hstate_vma(vma);
71605
71606 +#ifdef CONFIG_PAX_SEGMEXEC
71607 + struct vm_area_struct *vma_m;
71608 +#endif
71609 +
71610 ptep = huge_pte_offset(mm, address);
71611 if (ptep) {
71612 entry = huge_ptep_get(ptep);
71613 @@ -2623,6 +2657,26 @@ int hugetlb_fault(struct mm_struct *mm,
71614 VM_FAULT_SET_HINDEX(h - hstates);
71615 }
71616
71617 +#ifdef CONFIG_PAX_SEGMEXEC
71618 + vma_m = pax_find_mirror_vma(vma);
71619 + if (vma_m) {
71620 + unsigned long address_m;
71621 +
71622 + if (vma->vm_start > vma_m->vm_start) {
71623 + address_m = address;
71624 + address -= SEGMEXEC_TASK_SIZE;
71625 + vma = vma_m;
71626 + h = hstate_vma(vma);
71627 + } else
71628 + address_m = address + SEGMEXEC_TASK_SIZE;
71629 +
71630 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71631 + return VM_FAULT_OOM;
71632 + address_m &= HPAGE_MASK;
71633 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71634 + }
71635 +#endif
71636 +
71637 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71638 if (!ptep)
71639 return VM_FAULT_OOM;
71640 diff -urNp linux-2.6.39.2/mm/Kconfig linux-2.6.39.2/mm/Kconfig
71641 --- linux-2.6.39.2/mm/Kconfig 2011-05-19 00:06:34.000000000 -0400
71642 +++ linux-2.6.39.2/mm/Kconfig 2011-05-22 19:41:42.000000000 -0400
71643 @@ -240,7 +240,7 @@ config KSM
71644 config DEFAULT_MMAP_MIN_ADDR
71645 int "Low address space to protect from user allocation"
71646 depends on MMU
71647 - default 4096
71648 + default 65536
71649 help
71650 This is the portion of low virtual memory which should be protected
71651 from userspace allocation. Keeping a user from writing to low pages
71652 diff -urNp linux-2.6.39.2/mm/kmemleak.c linux-2.6.39.2/mm/kmemleak.c
71653 --- linux-2.6.39.2/mm/kmemleak.c 2011-06-03 00:04:14.000000000 -0400
71654 +++ linux-2.6.39.2/mm/kmemleak.c 2011-06-03 00:32:08.000000000 -0400
71655 @@ -357,7 +357,7 @@ static void print_unreferenced(struct se
71656
71657 for (i = 0; i < object->trace_len; i++) {
71658 void *ptr = (void *)object->trace[i];
71659 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71660 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71661 }
71662 }
71663
71664 diff -urNp linux-2.6.39.2/mm/ksm.c linux-2.6.39.2/mm/ksm.c
71665 --- linux-2.6.39.2/mm/ksm.c 2011-05-19 00:06:34.000000000 -0400
71666 +++ linux-2.6.39.2/mm/ksm.c 2011-06-20 19:42:16.000000000 -0400
71667 @@ -1301,6 +1301,12 @@ static struct rmap_item *scan_get_next_r
71668 slot = list_entry(slot->mm_list.next, struct mm_slot, mm_list);
71669 ksm_scan.mm_slot = slot;
71670 spin_unlock(&ksm_mmlist_lock);
71671 + /*
71672 + * Although we tested list_empty() above, a racing __ksm_exit
71673 + * of the last mm on the list may have removed it since then.
71674 + */
71675 + if (slot == &ksm_mm_head)
71676 + return NULL;
71677 next_mm:
71678 ksm_scan.address = 0;
71679 ksm_scan.rmap_list = &slot->rmap_list;
71680 diff -urNp linux-2.6.39.2/mm/maccess.c linux-2.6.39.2/mm/maccess.c
71681 --- linux-2.6.39.2/mm/maccess.c 2011-05-19 00:06:34.000000000 -0400
71682 +++ linux-2.6.39.2/mm/maccess.c 2011-05-22 19:36:33.000000000 -0400
71683 @@ -15,10 +15,10 @@
71684 * happens, handle that and return -EFAULT.
71685 */
71686
71687 -long __weak probe_kernel_read(void *dst, void *src, size_t size)
71688 +long __weak probe_kernel_read(void *dst, const void *src, size_t size)
71689 __attribute__((alias("__probe_kernel_read")));
71690
71691 -long __probe_kernel_read(void *dst, void *src, size_t size)
71692 +long __probe_kernel_read(void *dst, const void *src, size_t size)
71693 {
71694 long ret;
71695 mm_segment_t old_fs = get_fs();
71696 @@ -43,10 +43,10 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
71697 * Safely write to address @dst from the buffer at @src. If a kernel fault
71698 * happens, handle that and return -EFAULT.
71699 */
71700 -long __weak probe_kernel_write(void *dst, void *src, size_t size)
71701 +long __weak probe_kernel_write(void *dst, const void *src, size_t size)
71702 __attribute__((alias("__probe_kernel_write")));
71703
71704 -long __probe_kernel_write(void *dst, void *src, size_t size)
71705 +long __probe_kernel_write(void *dst, const void *src, size_t size)
71706 {
71707 long ret;
71708 mm_segment_t old_fs = get_fs();
71709 diff -urNp linux-2.6.39.2/mm/madvise.c linux-2.6.39.2/mm/madvise.c
71710 --- linux-2.6.39.2/mm/madvise.c 2011-05-19 00:06:34.000000000 -0400
71711 +++ linux-2.6.39.2/mm/madvise.c 2011-05-22 19:36:33.000000000 -0400
71712 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_a
71713 pgoff_t pgoff;
71714 unsigned long new_flags = vma->vm_flags;
71715
71716 +#ifdef CONFIG_PAX_SEGMEXEC
71717 + struct vm_area_struct *vma_m;
71718 +#endif
71719 +
71720 switch (behavior) {
71721 case MADV_NORMAL:
71722 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71723 @@ -110,6 +114,13 @@ success:
71724 /*
71725 * vm_flags is protected by the mmap_sem held in write mode.
71726 */
71727 +
71728 +#ifdef CONFIG_PAX_SEGMEXEC
71729 + vma_m = pax_find_mirror_vma(vma);
71730 + if (vma_m)
71731 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71732 +#endif
71733 +
71734 vma->vm_flags = new_flags;
71735
71736 out:
71737 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_a
71738 struct vm_area_struct ** prev,
71739 unsigned long start, unsigned long end)
71740 {
71741 +
71742 +#ifdef CONFIG_PAX_SEGMEXEC
71743 + struct vm_area_struct *vma_m;
71744 +#endif
71745 +
71746 *prev = vma;
71747 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71748 return -EINVAL;
71749 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_a
71750 zap_page_range(vma, start, end - start, &details);
71751 } else
71752 zap_page_range(vma, start, end - start, NULL);
71753 +
71754 +#ifdef CONFIG_PAX_SEGMEXEC
71755 + vma_m = pax_find_mirror_vma(vma);
71756 + if (vma_m) {
71757 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71758 + struct zap_details details = {
71759 + .nonlinear_vma = vma_m,
71760 + .last_index = ULONG_MAX,
71761 + };
71762 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71763 + } else
71764 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71765 + }
71766 +#endif
71767 +
71768 return 0;
71769 }
71770
71771 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long,
71772 if (end < start)
71773 goto out;
71774
71775 +#ifdef CONFIG_PAX_SEGMEXEC
71776 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71777 + if (end > SEGMEXEC_TASK_SIZE)
71778 + goto out;
71779 + } else
71780 +#endif
71781 +
71782 + if (end > TASK_SIZE)
71783 + goto out;
71784 +
71785 error = 0;
71786 if (end == start)
71787 goto out;
71788 diff -urNp linux-2.6.39.2/mm/memory.c linux-2.6.39.2/mm/memory.c
71789 --- linux-2.6.39.2/mm/memory.c 2011-05-19 00:06:34.000000000 -0400
71790 +++ linux-2.6.39.2/mm/memory.c 2011-05-22 19:36:33.000000000 -0400
71791 @@ -259,8 +259,12 @@ static inline void free_pmd_range(struct
71792 return;
71793
71794 pmd = pmd_offset(pud, start);
71795 +
71796 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71797 pud_clear(pud);
71798 pmd_free_tlb(tlb, pmd, start);
71799 +#endif
71800 +
71801 }
71802
71803 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71804 @@ -291,9 +295,12 @@ static inline void free_pud_range(struct
71805 if (end - 1 > ceiling - 1)
71806 return;
71807
71808 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71809 pud = pud_offset(pgd, start);
71810 pgd_clear(pgd);
71811 pud_free_tlb(tlb, pud, start);
71812 +#endif
71813 +
71814 }
71815
71816 /*
71817 @@ -1410,12 +1417,6 @@ no_page_table:
71818 return page;
71819 }
71820
71821 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71822 -{
71823 - return stack_guard_page_start(vma, addr) ||
71824 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71825 -}
71826 -
71827 /**
71828 * __get_user_pages() - pin user pages in memory
71829 * @tsk: task_struct of target task
71830 @@ -1488,10 +1489,10 @@ int __get_user_pages(struct task_struct
71831 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71832 i = 0;
71833
71834 - do {
71835 + while (nr_pages) {
71836 struct vm_area_struct *vma;
71837
71838 - vma = find_extend_vma(mm, start);
71839 + vma = find_vma(mm, start);
71840 if (!vma && in_gate_area(mm, start)) {
71841 unsigned long pg = start & PAGE_MASK;
71842 pgd_t *pgd;
71843 @@ -1539,7 +1540,7 @@ int __get_user_pages(struct task_struct
71844 goto next_page;
71845 }
71846
71847 - if (!vma ||
71848 + if (!vma || start < vma->vm_start ||
71849 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71850 !(vm_flags & vma->vm_flags))
71851 return i ? : -EFAULT;
71852 @@ -1566,11 +1567,6 @@ int __get_user_pages(struct task_struct
71853 int ret;
71854 unsigned int fault_flags = 0;
71855
71856 - /* For mlock, just skip the stack guard page. */
71857 - if (foll_flags & FOLL_MLOCK) {
71858 - if (stack_guard_page(vma, start))
71859 - goto next_page;
71860 - }
71861 if (foll_flags & FOLL_WRITE)
71862 fault_flags |= FAULT_FLAG_WRITE;
71863 if (nonblocking)
71864 @@ -1644,7 +1640,7 @@ next_page:
71865 start += PAGE_SIZE;
71866 nr_pages--;
71867 } while (nr_pages && start < vma->vm_end);
71868 - } while (nr_pages);
71869 + }
71870 return i;
71871 }
71872 EXPORT_SYMBOL(__get_user_pages);
71873 @@ -1795,6 +1791,10 @@ static int insert_page(struct vm_area_st
71874 page_add_file_rmap(page);
71875 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71876
71877 +#ifdef CONFIG_PAX_SEGMEXEC
71878 + pax_mirror_file_pte(vma, addr, page, ptl);
71879 +#endif
71880 +
71881 retval = 0;
71882 pte_unmap_unlock(pte, ptl);
71883 return retval;
71884 @@ -1829,10 +1829,22 @@ out:
71885 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71886 struct page *page)
71887 {
71888 +
71889 +#ifdef CONFIG_PAX_SEGMEXEC
71890 + struct vm_area_struct *vma_m;
71891 +#endif
71892 +
71893 if (addr < vma->vm_start || addr >= vma->vm_end)
71894 return -EFAULT;
71895 if (!page_count(page))
71896 return -EINVAL;
71897 +
71898 +#ifdef CONFIG_PAX_SEGMEXEC
71899 + vma_m = pax_find_mirror_vma(vma);
71900 + if (vma_m)
71901 + vma_m->vm_flags |= VM_INSERTPAGE;
71902 +#endif
71903 +
71904 vma->vm_flags |= VM_INSERTPAGE;
71905 return insert_page(vma, addr, page, vma->vm_page_prot);
71906 }
71907 @@ -1918,6 +1930,7 @@ int vm_insert_mixed(struct vm_area_struc
71908 unsigned long pfn)
71909 {
71910 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71911 + BUG_ON(vma->vm_mirror);
71912
71913 if (addr < vma->vm_start || addr >= vma->vm_end)
71914 return -EFAULT;
71915 @@ -2233,6 +2246,186 @@ static inline void cow_user_page(struct
71916 copy_user_highpage(dst, src, va, vma);
71917 }
71918
71919 +#ifdef CONFIG_PAX_SEGMEXEC
71920 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71921 +{
71922 + struct mm_struct *mm = vma->vm_mm;
71923 + spinlock_t *ptl;
71924 + pte_t *pte, entry;
71925 +
71926 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71927 + entry = *pte;
71928 + if (!pte_present(entry)) {
71929 + if (!pte_none(entry)) {
71930 + BUG_ON(pte_file(entry));
71931 + free_swap_and_cache(pte_to_swp_entry(entry));
71932 + pte_clear_not_present_full(mm, address, pte, 0);
71933 + }
71934 + } else {
71935 + struct page *page;
71936 +
71937 + flush_cache_page(vma, address, pte_pfn(entry));
71938 + entry = ptep_clear_flush(vma, address, pte);
71939 + BUG_ON(pte_dirty(entry));
71940 + page = vm_normal_page(vma, address, entry);
71941 + if (page) {
71942 + update_hiwater_rss(mm);
71943 + if (PageAnon(page))
71944 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71945 + else
71946 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71947 + page_remove_rmap(page);
71948 + page_cache_release(page);
71949 + }
71950 + }
71951 + pte_unmap_unlock(pte, ptl);
71952 +}
71953 +
71954 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71955 + *
71956 + * the ptl of the lower mapped page is held on entry and is not released on exit
71957 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71958 + */
71959 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71960 +{
71961 + struct mm_struct *mm = vma->vm_mm;
71962 + unsigned long address_m;
71963 + spinlock_t *ptl_m;
71964 + struct vm_area_struct *vma_m;
71965 + pmd_t *pmd_m;
71966 + pte_t *pte_m, entry_m;
71967 +
71968 + BUG_ON(!page_m || !PageAnon(page_m));
71969 +
71970 + vma_m = pax_find_mirror_vma(vma);
71971 + if (!vma_m)
71972 + return;
71973 +
71974 + BUG_ON(!PageLocked(page_m));
71975 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71976 + address_m = address + SEGMEXEC_TASK_SIZE;
71977 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71978 + pte_m = pte_offset_map(pmd_m, address_m);
71979 + ptl_m = pte_lockptr(mm, pmd_m);
71980 + if (ptl != ptl_m) {
71981 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71982 + if (!pte_none(*pte_m))
71983 + goto out;
71984 + }
71985 +
71986 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71987 + page_cache_get(page_m);
71988 + page_add_anon_rmap(page_m, vma_m, address_m);
71989 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71990 + set_pte_at(mm, address_m, pte_m, entry_m);
71991 + update_mmu_cache(vma_m, address_m, entry_m);
71992 +out:
71993 + if (ptl != ptl_m)
71994 + spin_unlock(ptl_m);
71995 + pte_unmap(pte_m);
71996 + unlock_page(page_m);
71997 +}
71998 +
71999 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72000 +{
72001 + struct mm_struct *mm = vma->vm_mm;
72002 + unsigned long address_m;
72003 + spinlock_t *ptl_m;
72004 + struct vm_area_struct *vma_m;
72005 + pmd_t *pmd_m;
72006 + pte_t *pte_m, entry_m;
72007 +
72008 + BUG_ON(!page_m || PageAnon(page_m));
72009 +
72010 + vma_m = pax_find_mirror_vma(vma);
72011 + if (!vma_m)
72012 + return;
72013 +
72014 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72015 + address_m = address + SEGMEXEC_TASK_SIZE;
72016 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72017 + pte_m = pte_offset_map(pmd_m, address_m);
72018 + ptl_m = pte_lockptr(mm, pmd_m);
72019 + if (ptl != ptl_m) {
72020 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72021 + if (!pte_none(*pte_m))
72022 + goto out;
72023 + }
72024 +
72025 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72026 + page_cache_get(page_m);
72027 + page_add_file_rmap(page_m);
72028 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72029 + set_pte_at(mm, address_m, pte_m, entry_m);
72030 + update_mmu_cache(vma_m, address_m, entry_m);
72031 +out:
72032 + if (ptl != ptl_m)
72033 + spin_unlock(ptl_m);
72034 + pte_unmap(pte_m);
72035 +}
72036 +
72037 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72038 +{
72039 + struct mm_struct *mm = vma->vm_mm;
72040 + unsigned long address_m;
72041 + spinlock_t *ptl_m;
72042 + struct vm_area_struct *vma_m;
72043 + pmd_t *pmd_m;
72044 + pte_t *pte_m, entry_m;
72045 +
72046 + vma_m = pax_find_mirror_vma(vma);
72047 + if (!vma_m)
72048 + return;
72049 +
72050 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72051 + address_m = address + SEGMEXEC_TASK_SIZE;
72052 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72053 + pte_m = pte_offset_map(pmd_m, address_m);
72054 + ptl_m = pte_lockptr(mm, pmd_m);
72055 + if (ptl != ptl_m) {
72056 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72057 + if (!pte_none(*pte_m))
72058 + goto out;
72059 + }
72060 +
72061 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72062 + set_pte_at(mm, address_m, pte_m, entry_m);
72063 +out:
72064 + if (ptl != ptl_m)
72065 + spin_unlock(ptl_m);
72066 + pte_unmap(pte_m);
72067 +}
72068 +
72069 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72070 +{
72071 + struct page *page_m;
72072 + pte_t entry;
72073 +
72074 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72075 + goto out;
72076 +
72077 + entry = *pte;
72078 + page_m = vm_normal_page(vma, address, entry);
72079 + if (!page_m)
72080 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72081 + else if (PageAnon(page_m)) {
72082 + if (pax_find_mirror_vma(vma)) {
72083 + pte_unmap_unlock(pte, ptl);
72084 + lock_page(page_m);
72085 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72086 + if (pte_same(entry, *pte))
72087 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72088 + else
72089 + unlock_page(page_m);
72090 + }
72091 + } else
72092 + pax_mirror_file_pte(vma, address, page_m, ptl);
72093 +
72094 +out:
72095 + pte_unmap_unlock(pte, ptl);
72096 +}
72097 +#endif
72098 +
72099 /*
72100 * This routine handles present pages, when users try to write
72101 * to a shared page. It is done by copying the page to a new address
72102 @@ -2444,6 +2637,12 @@ gotten:
72103 */
72104 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72105 if (likely(pte_same(*page_table, orig_pte))) {
72106 +
72107 +#ifdef CONFIG_PAX_SEGMEXEC
72108 + if (pax_find_mirror_vma(vma))
72109 + BUG_ON(!trylock_page(new_page));
72110 +#endif
72111 +
72112 if (old_page) {
72113 if (!PageAnon(old_page)) {
72114 dec_mm_counter_fast(mm, MM_FILEPAGES);
72115 @@ -2495,6 +2694,10 @@ gotten:
72116 page_remove_rmap(old_page);
72117 }
72118
72119 +#ifdef CONFIG_PAX_SEGMEXEC
72120 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72121 +#endif
72122 +
72123 /* Free the old page.. */
72124 new_page = old_page;
72125 ret |= VM_FAULT_WRITE;
72126 @@ -2905,6 +3108,11 @@ static int do_swap_page(struct mm_struct
72127 swap_free(entry);
72128 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72129 try_to_free_swap(page);
72130 +
72131 +#ifdef CONFIG_PAX_SEGMEXEC
72132 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72133 +#endif
72134 +
72135 unlock_page(page);
72136 if (swapcache) {
72137 /*
72138 @@ -2928,6 +3136,11 @@ static int do_swap_page(struct mm_struct
72139
72140 /* No need to invalidate - it was non-present before */
72141 update_mmu_cache(vma, address, page_table);
72142 +
72143 +#ifdef CONFIG_PAX_SEGMEXEC
72144 + pax_mirror_anon_pte(vma, address, page, ptl);
72145 +#endif
72146 +
72147 unlock:
72148 pte_unmap_unlock(page_table, ptl);
72149 out:
72150 @@ -2947,40 +3160,6 @@ out_release:
72151 }
72152
72153 /*
72154 - * This is like a special single-page "expand_{down|up}wards()",
72155 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72156 - * doesn't hit another vma.
72157 - */
72158 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72159 -{
72160 - address &= PAGE_MASK;
72161 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72162 - struct vm_area_struct *prev = vma->vm_prev;
72163 -
72164 - /*
72165 - * Is there a mapping abutting this one below?
72166 - *
72167 - * That's only ok if it's the same stack mapping
72168 - * that has gotten split..
72169 - */
72170 - if (prev && prev->vm_end == address)
72171 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72172 -
72173 - expand_stack(vma, address - PAGE_SIZE);
72174 - }
72175 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72176 - struct vm_area_struct *next = vma->vm_next;
72177 -
72178 - /* As VM_GROWSDOWN but s/below/above/ */
72179 - if (next && next->vm_start == address + PAGE_SIZE)
72180 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72181 -
72182 - expand_upwards(vma, address + PAGE_SIZE);
72183 - }
72184 - return 0;
72185 -}
72186 -
72187 -/*
72188 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72189 * but allow concurrent faults), and pte mapped but not yet locked.
72190 * We return with mmap_sem still held, but pte unmapped and unlocked.
72191 @@ -2989,27 +3168,23 @@ static int do_anonymous_page(struct mm_s
72192 unsigned long address, pte_t *page_table, pmd_t *pmd,
72193 unsigned int flags)
72194 {
72195 - struct page *page;
72196 + struct page *page = NULL;
72197 spinlock_t *ptl;
72198 pte_t entry;
72199
72200 - pte_unmap(page_table);
72201 -
72202 - /* Check if we need to add a guard page to the stack */
72203 - if (check_stack_guard_page(vma, address) < 0)
72204 - return VM_FAULT_SIGBUS;
72205 -
72206 - /* Use the zero-page for reads */
72207 if (!(flags & FAULT_FLAG_WRITE)) {
72208 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72209 vma->vm_page_prot));
72210 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72211 + ptl = pte_lockptr(mm, pmd);
72212 + spin_lock(ptl);
72213 if (!pte_none(*page_table))
72214 goto unlock;
72215 goto setpte;
72216 }
72217
72218 /* Allocate our own private page. */
72219 + pte_unmap(page_table);
72220 +
72221 if (unlikely(anon_vma_prepare(vma)))
72222 goto oom;
72223 page = alloc_zeroed_user_highpage_movable(vma, address);
72224 @@ -3028,6 +3203,11 @@ static int do_anonymous_page(struct mm_s
72225 if (!pte_none(*page_table))
72226 goto release;
72227
72228 +#ifdef CONFIG_PAX_SEGMEXEC
72229 + if (pax_find_mirror_vma(vma))
72230 + BUG_ON(!trylock_page(page));
72231 +#endif
72232 +
72233 inc_mm_counter_fast(mm, MM_ANONPAGES);
72234 page_add_new_anon_rmap(page, vma, address);
72235 setpte:
72236 @@ -3035,6 +3215,12 @@ setpte:
72237
72238 /* No need to invalidate - it was non-present before */
72239 update_mmu_cache(vma, address, page_table);
72240 +
72241 +#ifdef CONFIG_PAX_SEGMEXEC
72242 + if (page)
72243 + pax_mirror_anon_pte(vma, address, page, ptl);
72244 +#endif
72245 +
72246 unlock:
72247 pte_unmap_unlock(page_table, ptl);
72248 return 0;
72249 @@ -3172,6 +3358,12 @@ static int __do_fault(struct mm_struct *
72250 */
72251 /* Only go through if we didn't race with anybody else... */
72252 if (likely(pte_same(*page_table, orig_pte))) {
72253 +
72254 +#ifdef CONFIG_PAX_SEGMEXEC
72255 + if (anon && pax_find_mirror_vma(vma))
72256 + BUG_ON(!trylock_page(page));
72257 +#endif
72258 +
72259 flush_icache_page(vma, page);
72260 entry = mk_pte(page, vma->vm_page_prot);
72261 if (flags & FAULT_FLAG_WRITE)
72262 @@ -3191,6 +3383,14 @@ static int __do_fault(struct mm_struct *
72263
72264 /* no need to invalidate: a not-present page won't be cached */
72265 update_mmu_cache(vma, address, page_table);
72266 +
72267 +#ifdef CONFIG_PAX_SEGMEXEC
72268 + if (anon)
72269 + pax_mirror_anon_pte(vma, address, page, ptl);
72270 + else
72271 + pax_mirror_file_pte(vma, address, page, ptl);
72272 +#endif
72273 +
72274 } else {
72275 if (charged)
72276 mem_cgroup_uncharge_page(page);
72277 @@ -3338,6 +3538,12 @@ int handle_pte_fault(struct mm_struct *m
72278 if (flags & FAULT_FLAG_WRITE)
72279 flush_tlb_fix_spurious_fault(vma, address);
72280 }
72281 +
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72284 + return 0;
72285 +#endif
72286 +
72287 unlock:
72288 pte_unmap_unlock(pte, ptl);
72289 return 0;
72290 @@ -3354,6 +3560,10 @@ int handle_mm_fault(struct mm_struct *mm
72291 pmd_t *pmd;
72292 pte_t *pte;
72293
72294 +#ifdef CONFIG_PAX_SEGMEXEC
72295 + struct vm_area_struct *vma_m;
72296 +#endif
72297 +
72298 __set_current_state(TASK_RUNNING);
72299
72300 count_vm_event(PGFAULT);
72301 @@ -3364,6 +3574,34 @@ int handle_mm_fault(struct mm_struct *mm
72302 if (unlikely(is_vm_hugetlb_page(vma)))
72303 return hugetlb_fault(mm, vma, address, flags);
72304
72305 +#ifdef CONFIG_PAX_SEGMEXEC
72306 + vma_m = pax_find_mirror_vma(vma);
72307 + if (vma_m) {
72308 + unsigned long address_m;
72309 + pgd_t *pgd_m;
72310 + pud_t *pud_m;
72311 + pmd_t *pmd_m;
72312 +
72313 + if (vma->vm_start > vma_m->vm_start) {
72314 + address_m = address;
72315 + address -= SEGMEXEC_TASK_SIZE;
72316 + vma = vma_m;
72317 + } else
72318 + address_m = address + SEGMEXEC_TASK_SIZE;
72319 +
72320 + pgd_m = pgd_offset(mm, address_m);
72321 + pud_m = pud_alloc(mm, pgd_m, address_m);
72322 + if (!pud_m)
72323 + return VM_FAULT_OOM;
72324 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72325 + if (!pmd_m)
72326 + return VM_FAULT_OOM;
72327 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72328 + return VM_FAULT_OOM;
72329 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72330 + }
72331 +#endif
72332 +
72333 pgd = pgd_offset(mm, address);
72334 pud = pud_alloc(mm, pgd, address);
72335 if (!pud)
72336 @@ -3393,7 +3631,7 @@ int handle_mm_fault(struct mm_struct *mm
72337 * run pte_offset_map on the pmd, if an huge pmd could
72338 * materialize from under us from a different thread.
72339 */
72340 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72341 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72342 return VM_FAULT_OOM;
72343 /* if an huge pmd materialized from under us just retry later */
72344 if (unlikely(pmd_trans_huge(*pmd)))
72345 @@ -3497,7 +3735,7 @@ static int __init gate_vma_init(void)
72346 gate_vma.vm_start = FIXADDR_USER_START;
72347 gate_vma.vm_end = FIXADDR_USER_END;
72348 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72349 - gate_vma.vm_page_prot = __P101;
72350 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72351 /*
72352 * Make sure the vDSO gets into every core dump.
72353 * Dumping its contents makes post-mortem fully interpretable later
72354 diff -urNp linux-2.6.39.2/mm/memory-failure.c linux-2.6.39.2/mm/memory-failure.c
72355 --- linux-2.6.39.2/mm/memory-failure.c 2011-05-19 00:06:34.000000000 -0400
72356 +++ linux-2.6.39.2/mm/memory-failure.c 2011-05-22 19:36:33.000000000 -0400
72357 @@ -58,7 +58,7 @@ int sysctl_memory_failure_early_kill __r
72358
72359 int sysctl_memory_failure_recovery __read_mostly = 1;
72360
72361 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72362 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72363
72364 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72365
72366 @@ -1012,7 +1012,7 @@ int __memory_failure(unsigned long pfn,
72367 }
72368
72369 nr_pages = 1 << compound_trans_order(hpage);
72370 - atomic_long_add(nr_pages, &mce_bad_pages);
72371 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72372
72373 /*
72374 * We need/can do nothing about count=0 pages.
72375 @@ -1042,7 +1042,7 @@ int __memory_failure(unsigned long pfn,
72376 if (!PageHWPoison(hpage)
72377 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72378 || (p != hpage && TestSetPageHWPoison(hpage))) {
72379 - atomic_long_sub(nr_pages, &mce_bad_pages);
72380 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72381 return 0;
72382 }
72383 set_page_hwpoison_huge_page(hpage);
72384 @@ -1100,7 +1100,7 @@ int __memory_failure(unsigned long pfn,
72385 }
72386 if (hwpoison_filter(p)) {
72387 if (TestClearPageHWPoison(p))
72388 - atomic_long_sub(nr_pages, &mce_bad_pages);
72389 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72390 unlock_page(hpage);
72391 put_page(hpage);
72392 return 0;
72393 @@ -1226,7 +1226,7 @@ int unpoison_memory(unsigned long pfn)
72394 return 0;
72395 }
72396 if (TestClearPageHWPoison(p))
72397 - atomic_long_sub(nr_pages, &mce_bad_pages);
72398 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72399 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72400 return 0;
72401 }
72402 @@ -1240,7 +1240,7 @@ int unpoison_memory(unsigned long pfn)
72403 */
72404 if (TestClearPageHWPoison(page)) {
72405 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72406 - atomic_long_sub(nr_pages, &mce_bad_pages);
72407 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72408 freeit = 1;
72409 if (PageHuge(page))
72410 clear_page_hwpoison_huge_page(page);
72411 @@ -1353,7 +1353,7 @@ static int soft_offline_huge_page(struct
72412 }
72413 done:
72414 if (!PageHWPoison(hpage))
72415 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
72416 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
72417 set_page_hwpoison_huge_page(hpage);
72418 dequeue_hwpoisoned_huge_page(hpage);
72419 /* keep elevated page count for bad page */
72420 @@ -1482,7 +1482,7 @@ int soft_offline_page(struct page *page,
72421 return ret;
72422
72423 done:
72424 - atomic_long_add(1, &mce_bad_pages);
72425 + atomic_long_add_unchecked(1, &mce_bad_pages);
72426 SetPageHWPoison(page);
72427 /* keep elevated page count for bad page */
72428 return ret;
72429 diff -urNp linux-2.6.39.2/mm/mempolicy.c linux-2.6.39.2/mm/mempolicy.c
72430 --- linux-2.6.39.2/mm/mempolicy.c 2011-05-19 00:06:34.000000000 -0400
72431 +++ linux-2.6.39.2/mm/mempolicy.c 2011-05-22 19:41:42.000000000 -0400
72432 @@ -643,6 +643,10 @@ static int mbind_range(struct mm_struct
72433 unsigned long vmstart;
72434 unsigned long vmend;
72435
72436 +#ifdef CONFIG_PAX_SEGMEXEC
72437 + struct vm_area_struct *vma_m;
72438 +#endif
72439 +
72440 vma = find_vma_prev(mm, start, &prev);
72441 if (!vma || vma->vm_start > start)
72442 return -EFAULT;
72443 @@ -673,6 +677,16 @@ static int mbind_range(struct mm_struct
72444 err = policy_vma(vma, new_pol);
72445 if (err)
72446 goto out;
72447 +
72448 +#ifdef CONFIG_PAX_SEGMEXEC
72449 + vma_m = pax_find_mirror_vma(vma);
72450 + if (vma_m) {
72451 + err = policy_vma(vma_m, new_pol);
72452 + if (err)
72453 + goto out;
72454 + }
72455 +#endif
72456 +
72457 }
72458
72459 out:
72460 @@ -1106,6 +1120,17 @@ static long do_mbind(unsigned long start
72461
72462 if (end < start)
72463 return -EINVAL;
72464 +
72465 +#ifdef CONFIG_PAX_SEGMEXEC
72466 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72467 + if (end > SEGMEXEC_TASK_SIZE)
72468 + return -EINVAL;
72469 + } else
72470 +#endif
72471 +
72472 + if (end > TASK_SIZE)
72473 + return -EINVAL;
72474 +
72475 if (end == start)
72476 return 0;
72477
72478 @@ -1324,6 +1349,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72479 if (!mm)
72480 goto out;
72481
72482 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72483 + if (mm != current->mm &&
72484 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72485 + err = -EPERM;
72486 + goto out;
72487 + }
72488 +#endif
72489 +
72490 /*
72491 * Check if this process has the right to modify the specified
72492 * process. The right exists if the process has administrative
72493 @@ -1333,8 +1366,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
72494 rcu_read_lock();
72495 tcred = __task_cred(task);
72496 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72497 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72498 - !capable(CAP_SYS_NICE)) {
72499 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72500 rcu_read_unlock();
72501 err = -EPERM;
72502 goto out;
72503 @@ -2634,7 +2666,7 @@ int show_numa_map(struct seq_file *m, vo
72504
72505 if (file) {
72506 seq_printf(m, " file=");
72507 - seq_path(m, &file->f_path, "\n\t= ");
72508 + seq_path(m, &file->f_path, "\n\t\\= ");
72509 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
72510 seq_printf(m, " heap");
72511 } else if (vma->vm_start <= mm->start_stack &&
72512 diff -urNp linux-2.6.39.2/mm/migrate.c linux-2.6.39.2/mm/migrate.c
72513 --- linux-2.6.39.2/mm/migrate.c 2011-05-19 00:06:34.000000000 -0400
72514 +++ linux-2.6.39.2/mm/migrate.c 2011-05-22 19:41:42.000000000 -0400
72515 @@ -1133,6 +1133,8 @@ static int do_pages_move(struct mm_struc
72516 unsigned long chunk_start;
72517 int err;
72518
72519 + pax_track_stack();
72520 +
72521 task_nodes = cpuset_mems_allowed(task);
72522
72523 err = -ENOMEM;
72524 @@ -1317,6 +1319,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72525 if (!mm)
72526 return -EINVAL;
72527
72528 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72529 + if (mm != current->mm &&
72530 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72531 + err = -EPERM;
72532 + goto out;
72533 + }
72534 +#endif
72535 +
72536 /*
72537 * Check if this process has the right to modify the specified
72538 * process. The right exists if the process has administrative
72539 @@ -1326,8 +1336,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid,
72540 rcu_read_lock();
72541 tcred = __task_cred(task);
72542 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72543 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72544 - !capable(CAP_SYS_NICE)) {
72545 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72546 rcu_read_unlock();
72547 err = -EPERM;
72548 goto out;
72549 diff -urNp linux-2.6.39.2/mm/mlock.c linux-2.6.39.2/mm/mlock.c
72550 --- linux-2.6.39.2/mm/mlock.c 2011-05-19 00:06:34.000000000 -0400
72551 +++ linux-2.6.39.2/mm/mlock.c 2011-05-22 19:41:42.000000000 -0400
72552 @@ -13,6 +13,7 @@
72553 #include <linux/pagemap.h>
72554 #include <linux/mempolicy.h>
72555 #include <linux/syscalls.h>
72556 +#include <linux/security.h>
72557 #include <linux/sched.h>
72558 #include <linux/module.h>
72559 #include <linux/rmap.h>
72560 @@ -377,6 +378,9 @@ static int do_mlock(unsigned long start,
72561 return -EINVAL;
72562 if (end == start)
72563 return 0;
72564 + if (end > TASK_SIZE)
72565 + return -EINVAL;
72566 +
72567 vma = find_vma_prev(current->mm, start, &prev);
72568 if (!vma || vma->vm_start > start)
72569 return -ENOMEM;
72570 @@ -387,6 +391,11 @@ static int do_mlock(unsigned long start,
72571 for (nstart = start ; ; ) {
72572 unsigned int newflags;
72573
72574 +#ifdef CONFIG_PAX_SEGMEXEC
72575 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72576 + break;
72577 +#endif
72578 +
72579 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72580
72581 newflags = vma->vm_flags | VM_LOCKED;
72582 @@ -492,6 +501,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
72583 lock_limit >>= PAGE_SHIFT;
72584
72585 /* check against resource limits */
72586 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72587 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72588 error = do_mlock(start, len, 1);
72589 up_write(&current->mm->mmap_sem);
72590 @@ -515,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long,
72591 static int do_mlockall(int flags)
72592 {
72593 struct vm_area_struct * vma, * prev = NULL;
72594 - unsigned int def_flags = 0;
72595
72596 if (flags & MCL_FUTURE)
72597 - def_flags = VM_LOCKED;
72598 - current->mm->def_flags = def_flags;
72599 + current->mm->def_flags |= VM_LOCKED;
72600 + else
72601 + current->mm->def_flags &= ~VM_LOCKED;
72602 if (flags == MCL_FUTURE)
72603 goto out;
72604
72605 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72606 - unsigned int newflags;
72607 + unsigned long newflags;
72608 +
72609 +#ifdef CONFIG_PAX_SEGMEXEC
72610 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72611 + break;
72612 +#endif
72613
72614 + BUG_ON(vma->vm_end > TASK_SIZE);
72615 newflags = vma->vm_flags | VM_LOCKED;
72616 if (!(flags & MCL_CURRENT))
72617 newflags &= ~VM_LOCKED;
72618 @@ -557,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72619 lock_limit >>= PAGE_SHIFT;
72620
72621 ret = -ENOMEM;
72622 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72623 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72624 capable(CAP_IPC_LOCK))
72625 ret = do_mlockall(flags);
72626 diff -urNp linux-2.6.39.2/mm/mmap.c linux-2.6.39.2/mm/mmap.c
72627 --- linux-2.6.39.2/mm/mmap.c 2011-05-19 00:06:34.000000000 -0400
72628 +++ linux-2.6.39.2/mm/mmap.c 2011-05-22 19:41:42.000000000 -0400
72629 @@ -46,6 +46,16 @@
72630 #define arch_rebalance_pgtables(addr, len) (addr)
72631 #endif
72632
72633 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72634 +{
72635 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72636 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72637 + up_read(&mm->mmap_sem);
72638 + BUG();
72639 + }
72640 +#endif
72641 +}
72642 +
72643 static void unmap_region(struct mm_struct *mm,
72644 struct vm_area_struct *vma, struct vm_area_struct *prev,
72645 unsigned long start, unsigned long end);
72646 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struc
72647 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72648 *
72649 */
72650 -pgprot_t protection_map[16] = {
72651 +pgprot_t protection_map[16] __read_only = {
72652 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72653 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72654 };
72655
72656 pgprot_t vm_get_page_prot(unsigned long vm_flags)
72657 {
72658 - return __pgprot(pgprot_val(protection_map[vm_flags &
72659 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72660 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72661 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72662 +
72663 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72664 + if (!(__supported_pte_mask & _PAGE_NX) &&
72665 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72666 + (vm_flags & (VM_READ | VM_WRITE)))
72667 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72668 +#endif
72669 +
72670 + return prot;
72671 }
72672 EXPORT_SYMBOL(vm_get_page_prot);
72673
72674 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72675 int sysctl_overcommit_ratio = 50; /* default is 50% */
72676 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72677 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72678 struct percpu_counter vm_committed_as;
72679
72680 /*
72681 @@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
72682 struct vm_area_struct *next = vma->vm_next;
72683
72684 might_sleep();
72685 + BUG_ON(vma->vm_mirror);
72686 if (vma->vm_ops && vma->vm_ops->close)
72687 vma->vm_ops->close(vma);
72688 if (vma->vm_file) {
72689 @@ -276,6 +297,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72690 * not page aligned -Ram Gupta
72691 */
72692 rlim = rlimit(RLIMIT_DATA);
72693 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72694 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72695 (mm->end_data - mm->start_data) > rlim)
72696 goto out;
72697 @@ -719,6 +741,12 @@ static int
72698 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72699 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72700 {
72701 +
72702 +#ifdef CONFIG_PAX_SEGMEXEC
72703 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72704 + return 0;
72705 +#endif
72706 +
72707 if (is_mergeable_vma(vma, file, vm_flags) &&
72708 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72709 if (vma->vm_pgoff == vm_pgoff)
72710 @@ -738,6 +766,12 @@ static int
72711 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72712 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72713 {
72714 +
72715 +#ifdef CONFIG_PAX_SEGMEXEC
72716 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72717 + return 0;
72718 +#endif
72719 +
72720 if (is_mergeable_vma(vma, file, vm_flags) &&
72721 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
72722 pgoff_t vm_pglen;
72723 @@ -780,13 +814,20 @@ can_vma_merge_after(struct vm_area_struc
72724 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72725 struct vm_area_struct *prev, unsigned long addr,
72726 unsigned long end, unsigned long vm_flags,
72727 - struct anon_vma *anon_vma, struct file *file,
72728 + struct anon_vma *anon_vma, struct file *file,
72729 pgoff_t pgoff, struct mempolicy *policy)
72730 {
72731 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72732 struct vm_area_struct *area, *next;
72733 int err;
72734
72735 +#ifdef CONFIG_PAX_SEGMEXEC
72736 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72737 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72738 +
72739 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72740 +#endif
72741 +
72742 /*
72743 * We later require that vma->vm_flags == vm_flags,
72744 * so this tests vma->vm_flags & VM_SPECIAL, too.
72745 @@ -802,6 +843,15 @@ struct vm_area_struct *vma_merge(struct
72746 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72747 next = next->vm_next;
72748
72749 +#ifdef CONFIG_PAX_SEGMEXEC
72750 + if (prev)
72751 + prev_m = pax_find_mirror_vma(prev);
72752 + if (area)
72753 + area_m = pax_find_mirror_vma(area);
72754 + if (next)
72755 + next_m = pax_find_mirror_vma(next);
72756 +#endif
72757 +
72758 /*
72759 * Can it merge with the predecessor?
72760 */
72761 @@ -821,9 +871,24 @@ struct vm_area_struct *vma_merge(struct
72762 /* cases 1, 6 */
72763 err = vma_adjust(prev, prev->vm_start,
72764 next->vm_end, prev->vm_pgoff, NULL);
72765 - } else /* cases 2, 5, 7 */
72766 +
72767 +#ifdef CONFIG_PAX_SEGMEXEC
72768 + if (!err && prev_m)
72769 + err = vma_adjust(prev_m, prev_m->vm_start,
72770 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72771 +#endif
72772 +
72773 + } else { /* cases 2, 5, 7 */
72774 err = vma_adjust(prev, prev->vm_start,
72775 end, prev->vm_pgoff, NULL);
72776 +
72777 +#ifdef CONFIG_PAX_SEGMEXEC
72778 + if (!err && prev_m)
72779 + err = vma_adjust(prev_m, prev_m->vm_start,
72780 + end_m, prev_m->vm_pgoff, NULL);
72781 +#endif
72782 +
72783 + }
72784 if (err)
72785 return NULL;
72786 khugepaged_enter_vma_merge(prev);
72787 @@ -837,12 +902,27 @@ struct vm_area_struct *vma_merge(struct
72788 mpol_equal(policy, vma_policy(next)) &&
72789 can_vma_merge_before(next, vm_flags,
72790 anon_vma, file, pgoff+pglen)) {
72791 - if (prev && addr < prev->vm_end) /* case 4 */
72792 + if (prev && addr < prev->vm_end) { /* case 4 */
72793 err = vma_adjust(prev, prev->vm_start,
72794 addr, prev->vm_pgoff, NULL);
72795 - else /* cases 3, 8 */
72796 +
72797 +#ifdef CONFIG_PAX_SEGMEXEC
72798 + if (!err && prev_m)
72799 + err = vma_adjust(prev_m, prev_m->vm_start,
72800 + addr_m, prev_m->vm_pgoff, NULL);
72801 +#endif
72802 +
72803 + } else { /* cases 3, 8 */
72804 err = vma_adjust(area, addr, next->vm_end,
72805 next->vm_pgoff - pglen, NULL);
72806 +
72807 +#ifdef CONFIG_PAX_SEGMEXEC
72808 + if (!err && area_m)
72809 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72810 + next_m->vm_pgoff - pglen, NULL);
72811 +#endif
72812 +
72813 + }
72814 if (err)
72815 return NULL;
72816 khugepaged_enter_vma_merge(area);
72817 @@ -958,14 +1038,11 @@ none:
72818 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72819 struct file *file, long pages)
72820 {
72821 - const unsigned long stack_flags
72822 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72823 -
72824 if (file) {
72825 mm->shared_vm += pages;
72826 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72827 mm->exec_vm += pages;
72828 - } else if (flags & stack_flags)
72829 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72830 mm->stack_vm += pages;
72831 if (flags & (VM_RESERVED|VM_IO))
72832 mm->reserved_vm += pages;
72833 @@ -992,7 +1069,7 @@ unsigned long do_mmap_pgoff(struct file
72834 * (the exception is when the underlying filesystem is noexec
72835 * mounted, in which case we dont add PROT_EXEC.)
72836 */
72837 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72838 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72839 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72840 prot |= PROT_EXEC;
72841
72842 @@ -1018,7 +1095,7 @@ unsigned long do_mmap_pgoff(struct file
72843 /* Obtain the address to map to. we verify (or select) it and ensure
72844 * that it represents a valid section of the address space.
72845 */
72846 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72847 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72848 if (addr & ~PAGE_MASK)
72849 return addr;
72850
72851 @@ -1029,6 +1106,36 @@ unsigned long do_mmap_pgoff(struct file
72852 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72853 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72854
72855 +#ifdef CONFIG_PAX_MPROTECT
72856 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72857 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72858 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72859 + gr_log_rwxmmap(file);
72860 +
72861 +#ifdef CONFIG_PAX_EMUPLT
72862 + vm_flags &= ~VM_EXEC;
72863 +#else
72864 + return -EPERM;
72865 +#endif
72866 +
72867 + }
72868 +
72869 + if (!(vm_flags & VM_EXEC))
72870 + vm_flags &= ~VM_MAYEXEC;
72871 +#else
72872 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72873 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72874 +#endif
72875 + else
72876 + vm_flags &= ~VM_MAYWRITE;
72877 + }
72878 +#endif
72879 +
72880 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72881 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72882 + vm_flags &= ~VM_PAGEEXEC;
72883 +#endif
72884 +
72885 if (flags & MAP_LOCKED)
72886 if (!can_do_mlock())
72887 return -EPERM;
72888 @@ -1040,6 +1147,7 @@ unsigned long do_mmap_pgoff(struct file
72889 locked += mm->locked_vm;
72890 lock_limit = rlimit(RLIMIT_MEMLOCK);
72891 lock_limit >>= PAGE_SHIFT;
72892 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72893 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72894 return -EAGAIN;
72895 }
72896 @@ -1110,6 +1218,9 @@ unsigned long do_mmap_pgoff(struct file
72897 if (error)
72898 return error;
72899
72900 + if (!gr_acl_handle_mmap(file, prot))
72901 + return -EACCES;
72902 +
72903 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72904 }
72905 EXPORT_SYMBOL(do_mmap_pgoff);
72906 @@ -1187,10 +1298,10 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_ar
72907 */
72908 int vma_wants_writenotify(struct vm_area_struct *vma)
72909 {
72910 - unsigned int vm_flags = vma->vm_flags;
72911 + unsigned long vm_flags = vma->vm_flags;
72912
72913 /* If it was private or non-writable, the write bit is already clear */
72914 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72915 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72916 return 0;
72917
72918 /* The backer wishes to know when pages are first written to? */
72919 @@ -1239,14 +1350,24 @@ unsigned long mmap_region(struct file *f
72920 unsigned long charged = 0;
72921 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72922
72923 +#ifdef CONFIG_PAX_SEGMEXEC
72924 + struct vm_area_struct *vma_m = NULL;
72925 +#endif
72926 +
72927 + /*
72928 + * mm->mmap_sem is required to protect against another thread
72929 + * changing the mappings in case we sleep.
72930 + */
72931 + verify_mm_writelocked(mm);
72932 +
72933 /* Clear old maps */
72934 error = -ENOMEM;
72935 -munmap_back:
72936 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72937 if (vma && vma->vm_start < addr + len) {
72938 if (do_munmap(mm, addr, len))
72939 return -ENOMEM;
72940 - goto munmap_back;
72941 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72942 + BUG_ON(vma && vma->vm_start < addr + len);
72943 }
72944
72945 /* Check against address space limit. */
72946 @@ -1295,6 +1416,16 @@ munmap_back:
72947 goto unacct_error;
72948 }
72949
72950 +#ifdef CONFIG_PAX_SEGMEXEC
72951 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72952 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72953 + if (!vma_m) {
72954 + error = -ENOMEM;
72955 + goto free_vma;
72956 + }
72957 + }
72958 +#endif
72959 +
72960 vma->vm_mm = mm;
72961 vma->vm_start = addr;
72962 vma->vm_end = addr + len;
72963 @@ -1318,6 +1449,19 @@ munmap_back:
72964 error = file->f_op->mmap(file, vma);
72965 if (error)
72966 goto unmap_and_free_vma;
72967 +
72968 +#ifdef CONFIG_PAX_SEGMEXEC
72969 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72970 + added_exe_file_vma(mm);
72971 +#endif
72972 +
72973 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72974 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72975 + vma->vm_flags |= VM_PAGEEXEC;
72976 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72977 + }
72978 +#endif
72979 +
72980 if (vm_flags & VM_EXECUTABLE)
72981 added_exe_file_vma(mm);
72982
72983 @@ -1353,6 +1497,11 @@ munmap_back:
72984 vma_link(mm, vma, prev, rb_link, rb_parent);
72985 file = vma->vm_file;
72986
72987 +#ifdef CONFIG_PAX_SEGMEXEC
72988 + if (vma_m)
72989 + BUG_ON(pax_mirror_vma(vma_m, vma));
72990 +#endif
72991 +
72992 /* Once vma denies write, undo our temporary denial count */
72993 if (correct_wcount)
72994 atomic_inc(&inode->i_writecount);
72995 @@ -1361,6 +1510,7 @@ out:
72996
72997 mm->total_vm += len >> PAGE_SHIFT;
72998 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72999 + track_exec_limit(mm, addr, addr + len, vm_flags);
73000 if (vm_flags & VM_LOCKED) {
73001 if (!mlock_vma_pages_range(vma, addr, addr + len))
73002 mm->locked_vm += (len >> PAGE_SHIFT);
73003 @@ -1378,6 +1528,12 @@ unmap_and_free_vma:
73004 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73005 charged = 0;
73006 free_vma:
73007 +
73008 +#ifdef CONFIG_PAX_SEGMEXEC
73009 + if (vma_m)
73010 + kmem_cache_free(vm_area_cachep, vma_m);
73011 +#endif
73012 +
73013 kmem_cache_free(vm_area_cachep, vma);
73014 unacct_error:
73015 if (charged)
73016 @@ -1385,6 +1541,44 @@ unacct_error:
73017 return error;
73018 }
73019
73020 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73021 +{
73022 + if (!vma) {
73023 +#ifdef CONFIG_STACK_GROWSUP
73024 + if (addr > sysctl_heap_stack_gap)
73025 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73026 + else
73027 + vma = find_vma(current->mm, 0);
73028 + if (vma && (vma->vm_flags & VM_GROWSUP))
73029 + return false;
73030 +#endif
73031 + return true;
73032 + }
73033 +
73034 + if (addr + len > vma->vm_start)
73035 + return false;
73036 +
73037 + if (vma->vm_flags & VM_GROWSDOWN)
73038 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73039 +#ifdef CONFIG_STACK_GROWSUP
73040 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73041 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73042 +#endif
73043 +
73044 + return true;
73045 +}
73046 +
73047 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73048 +{
73049 + if (vma->vm_start < len)
73050 + return -ENOMEM;
73051 + if (!(vma->vm_flags & VM_GROWSDOWN))
73052 + return vma->vm_start - len;
73053 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73054 + return vma->vm_start - len - sysctl_heap_stack_gap;
73055 + return -ENOMEM;
73056 +}
73057 +
73058 /* Get an address range which is currently unmapped.
73059 * For shmat() with addr=0.
73060 *
73061 @@ -1411,18 +1605,23 @@ arch_get_unmapped_area(struct file *filp
73062 if (flags & MAP_FIXED)
73063 return addr;
73064
73065 +#ifdef CONFIG_PAX_RANDMMAP
73066 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73067 +#endif
73068 +
73069 if (addr) {
73070 addr = PAGE_ALIGN(addr);
73071 - vma = find_vma(mm, addr);
73072 - if (TASK_SIZE - len >= addr &&
73073 - (!vma || addr + len <= vma->vm_start))
73074 - return addr;
73075 + if (TASK_SIZE - len >= addr) {
73076 + vma = find_vma(mm, addr);
73077 + if (check_heap_stack_gap(vma, addr, len))
73078 + return addr;
73079 + }
73080 }
73081 if (len > mm->cached_hole_size) {
73082 - start_addr = addr = mm->free_area_cache;
73083 + start_addr = addr = mm->free_area_cache;
73084 } else {
73085 - start_addr = addr = TASK_UNMAPPED_BASE;
73086 - mm->cached_hole_size = 0;
73087 + start_addr = addr = mm->mmap_base;
73088 + mm->cached_hole_size = 0;
73089 }
73090
73091 full_search:
73092 @@ -1433,34 +1632,40 @@ full_search:
73093 * Start a new search - just in case we missed
73094 * some holes.
73095 */
73096 - if (start_addr != TASK_UNMAPPED_BASE) {
73097 - addr = TASK_UNMAPPED_BASE;
73098 - start_addr = addr;
73099 + if (start_addr != mm->mmap_base) {
73100 + start_addr = addr = mm->mmap_base;
73101 mm->cached_hole_size = 0;
73102 goto full_search;
73103 }
73104 return -ENOMEM;
73105 }
73106 - if (!vma || addr + len <= vma->vm_start) {
73107 - /*
73108 - * Remember the place where we stopped the search:
73109 - */
73110 - mm->free_area_cache = addr + len;
73111 - return addr;
73112 - }
73113 + if (check_heap_stack_gap(vma, addr, len))
73114 + break;
73115 if (addr + mm->cached_hole_size < vma->vm_start)
73116 mm->cached_hole_size = vma->vm_start - addr;
73117 addr = vma->vm_end;
73118 }
73119 +
73120 + /*
73121 + * Remember the place where we stopped the search:
73122 + */
73123 + mm->free_area_cache = addr + len;
73124 + return addr;
73125 }
73126 #endif
73127
73128 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73129 {
73130 +
73131 +#ifdef CONFIG_PAX_SEGMEXEC
73132 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73133 + return;
73134 +#endif
73135 +
73136 /*
73137 * Is this a new hole at the lowest possible address?
73138 */
73139 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
73140 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
73141 mm->free_area_cache = addr;
73142 mm->cached_hole_size = ~0UL;
73143 }
73144 @@ -1478,7 +1683,7 @@ arch_get_unmapped_area_topdown(struct fi
73145 {
73146 struct vm_area_struct *vma;
73147 struct mm_struct *mm = current->mm;
73148 - unsigned long addr = addr0;
73149 + unsigned long base = mm->mmap_base, addr = addr0;
73150
73151 /* requested length too big for entire address space */
73152 if (len > TASK_SIZE)
73153 @@ -1487,13 +1692,18 @@ arch_get_unmapped_area_topdown(struct fi
73154 if (flags & MAP_FIXED)
73155 return addr;
73156
73157 +#ifdef CONFIG_PAX_RANDMMAP
73158 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73159 +#endif
73160 +
73161 /* requesting a specific address */
73162 if (addr) {
73163 addr = PAGE_ALIGN(addr);
73164 - vma = find_vma(mm, addr);
73165 - if (TASK_SIZE - len >= addr &&
73166 - (!vma || addr + len <= vma->vm_start))
73167 - return addr;
73168 + if (TASK_SIZE - len >= addr) {
73169 + vma = find_vma(mm, addr);
73170 + if (check_heap_stack_gap(vma, addr, len))
73171 + return addr;
73172 + }
73173 }
73174
73175 /* check if free_area_cache is useful for us */
73176 @@ -1508,7 +1718,7 @@ arch_get_unmapped_area_topdown(struct fi
73177 /* make sure it can fit in the remaining address space */
73178 if (addr > len) {
73179 vma = find_vma(mm, addr-len);
73180 - if (!vma || addr <= vma->vm_start)
73181 + if (check_heap_stack_gap(vma, addr - len, len))
73182 /* remember the address as a hint for next time */
73183 return (mm->free_area_cache = addr-len);
73184 }
73185 @@ -1525,7 +1735,7 @@ arch_get_unmapped_area_topdown(struct fi
73186 * return with success:
73187 */
73188 vma = find_vma(mm, addr);
73189 - if (!vma || addr+len <= vma->vm_start)
73190 + if (check_heap_stack_gap(vma, addr, len))
73191 /* remember the address as a hint for next time */
73192 return (mm->free_area_cache = addr);
73193
73194 @@ -1534,8 +1744,8 @@ arch_get_unmapped_area_topdown(struct fi
73195 mm->cached_hole_size = vma->vm_start - addr;
73196
73197 /* try just below the current vma->vm_start */
73198 - addr = vma->vm_start-len;
73199 - } while (len < vma->vm_start);
73200 + addr = skip_heap_stack_gap(vma, len);
73201 + } while (!IS_ERR_VALUE(addr));
73202
73203 bottomup:
73204 /*
73205 @@ -1544,13 +1754,21 @@ bottomup:
73206 * can happen with large stack limits and large mmap()
73207 * allocations.
73208 */
73209 + mm->mmap_base = TASK_UNMAPPED_BASE;
73210 +
73211 +#ifdef CONFIG_PAX_RANDMMAP
73212 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73213 + mm->mmap_base += mm->delta_mmap;
73214 +#endif
73215 +
73216 + mm->free_area_cache = mm->mmap_base;
73217 mm->cached_hole_size = ~0UL;
73218 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73219 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73220 /*
73221 * Restore the topdown base:
73222 */
73223 - mm->free_area_cache = mm->mmap_base;
73224 + mm->mmap_base = base;
73225 + mm->free_area_cache = base;
73226 mm->cached_hole_size = ~0UL;
73227
73228 return addr;
73229 @@ -1559,6 +1777,12 @@ bottomup:
73230
73231 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73232 {
73233 +
73234 +#ifdef CONFIG_PAX_SEGMEXEC
73235 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73236 + return;
73237 +#endif
73238 +
73239 /*
73240 * Is this a new hole at the highest possible address?
73241 */
73242 @@ -1566,8 +1790,10 @@ void arch_unmap_area_topdown(struct mm_s
73243 mm->free_area_cache = addr;
73244
73245 /* dont allow allocations above current base */
73246 - if (mm->free_area_cache > mm->mmap_base)
73247 + if (mm->free_area_cache > mm->mmap_base) {
73248 mm->free_area_cache = mm->mmap_base;
73249 + mm->cached_hole_size = ~0UL;
73250 + }
73251 }
73252
73253 unsigned long
73254 @@ -1675,6 +1901,28 @@ out:
73255 return prev ? prev->vm_next : vma;
73256 }
73257
73258 +#ifdef CONFIG_PAX_SEGMEXEC
73259 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73260 +{
73261 + struct vm_area_struct *vma_m;
73262 +
73263 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73264 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73265 + BUG_ON(vma->vm_mirror);
73266 + return NULL;
73267 + }
73268 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73269 + vma_m = vma->vm_mirror;
73270 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73271 + BUG_ON(vma->vm_file != vma_m->vm_file);
73272 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73273 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73274 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73275 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73276 + return vma_m;
73277 +}
73278 +#endif
73279 +
73280 /*
73281 * Verify that the stack growth is acceptable and
73282 * update accounting. This is shared with both the
73283 @@ -1691,6 +1939,7 @@ static int acct_stack_growth(struct vm_a
73284 return -ENOMEM;
73285
73286 /* Stack limit test */
73287 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73288 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73289 return -ENOMEM;
73290
73291 @@ -1701,6 +1950,7 @@ static int acct_stack_growth(struct vm_a
73292 locked = mm->locked_vm + grow;
73293 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73294 limit >>= PAGE_SHIFT;
73295 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73296 if (locked > limit && !capable(CAP_IPC_LOCK))
73297 return -ENOMEM;
73298 }
73299 @@ -1731,37 +1981,48 @@ static int acct_stack_growth(struct vm_a
73300 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73301 * vma is the last one with address > vma->vm_end. Have to extend vma.
73302 */
73303 +#ifndef CONFIG_IA64
73304 +static
73305 +#endif
73306 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73307 {
73308 int error;
73309 + bool locknext;
73310
73311 if (!(vma->vm_flags & VM_GROWSUP))
73312 return -EFAULT;
73313
73314 + /* Also guard against wrapping around to address 0. */
73315 + if (address < PAGE_ALIGN(address+1))
73316 + address = PAGE_ALIGN(address+1);
73317 + else
73318 + return -ENOMEM;
73319 +
73320 /*
73321 * We must make sure the anon_vma is allocated
73322 * so that the anon_vma locking is not a noop.
73323 */
73324 if (unlikely(anon_vma_prepare(vma)))
73325 return -ENOMEM;
73326 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73327 + if (locknext && anon_vma_prepare(vma->vm_next))
73328 + return -ENOMEM;
73329 vma_lock_anon_vma(vma);
73330 + if (locknext)
73331 + vma_lock_anon_vma(vma->vm_next);
73332
73333 /*
73334 * vma->vm_start/vm_end cannot change under us because the caller
73335 * is required to hold the mmap_sem in read mode. We need the
73336 - * anon_vma lock to serialize against concurrent expand_stacks.
73337 - * Also guard against wrapping around to address 0.
73338 + * anon_vma locks to serialize against concurrent expand_stacks
73339 + * and expand_upwards.
73340 */
73341 - if (address < PAGE_ALIGN(address+4))
73342 - address = PAGE_ALIGN(address+4);
73343 - else {
73344 - vma_unlock_anon_vma(vma);
73345 - return -ENOMEM;
73346 - }
73347 error = 0;
73348
73349 /* Somebody else might have raced and expanded it already */
73350 - if (address > vma->vm_end) {
73351 + if (vma->vm_next && (vma->vm_next->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && vma->vm_next->vm_start - address < sysctl_heap_stack_gap)
73352 + error = -ENOMEM;
73353 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73354 unsigned long size, grow;
73355
73356 size = address - vma->vm_start;
73357 @@ -1776,6 +2037,8 @@ int expand_upwards(struct vm_area_struct
73358 }
73359 }
73360 }
73361 + if (locknext)
73362 + vma_unlock_anon_vma(vma->vm_next);
73363 vma_unlock_anon_vma(vma);
73364 khugepaged_enter_vma_merge(vma);
73365 return error;
73366 @@ -1789,6 +2052,8 @@ static int expand_downwards(struct vm_ar
73367 unsigned long address)
73368 {
73369 int error;
73370 + bool lockprev = false;
73371 + struct vm_area_struct *prev;
73372
73373 /*
73374 * We must make sure the anon_vma is allocated
73375 @@ -1802,6 +2067,15 @@ static int expand_downwards(struct vm_ar
73376 if (error)
73377 return error;
73378
73379 + prev = vma->vm_prev;
73380 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73381 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73382 +#endif
73383 + if (lockprev && anon_vma_prepare(prev))
73384 + return -ENOMEM;
73385 + if (lockprev)
73386 + vma_lock_anon_vma(prev);
73387 +
73388 vma_lock_anon_vma(vma);
73389
73390 /*
73391 @@ -1811,9 +2085,17 @@ static int expand_downwards(struct vm_ar
73392 */
73393
73394 /* Somebody else might have raced and expanded it already */
73395 - if (address < vma->vm_start) {
73396 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73397 + error = -ENOMEM;
73398 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73399 unsigned long size, grow;
73400
73401 +#ifdef CONFIG_PAX_SEGMEXEC
73402 + struct vm_area_struct *vma_m;
73403 +
73404 + vma_m = pax_find_mirror_vma(vma);
73405 +#endif
73406 +
73407 size = vma->vm_end - address;
73408 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73409
73410 @@ -1823,11 +2105,22 @@ static int expand_downwards(struct vm_ar
73411 if (!error) {
73412 vma->vm_start = address;
73413 vma->vm_pgoff -= grow;
73414 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73415 +
73416 +#ifdef CONFIG_PAX_SEGMEXEC
73417 + if (vma_m) {
73418 + vma_m->vm_start -= grow << PAGE_SHIFT;
73419 + vma_m->vm_pgoff -= grow;
73420 + }
73421 +#endif
73422 +
73423 perf_event_mmap(vma);
73424 }
73425 }
73426 }
73427 vma_unlock_anon_vma(vma);
73428 + if (lockprev)
73429 + vma_unlock_anon_vma(prev);
73430 khugepaged_enter_vma_merge(vma);
73431 return error;
73432 }
73433 @@ -1902,6 +2195,13 @@ static void remove_vma_list(struct mm_st
73434 do {
73435 long nrpages = vma_pages(vma);
73436
73437 +#ifdef CONFIG_PAX_SEGMEXEC
73438 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73439 + vma = remove_vma(vma);
73440 + continue;
73441 + }
73442 +#endif
73443 +
73444 mm->total_vm -= nrpages;
73445 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73446 vma = remove_vma(vma);
73447 @@ -1947,6 +2247,16 @@ detach_vmas_to_be_unmapped(struct mm_str
73448 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73449 vma->vm_prev = NULL;
73450 do {
73451 +
73452 +#ifdef CONFIG_PAX_SEGMEXEC
73453 + if (vma->vm_mirror) {
73454 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73455 + vma->vm_mirror->vm_mirror = NULL;
73456 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73457 + vma->vm_mirror = NULL;
73458 + }
73459 +#endif
73460 +
73461 rb_erase(&vma->vm_rb, &mm->mm_rb);
73462 mm->map_count--;
73463 tail_vma = vma;
73464 @@ -1975,14 +2285,33 @@ static int __split_vma(struct mm_struct
73465 struct vm_area_struct *new;
73466 int err = -ENOMEM;
73467
73468 +#ifdef CONFIG_PAX_SEGMEXEC
73469 + struct vm_area_struct *vma_m, *new_m = NULL;
73470 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73471 +#endif
73472 +
73473 if (is_vm_hugetlb_page(vma) && (addr &
73474 ~(huge_page_mask(hstate_vma(vma)))))
73475 return -EINVAL;
73476
73477 +#ifdef CONFIG_PAX_SEGMEXEC
73478 + vma_m = pax_find_mirror_vma(vma);
73479 +#endif
73480 +
73481 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73482 if (!new)
73483 goto out_err;
73484
73485 +#ifdef CONFIG_PAX_SEGMEXEC
73486 + if (vma_m) {
73487 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73488 + if (!new_m) {
73489 + kmem_cache_free(vm_area_cachep, new);
73490 + goto out_err;
73491 + }
73492 + }
73493 +#endif
73494 +
73495 /* most fields are the same, copy all, and then fixup */
73496 *new = *vma;
73497
73498 @@ -1995,6 +2324,22 @@ static int __split_vma(struct mm_struct
73499 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73500 }
73501
73502 +#ifdef CONFIG_PAX_SEGMEXEC
73503 + if (vma_m) {
73504 + *new_m = *vma_m;
73505 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73506 + new_m->vm_mirror = new;
73507 + new->vm_mirror = new_m;
73508 +
73509 + if (new_below)
73510 + new_m->vm_end = addr_m;
73511 + else {
73512 + new_m->vm_start = addr_m;
73513 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73514 + }
73515 + }
73516 +#endif
73517 +
73518 pol = mpol_dup(vma_policy(vma));
73519 if (IS_ERR(pol)) {
73520 err = PTR_ERR(pol);
73521 @@ -2020,6 +2365,42 @@ static int __split_vma(struct mm_struct
73522 else
73523 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73524
73525 +#ifdef CONFIG_PAX_SEGMEXEC
73526 + if (!err && vma_m) {
73527 + if (anon_vma_clone(new_m, vma_m))
73528 + goto out_free_mpol;
73529 +
73530 + mpol_get(pol);
73531 + vma_set_policy(new_m, pol);
73532 +
73533 + if (new_m->vm_file) {
73534 + get_file(new_m->vm_file);
73535 + if (vma_m->vm_flags & VM_EXECUTABLE)
73536 + added_exe_file_vma(mm);
73537 + }
73538 +
73539 + if (new_m->vm_ops && new_m->vm_ops->open)
73540 + new_m->vm_ops->open(new_m);
73541 +
73542 + if (new_below)
73543 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73544 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73545 + else
73546 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73547 +
73548 + if (err) {
73549 + if (new_m->vm_ops && new_m->vm_ops->close)
73550 + new_m->vm_ops->close(new_m);
73551 + if (new_m->vm_file) {
73552 + if (vma_m->vm_flags & VM_EXECUTABLE)
73553 + removed_exe_file_vma(mm);
73554 + fput(new_m->vm_file);
73555 + }
73556 + mpol_put(pol);
73557 + }
73558 + }
73559 +#endif
73560 +
73561 /* Success. */
73562 if (!err)
73563 return 0;
73564 @@ -2032,10 +2413,18 @@ static int __split_vma(struct mm_struct
73565 removed_exe_file_vma(mm);
73566 fput(new->vm_file);
73567 }
73568 - unlink_anon_vmas(new);
73569 out_free_mpol:
73570 mpol_put(pol);
73571 out_free_vma:
73572 +
73573 +#ifdef CONFIG_PAX_SEGMEXEC
73574 + if (new_m) {
73575 + unlink_anon_vmas(new_m);
73576 + kmem_cache_free(vm_area_cachep, new_m);
73577 + }
73578 +#endif
73579 +
73580 + unlink_anon_vmas(new);
73581 kmem_cache_free(vm_area_cachep, new);
73582 out_err:
73583 return err;
73584 @@ -2048,6 +2437,15 @@ static int __split_vma(struct mm_struct
73585 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73586 unsigned long addr, int new_below)
73587 {
73588 +
73589 +#ifdef CONFIG_PAX_SEGMEXEC
73590 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73591 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73592 + if (mm->map_count >= sysctl_max_map_count-1)
73593 + return -ENOMEM;
73594 + } else
73595 +#endif
73596 +
73597 if (mm->map_count >= sysctl_max_map_count)
73598 return -ENOMEM;
73599
73600 @@ -2059,11 +2457,30 @@ int split_vma(struct mm_struct *mm, stru
73601 * work. This now handles partial unmappings.
73602 * Jeremy Fitzhardinge <jeremy@goop.org>
73603 */
73604 +#ifdef CONFIG_PAX_SEGMEXEC
73605 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73606 +{
73607 + int ret = __do_munmap(mm, start, len);
73608 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73609 + return ret;
73610 +
73611 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73612 +}
73613 +
73614 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73615 +#else
73616 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73617 +#endif
73618 {
73619 unsigned long end;
73620 struct vm_area_struct *vma, *prev, *last;
73621
73622 + /*
73623 + * mm->mmap_sem is required to protect against another thread
73624 + * changing the mappings in case we sleep.
73625 + */
73626 + verify_mm_writelocked(mm);
73627 +
73628 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73629 return -EINVAL;
73630
73631 @@ -2137,6 +2554,8 @@ int do_munmap(struct mm_struct *mm, unsi
73632 /* Fix up all other VM information */
73633 remove_vma_list(mm, vma);
73634
73635 + track_exec_limit(mm, start, end, 0UL);
73636 +
73637 return 0;
73638 }
73639
73640 @@ -2149,22 +2568,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, a
73641
73642 profile_munmap(addr);
73643
73644 +#ifdef CONFIG_PAX_SEGMEXEC
73645 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73646 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73647 + return -EINVAL;
73648 +#endif
73649 +
73650 down_write(&mm->mmap_sem);
73651 ret = do_munmap(mm, addr, len);
73652 up_write(&mm->mmap_sem);
73653 return ret;
73654 }
73655
73656 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73657 -{
73658 -#ifdef CONFIG_DEBUG_VM
73659 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73660 - WARN_ON(1);
73661 - up_read(&mm->mmap_sem);
73662 - }
73663 -#endif
73664 -}
73665 -
73666 /*
73667 * this is really a simplified "do_mmap". it only handles
73668 * anonymous maps. eventually we may be able to do some
73669 @@ -2178,6 +2593,7 @@ unsigned long do_brk(unsigned long addr,
73670 struct rb_node ** rb_link, * rb_parent;
73671 pgoff_t pgoff = addr >> PAGE_SHIFT;
73672 int error;
73673 + unsigned long charged;
73674
73675 len = PAGE_ALIGN(len);
73676 if (!len)
73677 @@ -2189,16 +2605,30 @@ unsigned long do_brk(unsigned long addr,
73678
73679 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73680
73681 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73682 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73683 + flags &= ~VM_EXEC;
73684 +
73685 +#ifdef CONFIG_PAX_MPROTECT
73686 + if (mm->pax_flags & MF_PAX_MPROTECT)
73687 + flags &= ~VM_MAYEXEC;
73688 +#endif
73689 +
73690 + }
73691 +#endif
73692 +
73693 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73694 if (error & ~PAGE_MASK)
73695 return error;
73696
73697 + charged = len >> PAGE_SHIFT;
73698 +
73699 /*
73700 * mlock MCL_FUTURE?
73701 */
73702 if (mm->def_flags & VM_LOCKED) {
73703 unsigned long locked, lock_limit;
73704 - locked = len >> PAGE_SHIFT;
73705 + locked = charged;
73706 locked += mm->locked_vm;
73707 lock_limit = rlimit(RLIMIT_MEMLOCK);
73708 lock_limit >>= PAGE_SHIFT;
73709 @@ -2215,22 +2645,22 @@ unsigned long do_brk(unsigned long addr,
73710 /*
73711 * Clear old maps. this also does some error checking for us
73712 */
73713 - munmap_back:
73714 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73715 if (vma && vma->vm_start < addr + len) {
73716 if (do_munmap(mm, addr, len))
73717 return -ENOMEM;
73718 - goto munmap_back;
73719 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73720 + BUG_ON(vma && vma->vm_start < addr + len);
73721 }
73722
73723 /* Check against address space limits *after* clearing old maps... */
73724 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73725 + if (!may_expand_vm(mm, charged))
73726 return -ENOMEM;
73727
73728 if (mm->map_count > sysctl_max_map_count)
73729 return -ENOMEM;
73730
73731 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
73732 + if (security_vm_enough_memory(charged))
73733 return -ENOMEM;
73734
73735 /* Can we just expand an old private anonymous mapping? */
73736 @@ -2244,7 +2674,7 @@ unsigned long do_brk(unsigned long addr,
73737 */
73738 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73739 if (!vma) {
73740 - vm_unacct_memory(len >> PAGE_SHIFT);
73741 + vm_unacct_memory(charged);
73742 return -ENOMEM;
73743 }
73744
73745 @@ -2258,11 +2688,12 @@ unsigned long do_brk(unsigned long addr,
73746 vma_link(mm, vma, prev, rb_link, rb_parent);
73747 out:
73748 perf_event_mmap(vma);
73749 - mm->total_vm += len >> PAGE_SHIFT;
73750 + mm->total_vm += charged;
73751 if (flags & VM_LOCKED) {
73752 if (!mlock_vma_pages_range(vma, addr, addr + len))
73753 - mm->locked_vm += (len >> PAGE_SHIFT);
73754 + mm->locked_vm += charged;
73755 }
73756 + track_exec_limit(mm, addr, addr + len, flags);
73757 return addr;
73758 }
73759
73760 @@ -2309,8 +2740,10 @@ void exit_mmap(struct mm_struct *mm)
73761 * Walk the list again, actually closing and freeing it,
73762 * with preemption enabled, without holding any MM locks.
73763 */
73764 - while (vma)
73765 + while (vma) {
73766 + vma->vm_mirror = NULL;
73767 vma = remove_vma(vma);
73768 + }
73769
73770 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73771 }
73772 @@ -2324,6 +2757,13 @@ int insert_vm_struct(struct mm_struct *
73773 struct vm_area_struct * __vma, * prev;
73774 struct rb_node ** rb_link, * rb_parent;
73775
73776 +#ifdef CONFIG_PAX_SEGMEXEC
73777 + struct vm_area_struct *vma_m = NULL;
73778 +#endif
73779 +
73780 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73781 + return -EPERM;
73782 +
73783 /*
73784 * The vm_pgoff of a purely anonymous vma should be irrelevant
73785 * until its first write fault, when page's anon_vma and index
73786 @@ -2346,7 +2786,22 @@ int insert_vm_struct(struct mm_struct *
73787 if ((vma->vm_flags & VM_ACCOUNT) &&
73788 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73789 return -ENOMEM;
73790 +
73791 +#ifdef CONFIG_PAX_SEGMEXEC
73792 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73793 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73794 + if (!vma_m)
73795 + return -ENOMEM;
73796 + }
73797 +#endif
73798 +
73799 vma_link(mm, vma, prev, rb_link, rb_parent);
73800 +
73801 +#ifdef CONFIG_PAX_SEGMEXEC
73802 + if (vma_m)
73803 + BUG_ON(pax_mirror_vma(vma_m, vma));
73804 +#endif
73805 +
73806 return 0;
73807 }
73808
73809 @@ -2364,6 +2819,8 @@ struct vm_area_struct *copy_vma(struct v
73810 struct rb_node **rb_link, *rb_parent;
73811 struct mempolicy *pol;
73812
73813 + BUG_ON(vma->vm_mirror);
73814 +
73815 /*
73816 * If anonymous vma has not yet been faulted, update new pgoff
73817 * to match new location, to increase its chance of merging.
73818 @@ -2413,6 +2870,39 @@ struct vm_area_struct *copy_vma(struct v
73819 kmem_cache_free(vm_area_cachep, new_vma);
73820 return NULL;
73821 }
73822 +
73823 +#ifdef CONFIG_PAX_SEGMEXEC
73824 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73825 +{
73826 + struct vm_area_struct *prev_m;
73827 + struct rb_node **rb_link_m, *rb_parent_m;
73828 + struct mempolicy *pol_m;
73829 +
73830 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73831 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73832 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73833 + *vma_m = *vma;
73834 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73835 + if (anon_vma_clone(vma_m, vma))
73836 + return -ENOMEM;
73837 + pol_m = vma_policy(vma_m);
73838 + mpol_get(pol_m);
73839 + vma_set_policy(vma_m, pol_m);
73840 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73841 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73842 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73843 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73844 + if (vma_m->vm_file)
73845 + get_file(vma_m->vm_file);
73846 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73847 + vma_m->vm_ops->open(vma_m);
73848 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73849 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73850 + vma_m->vm_mirror = vma;
73851 + vma->vm_mirror = vma_m;
73852 + return 0;
73853 +}
73854 +#endif
73855
73856 /*
73857 * Return true if the calling process may expand its vm space by the passed
73858 @@ -2424,7 +2914,7 @@ int may_expand_vm(struct mm_struct *mm,
73859 unsigned long lim;
73860
73861 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73862 -
73863 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73864 if (cur + npages > lim)
73865 return 0;
73866 return 1;
73867 @@ -2495,6 +2985,22 @@ int install_special_mapping(struct mm_st
73868 vma->vm_start = addr;
73869 vma->vm_end = addr + len;
73870
73871 +#ifdef CONFIG_PAX_MPROTECT
73872 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73873 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73874 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73875 + return -EPERM;
73876 + if (!(vm_flags & VM_EXEC))
73877 + vm_flags &= ~VM_MAYEXEC;
73878 +#else
73879 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73880 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73881 +#endif
73882 + else
73883 + vm_flags &= ~VM_MAYWRITE;
73884 + }
73885 +#endif
73886 +
73887 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73888 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73889
73890 diff -urNp linux-2.6.39.2/mm/mprotect.c linux-2.6.39.2/mm/mprotect.c
73891 --- linux-2.6.39.2/mm/mprotect.c 2011-05-19 00:06:34.000000000 -0400
73892 +++ linux-2.6.39.2/mm/mprotect.c 2011-05-22 19:41:42.000000000 -0400
73893 @@ -23,10 +23,16 @@
73894 #include <linux/mmu_notifier.h>
73895 #include <linux/migrate.h>
73896 #include <linux/perf_event.h>
73897 +
73898 +#ifdef CONFIG_PAX_MPROTECT
73899 +#include <linux/elf.h>
73900 +#endif
73901 +
73902 #include <asm/uaccess.h>
73903 #include <asm/pgtable.h>
73904 #include <asm/cacheflush.h>
73905 #include <asm/tlbflush.h>
73906 +#include <asm/mmu_context.h>
73907
73908 #ifndef pgprot_modify
73909 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73910 @@ -141,6 +147,48 @@ static void change_protection(struct vm_
73911 flush_tlb_range(vma, start, end);
73912 }
73913
73914 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73915 +/* called while holding the mmap semaphor for writing except stack expansion */
73916 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73917 +{
73918 + unsigned long oldlimit, newlimit = 0UL;
73919 +
73920 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73921 + return;
73922 +
73923 + spin_lock(&mm->page_table_lock);
73924 + oldlimit = mm->context.user_cs_limit;
73925 + if ((prot & VM_EXEC) && oldlimit < end)
73926 + /* USER_CS limit moved up */
73927 + newlimit = end;
73928 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73929 + /* USER_CS limit moved down */
73930 + newlimit = start;
73931 +
73932 + if (newlimit) {
73933 + mm->context.user_cs_limit = newlimit;
73934 +
73935 +#ifdef CONFIG_SMP
73936 + wmb();
73937 + cpus_clear(mm->context.cpu_user_cs_mask);
73938 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73939 +#endif
73940 +
73941 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73942 + }
73943 + spin_unlock(&mm->page_table_lock);
73944 + if (newlimit == end) {
73945 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73946 +
73947 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73948 + if (is_vm_hugetlb_page(vma))
73949 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73950 + else
73951 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73952 + }
73953 +}
73954 +#endif
73955 +
73956 int
73957 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73958 unsigned long start, unsigned long end, unsigned long newflags)
73959 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vm
73960 int error;
73961 int dirty_accountable = 0;
73962
73963 +#ifdef CONFIG_PAX_SEGMEXEC
73964 + struct vm_area_struct *vma_m = NULL;
73965 + unsigned long start_m, end_m;
73966 +
73967 + start_m = start + SEGMEXEC_TASK_SIZE;
73968 + end_m = end + SEGMEXEC_TASK_SIZE;
73969 +#endif
73970 +
73971 if (newflags == oldflags) {
73972 *pprev = vma;
73973 return 0;
73974 }
73975
73976 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73977 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73978 +
73979 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73980 + return -ENOMEM;
73981 +
73982 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73983 + return -ENOMEM;
73984 + }
73985 +
73986 /*
73987 * If we make a private mapping writable we increase our commit;
73988 * but (without finer accounting) cannot reduce our commit if we
73989 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vm
73990 }
73991 }
73992
73993 +#ifdef CONFIG_PAX_SEGMEXEC
73994 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73995 + if (start != vma->vm_start) {
73996 + error = split_vma(mm, vma, start, 1);
73997 + if (error)
73998 + goto fail;
73999 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74000 + *pprev = (*pprev)->vm_next;
74001 + }
74002 +
74003 + if (end != vma->vm_end) {
74004 + error = split_vma(mm, vma, end, 0);
74005 + if (error)
74006 + goto fail;
74007 + }
74008 +
74009 + if (pax_find_mirror_vma(vma)) {
74010 + error = __do_munmap(mm, start_m, end_m - start_m);
74011 + if (error)
74012 + goto fail;
74013 + } else {
74014 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74015 + if (!vma_m) {
74016 + error = -ENOMEM;
74017 + goto fail;
74018 + }
74019 + vma->vm_flags = newflags;
74020 + error = pax_mirror_vma(vma_m, vma);
74021 + if (error) {
74022 + vma->vm_flags = oldflags;
74023 + goto fail;
74024 + }
74025 + }
74026 + }
74027 +#endif
74028 +
74029 /*
74030 * First try to merge with previous and/or next vma.
74031 */
74032 @@ -204,9 +306,21 @@ success:
74033 * vm_flags and vm_page_prot are protected by the mmap_sem
74034 * held in write mode.
74035 */
74036 +
74037 +#ifdef CONFIG_PAX_SEGMEXEC
74038 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74039 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74040 +#endif
74041 +
74042 vma->vm_flags = newflags;
74043 +
74044 +#ifdef CONFIG_PAX_MPROTECT
74045 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74046 + mm->binfmt->handle_mprotect(vma, newflags);
74047 +#endif
74048 +
74049 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74050 - vm_get_page_prot(newflags));
74051 + vm_get_page_prot(vma->vm_flags));
74052
74053 if (vma_wants_writenotify(vma)) {
74054 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74055 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74056 end = start + len;
74057 if (end <= start)
74058 return -ENOMEM;
74059 +
74060 +#ifdef CONFIG_PAX_SEGMEXEC
74061 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74062 + if (end > SEGMEXEC_TASK_SIZE)
74063 + return -EINVAL;
74064 + } else
74065 +#endif
74066 +
74067 + if (end > TASK_SIZE)
74068 + return -EINVAL;
74069 +
74070 if (!arch_validate_prot(prot))
74071 return -EINVAL;
74072
74073 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74074 /*
74075 * Does the application expect PROT_READ to imply PROT_EXEC:
74076 */
74077 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74078 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74079 prot |= PROT_EXEC;
74080
74081 vm_flags = calc_vm_prot_bits(prot);
74082 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74083 if (start > vma->vm_start)
74084 prev = vma;
74085
74086 +#ifdef CONFIG_PAX_MPROTECT
74087 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74088 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74089 +#endif
74090 +
74091 for (nstart = start ; ; ) {
74092 unsigned long newflags;
74093
74094 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74095
74096 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74097 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74098 + if (prot & (PROT_WRITE | PROT_EXEC))
74099 + gr_log_rwxmprotect(vma->vm_file);
74100 +
74101 + error = -EACCES;
74102 + goto out;
74103 + }
74104 +
74105 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74106 error = -EACCES;
74107 goto out;
74108 }
74109 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
74110 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74111 if (error)
74112 goto out;
74113 +
74114 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74115 +
74116 nstart = tmp;
74117
74118 if (nstart < prev->vm_end)
74119 diff -urNp linux-2.6.39.2/mm/mremap.c linux-2.6.39.2/mm/mremap.c
74120 --- linux-2.6.39.2/mm/mremap.c 2011-05-19 00:06:34.000000000 -0400
74121 +++ linux-2.6.39.2/mm/mremap.c 2011-05-22 19:36:33.000000000 -0400
74122 @@ -114,6 +114,12 @@ static void move_ptes(struct vm_area_str
74123 continue;
74124 pte = ptep_clear_flush(vma, old_addr, old_pte);
74125 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74126 +
74127 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74128 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74129 + pte = pte_exprotect(pte);
74130 +#endif
74131 +
74132 set_pte_at(mm, new_addr, new_pte, pte);
74133 }
74134
74135 @@ -273,6 +279,11 @@ static struct vm_area_struct *vma_to_res
74136 if (is_vm_hugetlb_page(vma))
74137 goto Einval;
74138
74139 +#ifdef CONFIG_PAX_SEGMEXEC
74140 + if (pax_find_mirror_vma(vma))
74141 + goto Einval;
74142 +#endif
74143 +
74144 /* We can't remap across vm area boundaries */
74145 if (old_len > vma->vm_end - addr)
74146 goto Efault;
74147 @@ -329,20 +340,25 @@ static unsigned long mremap_to(unsigned
74148 unsigned long ret = -EINVAL;
74149 unsigned long charged = 0;
74150 unsigned long map_flags;
74151 + unsigned long pax_task_size = TASK_SIZE;
74152
74153 if (new_addr & ~PAGE_MASK)
74154 goto out;
74155
74156 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74157 +#ifdef CONFIG_PAX_SEGMEXEC
74158 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74159 + pax_task_size = SEGMEXEC_TASK_SIZE;
74160 +#endif
74161 +
74162 + pax_task_size -= PAGE_SIZE;
74163 +
74164 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74165 goto out;
74166
74167 /* Check if the location we're moving into overlaps the
74168 * old location at all, and fail if it does.
74169 */
74170 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74171 - goto out;
74172 -
74173 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74174 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74175 goto out;
74176
74177 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74178 @@ -414,6 +430,7 @@ unsigned long do_mremap(unsigned long ad
74179 struct vm_area_struct *vma;
74180 unsigned long ret = -EINVAL;
74181 unsigned long charged = 0;
74182 + unsigned long pax_task_size = TASK_SIZE;
74183
74184 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
74185 goto out;
74186 @@ -432,6 +449,17 @@ unsigned long do_mremap(unsigned long ad
74187 if (!new_len)
74188 goto out;
74189
74190 +#ifdef CONFIG_PAX_SEGMEXEC
74191 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74192 + pax_task_size = SEGMEXEC_TASK_SIZE;
74193 +#endif
74194 +
74195 + pax_task_size -= PAGE_SIZE;
74196 +
74197 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74198 + old_len > pax_task_size || addr > pax_task_size-old_len)
74199 + goto out;
74200 +
74201 if (flags & MREMAP_FIXED) {
74202 if (flags & MREMAP_MAYMOVE)
74203 ret = mremap_to(addr, old_len, new_addr, new_len);
74204 @@ -481,6 +509,7 @@ unsigned long do_mremap(unsigned long ad
74205 addr + new_len);
74206 }
74207 ret = addr;
74208 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74209 goto out;
74210 }
74211 }
74212 @@ -507,7 +536,13 @@ unsigned long do_mremap(unsigned long ad
74213 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74214 if (ret)
74215 goto out;
74216 +
74217 + map_flags = vma->vm_flags;
74218 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74219 + if (!(ret & ~PAGE_MASK)) {
74220 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74221 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74222 + }
74223 }
74224 out:
74225 if (ret & ~PAGE_MASK)
74226 diff -urNp linux-2.6.39.2/mm/nobootmem.c linux-2.6.39.2/mm/nobootmem.c
74227 --- linux-2.6.39.2/mm/nobootmem.c 2011-05-19 00:06:34.000000000 -0400
74228 +++ linux-2.6.39.2/mm/nobootmem.c 2011-05-22 19:36:33.000000000 -0400
74229 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(u
74230 unsigned long __init free_all_memory_core_early(int nodeid)
74231 {
74232 int i;
74233 - u64 start, end;
74234 + u64 start, end, startrange, endrange;
74235 unsigned long count = 0;
74236 - struct range *range = NULL;
74237 + struct range *range = NULL, rangerange = { 0, 0 };
74238 int nr_range;
74239
74240 nr_range = get_free_all_memory_range(&range, nodeid);
74241 + startrange = __pa(range) >> PAGE_SHIFT;
74242 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
74243
74244 for (i = 0; i < nr_range; i++) {
74245 start = range[i].start;
74246 end = range[i].end;
74247 + if (start <= endrange && startrange < end) {
74248 + BUG_ON(rangerange.start | rangerange.end);
74249 + rangerange = range[i];
74250 + continue;
74251 + }
74252 count += end - start;
74253 __free_pages_memory(start, end);
74254 }
74255 + start = rangerange.start;
74256 + end = rangerange.end;
74257 + count += end - start;
74258 + __free_pages_memory(start, end);
74259
74260 return count;
74261 }
74262 diff -urNp linux-2.6.39.2/mm/nommu.c linux-2.6.39.2/mm/nommu.c
74263 --- linux-2.6.39.2/mm/nommu.c 2011-05-19 00:06:34.000000000 -0400
74264 +++ linux-2.6.39.2/mm/nommu.c 2011-05-22 19:36:33.000000000 -0400
74265 @@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMI
74266 int sysctl_overcommit_ratio = 50; /* default is 50% */
74267 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74268 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74269 -int heap_stack_gap = 0;
74270
74271 atomic_long_t mmap_pages_allocated;
74272
74273 @@ -833,15 +832,6 @@ struct vm_area_struct *find_vma(struct m
74274 EXPORT_SYMBOL(find_vma);
74275
74276 /*
74277 - * find a VMA
74278 - * - we don't extend stack VMAs under NOMMU conditions
74279 - */
74280 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74281 -{
74282 - return find_vma(mm, addr);
74283 -}
74284 -
74285 -/*
74286 * expand a stack to a given address
74287 * - not supported under NOMMU conditions
74288 */
74289 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, stru
74290
74291 /* most fields are the same, copy all, and then fixup */
74292 *new = *vma;
74293 + INIT_LIST_HEAD(&new->anon_vma_chain);
74294 *region = *vma->vm_region;
74295 new->vm_region = region;
74296
74297 diff -urNp linux-2.6.39.2/mm/page_alloc.c linux-2.6.39.2/mm/page_alloc.c
74298 --- linux-2.6.39.2/mm/page_alloc.c 2011-06-03 00:04:14.000000000 -0400
74299 +++ linux-2.6.39.2/mm/page_alloc.c 2011-06-03 00:32:08.000000000 -0400
74300 @@ -650,6 +650,10 @@ static bool free_pages_prepare(struct pa
74301 int i;
74302 int bad = 0;
74303
74304 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74305 + unsigned long index = 1UL << order;
74306 +#endif
74307 +
74308 trace_mm_page_free_direct(page, order);
74309 kmemcheck_free_shadow(page, order);
74310
74311 @@ -665,6 +669,12 @@ static bool free_pages_prepare(struct pa
74312 debug_check_no_obj_freed(page_address(page),
74313 PAGE_SIZE << order);
74314 }
74315 +
74316 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74317 + for (; index; --index)
74318 + sanitize_highpage(page + index - 1);
74319 +#endif
74320 +
74321 arch_free_page(page, order);
74322 kernel_map_pages(page, 1 << order, 0);
74323
74324 @@ -780,8 +790,10 @@ static int prep_new_page(struct page *pa
74325 arch_alloc_page(page, order);
74326 kernel_map_pages(page, 1 << order, 1);
74327
74328 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74329 if (gfp_flags & __GFP_ZERO)
74330 prep_zero_page(page, order, gfp_flags);
74331 +#endif
74332
74333 if (order && (gfp_flags & __GFP_COMP))
74334 prep_compound_page(page, order);
74335 @@ -2504,6 +2516,8 @@ void __show_free_areas(unsigned int filt
74336 int cpu;
74337 struct zone *zone;
74338
74339 + pax_track_stack();
74340 +
74341 for_each_populated_zone(zone) {
74342 if (skip_free_areas_zone(filter, zone))
74343 continue;
74344 diff -urNp linux-2.6.39.2/mm/percpu.c linux-2.6.39.2/mm/percpu.c
74345 --- linux-2.6.39.2/mm/percpu.c 2011-05-19 00:06:34.000000000 -0400
74346 +++ linux-2.6.39.2/mm/percpu.c 2011-05-22 19:36:33.000000000 -0400
74347 @@ -121,7 +121,7 @@ static unsigned int pcpu_first_unit_cpu
74348 static unsigned int pcpu_last_unit_cpu __read_mostly;
74349
74350 /* the address of the first chunk which starts with the kernel static area */
74351 -void *pcpu_base_addr __read_mostly;
74352 +void *pcpu_base_addr __read_only;
74353 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74354
74355 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74356 diff -urNp linux-2.6.39.2/mm/rmap.c linux-2.6.39.2/mm/rmap.c
74357 --- linux-2.6.39.2/mm/rmap.c 2011-05-19 00:06:34.000000000 -0400
74358 +++ linux-2.6.39.2/mm/rmap.c 2011-05-22 19:36:33.000000000 -0400
74359 @@ -131,6 +131,10 @@ int anon_vma_prepare(struct vm_area_stru
74360 struct anon_vma *anon_vma = vma->anon_vma;
74361 struct anon_vma_chain *avc;
74362
74363 +#ifdef CONFIG_PAX_SEGMEXEC
74364 + struct anon_vma_chain *avc_m = NULL;
74365 +#endif
74366 +
74367 might_sleep();
74368 if (unlikely(!anon_vma)) {
74369 struct mm_struct *mm = vma->vm_mm;
74370 @@ -140,6 +144,12 @@ int anon_vma_prepare(struct vm_area_stru
74371 if (!avc)
74372 goto out_enomem;
74373
74374 +#ifdef CONFIG_PAX_SEGMEXEC
74375 + avc_m = anon_vma_chain_alloc();
74376 + if (!avc_m)
74377 + goto out_enomem_free_avc;
74378 +#endif
74379 +
74380 anon_vma = find_mergeable_anon_vma(vma);
74381 allocated = NULL;
74382 if (!anon_vma) {
74383 @@ -153,6 +163,21 @@ int anon_vma_prepare(struct vm_area_stru
74384 /* page_table_lock to protect against threads */
74385 spin_lock(&mm->page_table_lock);
74386 if (likely(!vma->anon_vma)) {
74387 +
74388 +#ifdef CONFIG_PAX_SEGMEXEC
74389 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74390 +
74391 + if (vma_m) {
74392 + BUG_ON(vma_m->anon_vma);
74393 + vma_m->anon_vma = anon_vma;
74394 + avc_m->anon_vma = anon_vma;
74395 + avc_m->vma = vma;
74396 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74397 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
74398 + avc_m = NULL;
74399 + }
74400 +#endif
74401 +
74402 vma->anon_vma = anon_vma;
74403 avc->anon_vma = anon_vma;
74404 avc->vma = vma;
74405 @@ -166,12 +191,24 @@ int anon_vma_prepare(struct vm_area_stru
74406
74407 if (unlikely(allocated))
74408 put_anon_vma(allocated);
74409 +
74410 +#ifdef CONFIG_PAX_SEGMEXEC
74411 + if (unlikely(avc_m))
74412 + anon_vma_chain_free(avc_m);
74413 +#endif
74414 +
74415 if (unlikely(avc))
74416 anon_vma_chain_free(avc);
74417 }
74418 return 0;
74419
74420 out_enomem_free_avc:
74421 +
74422 +#ifdef CONFIG_PAX_SEGMEXEC
74423 + if (avc_m)
74424 + anon_vma_chain_free(avc_m);
74425 +#endif
74426 +
74427 anon_vma_chain_free(avc);
74428 out_enomem:
74429 return -ENOMEM;
74430 @@ -198,7 +235,7 @@ static void anon_vma_chain_link(struct v
74431 * Attach the anon_vmas from src to dst.
74432 * Returns 0 on success, -ENOMEM on failure.
74433 */
74434 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74435 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74436 {
74437 struct anon_vma_chain *avc, *pavc;
74438
74439 @@ -220,7 +257,7 @@ int anon_vma_clone(struct vm_area_struct
74440 * the corresponding VMA in the parent process is attached to.
74441 * Returns 0 on success, non-zero on failure.
74442 */
74443 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74444 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74445 {
74446 struct anon_vma_chain *avc;
74447 struct anon_vma *anon_vma;
74448 diff -urNp linux-2.6.39.2/mm/shmem.c linux-2.6.39.2/mm/shmem.c
74449 --- linux-2.6.39.2/mm/shmem.c 2011-06-03 00:04:14.000000000 -0400
74450 +++ linux-2.6.39.2/mm/shmem.c 2011-06-03 00:32:08.000000000 -0400
74451 @@ -31,7 +31,7 @@
74452 #include <linux/percpu_counter.h>
74453 #include <linux/swap.h>
74454
74455 -static struct vfsmount *shm_mnt;
74456 +struct vfsmount *shm_mnt;
74457
74458 #ifdef CONFIG_SHMEM
74459 /*
74460 @@ -1087,6 +1087,8 @@ static int shmem_writepage(struct page *
74461 goto unlock;
74462 }
74463 entry = shmem_swp_entry(info, index, NULL);
74464 + if (!entry)
74465 + goto unlock;
74466 if (entry->val) {
74467 /*
74468 * The more uptodate page coming down from a stacked
74469 @@ -1158,6 +1160,8 @@ static struct page *shmem_swapin(swp_ent
74470 struct vm_area_struct pvma;
74471 struct page *page;
74472
74473 + pax_track_stack();
74474 +
74475 spol = mpol_cond_copy(&mpol,
74476 mpol_shared_policy_lookup(&info->policy, idx));
74477
74478 @@ -2014,7 +2018,7 @@ static int shmem_symlink(struct inode *d
74479
74480 info = SHMEM_I(inode);
74481 inode->i_size = len-1;
74482 - if (len <= (char *)inode - (char *)info) {
74483 + if (len <= (char *)inode - (char *)info && len <= 64) {
74484 /* do it inline */
74485 memcpy(info, symname, len);
74486 inode->i_op = &shmem_symlink_inline_operations;
74487 @@ -2362,8 +2366,7 @@ int shmem_fill_super(struct super_block
74488 int err = -ENOMEM;
74489
74490 /* Round up to L1_CACHE_BYTES to resist false sharing */
74491 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74492 - L1_CACHE_BYTES), GFP_KERNEL);
74493 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74494 if (!sbinfo)
74495 return -ENOMEM;
74496
74497 diff -urNp linux-2.6.39.2/mm/slab.c linux-2.6.39.2/mm/slab.c
74498 --- linux-2.6.39.2/mm/slab.c 2011-05-19 00:06:34.000000000 -0400
74499 +++ linux-2.6.39.2/mm/slab.c 2011-05-22 19:41:42.000000000 -0400
74500 @@ -150,7 +150,7 @@
74501
74502 /* Legal flag mask for kmem_cache_create(). */
74503 #if DEBUG
74504 -# define CREATE_MASK (SLAB_RED_ZONE | \
74505 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74506 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74507 SLAB_CACHE_DMA | \
74508 SLAB_STORE_USER | \
74509 @@ -158,7 +158,7 @@
74510 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74511 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74512 #else
74513 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74514 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74515 SLAB_CACHE_DMA | \
74516 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74517 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74518 @@ -287,7 +287,7 @@ struct kmem_list3 {
74519 * Need this for bootstrapping a per node allocator.
74520 */
74521 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74522 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74523 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74524 #define CACHE_CACHE 0
74525 #define SIZE_AC MAX_NUMNODES
74526 #define SIZE_L3 (2 * MAX_NUMNODES)
74527 @@ -388,10 +388,10 @@ static void kmem_list3_init(struct kmem_
74528 if ((x)->max_freeable < i) \
74529 (x)->max_freeable = i; \
74530 } while (0)
74531 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74532 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74533 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74534 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74535 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74536 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74537 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74538 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74539 #else
74540 #define STATS_INC_ACTIVE(x) do { } while (0)
74541 #define STATS_DEC_ACTIVE(x) do { } while (0)
74542 @@ -537,7 +537,7 @@ static inline void *index_to_obj(struct
74543 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74544 */
74545 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74546 - const struct slab *slab, void *obj)
74547 + const struct slab *slab, const void *obj)
74548 {
74549 u32 offset = (obj - slab->s_mem);
74550 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74551 @@ -563,7 +563,7 @@ struct cache_names {
74552 static struct cache_names __initdata cache_names[] = {
74553 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74554 #include <linux/kmalloc_sizes.h>
74555 - {NULL,}
74556 + {NULL}
74557 #undef CACHE
74558 };
74559
74560 @@ -1529,7 +1529,7 @@ void __init kmem_cache_init(void)
74561 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74562 sizes[INDEX_AC].cs_size,
74563 ARCH_KMALLOC_MINALIGN,
74564 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74565 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74566 NULL);
74567
74568 if (INDEX_AC != INDEX_L3) {
74569 @@ -1537,7 +1537,7 @@ void __init kmem_cache_init(void)
74570 kmem_cache_create(names[INDEX_L3].name,
74571 sizes[INDEX_L3].cs_size,
74572 ARCH_KMALLOC_MINALIGN,
74573 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74574 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74575 NULL);
74576 }
74577
74578 @@ -1555,7 +1555,7 @@ void __init kmem_cache_init(void)
74579 sizes->cs_cachep = kmem_cache_create(names->name,
74580 sizes->cs_size,
74581 ARCH_KMALLOC_MINALIGN,
74582 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74583 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74584 NULL);
74585 }
74586 #ifdef CONFIG_ZONE_DMA
74587 @@ -4270,10 +4270,10 @@ static int s_show(struct seq_file *m, vo
74588 }
74589 /* cpu stats */
74590 {
74591 - unsigned long allochit = atomic_read(&cachep->allochit);
74592 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74593 - unsigned long freehit = atomic_read(&cachep->freehit);
74594 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74595 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74596 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74597 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74598 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74599
74600 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74601 allochit, allocmiss, freehit, freemiss);
74602 @@ -4530,15 +4530,66 @@ static const struct file_operations proc
74603
74604 static int __init slab_proc_init(void)
74605 {
74606 - proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
74607 + mode_t gr_mode = S_IRUGO;
74608 +
74609 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74610 + gr_mode = S_IRUSR;
74611 +#endif
74612 +
74613 + proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
74614 #ifdef CONFIG_DEBUG_SLAB_LEAK
74615 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74616 + proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
74617 #endif
74618 return 0;
74619 }
74620 module_init(slab_proc_init);
74621 #endif
74622
74623 +void check_object_size(const void *ptr, unsigned long n, bool to)
74624 +{
74625 +
74626 +#ifdef CONFIG_PAX_USERCOPY
74627 + struct page *page;
74628 + struct kmem_cache *cachep = NULL;
74629 + struct slab *slabp;
74630 + unsigned int objnr;
74631 + unsigned long offset;
74632 +
74633 + if (!n)
74634 + return;
74635 +
74636 + if (ZERO_OR_NULL_PTR(ptr))
74637 + goto report;
74638 +
74639 + if (!virt_addr_valid(ptr))
74640 + return;
74641 +
74642 + page = virt_to_head_page(ptr);
74643 +
74644 + if (!PageSlab(page)) {
74645 + if (object_is_on_stack(ptr, n) == -1)
74646 + goto report;
74647 + return;
74648 + }
74649 +
74650 + cachep = page_get_cache(page);
74651 + if (!(cachep->flags & SLAB_USERCOPY))
74652 + goto report;
74653 +
74654 + slabp = page_get_slab(page);
74655 + objnr = obj_to_index(cachep, slabp, ptr);
74656 + BUG_ON(objnr >= cachep->num);
74657 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74658 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74659 + return;
74660 +
74661 +report:
74662 + pax_report_usercopy(ptr, n, to, cachep ? cachep->name : NULL);
74663 +#endif
74664 +
74665 +}
74666 +EXPORT_SYMBOL(check_object_size);
74667 +
74668 /**
74669 * ksize - get the actual amount of memory allocated for a given object
74670 * @objp: Pointer to the object
74671 diff -urNp linux-2.6.39.2/mm/slob.c linux-2.6.39.2/mm/slob.c
74672 --- linux-2.6.39.2/mm/slob.c 2011-05-19 00:06:34.000000000 -0400
74673 +++ linux-2.6.39.2/mm/slob.c 2011-05-22 19:36:33.000000000 -0400
74674 @@ -29,7 +29,7 @@
74675 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74676 * alloc_pages() directly, allocating compound pages so the page order
74677 * does not have to be separately tracked, and also stores the exact
74678 - * allocation size in page->private so that it can be used to accurately
74679 + * allocation size in slob_page->size so that it can be used to accurately
74680 * provide ksize(). These objects are detected in kfree() because slob_page()
74681 * is false for them.
74682 *
74683 @@ -58,6 +58,7 @@
74684 */
74685
74686 #include <linux/kernel.h>
74687 +#include <linux/sched.h>
74688 #include <linux/slab.h>
74689 #include <linux/mm.h>
74690 #include <linux/swap.h> /* struct reclaim_state */
74691 @@ -102,7 +103,8 @@ struct slob_page {
74692 unsigned long flags; /* mandatory */
74693 atomic_t _count; /* mandatory */
74694 slobidx_t units; /* free units left in page */
74695 - unsigned long pad[2];
74696 + unsigned long pad[1];
74697 + unsigned long size; /* size when >=PAGE_SIZE */
74698 slob_t *free; /* first free slob_t in page */
74699 struct list_head list; /* linked list of free pages */
74700 };
74701 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74702 */
74703 static inline int is_slob_page(struct slob_page *sp)
74704 {
74705 - return PageSlab((struct page *)sp);
74706 + return PageSlab((struct page *)sp) && !sp->size;
74707 }
74708
74709 static inline void set_slob_page(struct slob_page *sp)
74710 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struc
74711
74712 static inline struct slob_page *slob_page(const void *addr)
74713 {
74714 - return (struct slob_page *)virt_to_page(addr);
74715 + return (struct slob_page *)virt_to_head_page(addr);
74716 }
74717
74718 /*
74719 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_
74720 /*
74721 * Return the size of a slob block.
74722 */
74723 -static slobidx_t slob_units(slob_t *s)
74724 +static slobidx_t slob_units(const slob_t *s)
74725 {
74726 if (s->units > 0)
74727 return s->units;
74728 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74729 /*
74730 * Return the next free slob block pointer after this one.
74731 */
74732 -static slob_t *slob_next(slob_t *s)
74733 +static slob_t *slob_next(const slob_t *s)
74734 {
74735 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74736 slobidx_t next;
74737 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74738 /*
74739 * Returns true if s is the last free block in its page.
74740 */
74741 -static int slob_last(slob_t *s)
74742 +static int slob_last(const slob_t *s)
74743 {
74744 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74745 }
74746 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, i
74747 if (!page)
74748 return NULL;
74749
74750 + set_slob_page(page);
74751 return page_address(page);
74752 }
74753
74754 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp
74755 if (!b)
74756 return NULL;
74757 sp = slob_page(b);
74758 - set_slob_page(sp);
74759
74760 spin_lock_irqsave(&slob_lock, flags);
74761 sp->units = SLOB_UNITS(PAGE_SIZE);
74762 sp->free = b;
74763 + sp->size = 0;
74764 INIT_LIST_HEAD(&sp->list);
74765 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74766 set_slob_page_free(sp, slob_list);
74767 @@ -476,10 +479,9 @@ out:
74768 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74769 */
74770
74771 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74772 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74773 {
74774 - unsigned int *m;
74775 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74776 + slob_t *m;
74777 void *ret;
74778
74779 lockdep_trace_alloc(gfp);
74780 @@ -492,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t
74781
74782 if (!m)
74783 return NULL;
74784 - *m = size;
74785 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74786 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74787 + m[0].units = size;
74788 + m[1].units = align;
74789 ret = (void *)m + align;
74790
74791 trace_kmalloc_node(_RET_IP_, ret,
74792 @@ -504,9 +509,9 @@ void *__kmalloc_node(size_t size, gfp_t
74793 gfp |= __GFP_COMP;
74794 ret = slob_new_pages(gfp, order, node);
74795 if (ret) {
74796 - struct page *page;
74797 - page = virt_to_page(ret);
74798 - page->private = size;
74799 + struct slob_page *sp;
74800 + sp = slob_page(ret);
74801 + sp->size = size;
74802 }
74803
74804 trace_kmalloc_node(_RET_IP_, ret,
74805 @@ -516,6 +521,13 @@ void *__kmalloc_node(size_t size, gfp_t
74806 kmemleak_alloc(ret, size, 1, gfp);
74807 return ret;
74808 }
74809 +
74810 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74811 +{
74812 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74813 +
74814 + return __kmalloc_node_align(size, gfp, node, align);
74815 +}
74816 EXPORT_SYMBOL(__kmalloc_node);
74817
74818 void kfree(const void *block)
74819 @@ -531,13 +543,81 @@ void kfree(const void *block)
74820 sp = slob_page(block);
74821 if (is_slob_page(sp)) {
74822 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74823 - unsigned int *m = (unsigned int *)(block - align);
74824 - slob_free(m, *m + align);
74825 - } else
74826 + slob_t *m = (slob_t *)(block - align);
74827 + slob_free(m, m[0].units + align);
74828 + } else {
74829 + clear_slob_page(sp);
74830 + free_slob_page(sp);
74831 + sp->size = 0;
74832 put_page(&sp->page);
74833 + }
74834 }
74835 EXPORT_SYMBOL(kfree);
74836
74837 +void check_object_size(const void *ptr, unsigned long n, bool to)
74838 +{
74839 +
74840 +#ifdef CONFIG_PAX_USERCOPY
74841 + struct slob_page *sp;
74842 + const slob_t *free;
74843 + const void *base;
74844 +
74845 + if (!n)
74846 + return;
74847 +
74848 + if (ZERO_OR_NULL_PTR(ptr))
74849 + goto report;
74850 +
74851 + if (!virt_addr_valid(ptr))
74852 + return;
74853 +
74854 + sp = slob_page(ptr);
74855 + if (!PageSlab((struct page*)sp)) {
74856 + if (object_is_on_stack(ptr, n) == -1)
74857 + goto report;
74858 + return;
74859 + }
74860 +
74861 + if (sp->size) {
74862 + base = page_address(&sp->page);
74863 + if (base <= ptr && n <= sp->size - (ptr - base))
74864 + return;
74865 + goto report;
74866 + }
74867 +
74868 + /* some tricky double walking to find the chunk */
74869 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74870 + free = sp->free;
74871 +
74872 + while (!slob_last(free) && (void *)free <= ptr) {
74873 + base = free + slob_units(free);
74874 + free = slob_next(free);
74875 + }
74876 +
74877 + while (base < (void *)free) {
74878 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74879 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74880 + int offset;
74881 +
74882 + if (ptr < base + align)
74883 + goto report;
74884 +
74885 + offset = ptr - base - align;
74886 + if (offset < m) {
74887 + if (n <= m - offset)
74888 + return;
74889 + goto report;
74890 + }
74891 + base += size;
74892 + }
74893 +
74894 +report:
74895 + pax_report_usercopy(ptr, n, to, NULL);
74896 +#endif
74897 +
74898 +}
74899 +EXPORT_SYMBOL(check_object_size);
74900 +
74901 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74902 size_t ksize(const void *block)
74903 {
74904 @@ -550,10 +630,10 @@ size_t ksize(const void *block)
74905 sp = slob_page(block);
74906 if (is_slob_page(sp)) {
74907 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74908 - unsigned int *m = (unsigned int *)(block - align);
74909 - return SLOB_UNITS(*m) * SLOB_UNIT;
74910 + slob_t *m = (slob_t *)(block - align);
74911 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74912 } else
74913 - return sp->page.private;
74914 + return sp->size;
74915 }
74916 EXPORT_SYMBOL(ksize);
74917
74918 @@ -608,17 +688,25 @@ void *kmem_cache_alloc_node(struct kmem_
74919 {
74920 void *b;
74921
74922 +#ifdef CONFIG_PAX_USERCOPY
74923 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74924 +#else
74925 if (c->size < PAGE_SIZE) {
74926 b = slob_alloc(c->size, flags, c->align, node);
74927 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74928 SLOB_UNITS(c->size) * SLOB_UNIT,
74929 flags, node);
74930 } else {
74931 + struct slob_page *sp;
74932 +
74933 b = slob_new_pages(flags, get_order(c->size), node);
74934 + sp = slob_page(b);
74935 + sp->size = c->size;
74936 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74937 PAGE_SIZE << get_order(c->size),
74938 flags, node);
74939 }
74940 +#endif
74941
74942 if (c->ctor)
74943 c->ctor(b);
74944 @@ -630,10 +718,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74945
74946 static void __kmem_cache_free(void *b, int size)
74947 {
74948 - if (size < PAGE_SIZE)
74949 + struct slob_page *sp = slob_page(b);
74950 +
74951 + if (is_slob_page(sp))
74952 slob_free(b, size);
74953 - else
74954 + else {
74955 + clear_slob_page(sp);
74956 + free_slob_page(sp);
74957 + sp->size = 0;
74958 slob_free_pages(b, get_order(size));
74959 + }
74960 }
74961
74962 static void kmem_rcu_free(struct rcu_head *head)
74963 @@ -646,14 +740,23 @@ static void kmem_rcu_free(struct rcu_hea
74964
74965 void kmem_cache_free(struct kmem_cache *c, void *b)
74966 {
74967 + int size = c->size;
74968 +
74969 +#ifdef CONFIG_PAX_USERCOPY
74970 + if (size + c->align < PAGE_SIZE) {
74971 + size += c->align;
74972 + b -= c->align;
74973 + }
74974 +#endif
74975 +
74976 kmemleak_free_recursive(b, c->flags);
74977 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74978 struct slob_rcu *slob_rcu;
74979 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74980 - slob_rcu->size = c->size;
74981 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74982 + slob_rcu->size = size;
74983 call_rcu(&slob_rcu->head, kmem_rcu_free);
74984 } else {
74985 - __kmem_cache_free(b, c->size);
74986 + __kmem_cache_free(b, size);
74987 }
74988
74989 trace_kmem_cache_free(_RET_IP_, b);
74990 diff -urNp linux-2.6.39.2/mm/slub.c linux-2.6.39.2/mm/slub.c
74991 --- linux-2.6.39.2/mm/slub.c 2011-06-03 00:04:14.000000000 -0400
74992 +++ linux-2.6.39.2/mm/slub.c 2011-06-03 00:32:08.000000000 -0400
74993 @@ -431,7 +431,7 @@ static void print_track(const char *s, s
74994 if (!t->addr)
74995 return;
74996
74997 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74998 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74999 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75000 }
75001
75002 @@ -2183,6 +2183,8 @@ void kmem_cache_free(struct kmem_cache *
75003
75004 page = virt_to_head_page(x);
75005
75006 + BUG_ON(!PageSlab(page));
75007 +
75008 slab_free(s, page, x, _RET_IP_);
75009
75010 trace_kmem_cache_free(_RET_IP_, x);
75011 @@ -2216,7 +2218,7 @@ static int slub_min_objects;
75012 * Merge control. If this is set then no merging of slab caches will occur.
75013 * (Could be removed. This was introduced to pacify the merge skeptics.)
75014 */
75015 -static int slub_nomerge;
75016 +static int slub_nomerge = 1;
75017
75018 /*
75019 * Calculate the order of allocation given an slab object size.
75020 @@ -2644,7 +2646,7 @@ static int kmem_cache_open(struct kmem_c
75021 * list to avoid pounding the page allocator excessively.
75022 */
75023 set_min_partial(s, ilog2(s->size));
75024 - s->refcount = 1;
75025 + atomic_set(&s->refcount, 1);
75026 #ifdef CONFIG_NUMA
75027 s->remote_node_defrag_ratio = 1000;
75028 #endif
75029 @@ -2750,8 +2752,7 @@ static inline int kmem_cache_close(struc
75030 void kmem_cache_destroy(struct kmem_cache *s)
75031 {
75032 down_write(&slub_lock);
75033 - s->refcount--;
75034 - if (!s->refcount) {
75035 + if (atomic_dec_and_test(&s->refcount)) {
75036 list_del(&s->list);
75037 if (kmem_cache_close(s)) {
75038 printk(KERN_ERR "SLUB %s: %s called for cache that "
75039 @@ -2961,6 +2962,46 @@ void *__kmalloc_node(size_t size, gfp_t
75040 EXPORT_SYMBOL(__kmalloc_node);
75041 #endif
75042
75043 +void check_object_size(const void *ptr, unsigned long n, bool to)
75044 +{
75045 +
75046 +#ifdef CONFIG_PAX_USERCOPY
75047 + struct page *page;
75048 + struct kmem_cache *s = NULL;
75049 + unsigned long offset;
75050 +
75051 + if (!n)
75052 + return;
75053 +
75054 + if (ZERO_OR_NULL_PTR(ptr))
75055 + goto report;
75056 +
75057 + if (!virt_addr_valid(ptr))
75058 + return;
75059 +
75060 + page = virt_to_head_page(ptr);
75061 +
75062 + if (!PageSlab(page)) {
75063 + if (object_is_on_stack(ptr, n) == -1)
75064 + goto report;
75065 + return;
75066 + }
75067 +
75068 + s = page->slab;
75069 + if (!(s->flags & SLAB_USERCOPY))
75070 + goto report;
75071 +
75072 + offset = (ptr - page_address(page)) % s->size;
75073 + if (offset <= s->objsize && n <= s->objsize - offset)
75074 + return;
75075 +
75076 +report:
75077 + pax_report_usercopy(ptr, n, to, s ? s->name : NULL);
75078 +#endif
75079 +
75080 +}
75081 +EXPORT_SYMBOL(check_object_size);
75082 +
75083 size_t ksize(const void *object)
75084 {
75085 struct page *page;
75086 @@ -3205,7 +3246,7 @@ static void __init kmem_cache_bootstrap_
75087 int node;
75088
75089 list_add(&s->list, &slab_caches);
75090 - s->refcount = -1;
75091 + atomic_set(&s->refcount, -1);
75092
75093 for_each_node_state(node, N_NORMAL_MEMORY) {
75094 struct kmem_cache_node *n = get_node(s, node);
75095 @@ -3322,17 +3363,17 @@ void __init kmem_cache_init(void)
75096
75097 /* Caches that are not of the two-to-the-power-of size */
75098 if (KMALLOC_MIN_SIZE <= 32) {
75099 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75100 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75101 caches++;
75102 }
75103
75104 if (KMALLOC_MIN_SIZE <= 64) {
75105 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75106 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75107 caches++;
75108 }
75109
75110 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75111 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75112 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75113 caches++;
75114 }
75115
75116 @@ -3400,7 +3441,7 @@ static int slab_unmergeable(struct kmem_
75117 /*
75118 * We may have set a slab to be unmergeable during bootstrap.
75119 */
75120 - if (s->refcount < 0)
75121 + if (atomic_read(&s->refcount) < 0)
75122 return 1;
75123
75124 return 0;
75125 @@ -3459,7 +3500,7 @@ struct kmem_cache *kmem_cache_create(con
75126 down_write(&slub_lock);
75127 s = find_mergeable(size, align, flags, name, ctor);
75128 if (s) {
75129 - s->refcount++;
75130 + atomic_inc(&s->refcount);
75131 /*
75132 * Adjust the object sizes so that we clear
75133 * the complete object on kzalloc.
75134 @@ -3468,7 +3509,7 @@ struct kmem_cache *kmem_cache_create(con
75135 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75136
75137 if (sysfs_slab_alias(s, name)) {
75138 - s->refcount--;
75139 + atomic_dec(&s->refcount);
75140 goto err;
75141 }
75142 up_write(&slub_lock);
75143 @@ -4201,7 +4242,7 @@ SLAB_ATTR_RO(ctor);
75144
75145 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75146 {
75147 - return sprintf(buf, "%d\n", s->refcount - 1);
75148 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75149 }
75150 SLAB_ATTR_RO(aliases);
75151
75152 @@ -4945,7 +4986,13 @@ static const struct file_operations proc
75153
75154 static int __init slab_proc_init(void)
75155 {
75156 - proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
75157 + mode_t gr_mode = S_IRUGO;
75158 +
75159 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75160 + gr_mode = S_IRUSR;
75161 +#endif
75162 +
75163 + proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
75164 return 0;
75165 }
75166 module_init(slab_proc_init);
75167 diff -urNp linux-2.6.39.2/mm/swapfile.c linux-2.6.39.2/mm/swapfile.c
75168 --- linux-2.6.39.2/mm/swapfile.c 2011-05-19 00:06:34.000000000 -0400
75169 +++ linux-2.6.39.2/mm/swapfile.c 2011-05-22 19:36:33.000000000 -0400
75170 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
75171
75172 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75173 /* Activity counter to indicate that a swapon or swapoff has occurred */
75174 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75175 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75176
75177 static inline unsigned char swap_count(unsigned char ent)
75178 {
75179 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
75180 }
75181 filp_close(swap_file, NULL);
75182 err = 0;
75183 - atomic_inc(&proc_poll_event);
75184 + atomic_inc_unchecked(&proc_poll_event);
75185 wake_up_interruptible(&proc_poll_wait);
75186
75187 out_dput:
75188 @@ -1690,8 +1690,8 @@ static unsigned swaps_poll(struct file *
75189
75190 poll_wait(file, &proc_poll_wait, wait);
75191
75192 - if (s->event != atomic_read(&proc_poll_event)) {
75193 - s->event = atomic_read(&proc_poll_event);
75194 + if (s->event != atomic_read_unchecked(&proc_poll_event)) {
75195 + s->event = atomic_read_unchecked(&proc_poll_event);
75196 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75197 }
75198
75199 @@ -1797,7 +1797,7 @@ static int swaps_open(struct inode *inod
75200 }
75201
75202 s->seq.private = s;
75203 - s->event = atomic_read(&proc_poll_event);
75204 + s->event = atomic_read_unchecked(&proc_poll_event);
75205 return ret;
75206 }
75207
75208 @@ -2131,7 +2131,7 @@ SYSCALL_DEFINE2(swapon, const char __use
75209 (p->flags & SWP_DISCARDABLE) ? "D" : "");
75210
75211 mutex_unlock(&swapon_mutex);
75212 - atomic_inc(&proc_poll_event);
75213 + atomic_inc_unchecked(&proc_poll_event);
75214 wake_up_interruptible(&proc_poll_wait);
75215
75216 if (S_ISREG(inode->i_mode))
75217 diff -urNp linux-2.6.39.2/mm/util.c linux-2.6.39.2/mm/util.c
75218 --- linux-2.6.39.2/mm/util.c 2011-05-19 00:06:34.000000000 -0400
75219 +++ linux-2.6.39.2/mm/util.c 2011-05-23 17:07:00.000000000 -0400
75220 @@ -112,6 +112,7 @@ EXPORT_SYMBOL(memdup_user);
75221 * allocated buffer. Use this if you don't want to free the buffer immediately
75222 * like, for example, with RCU.
75223 */
75224 +#undef __krealloc
75225 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
75226 {
75227 void *ret;
75228 @@ -145,6 +146,7 @@ EXPORT_SYMBOL(__krealloc);
75229 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
75230 * %NULL pointer, the object pointed to is freed.
75231 */
75232 +#undef krealloc
75233 void *krealloc(const void *p, size_t new_size, gfp_t flags)
75234 {
75235 void *ret;
75236 @@ -219,6 +221,12 @@ EXPORT_SYMBOL(strndup_user);
75237 void arch_pick_mmap_layout(struct mm_struct *mm)
75238 {
75239 mm->mmap_base = TASK_UNMAPPED_BASE;
75240 +
75241 +#ifdef CONFIG_PAX_RANDMMAP
75242 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75243 + mm->mmap_base += mm->delta_mmap;
75244 +#endif
75245 +
75246 mm->get_unmapped_area = arch_get_unmapped_area;
75247 mm->unmap_area = arch_unmap_area;
75248 }
75249 diff -urNp linux-2.6.39.2/mm/vmalloc.c linux-2.6.39.2/mm/vmalloc.c
75250 --- linux-2.6.39.2/mm/vmalloc.c 2011-05-19 00:06:34.000000000 -0400
75251 +++ linux-2.6.39.2/mm/vmalloc.c 2011-05-22 19:36:33.000000000 -0400
75252 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd,
75253
75254 pte = pte_offset_kernel(pmd, addr);
75255 do {
75256 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75257 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75258 +
75259 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75260 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75261 + BUG_ON(!pte_exec(*pte));
75262 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75263 + continue;
75264 + }
75265 +#endif
75266 +
75267 + {
75268 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75269 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75270 + }
75271 } while (pte++, addr += PAGE_SIZE, addr != end);
75272 }
75273
75274 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, un
75275 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75276 {
75277 pte_t *pte;
75278 + int ret = -ENOMEM;
75279
75280 /*
75281 * nr is a running index into the array which helps higher level
75282 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, un
75283 pte = pte_alloc_kernel(pmd, addr);
75284 if (!pte)
75285 return -ENOMEM;
75286 +
75287 + pax_open_kernel();
75288 do {
75289 struct page *page = pages[*nr];
75290
75291 - if (WARN_ON(!pte_none(*pte)))
75292 - return -EBUSY;
75293 - if (WARN_ON(!page))
75294 - return -ENOMEM;
75295 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75296 + if (pgprot_val(prot) & _PAGE_NX)
75297 +#endif
75298 +
75299 + if (WARN_ON(!pte_none(*pte))) {
75300 + ret = -EBUSY;
75301 + goto out;
75302 + }
75303 + if (WARN_ON(!page)) {
75304 + ret = -ENOMEM;
75305 + goto out;
75306 + }
75307 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75308 (*nr)++;
75309 } while (pte++, addr += PAGE_SIZE, addr != end);
75310 - return 0;
75311 + ret = 0;
75312 +out:
75313 + pax_close_kernel();
75314 + return ret;
75315 }
75316
75317 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75318 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void
75319 * and fall back on vmalloc() if that fails. Others
75320 * just put it in the vmalloc space.
75321 */
75322 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75323 +#ifdef CONFIG_MODULES
75324 +#ifdef MODULES_VADDR
75325 unsigned long addr = (unsigned long)x;
75326 if (addr >= MODULES_VADDR && addr < MODULES_END)
75327 return 1;
75328 #endif
75329 +
75330 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75331 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75332 + return 1;
75333 +#endif
75334 +
75335 +#endif
75336 +
75337 return is_vmalloc_addr(x);
75338 }
75339
75340 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void
75341
75342 if (!pgd_none(*pgd)) {
75343 pud_t *pud = pud_offset(pgd, addr);
75344 +#ifdef CONFIG_X86
75345 + if (!pud_large(*pud))
75346 +#endif
75347 if (!pud_none(*pud)) {
75348 pmd_t *pmd = pmd_offset(pud, addr);
75349 +#ifdef CONFIG_X86
75350 + if (!pmd_large(*pmd))
75351 +#endif
75352 if (!pmd_none(*pmd)) {
75353 pte_t *ptep, pte;
75354
75355 @@ -1296,6 +1336,16 @@ static struct vm_struct *__get_vm_area_n
75356 struct vm_struct *area;
75357
75358 BUG_ON(in_interrupt());
75359 +
75360 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75361 + if (flags & VM_KERNEXEC) {
75362 + if (start != VMALLOC_START || end != VMALLOC_END)
75363 + return NULL;
75364 + start = (unsigned long)MODULES_EXEC_VADDR;
75365 + end = (unsigned long)MODULES_EXEC_END;
75366 + }
75367 +#endif
75368 +
75369 if (flags & VM_IOREMAP) {
75370 int bit = fls(size);
75371
75372 @@ -1514,6 +1564,11 @@ void *vmap(struct page **pages, unsigned
75373 if (count > totalram_pages)
75374 return NULL;
75375
75376 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75377 + if (!(pgprot_val(prot) & _PAGE_NX))
75378 + flags |= VM_KERNEXEC;
75379 +#endif
75380 +
75381 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75382 __builtin_return_address(0));
75383 if (!area)
75384 @@ -1610,6 +1665,13 @@ void *__vmalloc_node_range(unsigned long
75385 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75386 return NULL;
75387
75388 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75389 + if (!(pgprot_val(prot) & _PAGE_NX))
75390 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
75391 + node, gfp_mask, caller);
75392 + else
75393 +#endif
75394 +
75395 area = __get_vm_area_node(size, align, VM_ALLOC, start, end, node,
75396 gfp_mask, caller);
75397
75398 @@ -1649,6 +1711,7 @@ static void *__vmalloc_node(unsigned lon
75399 gfp_mask, prot, node, caller);
75400 }
75401
75402 +#undef __vmalloc
75403 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
75404 {
75405 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
75406 @@ -1672,6 +1735,7 @@ static inline void *__vmalloc_node_flags
75407 * For tight control over page level allocator and protection flags
75408 * use __vmalloc() instead.
75409 */
75410 +#undef vmalloc
75411 void *vmalloc(unsigned long size)
75412 {
75413 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
75414 @@ -1688,6 +1752,7 @@ EXPORT_SYMBOL(vmalloc);
75415 * For tight control over page level allocator and protection flags
75416 * use __vmalloc() instead.
75417 */
75418 +#undef vzalloc
75419 void *vzalloc(unsigned long size)
75420 {
75421 return __vmalloc_node_flags(size, -1,
75422 @@ -1702,6 +1767,7 @@ EXPORT_SYMBOL(vzalloc);
75423 * The resulting memory area is zeroed so it can be mapped to userspace
75424 * without leaking data.
75425 */
75426 +#undef vmalloc_user
75427 void *vmalloc_user(unsigned long size)
75428 {
75429 struct vm_struct *area;
75430 @@ -1729,6 +1795,7 @@ EXPORT_SYMBOL(vmalloc_user);
75431 * For tight control over page level allocator and protection flags
75432 * use __vmalloc() instead.
75433 */
75434 +#undef vmalloc_node
75435 void *vmalloc_node(unsigned long size, int node)
75436 {
75437 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
75438 @@ -1748,6 +1815,7 @@ EXPORT_SYMBOL(vmalloc_node);
75439 * For tight control over page level allocator and protection flags
75440 * use __vmalloc_node() instead.
75441 */
75442 +#undef vzalloc_node
75443 void *vzalloc_node(unsigned long size, int node)
75444 {
75445 return __vmalloc_node_flags(size, node,
75446 @@ -1770,10 +1838,10 @@ EXPORT_SYMBOL(vzalloc_node);
75447 * For tight control over page level allocator and protection flags
75448 * use __vmalloc() instead.
75449 */
75450 -
75451 +#undef vmalloc_exec
75452 void *vmalloc_exec(unsigned long size)
75453 {
75454 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75455 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75456 -1, __builtin_return_address(0));
75457 }
75458
75459 @@ -1792,6 +1860,7 @@ void *vmalloc_exec(unsigned long size)
75460 * Allocate enough 32bit PA addressable pages to cover @size from the
75461 * page level allocator and map them into contiguous kernel virtual space.
75462 */
75463 +#undef vmalloc_32
75464 void *vmalloc_32(unsigned long size)
75465 {
75466 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
75467 @@ -1806,6 +1875,7 @@ EXPORT_SYMBOL(vmalloc_32);
75468 * The resulting memory area is 32bit addressable and zeroed so it can be
75469 * mapped to userspace without leaking data.
75470 */
75471 +#undef vmalloc_32_user
75472 void *vmalloc_32_user(unsigned long size)
75473 {
75474 struct vm_struct *area;
75475 @@ -2068,6 +2138,8 @@ int remap_vmalloc_range(struct vm_area_s
75476 unsigned long uaddr = vma->vm_start;
75477 unsigned long usize = vma->vm_end - vma->vm_start;
75478
75479 + BUG_ON(vma->vm_mirror);
75480 +
75481 if ((PAGE_SIZE-1) & (unsigned long)addr)
75482 return -EINVAL;
75483
75484 diff -urNp linux-2.6.39.2/mm/vmstat.c linux-2.6.39.2/mm/vmstat.c
75485 --- linux-2.6.39.2/mm/vmstat.c 2011-05-19 00:06:34.000000000 -0400
75486 +++ linux-2.6.39.2/mm/vmstat.c 2011-05-22 19:41:42.000000000 -0400
75487 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75488 *
75489 * vm_stat contains the global counters
75490 */
75491 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75492 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75493 EXPORT_SYMBOL(vm_stat);
75494
75495 #ifdef CONFIG_SMP
75496 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75497 v = p->vm_stat_diff[i];
75498 p->vm_stat_diff[i] = 0;
75499 local_irq_restore(flags);
75500 - atomic_long_add(v, &zone->vm_stat[i]);
75501 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75502 global_diff[i] += v;
75503 #ifdef CONFIG_NUMA
75504 /* 3 seconds idle till flush */
75505 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75506
75507 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75508 if (global_diff[i])
75509 - atomic_long_add(global_diff[i], &vm_stat[i]);
75510 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75511 }
75512
75513 #endif
75514 @@ -1205,10 +1205,20 @@ static int __init setup_vmstat(void)
75515 start_cpu_timer(cpu);
75516 #endif
75517 #ifdef CONFIG_PROC_FS
75518 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75519 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75520 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75521 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75522 + {
75523 + mode_t gr_mode = S_IRUGO;
75524 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75525 + gr_mode = S_IRUSR;
75526 +#endif
75527 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75528 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75529 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75530 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75531 +#else
75532 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75533 +#endif
75534 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75535 + }
75536 #endif
75537 return 0;
75538 }
75539 diff -urNp linux-2.6.39.2/net/8021q/vlan.c linux-2.6.39.2/net/8021q/vlan.c
75540 --- linux-2.6.39.2/net/8021q/vlan.c 2011-05-19 00:06:34.000000000 -0400
75541 +++ linux-2.6.39.2/net/8021q/vlan.c 2011-05-22 19:36:33.000000000 -0400
75542 @@ -592,8 +592,7 @@ static int vlan_ioctl_handler(struct net
75543 err = -EPERM;
75544 if (!capable(CAP_NET_ADMIN))
75545 break;
75546 - if ((args.u.name_type >= 0) &&
75547 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75548 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75549 struct vlan_net *vn;
75550
75551 vn = net_generic(net, vlan_net_id);
75552 diff -urNp linux-2.6.39.2/net/atm/atm_misc.c linux-2.6.39.2/net/atm/atm_misc.c
75553 --- linux-2.6.39.2/net/atm/atm_misc.c 2011-05-19 00:06:34.000000000 -0400
75554 +++ linux-2.6.39.2/net/atm/atm_misc.c 2011-05-22 19:36:33.000000000 -0400
75555 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int
75556 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75557 return 1;
75558 atm_return(vcc, truesize);
75559 - atomic_inc(&vcc->stats->rx_drop);
75560 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75561 return 0;
75562 }
75563 EXPORT_SYMBOL(atm_charge);
75564 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct
75565 }
75566 }
75567 atm_return(vcc, guess);
75568 - atomic_inc(&vcc->stats->rx_drop);
75569 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75570 return NULL;
75571 }
75572 EXPORT_SYMBOL(atm_alloc_charge);
75573 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75574
75575 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75576 {
75577 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75578 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75579 __SONET_ITEMS
75580 #undef __HANDLE_ITEM
75581 }
75582 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75583
75584 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75585 {
75586 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75587 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75588 __SONET_ITEMS
75589 #undef __HANDLE_ITEM
75590 }
75591 diff -urNp linux-2.6.39.2/net/atm/mpoa_caches.c linux-2.6.39.2/net/atm/mpoa_caches.c
75592 --- linux-2.6.39.2/net/atm/mpoa_caches.c 2011-05-19 00:06:34.000000000 -0400
75593 +++ linux-2.6.39.2/net/atm/mpoa_caches.c 2011-05-22 19:36:33.000000000 -0400
75594 @@ -255,6 +255,8 @@ static void check_resolving_entries(stru
75595 struct timeval now;
75596 struct k_message msg;
75597
75598 + pax_track_stack();
75599 +
75600 do_gettimeofday(&now);
75601
75602 read_lock_bh(&client->ingress_lock);
75603 diff -urNp linux-2.6.39.2/net/atm/proc.c linux-2.6.39.2/net/atm/proc.c
75604 --- linux-2.6.39.2/net/atm/proc.c 2011-05-19 00:06:34.000000000 -0400
75605 +++ linux-2.6.39.2/net/atm/proc.c 2011-05-22 19:41:42.000000000 -0400
75606 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *s
75607 const struct k_atm_aal_stats *stats)
75608 {
75609 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75610 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75611 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75612 - atomic_read(&stats->rx_drop));
75613 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75614 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75615 + atomic_read_unchecked(&stats->rx_drop));
75616 }
75617
75618 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75619 @@ -191,7 +191,12 @@ static void vcc_info(struct seq_file *se
75620 {
75621 struct sock *sk = sk_atm(vcc);
75622
75623 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75624 + seq_printf(seq, "%p ", NULL);
75625 +#else
75626 seq_printf(seq, "%p ", vcc);
75627 +#endif
75628 +
75629 if (!vcc->dev)
75630 seq_printf(seq, "Unassigned ");
75631 else
75632 @@ -218,7 +223,11 @@ static void svc_info(struct seq_file *se
75633 {
75634 if (!vcc->dev)
75635 seq_printf(seq, sizeof(void *) == 4 ?
75636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75637 + "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
75638 +#else
75639 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
75640 +#endif
75641 else
75642 seq_printf(seq, "%3d %3d %5d ",
75643 vcc->dev->number, vcc->vpi, vcc->vci);
75644 diff -urNp linux-2.6.39.2/net/atm/resources.c linux-2.6.39.2/net/atm/resources.c
75645 --- linux-2.6.39.2/net/atm/resources.c 2011-05-19 00:06:34.000000000 -0400
75646 +++ linux-2.6.39.2/net/atm/resources.c 2011-05-22 19:36:33.000000000 -0400
75647 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75648 static void copy_aal_stats(struct k_atm_aal_stats *from,
75649 struct atm_aal_stats *to)
75650 {
75651 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75652 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75653 __AAL_STAT_ITEMS
75654 #undef __HANDLE_ITEM
75655 }
75656 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_
75657 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75658 struct atm_aal_stats *to)
75659 {
75660 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75661 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75662 __AAL_STAT_ITEMS
75663 #undef __HANDLE_ITEM
75664 }
75665 diff -urNp linux-2.6.39.2/net/batman-adv/hard-interface.c linux-2.6.39.2/net/batman-adv/hard-interface.c
75666 --- linux-2.6.39.2/net/batman-adv/hard-interface.c 2011-05-19 00:06:34.000000000 -0400
75667 +++ linux-2.6.39.2/net/batman-adv/hard-interface.c 2011-05-22 19:36:33.000000000 -0400
75668 @@ -339,8 +339,8 @@ int hardif_enable_interface(struct hard_
75669 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75670 dev_add_pack(&hard_iface->batman_adv_ptype);
75671
75672 - atomic_set(&hard_iface->seqno, 1);
75673 - atomic_set(&hard_iface->frag_seqno, 1);
75674 + atomic_set_unchecked(&hard_iface->seqno, 1);
75675 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75676 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75677 hard_iface->net_dev->name);
75678
75679 diff -urNp linux-2.6.39.2/net/batman-adv/routing.c linux-2.6.39.2/net/batman-adv/routing.c
75680 --- linux-2.6.39.2/net/batman-adv/routing.c 2011-05-19 00:06:34.000000000 -0400
75681 +++ linux-2.6.39.2/net/batman-adv/routing.c 2011-05-22 19:36:33.000000000 -0400
75682 @@ -625,7 +625,7 @@ void receive_bat_packet(struct ethhdr *e
75683 return;
75684
75685 /* could be changed by schedule_own_packet() */
75686 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75687 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75688
75689 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
75690
75691 diff -urNp linux-2.6.39.2/net/batman-adv/send.c linux-2.6.39.2/net/batman-adv/send.c
75692 --- linux-2.6.39.2/net/batman-adv/send.c 2011-05-19 00:06:34.000000000 -0400
75693 +++ linux-2.6.39.2/net/batman-adv/send.c 2011-05-22 19:36:33.000000000 -0400
75694 @@ -277,7 +277,7 @@ void schedule_own_packet(struct hard_ifa
75695
75696 /* change sequence number to network order */
75697 batman_packet->seqno =
75698 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75699 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75700
75701 if (vis_server == VIS_TYPE_SERVER_SYNC)
75702 batman_packet->flags |= VIS_SERVER;
75703 @@ -291,7 +291,7 @@ void schedule_own_packet(struct hard_ifa
75704 else
75705 batman_packet->gw_flags = 0;
75706
75707 - atomic_inc(&hard_iface->seqno);
75708 + atomic_inc_unchecked(&hard_iface->seqno);
75709
75710 slide_own_bcast_window(hard_iface);
75711 send_time = own_send_time(bat_priv);
75712 diff -urNp linux-2.6.39.2/net/batman-adv/soft-interface.c linux-2.6.39.2/net/batman-adv/soft-interface.c
75713 --- linux-2.6.39.2/net/batman-adv/soft-interface.c 2011-05-19 00:06:34.000000000 -0400
75714 +++ linux-2.6.39.2/net/batman-adv/soft-interface.c 2011-05-22 19:36:33.000000000 -0400
75715 @@ -386,7 +386,7 @@ int interface_tx(struct sk_buff *skb, st
75716
75717 /* set broadcast sequence number */
75718 bcast_packet->seqno =
75719 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75720 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75721
75722 add_bcast_packet_to_list(bat_priv, skb);
75723
75724 @@ -579,7 +579,7 @@ struct net_device *softif_create(char *n
75725 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75726
75727 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75728 - atomic_set(&bat_priv->bcast_seqno, 1);
75729 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75730 atomic_set(&bat_priv->hna_local_changed, 0);
75731
75732 bat_priv->primary_if = NULL;
75733 diff -urNp linux-2.6.39.2/net/batman-adv/types.h linux-2.6.39.2/net/batman-adv/types.h
75734 --- linux-2.6.39.2/net/batman-adv/types.h 2011-05-19 00:06:34.000000000 -0400
75735 +++ linux-2.6.39.2/net/batman-adv/types.h 2011-05-22 19:36:33.000000000 -0400
75736 @@ -38,8 +38,8 @@ struct hard_iface {
75737 int16_t if_num;
75738 char if_status;
75739 struct net_device *net_dev;
75740 - atomic_t seqno;
75741 - atomic_t frag_seqno;
75742 + atomic_unchecked_t seqno;
75743 + atomic_unchecked_t frag_seqno;
75744 unsigned char *packet_buff;
75745 int packet_len;
75746 struct kobject *hardif_obj;
75747 @@ -141,7 +141,7 @@ struct bat_priv {
75748 atomic_t orig_interval; /* uint */
75749 atomic_t hop_penalty; /* uint */
75750 atomic_t log_level; /* uint */
75751 - atomic_t bcast_seqno;
75752 + atomic_unchecked_t bcast_seqno;
75753 atomic_t bcast_queue_left;
75754 atomic_t batman_queue_left;
75755 char num_ifaces;
75756 diff -urNp linux-2.6.39.2/net/batman-adv/unicast.c linux-2.6.39.2/net/batman-adv/unicast.c
75757 --- linux-2.6.39.2/net/batman-adv/unicast.c 2011-05-19 00:06:34.000000000 -0400
75758 +++ linux-2.6.39.2/net/batman-adv/unicast.c 2011-05-22 19:36:33.000000000 -0400
75759 @@ -263,7 +263,7 @@ int frag_send_skb(struct sk_buff *skb, s
75760 frag1->flags = UNI_FRAG_HEAD | large_tail;
75761 frag2->flags = large_tail;
75762
75763 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75764 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75765 frag1->seqno = htons(seqno - 1);
75766 frag2->seqno = htons(seqno);
75767
75768 diff -urNp linux-2.6.39.2/net/bluetooth/l2cap_core.c linux-2.6.39.2/net/bluetooth/l2cap_core.c
75769 --- linux-2.6.39.2/net/bluetooth/l2cap_core.c 2011-05-19 00:06:34.000000000 -0400
75770 +++ linux-2.6.39.2/net/bluetooth/l2cap_core.c 2011-06-25 14:32:21.000000000 -0400
75771 @@ -2202,7 +2202,7 @@ static inline int l2cap_config_req(struc
75772
75773 /* Reject if config buffer is too small. */
75774 len = cmd_len - sizeof(*req);
75775 - if (l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
75776 + if (len < 0 || l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
75777 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
75778 l2cap_build_conf_rsp(sk, rsp,
75779 L2CAP_CONF_REJECT, flags), rsp);
75780 diff -urNp linux-2.6.39.2/net/bluetooth/l2cap_sock.c linux-2.6.39.2/net/bluetooth/l2cap_sock.c
75781 --- linux-2.6.39.2/net/bluetooth/l2cap_sock.c 2011-05-19 00:06:34.000000000 -0400
75782 +++ linux-2.6.39.2/net/bluetooth/l2cap_sock.c 2011-06-12 06:36:08.000000000 -0400
75783 @@ -446,6 +446,7 @@ static int l2cap_sock_getsockopt_old(str
75784 break;
75785 }
75786
75787 + memset(&cinfo, 0, sizeof(cinfo));
75788 cinfo.hci_handle = l2cap_pi(sk)->conn->hcon->handle;
75789 memcpy(cinfo.dev_class, l2cap_pi(sk)->conn->hcon->dev_class, 3);
75790
75791 diff -urNp linux-2.6.39.2/net/bluetooth/rfcomm/sock.c linux-2.6.39.2/net/bluetooth/rfcomm/sock.c
75792 --- linux-2.6.39.2/net/bluetooth/rfcomm/sock.c 2011-05-19 00:06:34.000000000 -0400
75793 +++ linux-2.6.39.2/net/bluetooth/rfcomm/sock.c 2011-06-12 06:36:42.000000000 -0400
75794 @@ -787,6 +787,7 @@ static int rfcomm_sock_getsockopt_old(st
75795
75796 l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;
75797
75798 + memset(&cinfo, 0, sizeof(cinfo));
75799 cinfo.hci_handle = l2cap_pi(l2cap_sk)->conn->hcon->handle;
75800 memcpy(cinfo.dev_class, l2cap_pi(l2cap_sk)->conn->hcon->dev_class, 3);
75801
75802 diff -urNp linux-2.6.39.2/net/bridge/br_multicast.c linux-2.6.39.2/net/bridge/br_multicast.c
75803 --- linux-2.6.39.2/net/bridge/br_multicast.c 2011-05-19 00:06:34.000000000 -0400
75804 +++ linux-2.6.39.2/net/bridge/br_multicast.c 2011-05-22 19:36:33.000000000 -0400
75805 @@ -1482,7 +1482,7 @@ static int br_multicast_ipv6_rcv(struct
75806 nexthdr = ip6h->nexthdr;
75807 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
75808
75809 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
75810 + if (nexthdr != IPPROTO_ICMPV6)
75811 return 0;
75812
75813 /* Okay, we found ICMPv6 header */
75814 diff -urNp linux-2.6.39.2/net/bridge/netfilter/ebtables.c linux-2.6.39.2/net/bridge/netfilter/ebtables.c
75815 --- linux-2.6.39.2/net/bridge/netfilter/ebtables.c 2011-05-19 00:06:34.000000000 -0400
75816 +++ linux-2.6.39.2/net/bridge/netfilter/ebtables.c 2011-05-22 19:36:33.000000000 -0400
75817 @@ -1512,7 +1512,7 @@ static int do_ebt_get_ctl(struct sock *s
75818 tmp.valid_hooks = t->table->valid_hooks;
75819 }
75820 mutex_unlock(&ebt_mutex);
75821 - if (copy_to_user(user, &tmp, *len) != 0){
75822 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75823 BUGPRINT("c2u Didn't work\n");
75824 ret = -EFAULT;
75825 break;
75826 @@ -1780,6 +1780,8 @@ static int compat_copy_everything_to_use
75827 int ret;
75828 void __user *pos;
75829
75830 + pax_track_stack();
75831 +
75832 memset(&tinfo, 0, sizeof(tinfo));
75833
75834 if (cmd == EBT_SO_GET_ENTRIES) {
75835 diff -urNp linux-2.6.39.2/net/caif/caif_socket.c linux-2.6.39.2/net/caif/caif_socket.c
75836 --- linux-2.6.39.2/net/caif/caif_socket.c 2011-05-19 00:06:34.000000000 -0400
75837 +++ linux-2.6.39.2/net/caif/caif_socket.c 2011-05-22 19:36:33.000000000 -0400
75838 @@ -48,18 +48,19 @@ static struct dentry *debugfsdir;
75839 #ifdef CONFIG_DEBUG_FS
75840 struct debug_fs_counter {
75841 atomic_t caif_nr_socks;
75842 - atomic_t num_connect_req;
75843 - atomic_t num_connect_resp;
75844 - atomic_t num_connect_fail_resp;
75845 - atomic_t num_disconnect;
75846 - atomic_t num_remote_shutdown_ind;
75847 - atomic_t num_tx_flow_off_ind;
75848 - atomic_t num_tx_flow_on_ind;
75849 - atomic_t num_rx_flow_off;
75850 - atomic_t num_rx_flow_on;
75851 + atomic_unchecked_t num_connect_req;
75852 + atomic_unchecked_t num_connect_resp;
75853 + atomic_unchecked_t num_connect_fail_resp;
75854 + atomic_unchecked_t num_disconnect;
75855 + atomic_unchecked_t num_remote_shutdown_ind;
75856 + atomic_unchecked_t num_tx_flow_off_ind;
75857 + atomic_unchecked_t num_tx_flow_on_ind;
75858 + atomic_unchecked_t num_rx_flow_off;
75859 + atomic_unchecked_t num_rx_flow_on;
75860 };
75861 static struct debug_fs_counter cnt;
75862 #define dbfs_atomic_inc(v) atomic_inc(v)
75863 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_unchecked(v)
75864 #define dbfs_atomic_dec(v) atomic_dec(v)
75865 #else
75866 #define dbfs_atomic_inc(v)
75867 @@ -159,7 +160,7 @@ static int caif_queue_rcv_skb(struct soc
75868 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75869 sk_rcvbuf_lowwater(cf_sk));
75870 set_rx_flow_off(cf_sk);
75871 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75872 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75873 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75874 }
75875
75876 @@ -169,7 +170,7 @@ static int caif_queue_rcv_skb(struct soc
75877 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
75878 set_rx_flow_off(cf_sk);
75879 pr_debug("sending flow OFF due to rmem_schedule\n");
75880 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75881 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75882 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75883 }
75884 skb->dev = NULL;
75885 @@ -218,21 +219,21 @@ static void caif_ctrl_cb(struct cflayer
75886 switch (flow) {
75887 case CAIF_CTRLCMD_FLOW_ON_IND:
75888 /* OK from modem to start sending again */
75889 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75890 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75891 set_tx_flow_on(cf_sk);
75892 cf_sk->sk.sk_state_change(&cf_sk->sk);
75893 break;
75894
75895 case CAIF_CTRLCMD_FLOW_OFF_IND:
75896 /* Modem asks us to shut up */
75897 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75898 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75899 set_tx_flow_off(cf_sk);
75900 cf_sk->sk.sk_state_change(&cf_sk->sk);
75901 break;
75902
75903 case CAIF_CTRLCMD_INIT_RSP:
75904 /* We're now connected */
75905 - dbfs_atomic_inc(&cnt.num_connect_resp);
75906 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75907 cf_sk->sk.sk_state = CAIF_CONNECTED;
75908 set_tx_flow_on(cf_sk);
75909 cf_sk->sk.sk_state_change(&cf_sk->sk);
75910 @@ -247,7 +248,7 @@ static void caif_ctrl_cb(struct cflayer
75911
75912 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75913 /* Connect request failed */
75914 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75915 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75916 cf_sk->sk.sk_err = ECONNREFUSED;
75917 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75918 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75919 @@ -261,7 +262,7 @@ static void caif_ctrl_cb(struct cflayer
75920
75921 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75922 /* Modem has closed this connection, or device is down. */
75923 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75924 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75925 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75926 cf_sk->sk.sk_err = ECONNRESET;
75927 set_rx_flow_on(cf_sk);
75928 @@ -281,7 +282,7 @@ static void caif_check_flow_release(stru
75929 return;
75930
75931 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75932 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75933 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75934 set_rx_flow_on(cf_sk);
75935 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75936 }
75937 @@ -864,7 +865,7 @@ static int caif_connect(struct socket *s
75938 /*ifindex = id of the interface.*/
75939 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75940
75941 - dbfs_atomic_inc(&cnt.num_connect_req);
75942 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75943 cf_sk->layer.receive = caif_sktrecv_cb;
75944 err = caif_connect_client(&cf_sk->conn_req,
75945 &cf_sk->layer, &ifindex, &headroom, &tailroom);
75946 @@ -952,7 +953,7 @@ static int caif_release(struct socket *s
75947 spin_unlock(&sk->sk_receive_queue.lock);
75948 sock->sk = NULL;
75949
75950 - dbfs_atomic_inc(&cnt.num_disconnect);
75951 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75952
75953 if (cf_sk->debugfs_socket_dir != NULL)
75954 debugfs_remove_recursive(cf_sk->debugfs_socket_dir);
75955 diff -urNp linux-2.6.39.2/net/caif/cfctrl.c linux-2.6.39.2/net/caif/cfctrl.c
75956 --- linux-2.6.39.2/net/caif/cfctrl.c 2011-05-19 00:06:34.000000000 -0400
75957 +++ linux-2.6.39.2/net/caif/cfctrl.c 2011-05-22 19:36:33.000000000 -0400
75958 @@ -9,6 +9,7 @@
75959 #include <linux/stddef.h>
75960 #include <linux/spinlock.h>
75961 #include <linux/slab.h>
75962 +#include <linux/sched.h>
75963 #include <net/caif/caif_layer.h>
75964 #include <net/caif/cfpkt.h>
75965 #include <net/caif/cfctrl.h>
75966 @@ -46,8 +47,8 @@ struct cflayer *cfctrl_create(void)
75967 dev_info.id = 0xff;
75968 memset(this, 0, sizeof(*this));
75969 cfsrvl_init(&this->serv, 0, &dev_info, false);
75970 - atomic_set(&this->req_seq_no, 1);
75971 - atomic_set(&this->rsp_seq_no, 1);
75972 + atomic_set_unchecked(&this->req_seq_no, 1);
75973 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75974 this->serv.layer.receive = cfctrl_recv;
75975 sprintf(this->serv.layer.name, "ctrl");
75976 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75977 @@ -116,8 +117,8 @@ void cfctrl_insert_req(struct cfctrl *ct
75978 struct cfctrl_request_info *req)
75979 {
75980 spin_lock(&ctrl->info_list_lock);
75981 - atomic_inc(&ctrl->req_seq_no);
75982 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75983 + atomic_inc_unchecked(&ctrl->req_seq_no);
75984 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75985 list_add_tail(&req->list, &ctrl->list);
75986 spin_unlock(&ctrl->info_list_lock);
75987 }
75988 @@ -136,7 +137,7 @@ struct cfctrl_request_info *cfctrl_remov
75989 if (p != first)
75990 pr_warn("Requests are not received in order\n");
75991
75992 - atomic_set(&ctrl->rsp_seq_no,
75993 + atomic_set_unchecked(&ctrl->rsp_seq_no,
75994 p->sequence_no);
75995 list_del(&p->list);
75996 goto out;
75997 @@ -385,6 +386,7 @@ static int cfctrl_recv(struct cflayer *l
75998 struct cfctrl *cfctrl = container_obj(layer);
75999 struct cfctrl_request_info rsp, *req;
76000
76001 + pax_track_stack();
76002
76003 cfpkt_extr_head(pkt, &cmdrsp, 1);
76004 cmd = cmdrsp & CFCTRL_CMD_MASK;
76005 diff -urNp linux-2.6.39.2/net/can/bcm.c linux-2.6.39.2/net/can/bcm.c
76006 --- linux-2.6.39.2/net/can/bcm.c 2011-05-19 00:06:34.000000000 -0400
76007 +++ linux-2.6.39.2/net/can/bcm.c 2011-05-22 19:41:42.000000000 -0400
76008 @@ -165,9 +165,15 @@ static int bcm_proc_show(struct seq_file
76009 struct bcm_sock *bo = bcm_sk(sk);
76010 struct bcm_op *op;
76011
76012 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76013 + seq_printf(m, ">>> socket %p", NULL);
76014 + seq_printf(m, " / sk %p", NULL);
76015 + seq_printf(m, " / bo %p", NULL);
76016 +#else
76017 seq_printf(m, ">>> socket %p", sk->sk_socket);
76018 seq_printf(m, " / sk %p", sk);
76019 seq_printf(m, " / bo %p", bo);
76020 +#endif
76021 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
76022 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
76023 seq_printf(m, " <<<\n");
76024 diff -urNp linux-2.6.39.2/net/core/datagram.c linux-2.6.39.2/net/core/datagram.c
76025 --- linux-2.6.39.2/net/core/datagram.c 2011-05-19 00:06:34.000000000 -0400
76026 +++ linux-2.6.39.2/net/core/datagram.c 2011-05-22 19:36:33.000000000 -0400
76027 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, s
76028 }
76029
76030 kfree_skb(skb);
76031 - atomic_inc(&sk->sk_drops);
76032 + atomic_inc_unchecked(&sk->sk_drops);
76033 sk_mem_reclaim_partial(sk);
76034
76035 return err;
76036 diff -urNp linux-2.6.39.2/net/core/dev.c linux-2.6.39.2/net/core/dev.c
76037 --- linux-2.6.39.2/net/core/dev.c 2011-06-03 00:04:14.000000000 -0400
76038 +++ linux-2.6.39.2/net/core/dev.c 2011-06-03 00:32:08.000000000 -0400
76039 @@ -1125,10 +1125,14 @@ void dev_load(struct net *net, const cha
76040 if (no_module && capable(CAP_NET_ADMIN))
76041 no_module = request_module("netdev-%s", name);
76042 if (no_module && capable(CAP_SYS_MODULE)) {
76043 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76044 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76045 +#else
76046 if (!request_module("%s", name))
76047 pr_err("Loading kernel module for a network device "
76048 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
76049 "instead\n", name);
76050 +#endif
76051 }
76052 }
76053 EXPORT_SYMBOL(dev_load);
76054 @@ -1957,7 +1961,7 @@ struct dev_gso_cb {
76055
76056 static void dev_gso_skb_destructor(struct sk_buff *skb)
76057 {
76058 - struct dev_gso_cb *cb;
76059 + const struct dev_gso_cb *cb;
76060
76061 do {
76062 struct sk_buff *nskb = skb->next;
76063 @@ -2901,7 +2905,7 @@ int netif_rx_ni(struct sk_buff *skb)
76064 }
76065 EXPORT_SYMBOL(netif_rx_ni);
76066
76067 -static void net_tx_action(struct softirq_action *h)
76068 +static void net_tx_action(void)
76069 {
76070 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76071
76072 @@ -3765,7 +3769,7 @@ void netif_napi_del(struct napi_struct *
76073 }
76074 EXPORT_SYMBOL(netif_napi_del);
76075
76076 -static void net_rx_action(struct softirq_action *h)
76077 +static void net_rx_action(void)
76078 {
76079 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76080 unsigned long time_limit = jiffies + 2;
76081 diff -urNp linux-2.6.39.2/net/core/flow.c linux-2.6.39.2/net/core/flow.c
76082 --- linux-2.6.39.2/net/core/flow.c 2011-05-19 00:06:34.000000000 -0400
76083 +++ linux-2.6.39.2/net/core/flow.c 2011-05-22 19:36:34.000000000 -0400
76084 @@ -60,7 +60,7 @@ struct flow_cache {
76085 struct timer_list rnd_timer;
76086 };
76087
76088 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76089 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76090 EXPORT_SYMBOL(flow_cache_genid);
76091 static struct flow_cache flow_cache_global;
76092 static struct kmem_cache *flow_cachep __read_mostly;
76093 @@ -85,7 +85,7 @@ static void flow_cache_new_hashrnd(unsig
76094
76095 static int flow_entry_valid(struct flow_cache_entry *fle)
76096 {
76097 - if (atomic_read(&flow_cache_genid) != fle->genid)
76098 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76099 return 0;
76100 if (fle->object && !fle->object->ops->check(fle->object))
76101 return 0;
76102 @@ -253,7 +253,7 @@ flow_cache_lookup(struct net *net, const
76103 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76104 fcp->hash_count++;
76105 }
76106 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76107 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76108 flo = fle->object;
76109 if (!flo)
76110 goto ret_object;
76111 @@ -274,7 +274,7 @@ nocache:
76112 }
76113 flo = resolver(net, key, family, dir, flo, ctx);
76114 if (fle) {
76115 - fle->genid = atomic_read(&flow_cache_genid);
76116 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76117 if (!IS_ERR(flo))
76118 fle->object = flo;
76119 else
76120 diff -urNp linux-2.6.39.2/net/core/skbuff.c linux-2.6.39.2/net/core/skbuff.c
76121 --- linux-2.6.39.2/net/core/skbuff.c 2011-06-03 00:04:14.000000000 -0400
76122 +++ linux-2.6.39.2/net/core/skbuff.c 2011-06-03 00:32:08.000000000 -0400
76123 @@ -1542,6 +1542,8 @@ int skb_splice_bits(struct sk_buff *skb,
76124 struct sock *sk = skb->sk;
76125 int ret = 0;
76126
76127 + pax_track_stack();
76128 +
76129 if (splice_grow_spd(pipe, &spd))
76130 return -ENOMEM;
76131
76132 diff -urNp linux-2.6.39.2/net/core/sock.c linux-2.6.39.2/net/core/sock.c
76133 --- linux-2.6.39.2/net/core/sock.c 2011-05-19 00:06:34.000000000 -0400
76134 +++ linux-2.6.39.2/net/core/sock.c 2011-05-22 19:36:34.000000000 -0400
76135 @@ -291,7 +291,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76136 */
76137 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
76138 (unsigned)sk->sk_rcvbuf) {
76139 - atomic_inc(&sk->sk_drops);
76140 + atomic_inc_unchecked(&sk->sk_drops);
76141 return -ENOMEM;
76142 }
76143
76144 @@ -300,7 +300,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76145 return err;
76146
76147 if (!sk_rmem_schedule(sk, skb->truesize)) {
76148 - atomic_inc(&sk->sk_drops);
76149 + atomic_inc_unchecked(&sk->sk_drops);
76150 return -ENOBUFS;
76151 }
76152
76153 @@ -320,7 +320,7 @@ int sock_queue_rcv_skb(struct sock *sk,
76154 skb_dst_force(skb);
76155
76156 spin_lock_irqsave(&list->lock, flags);
76157 - skb->dropcount = atomic_read(&sk->sk_drops);
76158 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76159 __skb_queue_tail(list, skb);
76160 spin_unlock_irqrestore(&list->lock, flags);
76161
76162 @@ -340,7 +340,7 @@ int sk_receive_skb(struct sock *sk, stru
76163 skb->dev = NULL;
76164
76165 if (sk_rcvqueues_full(sk, skb)) {
76166 - atomic_inc(&sk->sk_drops);
76167 + atomic_inc_unchecked(&sk->sk_drops);
76168 goto discard_and_relse;
76169 }
76170 if (nested)
76171 @@ -358,7 +358,7 @@ int sk_receive_skb(struct sock *sk, stru
76172 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76173 } else if (sk_add_backlog(sk, skb)) {
76174 bh_unlock_sock(sk);
76175 - atomic_inc(&sk->sk_drops);
76176 + atomic_inc_unchecked(&sk->sk_drops);
76177 goto discard_and_relse;
76178 }
76179
76180 @@ -934,7 +934,7 @@ int sock_getsockopt(struct socket *sock,
76181 return -ENOTCONN;
76182 if (lv < len)
76183 return -EINVAL;
76184 - if (copy_to_user(optval, address, len))
76185 + if (len > sizeof(address) || copy_to_user(optval, address, len))
76186 return -EFAULT;
76187 goto lenout;
76188 }
76189 @@ -967,7 +967,7 @@ int sock_getsockopt(struct socket *sock,
76190
76191 if (len > lv)
76192 len = lv;
76193 - if (copy_to_user(optval, &v, len))
76194 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76195 return -EFAULT;
76196 lenout:
76197 if (put_user(len, optlen))
76198 @@ -2023,7 +2023,7 @@ void sock_init_data(struct socket *sock,
76199 */
76200 smp_wmb();
76201 atomic_set(&sk->sk_refcnt, 1);
76202 - atomic_set(&sk->sk_drops, 0);
76203 + atomic_set_unchecked(&sk->sk_drops, 0);
76204 }
76205 EXPORT_SYMBOL(sock_init_data);
76206
76207 diff -urNp linux-2.6.39.2/net/decnet/sysctl_net_decnet.c linux-2.6.39.2/net/decnet/sysctl_net_decnet.c
76208 --- linux-2.6.39.2/net/decnet/sysctl_net_decnet.c 2011-05-19 00:06:34.000000000 -0400
76209 +++ linux-2.6.39.2/net/decnet/sysctl_net_decnet.c 2011-05-22 19:36:34.000000000 -0400
76210 @@ -173,7 +173,7 @@ static int dn_node_address_handler(ctl_t
76211
76212 if (len > *lenp) len = *lenp;
76213
76214 - if (copy_to_user(buffer, addr, len))
76215 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76216 return -EFAULT;
76217
76218 *lenp = len;
76219 @@ -236,7 +236,7 @@ static int dn_def_dev_handler(ctl_table
76220
76221 if (len > *lenp) len = *lenp;
76222
76223 - if (copy_to_user(buffer, devname, len))
76224 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76225 return -EFAULT;
76226
76227 *lenp = len;
76228 diff -urNp linux-2.6.39.2/net/econet/Kconfig linux-2.6.39.2/net/econet/Kconfig
76229 --- linux-2.6.39.2/net/econet/Kconfig 2011-05-19 00:06:34.000000000 -0400
76230 +++ linux-2.6.39.2/net/econet/Kconfig 2011-05-22 19:41:42.000000000 -0400
76231 @@ -4,7 +4,7 @@
76232
76233 config ECONET
76234 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
76235 - depends on EXPERIMENTAL && INET
76236 + depends on EXPERIMENTAL && INET && BROKEN
76237 ---help---
76238 Econet is a fairly old and slow networking protocol mainly used by
76239 Acorn computers to access file and print servers. It uses native
76240 diff -urNp linux-2.6.39.2/net/ipv4/fib_frontend.c linux-2.6.39.2/net/ipv4/fib_frontend.c
76241 --- linux-2.6.39.2/net/ipv4/fib_frontend.c 2011-05-19 00:06:34.000000000 -0400
76242 +++ linux-2.6.39.2/net/ipv4/fib_frontend.c 2011-05-22 19:36:34.000000000 -0400
76243 @@ -968,12 +968,12 @@ static int fib_inetaddr_event(struct not
76244 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76245 fib_sync_up(dev);
76246 #endif
76247 - atomic_inc(&net->ipv4.dev_addr_genid);
76248 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76249 rt_cache_flush(dev_net(dev), -1);
76250 break;
76251 case NETDEV_DOWN:
76252 fib_del_ifaddr(ifa, NULL);
76253 - atomic_inc(&net->ipv4.dev_addr_genid);
76254 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76255 if (ifa->ifa_dev->ifa_list == NULL) {
76256 /* Last address was deleted from this interface.
76257 * Disable IP.
76258 @@ -1009,7 +1009,7 @@ static int fib_netdev_event(struct notif
76259 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76260 fib_sync_up(dev);
76261 #endif
76262 - atomic_inc(&net->ipv4.dev_addr_genid);
76263 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76264 rt_cache_flush(dev_net(dev), -1);
76265 break;
76266 case NETDEV_DOWN:
76267 diff -urNp linux-2.6.39.2/net/ipv4/fib_semantics.c linux-2.6.39.2/net/ipv4/fib_semantics.c
76268 --- linux-2.6.39.2/net/ipv4/fib_semantics.c 2011-05-19 00:06:34.000000000 -0400
76269 +++ linux-2.6.39.2/net/ipv4/fib_semantics.c 2011-05-22 19:36:34.000000000 -0400
76270 @@ -701,7 +701,7 @@ __be32 fib_info_update_nh_saddr(struct n
76271 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76272 nh->nh_gw,
76273 nh->nh_parent->fib_scope);
76274 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76275 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76276
76277 return nh->nh_saddr;
76278 }
76279 diff -urNp linux-2.6.39.2/net/ipv4/inet_diag.c linux-2.6.39.2/net/ipv4/inet_diag.c
76280 --- linux-2.6.39.2/net/ipv4/inet_diag.c 2011-05-19 00:06:34.000000000 -0400
76281 +++ linux-2.6.39.2/net/ipv4/inet_diag.c 2011-06-20 19:27:58.000000000 -0400
76282 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct soc
76283 r->idiag_retrans = 0;
76284
76285 r->id.idiag_if = sk->sk_bound_dev_if;
76286 +
76287 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76288 + r->id.idiag_cookie[0] = 0;
76289 + r->id.idiag_cookie[1] = 0;
76290 +#else
76291 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
76292 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76293 +#endif
76294
76295 r->id.idiag_sport = inet->inet_sport;
76296 r->id.idiag_dport = inet->inet_dport;
76297 @@ -201,8 +207,15 @@ static int inet_twsk_diag_fill(struct in
76298 r->idiag_family = tw->tw_family;
76299 r->idiag_retrans = 0;
76300 r->id.idiag_if = tw->tw_bound_dev_if;
76301 +
76302 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76303 + r->id.idiag_cookie[0] = 0;
76304 + r->id.idiag_cookie[1] = 0;
76305 +#else
76306 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
76307 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
76308 +#endif
76309 +
76310 r->id.idiag_sport = tw->tw_sport;
76311 r->id.idiag_dport = tw->tw_dport;
76312 r->id.idiag_src[0] = tw->tw_rcv_saddr;
76313 @@ -285,12 +298,14 @@ static int inet_diag_get_exact(struct sk
76314 if (sk == NULL)
76315 goto unlock;
76316
76317 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76318 err = -ESTALE;
76319 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
76320 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
76321 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
76322 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
76323 goto out;
76324 +#endif
76325
76326 err = -ENOMEM;
76327 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
76328 @@ -437,7 +452,7 @@ static int valid_cc(const void *bc, int
76329 return 0;
76330 if (cc == len)
76331 return 1;
76332 - if (op->yes < 4)
76333 + if (op->yes < 4 || op->yes & 3)
76334 return 0;
76335 len -= op->yes;
76336 bc += op->yes;
76337 @@ -447,11 +462,11 @@ static int valid_cc(const void *bc, int
76338
76339 static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
76340 {
76341 - const unsigned char *bc = bytecode;
76342 + const void *bc = bytecode;
76343 int len = bytecode_len;
76344
76345 while (len > 0) {
76346 - struct inet_diag_bc_op *op = (struct inet_diag_bc_op *)bc;
76347 + const struct inet_diag_bc_op *op = bc;
76348
76349 //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len);
76350 switch (op->code) {
76351 @@ -462,22 +477,20 @@ static int inet_diag_bc_audit(const void
76352 case INET_DIAG_BC_S_LE:
76353 case INET_DIAG_BC_D_GE:
76354 case INET_DIAG_BC_D_LE:
76355 - if (op->yes < 4 || op->yes > len + 4)
76356 - return -EINVAL;
76357 case INET_DIAG_BC_JMP:
76358 - if (op->no < 4 || op->no > len + 4)
76359 + if (op->no < 4 || op->no > len + 4 || op->no & 3)
76360 return -EINVAL;
76361 if (op->no < len &&
76362 !valid_cc(bytecode, bytecode_len, len - op->no))
76363 return -EINVAL;
76364 break;
76365 case INET_DIAG_BC_NOP:
76366 - if (op->yes < 4 || op->yes > len + 4)
76367 - return -EINVAL;
76368 break;
76369 default:
76370 return -EINVAL;
76371 }
76372 + if (op->yes < 4 || op->yes > len + 4 || op->yes & 3)
76373 + return -EINVAL;
76374 bc += op->yes;
76375 len -= op->yes;
76376 }
76377 @@ -582,8 +595,14 @@ static int inet_diag_fill_req(struct sk_
76378 r->idiag_retrans = req->retrans;
76379
76380 r->id.idiag_if = sk->sk_bound_dev_if;
76381 +
76382 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76383 + r->id.idiag_cookie[0] = 0;
76384 + r->id.idiag_cookie[1] = 0;
76385 +#else
76386 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
76387 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
76388 +#endif
76389
76390 tmo = req->expires - jiffies;
76391 if (tmo < 0)
76392 diff -urNp linux-2.6.39.2/net/ipv4/inet_hashtables.c linux-2.6.39.2/net/ipv4/inet_hashtables.c
76393 --- linux-2.6.39.2/net/ipv4/inet_hashtables.c 2011-05-19 00:06:34.000000000 -0400
76394 +++ linux-2.6.39.2/net/ipv4/inet_hashtables.c 2011-05-22 19:41:42.000000000 -0400
76395 @@ -18,11 +18,14 @@
76396 #include <linux/sched.h>
76397 #include <linux/slab.h>
76398 #include <linux/wait.h>
76399 +#include <linux/security.h>
76400
76401 #include <net/inet_connection_sock.h>
76402 #include <net/inet_hashtables.h>
76403 #include <net/ip.h>
76404
76405 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76406 +
76407 /*
76408 * Allocate and initialize a new local port bind bucket.
76409 * The bindhash mutex for snum's hash chain must be held here.
76410 @@ -529,6 +532,8 @@ ok:
76411 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76412 spin_unlock(&head->lock);
76413
76414 + gr_update_task_in_ip_table(current, inet_sk(sk));
76415 +
76416 if (tw) {
76417 inet_twsk_deschedule(tw, death_row);
76418 while (twrefcnt) {
76419 diff -urNp linux-2.6.39.2/net/ipv4/inetpeer.c linux-2.6.39.2/net/ipv4/inetpeer.c
76420 --- linux-2.6.39.2/net/ipv4/inetpeer.c 2011-05-19 00:06:34.000000000 -0400
76421 +++ linux-2.6.39.2/net/ipv4/inetpeer.c 2011-05-22 19:36:34.000000000 -0400
76422 @@ -467,6 +467,8 @@ struct inet_peer *inet_getpeer(struct in
76423 unsigned int sequence;
76424 int invalidated;
76425
76426 + pax_track_stack();
76427 +
76428 /* Look up for the address quickly, lockless.
76429 * Because of a concurrent writer, we might not find an existing entry.
76430 */
76431 @@ -504,8 +506,8 @@ struct inet_peer *inet_getpeer(struct in
76432 if (p) {
76433 p->daddr = *daddr;
76434 atomic_set(&p->refcnt, 1);
76435 - atomic_set(&p->rid, 0);
76436 - atomic_set(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76437 + atomic_set_unchecked(&p->rid, 0);
76438 + atomic_set_unchecked(&p->ip_id_count, secure_ip_id(daddr->addr.a4));
76439 p->tcp_ts_stamp = 0;
76440 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
76441 p->rate_tokens = 0;
76442 diff -urNp linux-2.6.39.2/net/ipv4/ip_fragment.c linux-2.6.39.2/net/ipv4/ip_fragment.c
76443 --- linux-2.6.39.2/net/ipv4/ip_fragment.c 2011-05-19 00:06:34.000000000 -0400
76444 +++ linux-2.6.39.2/net/ipv4/ip_fragment.c 2011-05-22 19:36:34.000000000 -0400
76445 @@ -297,7 +297,7 @@ static inline int ip_frag_too_far(struct
76446 return 0;
76447
76448 start = qp->rid;
76449 - end = atomic_inc_return(&peer->rid);
76450 + end = atomic_inc_return_unchecked(&peer->rid);
76451 qp->rid = end;
76452
76453 rc = qp->q.fragments && (end - start) > max;
76454 diff -urNp linux-2.6.39.2/net/ipv4/ip_sockglue.c linux-2.6.39.2/net/ipv4/ip_sockglue.c
76455 --- linux-2.6.39.2/net/ipv4/ip_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76456 +++ linux-2.6.39.2/net/ipv4/ip_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76457 @@ -1064,6 +1064,8 @@ static int do_ip_getsockopt(struct sock
76458 int val;
76459 int len;
76460
76461 + pax_track_stack();
76462 +
76463 if (level != SOL_IP)
76464 return -EOPNOTSUPP;
76465
76466 diff -urNp linux-2.6.39.2/net/ipv4/netfilter/nf_nat_snmp_basic.c linux-2.6.39.2/net/ipv4/netfilter/nf_nat_snmp_basic.c
76467 --- linux-2.6.39.2/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-19 00:06:34.000000000 -0400
76468 +++ linux-2.6.39.2/net/ipv4/netfilter/nf_nat_snmp_basic.c 2011-05-22 19:36:34.000000000 -0400
76469 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(
76470
76471 *len = 0;
76472
76473 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
76474 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
76475 if (*octets == NULL) {
76476 if (net_ratelimit())
76477 pr_notice("OOM in bsalg (%d)\n", __LINE__);
76478 diff -urNp linux-2.6.39.2/net/ipv4/raw.c linux-2.6.39.2/net/ipv4/raw.c
76479 --- linux-2.6.39.2/net/ipv4/raw.c 2011-05-19 00:06:34.000000000 -0400
76480 +++ linux-2.6.39.2/net/ipv4/raw.c 2011-05-22 19:41:42.000000000 -0400
76481 @@ -302,7 +302,7 @@ static int raw_rcv_skb(struct sock * sk,
76482 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76483 {
76484 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76485 - atomic_inc(&sk->sk_drops);
76486 + atomic_inc_unchecked(&sk->sk_drops);
76487 kfree_skb(skb);
76488 return NET_RX_DROP;
76489 }
76490 @@ -730,15 +730,19 @@ static int raw_init(struct sock *sk)
76491
76492 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76493 {
76494 + struct icmp_filter filter;
76495 +
76496 if (optlen > sizeof(struct icmp_filter))
76497 optlen = sizeof(struct icmp_filter);
76498 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76499 + if (copy_from_user(&filter, optval, optlen))
76500 return -EFAULT;
76501 + memcpy(&raw_sk(sk)->filter, &filter, sizeof(filter));
76502 return 0;
76503 }
76504
76505 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76506 {
76507 + struct icmp_filter filter;
76508 int len, ret = -EFAULT;
76509
76510 if (get_user(len, optlen))
76511 @@ -749,8 +753,9 @@ static int raw_geticmpfilter(struct sock
76512 if (len > sizeof(struct icmp_filter))
76513 len = sizeof(struct icmp_filter);
76514 ret = -EFAULT;
76515 + memcpy(&filter, &raw_sk(sk)->filter, len);
76516 if (put_user(len, optlen) ||
76517 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76518 + copy_to_user(optval, &filter, len))
76519 goto out;
76520 ret = 0;
76521 out: return ret;
76522 @@ -978,7 +983,13 @@ static void raw_sock_seq_show(struct seq
76523 sk_wmem_alloc_get(sp),
76524 sk_rmem_alloc_get(sp),
76525 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76526 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76527 + atomic_read(&sp->sk_refcnt),
76528 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76529 + NULL,
76530 +#else
76531 + sp,
76532 +#endif
76533 + atomic_read_unchecked(&sp->sk_drops));
76534 }
76535
76536 static int raw_seq_show(struct seq_file *seq, void *v)
76537 diff -urNp linux-2.6.39.2/net/ipv4/route.c linux-2.6.39.2/net/ipv4/route.c
76538 --- linux-2.6.39.2/net/ipv4/route.c 2011-05-19 00:06:34.000000000 -0400
76539 +++ linux-2.6.39.2/net/ipv4/route.c 2011-05-22 19:36:34.000000000 -0400
76540 @@ -303,7 +303,7 @@ static inline unsigned int rt_hash(__be3
76541
76542 static inline int rt_genid(struct net *net)
76543 {
76544 - return atomic_read(&net->ipv4.rt_genid);
76545 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76546 }
76547
76548 #ifdef CONFIG_PROC_FS
76549 @@ -831,7 +831,7 @@ static void rt_cache_invalidate(struct n
76550 unsigned char shuffle;
76551
76552 get_random_bytes(&shuffle, sizeof(shuffle));
76553 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76554 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76555 }
76556
76557 /*
76558 @@ -2835,7 +2835,7 @@ static int rt_fill_info(struct net *net,
76559 rt->peer->pmtu_expires - jiffies : 0;
76560 if (rt->peer) {
76561 inet_peer_refcheck(rt->peer);
76562 - id = atomic_read(&rt->peer->ip_id_count) & 0xffff;
76563 + id = atomic_read_unchecked(&rt->peer->ip_id_count) & 0xffff;
76564 if (rt->peer->tcp_ts_stamp) {
76565 ts = rt->peer->tcp_ts;
76566 tsage = get_seconds() - rt->peer->tcp_ts_stamp;
76567 diff -urNp linux-2.6.39.2/net/ipv4/tcp.c linux-2.6.39.2/net/ipv4/tcp.c
76568 --- linux-2.6.39.2/net/ipv4/tcp.c 2011-05-19 00:06:34.000000000 -0400
76569 +++ linux-2.6.39.2/net/ipv4/tcp.c 2011-05-22 19:36:34.000000000 -0400
76570 @@ -2121,6 +2121,8 @@ static int do_tcp_setsockopt(struct sock
76571 int val;
76572 int err = 0;
76573
76574 + pax_track_stack();
76575 +
76576 /* These are data/string values, all the others are ints */
76577 switch (optname) {
76578 case TCP_CONGESTION: {
76579 @@ -2500,6 +2502,8 @@ static int do_tcp_getsockopt(struct sock
76580 struct tcp_sock *tp = tcp_sk(sk);
76581 int val, len;
76582
76583 + pax_track_stack();
76584 +
76585 if (get_user(len, optlen))
76586 return -EFAULT;
76587
76588 diff -urNp linux-2.6.39.2/net/ipv4/tcp_ipv4.c linux-2.6.39.2/net/ipv4/tcp_ipv4.c
76589 --- linux-2.6.39.2/net/ipv4/tcp_ipv4.c 2011-05-19 00:06:34.000000000 -0400
76590 +++ linux-2.6.39.2/net/ipv4/tcp_ipv4.c 2011-05-22 19:41:42.000000000 -0400
76591 @@ -86,6 +86,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76592 int sysctl_tcp_low_latency __read_mostly;
76593 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76594
76595 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76596 +extern int grsec_enable_blackhole;
76597 +#endif
76598
76599 #ifdef CONFIG_TCP_MD5SIG
76600 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76601 @@ -1594,6 +1597,9 @@ int tcp_v4_do_rcv(struct sock *sk, struc
76602 return 0;
76603
76604 reset:
76605 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76606 + if (!grsec_enable_blackhole)
76607 +#endif
76608 tcp_v4_send_reset(rsk, skb);
76609 discard:
76610 kfree_skb(skb);
76611 @@ -1656,12 +1662,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76612 TCP_SKB_CB(skb)->sacked = 0;
76613
76614 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76615 - if (!sk)
76616 + if (!sk) {
76617 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76618 + ret = 1;
76619 +#endif
76620 goto no_tcp_socket;
76621 -
76622 + }
76623 process:
76624 - if (sk->sk_state == TCP_TIME_WAIT)
76625 + if (sk->sk_state == TCP_TIME_WAIT) {
76626 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76627 + ret = 2;
76628 +#endif
76629 goto do_time_wait;
76630 + }
76631
76632 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76633 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76634 @@ -1711,6 +1724,10 @@ no_tcp_socket:
76635 bad_packet:
76636 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76637 } else {
76638 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76639 + if (!grsec_enable_blackhole || (ret == 1 &&
76640 + (skb->dev->flags & IFF_LOOPBACK)))
76641 +#endif
76642 tcp_v4_send_reset(NULL, skb);
76643 }
76644
76645 @@ -2374,7 +2391,11 @@ static void get_openreq4(struct sock *sk
76646 0, /* non standard timer */
76647 0, /* open_requests have no inode */
76648 atomic_read(&sk->sk_refcnt),
76649 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76650 + NULL,
76651 +#else
76652 req,
76653 +#endif
76654 len);
76655 }
76656
76657 @@ -2424,7 +2445,12 @@ static void get_tcp4_sock(struct sock *s
76658 sock_i_uid(sk),
76659 icsk->icsk_probes_out,
76660 sock_i_ino(sk),
76661 - atomic_read(&sk->sk_refcnt), sk,
76662 + atomic_read(&sk->sk_refcnt),
76663 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76664 + NULL,
76665 +#else
76666 + sk,
76667 +#endif
76668 jiffies_to_clock_t(icsk->icsk_rto),
76669 jiffies_to_clock_t(icsk->icsk_ack.ato),
76670 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76671 @@ -2452,7 +2478,13 @@ static void get_timewait4_sock(struct in
76672 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
76673 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76674 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76675 - atomic_read(&tw->tw_refcnt), tw, len);
76676 + atomic_read(&tw->tw_refcnt),
76677 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76678 + NULL,
76679 +#else
76680 + tw,
76681 +#endif
76682 + len);
76683 }
76684
76685 #define TMPSZ 150
76686 diff -urNp linux-2.6.39.2/net/ipv4/tcp_minisocks.c linux-2.6.39.2/net/ipv4/tcp_minisocks.c
76687 --- linux-2.6.39.2/net/ipv4/tcp_minisocks.c 2011-05-19 00:06:34.000000000 -0400
76688 +++ linux-2.6.39.2/net/ipv4/tcp_minisocks.c 2011-05-22 19:41:42.000000000 -0400
76689 @@ -27,6 +27,10 @@
76690 #include <net/inet_common.h>
76691 #include <net/xfrm.h>
76692
76693 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76694 +extern int grsec_enable_blackhole;
76695 +#endif
76696 +
76697 int sysctl_tcp_syncookies __read_mostly = 1;
76698 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76699
76700 @@ -745,6 +749,10 @@ listen_overflow:
76701
76702 embryonic_reset:
76703 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76704 +
76705 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76706 + if (!grsec_enable_blackhole)
76707 +#endif
76708 if (!(flg & TCP_FLAG_RST))
76709 req->rsk_ops->send_reset(sk, skb);
76710
76711 diff -urNp linux-2.6.39.2/net/ipv4/tcp_output.c linux-2.6.39.2/net/ipv4/tcp_output.c
76712 --- linux-2.6.39.2/net/ipv4/tcp_output.c 2011-05-19 00:06:34.000000000 -0400
76713 +++ linux-2.6.39.2/net/ipv4/tcp_output.c 2011-05-22 19:36:34.000000000 -0400
76714 @@ -2421,6 +2421,8 @@ struct sk_buff *tcp_make_synack(struct s
76715 int mss;
76716 int s_data_desired = 0;
76717
76718 + pax_track_stack();
76719 +
76720 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
76721 s_data_desired = cvp->s_data_desired;
76722 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
76723 diff -urNp linux-2.6.39.2/net/ipv4/tcp_probe.c linux-2.6.39.2/net/ipv4/tcp_probe.c
76724 --- linux-2.6.39.2/net/ipv4/tcp_probe.c 2011-05-19 00:06:34.000000000 -0400
76725 +++ linux-2.6.39.2/net/ipv4/tcp_probe.c 2011-05-22 19:36:34.000000000 -0400
76726 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file
76727 if (cnt + width >= len)
76728 break;
76729
76730 - if (copy_to_user(buf + cnt, tbuf, width))
76731 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76732 return -EFAULT;
76733 cnt += width;
76734 }
76735 diff -urNp linux-2.6.39.2/net/ipv4/tcp_timer.c linux-2.6.39.2/net/ipv4/tcp_timer.c
76736 --- linux-2.6.39.2/net/ipv4/tcp_timer.c 2011-05-19 00:06:34.000000000 -0400
76737 +++ linux-2.6.39.2/net/ipv4/tcp_timer.c 2011-05-22 19:41:42.000000000 -0400
76738 @@ -22,6 +22,10 @@
76739 #include <linux/gfp.h>
76740 #include <net/tcp.h>
76741
76742 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76743 +extern int grsec_lastack_retries;
76744 +#endif
76745 +
76746 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76747 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76748 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76749 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock
76750 }
76751 }
76752
76753 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76754 + if ((sk->sk_state == TCP_LAST_ACK) &&
76755 + (grsec_lastack_retries > 0) &&
76756 + (grsec_lastack_retries < retry_until))
76757 + retry_until = grsec_lastack_retries;
76758 +#endif
76759 +
76760 if (retransmits_timed_out(sk, retry_until,
76761 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76762 /* Has it gone just too far? */
76763 diff -urNp linux-2.6.39.2/net/ipv4/udp.c linux-2.6.39.2/net/ipv4/udp.c
76764 --- linux-2.6.39.2/net/ipv4/udp.c 2011-05-19 00:06:34.000000000 -0400
76765 +++ linux-2.6.39.2/net/ipv4/udp.c 2011-05-22 19:41:42.000000000 -0400
76766 @@ -86,6 +86,7 @@
76767 #include <linux/types.h>
76768 #include <linux/fcntl.h>
76769 #include <linux/module.h>
76770 +#include <linux/security.h>
76771 #include <linux/socket.h>
76772 #include <linux/sockios.h>
76773 #include <linux/igmp.h>
76774 @@ -107,6 +108,10 @@
76775 #include <net/xfrm.h>
76776 #include "udp_impl.h"
76777
76778 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76779 +extern int grsec_enable_blackhole;
76780 +#endif
76781 +
76782 struct udp_table udp_table __read_mostly;
76783 EXPORT_SYMBOL(udp_table);
76784
76785 @@ -564,6 +569,9 @@ found:
76786 return s;
76787 }
76788
76789 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76790 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76791 +
76792 /*
76793 * This routine is called by the ICMP module when it gets some
76794 * sort of error condition. If err < 0 then the socket should
76795 @@ -853,9 +861,18 @@ int udp_sendmsg(struct kiocb *iocb, stru
76796 dport = usin->sin_port;
76797 if (dport == 0)
76798 return -EINVAL;
76799 +
76800 + err = gr_search_udp_sendmsg(sk, usin);
76801 + if (err)
76802 + return err;
76803 } else {
76804 if (sk->sk_state != TCP_ESTABLISHED)
76805 return -EDESTADDRREQ;
76806 +
76807 + err = gr_search_udp_sendmsg(sk, NULL);
76808 + if (err)
76809 + return err;
76810 +
76811 daddr = inet->inet_daddr;
76812 dport = inet->inet_dport;
76813 /* Open fast path for connected socket.
76814 @@ -1090,7 +1107,7 @@ static unsigned int first_packet_length(
76815 udp_lib_checksum_complete(skb)) {
76816 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76817 IS_UDPLITE(sk));
76818 - atomic_inc(&sk->sk_drops);
76819 + atomic_inc_unchecked(&sk->sk_drops);
76820 __skb_unlink(skb, rcvq);
76821 __skb_queue_tail(&list_kill, skb);
76822 }
76823 @@ -1176,6 +1193,10 @@ try_again:
76824 if (!skb)
76825 goto out;
76826
76827 + err = gr_search_udp_recvmsg(sk, skb);
76828 + if (err)
76829 + goto out_free;
76830 +
76831 ulen = skb->len - sizeof(struct udphdr);
76832 if (len > ulen)
76833 len = ulen;
76834 @@ -1472,7 +1493,7 @@ int udp_queue_rcv_skb(struct sock *sk, s
76835
76836 drop:
76837 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76838 - atomic_inc(&sk->sk_drops);
76839 + atomic_inc_unchecked(&sk->sk_drops);
76840 kfree_skb(skb);
76841 return -1;
76842 }
76843 @@ -1491,7 +1512,7 @@ static void flush_stack(struct sock **st
76844 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76845
76846 if (!skb1) {
76847 - atomic_inc(&sk->sk_drops);
76848 + atomic_inc_unchecked(&sk->sk_drops);
76849 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76850 IS_UDPLITE(sk));
76851 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76852 @@ -1660,6 +1681,9 @@ int __udp4_lib_rcv(struct sk_buff *skb,
76853 goto csum_error;
76854
76855 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76856 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76857 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76858 +#endif
76859 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76860
76861 /*
76862 @@ -2087,8 +2111,13 @@ static void udp4_format_sock(struct sock
76863 sk_wmem_alloc_get(sp),
76864 sk_rmem_alloc_get(sp),
76865 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76866 - atomic_read(&sp->sk_refcnt), sp,
76867 - atomic_read(&sp->sk_drops), len);
76868 + atomic_read(&sp->sk_refcnt),
76869 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76870 + NULL,
76871 +#else
76872 + sp,
76873 +#endif
76874 + atomic_read_unchecked(&sp->sk_drops), len);
76875 }
76876
76877 int udp4_seq_show(struct seq_file *seq, void *v)
76878 diff -urNp linux-2.6.39.2/net/ipv6/inet6_connection_sock.c linux-2.6.39.2/net/ipv6/inet6_connection_sock.c
76879 --- linux-2.6.39.2/net/ipv6/inet6_connection_sock.c 2011-05-19 00:06:34.000000000 -0400
76880 +++ linux-2.6.39.2/net/ipv6/inet6_connection_sock.c 2011-05-22 19:36:34.000000000 -0400
76881 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *
76882 #ifdef CONFIG_XFRM
76883 {
76884 struct rt6_info *rt = (struct rt6_info *)dst;
76885 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76886 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76887 }
76888 #endif
76889 }
76890 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(
76891 #ifdef CONFIG_XFRM
76892 if (dst) {
76893 struct rt6_info *rt = (struct rt6_info *)dst;
76894 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76895 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76896 __sk_dst_reset(sk);
76897 dst = NULL;
76898 }
76899 diff -urNp linux-2.6.39.2/net/ipv6/ipv6_sockglue.c linux-2.6.39.2/net/ipv6/ipv6_sockglue.c
76900 --- linux-2.6.39.2/net/ipv6/ipv6_sockglue.c 2011-05-19 00:06:34.000000000 -0400
76901 +++ linux-2.6.39.2/net/ipv6/ipv6_sockglue.c 2011-05-22 19:36:34.000000000 -0400
76902 @@ -129,6 +129,8 @@ static int do_ipv6_setsockopt(struct soc
76903 int val, valbool;
76904 int retv = -ENOPROTOOPT;
76905
76906 + pax_track_stack();
76907 +
76908 if (optval == NULL)
76909 val=0;
76910 else {
76911 @@ -919,6 +921,8 @@ static int do_ipv6_getsockopt(struct soc
76912 int len;
76913 int val;
76914
76915 + pax_track_stack();
76916 +
76917 if (ip6_mroute_opt(optname))
76918 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
76919
76920 diff -urNp linux-2.6.39.2/net/ipv6/raw.c linux-2.6.39.2/net/ipv6/raw.c
76921 --- linux-2.6.39.2/net/ipv6/raw.c 2011-05-19 00:06:34.000000000 -0400
76922 +++ linux-2.6.39.2/net/ipv6/raw.c 2011-05-22 19:41:42.000000000 -0400
76923 @@ -376,7 +376,7 @@ static inline int rawv6_rcv_skb(struct s
76924 {
76925 if ((raw6_sk(sk)->checksum || rcu_dereference_raw(sk->sk_filter)) &&
76926 skb_checksum_complete(skb)) {
76927 - atomic_inc(&sk->sk_drops);
76928 + atomic_inc_unchecked(&sk->sk_drops);
76929 kfree_skb(skb);
76930 return NET_RX_DROP;
76931 }
76932 @@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76933 struct raw6_sock *rp = raw6_sk(sk);
76934
76935 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76936 - atomic_inc(&sk->sk_drops);
76937 + atomic_inc_unchecked(&sk->sk_drops);
76938 kfree_skb(skb);
76939 return NET_RX_DROP;
76940 }
76941 @@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk
76942
76943 if (inet->hdrincl) {
76944 if (skb_checksum_complete(skb)) {
76945 - atomic_inc(&sk->sk_drops);
76946 + atomic_inc_unchecked(&sk->sk_drops);
76947 kfree_skb(skb);
76948 return NET_RX_DROP;
76949 }
76950 @@ -601,7 +601,7 @@ out:
76951 return err;
76952 }
76953
76954 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76955 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76956 struct flowi6 *fl6, struct dst_entry **dstp,
76957 unsigned int flags)
76958 {
76959 @@ -742,6 +742,8 @@ static int rawv6_sendmsg(struct kiocb *i
76960 u16 proto;
76961 int err;
76962
76963 + pax_track_stack();
76964 +
76965 /* Rough check on arithmetic overflow,
76966 better check is made in ip6_append_data().
76967 */
76968 @@ -909,12 +911,15 @@ do_confirm:
76969 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76970 char __user *optval, int optlen)
76971 {
76972 + struct icmp6_filter filter;
76973 +
76974 switch (optname) {
76975 case ICMPV6_FILTER:
76976 if (optlen > sizeof(struct icmp6_filter))
76977 optlen = sizeof(struct icmp6_filter);
76978 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76979 + if (copy_from_user(&filter, optval, optlen))
76980 return -EFAULT;
76981 + memcpy(&raw6_sk(sk)->filter, &filter, optlen);
76982 return 0;
76983 default:
76984 return -ENOPROTOOPT;
76985 @@ -926,6 +931,7 @@ static int rawv6_seticmpfilter(struct so
76986 static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76987 char __user *optval, int __user *optlen)
76988 {
76989 + struct icmp6_filter filter;
76990 int len;
76991
76992 switch (optname) {
76993 @@ -938,7 +944,8 @@ static int rawv6_geticmpfilter(struct so
76994 len = sizeof(struct icmp6_filter);
76995 if (put_user(len, optlen))
76996 return -EFAULT;
76997 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76998 + memcpy(&filter, &raw6_sk(sk)->filter, len);
76999 + if (copy_to_user(optval, &filter, len))
77000 return -EFAULT;
77001 return 0;
77002 default:
77003 @@ -1252,7 +1259,13 @@ static void raw6_sock_seq_show(struct se
77004 0, 0L, 0,
77005 sock_i_uid(sp), 0,
77006 sock_i_ino(sp),
77007 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77008 + atomic_read(&sp->sk_refcnt),
77009 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77010 + NULL,
77011 +#else
77012 + sp,
77013 +#endif
77014 + atomic_read_unchecked(&sp->sk_drops));
77015 }
77016
77017 static int raw6_seq_show(struct seq_file *seq, void *v)
77018 diff -urNp linux-2.6.39.2/net/ipv6/tcp_ipv6.c linux-2.6.39.2/net/ipv6/tcp_ipv6.c
77019 --- linux-2.6.39.2/net/ipv6/tcp_ipv6.c 2011-05-19 00:06:34.000000000 -0400
77020 +++ linux-2.6.39.2/net/ipv6/tcp_ipv6.c 2011-05-22 19:41:42.000000000 -0400
77021 @@ -92,6 +92,10 @@ static struct tcp_md5sig_key *tcp_v6_md5
77022 }
77023 #endif
77024
77025 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77026 +extern int grsec_enable_blackhole;
77027 +#endif
77028 +
77029 static void tcp_v6_hash(struct sock *sk)
77030 {
77031 if (sk->sk_state != TCP_CLOSE) {
77032 @@ -1660,6 +1664,9 @@ static int tcp_v6_do_rcv(struct sock *sk
77033 return 0;
77034
77035 reset:
77036 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77037 + if (!grsec_enable_blackhole)
77038 +#endif
77039 tcp_v6_send_reset(sk, skb);
77040 discard:
77041 if (opt_skb)
77042 @@ -1739,12 +1746,20 @@ static int tcp_v6_rcv(struct sk_buff *sk
77043 TCP_SKB_CB(skb)->sacked = 0;
77044
77045 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77046 - if (!sk)
77047 + if (!sk) {
77048 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77049 + ret = 1;
77050 +#endif
77051 goto no_tcp_socket;
77052 + }
77053
77054 process:
77055 - if (sk->sk_state == TCP_TIME_WAIT)
77056 + if (sk->sk_state == TCP_TIME_WAIT) {
77057 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77058 + ret = 2;
77059 +#endif
77060 goto do_time_wait;
77061 + }
77062
77063 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77064 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77065 @@ -1792,6 +1807,10 @@ no_tcp_socket:
77066 bad_packet:
77067 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77068 } else {
77069 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77070 + if (!grsec_enable_blackhole || (ret == 1 &&
77071 + (skb->dev->flags & IFF_LOOPBACK)))
77072 +#endif
77073 tcp_v6_send_reset(NULL, skb);
77074 }
77075
77076 @@ -2052,7 +2071,13 @@ static void get_openreq6(struct seq_file
77077 uid,
77078 0, /* non standard timer */
77079 0, /* open_requests have no inode */
77080 - 0, req);
77081 + 0,
77082 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77083 + NULL
77084 +#else
77085 + req
77086 +#endif
77087 + );
77088 }
77089
77090 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77091 @@ -2102,7 +2127,12 @@ static void get_tcp6_sock(struct seq_fil
77092 sock_i_uid(sp),
77093 icsk->icsk_probes_out,
77094 sock_i_ino(sp),
77095 - atomic_read(&sp->sk_refcnt), sp,
77096 + atomic_read(&sp->sk_refcnt),
77097 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77098 + NULL,
77099 +#else
77100 + sp,
77101 +#endif
77102 jiffies_to_clock_t(icsk->icsk_rto),
77103 jiffies_to_clock_t(icsk->icsk_ack.ato),
77104 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77105 @@ -2137,7 +2167,13 @@ static void get_timewait6_sock(struct se
77106 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77107 tw->tw_substate, 0, 0,
77108 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77109 - atomic_read(&tw->tw_refcnt), tw);
77110 + atomic_read(&tw->tw_refcnt),
77111 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77112 + NULL
77113 +#else
77114 + tw
77115 +#endif
77116 + );
77117 }
77118
77119 static int tcp6_seq_show(struct seq_file *seq, void *v)
77120 diff -urNp linux-2.6.39.2/net/ipv6/udp.c linux-2.6.39.2/net/ipv6/udp.c
77121 --- linux-2.6.39.2/net/ipv6/udp.c 2011-05-19 00:06:34.000000000 -0400
77122 +++ linux-2.6.39.2/net/ipv6/udp.c 2011-05-22 19:41:42.000000000 -0400
77123 @@ -50,6 +50,10 @@
77124 #include <linux/seq_file.h>
77125 #include "udp_impl.h"
77126
77127 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77128 +extern int grsec_enable_blackhole;
77129 +#endif
77130 +
77131 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77132 {
77133 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77134 @@ -545,7 +549,7 @@ int udpv6_queue_rcv_skb(struct sock * sk
77135
77136 return 0;
77137 drop:
77138 - atomic_inc(&sk->sk_drops);
77139 + atomic_inc_unchecked(&sk->sk_drops);
77140 drop_no_sk_drops_inc:
77141 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77142 kfree_skb(skb);
77143 @@ -621,7 +625,7 @@ static void flush_stack(struct sock **st
77144 continue;
77145 }
77146 drop:
77147 - atomic_inc(&sk->sk_drops);
77148 + atomic_inc_unchecked(&sk->sk_drops);
77149 UDP6_INC_STATS_BH(sock_net(sk),
77150 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
77151 UDP6_INC_STATS_BH(sock_net(sk),
77152 @@ -776,6 +780,9 @@ int __udp6_lib_rcv(struct sk_buff *skb,
77153 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
77154 proto == IPPROTO_UDPLITE);
77155
77156 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77157 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77158 +#endif
77159 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77160
77161 kfree_skb(skb);
77162 @@ -792,7 +799,7 @@ int __udp6_lib_rcv(struct sk_buff *skb,
77163 if (!sock_owned_by_user(sk))
77164 udpv6_queue_rcv_skb(sk, skb);
77165 else if (sk_add_backlog(sk, skb)) {
77166 - atomic_inc(&sk->sk_drops);
77167 + atomic_inc_unchecked(&sk->sk_drops);
77168 bh_unlock_sock(sk);
77169 sock_put(sk);
77170 goto discard;
77171 @@ -1403,8 +1410,13 @@ static void udp6_sock_seq_show(struct se
77172 0, 0L, 0,
77173 sock_i_uid(sp), 0,
77174 sock_i_ino(sp),
77175 - atomic_read(&sp->sk_refcnt), sp,
77176 - atomic_read(&sp->sk_drops));
77177 + atomic_read(&sp->sk_refcnt),
77178 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77179 + NULL,
77180 +#else
77181 + sp,
77182 +#endif
77183 + atomic_read_unchecked(&sp->sk_drops));
77184 }
77185
77186 int udp6_seq_show(struct seq_file *seq, void *v)
77187 diff -urNp linux-2.6.39.2/net/irda/ircomm/ircomm_tty.c linux-2.6.39.2/net/irda/ircomm/ircomm_tty.c
77188 --- linux-2.6.39.2/net/irda/ircomm/ircomm_tty.c 2011-05-19 00:06:34.000000000 -0400
77189 +++ linux-2.6.39.2/net/irda/ircomm/ircomm_tty.c 2011-05-22 19:36:34.000000000 -0400
77190 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(st
77191 add_wait_queue(&self->open_wait, &wait);
77192
77193 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77194 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77195 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77196
77197 /* As far as I can see, we protect open_count - Jean II */
77198 spin_lock_irqsave(&self->spinlock, flags);
77199 if (!tty_hung_up_p(filp)) {
77200 extra_count = 1;
77201 - self->open_count--;
77202 + local_dec(&self->open_count);
77203 }
77204 spin_unlock_irqrestore(&self->spinlock, flags);
77205 - self->blocked_open++;
77206 + local_inc(&self->blocked_open);
77207
77208 while (1) {
77209 if (tty->termios->c_cflag & CBAUD) {
77210 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(st
77211 }
77212
77213 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77214 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77215 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77216
77217 schedule();
77218 }
77219 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(st
77220 if (extra_count) {
77221 /* ++ is not atomic, so this should be protected - Jean II */
77222 spin_lock_irqsave(&self->spinlock, flags);
77223 - self->open_count++;
77224 + local_inc(&self->open_count);
77225 spin_unlock_irqrestore(&self->spinlock, flags);
77226 }
77227 - self->blocked_open--;
77228 + local_dec(&self->blocked_open);
77229
77230 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77231 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77232 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77233
77234 if (!retval)
77235 self->flags |= ASYNC_NORMAL_ACTIVE;
77236 @@ -416,14 +416,14 @@ static int ircomm_tty_open(struct tty_st
77237 }
77238 /* ++ is not atomic, so this should be protected - Jean II */
77239 spin_lock_irqsave(&self->spinlock, flags);
77240 - self->open_count++;
77241 + local_inc(&self->open_count);
77242
77243 tty->driver_data = self;
77244 self->tty = tty;
77245 spin_unlock_irqrestore(&self->spinlock, flags);
77246
77247 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77248 - self->line, self->open_count);
77249 + self->line, local_read(&self->open_count));
77250
77251 /* Not really used by us, but lets do it anyway */
77252 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77253 @@ -509,7 +509,7 @@ static void ircomm_tty_close(struct tty_
77254 return;
77255 }
77256
77257 - if ((tty->count == 1) && (self->open_count != 1)) {
77258 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77259 /*
77260 * Uh, oh. tty->count is 1, which means that the tty
77261 * structure will be freed. state->count should always
77262 @@ -519,16 +519,16 @@ static void ircomm_tty_close(struct tty_
77263 */
77264 IRDA_DEBUG(0, "%s(), bad serial port count; "
77265 "tty->count is 1, state->count is %d\n", __func__ ,
77266 - self->open_count);
77267 - self->open_count = 1;
77268 + local_read(&self->open_count));
77269 + local_set(&self->open_count, 1);
77270 }
77271
77272 - if (--self->open_count < 0) {
77273 + if (local_dec_return(&self->open_count) < 0) {
77274 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77275 - __func__, self->line, self->open_count);
77276 - self->open_count = 0;
77277 + __func__, self->line, local_read(&self->open_count));
77278 + local_set(&self->open_count, 0);
77279 }
77280 - if (self->open_count) {
77281 + if (local_read(&self->open_count)) {
77282 spin_unlock_irqrestore(&self->spinlock, flags);
77283
77284 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77285 @@ -560,7 +560,7 @@ static void ircomm_tty_close(struct tty_
77286 tty->closing = 0;
77287 self->tty = NULL;
77288
77289 - if (self->blocked_open) {
77290 + if (local_read(&self->blocked_open)) {
77291 if (self->close_delay)
77292 schedule_timeout_interruptible(self->close_delay);
77293 wake_up_interruptible(&self->open_wait);
77294 @@ -1012,7 +1012,7 @@ static void ircomm_tty_hangup(struct tty
77295 spin_lock_irqsave(&self->spinlock, flags);
77296 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77297 self->tty = NULL;
77298 - self->open_count = 0;
77299 + local_set(&self->open_count, 0);
77300 spin_unlock_irqrestore(&self->spinlock, flags);
77301
77302 wake_up_interruptible(&self->open_wait);
77303 @@ -1364,7 +1364,7 @@ static void ircomm_tty_line_info(struct
77304 seq_putc(m, '\n');
77305
77306 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77307 - seq_printf(m, "Open count: %d\n", self->open_count);
77308 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77309 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77310 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77311
77312 diff -urNp linux-2.6.39.2/net/iucv/af_iucv.c linux-2.6.39.2/net/iucv/af_iucv.c
77313 --- linux-2.6.39.2/net/iucv/af_iucv.c 2011-05-19 00:06:34.000000000 -0400
77314 +++ linux-2.6.39.2/net/iucv/af_iucv.c 2011-05-22 19:36:34.000000000 -0400
77315 @@ -653,10 +653,10 @@ static int iucv_sock_autobind(struct soc
77316
77317 write_lock_bh(&iucv_sk_list.lock);
77318
77319 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77320 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77321 while (__iucv_get_sock_by_name(name)) {
77322 sprintf(name, "%08x",
77323 - atomic_inc_return(&iucv_sk_list.autobind_name));
77324 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77325 }
77326
77327 write_unlock_bh(&iucv_sk_list.lock);
77328 diff -urNp linux-2.6.39.2/net/key/af_key.c linux-2.6.39.2/net/key/af_key.c
77329 --- linux-2.6.39.2/net/key/af_key.c 2011-05-19 00:06:34.000000000 -0400
77330 +++ linux-2.6.39.2/net/key/af_key.c 2011-05-22 19:41:42.000000000 -0400
77331 @@ -2481,6 +2481,8 @@ static int pfkey_migrate(struct sock *sk
77332 struct xfrm_migrate m[XFRM_MAX_DEPTH];
77333 struct xfrm_kmaddress k;
77334
77335 + pax_track_stack();
77336 +
77337 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
77338 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
77339 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
77340 @@ -3016,10 +3018,10 @@ static int pfkey_send_policy_notify(stru
77341 static u32 get_acqseq(void)
77342 {
77343 u32 res;
77344 - static atomic_t acqseq;
77345 + static atomic_unchecked_t acqseq;
77346
77347 do {
77348 - res = atomic_inc_return(&acqseq);
77349 + res = atomic_inc_return_unchecked(&acqseq);
77350 } while (!res);
77351 return res;
77352 }
77353 @@ -3657,7 +3659,11 @@ static int pfkey_seq_show(struct seq_fil
77354 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
77355 else
77356 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
77357 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77358 + NULL,
77359 +#else
77360 s,
77361 +#endif
77362 atomic_read(&s->sk_refcnt),
77363 sk_rmem_alloc_get(s),
77364 sk_wmem_alloc_get(s),
77365 diff -urNp linux-2.6.39.2/net/l2tp/l2tp_ip.c linux-2.6.39.2/net/l2tp/l2tp_ip.c
77366 --- linux-2.6.39.2/net/l2tp/l2tp_ip.c 2011-05-19 00:06:34.000000000 -0400
77367 +++ linux-2.6.39.2/net/l2tp/l2tp_ip.c 2011-05-22 19:36:34.000000000 -0400
77368 @@ -625,7 +625,7 @@ static struct inet_protosw l2tp_ip_proto
77369 .no_check = 0,
77370 };
77371
77372 -static struct net_protocol l2tp_ip_protocol __read_mostly = {
77373 +static const struct net_protocol l2tp_ip_protocol = {
77374 .handler = l2tp_ip_recv,
77375 };
77376
77377 diff -urNp linux-2.6.39.2/net/lapb/lapb_iface.c linux-2.6.39.2/net/lapb/lapb_iface.c
77378 --- linux-2.6.39.2/net/lapb/lapb_iface.c 2011-05-19 00:06:34.000000000 -0400
77379 +++ linux-2.6.39.2/net/lapb/lapb_iface.c 2011-05-22 19:36:34.000000000 -0400
77380 @@ -138,8 +138,7 @@ static struct lapb_cb *lapb_create_cb(vo
77381 out:
77382 return lapb;
77383 }
77384 -
77385 -int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks)
77386 +int lapb_register(struct net_device *dev, const struct lapb_register_struct *callbacks)
77387 {
77388 struct lapb_cb *lapb;
77389 int rc = LAPB_BADTOKEN;
77390 diff -urNp linux-2.6.39.2/net/mac80211/cfg.c linux-2.6.39.2/net/mac80211/cfg.c
77391 --- linux-2.6.39.2/net/mac80211/cfg.c 2011-06-03 00:04:14.000000000 -0400
77392 +++ linux-2.6.39.2/net/mac80211/cfg.c 2011-06-03 00:32:08.000000000 -0400
77393 @@ -2031,7 +2031,7 @@ static void ieee80211_get_ringparam(stru
77394 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
77395 }
77396
77397 -struct cfg80211_ops mac80211_config_ops = {
77398 +const struct cfg80211_ops mac80211_config_ops = {
77399 .add_virtual_intf = ieee80211_add_iface,
77400 .del_virtual_intf = ieee80211_del_iface,
77401 .change_virtual_intf = ieee80211_change_iface,
77402 diff -urNp linux-2.6.39.2/net/mac80211/cfg.h linux-2.6.39.2/net/mac80211/cfg.h
77403 --- linux-2.6.39.2/net/mac80211/cfg.h 2011-05-19 00:06:34.000000000 -0400
77404 +++ linux-2.6.39.2/net/mac80211/cfg.h 2011-05-22 19:36:34.000000000 -0400
77405 @@ -4,6 +4,6 @@
77406 #ifndef __CFG_H
77407 #define __CFG_H
77408
77409 -extern struct cfg80211_ops mac80211_config_ops;
77410 +extern const struct cfg80211_ops mac80211_config_ops;
77411
77412 #endif /* __CFG_H */
77413 diff -urNp linux-2.6.39.2/net/mac80211/debugfs_sta.c linux-2.6.39.2/net/mac80211/debugfs_sta.c
77414 --- linux-2.6.39.2/net/mac80211/debugfs_sta.c 2011-05-19 00:06:34.000000000 -0400
77415 +++ linux-2.6.39.2/net/mac80211/debugfs_sta.c 2011-05-22 19:36:34.000000000 -0400
77416 @@ -115,6 +115,8 @@ static ssize_t sta_agg_status_read(struc
77417 struct tid_ampdu_rx *tid_rx;
77418 struct tid_ampdu_tx *tid_tx;
77419
77420 + pax_track_stack();
77421 +
77422 rcu_read_lock();
77423
77424 p += scnprintf(p, sizeof(buf) + buf - p, "next dialog_token: %#02x\n",
77425 @@ -215,6 +217,8 @@ static ssize_t sta_ht_capa_read(struct f
77426 struct sta_info *sta = file->private_data;
77427 struct ieee80211_sta_ht_cap *htc = &sta->sta.ht_cap;
77428
77429 + pax_track_stack();
77430 +
77431 p += scnprintf(p, sizeof(buf) + buf - p, "ht %ssupported\n",
77432 htc->ht_supported ? "" : "not ");
77433 if (htc->ht_supported) {
77434 diff -urNp linux-2.6.39.2/net/mac80211/ieee80211_i.h linux-2.6.39.2/net/mac80211/ieee80211_i.h
77435 --- linux-2.6.39.2/net/mac80211/ieee80211_i.h 2011-05-19 00:06:34.000000000 -0400
77436 +++ linux-2.6.39.2/net/mac80211/ieee80211_i.h 2011-05-22 19:36:34.000000000 -0400
77437 @@ -27,6 +27,7 @@
77438 #include <net/ieee80211_radiotap.h>
77439 #include <net/cfg80211.h>
77440 #include <net/mac80211.h>
77441 +#include <asm/local.h>
77442 #include "key.h"
77443 #include "sta_info.h"
77444
77445 @@ -714,7 +715,7 @@ struct ieee80211_local {
77446 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77447 spinlock_t queue_stop_reason_lock;
77448
77449 - int open_count;
77450 + local_t open_count;
77451 int monitors, cooked_mntrs;
77452 /* number of interfaces with corresponding FIF_ flags */
77453 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77454 diff -urNp linux-2.6.39.2/net/mac80211/iface.c linux-2.6.39.2/net/mac80211/iface.c
77455 --- linux-2.6.39.2/net/mac80211/iface.c 2011-05-19 00:06:34.000000000 -0400
77456 +++ linux-2.6.39.2/net/mac80211/iface.c 2011-05-22 19:36:34.000000000 -0400
77457 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_
77458 break;
77459 }
77460
77461 - if (local->open_count == 0) {
77462 + if (local_read(&local->open_count) == 0) {
77463 res = drv_start(local);
77464 if (res)
77465 goto err_del_bss;
77466 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_
77467 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77468
77469 if (!is_valid_ether_addr(dev->dev_addr)) {
77470 - if (!local->open_count)
77471 + if (!local_read(&local->open_count))
77472 drv_stop(local);
77473 return -EADDRNOTAVAIL;
77474 }
77475 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_
77476 mutex_unlock(&local->mtx);
77477
77478 if (coming_up)
77479 - local->open_count++;
77480 + local_inc(&local->open_count);
77481
77482 if (hw_reconf_flags) {
77483 ieee80211_hw_config(local, hw_reconf_flags);
77484 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_
77485 err_del_interface:
77486 drv_remove_interface(local, &sdata->vif);
77487 err_stop:
77488 - if (!local->open_count)
77489 + if (!local_read(&local->open_count))
77490 drv_stop(local);
77491 err_del_bss:
77492 sdata->bss = NULL;
77493 @@ -474,7 +474,7 @@ static void ieee80211_do_stop(struct iee
77494 }
77495
77496 if (going_down)
77497 - local->open_count--;
77498 + local_dec(&local->open_count);
77499
77500 switch (sdata->vif.type) {
77501 case NL80211_IFTYPE_AP_VLAN:
77502 @@ -533,7 +533,7 @@ static void ieee80211_do_stop(struct iee
77503
77504 ieee80211_recalc_ps(local, -1);
77505
77506 - if (local->open_count == 0) {
77507 + if (local_read(&local->open_count) == 0) {
77508 if (local->ops->napi_poll)
77509 napi_disable(&local->napi);
77510 ieee80211_clear_tx_pending(local);
77511 diff -urNp linux-2.6.39.2/net/mac80211/main.c linux-2.6.39.2/net/mac80211/main.c
77512 --- linux-2.6.39.2/net/mac80211/main.c 2011-05-19 00:06:34.000000000 -0400
77513 +++ linux-2.6.39.2/net/mac80211/main.c 2011-05-22 19:36:34.000000000 -0400
77514 @@ -215,7 +215,7 @@ int ieee80211_hw_config(struct ieee80211
77515 local->hw.conf.power_level = power;
77516 }
77517
77518 - if (changed && local->open_count) {
77519 + if (changed && local_read(&local->open_count)) {
77520 ret = drv_config(local, changed);
77521 /*
77522 * Goal:
77523 diff -urNp linux-2.6.39.2/net/mac80211/mlme.c linux-2.6.39.2/net/mac80211/mlme.c
77524 --- linux-2.6.39.2/net/mac80211/mlme.c 2011-06-03 00:04:14.000000000 -0400
77525 +++ linux-2.6.39.2/net/mac80211/mlme.c 2011-06-03 00:32:08.000000000 -0400
77526 @@ -1431,6 +1431,8 @@ static bool ieee80211_assoc_success(stru
77527 bool have_higher_than_11mbit = false;
77528 u16 ap_ht_cap_flags;
77529
77530 + pax_track_stack();
77531 +
77532 /* AssocResp and ReassocResp have identical structure */
77533
77534 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
77535 diff -urNp linux-2.6.39.2/net/mac80211/pm.c linux-2.6.39.2/net/mac80211/pm.c
77536 --- linux-2.6.39.2/net/mac80211/pm.c 2011-05-19 00:06:34.000000000 -0400
77537 +++ linux-2.6.39.2/net/mac80211/pm.c 2011-05-22 19:36:34.000000000 -0400
77538 @@ -95,7 +95,7 @@ int __ieee80211_suspend(struct ieee80211
77539 }
77540
77541 /* stop hardware - this must stop RX */
77542 - if (local->open_count)
77543 + if (local_read(&local->open_count))
77544 ieee80211_stop_device(local);
77545
77546 local->suspended = true;
77547 diff -urNp linux-2.6.39.2/net/mac80211/rate.c linux-2.6.39.2/net/mac80211/rate.c
77548 --- linux-2.6.39.2/net/mac80211/rate.c 2011-05-19 00:06:34.000000000 -0400
77549 +++ linux-2.6.39.2/net/mac80211/rate.c 2011-05-22 19:36:34.000000000 -0400
77550 @@ -371,7 +371,7 @@ int ieee80211_init_rate_ctrl_alg(struct
77551
77552 ASSERT_RTNL();
77553
77554 - if (local->open_count)
77555 + if (local_read(&local->open_count))
77556 return -EBUSY;
77557
77558 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77559 diff -urNp linux-2.6.39.2/net/mac80211/rc80211_pid_debugfs.c linux-2.6.39.2/net/mac80211/rc80211_pid_debugfs.c
77560 --- linux-2.6.39.2/net/mac80211/rc80211_pid_debugfs.c 2011-05-19 00:06:34.000000000 -0400
77561 +++ linux-2.6.39.2/net/mac80211/rc80211_pid_debugfs.c 2011-05-22 19:36:34.000000000 -0400
77562 @@ -192,7 +192,7 @@ static ssize_t rate_control_pid_events_r
77563
77564 spin_unlock_irqrestore(&events->lock, status);
77565
77566 - if (copy_to_user(buf, pb, p))
77567 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77568 return -EFAULT;
77569
77570 return p;
77571 diff -urNp linux-2.6.39.2/net/mac80211/util.c linux-2.6.39.2/net/mac80211/util.c
77572 --- linux-2.6.39.2/net/mac80211/util.c 2011-05-19 00:06:34.000000000 -0400
77573 +++ linux-2.6.39.2/net/mac80211/util.c 2011-05-22 19:36:34.000000000 -0400
77574 @@ -1129,7 +1129,7 @@ int ieee80211_reconfig(struct ieee80211_
77575 local->resuming = true;
77576
77577 /* restart hardware */
77578 - if (local->open_count) {
77579 + if (local_read(&local->open_count)) {
77580 /*
77581 * Upon resume hardware can sometimes be goofy due to
77582 * various platform / driver / bus issues, so restarting
77583 diff -urNp linux-2.6.39.2/net/netfilter/ipvs/ip_vs_conn.c linux-2.6.39.2/net/netfilter/ipvs/ip_vs_conn.c
77584 --- linux-2.6.39.2/net/netfilter/ipvs/ip_vs_conn.c 2011-05-19 00:06:34.000000000 -0400
77585 +++ linux-2.6.39.2/net/netfilter/ipvs/ip_vs_conn.c 2011-05-22 19:36:34.000000000 -0400
77586 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, s
77587 /* Increase the refcnt counter of the dest */
77588 atomic_inc(&dest->refcnt);
77589
77590 - conn_flags = atomic_read(&dest->conn_flags);
77591 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77592 if (cp->protocol != IPPROTO_UDP)
77593 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77594 /* Bind with the destination and its corresponding transmitter */
77595 @@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_p
77596 atomic_set(&cp->refcnt, 1);
77597
77598 atomic_set(&cp->n_control, 0);
77599 - atomic_set(&cp->in_pkts, 0);
77600 + atomic_set_unchecked(&cp->in_pkts, 0);
77601
77602 atomic_inc(&ipvs->conn_count);
77603 if (flags & IP_VS_CONN_F_NO_CPORT)
77604 @@ -1141,7 +1141,7 @@ static inline int todrop_entry(struct ip
77605
77606 /* Don't drop the entry if its number of incoming packets is not
77607 located in [0, 8] */
77608 - i = atomic_read(&cp->in_pkts);
77609 + i = atomic_read_unchecked(&cp->in_pkts);
77610 if (i > 8 || i < 0) return 0;
77611
77612 if (!todrop_rate[i]) return 0;
77613 diff -urNp linux-2.6.39.2/net/netfilter/ipvs/ip_vs_core.c linux-2.6.39.2/net/netfilter/ipvs/ip_vs_core.c
77614 --- linux-2.6.39.2/net/netfilter/ipvs/ip_vs_core.c 2011-05-19 00:06:34.000000000 -0400
77615 +++ linux-2.6.39.2/net/netfilter/ipvs/ip_vs_core.c 2011-05-22 19:36:34.000000000 -0400
77616 @@ -563,7 +563,7 @@ int ip_vs_leave(struct ip_vs_service *sv
77617 ret = cp->packet_xmit(skb, cp, pd->pp);
77618 /* do not touch skb anymore */
77619
77620 - atomic_inc(&cp->in_pkts);
77621 + atomic_inc_unchecked(&cp->in_pkts);
77622 ip_vs_conn_put(cp);
77623 return ret;
77624 }
77625 @@ -1633,7 +1633,7 @@ ip_vs_in(unsigned int hooknum, struct sk
77626 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77627 pkts = sysctl_sync_threshold(ipvs);
77628 else
77629 - pkts = atomic_add_return(1, &cp->in_pkts);
77630 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77631
77632 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77633 cp->protocol == IPPROTO_SCTP) {
77634 diff -urNp linux-2.6.39.2/net/netfilter/ipvs/ip_vs_ctl.c linux-2.6.39.2/net/netfilter/ipvs/ip_vs_ctl.c
77635 --- linux-2.6.39.2/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-19 00:06:34.000000000 -0400
77636 +++ linux-2.6.39.2/net/netfilter/ipvs/ip_vs_ctl.c 2011-05-22 19:36:34.000000000 -0400
77637 @@ -782,7 +782,7 @@ __ip_vs_update_dest(struct ip_vs_service
77638 ip_vs_rs_hash(ipvs, dest);
77639 write_unlock_bh(&ipvs->rs_lock);
77640 }
77641 - atomic_set(&dest->conn_flags, conn_flags);
77642 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77643
77644 /* bind the service */
77645 if (!dest->svc) {
77646 @@ -2027,7 +2027,7 @@ static int ip_vs_info_seq_show(struct se
77647 " %-7s %-6d %-10d %-10d\n",
77648 &dest->addr.in6,
77649 ntohs(dest->port),
77650 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77651 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77652 atomic_read(&dest->weight),
77653 atomic_read(&dest->activeconns),
77654 atomic_read(&dest->inactconns));
77655 @@ -2038,7 +2038,7 @@ static int ip_vs_info_seq_show(struct se
77656 "%-7s %-6d %-10d %-10d\n",
77657 ntohl(dest->addr.ip),
77658 ntohs(dest->port),
77659 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77660 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77661 atomic_read(&dest->weight),
77662 atomic_read(&dest->activeconns),
77663 atomic_read(&dest->inactconns));
77664 @@ -2287,6 +2287,8 @@ do_ip_vs_set_ctl(struct sock *sk, int cm
77665 struct ip_vs_dest_user *udest_compat;
77666 struct ip_vs_dest_user_kern udest;
77667
77668 + pax_track_stack();
77669 +
77670 if (!capable(CAP_NET_ADMIN))
77671 return -EPERM;
77672
77673 @@ -2501,7 +2503,7 @@ __ip_vs_get_dest_entries(struct net *net
77674
77675 entry.addr = dest->addr.ip;
77676 entry.port = dest->port;
77677 - entry.conn_flags = atomic_read(&dest->conn_flags);
77678 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77679 entry.weight = atomic_read(&dest->weight);
77680 entry.u_threshold = dest->u_threshold;
77681 entry.l_threshold = dest->l_threshold;
77682 @@ -3029,7 +3031,7 @@ static int ip_vs_genl_fill_dest(struct s
77683 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77684
77685 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77686 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77687 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77688 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
77689 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
77690 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
77691 diff -urNp linux-2.6.39.2/net/netfilter/ipvs/ip_vs_sync.c linux-2.6.39.2/net/netfilter/ipvs/ip_vs_sync.c
77692 --- linux-2.6.39.2/net/netfilter/ipvs/ip_vs_sync.c 2011-05-19 00:06:34.000000000 -0400
77693 +++ linux-2.6.39.2/net/netfilter/ipvs/ip_vs_sync.c 2011-05-22 19:36:34.000000000 -0400
77694 @@ -648,7 +648,7 @@ control:
77695 * i.e only increment in_pkts for Templates.
77696 */
77697 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
77698 - int pkts = atomic_add_return(1, &cp->in_pkts);
77699 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77700
77701 if (pkts % sysctl_sync_period(ipvs) != 1)
77702 return;
77703 @@ -794,7 +794,7 @@ static void ip_vs_proc_conn(struct net *
77704
77705 if (opt)
77706 memcpy(&cp->in_seq, opt, sizeof(*opt));
77707 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77708 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77709 cp->state = state;
77710 cp->old_state = cp->state;
77711 /*
77712 diff -urNp linux-2.6.39.2/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.39.2/net/netfilter/ipvs/ip_vs_xmit.c
77713 --- linux-2.6.39.2/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-19 00:06:34.000000000 -0400
77714 +++ linux-2.6.39.2/net/netfilter/ipvs/ip_vs_xmit.c 2011-05-22 19:36:34.000000000 -0400
77715 @@ -1127,7 +1127,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, str
77716 else
77717 rc = NF_ACCEPT;
77718 /* do not touch skb anymore */
77719 - atomic_inc(&cp->in_pkts);
77720 + atomic_inc_unchecked(&cp->in_pkts);
77721 goto out;
77722 }
77723
77724 @@ -1245,7 +1245,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb,
77725 else
77726 rc = NF_ACCEPT;
77727 /* do not touch skb anymore */
77728 - atomic_inc(&cp->in_pkts);
77729 + atomic_inc_unchecked(&cp->in_pkts);
77730 goto out;
77731 }
77732
77733 diff -urNp linux-2.6.39.2/net/netfilter/Kconfig linux-2.6.39.2/net/netfilter/Kconfig
77734 --- linux-2.6.39.2/net/netfilter/Kconfig 2011-05-19 00:06:34.000000000 -0400
77735 +++ linux-2.6.39.2/net/netfilter/Kconfig 2011-05-22 19:41:42.000000000 -0400
77736 @@ -781,6 +781,16 @@ config NETFILTER_XT_MATCH_ESP
77737
77738 To compile it as a module, choose M here. If unsure, say N.
77739
77740 +config NETFILTER_XT_MATCH_GRADM
77741 + tristate '"gradm" match support'
77742 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77743 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77744 + ---help---
77745 + The gradm match allows to match on grsecurity RBAC being enabled.
77746 + It is useful when iptables rules are applied early on bootup to
77747 + prevent connections to the machine (except from a trusted host)
77748 + while the RBAC system is disabled.
77749 +
77750 config NETFILTER_XT_MATCH_HASHLIMIT
77751 tristate '"hashlimit" match support'
77752 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77753 diff -urNp linux-2.6.39.2/net/netfilter/Makefile linux-2.6.39.2/net/netfilter/Makefile
77754 --- linux-2.6.39.2/net/netfilter/Makefile 2011-05-19 00:06:34.000000000 -0400
77755 +++ linux-2.6.39.2/net/netfilter/Makefile 2011-05-22 20:40:16.000000000 -0400
77756 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) +=
77757 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77758 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77759 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77760 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77761 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77762 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77763 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77764 diff -urNp linux-2.6.39.2/net/netfilter/nfnetlink_log.c linux-2.6.39.2/net/netfilter/nfnetlink_log.c
77765 --- linux-2.6.39.2/net/netfilter/nfnetlink_log.c 2011-05-19 00:06:34.000000000 -0400
77766 +++ linux-2.6.39.2/net/netfilter/nfnetlink_log.c 2011-05-22 19:36:35.000000000 -0400
77767 @@ -70,7 +70,7 @@ struct nfulnl_instance {
77768 };
77769
77770 static DEFINE_SPINLOCK(instances_lock);
77771 -static atomic_t global_seq;
77772 +static atomic_unchecked_t global_seq;
77773
77774 #define INSTANCE_BUCKETS 16
77775 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77776 @@ -506,7 +506,7 @@ __build_packet_message(struct nfulnl_ins
77777 /* global sequence number */
77778 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
77779 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
77780 - htonl(atomic_inc_return(&global_seq)));
77781 + htonl(atomic_inc_return_unchecked(&global_seq)));
77782
77783 if (data_len) {
77784 struct nlattr *nla;
77785 diff -urNp linux-2.6.39.2/net/netfilter/nfnetlink_queue.c linux-2.6.39.2/net/netfilter/nfnetlink_queue.c
77786 --- linux-2.6.39.2/net/netfilter/nfnetlink_queue.c 2011-05-19 00:06:34.000000000 -0400
77787 +++ linux-2.6.39.2/net/netfilter/nfnetlink_queue.c 2011-05-22 19:36:35.000000000 -0400
77788 @@ -58,7 +58,7 @@ struct nfqnl_instance {
77789 */
77790 spinlock_t lock;
77791 unsigned int queue_total;
77792 - atomic_t id_sequence; /* 'sequence' of pkt ids */
77793 + atomic_unchecked_t id_sequence; /* 'sequence' of pkt ids */
77794 struct list_head queue_list; /* packets in queue */
77795 };
77796
77797 @@ -272,7 +272,7 @@ nfqnl_build_packet_message(struct nfqnl_
77798 nfmsg->version = NFNETLINK_V0;
77799 nfmsg->res_id = htons(queue->queue_num);
77800
77801 - entry->id = atomic_inc_return(&queue->id_sequence);
77802 + entry->id = atomic_inc_return_unchecked(&queue->id_sequence);
77803 pmsg.packet_id = htonl(entry->id);
77804 pmsg.hw_protocol = entskb->protocol;
77805 pmsg.hook = entry->hook;
77806 @@ -869,7 +869,7 @@ static int seq_show(struct seq_file *s,
77807 inst->peer_pid, inst->queue_total,
77808 inst->copy_mode, inst->copy_range,
77809 inst->queue_dropped, inst->queue_user_dropped,
77810 - atomic_read(&inst->id_sequence), 1);
77811 + atomic_read_unchecked(&inst->id_sequence), 1);
77812 }
77813
77814 static const struct seq_operations nfqnl_seq_ops = {
77815 diff -urNp linux-2.6.39.2/net/netfilter/xt_gradm.c linux-2.6.39.2/net/netfilter/xt_gradm.c
77816 --- linux-2.6.39.2/net/netfilter/xt_gradm.c 1969-12-31 19:00:00.000000000 -0500
77817 +++ linux-2.6.39.2/net/netfilter/xt_gradm.c 2011-05-22 19:41:42.000000000 -0400
77818 @@ -0,0 +1,51 @@
77819 +/*
77820 + * gradm match for netfilter
77821 + * Copyright © Zbigniew Krzystolik, 2010
77822 + *
77823 + * This program is free software; you can redistribute it and/or modify
77824 + * it under the terms of the GNU General Public License; either version
77825 + * 2 or 3 as published by the Free Software Foundation.
77826 + */
77827 +#include <linux/module.h>
77828 +#include <linux/moduleparam.h>
77829 +#include <linux/skbuff.h>
77830 +#include <linux/netfilter/x_tables.h>
77831 +#include <linux/grsecurity.h>
77832 +#include <linux/netfilter/xt_gradm.h>
77833 +
77834 +static bool
77835 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
77836 +{
77837 + const struct xt_gradm_mtinfo *info = par->matchinfo;
77838 + bool retval = false;
77839 + if (gr_acl_is_enabled())
77840 + retval = true;
77841 + return retval ^ info->invflags;
77842 +}
77843 +
77844 +static struct xt_match gradm_mt_reg __read_mostly = {
77845 + .name = "gradm",
77846 + .revision = 0,
77847 + .family = NFPROTO_UNSPEC,
77848 + .match = gradm_mt,
77849 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
77850 + .me = THIS_MODULE,
77851 +};
77852 +
77853 +static int __init gradm_mt_init(void)
77854 +{
77855 + return xt_register_match(&gradm_mt_reg);
77856 +}
77857 +
77858 +static void __exit gradm_mt_exit(void)
77859 +{
77860 + xt_unregister_match(&gradm_mt_reg);
77861 +}
77862 +
77863 +module_init(gradm_mt_init);
77864 +module_exit(gradm_mt_exit);
77865 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
77866 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
77867 +MODULE_LICENSE("GPL");
77868 +MODULE_ALIAS("ipt_gradm");
77869 +MODULE_ALIAS("ip6t_gradm");
77870 diff -urNp linux-2.6.39.2/net/netfilter/xt_statistic.c linux-2.6.39.2/net/netfilter/xt_statistic.c
77871 --- linux-2.6.39.2/net/netfilter/xt_statistic.c 2011-05-19 00:06:34.000000000 -0400
77872 +++ linux-2.6.39.2/net/netfilter/xt_statistic.c 2011-05-22 19:36:35.000000000 -0400
77873 @@ -18,7 +18,7 @@
77874 #include <linux/netfilter/x_tables.h>
77875
77876 struct xt_statistic_priv {
77877 - atomic_t count;
77878 + atomic_unchecked_t count;
77879 } ____cacheline_aligned_in_smp;
77880
77881 MODULE_LICENSE("GPL");
77882 @@ -41,9 +41,9 @@ statistic_mt(const struct sk_buff *skb,
77883 break;
77884 case XT_STATISTIC_MODE_NTH:
77885 do {
77886 - oval = atomic_read(&info->master->count);
77887 + oval = atomic_read_unchecked(&info->master->count);
77888 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
77889 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
77890 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
77891 if (nval == 0)
77892 ret = !ret;
77893 break;
77894 @@ -63,7 +63,7 @@ static int statistic_mt_check(const stru
77895 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
77896 if (info->master == NULL)
77897 return -ENOMEM;
77898 - atomic_set(&info->master->count, info->u.nth.count);
77899 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
77900
77901 return 0;
77902 }
77903 diff -urNp linux-2.6.39.2/net/netlink/af_netlink.c linux-2.6.39.2/net/netlink/af_netlink.c
77904 --- linux-2.6.39.2/net/netlink/af_netlink.c 2011-05-19 00:06:34.000000000 -0400
77905 +++ linux-2.6.39.2/net/netlink/af_netlink.c 2011-05-22 19:41:42.000000000 -0400
77906 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock
77907 sk->sk_error_report(sk);
77908 }
77909 }
77910 - atomic_inc(&sk->sk_drops);
77911 + atomic_inc_unchecked(&sk->sk_drops);
77912 }
77913
77914 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
77915 @@ -1992,15 +1992,23 @@ static int netlink_seq_show(struct seq_f
77916 struct netlink_sock *nlk = nlk_sk(s);
77917
77918 seq_printf(seq, "%p %-3d %-6d %08x %-8d %-8d %p %-8d %-8d %-8lu\n",
77919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77920 + NULL,
77921 +#else
77922 s,
77923 +#endif
77924 s->sk_protocol,
77925 nlk->pid,
77926 nlk->groups ? (u32)nlk->groups[0] : 0,
77927 sk_rmem_alloc_get(s),
77928 sk_wmem_alloc_get(s),
77929 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77930 + NULL,
77931 +#else
77932 nlk->cb,
77933 +#endif
77934 atomic_read(&s->sk_refcnt),
77935 - atomic_read(&s->sk_drops),
77936 + atomic_read_unchecked(&s->sk_drops),
77937 sock_i_ino(s)
77938 );
77939
77940 diff -urNp linux-2.6.39.2/net/netrom/af_netrom.c linux-2.6.39.2/net/netrom/af_netrom.c
77941 --- linux-2.6.39.2/net/netrom/af_netrom.c 2011-05-19 00:06:34.000000000 -0400
77942 +++ linux-2.6.39.2/net/netrom/af_netrom.c 2011-05-22 19:41:42.000000000 -0400
77943 @@ -840,6 +840,7 @@ static int nr_getname(struct socket *soc
77944 struct sock *sk = sock->sk;
77945 struct nr_sock *nr = nr_sk(sk);
77946
77947 + memset(sax, 0, sizeof(*sax));
77948 lock_sock(sk);
77949 if (peer != 0) {
77950 if (sk->sk_state != TCP_ESTABLISHED) {
77951 @@ -854,7 +855,6 @@ static int nr_getname(struct socket *soc
77952 *uaddr_len = sizeof(struct full_sockaddr_ax25);
77953 } else {
77954 sax->fsa_ax25.sax25_family = AF_NETROM;
77955 - sax->fsa_ax25.sax25_ndigis = 0;
77956 sax->fsa_ax25.sax25_call = nr->source_addr;
77957 *uaddr_len = sizeof(struct sockaddr_ax25);
77958 }
77959 diff -urNp linux-2.6.39.2/net/packet/af_packet.c linux-2.6.39.2/net/packet/af_packet.c
77960 --- linux-2.6.39.2/net/packet/af_packet.c 2011-05-19 00:06:34.000000000 -0400
77961 +++ linux-2.6.39.2/net/packet/af_packet.c 2011-05-22 19:41:42.000000000 -0400
77962 @@ -647,14 +647,14 @@ static int packet_rcv(struct sk_buff *sk
77963
77964 spin_lock(&sk->sk_receive_queue.lock);
77965 po->stats.tp_packets++;
77966 - skb->dropcount = atomic_read(&sk->sk_drops);
77967 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77968 __skb_queue_tail(&sk->sk_receive_queue, skb);
77969 spin_unlock(&sk->sk_receive_queue.lock);
77970 sk->sk_data_ready(sk, skb->len);
77971 return 0;
77972
77973 drop_n_acct:
77974 - po->stats.tp_drops = atomic_inc_return(&sk->sk_drops);
77975 + po->stats.tp_drops = atomic_inc_return_unchecked(&sk->sk_drops);
77976
77977 drop_n_restore:
77978 if (skb_head != skb->data && skb_shared(skb)) {
77979 @@ -2157,7 +2157,7 @@ static int packet_getsockopt(struct sock
77980 case PACKET_HDRLEN:
77981 if (len > sizeof(int))
77982 len = sizeof(int);
77983 - if (copy_from_user(&val, optval, len))
77984 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
77985 return -EFAULT;
77986 switch (val) {
77987 case TPACKET_V1:
77988 @@ -2195,7 +2195,7 @@ static int packet_getsockopt(struct sock
77989
77990 if (put_user(len, optlen))
77991 return -EFAULT;
77992 - if (copy_to_user(optval, data, len))
77993 + if (len > sizeof(st) || copy_to_user(optval, data, len))
77994 return -EFAULT;
77995 return 0;
77996 }
77997 @@ -2707,7 +2707,11 @@ static int packet_seq_show(struct seq_fi
77998
77999 seq_printf(seq,
78000 "%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n",
78001 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78002 + NULL,
78003 +#else
78004 s,
78005 +#endif
78006 atomic_read(&s->sk_refcnt),
78007 s->sk_type,
78008 ntohs(po->num),
78009 diff -urNp linux-2.6.39.2/net/phonet/af_phonet.c linux-2.6.39.2/net/phonet/af_phonet.c
78010 --- linux-2.6.39.2/net/phonet/af_phonet.c 2011-05-19 00:06:34.000000000 -0400
78011 +++ linux-2.6.39.2/net/phonet/af_phonet.c 2011-05-22 19:41:42.000000000 -0400
78012 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_pr
78013 {
78014 struct phonet_protocol *pp;
78015
78016 - if (protocol >= PHONET_NPROTO)
78017 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78018 return NULL;
78019
78020 rcu_read_lock();
78021 @@ -149,7 +149,7 @@ static int pn_header_parse(const struct
78022 return 1;
78023 }
78024
78025 -struct header_ops phonet_header_ops = {
78026 +const struct header_ops phonet_header_ops = {
78027 .create = pn_header_create,
78028 .parse = pn_header_parse,
78029 };
78030 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_regist
78031 {
78032 int err = 0;
78033
78034 - if (protocol >= PHONET_NPROTO)
78035 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78036 return -EINVAL;
78037
78038 err = proto_register(pp->prot, 1);
78039 diff -urNp linux-2.6.39.2/net/phonet/pep.c linux-2.6.39.2/net/phonet/pep.c
78040 --- linux-2.6.39.2/net/phonet/pep.c 2011-05-19 00:06:34.000000000 -0400
78041 +++ linux-2.6.39.2/net/phonet/pep.c 2011-05-22 19:36:35.000000000 -0400
78042 @@ -387,7 +387,7 @@ static int pipe_do_rcv(struct sock *sk,
78043
78044 case PNS_PEP_CTRL_REQ:
78045 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78046 - atomic_inc(&sk->sk_drops);
78047 + atomic_inc_unchecked(&sk->sk_drops);
78048 break;
78049 }
78050 __skb_pull(skb, 4);
78051 @@ -408,7 +408,7 @@ static int pipe_do_rcv(struct sock *sk,
78052 }
78053
78054 if (pn->rx_credits == 0) {
78055 - atomic_inc(&sk->sk_drops);
78056 + atomic_inc_unchecked(&sk->sk_drops);
78057 err = -ENOBUFS;
78058 break;
78059 }
78060 @@ -556,7 +556,7 @@ static int pipe_handler_do_rcv(struct so
78061 }
78062
78063 if (pn->rx_credits == 0) {
78064 - atomic_inc(&sk->sk_drops);
78065 + atomic_inc_unchecked(&sk->sk_drops);
78066 err = NET_RX_DROP;
78067 break;
78068 }
78069 diff -urNp linux-2.6.39.2/net/phonet/socket.c linux-2.6.39.2/net/phonet/socket.c
78070 --- linux-2.6.39.2/net/phonet/socket.c 2011-05-19 00:06:34.000000000 -0400
78071 +++ linux-2.6.39.2/net/phonet/socket.c 2011-05-22 20:39:26.000000000 -0400
78072 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_f
78073 pn->resource, sk->sk_state,
78074 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78075 sock_i_uid(sk), sock_i_ino(sk),
78076 - atomic_read(&sk->sk_refcnt), sk,
78077 - atomic_read(&sk->sk_drops), &len);
78078 + atomic_read(&sk->sk_refcnt),
78079 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78080 + NULL,
78081 +#else
78082 + sk,
78083 +#endif
78084 + atomic_read_unchecked(&sk->sk_drops), &len);
78085 }
78086 seq_printf(seq, "%*s\n", 127 - len, "");
78087 return 0;
78088 diff -urNp linux-2.6.39.2/net/rds/cong.c linux-2.6.39.2/net/rds/cong.c
78089 --- linux-2.6.39.2/net/rds/cong.c 2011-05-19 00:06:34.000000000 -0400
78090 +++ linux-2.6.39.2/net/rds/cong.c 2011-05-22 19:36:35.000000000 -0400
78091 @@ -77,7 +77,7 @@
78092 * finds that the saved generation number is smaller than the global generation
78093 * number, it wakes up the process.
78094 */
78095 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78096 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78097
78098 /*
78099 * Congestion monitoring
78100 @@ -232,7 +232,7 @@ void rds_cong_map_updated(struct rds_con
78101 rdsdebug("waking map %p for %pI4\n",
78102 map, &map->m_addr);
78103 rds_stats_inc(s_cong_update_received);
78104 - atomic_inc(&rds_cong_generation);
78105 + atomic_inc_unchecked(&rds_cong_generation);
78106 if (waitqueue_active(&map->m_waitq))
78107 wake_up(&map->m_waitq);
78108 if (waitqueue_active(&rds_poll_waitq))
78109 @@ -258,7 +258,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78110
78111 int rds_cong_updated_since(unsigned long *recent)
78112 {
78113 - unsigned long gen = atomic_read(&rds_cong_generation);
78114 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78115
78116 if (likely(*recent == gen))
78117 return 0;
78118 diff -urNp linux-2.6.39.2/net/rds/ib_cm.c linux-2.6.39.2/net/rds/ib_cm.c
78119 --- linux-2.6.39.2/net/rds/ib_cm.c 2011-05-19 00:06:34.000000000 -0400
78120 +++ linux-2.6.39.2/net/rds/ib_cm.c 2011-05-22 19:36:35.000000000 -0400
78121 @@ -720,7 +720,7 @@ void rds_ib_conn_shutdown(struct rds_con
78122 /* Clear the ACK state */
78123 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78124 #ifdef KERNEL_HAS_ATOMIC64
78125 - atomic64_set(&ic->i_ack_next, 0);
78126 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78127 #else
78128 ic->i_ack_next = 0;
78129 #endif
78130 diff -urNp linux-2.6.39.2/net/rds/ib.h linux-2.6.39.2/net/rds/ib.h
78131 --- linux-2.6.39.2/net/rds/ib.h 2011-05-19 00:06:34.000000000 -0400
78132 +++ linux-2.6.39.2/net/rds/ib.h 2011-05-22 19:36:35.000000000 -0400
78133 @@ -127,7 +127,7 @@ struct rds_ib_connection {
78134 /* sending acks */
78135 unsigned long i_ack_flags;
78136 #ifdef KERNEL_HAS_ATOMIC64
78137 - atomic64_t i_ack_next; /* next ACK to send */
78138 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78139 #else
78140 spinlock_t i_ack_lock; /* protect i_ack_next */
78141 u64 i_ack_next; /* next ACK to send */
78142 diff -urNp linux-2.6.39.2/net/rds/ib_recv.c linux-2.6.39.2/net/rds/ib_recv.c
78143 --- linux-2.6.39.2/net/rds/ib_recv.c 2011-05-19 00:06:34.000000000 -0400
78144 +++ linux-2.6.39.2/net/rds/ib_recv.c 2011-05-22 19:36:35.000000000 -0400
78145 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
78146 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78147 int ack_required)
78148 {
78149 - atomic64_set(&ic->i_ack_next, seq);
78150 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78151 if (ack_required) {
78152 smp_mb__before_clear_bit();
78153 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78154 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_
78155 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78156 smp_mb__after_clear_bit();
78157
78158 - return atomic64_read(&ic->i_ack_next);
78159 + return atomic64_read_unchecked(&ic->i_ack_next);
78160 }
78161 #endif
78162
78163 diff -urNp linux-2.6.39.2/net/rds/iw_cm.c linux-2.6.39.2/net/rds/iw_cm.c
78164 --- linux-2.6.39.2/net/rds/iw_cm.c 2011-05-19 00:06:34.000000000 -0400
78165 +++ linux-2.6.39.2/net/rds/iw_cm.c 2011-05-22 19:36:35.000000000 -0400
78166 @@ -664,7 +664,7 @@ void rds_iw_conn_shutdown(struct rds_con
78167 /* Clear the ACK state */
78168 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78169 #ifdef KERNEL_HAS_ATOMIC64
78170 - atomic64_set(&ic->i_ack_next, 0);
78171 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78172 #else
78173 ic->i_ack_next = 0;
78174 #endif
78175 diff -urNp linux-2.6.39.2/net/rds/iw.h linux-2.6.39.2/net/rds/iw.h
78176 --- linux-2.6.39.2/net/rds/iw.h 2011-05-19 00:06:34.000000000 -0400
78177 +++ linux-2.6.39.2/net/rds/iw.h 2011-05-22 19:36:35.000000000 -0400
78178 @@ -133,7 +133,7 @@ struct rds_iw_connection {
78179 /* sending acks */
78180 unsigned long i_ack_flags;
78181 #ifdef KERNEL_HAS_ATOMIC64
78182 - atomic64_t i_ack_next; /* next ACK to send */
78183 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78184 #else
78185 spinlock_t i_ack_lock; /* protect i_ack_next */
78186 u64 i_ack_next; /* next ACK to send */
78187 diff -urNp linux-2.6.39.2/net/rds/iw_rdma.c linux-2.6.39.2/net/rds/iw_rdma.c
78188 --- linux-2.6.39.2/net/rds/iw_rdma.c 2011-05-19 00:06:34.000000000 -0400
78189 +++ linux-2.6.39.2/net/rds/iw_rdma.c 2011-05-22 19:36:35.000000000 -0400
78190 @@ -182,6 +182,8 @@ int rds_iw_update_cm_id(struct rds_iw_de
78191 struct rdma_cm_id *pcm_id;
78192 int rc;
78193
78194 + pax_track_stack();
78195 +
78196 src_addr = (struct sockaddr_in *)&cm_id->route.addr.src_addr;
78197 dst_addr = (struct sockaddr_in *)&cm_id->route.addr.dst_addr;
78198
78199 diff -urNp linux-2.6.39.2/net/rds/iw_recv.c linux-2.6.39.2/net/rds/iw_recv.c
78200 --- linux-2.6.39.2/net/rds/iw_recv.c 2011-05-19 00:06:34.000000000 -0400
78201 +++ linux-2.6.39.2/net/rds/iw_recv.c 2011-05-22 19:36:35.000000000 -0400
78202 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
78203 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78204 int ack_required)
78205 {
78206 - atomic64_set(&ic->i_ack_next, seq);
78207 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78208 if (ack_required) {
78209 smp_mb__before_clear_bit();
78210 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78211 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_
78212 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78213 smp_mb__after_clear_bit();
78214
78215 - return atomic64_read(&ic->i_ack_next);
78216 + return atomic64_read_unchecked(&ic->i_ack_next);
78217 }
78218 #endif
78219
78220 diff -urNp linux-2.6.39.2/net/rxrpc/af_rxrpc.c linux-2.6.39.2/net/rxrpc/af_rxrpc.c
78221 --- linux-2.6.39.2/net/rxrpc/af_rxrpc.c 2011-05-19 00:06:34.000000000 -0400
78222 +++ linux-2.6.39.2/net/rxrpc/af_rxrpc.c 2011-05-22 19:36:35.000000000 -0400
78223 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_
78224 __be32 rxrpc_epoch;
78225
78226 /* current debugging ID */
78227 -atomic_t rxrpc_debug_id;
78228 +atomic_unchecked_t rxrpc_debug_id;
78229
78230 /* count of skbs currently in use */
78231 atomic_t rxrpc_n_skbs;
78232 diff -urNp linux-2.6.39.2/net/rxrpc/ar-ack.c linux-2.6.39.2/net/rxrpc/ar-ack.c
78233 --- linux-2.6.39.2/net/rxrpc/ar-ack.c 2011-05-19 00:06:34.000000000 -0400
78234 +++ linux-2.6.39.2/net/rxrpc/ar-ack.c 2011-05-22 19:36:35.000000000 -0400
78235 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_ca
78236
78237 _enter("{%d,%d,%d,%d},",
78238 call->acks_hard, call->acks_unacked,
78239 - atomic_read(&call->sequence),
78240 + atomic_read_unchecked(&call->sequence),
78241 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78242
78243 stop = 0;
78244 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_ca
78245
78246 /* each Tx packet has a new serial number */
78247 sp->hdr.serial =
78248 - htonl(atomic_inc_return(&call->conn->serial));
78249 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78250
78251 hdr = (struct rxrpc_header *) txb->head;
78252 hdr->serial = sp->hdr.serial;
78253 @@ -405,7 +405,7 @@ static void rxrpc_rotate_tx_window(struc
78254 */
78255 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78256 {
78257 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78258 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78259 }
78260
78261 /*
78262 @@ -631,7 +631,7 @@ process_further:
78263
78264 latest = ntohl(sp->hdr.serial);
78265 hard = ntohl(ack.firstPacket);
78266 - tx = atomic_read(&call->sequence);
78267 + tx = atomic_read_unchecked(&call->sequence);
78268
78269 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78270 latest,
78271 @@ -844,6 +844,8 @@ void rxrpc_process_call(struct work_stru
78272 u32 abort_code = RX_PROTOCOL_ERROR;
78273 u8 *acks = NULL;
78274
78275 + pax_track_stack();
78276 +
78277 //printk("\n--------------------\n");
78278 _enter("{%d,%s,%lx} [%lu]",
78279 call->debug_id, rxrpc_call_states[call->state], call->events,
78280 @@ -1163,7 +1165,7 @@ void rxrpc_process_call(struct work_stru
78281 goto maybe_reschedule;
78282
78283 send_ACK_with_skew:
78284 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78285 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78286 ntohl(ack.serial));
78287 send_ACK:
78288 mtu = call->conn->trans->peer->if_mtu;
78289 @@ -1175,7 +1177,7 @@ send_ACK:
78290 ackinfo.rxMTU = htonl(5692);
78291 ackinfo.jumbo_max = htonl(4);
78292
78293 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78294 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78295 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78296 ntohl(hdr.serial),
78297 ntohs(ack.maxSkew),
78298 @@ -1193,7 +1195,7 @@ send_ACK:
78299 send_message:
78300 _debug("send message");
78301
78302 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78303 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78304 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78305 send_message_2:
78306
78307 diff -urNp linux-2.6.39.2/net/rxrpc/ar-call.c linux-2.6.39.2/net/rxrpc/ar-call.c
78308 --- linux-2.6.39.2/net/rxrpc/ar-call.c 2011-05-19 00:06:34.000000000 -0400
78309 +++ linux-2.6.39.2/net/rxrpc/ar-call.c 2011-05-22 19:36:35.000000000 -0400
78310 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_ca
78311 spin_lock_init(&call->lock);
78312 rwlock_init(&call->state_lock);
78313 atomic_set(&call->usage, 1);
78314 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78315 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78316 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78317
78318 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78319 diff -urNp linux-2.6.39.2/net/rxrpc/ar-connection.c linux-2.6.39.2/net/rxrpc/ar-connection.c
78320 --- linux-2.6.39.2/net/rxrpc/ar-connection.c 2011-05-19 00:06:34.000000000 -0400
78321 +++ linux-2.6.39.2/net/rxrpc/ar-connection.c 2011-05-22 19:36:35.000000000 -0400
78322 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_al
78323 rwlock_init(&conn->lock);
78324 spin_lock_init(&conn->state_lock);
78325 atomic_set(&conn->usage, 1);
78326 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78327 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78328 conn->avail_calls = RXRPC_MAXCALLS;
78329 conn->size_align = 4;
78330 conn->header_size = sizeof(struct rxrpc_header);
78331 diff -urNp linux-2.6.39.2/net/rxrpc/ar-connevent.c linux-2.6.39.2/net/rxrpc/ar-connevent.c
78332 --- linux-2.6.39.2/net/rxrpc/ar-connevent.c 2011-05-19 00:06:34.000000000 -0400
78333 +++ linux-2.6.39.2/net/rxrpc/ar-connevent.c 2011-05-22 19:36:35.000000000 -0400
78334 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct
78335
78336 len = iov[0].iov_len + iov[1].iov_len;
78337
78338 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78339 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78340 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78341
78342 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78343 diff -urNp linux-2.6.39.2/net/rxrpc/ar-input.c linux-2.6.39.2/net/rxrpc/ar-input.c
78344 --- linux-2.6.39.2/net/rxrpc/ar-input.c 2011-05-19 00:06:34.000000000 -0400
78345 +++ linux-2.6.39.2/net/rxrpc/ar-input.c 2011-05-22 19:36:35.000000000 -0400
78346 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rx
78347 /* track the latest serial number on this connection for ACK packet
78348 * information */
78349 serial = ntohl(sp->hdr.serial);
78350 - hi_serial = atomic_read(&call->conn->hi_serial);
78351 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78352 while (serial > hi_serial)
78353 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78354 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78355 serial);
78356
78357 /* request ACK generation for any ACK or DATA packet that requests
78358 diff -urNp linux-2.6.39.2/net/rxrpc/ar-internal.h linux-2.6.39.2/net/rxrpc/ar-internal.h
78359 --- linux-2.6.39.2/net/rxrpc/ar-internal.h 2011-05-19 00:06:34.000000000 -0400
78360 +++ linux-2.6.39.2/net/rxrpc/ar-internal.h 2011-05-22 19:36:35.000000000 -0400
78361 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78362 int error; /* error code for local abort */
78363 int debug_id; /* debug ID for printks */
78364 unsigned call_counter; /* call ID counter */
78365 - atomic_t serial; /* packet serial number counter */
78366 - atomic_t hi_serial; /* highest serial number received */
78367 + atomic_unchecked_t serial; /* packet serial number counter */
78368 + atomic_unchecked_t hi_serial; /* highest serial number received */
78369 u8 avail_calls; /* number of calls available */
78370 u8 size_align; /* data size alignment (for security) */
78371 u8 header_size; /* rxrpc + security header size */
78372 @@ -346,7 +346,7 @@ struct rxrpc_call {
78373 spinlock_t lock;
78374 rwlock_t state_lock; /* lock for state transition */
78375 atomic_t usage;
78376 - atomic_t sequence; /* Tx data packet sequence counter */
78377 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78378 u32 abort_code; /* local/remote abort code */
78379 enum { /* current state of call */
78380 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78381 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(stru
78382 */
78383 extern atomic_t rxrpc_n_skbs;
78384 extern __be32 rxrpc_epoch;
78385 -extern atomic_t rxrpc_debug_id;
78386 +extern atomic_unchecked_t rxrpc_debug_id;
78387 extern struct workqueue_struct *rxrpc_workqueue;
78388
78389 /*
78390 diff -urNp linux-2.6.39.2/net/rxrpc/ar-local.c linux-2.6.39.2/net/rxrpc/ar-local.c
78391 --- linux-2.6.39.2/net/rxrpc/ar-local.c 2011-05-19 00:06:34.000000000 -0400
78392 +++ linux-2.6.39.2/net/rxrpc/ar-local.c 2011-05-22 19:36:35.000000000 -0400
78393 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(st
78394 spin_lock_init(&local->lock);
78395 rwlock_init(&local->services_lock);
78396 atomic_set(&local->usage, 1);
78397 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78398 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78399 memcpy(&local->srx, srx, sizeof(*srx));
78400 }
78401
78402 diff -urNp linux-2.6.39.2/net/rxrpc/ar-output.c linux-2.6.39.2/net/rxrpc/ar-output.c
78403 --- linux-2.6.39.2/net/rxrpc/ar-output.c 2011-05-19 00:06:34.000000000 -0400
78404 +++ linux-2.6.39.2/net/rxrpc/ar-output.c 2011-05-22 19:36:35.000000000 -0400
78405 @@ -681,9 +681,9 @@ static int rxrpc_send_data(struct kiocb
78406 sp->hdr.cid = call->cid;
78407 sp->hdr.callNumber = call->call_id;
78408 sp->hdr.seq =
78409 - htonl(atomic_inc_return(&call->sequence));
78410 + htonl(atomic_inc_return_unchecked(&call->sequence));
78411 sp->hdr.serial =
78412 - htonl(atomic_inc_return(&conn->serial));
78413 + htonl(atomic_inc_return_unchecked(&conn->serial));
78414 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78415 sp->hdr.userStatus = 0;
78416 sp->hdr.securityIndex = conn->security_ix;
78417 diff -urNp linux-2.6.39.2/net/rxrpc/ar-peer.c linux-2.6.39.2/net/rxrpc/ar-peer.c
78418 --- linux-2.6.39.2/net/rxrpc/ar-peer.c 2011-05-19 00:06:34.000000000 -0400
78419 +++ linux-2.6.39.2/net/rxrpc/ar-peer.c 2011-05-22 19:36:35.000000000 -0400
78420 @@ -71,7 +71,7 @@ static struct rxrpc_peer *rxrpc_alloc_pe
78421 INIT_LIST_HEAD(&peer->error_targets);
78422 spin_lock_init(&peer->lock);
78423 atomic_set(&peer->usage, 1);
78424 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78425 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78426 memcpy(&peer->srx, srx, sizeof(*srx));
78427
78428 rxrpc_assess_MTU_size(peer);
78429 diff -urNp linux-2.6.39.2/net/rxrpc/ar-proc.c linux-2.6.39.2/net/rxrpc/ar-proc.c
78430 --- linux-2.6.39.2/net/rxrpc/ar-proc.c 2011-05-19 00:06:34.000000000 -0400
78431 +++ linux-2.6.39.2/net/rxrpc/ar-proc.c 2011-05-22 19:36:35.000000000 -0400
78432 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(str
78433 atomic_read(&conn->usage),
78434 rxrpc_conn_states[conn->state],
78435 key_serial(conn->key),
78436 - atomic_read(&conn->serial),
78437 - atomic_read(&conn->hi_serial));
78438 + atomic_read_unchecked(&conn->serial),
78439 + atomic_read_unchecked(&conn->hi_serial));
78440
78441 return 0;
78442 }
78443 diff -urNp linux-2.6.39.2/net/rxrpc/ar-transport.c linux-2.6.39.2/net/rxrpc/ar-transport.c
78444 --- linux-2.6.39.2/net/rxrpc/ar-transport.c 2011-05-19 00:06:34.000000000 -0400
78445 +++ linux-2.6.39.2/net/rxrpc/ar-transport.c 2011-05-22 19:36:35.000000000 -0400
78446 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_all
78447 spin_lock_init(&trans->client_lock);
78448 rwlock_init(&trans->conn_lock);
78449 atomic_set(&trans->usage, 1);
78450 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78451 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78452
78453 if (peer->srx.transport.family == AF_INET) {
78454 switch (peer->srx.transport_type) {
78455 diff -urNp linux-2.6.39.2/net/rxrpc/rxkad.c linux-2.6.39.2/net/rxrpc/rxkad.c
78456 --- linux-2.6.39.2/net/rxrpc/rxkad.c 2011-05-19 00:06:34.000000000 -0400
78457 +++ linux-2.6.39.2/net/rxrpc/rxkad.c 2011-05-22 19:36:35.000000000 -0400
78458 @@ -211,6 +211,8 @@ static int rxkad_secure_packet_encrypt(c
78459 u16 check;
78460 int nsg;
78461
78462 + pax_track_stack();
78463 +
78464 sp = rxrpc_skb(skb);
78465
78466 _enter("");
78467 @@ -338,6 +340,8 @@ static int rxkad_verify_packet_auth(cons
78468 u16 check;
78469 int nsg;
78470
78471 + pax_track_stack();
78472 +
78473 _enter("");
78474
78475 sp = rxrpc_skb(skb);
78476 @@ -610,7 +614,7 @@ static int rxkad_issue_challenge(struct
78477
78478 len = iov[0].iov_len + iov[1].iov_len;
78479
78480 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78481 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78482 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78483
78484 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78485 @@ -660,7 +664,7 @@ static int rxkad_send_response(struct rx
78486
78487 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78488
78489 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78490 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78491 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78492
78493 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78494 diff -urNp linux-2.6.39.2/net/sched/em_meta.c linux-2.6.39.2/net/sched/em_meta.c
78495 --- linux-2.6.39.2/net/sched/em_meta.c 2011-05-19 00:06:34.000000000 -0400
78496 +++ linux-2.6.39.2/net/sched/em_meta.c 2011-05-22 19:36:35.000000000 -0400
78497 @@ -832,7 +832,7 @@ static int em_meta_dump(struct sk_buff *
78498 {
78499 struct meta_match *meta = (struct meta_match *) em->data;
78500 struct tcf_meta_hdr hdr;
78501 - struct meta_type_ops *ops;
78502 + const struct meta_type_ops *ops;
78503
78504 memset(&hdr, 0, sizeof(hdr));
78505 memcpy(&hdr.left, &meta->lvalue.hdr, sizeof(hdr.left));
78506 diff -urNp linux-2.6.39.2/net/sctp/proc.c linux-2.6.39.2/net/sctp/proc.c
78507 --- linux-2.6.39.2/net/sctp/proc.c 2011-05-19 00:06:34.000000000 -0400
78508 +++ linux-2.6.39.2/net/sctp/proc.c 2011-05-22 19:41:42.000000000 -0400
78509 @@ -212,7 +212,12 @@ static int sctp_eps_seq_show(struct seq_
78510 sctp_for_each_hentry(epb, node, &head->chain) {
78511 ep = sctp_ep(epb);
78512 sk = epb->sk;
78513 - seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
78514 + seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ",
78515 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78516 + NULL, NULL,
78517 +#else
78518 + ep, sk,
78519 +#endif
78520 sctp_sk(sk)->type, sk->sk_state, hash,
78521 epb->bind_addr.port,
78522 sock_i_uid(sk), sock_i_ino(sk));
78523 @@ -318,7 +323,12 @@ static int sctp_assocs_seq_show(struct s
78524 seq_printf(seq,
78525 "%8p %8p %-3d %-3d %-2d %-4d "
78526 "%4d %8d %8d %7d %5lu %-5d %5d ",
78527 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78528 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78529 + NULL, NULL,
78530 +#else
78531 + assoc, sk,
78532 +#endif
78533 + sctp_sk(sk)->type, sk->sk_state,
78534 assoc->state, hash,
78535 assoc->assoc_id,
78536 assoc->sndbuf_used,
78537 diff -urNp linux-2.6.39.2/net/sctp/socket.c linux-2.6.39.2/net/sctp/socket.c
78538 --- linux-2.6.39.2/net/sctp/socket.c 2011-05-19 00:06:34.000000000 -0400
78539 +++ linux-2.6.39.2/net/sctp/socket.c 2011-05-22 19:36:35.000000000 -0400
78540 @@ -4433,7 +4433,7 @@ static int sctp_getsockopt_peer_addrs(st
78541 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78542 if (space_left < addrlen)
78543 return -ENOMEM;
78544 - if (copy_to_user(to, &temp, addrlen))
78545 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78546 return -EFAULT;
78547 to += addrlen;
78548 cnt++;
78549 diff -urNp linux-2.6.39.2/net/socket.c linux-2.6.39.2/net/socket.c
78550 --- linux-2.6.39.2/net/socket.c 2011-06-03 00:04:14.000000000 -0400
78551 +++ linux-2.6.39.2/net/socket.c 2011-06-03 00:32:08.000000000 -0400
78552 @@ -88,6 +88,7 @@
78553 #include <linux/nsproxy.h>
78554 #include <linux/magic.h>
78555 #include <linux/slab.h>
78556 +#include <linux/in.h>
78557
78558 #include <asm/uaccess.h>
78559 #include <asm/unistd.h>
78560 @@ -105,6 +106,8 @@
78561 #include <linux/sockios.h>
78562 #include <linux/atalk.h>
78563
78564 +#include <linux/grsock.h>
78565 +
78566 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78567 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78568 unsigned long nr_segs, loff_t pos);
78569 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struc
78570 &sockfs_dentry_operations, SOCKFS_MAGIC);
78571 }
78572
78573 -static struct vfsmount *sock_mnt __read_mostly;
78574 +struct vfsmount *sock_mnt __read_mostly;
78575
78576 static struct file_system_type sock_fs_type = {
78577 .name = "sockfs",
78578 @@ -1179,6 +1182,8 @@ int __sock_create(struct net *net, int f
78579 return -EAFNOSUPPORT;
78580 if (type < 0 || type >= SOCK_MAX)
78581 return -EINVAL;
78582 + if (protocol < 0)
78583 + return -EINVAL;
78584
78585 /* Compatibility.
78586
78587 @@ -1311,6 +1316,16 @@ SYSCALL_DEFINE3(socket, int, family, int
78588 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78589 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78590
78591 + if(!gr_search_socket(family, type, protocol)) {
78592 + retval = -EACCES;
78593 + goto out;
78594 + }
78595 +
78596 + if (gr_handle_sock_all(family, type, protocol)) {
78597 + retval = -EACCES;
78598 + goto out;
78599 + }
78600 +
78601 retval = sock_create(family, type, protocol, &sock);
78602 if (retval < 0)
78603 goto out;
78604 @@ -1423,6 +1438,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78605 if (sock) {
78606 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78607 if (err >= 0) {
78608 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78609 + err = -EACCES;
78610 + goto error;
78611 + }
78612 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78613 + if (err)
78614 + goto error;
78615 +
78616 err = security_socket_bind(sock,
78617 (struct sockaddr *)&address,
78618 addrlen);
78619 @@ -1431,6 +1454,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct so
78620 (struct sockaddr *)
78621 &address, addrlen);
78622 }
78623 +error:
78624 fput_light(sock->file, fput_needed);
78625 }
78626 return err;
78627 @@ -1454,10 +1478,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba
78628 if ((unsigned)backlog > somaxconn)
78629 backlog = somaxconn;
78630
78631 + if (gr_handle_sock_server_other(sock->sk)) {
78632 + err = -EPERM;
78633 + goto error;
78634 + }
78635 +
78636 + err = gr_search_listen(sock);
78637 + if (err)
78638 + goto error;
78639 +
78640 err = security_socket_listen(sock, backlog);
78641 if (!err)
78642 err = sock->ops->listen(sock, backlog);
78643
78644 +error:
78645 fput_light(sock->file, fput_needed);
78646 }
78647 return err;
78648 @@ -1501,6 +1535,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78649 newsock->type = sock->type;
78650 newsock->ops = sock->ops;
78651
78652 + if (gr_handle_sock_server_other(sock->sk)) {
78653 + err = -EPERM;
78654 + sock_release(newsock);
78655 + goto out_put;
78656 + }
78657 +
78658 + err = gr_search_accept(sock);
78659 + if (err) {
78660 + sock_release(newsock);
78661 + goto out_put;
78662 + }
78663 +
78664 /*
78665 * We don't need try_module_get here, as the listening socket (sock)
78666 * has the protocol module (sock->ops->owner) held.
78667 @@ -1539,6 +1585,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct
78668 fd_install(newfd, newfile);
78669 err = newfd;
78670
78671 + gr_attach_curr_ip(newsock->sk);
78672 +
78673 out_put:
78674 fput_light(sock->file, fput_needed);
78675 out:
78676 @@ -1571,6 +1619,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78677 int, addrlen)
78678 {
78679 struct socket *sock;
78680 + struct sockaddr *sck;
78681 struct sockaddr_storage address;
78682 int err, fput_needed;
78683
78684 @@ -1581,6 +1630,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct
78685 if (err < 0)
78686 goto out_put;
78687
78688 + sck = (struct sockaddr *)&address;
78689 +
78690 + if (gr_handle_sock_client(sck)) {
78691 + err = -EACCES;
78692 + goto out_put;
78693 + }
78694 +
78695 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78696 + if (err)
78697 + goto out_put;
78698 +
78699 err =
78700 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78701 if (err)
78702 @@ -1882,6 +1942,8 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct
78703 int err, ctl_len, iov_size, total_len;
78704 int fput_needed;
78705
78706 + pax_track_stack();
78707 +
78708 err = -EFAULT;
78709 if (MSG_CMSG_COMPAT & flags) {
78710 if (get_compat_msghdr(&msg_sys, msg_compat))
78711 diff -urNp linux-2.6.39.2/net/sunrpc/sched.c linux-2.6.39.2/net/sunrpc/sched.c
78712 --- linux-2.6.39.2/net/sunrpc/sched.c 2011-05-19 00:06:34.000000000 -0400
78713 +++ linux-2.6.39.2/net/sunrpc/sched.c 2011-05-22 19:36:35.000000000 -0400
78714 @@ -234,9 +234,9 @@ static int rpc_wait_bit_killable(void *w
78715 #ifdef RPC_DEBUG
78716 static void rpc_task_set_debuginfo(struct rpc_task *task)
78717 {
78718 - static atomic_t rpc_pid;
78719 + static atomic_unchecked_t rpc_pid;
78720
78721 - task->tk_pid = atomic_inc_return(&rpc_pid);
78722 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
78723 }
78724 #else
78725 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
78726 diff -urNp linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma.c linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma.c
78727 --- linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-19 00:06:34.000000000 -0400
78728 +++ linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma.c 2011-05-22 19:36:35.000000000 -0400
78729 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCR
78730 static unsigned int min_max_inline = 4096;
78731 static unsigned int max_max_inline = 65536;
78732
78733 -atomic_t rdma_stat_recv;
78734 -atomic_t rdma_stat_read;
78735 -atomic_t rdma_stat_write;
78736 -atomic_t rdma_stat_sq_starve;
78737 -atomic_t rdma_stat_rq_starve;
78738 -atomic_t rdma_stat_rq_poll;
78739 -atomic_t rdma_stat_rq_prod;
78740 -atomic_t rdma_stat_sq_poll;
78741 -atomic_t rdma_stat_sq_prod;
78742 +atomic_unchecked_t rdma_stat_recv;
78743 +atomic_unchecked_t rdma_stat_read;
78744 +atomic_unchecked_t rdma_stat_write;
78745 +atomic_unchecked_t rdma_stat_sq_starve;
78746 +atomic_unchecked_t rdma_stat_rq_starve;
78747 +atomic_unchecked_t rdma_stat_rq_poll;
78748 +atomic_unchecked_t rdma_stat_rq_prod;
78749 +atomic_unchecked_t rdma_stat_sq_poll;
78750 +atomic_unchecked_t rdma_stat_sq_prod;
78751
78752 /* Temporary NFS request map and context caches */
78753 struct kmem_cache *svc_rdma_map_cachep;
78754 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *ta
78755 len -= *ppos;
78756 if (len > *lenp)
78757 len = *lenp;
78758 - if (len && copy_to_user(buffer, str_buf, len))
78759 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
78760 return -EFAULT;
78761 *lenp = len;
78762 *ppos += len;
78763 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] =
78764 {
78765 .procname = "rdma_stat_read",
78766 .data = &rdma_stat_read,
78767 - .maxlen = sizeof(atomic_t),
78768 + .maxlen = sizeof(atomic_unchecked_t),
78769 .mode = 0644,
78770 .proc_handler = read_reset_stat,
78771 },
78772 {
78773 .procname = "rdma_stat_recv",
78774 .data = &rdma_stat_recv,
78775 - .maxlen = sizeof(atomic_t),
78776 + .maxlen = sizeof(atomic_unchecked_t),
78777 .mode = 0644,
78778 .proc_handler = read_reset_stat,
78779 },
78780 {
78781 .procname = "rdma_stat_write",
78782 .data = &rdma_stat_write,
78783 - .maxlen = sizeof(atomic_t),
78784 + .maxlen = sizeof(atomic_unchecked_t),
78785 .mode = 0644,
78786 .proc_handler = read_reset_stat,
78787 },
78788 {
78789 .procname = "rdma_stat_sq_starve",
78790 .data = &rdma_stat_sq_starve,
78791 - .maxlen = sizeof(atomic_t),
78792 + .maxlen = sizeof(atomic_unchecked_t),
78793 .mode = 0644,
78794 .proc_handler = read_reset_stat,
78795 },
78796 {
78797 .procname = "rdma_stat_rq_starve",
78798 .data = &rdma_stat_rq_starve,
78799 - .maxlen = sizeof(atomic_t),
78800 + .maxlen = sizeof(atomic_unchecked_t),
78801 .mode = 0644,
78802 .proc_handler = read_reset_stat,
78803 },
78804 {
78805 .procname = "rdma_stat_rq_poll",
78806 .data = &rdma_stat_rq_poll,
78807 - .maxlen = sizeof(atomic_t),
78808 + .maxlen = sizeof(atomic_unchecked_t),
78809 .mode = 0644,
78810 .proc_handler = read_reset_stat,
78811 },
78812 {
78813 .procname = "rdma_stat_rq_prod",
78814 .data = &rdma_stat_rq_prod,
78815 - .maxlen = sizeof(atomic_t),
78816 + .maxlen = sizeof(atomic_unchecked_t),
78817 .mode = 0644,
78818 .proc_handler = read_reset_stat,
78819 },
78820 {
78821 .procname = "rdma_stat_sq_poll",
78822 .data = &rdma_stat_sq_poll,
78823 - .maxlen = sizeof(atomic_t),
78824 + .maxlen = sizeof(atomic_unchecked_t),
78825 .mode = 0644,
78826 .proc_handler = read_reset_stat,
78827 },
78828 {
78829 .procname = "rdma_stat_sq_prod",
78830 .data = &rdma_stat_sq_prod,
78831 - .maxlen = sizeof(atomic_t),
78832 + .maxlen = sizeof(atomic_unchecked_t),
78833 .mode = 0644,
78834 .proc_handler = read_reset_stat,
78835 },
78836 diff -urNp linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
78837 --- linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-19 00:06:34.000000000 -0400
78838 +++ linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c 2011-05-22 19:36:35.000000000 -0400
78839 @@ -499,7 +499,7 @@ next_sge:
78840 svc_rdma_put_context(ctxt, 0);
78841 goto out;
78842 }
78843 - atomic_inc(&rdma_stat_read);
78844 + atomic_inc_unchecked(&rdma_stat_read);
78845
78846 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
78847 chl_map->ch[ch_no].count -= read_wr.num_sge;
78848 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78849 dto_q);
78850 list_del_init(&ctxt->dto_q);
78851 } else {
78852 - atomic_inc(&rdma_stat_rq_starve);
78853 + atomic_inc_unchecked(&rdma_stat_rq_starve);
78854 clear_bit(XPT_DATA, &xprt->xpt_flags);
78855 ctxt = NULL;
78856 }
78857 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *r
78858 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
78859 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
78860 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
78861 - atomic_inc(&rdma_stat_recv);
78862 + atomic_inc_unchecked(&rdma_stat_recv);
78863
78864 /* Build up the XDR from the receive buffers. */
78865 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
78866 diff -urNp linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_sendto.c linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_sendto.c
78867 --- linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-19 00:06:34.000000000 -0400
78868 +++ linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_sendto.c 2011-05-22 19:36:35.000000000 -0400
78869 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdm
78870 write_wr.wr.rdma.remote_addr = to;
78871
78872 /* Post It */
78873 - atomic_inc(&rdma_stat_write);
78874 + atomic_inc_unchecked(&rdma_stat_write);
78875 if (svc_rdma_send(xprt, &write_wr))
78876 goto err;
78877 return 0;
78878 diff -urNp linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_transport.c linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_transport.c
78879 --- linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-19 00:06:34.000000000 -0400
78880 +++ linux-2.6.39.2/net/sunrpc/xprtrdma/svc_rdma_transport.c 2011-05-22 19:36:35.000000000 -0400
78881 @@ -298,7 +298,7 @@ static void rq_cq_reap(struct svcxprt_rd
78882 return;
78883
78884 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
78885 - atomic_inc(&rdma_stat_rq_poll);
78886 + atomic_inc_unchecked(&rdma_stat_rq_poll);
78887
78888 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
78889 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
78890 @@ -320,7 +320,7 @@ static void rq_cq_reap(struct svcxprt_rd
78891 }
78892
78893 if (ctxt)
78894 - atomic_inc(&rdma_stat_rq_prod);
78895 + atomic_inc_unchecked(&rdma_stat_rq_prod);
78896
78897 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
78898 /*
78899 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rd
78900 return;
78901
78902 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
78903 - atomic_inc(&rdma_stat_sq_poll);
78904 + atomic_inc_unchecked(&rdma_stat_sq_poll);
78905 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
78906 if (wc.status != IB_WC_SUCCESS)
78907 /* Close the transport */
78908 @@ -410,7 +410,7 @@ static void sq_cq_reap(struct svcxprt_rd
78909 }
78910
78911 if (ctxt)
78912 - atomic_inc(&rdma_stat_sq_prod);
78913 + atomic_inc_unchecked(&rdma_stat_sq_prod);
78914 }
78915
78916 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
78917 @@ -1271,7 +1271,7 @@ int svc_rdma_send(struct svcxprt_rdma *x
78918 spin_lock_bh(&xprt->sc_lock);
78919 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
78920 spin_unlock_bh(&xprt->sc_lock);
78921 - atomic_inc(&rdma_stat_sq_starve);
78922 + atomic_inc_unchecked(&rdma_stat_sq_starve);
78923
78924 /* See if we can opportunistically reap SQ WR to make room */
78925 sq_cq_reap(xprt);
78926 diff -urNp linux-2.6.39.2/net/sysctl_net.c linux-2.6.39.2/net/sysctl_net.c
78927 --- linux-2.6.39.2/net/sysctl_net.c 2011-05-19 00:06:34.000000000 -0400
78928 +++ linux-2.6.39.2/net/sysctl_net.c 2011-05-22 19:41:42.000000000 -0400
78929 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ct
78930 struct ctl_table *table)
78931 {
78932 /* Allow network administrator to have same access as root. */
78933 - if (capable(CAP_NET_ADMIN)) {
78934 + if (capable_nolog(CAP_NET_ADMIN)) {
78935 int mode = (table->mode >> 6) & 7;
78936 return (mode << 6) | (mode << 3) | mode;
78937 }
78938 diff -urNp linux-2.6.39.2/net/unix/af_unix.c linux-2.6.39.2/net/unix/af_unix.c
78939 --- linux-2.6.39.2/net/unix/af_unix.c 2011-05-19 00:06:34.000000000 -0400
78940 +++ linux-2.6.39.2/net/unix/af_unix.c 2011-05-22 19:41:42.000000000 -0400
78941 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(stru
78942 err = -ECONNREFUSED;
78943 if (!S_ISSOCK(inode->i_mode))
78944 goto put_fail;
78945 +
78946 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78947 + err = -EACCES;
78948 + goto put_fail;
78949 + }
78950 +
78951 u = unix_find_socket_byinode(inode);
78952 if (!u)
78953 goto put_fail;
78954 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(stru
78955 if (u) {
78956 struct dentry *dentry;
78957 dentry = unix_sk(u)->dentry;
78958 +
78959 + if (!gr_handle_chroot_unix(u->sk_peer_pid)) {
78960 + err = -EPERM;
78961 + sock_put(u);
78962 + goto fail;
78963 + }
78964 +
78965 if (dentry)
78966 touch_atime(unix_sk(u)->mnt, dentry);
78967 } else
78968 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock
78969 err = security_path_mknod(&nd.path, dentry, mode, 0);
78970 if (err)
78971 goto out_mknod_drop_write;
78972 + if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
78973 + err = -EACCES;
78974 + goto out_mknod_drop_write;
78975 + }
78976 err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
78977 out_mknod_drop_write:
78978 mnt_drop_write(nd.path.mnt);
78979 if (err)
78980 goto out_mknod_dput;
78981 +
78982 + gr_handle_create(dentry, nd.path.mnt);
78983 +
78984 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
78985 dput(nd.path.dentry);
78986 nd.path.dentry = dentry;
78987 @@ -894,6 +914,11 @@ out_mknod_drop_write:
78988 goto out_unlock;
78989 }
78990
78991 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78992 + put_pid(sk->sk_peer_pid);
78993 + sk->sk_peer_pid = get_pid(task_tgid(current));
78994 +#endif
78995 +
78996 list = &unix_socket_table[addr->hash];
78997 } else {
78998 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
78999 @@ -2255,7 +2280,11 @@ static int unix_seq_show(struct seq_file
79000 unix_state_lock(s);
79001
79002 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
79003 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79004 + NULL,
79005 +#else
79006 s,
79007 +#endif
79008 atomic_read(&s->sk_refcnt),
79009 0,
79010 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
79011 diff -urNp linux-2.6.39.2/net/wireless/wext-core.c linux-2.6.39.2/net/wireless/wext-core.c
79012 --- linux-2.6.39.2/net/wireless/wext-core.c 2011-05-19 00:06:34.000000000 -0400
79013 +++ linux-2.6.39.2/net/wireless/wext-core.c 2011-05-22 19:36:35.000000000 -0400
79014 @@ -746,8 +746,7 @@ static int ioctl_standard_iw_point(struc
79015 */
79016
79017 /* Support for very large requests */
79018 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79019 - (user_length > descr->max_tokens)) {
79020 + if (user_length > descr->max_tokens) {
79021 /* Allow userspace to GET more than max so
79022 * we can support any size GET requests.
79023 * There is still a limit : -ENOMEM.
79024 @@ -784,22 +783,6 @@ static int ioctl_standard_iw_point(struc
79025 }
79026 }
79027
79028 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79029 - /*
79030 - * If this is a GET, but not NOMAX, it means that the extra
79031 - * data is not bounded by userspace, but by max_tokens. Thus
79032 - * set the length to max_tokens. This matches the extra data
79033 - * allocation.
79034 - * The driver should fill it with the number of tokens it
79035 - * provided, and it may check iwp->length rather than having
79036 - * knowledge of max_tokens. If the driver doesn't change the
79037 - * iwp->length, this ioctl just copies back max_token tokens
79038 - * filled with zeroes. Hopefully the driver isn't claiming
79039 - * them to be valid data.
79040 - */
79041 - iwp->length = descr->max_tokens;
79042 - }
79043 -
79044 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79045
79046 iwp->length += essid_compat;
79047 diff -urNp linux-2.6.39.2/net/xfrm/xfrm_policy.c linux-2.6.39.2/net/xfrm/xfrm_policy.c
79048 --- linux-2.6.39.2/net/xfrm/xfrm_policy.c 2011-05-19 00:06:34.000000000 -0400
79049 +++ linux-2.6.39.2/net/xfrm/xfrm_policy.c 2011-05-22 19:36:35.000000000 -0400
79050 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm
79051 {
79052 policy->walk.dead = 1;
79053
79054 - atomic_inc(&policy->genid);
79055 + atomic_inc_unchecked(&policy->genid);
79056
79057 if (del_timer(&policy->timer))
79058 xfrm_pol_put(policy);
79059 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct x
79060 hlist_add_head(&policy->bydst, chain);
79061 xfrm_pol_hold(policy);
79062 net->xfrm.policy_count[dir]++;
79063 - atomic_inc(&flow_cache_genid);
79064 + atomic_inc_unchecked(&flow_cache_genid);
79065 if (delpol)
79066 __xfrm_policy_unlink(delpol, dir);
79067 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
79068 @@ -1527,7 +1527,7 @@ free_dst:
79069 goto out;
79070 }
79071
79072 -static int inline
79073 +static inline int
79074 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79075 {
79076 if (!*target) {
79077 @@ -1539,7 +1539,7 @@ xfrm_dst_alloc_copy(void **target, const
79078 return 0;
79079 }
79080
79081 -static int inline
79082 +static inline int
79083 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79084 {
79085 #ifdef CONFIG_XFRM_SUB_POLICY
79086 @@ -1551,7 +1551,7 @@ xfrm_dst_update_parent(struct dst_entry
79087 #endif
79088 }
79089
79090 -static int inline
79091 +static inline int
79092 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79093 {
79094 #ifdef CONFIG_XFRM_SUB_POLICY
79095 @@ -1645,7 +1645,7 @@ xfrm_resolve_and_create_bundle(struct xf
79096
79097 xdst->num_pols = num_pols;
79098 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79099 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79100 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79101
79102 return xdst;
79103 }
79104 @@ -2332,7 +2332,7 @@ static int xfrm_bundle_ok(struct xfrm_ds
79105 if (xdst->xfrm_genid != dst->xfrm->genid)
79106 return 0;
79107 if (xdst->num_pols > 0 &&
79108 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79109 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79110 return 0;
79111
79112 mtu = dst_mtu(dst->child);
79113 @@ -2860,7 +2860,7 @@ static int xfrm_policy_migrate(struct xf
79114 sizeof(pol->xfrm_vec[i].saddr));
79115 pol->xfrm_vec[i].encap_family = mp->new_family;
79116 /* flush bundles */
79117 - atomic_inc(&pol->genid);
79118 + atomic_inc_unchecked(&pol->genid);
79119 }
79120 }
79121
79122 diff -urNp linux-2.6.39.2/net/xfrm/xfrm_user.c linux-2.6.39.2/net/xfrm/xfrm_user.c
79123 --- linux-2.6.39.2/net/xfrm/xfrm_user.c 2011-05-19 00:06:34.000000000 -0400
79124 +++ linux-2.6.39.2/net/xfrm/xfrm_user.c 2011-05-22 19:36:35.000000000 -0400
79125 @@ -1394,6 +1394,8 @@ static int copy_to_user_tmpl(struct xfrm
79126 struct xfrm_user_tmpl vec[XFRM_MAX_DEPTH];
79127 int i;
79128
79129 + pax_track_stack();
79130 +
79131 if (xp->xfrm_nr == 0)
79132 return 0;
79133
79134 @@ -2062,6 +2064,8 @@ static int xfrm_do_migrate(struct sk_buf
79135 int err;
79136 int n = 0;
79137
79138 + pax_track_stack();
79139 +
79140 if (attrs[XFRMA_MIGRATE] == NULL)
79141 return -EINVAL;
79142
79143 diff -urNp linux-2.6.39.2/scripts/basic/fixdep.c linux-2.6.39.2/scripts/basic/fixdep.c
79144 --- linux-2.6.39.2/scripts/basic/fixdep.c 2011-05-19 00:06:34.000000000 -0400
79145 +++ linux-2.6.39.2/scripts/basic/fixdep.c 2011-05-22 19:36:35.000000000 -0400
79146 @@ -235,9 +235,9 @@ static void use_config(const char *m, in
79147
79148 static void parse_config_file(const char *map, size_t len)
79149 {
79150 - const int *end = (const int *) (map + len);
79151 + const unsigned int *end = (const unsigned int *) (map + len);
79152 /* start at +1, so that p can never be < map */
79153 - const int *m = (const int *) map + 1;
79154 + const unsigned int *m = (const unsigned int *) map + 1;
79155 const char *p, *q;
79156
79157 for (; m < end; m++) {
79158 @@ -405,7 +405,7 @@ static void print_deps(void)
79159 static void traps(void)
79160 {
79161 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79162 - int *p = (int *)test;
79163 + unsigned int *p = (unsigned int *)test;
79164
79165 if (*p != INT_CONF) {
79166 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79167 diff -urNp linux-2.6.39.2/scripts/dtc/flattree.c linux-2.6.39.2/scripts/dtc/flattree.c
79168 --- linux-2.6.39.2/scripts/dtc/flattree.c 2011-05-19 00:06:34.000000000 -0400
79169 +++ linux-2.6.39.2/scripts/dtc/flattree.c 2011-05-22 19:36:35.000000000 -0400
79170 @@ -104,7 +104,7 @@ static void bin_emit_property(void *e, s
79171 bin_emit_cell(e, FDT_PROP);
79172 }
79173
79174 -static struct emitter bin_emitter = {
79175 +static const struct emitter bin_emitter = {
79176 .cell = bin_emit_cell,
79177 .string = bin_emit_string,
79178 .align = bin_emit_align,
79179 @@ -230,7 +230,7 @@ static void asm_emit_property(void *e, s
79180 asm_emit_cell(e, FDT_PROP);
79181 }
79182
79183 -static struct emitter asm_emitter = {
79184 +static const struct emitter asm_emitter = {
79185 .cell = asm_emit_cell,
79186 .string = asm_emit_string,
79187 .align = asm_emit_align,
79188 diff -urNp linux-2.6.39.2/scripts/Makefile.build linux-2.6.39.2/scripts/Makefile.build
79189 --- linux-2.6.39.2/scripts/Makefile.build 2011-05-19 00:06:34.000000000 -0400
79190 +++ linux-2.6.39.2/scripts/Makefile.build 2011-06-03 01:15:00.000000000 -0400
79191 @@ -93,7 +93,7 @@ endif
79192 endif
79193
79194 # Do not include host rules unless needed
79195 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79196 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
79197 include scripts/Makefile.host
79198 endif
79199
79200 diff -urNp linux-2.6.39.2/scripts/Makefile.clean linux-2.6.39.2/scripts/Makefile.clean
79201 --- linux-2.6.39.2/scripts/Makefile.clean 2011-05-19 00:06:34.000000000 -0400
79202 +++ linux-2.6.39.2/scripts/Makefile.clean 2011-06-03 01:16:02.000000000 -0400
79203 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subd
79204 __clean-files := $(extra-y) $(always) \
79205 $(targets) $(clean-files) \
79206 $(host-progs) \
79207 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79208 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79209 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79210
79211 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79212
79213 diff -urNp linux-2.6.39.2/scripts/Makefile.host linux-2.6.39.2/scripts/Makefile.host
79214 --- linux-2.6.39.2/scripts/Makefile.host 2011-05-19 00:06:34.000000000 -0400
79215 +++ linux-2.6.39.2/scripts/Makefile.host 2011-06-03 01:17:12.000000000 -0400
79216 @@ -31,6 +31,7 @@
79217 # Note: Shared libraries consisting of C++ files are not supported
79218
79219 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79220 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79221
79222 # C code
79223 # Executables compiled from a single .c file
79224 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(hos
79225 # Shared libaries (only .c supported)
79226 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79227 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79228 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79229 # Remove .so files from "xxx-objs"
79230 host-cobjs := $(filter-out %.so,$(host-cobjs))
79231
79232 diff -urNp linux-2.6.39.2/scripts/mod/file2alias.c linux-2.6.39.2/scripts/mod/file2alias.c
79233 --- linux-2.6.39.2/scripts/mod/file2alias.c 2011-05-19 00:06:34.000000000 -0400
79234 +++ linux-2.6.39.2/scripts/mod/file2alias.c 2011-05-22 19:36:35.000000000 -0400
79235 @@ -72,7 +72,7 @@ static void device_id_check(const char *
79236 unsigned long size, unsigned long id_size,
79237 void *symval)
79238 {
79239 - int i;
79240 + unsigned int i;
79241
79242 if (size % id_size || size < id_size) {
79243 if (cross_build != 0)
79244 @@ -102,7 +102,7 @@ static void device_id_check(const char *
79245 /* USB is special because the bcdDevice can be matched against a numeric range */
79246 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79247 static void do_usb_entry(struct usb_device_id *id,
79248 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79249 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79250 unsigned char range_lo, unsigned char range_hi,
79251 unsigned char max, struct module *mod)
79252 {
79253 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *sy
79254 for (i = 0; i < count; i++) {
79255 const char *id = (char *)devs[i].id;
79256 char acpi_id[sizeof(devs[0].id)];
79257 - int j;
79258 + unsigned int j;
79259
79260 buf_printf(&mod->dev_table_buf,
79261 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79262 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *sy
79263
79264 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79265 const char *id = (char *)card->devs[j].id;
79266 - int i2, j2;
79267 + unsigned int i2, j2;
79268 int dup = 0;
79269
79270 if (!id[0])
79271 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *sy
79272 /* add an individual alias for every device entry */
79273 if (!dup) {
79274 char acpi_id[sizeof(card->devs[0].id)];
79275 - int k;
79276 + unsigned int k;
79277
79278 buf_printf(&mod->dev_table_buf,
79279 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79280 @@ -768,7 +768,7 @@ static void dmi_ascii_filter(char *d, co
79281 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79282 char *alias)
79283 {
79284 - int i, j;
79285 + unsigned int i, j;
79286
79287 sprintf(alias, "dmi*");
79288
79289 diff -urNp linux-2.6.39.2/scripts/mod/modpost.c linux-2.6.39.2/scripts/mod/modpost.c
79290 --- linux-2.6.39.2/scripts/mod/modpost.c 2011-05-19 00:06:34.000000000 -0400
79291 +++ linux-2.6.39.2/scripts/mod/modpost.c 2011-05-22 19:36:35.000000000 -0400
79292 @@ -896,6 +896,7 @@ enum mismatch {
79293 ANY_INIT_TO_ANY_EXIT,
79294 ANY_EXIT_TO_ANY_INIT,
79295 EXPORT_TO_INIT_EXIT,
79296 + DATA_TO_TEXT
79297 };
79298
79299 struct sectioncheck {
79300 @@ -1004,6 +1005,12 @@ const struct sectioncheck sectioncheck[]
79301 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79302 .mismatch = EXPORT_TO_INIT_EXIT,
79303 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79304 +},
79305 +/* Do not reference code from writable data */
79306 +{
79307 + .fromsec = { DATA_SECTIONS, NULL },
79308 + .tosec = { TEXT_SECTIONS, NULL },
79309 + .mismatch = DATA_TO_TEXT
79310 }
79311 };
79312
79313 @@ -1126,10 +1133,10 @@ static Elf_Sym *find_elf_symbol(struct e
79314 continue;
79315 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79316 continue;
79317 - if (sym->st_value == addr)
79318 - return sym;
79319 /* Find a symbol nearby - addr are maybe negative */
79320 d = sym->st_value - addr;
79321 + if (d == 0)
79322 + return sym;
79323 if (d < 0)
79324 d = addr - sym->st_value;
79325 if (d < distance) {
79326 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const ch
79327 tosym, prl_to, prl_to, tosym);
79328 free(prl_to);
79329 break;
79330 + case DATA_TO_TEXT:
79331 +/*
79332 + fprintf(stderr,
79333 + "The variable %s references\n"
79334 + "the %s %s%s%s\n",
79335 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79336 +*/
79337 + break;
79338 }
79339 fprintf(stderr, "\n");
79340 }
79341 @@ -1731,7 +1746,7 @@ void __attribute__((format(printf, 2, 3)
79342 va_end(ap);
79343 }
79344
79345 -void buf_write(struct buffer *buf, const char *s, int len)
79346 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79347 {
79348 if (buf->size - buf->pos < len) {
79349 buf->size += len + SZ;
79350 @@ -1943,7 +1958,7 @@ static void write_if_changed(struct buff
79351 if (fstat(fileno(file), &st) < 0)
79352 goto close_write;
79353
79354 - if (st.st_size != b->pos)
79355 + if (st.st_size != (off_t)b->pos)
79356 goto close_write;
79357
79358 tmp = NOFAIL(malloc(b->pos));
79359 diff -urNp linux-2.6.39.2/scripts/mod/modpost.h linux-2.6.39.2/scripts/mod/modpost.h
79360 --- linux-2.6.39.2/scripts/mod/modpost.h 2011-05-19 00:06:34.000000000 -0400
79361 +++ linux-2.6.39.2/scripts/mod/modpost.h 2011-05-22 19:36:35.000000000 -0400
79362 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *e
79363
79364 struct buffer {
79365 char *p;
79366 - int pos;
79367 - int size;
79368 + unsigned int pos;
79369 + unsigned int size;
79370 };
79371
79372 void __attribute__((format(printf, 2, 3)))
79373 buf_printf(struct buffer *buf, const char *fmt, ...);
79374
79375 void
79376 -buf_write(struct buffer *buf, const char *s, int len);
79377 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79378
79379 struct module {
79380 struct module *next;
79381 diff -urNp linux-2.6.39.2/scripts/mod/sumversion.c linux-2.6.39.2/scripts/mod/sumversion.c
79382 --- linux-2.6.39.2/scripts/mod/sumversion.c 2011-05-19 00:06:34.000000000 -0400
79383 +++ linux-2.6.39.2/scripts/mod/sumversion.c 2011-05-22 19:36:35.000000000 -0400
79384 @@ -470,7 +470,7 @@ static void write_version(const char *fi
79385 goto out;
79386 }
79387
79388 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79389 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79390 warn("writing sum in %s failed: %s\n",
79391 filename, strerror(errno));
79392 goto out;
79393 diff -urNp linux-2.6.39.2/scripts/pnmtologo.c linux-2.6.39.2/scripts/pnmtologo.c
79394 --- linux-2.6.39.2/scripts/pnmtologo.c 2011-05-19 00:06:34.000000000 -0400
79395 +++ linux-2.6.39.2/scripts/pnmtologo.c 2011-05-22 19:36:35.000000000 -0400
79396 @@ -237,14 +237,14 @@ static void write_header(void)
79397 fprintf(out, " * Linux logo %s\n", logoname);
79398 fputs(" */\n\n", out);
79399 fputs("#include <linux/linux_logo.h>\n\n", out);
79400 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79401 + fprintf(out, "static unsigned char %s_data[] = {\n",
79402 logoname);
79403 }
79404
79405 static void write_footer(void)
79406 {
79407 fputs("\n};\n\n", out);
79408 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79409 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79410 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79411 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79412 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79413 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79414 fputs("\n};\n\n", out);
79415
79416 /* write logo clut */
79417 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79418 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79419 logoname);
79420 write_hex_cnt = 0;
79421 for (i = 0; i < logo_clutsize; i++) {
79422 diff -urNp linux-2.6.39.2/security/apparmor/lsm.c linux-2.6.39.2/security/apparmor/lsm.c
79423 --- linux-2.6.39.2/security/apparmor/lsm.c 2011-06-25 12:55:23.000000000 -0400
79424 +++ linux-2.6.39.2/security/apparmor/lsm.c 2011-06-25 13:00:28.000000000 -0400
79425 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struc
79426 return error;
79427 }
79428
79429 -static struct security_operations apparmor_ops = {
79430 +static struct security_operations apparmor_ops __read_only = {
79431 .name = "apparmor",
79432
79433 .ptrace_access_check = apparmor_ptrace_access_check,
79434 @@ -672,7 +672,7 @@ static struct security_operations apparm
79435 static int param_set_aabool(const char *val, const struct kernel_param *kp);
79436 static int param_get_aabool(char *buffer, const struct kernel_param *kp);
79437 #define param_check_aabool(name, p) __param_check(name, p, int)
79438 -static struct kernel_param_ops param_ops_aabool = {
79439 +static const struct kernel_param_ops param_ops_aabool = {
79440 .set = param_set_aabool,
79441 .get = param_get_aabool
79442 };
79443 @@ -680,7 +680,7 @@ static struct kernel_param_ops param_ops
79444 static int param_set_aauint(const char *val, const struct kernel_param *kp);
79445 static int param_get_aauint(char *buffer, const struct kernel_param *kp);
79446 #define param_check_aauint(name, p) __param_check(name, p, int)
79447 -static struct kernel_param_ops param_ops_aauint = {
79448 +static const struct kernel_param_ops param_ops_aauint = {
79449 .set = param_set_aauint,
79450 .get = param_get_aauint
79451 };
79452 @@ -688,7 +688,7 @@ static struct kernel_param_ops param_ops
79453 static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp);
79454 static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp);
79455 #define param_check_aalockpolicy(name, p) __param_check(name, p, int)
79456 -static struct kernel_param_ops param_ops_aalockpolicy = {
79457 +static const struct kernel_param_ops param_ops_aalockpolicy = {
79458 .set = param_set_aalockpolicy,
79459 .get = param_get_aalockpolicy
79460 };
79461 diff -urNp linux-2.6.39.2/security/commoncap.c linux-2.6.39.2/security/commoncap.c
79462 --- linux-2.6.39.2/security/commoncap.c 2011-05-19 00:06:34.000000000 -0400
79463 +++ linux-2.6.39.2/security/commoncap.c 2011-05-22 20:28:59.000000000 -0400
79464 @@ -28,6 +28,7 @@
79465 #include <linux/prctl.h>
79466 #include <linux/securebits.h>
79467 #include <linux/user_namespace.h>
79468 +#include <net/sock.h>
79469
79470 /*
79471 * If a non-root user executes a setuid-root binary in
79472 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, st
79473
79474 int cap_netlink_recv(struct sk_buff *skb, int cap)
79475 {
79476 - if (!cap_raised(current_cap(), cap))
79477 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
79478 return -EPERM;
79479 return 0;
79480 }
79481 @@ -580,6 +581,9 @@ int cap_bprm_secureexec(struct linux_bin
79482 {
79483 const struct cred *cred = current_cred();
79484
79485 + if (gr_acl_enable_at_secure())
79486 + return 1;
79487 +
79488 if (cred->uid != 0) {
79489 if (bprm->cap_effective)
79490 return 1;
79491 diff -urNp linux-2.6.39.2/security/integrity/ima/ima_api.c linux-2.6.39.2/security/integrity/ima/ima_api.c
79492 --- linux-2.6.39.2/security/integrity/ima/ima_api.c 2011-05-19 00:06:34.000000000 -0400
79493 +++ linux-2.6.39.2/security/integrity/ima/ima_api.c 2011-05-22 19:36:35.000000000 -0400
79494 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *ino
79495 int result;
79496
79497 /* can overflow, only indicator */
79498 - atomic_long_inc(&ima_htable.violations);
79499 + atomic_long_inc_unchecked(&ima_htable.violations);
79500
79501 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79502 if (!entry) {
79503 diff -urNp linux-2.6.39.2/security/integrity/ima/ima_fs.c linux-2.6.39.2/security/integrity/ima/ima_fs.c
79504 --- linux-2.6.39.2/security/integrity/ima/ima_fs.c 2011-05-19 00:06:34.000000000 -0400
79505 +++ linux-2.6.39.2/security/integrity/ima/ima_fs.c 2011-05-22 19:36:35.000000000 -0400
79506 @@ -28,12 +28,12 @@
79507 static int valid_policy = 1;
79508 #define TMPBUFLEN 12
79509 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79510 - loff_t *ppos, atomic_long_t *val)
79511 + loff_t *ppos, atomic_long_unchecked_t *val)
79512 {
79513 char tmpbuf[TMPBUFLEN];
79514 ssize_t len;
79515
79516 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79517 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79518 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79519 }
79520
79521 diff -urNp linux-2.6.39.2/security/integrity/ima/ima.h linux-2.6.39.2/security/integrity/ima/ima.h
79522 --- linux-2.6.39.2/security/integrity/ima/ima.h 2011-05-19 00:06:34.000000000 -0400
79523 +++ linux-2.6.39.2/security/integrity/ima/ima.h 2011-05-22 19:36:35.000000000 -0400
79524 @@ -85,8 +85,8 @@ void ima_add_violation(struct inode *ino
79525 extern spinlock_t ima_queue_lock;
79526
79527 struct ima_h_table {
79528 - atomic_long_t len; /* number of stored measurements in the list */
79529 - atomic_long_t violations;
79530 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79531 + atomic_long_unchecked_t violations;
79532 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79533 };
79534 extern struct ima_h_table ima_htable;
79535 diff -urNp linux-2.6.39.2/security/integrity/ima/ima_queue.c linux-2.6.39.2/security/integrity/ima/ima_queue.c
79536 --- linux-2.6.39.2/security/integrity/ima/ima_queue.c 2011-05-19 00:06:34.000000000 -0400
79537 +++ linux-2.6.39.2/security/integrity/ima/ima_queue.c 2011-05-22 19:36:35.000000000 -0400
79538 @@ -79,7 +79,7 @@ static int ima_add_digest_entry(struct i
79539 INIT_LIST_HEAD(&qe->later);
79540 list_add_tail_rcu(&qe->later, &ima_measurements);
79541
79542 - atomic_long_inc(&ima_htable.len);
79543 + atomic_long_inc_unchecked(&ima_htable.len);
79544 key = ima_hash_key(entry->digest);
79545 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79546 return 0;
79547 diff -urNp linux-2.6.39.2/security/Kconfig linux-2.6.39.2/security/Kconfig
79548 --- linux-2.6.39.2/security/Kconfig 2011-05-19 00:06:34.000000000 -0400
79549 +++ linux-2.6.39.2/security/Kconfig 2011-06-03 01:13:26.000000000 -0400
79550 @@ -4,6 +4,554 @@
79551
79552 menu "Security options"
79553
79554 +source grsecurity/Kconfig
79555 +
79556 +menu "PaX"
79557 +
79558 + config ARCH_TRACK_EXEC_LIMIT
79559 + bool
79560 +
79561 + config PAX_PER_CPU_PGD
79562 + bool
79563 +
79564 + config TASK_SIZE_MAX_SHIFT
79565 + int
79566 + depends on X86_64
79567 + default 47 if !PAX_PER_CPU_PGD
79568 + default 42 if PAX_PER_CPU_PGD
79569 +
79570 + config PAX_ENABLE_PAE
79571 + bool
79572 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79573 +
79574 +config PAX
79575 + bool "Enable various PaX features"
79576 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79577 + help
79578 + This allows you to enable various PaX features. PaX adds
79579 + intrusion prevention mechanisms to the kernel that reduce
79580 + the risks posed by exploitable memory corruption bugs.
79581 +
79582 +menu "PaX Control"
79583 + depends on PAX
79584 +
79585 +config PAX_SOFTMODE
79586 + bool 'Support soft mode'
79587 + select PAX_PT_PAX_FLAGS
79588 + help
79589 + Enabling this option will allow you to run PaX in soft mode, that
79590 + is, PaX features will not be enforced by default, only on executables
79591 + marked explicitly. You must also enable PT_PAX_FLAGS support as it
79592 + is the only way to mark executables for soft mode use.
79593 +
79594 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79595 + line option on boot. Furthermore you can control various PaX features
79596 + at runtime via the entries in /proc/sys/kernel/pax.
79597 +
79598 +config PAX_EI_PAX
79599 + bool 'Use legacy ELF header marking'
79600 + help
79601 + Enabling this option will allow you to control PaX features on
79602 + a per executable basis via the 'chpax' utility available at
79603 + http://pax.grsecurity.net/. The control flags will be read from
79604 + an otherwise reserved part of the ELF header. This marking has
79605 + numerous drawbacks (no support for soft-mode, toolchain does not
79606 + know about the non-standard use of the ELF header) therefore it
79607 + has been deprecated in favour of PT_PAX_FLAGS support.
79608 +
79609 + Note that if you enable PT_PAX_FLAGS marking support as well,
79610 + the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
79611 +
79612 +config PAX_PT_PAX_FLAGS
79613 + bool 'Use ELF program header marking'
79614 + help
79615 + Enabling this option will allow you to control PaX features on
79616 + a per executable basis via the 'paxctl' utility available at
79617 + http://pax.grsecurity.net/. The control flags will be read from
79618 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79619 + has the benefits of supporting both soft mode and being fully
79620 + integrated into the toolchain (the binutils patch is available
79621 + from http://pax.grsecurity.net).
79622 +
79623 + If your toolchain does not support PT_PAX_FLAGS markings,
79624 + you can create one in most cases with 'paxctl -C'.
79625 +
79626 + Note that if you enable the legacy EI_PAX marking support as well,
79627 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79628 +
79629 +choice
79630 + prompt 'MAC system integration'
79631 + default PAX_HAVE_ACL_FLAGS
79632 + help
79633 + Mandatory Access Control systems have the option of controlling
79634 + PaX flags on a per executable basis, choose the method supported
79635 + by your particular system.
79636 +
79637 + - "none": if your MAC system does not interact with PaX,
79638 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79639 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79640 +
79641 + NOTE: this option is for developers/integrators only.
79642 +
79643 + config PAX_NO_ACL_FLAGS
79644 + bool 'none'
79645 +
79646 + config PAX_HAVE_ACL_FLAGS
79647 + bool 'direct'
79648 +
79649 + config PAX_HOOK_ACL_FLAGS
79650 + bool 'hook'
79651 +endchoice
79652 +
79653 +endmenu
79654 +
79655 +menu "Non-executable pages"
79656 + depends on PAX
79657 +
79658 +config PAX_NOEXEC
79659 + bool "Enforce non-executable pages"
79660 + depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86)
79661 + help
79662 + By design some architectures do not allow for protecting memory
79663 + pages against execution or even if they do, Linux does not make
79664 + use of this feature. In practice this means that if a page is
79665 + readable (such as the stack or heap) it is also executable.
79666 +
79667 + There is a well known exploit technique that makes use of this
79668 + fact and a common programming mistake where an attacker can
79669 + introduce code of his choice somewhere in the attacked program's
79670 + memory (typically the stack or the heap) and then execute it.
79671 +
79672 + If the attacked program was running with different (typically
79673 + higher) privileges than that of the attacker, then he can elevate
79674 + his own privilege level (e.g. get a root shell, write to files for
79675 + which he does not have write access to, etc).
79676 +
79677 + Enabling this option will let you choose from various features
79678 + that prevent the injection and execution of 'foreign' code in
79679 + a program.
79680 +
79681 + This will also break programs that rely on the old behaviour and
79682 + expect that dynamically allocated memory via the malloc() family
79683 + of functions is executable (which it is not). Notable examples
79684 + are the XFree86 4.x server, the java runtime and wine.
79685 +
79686 +config PAX_PAGEEXEC
79687 + bool "Paging based non-executable pages"
79688 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
79689 + select S390_SWITCH_AMODE if S390
79690 + select S390_EXEC_PROTECT if S390
79691 + select ARCH_TRACK_EXEC_LIMIT if X86_32
79692 + help
79693 + This implementation is based on the paging feature of the CPU.
79694 + On i386 without hardware non-executable bit support there is a
79695 + variable but usually low performance impact, however on Intel's
79696 + P4 core based CPUs it is very high so you should not enable this
79697 + for kernels meant to be used on such CPUs.
79698 +
79699 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
79700 + with hardware non-executable bit support there is no performance
79701 + impact, on ppc the impact is negligible.
79702 +
79703 + Note that several architectures require various emulations due to
79704 + badly designed userland ABIs, this will cause a performance impact
79705 + but will disappear as soon as userland is fixed. For example, ppc
79706 + userland MUST have been built with secure-plt by a recent toolchain.
79707 +
79708 +config PAX_SEGMEXEC
79709 + bool "Segmentation based non-executable pages"
79710 + depends on PAX_NOEXEC && X86_32
79711 + help
79712 + This implementation is based on the segmentation feature of the
79713 + CPU and has a very small performance impact, however applications
79714 + will be limited to a 1.5 GB address space instead of the normal
79715 + 3 GB.
79716 +
79717 +config PAX_EMUTRAMP
79718 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
79719 + default y if PARISC
79720 + help
79721 + There are some programs and libraries that for one reason or
79722 + another attempt to execute special small code snippets from
79723 + non-executable memory pages. Most notable examples are the
79724 + signal handler return code generated by the kernel itself and
79725 + the GCC trampolines.
79726 +
79727 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
79728 + such programs will no longer work under your kernel.
79729 +
79730 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
79731 + utilities to enable trampoline emulation for the affected programs
79732 + yet still have the protection provided by the non-executable pages.
79733 +
79734 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
79735 + your system will not even boot.
79736 +
79737 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
79738 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
79739 + for the affected files.
79740 +
79741 + NOTE: enabling this feature *may* open up a loophole in the
79742 + protection provided by non-executable pages that an attacker
79743 + could abuse. Therefore the best solution is to not have any
79744 + files on your system that would require this option. This can
79745 + be achieved by not using libc5 (which relies on the kernel
79746 + signal handler return code) and not using or rewriting programs
79747 + that make use of the nested function implementation of GCC.
79748 + Skilled users can just fix GCC itself so that it implements
79749 + nested function calls in a way that does not interfere with PaX.
79750 +
79751 +config PAX_EMUSIGRT
79752 + bool "Automatically emulate sigreturn trampolines"
79753 + depends on PAX_EMUTRAMP && PARISC
79754 + default y
79755 + help
79756 + Enabling this option will have the kernel automatically detect
79757 + and emulate signal return trampolines executing on the stack
79758 + that would otherwise lead to task termination.
79759 +
79760 + This solution is intended as a temporary one for users with
79761 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
79762 + Modula-3 runtime, etc) or executables linked to such, basically
79763 + everything that does not specify its own SA_RESTORER function in
79764 + normal executable memory like glibc 2.1+ does.
79765 +
79766 + On parisc you MUST enable this option, otherwise your system will
79767 + not even boot.
79768 +
79769 + NOTE: this feature cannot be disabled on a per executable basis
79770 + and since it *does* open up a loophole in the protection provided
79771 + by non-executable pages, the best solution is to not have any
79772 + files on your system that would require this option.
79773 +
79774 +config PAX_MPROTECT
79775 + bool "Restrict mprotect()"
79776 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
79777 + help
79778 + Enabling this option will prevent programs from
79779 + - changing the executable status of memory pages that were
79780 + not originally created as executable,
79781 + - making read-only executable pages writable again,
79782 + - creating executable pages from anonymous memory,
79783 + - making read-only-after-relocations (RELRO) data pages writable again.
79784 +
79785 + You should say Y here to complete the protection provided by
79786 + the enforcement of non-executable pages.
79787 +
79788 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79789 + this feature on a per file basis.
79790 +
79791 +config PAX_MPROTECT_COMPAT
79792 + bool "Use legacy/compat protection demoting (read help)"
79793 + depends on PAX_MPROTECT
79794 + default n
79795 + help
79796 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
79797 + by sending the proper error code to the application. For some broken
79798 + userland, this can cause problems with Python or other applications. The
79799 + current implementation however allows for applications like clamav to
79800 + detect if JIT compilation/execution is allowed and to fall back gracefully
79801 + to an interpreter-based mode if it does not. While we encourage everyone
79802 + to use the current implementation as-is and push upstream to fix broken
79803 + userland (note that the RWX logging option can assist with this), in some
79804 + environments this may not be possible. Having to disable MPROTECT
79805 + completely on certain binaries reduces the security benefit of PaX,
79806 + so this option is provided for those environments to revert to the old
79807 + behavior.
79808 +
79809 +config PAX_ELFRELOCS
79810 + bool "Allow ELF text relocations (read help)"
79811 + depends on PAX_MPROTECT
79812 + default n
79813 + help
79814 + Non-executable pages and mprotect() restrictions are effective
79815 + in preventing the introduction of new executable code into an
79816 + attacked task's address space. There remain only two venues
79817 + for this kind of attack: if the attacker can execute already
79818 + existing code in the attacked task then he can either have it
79819 + create and mmap() a file containing his code or have it mmap()
79820 + an already existing ELF library that does not have position
79821 + independent code in it and use mprotect() on it to make it
79822 + writable and copy his code there. While protecting against
79823 + the former approach is beyond PaX, the latter can be prevented
79824 + by having only PIC ELF libraries on one's system (which do not
79825 + need to relocate their code). If you are sure this is your case,
79826 + as is the case with all modern Linux distributions, then leave
79827 + this option disabled. You should say 'n' here.
79828 +
79829 +config PAX_ETEXECRELOCS
79830 + bool "Allow ELF ET_EXEC text relocations"
79831 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
79832 + select PAX_ELFRELOCS
79833 + default y
79834 + help
79835 + On some architectures there are incorrectly created applications
79836 + that require text relocations and would not work without enabling
79837 + this option. If you are an alpha, ia64 or parisc user, you should
79838 + enable this option and disable it once you have made sure that
79839 + none of your applications need it.
79840 +
79841 +config PAX_EMUPLT
79842 + bool "Automatically emulate ELF PLT"
79843 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
79844 + default y
79845 + help
79846 + Enabling this option will have the kernel automatically detect
79847 + and emulate the Procedure Linkage Table entries in ELF files.
79848 + On some architectures such entries are in writable memory, and
79849 + become non-executable leading to task termination. Therefore
79850 + it is mandatory that you enable this option on alpha, parisc,
79851 + sparc and sparc64, otherwise your system would not even boot.
79852 +
79853 + NOTE: this feature *does* open up a loophole in the protection
79854 + provided by the non-executable pages, therefore the proper
79855 + solution is to modify the toolchain to produce a PLT that does
79856 + not need to be writable.
79857 +
79858 +config PAX_DLRESOLVE
79859 + bool 'Emulate old glibc resolver stub'
79860 + depends on PAX_EMUPLT && SPARC
79861 + default n
79862 + help
79863 + This option is needed if userland has an old glibc (before 2.4)
79864 + that puts a 'save' instruction into the runtime generated resolver
79865 + stub that needs special emulation.
79866 +
79867 +config PAX_KERNEXEC
79868 + bool "Enforce non-executable kernel pages"
79869 + depends on PAX_NOEXEC && (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
79870 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
79871 + help
79872 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
79873 + that is, enabling this option will make it harder to inject
79874 + and execute 'foreign' code in kernel memory itself.
79875 +
79876 + Note that on x86_64 kernels there is a known regression when
79877 + this feature and KVM/VMX are both enabled in the host kernel.
79878 +
79879 +config PAX_KERNEXEC_MODULE_TEXT
79880 + int "Minimum amount of memory reserved for module code"
79881 + default "4"
79882 + depends on PAX_KERNEXEC && X86_32 && MODULES
79883 + help
79884 + Due to implementation details the kernel must reserve a fixed
79885 + amount of memory for module code at compile time that cannot be
79886 + changed at runtime. Here you can specify the minimum amount
79887 + in MB that will be reserved. Due to the same implementation
79888 + details this size will always be rounded up to the next 2/4 MB
79889 + boundary (depends on PAE) so the actually available memory for
79890 + module code will usually be more than this minimum.
79891 +
79892 + The default 4 MB should be enough for most users but if you have
79893 + an excessive number of modules (e.g., most distribution configs
79894 + compile many drivers as modules) or use huge modules such as
79895 + nvidia's kernel driver, you will need to adjust this amount.
79896 + A good rule of thumb is to look at your currently loaded kernel
79897 + modules and add up their sizes.
79898 +
79899 +endmenu
79900 +
79901 +menu "Address Space Layout Randomization"
79902 + depends on PAX
79903 +
79904 +config PAX_ASLR
79905 + bool "Address Space Layout Randomization"
79906 + depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
79907 + help
79908 + Many if not most exploit techniques rely on the knowledge of
79909 + certain addresses in the attacked program. The following options
79910 + will allow the kernel to apply a certain amount of randomization
79911 + to specific parts of the program thereby forcing an attacker to
79912 + guess them in most cases. Any failed guess will most likely crash
79913 + the attacked program which allows the kernel to detect such attempts
79914 + and react on them. PaX itself provides no reaction mechanisms,
79915 + instead it is strongly encouraged that you make use of Nergal's
79916 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
79917 + (http://www.grsecurity.net/) built-in crash detection features or
79918 + develop one yourself.
79919 +
79920 + By saying Y here you can choose to randomize the following areas:
79921 + - top of the task's kernel stack
79922 + - top of the task's userland stack
79923 + - base address for mmap() requests that do not specify one
79924 + (this includes all libraries)
79925 + - base address of the main executable
79926 +
79927 + It is strongly recommended to say Y here as address space layout
79928 + randomization has negligible impact on performance yet it provides
79929 + a very effective protection.
79930 +
79931 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79932 + this feature on a per file basis.
79933 +
79934 +config PAX_RANDKSTACK
79935 + bool "Randomize kernel stack base"
79936 + depends on PAX_ASLR && X86_TSC && X86
79937 + help
79938 + By saying Y here the kernel will randomize every task's kernel
79939 + stack on every system call. This will not only force an attacker
79940 + to guess it but also prevent him from making use of possible
79941 + leaked information about it.
79942 +
79943 + Since the kernel stack is a rather scarce resource, randomization
79944 + may cause unexpected stack overflows, therefore you should very
79945 + carefully test your system. Note that once enabled in the kernel
79946 + configuration, this feature cannot be disabled on a per file basis.
79947 +
79948 +config PAX_RANDUSTACK
79949 + bool "Randomize user stack base"
79950 + depends on PAX_ASLR
79951 + help
79952 + By saying Y here the kernel will randomize every task's userland
79953 + stack. The randomization is done in two steps where the second
79954 + one may apply a big amount of shift to the top of the stack and
79955 + cause problems for programs that want to use lots of memory (more
79956 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79957 + For this reason the second step can be controlled by 'chpax' or
79958 + 'paxctl' on a per file basis.
79959 +
79960 +config PAX_RANDMMAP
79961 + bool "Randomize mmap() base"
79962 + depends on PAX_ASLR
79963 + help
79964 + By saying Y here the kernel will use a randomized base address for
79965 + mmap() requests that do not specify one themselves. As a result
79966 + all dynamically loaded libraries will appear at random addresses
79967 + and therefore be harder to exploit by a technique where an attacker
79968 + attempts to execute library code for his purposes (e.g. spawn a
79969 + shell from an exploited program that is running at an elevated
79970 + privilege level).
79971 +
79972 + Furthermore, if a program is relinked as a dynamic ELF file, its
79973 + base address will be randomized as well, completing the full
79974 + randomization of the address space layout. Attacking such programs
79975 + becomes a guess game. You can find an example of doing this at
79976 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79977 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79978 +
79979 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79980 + feature on a per file basis.
79981 +
79982 +endmenu
79983 +
79984 +menu "Miscellaneous hardening features"
79985 +
79986 +config PAX_MEMORY_SANITIZE
79987 + bool "Sanitize all freed memory"
79988 + help
79989 + By saying Y here the kernel will erase memory pages as soon as they
79990 + are freed. This in turn reduces the lifetime of data stored in the
79991 + pages, making it less likely that sensitive information such as
79992 + passwords, cryptographic secrets, etc stay in memory for too long.
79993 +
79994 + This is especially useful for programs whose runtime is short, long
79995 + lived processes and the kernel itself benefit from this as long as
79996 + they operate on whole memory pages and ensure timely freeing of pages
79997 + that may hold sensitive information.
79998 +
79999 + The tradeoff is performance impact, on a single CPU system kernel
80000 + compilation sees a 3% slowdown, other systems and workloads may vary
80001 + and you are advised to test this feature on your expected workload
80002 + before deploying it.
80003 +
80004 + Note that this feature does not protect data stored in live pages,
80005 + e.g., process memory swapped to disk may stay there for a long time.
80006 +
80007 +config PAX_MEMORY_STACKLEAK
80008 + bool "Sanitize kernel stack"
80009 + depends on X86
80010 + help
80011 + By saying Y here the kernel will erase the kernel stack before it
80012 + returns from a system call. This in turn reduces the information
80013 + that a kernel stack leak bug can reveal.
80014 +
80015 + Note that such a bug can still leak information that was put on
80016 + the stack by the current system call (the one eventually triggering
80017 + the bug) but traces of earlier system calls on the kernel stack
80018 + cannot leak anymore.
80019 +
80020 + The tradeoff is performance impact: on a single CPU system kernel
80021 + compilation sees a 1% slowdown, other systems and workloads may vary
80022 + and you are advised to test this feature on your expected workload
80023 + before deploying it.
80024 +
80025 + Note: full support for this feature requires gcc with plugin support
80026 + so make sure your compiler is at least gcc 4.5.0 (cross compilation
80027 + is not supported). Using older gcc versions means that functions
80028 + with large enough stack frames may leave uninitialized memory behind
80029 + that may be exposed to a later syscall leaking the stack.
80030 +
80031 +config PAX_MEMORY_UDEREF
80032 + bool "Prevent invalid userland pointer dereference"
80033 + depends on X86 && !UML_X86 && !XEN
80034 + select PAX_PER_CPU_PGD if X86_64
80035 + help
80036 + By saying Y here the kernel will be prevented from dereferencing
80037 + userland pointers in contexts where the kernel expects only kernel
80038 + pointers. This is both a useful runtime debugging feature and a
80039 + security measure that prevents exploiting a class of kernel bugs.
80040 +
80041 + The tradeoff is that some virtualization solutions may experience
80042 + a huge slowdown and therefore you should not enable this feature
80043 + for kernels meant to run in such environments. Whether a given VM
80044 + solution is affected or not is best determined by simply trying it
80045 + out, the performance impact will be obvious right on boot as this
80046 + mechanism engages from very early on. A good rule of thumb is that
80047 + VMs running on CPUs without hardware virtualization support (i.e.,
80048 + the majority of IA-32 CPUs) will likely experience the slowdown.
80049 +
80050 +config PAX_REFCOUNT
80051 + bool "Prevent various kernel object reference counter overflows"
80052 + depends on GRKERNSEC && (X86 || SPARC64)
80053 + help
80054 + By saying Y here the kernel will detect and prevent overflowing
80055 + various (but not all) kinds of object reference counters. Such
80056 + overflows can normally occur due to bugs only and are often, if
80057 + not always, exploitable.
80058 +
80059 + The tradeoff is that data structures protected by an overflowed
80060 + refcount will never be freed and therefore will leak memory. Note
80061 + that this leak also happens even without this protection but in
80062 + that case the overflow can eventually trigger the freeing of the
80063 + data structure while it is still being used elsewhere, resulting
80064 + in the exploitable situation that this feature prevents.
80065 +
80066 + Since this has a negligible performance impact, you should enable
80067 + this feature.
80068 +
80069 +config PAX_USERCOPY
80070 + bool "Harden heap object copies between kernel and userland"
80071 + depends on X86 || PPC || SPARC
80072 + depends on GRKERNSEC && (SLAB || SLUB)
80073 + help
80074 + By saying Y here the kernel will enforce the size of heap objects
80075 + when they are copied in either direction between the kernel and
80076 + userland, even if only a part of the heap object is copied.
80077 +
80078 + Specifically, this checking prevents information leaking from the
80079 + kernel heap during kernel to userland copies (if the kernel heap
80080 + object is otherwise fully initialized) and prevents kernel heap
80081 + overflows during userland to kernel copies.
80082 +
80083 + Note that the current implementation provides the strictest bounds
80084 + checks for the SLUB allocator.
80085 +
80086 + Enabling this option also enables per-slab cache protection against
80087 + data in a given cache being copied into/out of via userland
80088 + accessors. Though the whitelist of regions will be reduced over
80089 + time, it notably protects important data structures like task structs.
80090 +
80091 + If frame pointers are enabled on x86, this option will also restrict
80092 + copies into and out of the kernel stack to local variables within a
80093 + single frame.
80094 +
80095 + Since this has a negligible performance impact, you should enable
80096 + this feature.
80097 +
80098 +endmenu
80099 +
80100 +endmenu
80101 +
80102 config KEYS
80103 bool "Enable access key retention support"
80104 help
80105 @@ -167,7 +715,7 @@ config INTEL_TXT
80106 config LSM_MMAP_MIN_ADDR
80107 int "Low address space for LSM to protect from user allocation"
80108 depends on SECURITY && SECURITY_SELINUX
80109 - default 65536
80110 + default 32768
80111 help
80112 This is the portion of low virtual memory which should be protected
80113 from userspace allocation. Keeping a user from writing to low pages
80114 diff -urNp linux-2.6.39.2/security/keys/keyring.c linux-2.6.39.2/security/keys/keyring.c
80115 --- linux-2.6.39.2/security/keys/keyring.c 2011-05-19 00:06:34.000000000 -0400
80116 +++ linux-2.6.39.2/security/keys/keyring.c 2011-05-22 19:36:35.000000000 -0400
80117 @@ -213,15 +213,15 @@ static long keyring_read(const struct ke
80118 ret = -EFAULT;
80119
80120 for (loop = 0; loop < klist->nkeys; loop++) {
80121 + key_serial_t serial;
80122 key = klist->keys[loop];
80123 + serial = key->serial;
80124
80125 tmp = sizeof(key_serial_t);
80126 if (tmp > buflen)
80127 tmp = buflen;
80128
80129 - if (copy_to_user(buffer,
80130 - &key->serial,
80131 - tmp) != 0)
80132 + if (copy_to_user(buffer, &serial, tmp))
80133 goto error;
80134
80135 buflen -= tmp;
80136 diff -urNp linux-2.6.39.2/security/min_addr.c linux-2.6.39.2/security/min_addr.c
80137 --- linux-2.6.39.2/security/min_addr.c 2011-05-19 00:06:34.000000000 -0400
80138 +++ linux-2.6.39.2/security/min_addr.c 2011-05-22 19:41:42.000000000 -0400
80139 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG
80140 */
80141 static void update_mmap_min_addr(void)
80142 {
80143 +#ifndef SPARC
80144 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80145 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80146 mmap_min_addr = dac_mmap_min_addr;
80147 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80148 #else
80149 mmap_min_addr = dac_mmap_min_addr;
80150 #endif
80151 +#endif
80152 }
80153
80154 /*
80155 diff -urNp linux-2.6.39.2/security/security.c linux-2.6.39.2/security/security.c
80156 --- linux-2.6.39.2/security/security.c 2011-05-19 00:06:34.000000000 -0400
80157 +++ linux-2.6.39.2/security/security.c 2011-05-22 19:41:42.000000000 -0400
80158 @@ -25,8 +25,8 @@ static __initdata char chosen_lsm[SECURI
80159 /* things that live in capability.c */
80160 extern void __init security_fixup_ops(struct security_operations *ops);
80161
80162 -static struct security_operations *security_ops;
80163 -static struct security_operations default_security_ops = {
80164 +static struct security_operations *security_ops __read_only;
80165 +static struct security_operations default_security_ops __read_only = {
80166 .name = "default",
80167 };
80168
80169 @@ -67,7 +67,9 @@ int __init security_init(void)
80170
80171 void reset_security_ops(void)
80172 {
80173 + pax_open_kernel();
80174 security_ops = &default_security_ops;
80175 + pax_close_kernel();
80176 }
80177
80178 /* Save user chosen LSM */
80179 diff -urNp linux-2.6.39.2/security/selinux/hooks.c linux-2.6.39.2/security/selinux/hooks.c
80180 --- linux-2.6.39.2/security/selinux/hooks.c 2011-05-19 00:06:34.000000000 -0400
80181 +++ linux-2.6.39.2/security/selinux/hooks.c 2011-05-22 19:41:42.000000000 -0400
80182 @@ -93,7 +93,6 @@
80183 #define NUM_SEL_MNT_OPTS 5
80184
80185 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
80186 -extern struct security_operations *security_ops;
80187
80188 /* SECMARK reference count */
80189 atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80190 @@ -5431,7 +5430,7 @@ static int selinux_key_getsecurity(struc
80191
80192 #endif
80193
80194 -static struct security_operations selinux_ops = {
80195 +static struct security_operations selinux_ops __read_only = {
80196 .name = "selinux",
80197
80198 .ptrace_access_check = selinux_ptrace_access_check,
80199 diff -urNp linux-2.6.39.2/security/selinux/include/xfrm.h linux-2.6.39.2/security/selinux/include/xfrm.h
80200 --- linux-2.6.39.2/security/selinux/include/xfrm.h 2011-05-19 00:06:34.000000000 -0400
80201 +++ linux-2.6.39.2/security/selinux/include/xfrm.h 2011-05-22 19:36:35.000000000 -0400
80202 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct s
80203
80204 static inline void selinux_xfrm_notify_policyload(void)
80205 {
80206 - atomic_inc(&flow_cache_genid);
80207 + atomic_inc_unchecked(&flow_cache_genid);
80208 }
80209 #else
80210 static inline int selinux_xfrm_enabled(void)
80211 diff -urNp linux-2.6.39.2/security/selinux/ss/services.c linux-2.6.39.2/security/selinux/ss/services.c
80212 --- linux-2.6.39.2/security/selinux/ss/services.c 2011-05-19 00:06:34.000000000 -0400
80213 +++ linux-2.6.39.2/security/selinux/ss/services.c 2011-05-22 19:36:35.000000000 -0400
80214 @@ -1806,6 +1806,8 @@ int security_load_policy(void *data, siz
80215 int rc = 0;
80216 struct policy_file file = { data, len }, *fp = &file;
80217
80218 + pax_track_stack();
80219 +
80220 if (!ss_initialized) {
80221 avtab_cache_init();
80222 rc = policydb_read(&policydb, fp);
80223 diff -urNp linux-2.6.39.2/security/smack/smack_lsm.c linux-2.6.39.2/security/smack/smack_lsm.c
80224 --- linux-2.6.39.2/security/smack/smack_lsm.c 2011-05-19 00:06:34.000000000 -0400
80225 +++ linux-2.6.39.2/security/smack/smack_lsm.c 2011-05-22 19:36:35.000000000 -0400
80226 @@ -3386,7 +3386,7 @@ static int smack_inode_getsecctx(struct
80227 return 0;
80228 }
80229
80230 -struct security_operations smack_ops = {
80231 +struct security_operations smack_ops __read_only = {
80232 .name = "smack",
80233
80234 .ptrace_access_check = smack_ptrace_access_check,
80235 diff -urNp linux-2.6.39.2/security/tomoyo/tomoyo.c linux-2.6.39.2/security/tomoyo/tomoyo.c
80236 --- linux-2.6.39.2/security/tomoyo/tomoyo.c 2011-05-19 00:06:34.000000000 -0400
80237 +++ linux-2.6.39.2/security/tomoyo/tomoyo.c 2011-05-22 19:36:35.000000000 -0400
80238 @@ -240,7 +240,7 @@ static int tomoyo_sb_pivotroot(struct pa
80239 * tomoyo_security_ops is a "struct security_operations" which is used for
80240 * registering TOMOYO.
80241 */
80242 -static struct security_operations tomoyo_security_ops = {
80243 +static struct security_operations tomoyo_security_ops __read_only = {
80244 .name = "tomoyo",
80245 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80246 .cred_prepare = tomoyo_cred_prepare,
80247 diff -urNp linux-2.6.39.2/sound/aoa/aoa.h linux-2.6.39.2/sound/aoa/aoa.h
80248 --- linux-2.6.39.2/sound/aoa/aoa.h 2011-05-19 00:06:34.000000000 -0400
80249 +++ linux-2.6.39.2/sound/aoa/aoa.h 2011-05-22 19:36:35.000000000 -0400
80250 @@ -122,8 +122,8 @@ extern struct snd_card *aoa_get_card(voi
80251 extern int aoa_snd_ctl_add(struct snd_kcontrol* control);
80252
80253 /* GPIO stuff */
80254 -extern struct gpio_methods *pmf_gpio_methods;
80255 -extern struct gpio_methods *ftr_gpio_methods;
80256 +extern const struct gpio_methods *pmf_gpio_methods;
80257 +extern const struct gpio_methods *ftr_gpio_methods;
80258 /* extern struct gpio_methods *map_gpio_methods; */
80259
80260 #endif /* __AOA_H */
80261 diff -urNp linux-2.6.39.2/sound/aoa/codecs/onyx.c linux-2.6.39.2/sound/aoa/codecs/onyx.c
80262 --- linux-2.6.39.2/sound/aoa/codecs/onyx.c 2011-05-19 00:06:34.000000000 -0400
80263 +++ linux-2.6.39.2/sound/aoa/codecs/onyx.c 2011-05-22 19:36:35.000000000 -0400
80264 @@ -54,7 +54,7 @@ struct onyx {
80265 spdif_locked:1,
80266 analog_locked:1,
80267 original_mute:2;
80268 - int open_count;
80269 + local_t open_count;
80270 struct codec_info *codec_info;
80271
80272 /* mutex serializes concurrent access to the device
80273 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_i
80274 struct onyx *onyx = cii->codec_data;
80275
80276 mutex_lock(&onyx->mutex);
80277 - onyx->open_count++;
80278 + local_inc(&onyx->open_count);
80279 mutex_unlock(&onyx->mutex);
80280
80281 return 0;
80282 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_
80283 struct onyx *onyx = cii->codec_data;
80284
80285 mutex_lock(&onyx->mutex);
80286 - onyx->open_count--;
80287 - if (!onyx->open_count)
80288 + if (local_dec_and_test(&onyx->open_count))
80289 onyx->spdif_locked = onyx->analog_locked = 0;
80290 mutex_unlock(&onyx->mutex);
80291
80292 diff -urNp linux-2.6.39.2/sound/aoa/codecs/onyx.h linux-2.6.39.2/sound/aoa/codecs/onyx.h
80293 --- linux-2.6.39.2/sound/aoa/codecs/onyx.h 2011-05-19 00:06:34.000000000 -0400
80294 +++ linux-2.6.39.2/sound/aoa/codecs/onyx.h 2011-05-22 19:36:35.000000000 -0400
80295 @@ -11,6 +11,7 @@
80296 #include <linux/i2c.h>
80297 #include <asm/pmac_low_i2c.h>
80298 #include <asm/prom.h>
80299 +#include <asm/local.h>
80300
80301 /* PCM3052 register definitions */
80302
80303 diff -urNp linux-2.6.39.2/sound/arm/aaci.c linux-2.6.39.2/sound/arm/aaci.c
80304 --- linux-2.6.39.2/sound/arm/aaci.c 2011-05-19 00:06:34.000000000 -0400
80305 +++ linux-2.6.39.2/sound/arm/aaci.c 2011-05-22 19:36:35.000000000 -0400
80306 @@ -635,7 +635,7 @@ static int aaci_pcm_playback_trigger(str
80307 return ret;
80308 }
80309
80310 -static struct snd_pcm_ops aaci_playback_ops = {
80311 +static const struct snd_pcm_ops aaci_playback_ops = {
80312 .open = aaci_pcm_open,
80313 .close = aaci_pcm_close,
80314 .ioctl = snd_pcm_lib_ioctl,
80315 @@ -738,7 +738,7 @@ static int aaci_pcm_capture_prepare(stru
80316 return 0;
80317 }
80318
80319 -static struct snd_pcm_ops aaci_capture_ops = {
80320 +static const struct snd_pcm_ops aaci_capture_ops = {
80321 .open = aaci_pcm_open,
80322 .close = aaci_pcm_close,
80323 .ioctl = snd_pcm_lib_ioctl,
80324 @@ -827,7 +827,7 @@ static struct ac97_pcm ac97_defs[] __dev
80325 }
80326 };
80327
80328 -static struct snd_ac97_bus_ops aaci_bus_ops = {
80329 +static const struct snd_ac97_bus_ops aaci_bus_ops = {
80330 .write = aaci_ac97_write,
80331 .read = aaci_ac97_read,
80332 };
80333 diff -urNp linux-2.6.39.2/sound/arm/pxa2xx-ac97.c linux-2.6.39.2/sound/arm/pxa2xx-ac97.c
80334 --- linux-2.6.39.2/sound/arm/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
80335 +++ linux-2.6.39.2/sound/arm/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
80336 @@ -34,7 +34,7 @@ static void pxa2xx_ac97_reset(struct snd
80337 pxa2xx_ac97_finish_reset(ac97);
80338 }
80339
80340 -static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
80341 +static const struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
80342 .read = pxa2xx_ac97_read,
80343 .write = pxa2xx_ac97_write,
80344 .reset = pxa2xx_ac97_reset,
80345 diff -urNp linux-2.6.39.2/sound/atmel/abdac.c linux-2.6.39.2/sound/atmel/abdac.c
80346 --- linux-2.6.39.2/sound/atmel/abdac.c 2011-05-19 00:06:34.000000000 -0400
80347 +++ linux-2.6.39.2/sound/atmel/abdac.c 2011-05-22 19:36:35.000000000 -0400
80348 @@ -297,7 +297,7 @@ static irqreturn_t abdac_interrupt(int i
80349 return IRQ_HANDLED;
80350 }
80351
80352 -static struct snd_pcm_ops atmel_abdac_ops = {
80353 +static const struct snd_pcm_ops atmel_abdac_ops = {
80354 .open = atmel_abdac_open,
80355 .close = atmel_abdac_close,
80356 .ioctl = snd_pcm_lib_ioctl,
80357 diff -urNp linux-2.6.39.2/sound/atmel/ac97c.c linux-2.6.39.2/sound/atmel/ac97c.c
80358 --- linux-2.6.39.2/sound/atmel/ac97c.c 2011-05-19 00:06:34.000000000 -0400
80359 +++ linux-2.6.39.2/sound/atmel/ac97c.c 2011-05-22 19:36:35.000000000 -0400
80360 @@ -626,7 +626,7 @@ atmel_ac97c_capture_pointer(struct snd_p
80361 return frames;
80362 }
80363
80364 -static struct snd_pcm_ops atmel_ac97_playback_ops = {
80365 +static const struct snd_pcm_ops atmel_ac97_playback_ops = {
80366 .open = atmel_ac97c_playback_open,
80367 .close = atmel_ac97c_playback_close,
80368 .ioctl = snd_pcm_lib_ioctl,
80369 @@ -637,7 +637,7 @@ static struct snd_pcm_ops atmel_ac97_pla
80370 .pointer = atmel_ac97c_playback_pointer,
80371 };
80372
80373 -static struct snd_pcm_ops atmel_ac97_capture_ops = {
80374 +static const struct snd_pcm_ops atmel_ac97_capture_ops = {
80375 .open = atmel_ac97c_capture_open,
80376 .close = atmel_ac97c_capture_close,
80377 .ioctl = snd_pcm_lib_ioctl,
80378 @@ -909,7 +909,7 @@ static int __devinit atmel_ac97c_probe(s
80379 struct resource *regs;
80380 struct ac97c_platform_data *pdata;
80381 struct clk *pclk;
80382 - static struct snd_ac97_bus_ops ops = {
80383 + static const struct snd_ac97_bus_ops ops = {
80384 .write = atmel_ac97c_write,
80385 .read = atmel_ac97c_read,
80386 };
80387 diff -urNp linux-2.6.39.2/sound/core/control.c linux-2.6.39.2/sound/core/control.c
80388 --- linux-2.6.39.2/sound/core/control.c 2011-05-19 00:06:34.000000000 -0400
80389 +++ linux-2.6.39.2/sound/core/control.c 2011-05-22 19:36:35.000000000 -0400
80390 @@ -1520,7 +1520,7 @@ static int snd_ctl_dev_free(struct snd_d
80391 */
80392 int snd_ctl_create(struct snd_card *card)
80393 {
80394 - static struct snd_device_ops ops = {
80395 + static const struct snd_device_ops ops = {
80396 .dev_free = snd_ctl_dev_free,
80397 .dev_register = snd_ctl_dev_register,
80398 .dev_disconnect = snd_ctl_dev_disconnect,
80399 diff -urNp linux-2.6.39.2/sound/core/device.c linux-2.6.39.2/sound/core/device.c
80400 --- linux-2.6.39.2/sound/core/device.c 2011-05-19 00:06:34.000000000 -0400
80401 +++ linux-2.6.39.2/sound/core/device.c 2011-05-22 19:36:35.000000000 -0400
80402 @@ -41,7 +41,7 @@
80403 * Returns zero if successful, or a negative error code on failure.
80404 */
80405 int snd_device_new(struct snd_card *card, snd_device_type_t type,
80406 - void *device_data, struct snd_device_ops *ops)
80407 + void *device_data, const struct snd_device_ops *ops)
80408 {
80409 struct snd_device *dev;
80410
80411 diff -urNp linux-2.6.39.2/sound/core/hwdep.c linux-2.6.39.2/sound/core/hwdep.c
80412 --- linux-2.6.39.2/sound/core/hwdep.c 2011-05-19 00:06:34.000000000 -0400
80413 +++ linux-2.6.39.2/sound/core/hwdep.c 2011-05-22 19:36:35.000000000 -0400
80414 @@ -348,7 +348,7 @@ int snd_hwdep_new(struct snd_card *card,
80415 {
80416 struct snd_hwdep *hwdep;
80417 int err;
80418 - static struct snd_device_ops ops = {
80419 + static const struct snd_device_ops ops = {
80420 .dev_free = snd_hwdep_dev_free,
80421 .dev_register = snd_hwdep_dev_register,
80422 .dev_disconnect = snd_hwdep_dev_disconnect,
80423 diff -urNp linux-2.6.39.2/sound/core/info.c linux-2.6.39.2/sound/core/info.c
80424 --- linux-2.6.39.2/sound/core/info.c 2011-05-19 00:06:34.000000000 -0400
80425 +++ linux-2.6.39.2/sound/core/info.c 2011-05-22 19:36:35.000000000 -0400
80426 @@ -897,7 +897,7 @@ static int snd_info_dev_register_entry(s
80427 int snd_card_proc_new(struct snd_card *card, const char *name,
80428 struct snd_info_entry **entryp)
80429 {
80430 - static struct snd_device_ops ops = {
80431 + static const struct snd_device_ops ops = {
80432 .dev_free = snd_info_dev_free_entry,
80433 .dev_register = snd_info_dev_register_entry,
80434 /* disconnect is done via snd_info_card_disconnect() */
80435 diff -urNp linux-2.6.39.2/sound/core/jack.c linux-2.6.39.2/sound/core/jack.c
80436 --- linux-2.6.39.2/sound/core/jack.c 2011-05-19 00:06:34.000000000 -0400
80437 +++ linux-2.6.39.2/sound/core/jack.c 2011-05-22 19:36:35.000000000 -0400
80438 @@ -105,7 +105,7 @@ int snd_jack_new(struct snd_card *card,
80439 struct snd_jack *jack;
80440 int err;
80441 int i;
80442 - static struct snd_device_ops ops = {
80443 + static const struct snd_device_ops ops = {
80444 .dev_free = snd_jack_dev_free,
80445 .dev_register = snd_jack_dev_register,
80446 };
80447 diff -urNp linux-2.6.39.2/sound/core/pcm.c linux-2.6.39.2/sound/core/pcm.c
80448 --- linux-2.6.39.2/sound/core/pcm.c 2011-05-19 00:06:34.000000000 -0400
80449 +++ linux-2.6.39.2/sound/core/pcm.c 2011-05-22 19:36:35.000000000 -0400
80450 @@ -717,7 +717,7 @@ int snd_pcm_new(struct snd_card *card, c
80451 {
80452 struct snd_pcm *pcm;
80453 int err;
80454 - static struct snd_device_ops ops = {
80455 + static const struct snd_device_ops ops = {
80456 .dev_free = snd_pcm_dev_free,
80457 .dev_register = snd_pcm_dev_register,
80458 .dev_disconnect = snd_pcm_dev_disconnect,
80459 diff -urNp linux-2.6.39.2/sound/core/pcm_lib.c linux-2.6.39.2/sound/core/pcm_lib.c
80460 --- linux-2.6.39.2/sound/core/pcm_lib.c 2011-05-19 00:06:34.000000000 -0400
80461 +++ linux-2.6.39.2/sound/core/pcm_lib.c 2011-05-22 19:36:35.000000000 -0400
80462 @@ -505,7 +505,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm
80463 *
80464 * Sets the given PCM operators to the pcm instance.
80465 */
80466 -void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, struct snd_pcm_ops *ops)
80467 +void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, const struct snd_pcm_ops *ops)
80468 {
80469 struct snd_pcm_str *stream = &pcm->streams[direction];
80470 struct snd_pcm_substream *substream;
80471 diff -urNp linux-2.6.39.2/sound/core/pcm_native.c linux-2.6.39.2/sound/core/pcm_native.c
80472 --- linux-2.6.39.2/sound/core/pcm_native.c 2011-05-19 00:06:34.000000000 -0400
80473 +++ linux-2.6.39.2/sound/core/pcm_native.c 2011-05-22 19:36:35.000000000 -0400
80474 @@ -702,7 +702,7 @@ struct action_ops {
80475 * Note: the stream state might be changed also on failure
80476 * Note2: call with calling stream lock + link lock
80477 */
80478 -static int snd_pcm_action_group(struct action_ops *ops,
80479 +static int snd_pcm_action_group(const struct action_ops *ops,
80480 struct snd_pcm_substream *substream,
80481 int state, int do_lock)
80482 {
80483 @@ -751,7 +751,7 @@ static int snd_pcm_action_group(struct a
80484 /*
80485 * Note: call with stream lock
80486 */
80487 -static int snd_pcm_action_single(struct action_ops *ops,
80488 +static int snd_pcm_action_single(const struct action_ops *ops,
80489 struct snd_pcm_substream *substream,
80490 int state)
80491 {
80492 @@ -771,7 +771,7 @@ static int snd_pcm_action_single(struct
80493 /*
80494 * Note: call with stream lock
80495 */
80496 -static int snd_pcm_action(struct action_ops *ops,
80497 +static int snd_pcm_action(const struct action_ops *ops,
80498 struct snd_pcm_substream *substream,
80499 int state)
80500 {
80501 @@ -794,7 +794,7 @@ static int snd_pcm_action(struct action_
80502 /*
80503 * Note: don't use any locks before
80504 */
80505 -static int snd_pcm_action_lock_irq(struct action_ops *ops,
80506 +static int snd_pcm_action_lock_irq(const struct action_ops *ops,
80507 struct snd_pcm_substream *substream,
80508 int state)
80509 {
80510 @@ -818,7 +818,7 @@ static int snd_pcm_action_lock_irq(struc
80511
80512 /*
80513 */
80514 -static int snd_pcm_action_nonatomic(struct action_ops *ops,
80515 +static int snd_pcm_action_nonatomic(const struct action_ops *ops,
80516 struct snd_pcm_substream *substream,
80517 int state)
80518 {
80519 @@ -877,7 +877,7 @@ static void snd_pcm_post_start(struct sn
80520 &runtime->trigger_tstamp);
80521 }
80522
80523 -static struct action_ops snd_pcm_action_start = {
80524 +static const struct action_ops snd_pcm_action_start = {
80525 .pre_action = snd_pcm_pre_start,
80526 .do_action = snd_pcm_do_start,
80527 .undo_action = snd_pcm_undo_start,
80528 @@ -928,7 +928,7 @@ static void snd_pcm_post_stop(struct snd
80529 wake_up(&runtime->tsleep);
80530 }
80531
80532 -static struct action_ops snd_pcm_action_stop = {
80533 +static const struct action_ops snd_pcm_action_stop = {
80534 .pre_action = snd_pcm_pre_stop,
80535 .do_action = snd_pcm_do_stop,
80536 .post_action = snd_pcm_post_stop
80537 @@ -1025,7 +1025,7 @@ static void snd_pcm_post_pause(struct sn
80538 }
80539 }
80540
80541 -static struct action_ops snd_pcm_action_pause = {
80542 +static const struct action_ops snd_pcm_action_pause = {
80543 .pre_action = snd_pcm_pre_pause,
80544 .do_action = snd_pcm_do_pause,
80545 .undo_action = snd_pcm_undo_pause,
80546 @@ -1076,7 +1076,7 @@ static void snd_pcm_post_suspend(struct
80547 wake_up(&runtime->tsleep);
80548 }
80549
80550 -static struct action_ops snd_pcm_action_suspend = {
80551 +static const struct action_ops snd_pcm_action_suspend = {
80552 .pre_action = snd_pcm_pre_suspend,
80553 .do_action = snd_pcm_do_suspend,
80554 .post_action = snd_pcm_post_suspend
80555 @@ -1175,7 +1175,7 @@ static void snd_pcm_post_resume(struct s
80556 runtime->status->state = runtime->status->suspended_state;
80557 }
80558
80559 -static struct action_ops snd_pcm_action_resume = {
80560 +static const struct action_ops snd_pcm_action_resume = {
80561 .pre_action = snd_pcm_pre_resume,
80562 .do_action = snd_pcm_do_resume,
80563 .undo_action = snd_pcm_undo_resume,
80564 @@ -1278,7 +1278,7 @@ static void snd_pcm_post_reset(struct sn
80565 snd_pcm_playback_silence(substream, ULONG_MAX);
80566 }
80567
80568 -static struct action_ops snd_pcm_action_reset = {
80569 +static const struct action_ops snd_pcm_action_reset = {
80570 .pre_action = snd_pcm_pre_reset,
80571 .do_action = snd_pcm_do_reset,
80572 .post_action = snd_pcm_post_reset
80573 @@ -1322,7 +1322,7 @@ static void snd_pcm_post_prepare(struct
80574 runtime->status->state = SNDRV_PCM_STATE_PREPARED;
80575 }
80576
80577 -static struct action_ops snd_pcm_action_prepare = {
80578 +static const struct action_ops snd_pcm_action_prepare = {
80579 .pre_action = snd_pcm_pre_prepare,
80580 .do_action = snd_pcm_do_prepare,
80581 .post_action = snd_pcm_post_prepare
80582 @@ -1397,7 +1397,7 @@ static void snd_pcm_post_drain_init(stru
80583 {
80584 }
80585
80586 -static struct action_ops snd_pcm_action_drain_init = {
80587 +static const struct action_ops snd_pcm_action_drain_init = {
80588 .pre_action = snd_pcm_pre_drain_init,
80589 .do_action = snd_pcm_do_drain_init,
80590 .post_action = snd_pcm_post_drain_init
80591 diff -urNp linux-2.6.39.2/sound/core/rawmidi.c linux-2.6.39.2/sound/core/rawmidi.c
80592 --- linux-2.6.39.2/sound/core/rawmidi.c 2011-05-19 00:06:34.000000000 -0400
80593 +++ linux-2.6.39.2/sound/core/rawmidi.c 2011-05-22 19:36:35.000000000 -0400
80594 @@ -1449,7 +1449,7 @@ int snd_rawmidi_new(struct snd_card *car
80595 {
80596 struct snd_rawmidi *rmidi;
80597 int err;
80598 - static struct snd_device_ops ops = {
80599 + static const struct snd_device_ops ops = {
80600 .dev_free = snd_rawmidi_dev_free,
80601 .dev_register = snd_rawmidi_dev_register,
80602 .dev_disconnect = snd_rawmidi_dev_disconnect,
80603 @@ -1654,7 +1654,7 @@ static int snd_rawmidi_dev_disconnect(st
80604 * Sets the rawmidi operators for the given stream direction.
80605 */
80606 void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
80607 - struct snd_rawmidi_ops *ops)
80608 + const struct snd_rawmidi_ops *ops)
80609 {
80610 struct snd_rawmidi_substream *substream;
80611
80612 diff -urNp linux-2.6.39.2/sound/core/seq/seq_device.c linux-2.6.39.2/sound/core/seq/seq_device.c
80613 --- linux-2.6.39.2/sound/core/seq/seq_device.c 2011-05-19 00:06:34.000000000 -0400
80614 +++ linux-2.6.39.2/sound/core/seq/seq_device.c 2011-05-22 19:36:35.000000000 -0400
80615 @@ -178,7 +178,7 @@ int snd_seq_device_new(struct snd_card *
80616 struct snd_seq_device *dev;
80617 struct ops_list *ops;
80618 int err;
80619 - static struct snd_device_ops dops = {
80620 + static const struct snd_device_ops dops = {
80621 .dev_free = snd_seq_device_dev_free,
80622 .dev_register = snd_seq_device_dev_register,
80623 .dev_disconnect = snd_seq_device_dev_disconnect,
80624 @@ -307,7 +307,7 @@ static int snd_seq_device_dev_disconnect
80625 * id = driver id
80626 * entry = driver operators - duplicated to each instance
80627 */
80628 -int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80629 +int snd_seq_device_register_driver(char *id, const struct snd_seq_dev_ops *entry,
80630 int argsize)
80631 {
80632 struct ops_list *ops;
80633 diff -urNp linux-2.6.39.2/sound/core/seq/seq_midi.c linux-2.6.39.2/sound/core/seq/seq_midi.c
80634 --- linux-2.6.39.2/sound/core/seq/seq_midi.c 2011-05-19 00:06:34.000000000 -0400
80635 +++ linux-2.6.39.2/sound/core/seq/seq_midi.c 2011-05-22 19:36:35.000000000 -0400
80636 @@ -461,7 +461,7 @@ snd_seq_midisynth_unregister_port(struct
80637
80638 static int __init alsa_seq_midi_init(void)
80639 {
80640 - static struct snd_seq_dev_ops ops = {
80641 + static const struct snd_seq_dev_ops ops = {
80642 snd_seq_midisynth_register_port,
80643 snd_seq_midisynth_unregister_port,
80644 };
80645 diff -urNp linux-2.6.39.2/sound/core/seq/seq_virmidi.c linux-2.6.39.2/sound/core/seq/seq_virmidi.c
80646 --- linux-2.6.39.2/sound/core/seq/seq_virmidi.c 2011-05-19 00:06:34.000000000 -0400
80647 +++ linux-2.6.39.2/sound/core/seq/seq_virmidi.c 2011-05-22 19:36:35.000000000 -0400
80648 @@ -337,13 +337,13 @@ static int snd_virmidi_unuse(void *priva
80649 * Register functions
80650 */
80651
80652 -static struct snd_rawmidi_ops snd_virmidi_input_ops = {
80653 +static const struct snd_rawmidi_ops snd_virmidi_input_ops = {
80654 .open = snd_virmidi_input_open,
80655 .close = snd_virmidi_input_close,
80656 .trigger = snd_virmidi_input_trigger,
80657 };
80658
80659 -static struct snd_rawmidi_ops snd_virmidi_output_ops = {
80660 +static const struct snd_rawmidi_ops snd_virmidi_output_ops = {
80661 .open = snd_virmidi_output_open,
80662 .close = snd_virmidi_output_close,
80663 .trigger = snd_virmidi_output_trigger,
80664 @@ -467,7 +467,7 @@ static int snd_virmidi_dev_unregister(st
80665 /*
80666 *
80667 */
80668 -static struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80669 +static const struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
80670 .dev_register = snd_virmidi_dev_register,
80671 .dev_unregister = snd_virmidi_dev_unregister,
80672 };
80673 diff -urNp linux-2.6.39.2/sound/core/timer.c linux-2.6.39.2/sound/core/timer.c
80674 --- linux-2.6.39.2/sound/core/timer.c 2011-05-19 00:06:34.000000000 -0400
80675 +++ linux-2.6.39.2/sound/core/timer.c 2011-05-22 19:36:35.000000000 -0400
80676 @@ -756,7 +756,7 @@ int snd_timer_new(struct snd_card *card,
80677 {
80678 struct snd_timer *timer;
80679 int err;
80680 - static struct snd_device_ops ops = {
80681 + static const struct snd_device_ops ops = {
80682 .dev_free = snd_timer_dev_free,
80683 .dev_register = snd_timer_dev_register,
80684 .dev_disconnect = snd_timer_dev_disconnect,
80685 diff -urNp linux-2.6.39.2/sound/drivers/aloop.c linux-2.6.39.2/sound/drivers/aloop.c
80686 --- linux-2.6.39.2/sound/drivers/aloop.c 2011-05-19 00:06:34.000000000 -0400
80687 +++ linux-2.6.39.2/sound/drivers/aloop.c 2011-05-22 19:36:35.000000000 -0400
80688 @@ -731,7 +731,7 @@ static int loopback_close(struct snd_pcm
80689 return 0;
80690 }
80691
80692 -static struct snd_pcm_ops loopback_playback_ops = {
80693 +static const struct snd_pcm_ops loopback_playback_ops = {
80694 .open = loopback_open,
80695 .close = loopback_close,
80696 .ioctl = snd_pcm_lib_ioctl,
80697 @@ -742,7 +742,7 @@ static struct snd_pcm_ops loopback_playb
80698 .pointer = loopback_pointer,
80699 };
80700
80701 -static struct snd_pcm_ops loopback_capture_ops = {
80702 +static const struct snd_pcm_ops loopback_capture_ops = {
80703 .open = loopback_open,
80704 .close = loopback_close,
80705 .ioctl = snd_pcm_lib_ioctl,
80706 diff -urNp linux-2.6.39.2/sound/drivers/dummy.c linux-2.6.39.2/sound/drivers/dummy.c
80707 --- linux-2.6.39.2/sound/drivers/dummy.c 2011-05-19 00:06:34.000000000 -0400
80708 +++ linux-2.6.39.2/sound/drivers/dummy.c 2011-05-22 19:36:35.000000000 -0400
80709 @@ -350,7 +350,7 @@ static void dummy_systimer_free(struct s
80710 kfree(substream->runtime->private_data);
80711 }
80712
80713 -static struct dummy_timer_ops dummy_systimer_ops = {
80714 +static const struct dummy_timer_ops dummy_systimer_ops = {
80715 .create = dummy_systimer_create,
80716 .free = dummy_systimer_free,
80717 .prepare = dummy_systimer_prepare,
80718 @@ -474,7 +474,7 @@ static void dummy_hrtimer_free(struct sn
80719 kfree(dpcm);
80720 }
80721
80722 -static struct dummy_timer_ops dummy_hrtimer_ops = {
80723 +static const struct dummy_timer_ops dummy_hrtimer_ops = {
80724 .create = dummy_hrtimer_create,
80725 .free = dummy_hrtimer_free,
80726 .prepare = dummy_hrtimer_prepare,
80727 @@ -660,7 +660,7 @@ static struct page *dummy_pcm_page(struc
80728 return virt_to_page(dummy_page[substream->stream]); /* the same page */
80729 }
80730
80731 -static struct snd_pcm_ops dummy_pcm_ops = {
80732 +static const struct snd_pcm_ops dummy_pcm_ops = {
80733 .open = dummy_pcm_open,
80734 .close = dummy_pcm_close,
80735 .ioctl = snd_pcm_lib_ioctl,
80736 @@ -671,7 +671,7 @@ static struct snd_pcm_ops dummy_pcm_ops
80737 .pointer = dummy_pcm_pointer,
80738 };
80739
80740 -static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80741 +static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
80742 .open = dummy_pcm_open,
80743 .close = dummy_pcm_close,
80744 .ioctl = snd_pcm_lib_ioctl,
80745 @@ -689,7 +689,7 @@ static int __devinit snd_card_dummy_pcm(
80746 int substreams)
80747 {
80748 struct snd_pcm *pcm;
80749 - struct snd_pcm_ops *ops;
80750 + const struct snd_pcm_ops *ops;
80751 int err;
80752
80753 err = snd_pcm_new(dummy->card, "Dummy PCM", device,
80754 diff -urNp linux-2.6.39.2/sound/drivers/ml403-ac97cr.c linux-2.6.39.2/sound/drivers/ml403-ac97cr.c
80755 --- linux-2.6.39.2/sound/drivers/ml403-ac97cr.c 2011-05-19 00:06:34.000000000 -0400
80756 +++ linux-2.6.39.2/sound/drivers/ml403-ac97cr.c 2011-05-22 19:36:35.000000000 -0400
80757 @@ -759,7 +759,7 @@ static int snd_ml403_ac97cr_capture_clos
80758 return 0;
80759 }
80760
80761 -static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80762 +static const struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = {
80763 .open = snd_ml403_ac97cr_playback_open,
80764 .close = snd_ml403_ac97cr_playback_close,
80765 .ioctl = snd_pcm_lib_ioctl,
80766 @@ -770,7 +770,7 @@ static struct snd_pcm_ops snd_ml403_ac97
80767 .pointer = snd_ml403_ac97cr_pcm_pointer,
80768 };
80769
80770 -static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80771 +static const struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = {
80772 .open = snd_ml403_ac97cr_capture_open,
80773 .close = snd_ml403_ac97cr_capture_close,
80774 .ioctl = snd_pcm_lib_ioctl,
80775 @@ -1114,7 +1114,7 @@ snd_ml403_ac97cr_create(struct snd_card
80776 {
80777 struct snd_ml403_ac97cr *ml403_ac97cr;
80778 int err;
80779 - static struct snd_device_ops ops = {
80780 + static const struct snd_device_ops ops = {
80781 .dev_free = snd_ml403_ac97cr_dev_free,
80782 };
80783 struct resource *resource;
80784 @@ -1210,7 +1210,7 @@ snd_ml403_ac97cr_mixer(struct snd_ml403_
80785 struct snd_ac97_bus *bus;
80786 struct snd_ac97_template ac97;
80787 int err;
80788 - static struct snd_ac97_bus_ops ops = {
80789 + static const struct snd_ac97_bus_ops ops = {
80790 .write = snd_ml403_ac97cr_codec_write,
80791 .read = snd_ml403_ac97cr_codec_read,
80792 };
80793 diff -urNp linux-2.6.39.2/sound/drivers/mtpav.c linux-2.6.39.2/sound/drivers/mtpav.c
80794 --- linux-2.6.39.2/sound/drivers/mtpav.c 2011-05-19 00:06:34.000000000 -0400
80795 +++ linux-2.6.39.2/sound/drivers/mtpav.c 2011-05-22 19:36:35.000000000 -0400
80796 @@ -601,13 +601,13 @@ static int __devinit snd_mtpav_get_ISA(s
80797 /*
80798 */
80799
80800 -static struct snd_rawmidi_ops snd_mtpav_output = {
80801 +static const struct snd_rawmidi_ops snd_mtpav_output = {
80802 .open = snd_mtpav_output_open,
80803 .close = snd_mtpav_output_close,
80804 .trigger = snd_mtpav_output_trigger,
80805 };
80806
80807 -static struct snd_rawmidi_ops snd_mtpav_input = {
80808 +static const struct snd_rawmidi_ops snd_mtpav_input = {
80809 .open = snd_mtpav_input_open,
80810 .close = snd_mtpav_input_close,
80811 .trigger = snd_mtpav_input_trigger,
80812 diff -urNp linux-2.6.39.2/sound/drivers/mts64.c linux-2.6.39.2/sound/drivers/mts64.c
80813 --- linux-2.6.39.2/sound/drivers/mts64.c 2011-05-19 00:06:34.000000000 -0400
80814 +++ linux-2.6.39.2/sound/drivers/mts64.c 2011-05-22 19:36:35.000000000 -0400
80815 @@ -28,6 +28,7 @@
80816 #include <sound/initval.h>
80817 #include <sound/rawmidi.h>
80818 #include <sound/control.h>
80819 +#include <asm/local.h>
80820
80821 #define CARD_NAME "Miditerminal 4140"
80822 #define DRIVER_NAME "MTS64"
80823 @@ -66,7 +67,7 @@ struct mts64 {
80824 struct pardevice *pardev;
80825 int pardev_claimed;
80826
80827 - int open_count;
80828 + local_t open_count;
80829 int current_midi_output_port;
80830 int current_midi_input_port;
80831 u8 mode[MTS64_NUM_INPUT_PORTS];
80832 @@ -696,7 +697,7 @@ static int snd_mts64_rawmidi_open(struct
80833 {
80834 struct mts64 *mts = substream->rmidi->private_data;
80835
80836 - if (mts->open_count == 0) {
80837 + if (local_read(&mts->open_count) == 0) {
80838 /* We don't need a spinlock here, because this is just called
80839 if the device has not been opened before.
80840 So there aren't any IRQs from the device */
80841 @@ -704,7 +705,7 @@ static int snd_mts64_rawmidi_open(struct
80842
80843 msleep(50);
80844 }
80845 - ++(mts->open_count);
80846 + local_inc(&mts->open_count);
80847
80848 return 0;
80849 }
80850 @@ -714,8 +715,7 @@ static int snd_mts64_rawmidi_close(struc
80851 struct mts64 *mts = substream->rmidi->private_data;
80852 unsigned long flags;
80853
80854 - --(mts->open_count);
80855 - if (mts->open_count == 0) {
80856 + if (local_dec_return(&mts->open_count) == 0) {
80857 /* We need the spinlock_irqsave here because we can still
80858 have IRQs at this point */
80859 spin_lock_irqsave(&mts->lock, flags);
80860 @@ -724,8 +724,8 @@ static int snd_mts64_rawmidi_close(struc
80861
80862 msleep(500);
80863
80864 - } else if (mts->open_count < 0)
80865 - mts->open_count = 0;
80866 + } else if (local_read(&mts->open_count) < 0)
80867 + local_set(&mts->open_count, 0);
80868
80869 return 0;
80870 }
80871 @@ -760,13 +760,13 @@ static void snd_mts64_rawmidi_input_trig
80872 spin_unlock_irqrestore(&mts->lock, flags);
80873 }
80874
80875 -static struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80876 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
80877 .open = snd_mts64_rawmidi_open,
80878 .close = snd_mts64_rawmidi_close,
80879 .trigger = snd_mts64_rawmidi_output_trigger
80880 };
80881
80882 -static struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80883 +static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
80884 .open = snd_mts64_rawmidi_open,
80885 .close = snd_mts64_rawmidi_close,
80886 .trigger = snd_mts64_rawmidi_input_trigger
80887 diff -urNp linux-2.6.39.2/sound/drivers/pcsp/pcsp.c linux-2.6.39.2/sound/drivers/pcsp/pcsp.c
80888 --- linux-2.6.39.2/sound/drivers/pcsp/pcsp.c 2011-05-19 00:06:34.000000000 -0400
80889 +++ linux-2.6.39.2/sound/drivers/pcsp/pcsp.c 2011-05-22 19:36:35.000000000 -0400
80890 @@ -41,7 +41,7 @@ struct snd_pcsp pcsp_chip;
80891
80892 static int __devinit snd_pcsp_create(struct snd_card *card)
80893 {
80894 - static struct snd_device_ops ops = { };
80895 + static const struct snd_device_ops ops = { };
80896 struct timespec tp;
80897 int err;
80898 int div, min_div, order;
80899 diff -urNp linux-2.6.39.2/sound/drivers/pcsp/pcsp_lib.c linux-2.6.39.2/sound/drivers/pcsp/pcsp_lib.c
80900 --- linux-2.6.39.2/sound/drivers/pcsp/pcsp_lib.c 2011-05-19 00:06:34.000000000 -0400
80901 +++ linux-2.6.39.2/sound/drivers/pcsp/pcsp_lib.c 2011-05-22 19:36:35.000000000 -0400
80902 @@ -323,7 +323,7 @@ static int snd_pcsp_playback_open(struct
80903 return 0;
80904 }
80905
80906 -static struct snd_pcm_ops snd_pcsp_playback_ops = {
80907 +static const struct snd_pcm_ops snd_pcsp_playback_ops = {
80908 .open = snd_pcsp_playback_open,
80909 .close = snd_pcsp_playback_close,
80910 .ioctl = snd_pcm_lib_ioctl,
80911 diff -urNp linux-2.6.39.2/sound/drivers/portman2x4.c linux-2.6.39.2/sound/drivers/portman2x4.c
80912 --- linux-2.6.39.2/sound/drivers/portman2x4.c 2011-05-19 00:06:34.000000000 -0400
80913 +++ linux-2.6.39.2/sound/drivers/portman2x4.c 2011-05-22 19:36:35.000000000 -0400
80914 @@ -47,6 +47,7 @@
80915 #include <sound/initval.h>
80916 #include <sound/rawmidi.h>
80917 #include <sound/control.h>
80918 +#include <asm/local.h>
80919
80920 #define CARD_NAME "Portman 2x4"
80921 #define DRIVER_NAME "portman"
80922 @@ -84,7 +85,7 @@ struct portman {
80923 struct pardevice *pardev;
80924 int pardev_claimed;
80925
80926 - int open_count;
80927 + local_t open_count;
80928 int mode[PORTMAN_NUM_INPUT_PORTS];
80929 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
80930 };
80931 @@ -547,13 +548,13 @@ static void snd_portman_midi_output_trig
80932 spin_unlock_irqrestore(&pm->reg_lock, flags);
80933 }
80934
80935 -static struct snd_rawmidi_ops snd_portman_midi_output = {
80936 +static const struct snd_rawmidi_ops snd_portman_midi_output = {
80937 .open = snd_portman_midi_open,
80938 .close = snd_portman_midi_close,
80939 .trigger = snd_portman_midi_output_trigger,
80940 };
80941
80942 -static struct snd_rawmidi_ops snd_portman_midi_input = {
80943 +static const struct snd_rawmidi_ops snd_portman_midi_input = {
80944 .open = snd_portman_midi_open,
80945 .close = snd_portman_midi_close,
80946 .trigger = snd_portman_midi_input_trigger,
80947 diff -urNp linux-2.6.39.2/sound/drivers/serial-u16550.c linux-2.6.39.2/sound/drivers/serial-u16550.c
80948 --- linux-2.6.39.2/sound/drivers/serial-u16550.c 2011-05-19 00:06:34.000000000 -0400
80949 +++ linux-2.6.39.2/sound/drivers/serial-u16550.c 2011-05-22 19:36:35.000000000 -0400
80950 @@ -754,15 +754,13 @@ static void snd_uart16550_output_trigger
80951 snd_uart16550_output_write(substream);
80952 }
80953
80954 -static struct snd_rawmidi_ops snd_uart16550_output =
80955 -{
80956 +static const struct snd_rawmidi_ops snd_uart16550_output = {
80957 .open = snd_uart16550_output_open,
80958 .close = snd_uart16550_output_close,
80959 .trigger = snd_uart16550_output_trigger,
80960 };
80961
80962 -static struct snd_rawmidi_ops snd_uart16550_input =
80963 -{
80964 +static const struct snd_rawmidi_ops snd_uart16550_input = {
80965 .open = snd_uart16550_input_open,
80966 .close = snd_uart16550_input_close,
80967 .trigger = snd_uart16550_input_trigger,
80968 @@ -792,7 +790,7 @@ static int __devinit snd_uart16550_creat
80969 int droponfull,
80970 struct snd_uart16550 **ruart)
80971 {
80972 - static struct snd_device_ops ops = {
80973 + static const struct snd_device_ops ops = {
80974 .dev_free = snd_uart16550_dev_free,
80975 };
80976 struct snd_uart16550 *uart;
80977 diff -urNp linux-2.6.39.2/sound/drivers/vx/vx_pcm.c linux-2.6.39.2/sound/drivers/vx/vx_pcm.c
80978 --- linux-2.6.39.2/sound/drivers/vx/vx_pcm.c 2011-05-19 00:06:34.000000000 -0400
80979 +++ linux-2.6.39.2/sound/drivers/vx/vx_pcm.c 2011-05-22 19:36:35.000000000 -0400
80980 @@ -895,7 +895,7 @@ static int vx_pcm_prepare(struct snd_pcm
80981 /*
80982 * operators for PCM playback
80983 */
80984 -static struct snd_pcm_ops vx_pcm_playback_ops = {
80985 +static const struct snd_pcm_ops vx_pcm_playback_ops = {
80986 .open = vx_pcm_playback_open,
80987 .close = vx_pcm_playback_close,
80988 .ioctl = snd_pcm_lib_ioctl,
80989 @@ -1116,7 +1116,7 @@ static snd_pcm_uframes_t vx_pcm_capture_
80990 /*
80991 * operators for PCM capture
80992 */
80993 -static struct snd_pcm_ops vx_pcm_capture_ops = {
80994 +static const struct snd_pcm_ops vx_pcm_capture_ops = {
80995 .open = vx_pcm_capture_open,
80996 .close = vx_pcm_capture_close,
80997 .ioctl = snd_pcm_lib_ioctl,
80998 diff -urNp linux-2.6.39.2/sound/firewire/amdtp.c linux-2.6.39.2/sound/firewire/amdtp.c
80999 --- linux-2.6.39.2/sound/firewire/amdtp.c 2011-05-19 00:06:34.000000000 -0400
81000 +++ linux-2.6.39.2/sound/firewire/amdtp.c 2011-05-22 19:36:35.000000000 -0400
81001 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdt
81002 ptr = s->pcm_buffer_pointer + data_blocks;
81003 if (ptr >= pcm->runtime->buffer_size)
81004 ptr -= pcm->runtime->buffer_size;
81005 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81006 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81007
81008 s->pcm_period_pointer += data_blocks;
81009 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81010 @@ -510,7 +510,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
81011 */
81012 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81013 {
81014 - ACCESS_ONCE(s->source_node_id_field) =
81015 + ACCESS_ONCE_RW(s->source_node_id_field) =
81016 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81017 }
81018 EXPORT_SYMBOL(amdtp_out_stream_update);
81019 diff -urNp linux-2.6.39.2/sound/firewire/amdtp.h linux-2.6.39.2/sound/firewire/amdtp.h
81020 --- linux-2.6.39.2/sound/firewire/amdtp.h 2011-05-19 00:06:34.000000000 -0400
81021 +++ linux-2.6.39.2/sound/firewire/amdtp.h 2011-05-22 19:36:35.000000000 -0400
81022 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_
81023 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81024 struct snd_pcm_substream *pcm)
81025 {
81026 - ACCESS_ONCE(s->pcm) = pcm;
81027 + ACCESS_ONCE_RW(s->pcm) = pcm;
81028 }
81029
81030 /**
81031 diff -urNp linux-2.6.39.2/sound/i2c/i2c.c linux-2.6.39.2/sound/i2c/i2c.c
81032 --- linux-2.6.39.2/sound/i2c/i2c.c 2011-05-19 00:06:34.000000000 -0400
81033 +++ linux-2.6.39.2/sound/i2c/i2c.c 2011-05-22 19:36:35.000000000 -0400
81034 @@ -80,7 +80,7 @@ int snd_i2c_bus_create(struct snd_card *
81035 {
81036 struct snd_i2c_bus *bus;
81037 int err;
81038 - static struct snd_device_ops ops = {
81039 + static const struct snd_device_ops ops = {
81040 .dev_free = snd_i2c_bus_dev_free,
81041 };
81042
81043 diff -urNp linux-2.6.39.2/sound/i2c/other/ak4113.c linux-2.6.39.2/sound/i2c/other/ak4113.c
81044 --- linux-2.6.39.2/sound/i2c/other/ak4113.c 2011-05-19 00:06:34.000000000 -0400
81045 +++ linux-2.6.39.2/sound/i2c/other/ak4113.c 2011-05-22 19:36:35.000000000 -0400
81046 @@ -75,7 +75,7 @@ int snd_ak4113_create(struct snd_card *c
81047 struct ak4113 *chip;
81048 int err = 0;
81049 unsigned char reg;
81050 - static struct snd_device_ops ops = {
81051 + static const struct snd_device_ops ops = {
81052 .dev_free = snd_ak4113_dev_free,
81053 };
81054
81055 diff -urNp linux-2.6.39.2/sound/i2c/other/ak4114.c linux-2.6.39.2/sound/i2c/other/ak4114.c
81056 --- linux-2.6.39.2/sound/i2c/other/ak4114.c 2011-05-19 00:06:34.000000000 -0400
81057 +++ linux-2.6.39.2/sound/i2c/other/ak4114.c 2011-05-22 19:36:35.000000000 -0400
81058 @@ -86,7 +86,7 @@ int snd_ak4114_create(struct snd_card *c
81059 struct ak4114 *chip;
81060 int err = 0;
81061 unsigned char reg;
81062 - static struct snd_device_ops ops = {
81063 + static const struct snd_device_ops ops = {
81064 .dev_free = snd_ak4114_dev_free,
81065 };
81066
81067 diff -urNp linux-2.6.39.2/sound/i2c/other/ak4117.c linux-2.6.39.2/sound/i2c/other/ak4117.c
81068 --- linux-2.6.39.2/sound/i2c/other/ak4117.c 2011-05-19 00:06:34.000000000 -0400
81069 +++ linux-2.6.39.2/sound/i2c/other/ak4117.c 2011-05-22 19:36:35.000000000 -0400
81070 @@ -78,7 +78,7 @@ int snd_ak4117_create(struct snd_card *c
81071 struct ak4117 *chip;
81072 int err = 0;
81073 unsigned char reg;
81074 - static struct snd_device_ops ops = {
81075 + static const struct snd_device_ops ops = {
81076 .dev_free = snd_ak4117_dev_free,
81077 };
81078
81079 diff -urNp linux-2.6.39.2/sound/isa/ad1816a/ad1816a_lib.c linux-2.6.39.2/sound/isa/ad1816a/ad1816a_lib.c
81080 --- linux-2.6.39.2/sound/isa/ad1816a/ad1816a_lib.c 2011-05-19 00:06:34.000000000 -0400
81081 +++ linux-2.6.39.2/sound/isa/ad1816a/ad1816a_lib.c 2011-05-22 19:36:35.000000000 -0400
81082 @@ -575,7 +575,7 @@ int __devinit snd_ad1816a_create(struct
81083 unsigned long port, int irq, int dma1, int dma2,
81084 struct snd_ad1816a **rchip)
81085 {
81086 - static struct snd_device_ops ops = {
81087 + static const struct snd_device_ops ops = {
81088 .dev_free = snd_ad1816a_dev_free,
81089 };
81090 int error;
81091 diff -urNp linux-2.6.39.2/sound/isa/es1688/es1688_lib.c linux-2.6.39.2/sound/isa/es1688/es1688_lib.c
81092 --- linux-2.6.39.2/sound/isa/es1688/es1688_lib.c 2011-05-19 00:06:34.000000000 -0400
81093 +++ linux-2.6.39.2/sound/isa/es1688/es1688_lib.c 2011-05-22 19:36:35.000000000 -0400
81094 @@ -646,7 +646,7 @@ int snd_es1688_create(struct snd_card *c
81095 int dma8,
81096 unsigned short hardware)
81097 {
81098 - static struct snd_device_ops ops = {
81099 + static const struct snd_device_ops ops = {
81100 .dev_free = snd_es1688_dev_free,
81101 };
81102
81103 diff -urNp linux-2.6.39.2/sound/isa/es18xx.c linux-2.6.39.2/sound/isa/es18xx.c
81104 --- linux-2.6.39.2/sound/isa/es18xx.c 2011-05-19 00:06:34.000000000 -0400
81105 +++ linux-2.6.39.2/sound/isa/es18xx.c 2011-05-22 19:36:35.000000000 -0400
81106 @@ -1658,7 +1658,7 @@ static int __devinit snd_es18xx_probe(st
81107 return snd_es18xx_initialize(chip, mpu_port, fm_port);
81108 }
81109
81110 -static struct snd_pcm_ops snd_es18xx_playback_ops = {
81111 +static const struct snd_pcm_ops snd_es18xx_playback_ops = {
81112 .open = snd_es18xx_playback_open,
81113 .close = snd_es18xx_playback_close,
81114 .ioctl = snd_pcm_lib_ioctl,
81115 @@ -1669,7 +1669,7 @@ static struct snd_pcm_ops snd_es18xx_pla
81116 .pointer = snd_es18xx_playback_pointer,
81117 };
81118
81119 -static struct snd_pcm_ops snd_es18xx_capture_ops = {
81120 +static const struct snd_pcm_ops snd_es18xx_capture_ops = {
81121 .open = snd_es18xx_capture_open,
81122 .close = snd_es18xx_capture_close,
81123 .ioctl = snd_pcm_lib_ioctl,
81124 @@ -1784,7 +1784,7 @@ static int __devinit snd_es18xx_new_devi
81125 int irq, int dma1, int dma2)
81126 {
81127 struct snd_es18xx *chip = card->private_data;
81128 - static struct snd_device_ops ops = {
81129 + static const struct snd_device_ops ops = {
81130 .dev_free = snd_es18xx_dev_free,
81131 };
81132 int err;
81133 diff -urNp linux-2.6.39.2/sound/isa/gus/gus_main.c linux-2.6.39.2/sound/isa/gus/gus_main.c
81134 --- linux-2.6.39.2/sound/isa/gus/gus_main.c 2011-05-19 00:06:34.000000000 -0400
81135 +++ linux-2.6.39.2/sound/isa/gus/gus_main.c 2011-05-22 19:36:35.000000000 -0400
81136 @@ -139,7 +139,7 @@ int snd_gus_create(struct snd_card *card
81137 {
81138 struct snd_gus_card *gus;
81139 int err;
81140 - static struct snd_device_ops ops = {
81141 + static const struct snd_device_ops ops = {
81142 .dev_free = snd_gus_dev_free,
81143 };
81144
81145 diff -urNp linux-2.6.39.2/sound/isa/msnd/msnd.c linux-2.6.39.2/sound/isa/msnd/msnd.c
81146 --- linux-2.6.39.2/sound/isa/msnd/msnd.c 2011-05-19 00:06:34.000000000 -0400
81147 +++ linux-2.6.39.2/sound/isa/msnd/msnd.c 2011-05-22 19:36:35.000000000 -0400
81148 @@ -570,7 +570,7 @@ snd_msnd_playback_pointer(struct snd_pcm
81149 }
81150
81151
81152 -static struct snd_pcm_ops snd_msnd_playback_ops = {
81153 +static const struct snd_pcm_ops snd_msnd_playback_ops = {
81154 .open = snd_msnd_playback_open,
81155 .close = snd_msnd_playback_close,
81156 .ioctl = snd_pcm_lib_ioctl,
81157 @@ -667,7 +667,7 @@ static int snd_msnd_capture_hw_params(st
81158 }
81159
81160
81161 -static struct snd_pcm_ops snd_msnd_capture_ops = {
81162 +static const struct snd_pcm_ops snd_msnd_capture_ops = {
81163 .open = snd_msnd_capture_open,
81164 .close = snd_msnd_capture_close,
81165 .ioctl = snd_pcm_lib_ioctl,
81166 diff -urNp linux-2.6.39.2/sound/isa/msnd/msnd_midi.c linux-2.6.39.2/sound/isa/msnd/msnd_midi.c
81167 --- linux-2.6.39.2/sound/isa/msnd/msnd_midi.c 2011-05-19 00:06:34.000000000 -0400
81168 +++ linux-2.6.39.2/sound/isa/msnd/msnd_midi.c 2011-05-22 19:36:35.000000000 -0400
81169 @@ -141,7 +141,7 @@ void snd_msndmidi_input_read(void *mpuv)
81170 }
81171 EXPORT_SYMBOL(snd_msndmidi_input_read);
81172
81173 -static struct snd_rawmidi_ops snd_msndmidi_input = {
81174 +static const struct snd_rawmidi_ops snd_msndmidi_input = {
81175 .open = snd_msndmidi_input_open,
81176 .close = snd_msndmidi_input_close,
81177 .trigger = snd_msndmidi_input_trigger,
81178 diff -urNp linux-2.6.39.2/sound/isa/msnd/msnd_pinnacle.c linux-2.6.39.2/sound/isa/msnd/msnd_pinnacle.c
81179 --- linux-2.6.39.2/sound/isa/msnd/msnd_pinnacle.c 2011-05-19 00:06:34.000000000 -0400
81180 +++ linux-2.6.39.2/sound/isa/msnd/msnd_pinnacle.c 2011-05-22 19:36:35.000000000 -0400
81181 @@ -539,7 +539,7 @@ static int __devinit snd_msnd_attach(str
81182 {
81183 struct snd_msnd *chip = card->private_data;
81184 int err;
81185 - static struct snd_device_ops ops = {
81186 + static const struct snd_device_ops ops = {
81187 .dev_free = snd_msnd_dev_free,
81188 };
81189
81190 diff -urNp linux-2.6.39.2/sound/isa/sb/emu8000.c linux-2.6.39.2/sound/isa/sb/emu8000.c
81191 --- linux-2.6.39.2/sound/isa/sb/emu8000.c 2011-05-19 00:06:34.000000000 -0400
81192 +++ linux-2.6.39.2/sound/isa/sb/emu8000.c 2011-05-22 19:36:35.000000000 -0400
81193 @@ -1079,7 +1079,7 @@ snd_emu8000_new(struct snd_card *card, i
81194 struct snd_seq_device *awe;
81195 struct snd_emu8000 *hw;
81196 int err;
81197 - static struct snd_device_ops ops = {
81198 + static const struct snd_device_ops ops = {
81199 .dev_free = snd_emu8000_dev_free,
81200 };
81201
81202 diff -urNp linux-2.6.39.2/sound/isa/sb/emu8000_pcm.c linux-2.6.39.2/sound/isa/sb/emu8000_pcm.c
81203 --- linux-2.6.39.2/sound/isa/sb/emu8000_pcm.c 2011-05-19 00:06:34.000000000 -0400
81204 +++ linux-2.6.39.2/sound/isa/sb/emu8000_pcm.c 2011-05-22 19:36:35.000000000 -0400
81205 @@ -667,7 +667,7 @@ static snd_pcm_uframes_t emu8k_pcm_point
81206 }
81207
81208
81209 -static struct snd_pcm_ops emu8k_pcm_ops = {
81210 +static const struct snd_pcm_ops emu8k_pcm_ops = {
81211 .open = emu8k_pcm_open,
81212 .close = emu8k_pcm_close,
81213 .ioctl = snd_pcm_lib_ioctl,
81214 diff -urNp linux-2.6.39.2/sound/isa/sb/sb_common.c linux-2.6.39.2/sound/isa/sb/sb_common.c
81215 --- linux-2.6.39.2/sound/isa/sb/sb_common.c 2011-05-19 00:06:34.000000000 -0400
81216 +++ linux-2.6.39.2/sound/isa/sb/sb_common.c 2011-05-22 19:36:35.000000000 -0400
81217 @@ -218,7 +218,7 @@ int snd_sbdsp_create(struct snd_card *ca
81218 {
81219 struct snd_sb *chip;
81220 int err;
81221 - static struct snd_device_ops ops = {
81222 + static const struct snd_device_ops ops = {
81223 .dev_free = snd_sbdsp_dev_free,
81224 };
81225
81226 diff -urNp linux-2.6.39.2/sound/isa/wavefront/wavefront_midi.c linux-2.6.39.2/sound/isa/wavefront/wavefront_midi.c
81227 --- linux-2.6.39.2/sound/isa/wavefront/wavefront_midi.c 2011-05-19 00:06:34.000000000 -0400
81228 +++ linux-2.6.39.2/sound/isa/wavefront/wavefront_midi.c 2011-05-22 19:36:35.000000000 -0400
81229 @@ -561,14 +561,14 @@ snd_wavefront_midi_start (snd_wavefront_
81230 return 0;
81231 }
81232
81233 -struct snd_rawmidi_ops snd_wavefront_midi_output =
81234 +const struct snd_rawmidi_ops snd_wavefront_midi_output =
81235 {
81236 .open = snd_wavefront_midi_output_open,
81237 .close = snd_wavefront_midi_output_close,
81238 .trigger = snd_wavefront_midi_output_trigger,
81239 };
81240
81241 -struct snd_rawmidi_ops snd_wavefront_midi_input =
81242 +const struct snd_rawmidi_ops snd_wavefront_midi_input =
81243 {
81244 .open = snd_wavefront_midi_input_open,
81245 .close = snd_wavefront_midi_input_close,
81246 diff -urNp linux-2.6.39.2/sound/isa/wss/wss_lib.c linux-2.6.39.2/sound/isa/wss/wss_lib.c
81247 --- linux-2.6.39.2/sound/isa/wss/wss_lib.c 2011-05-19 00:06:34.000000000 -0400
81248 +++ linux-2.6.39.2/sound/isa/wss/wss_lib.c 2011-05-22 19:36:35.000000000 -0400
81249 @@ -1801,7 +1801,7 @@ int snd_wss_create(struct snd_card *card
81250 unsigned short hwshare,
81251 struct snd_wss **rchip)
81252 {
81253 - static struct snd_device_ops ops = {
81254 + static const struct snd_device_ops ops = {
81255 .dev_free = snd_wss_dev_free,
81256 };
81257 struct snd_wss *chip;
81258 diff -urNp linux-2.6.39.2/sound/mips/au1x00.c linux-2.6.39.2/sound/mips/au1x00.c
81259 --- linux-2.6.39.2/sound/mips/au1x00.c 2011-05-19 00:06:34.000000000 -0400
81260 +++ linux-2.6.39.2/sound/mips/au1x00.c 2011-05-22 19:36:35.000000000 -0400
81261 @@ -416,7 +416,7 @@ snd_au1000_pointer(struct snd_pcm_substr
81262 return bytes_to_frames(runtime,location);
81263 }
81264
81265 -static struct snd_pcm_ops snd_card_au1000_playback_ops = {
81266 +static const struct snd_pcm_ops snd_card_au1000_playback_ops = {
81267 .open = snd_au1000_playback_open,
81268 .close = snd_au1000_playback_close,
81269 .ioctl = snd_pcm_lib_ioctl,
81270 @@ -427,7 +427,7 @@ static struct snd_pcm_ops snd_card_au100
81271 .pointer = snd_au1000_pointer,
81272 };
81273
81274 -static struct snd_pcm_ops snd_card_au1000_capture_ops = {
81275 +static const struct snd_pcm_ops snd_card_au1000_capture_ops = {
81276 .open = snd_au1000_capture_open,
81277 .close = snd_au1000_capture_close,
81278 .ioctl = snd_pcm_lib_ioctl,
81279 @@ -557,7 +557,7 @@ snd_au1000_ac97_new(struct snd_au1000 *a
81280 int err;
81281 struct snd_ac97_bus *pbus;
81282 struct snd_ac97_template ac97;
81283 - static struct snd_ac97_bus_ops ops = {
81284 + static const struct snd_ac97_bus_ops ops = {
81285 .write = snd_au1000_ac97_write,
81286 .read = snd_au1000_ac97_read,
81287 };
81288 diff -urNp linux-2.6.39.2/sound/mips/hal2.c linux-2.6.39.2/sound/mips/hal2.c
81289 --- linux-2.6.39.2/sound/mips/hal2.c 2011-05-19 00:06:34.000000000 -0400
81290 +++ linux-2.6.39.2/sound/mips/hal2.c 2011-05-22 19:36:35.000000000 -0400
81291 @@ -708,7 +708,7 @@ static int hal2_capture_ack(struct snd_p
81292 return 0;
81293 }
81294
81295 -static struct snd_pcm_ops hal2_playback_ops = {
81296 +static const struct snd_pcm_ops hal2_playback_ops = {
81297 .open = hal2_playback_open,
81298 .close = hal2_playback_close,
81299 .ioctl = snd_pcm_lib_ioctl,
81300 @@ -720,7 +720,7 @@ static struct snd_pcm_ops hal2_playback_
81301 .ack = hal2_playback_ack,
81302 };
81303
81304 -static struct snd_pcm_ops hal2_capture_ops = {
81305 +static const struct snd_pcm_ops hal2_capture_ops = {
81306 .open = hal2_capture_open,
81307 .close = hal2_capture_close,
81308 .ioctl = snd_pcm_lib_ioctl,
81309 @@ -766,7 +766,7 @@ static int hal2_dev_free(struct snd_devi
81310 return 0;
81311 }
81312
81313 -static struct snd_device_ops hal2_ops = {
81314 +static const struct snd_device_ops hal2_ops = {
81315 .dev_free = hal2_dev_free,
81316 };
81317
81318 diff -urNp linux-2.6.39.2/sound/mips/sgio2audio.c linux-2.6.39.2/sound/mips/sgio2audio.c
81319 --- linux-2.6.39.2/sound/mips/sgio2audio.c 2011-05-19 00:06:34.000000000 -0400
81320 +++ linux-2.6.39.2/sound/mips/sgio2audio.c 2011-05-22 19:36:35.000000000 -0400
81321 @@ -681,7 +681,7 @@ snd_sgio2audio_pcm_pointer(struct snd_pc
81322 }
81323
81324 /* operators */
81325 -static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
81326 +static const struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
81327 .open = snd_sgio2audio_playback1_open,
81328 .close = snd_sgio2audio_pcm_close,
81329 .ioctl = snd_pcm_lib_ioctl,
81330 @@ -694,7 +694,7 @@ static struct snd_pcm_ops snd_sgio2audio
81331 .mmap = snd_pcm_lib_mmap_vmalloc,
81332 };
81333
81334 -static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
81335 +static const struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
81336 .open = snd_sgio2audio_playback2_open,
81337 .close = snd_sgio2audio_pcm_close,
81338 .ioctl = snd_pcm_lib_ioctl,
81339 @@ -707,7 +707,7 @@ static struct snd_pcm_ops snd_sgio2audio
81340 .mmap = snd_pcm_lib_mmap_vmalloc,
81341 };
81342
81343 -static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81344 +static const struct snd_pcm_ops snd_sgio2audio_capture_ops = {
81345 .open = snd_sgio2audio_capture_open,
81346 .close = snd_sgio2audio_pcm_close,
81347 .ioctl = snd_pcm_lib_ioctl,
81348 @@ -829,7 +829,7 @@ static int snd_sgio2audio_dev_free(struc
81349 return snd_sgio2audio_free(chip);
81350 }
81351
81352 -static struct snd_device_ops ops = {
81353 +static const struct snd_device_ops ops = {
81354 .dev_free = snd_sgio2audio_dev_free,
81355 };
81356
81357 diff -urNp linux-2.6.39.2/sound/oss/ac97_codec.c linux-2.6.39.2/sound/oss/ac97_codec.c
81358 --- linux-2.6.39.2/sound/oss/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81359 +++ linux-2.6.39.2/sound/oss/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81360 @@ -99,23 +99,23 @@ static int generic_digital_control(struc
81361 * operations yet
81362 */
81363
81364 -static struct ac97_ops null_ops = { NULL, NULL, NULL };
81365 -static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81366 -static struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81367 -static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81368 -static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81369 -static struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81370 -static struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81371 -static struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81372 -static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81373 -static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81374 -static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81375 -static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81376 -static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81377 -static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81378 -static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81379 -static struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81380 -static struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81381 +static const struct ac97_ops null_ops = { NULL, NULL, NULL };
81382 +static const struct ac97_ops default_ops = { NULL, eapd_control, NULL };
81383 +static const struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
81384 +static const struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
81385 +static const struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
81386 +static const struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
81387 +static const struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
81388 +static const struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
81389 +static const struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
81390 +static const struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
81391 +static const struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
81392 +static const struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
81393 +static const struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
81394 +static const struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
81395 +static const struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
81396 +static const struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
81397 +static const struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
81398
81399 /* sorted by vendor/device id */
81400 static const struct {
81401 diff -urNp linux-2.6.39.2/sound/oss/sb_audio.c linux-2.6.39.2/sound/oss/sb_audio.c
81402 --- linux-2.6.39.2/sound/oss/sb_audio.c 2011-05-19 00:06:34.000000000 -0400
81403 +++ linux-2.6.39.2/sound/oss/sb_audio.c 2011-05-22 19:36:35.000000000 -0400
81404 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81405 buf16 = (signed short *)(localbuf + localoffs);
81406 while (c)
81407 {
81408 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81409 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81410 if (copy_from_user(lbuf8,
81411 userbuf+useroffs + p,
81412 locallen))
81413 diff -urNp linux-2.6.39.2/sound/oss/swarm_cs4297a.c linux-2.6.39.2/sound/oss/swarm_cs4297a.c
81414 --- linux-2.6.39.2/sound/oss/swarm_cs4297a.c 2011-05-19 00:06:34.000000000 -0400
81415 +++ linux-2.6.39.2/sound/oss/swarm_cs4297a.c 2011-05-22 19:36:35.000000000 -0400
81416 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81417 {
81418 struct cs4297a_state *s;
81419 u32 pwr, id;
81420 - mm_segment_t fs;
81421 int rval;
81422 #ifndef CONFIG_BCM_CS4297A_CSWARM
81423 u64 cfg;
81424 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81425 if (!rval) {
81426 char *sb1250_duart_present;
81427
81428 +#if 0
81429 + mm_segment_t fs;
81430 fs = get_fs();
81431 set_fs(KERNEL_DS);
81432 -#if 0
81433 val = SOUND_MASK_LINE;
81434 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81435 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81436 val = initvol[i].vol;
81437 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81438 }
81439 + set_fs(fs);
81440 // cs4297a_write_ac97(s, 0x18, 0x0808);
81441 #else
81442 // cs4297a_write_ac97(s, 0x5e, 0x180);
81443 cs4297a_write_ac97(s, 0x02, 0x0808);
81444 cs4297a_write_ac97(s, 0x18, 0x0808);
81445 #endif
81446 - set_fs(fs);
81447
81448 list_add(&s->list, &cs4297a_devs);
81449
81450 diff -urNp linux-2.6.39.2/sound/parisc/harmony.c linux-2.6.39.2/sound/parisc/harmony.c
81451 --- linux-2.6.39.2/sound/parisc/harmony.c 2011-05-19 00:06:34.000000000 -0400
81452 +++ linux-2.6.39.2/sound/parisc/harmony.c 2011-05-22 19:36:35.000000000 -0400
81453 @@ -596,7 +596,7 @@ snd_harmony_hw_free(struct snd_pcm_subst
81454 return snd_pcm_lib_free_pages(ss);
81455 }
81456
81457 -static struct snd_pcm_ops snd_harmony_playback_ops = {
81458 +static const struct snd_pcm_ops snd_harmony_playback_ops = {
81459 .open = snd_harmony_playback_open,
81460 .close = snd_harmony_playback_close,
81461 .ioctl = snd_pcm_lib_ioctl,
81462 @@ -607,7 +607,7 @@ static struct snd_pcm_ops snd_harmony_pl
81463 .pointer = snd_harmony_playback_pointer,
81464 };
81465
81466 -static struct snd_pcm_ops snd_harmony_capture_ops = {
81467 +static const struct snd_pcm_ops snd_harmony_capture_ops = {
81468 .open = snd_harmony_capture_open,
81469 .close = snd_harmony_capture_close,
81470 .ioctl = snd_pcm_lib_ioctl,
81471 @@ -922,7 +922,7 @@ snd_harmony_create(struct snd_card *card
81472 {
81473 int err;
81474 struct snd_harmony *h;
81475 - static struct snd_device_ops ops = {
81476 + static const struct snd_device_ops ops = {
81477 .dev_free = snd_harmony_dev_free,
81478 };
81479
81480 diff -urNp linux-2.6.39.2/sound/pci/ac97/ac97_codec.c linux-2.6.39.2/sound/pci/ac97/ac97_codec.c
81481 --- linux-2.6.39.2/sound/pci/ac97/ac97_codec.c 2011-05-19 00:06:34.000000000 -0400
81482 +++ linux-2.6.39.2/sound/pci/ac97/ac97_codec.c 2011-05-22 19:36:35.000000000 -0400
81483 @@ -1910,12 +1910,12 @@ static int ac97_reset_wait(struct snd_ac
81484 *
81485 * Returns zero if successful, or a negative error code on failure.
81486 */
81487 -int snd_ac97_bus(struct snd_card *card, int num, struct snd_ac97_bus_ops *ops,
81488 +int snd_ac97_bus(struct snd_card *card, int num, const struct snd_ac97_bus_ops *ops,
81489 void *private_data, struct snd_ac97_bus **rbus)
81490 {
81491 int err;
81492 struct snd_ac97_bus *bus;
81493 - static struct snd_device_ops dev_ops = {
81494 + static const struct snd_device_ops dev_ops = {
81495 .dev_free = snd_ac97_bus_dev_free,
81496 };
81497
81498 @@ -2015,7 +2015,7 @@ int snd_ac97_mixer(struct snd_ac97_bus *
81499 unsigned long end_time;
81500 unsigned int reg;
81501 const struct ac97_codec_id *pid;
81502 - static struct snd_device_ops ops = {
81503 + static const struct snd_device_ops ops = {
81504 .dev_free = snd_ac97_dev_free,
81505 .dev_register = snd_ac97_dev_register,
81506 .dev_disconnect = snd_ac97_dev_disconnect,
81507 diff -urNp linux-2.6.39.2/sound/pci/ad1889.c linux-2.6.39.2/sound/pci/ad1889.c
81508 --- linux-2.6.39.2/sound/pci/ad1889.c 2011-05-19 00:06:34.000000000 -0400
81509 +++ linux-2.6.39.2/sound/pci/ad1889.c 2011-05-22 19:36:35.000000000 -0400
81510 @@ -574,7 +574,7 @@ snd_ad1889_capture_pointer(struct snd_pc
81511 return bytes_to_frames(ss->runtime, ptr);
81512 }
81513
81514 -static struct snd_pcm_ops snd_ad1889_playback_ops = {
81515 +static const struct snd_pcm_ops snd_ad1889_playback_ops = {
81516 .open = snd_ad1889_playback_open,
81517 .close = snd_ad1889_playback_close,
81518 .ioctl = snd_pcm_lib_ioctl,
81519 @@ -585,7 +585,7 @@ static struct snd_pcm_ops snd_ad1889_pla
81520 .pointer = snd_ad1889_playback_pointer,
81521 };
81522
81523 -static struct snd_pcm_ops snd_ad1889_capture_ops = {
81524 +static const struct snd_pcm_ops snd_ad1889_capture_ops = {
81525 .open = snd_ad1889_capture_open,
81526 .close = snd_ad1889_capture_close,
81527 .ioctl = snd_pcm_lib_ioctl,
81528 @@ -809,7 +809,7 @@ snd_ad1889_ac97_init(struct snd_ad1889 *
81529 {
81530 int err;
81531 struct snd_ac97_template ac97;
81532 - static struct snd_ac97_bus_ops ops = {
81533 + static const struct snd_ac97_bus_ops ops = {
81534 .write = snd_ad1889_ac97_write,
81535 .read = snd_ad1889_ac97_read,
81536 };
81537 @@ -899,7 +899,7 @@ snd_ad1889_create(struct snd_card *card,
81538 int err;
81539
81540 struct snd_ad1889 *chip;
81541 - static struct snd_device_ops ops = {
81542 + static const struct snd_device_ops ops = {
81543 .dev_free = snd_ad1889_dev_free,
81544 };
81545
81546 diff -urNp linux-2.6.39.2/sound/pci/ak4531_codec.c linux-2.6.39.2/sound/pci/ak4531_codec.c
81547 --- linux-2.6.39.2/sound/pci/ak4531_codec.c 2011-05-19 00:06:34.000000000 -0400
81548 +++ linux-2.6.39.2/sound/pci/ak4531_codec.c 2011-05-22 19:36:35.000000000 -0400
81549 @@ -389,7 +389,7 @@ int __devinit snd_ak4531_mixer(struct sn
81550 unsigned int idx;
81551 int err;
81552 struct snd_ak4531 *ak4531;
81553 - static struct snd_device_ops ops = {
81554 + static const struct snd_device_ops ops = {
81555 .dev_free = snd_ak4531_dev_free,
81556 };
81557
81558 diff -urNp linux-2.6.39.2/sound/pci/ali5451/ali5451.c linux-2.6.39.2/sound/pci/ali5451/ali5451.c
81559 --- linux-2.6.39.2/sound/pci/ali5451/ali5451.c 2011-05-19 00:06:34.000000000 -0400
81560 +++ linux-2.6.39.2/sound/pci/ali5451/ali5451.c 2011-05-22 19:36:35.000000000 -0400
81561 @@ -1847,7 +1847,7 @@ static int __devinit snd_ali_mixer(struc
81562 struct snd_ac97_template ac97;
81563 unsigned int idx;
81564 int i, err;
81565 - static struct snd_ac97_bus_ops ops = {
81566 + static const struct snd_ac97_bus_ops ops = {
81567 .write = snd_ali_codec_write,
81568 .read = snd_ali_codec_read,
81569 };
81570 @@ -2114,7 +2114,7 @@ static int __devinit snd_ali_create(stru
81571 struct snd_ali *codec;
81572 int i, err;
81573 unsigned short cmdw;
81574 - static struct snd_device_ops ops = {
81575 + static const struct snd_device_ops ops = {
81576 .dev_free = snd_ali_dev_free,
81577 };
81578
81579 diff -urNp linux-2.6.39.2/sound/pci/als300.c linux-2.6.39.2/sound/pci/als300.c
81580 --- linux-2.6.39.2/sound/pci/als300.c 2011-05-19 00:06:34.000000000 -0400
81581 +++ linux-2.6.39.2/sound/pci/als300.c 2011-05-22 19:36:35.000000000 -0400
81582 @@ -319,7 +319,7 @@ static int snd_als300_ac97(struct snd_al
81583 struct snd_ac97_bus *bus;
81584 struct snd_ac97_template ac97;
81585 int err;
81586 - static struct snd_ac97_bus_ops ops = {
81587 + static const struct snd_ac97_bus_ops ops = {
81588 .write = snd_als300_ac97_write,
81589 .read = snd_als300_ac97_read,
81590 };
81591 @@ -589,7 +589,7 @@ static snd_pcm_uframes_t snd_als300_poin
81592 return bytes_to_frames(substream->runtime, current_ptr);
81593 }
81594
81595 -static struct snd_pcm_ops snd_als300_playback_ops = {
81596 +static const struct snd_pcm_ops snd_als300_playback_ops = {
81597 .open = snd_als300_playback_open,
81598 .close = snd_als300_playback_close,
81599 .ioctl = snd_pcm_lib_ioctl,
81600 @@ -600,7 +600,7 @@ static struct snd_pcm_ops snd_als300_pla
81601 .pointer = snd_als300_pointer,
81602 };
81603
81604 -static struct snd_pcm_ops snd_als300_capture_ops = {
81605 +static const struct snd_pcm_ops snd_als300_capture_ops = {
81606 .open = snd_als300_capture_open,
81607 .close = snd_als300_capture_close,
81608 .ioctl = snd_pcm_lib_ioctl,
81609 @@ -680,7 +680,7 @@ static int __devinit snd_als300_create(s
81610 void *irq_handler;
81611 int err;
81612
81613 - static struct snd_device_ops ops = {
81614 + static const struct snd_device_ops ops = {
81615 .dev_free = snd_als300_dev_free,
81616 };
81617 *rchip = NULL;
81618 diff -urNp linux-2.6.39.2/sound/pci/als4000.c linux-2.6.39.2/sound/pci/als4000.c
81619 --- linux-2.6.39.2/sound/pci/als4000.c 2011-05-19 00:06:34.000000000 -0400
81620 +++ linux-2.6.39.2/sound/pci/als4000.c 2011-05-22 19:36:35.000000000 -0400
81621 @@ -672,7 +672,7 @@ static int snd_als4000_capture_close(str
81622
81623 /******************************************************************/
81624
81625 -static struct snd_pcm_ops snd_als4000_playback_ops = {
81626 +static const struct snd_pcm_ops snd_als4000_playback_ops = {
81627 .open = snd_als4000_playback_open,
81628 .close = snd_als4000_playback_close,
81629 .ioctl = snd_pcm_lib_ioctl,
81630 @@ -683,7 +683,7 @@ static struct snd_pcm_ops snd_als4000_pl
81631 .pointer = snd_als4000_playback_pointer
81632 };
81633
81634 -static struct snd_pcm_ops snd_als4000_capture_ops = {
81635 +static const struct snd_pcm_ops snd_als4000_capture_ops = {
81636 .open = snd_als4000_capture_open,
81637 .close = snd_als4000_capture_close,
81638 .ioctl = snd_pcm_lib_ioctl,
81639 diff -urNp linux-2.6.39.2/sound/pci/asihpi/asihpi.c linux-2.6.39.2/sound/pci/asihpi/asihpi.c
81640 --- linux-2.6.39.2/sound/pci/asihpi/asihpi.c 2011-05-19 00:06:34.000000000 -0400
81641 +++ linux-2.6.39.2/sound/pci/asihpi/asihpi.c 2011-05-22 19:36:35.000000000 -0400
81642 @@ -1067,7 +1067,7 @@ static int snd_card_asihpi_playback_sile
81643 return 0;
81644 }
81645
81646 -static struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81647 +static const struct snd_pcm_ops snd_card_asihpi_playback_ops = {
81648 .open = snd_card_asihpi_playback_open,
81649 .close = snd_card_asihpi_playback_close,
81650 .ioctl = snd_card_asihpi_playback_ioctl,
81651 @@ -1080,7 +1080,7 @@ static struct snd_pcm_ops snd_card_asihp
81652 .silence = snd_card_asihpi_playback_silence,
81653 };
81654
81655 -static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81656 +static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
81657 .open = snd_card_asihpi_playback_open,
81658 .close = snd_card_asihpi_playback_close,
81659 .ioctl = snd_card_asihpi_playback_ioctl,
81660 @@ -1268,7 +1268,7 @@ static int snd_card_asihpi_capture_copy(
81661 return 0;
81662 }
81663
81664 -static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81665 +static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
81666 .open = snd_card_asihpi_capture_open,
81667 .close = snd_card_asihpi_capture_close,
81668 .ioctl = snd_card_asihpi_capture_ioctl,
81669 @@ -1279,7 +1279,7 @@ static struct snd_pcm_ops snd_card_asihp
81670 .pointer = snd_card_asihpi_capture_pointer,
81671 };
81672
81673 -static struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81674 +static const struct snd_pcm_ops snd_card_asihpi_capture_ops = {
81675 .open = snd_card_asihpi_capture_open,
81676 .close = snd_card_asihpi_capture_close,
81677 .ioctl = snd_card_asihpi_capture_ioctl,
81678 diff -urNp linux-2.6.39.2/sound/pci/atiixp.c linux-2.6.39.2/sound/pci/atiixp.c
81679 --- linux-2.6.39.2/sound/pci/atiixp.c 2011-05-19 00:06:34.000000000 -0400
81680 +++ linux-2.6.39.2/sound/pci/atiixp.c 2011-05-22 19:36:35.000000000 -0400
81681 @@ -1148,7 +1148,7 @@ static int snd_atiixp_spdif_close(struct
81682 }
81683
81684 /* AC97 playback */
81685 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81686 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81687 .open = snd_atiixp_playback_open,
81688 .close = snd_atiixp_playback_close,
81689 .ioctl = snd_pcm_lib_ioctl,
81690 @@ -1160,7 +1160,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81691 };
81692
81693 /* AC97 capture */
81694 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81695 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81696 .open = snd_atiixp_capture_open,
81697 .close = snd_atiixp_capture_close,
81698 .ioctl = snd_pcm_lib_ioctl,
81699 @@ -1172,7 +1172,7 @@ static struct snd_pcm_ops snd_atiixp_cap
81700 };
81701
81702 /* SPDIF playback */
81703 -static struct snd_pcm_ops snd_atiixp_spdif_ops = {
81704 +static const struct snd_pcm_ops snd_atiixp_spdif_ops = {
81705 .open = snd_atiixp_spdif_open,
81706 .close = snd_atiixp_spdif_close,
81707 .ioctl = snd_pcm_lib_ioctl,
81708 @@ -1410,7 +1410,7 @@ static int __devinit snd_atiixp_mixer_ne
81709 struct snd_ac97_template ac97;
81710 int i, err;
81711 int codec_count;
81712 - static struct snd_ac97_bus_ops ops = {
81713 + static const struct snd_ac97_bus_ops ops = {
81714 .write = snd_atiixp_ac97_write,
81715 .read = snd_atiixp_ac97_read,
81716 };
81717 @@ -1590,7 +1590,7 @@ static int __devinit snd_atiixp_create(s
81718 struct pci_dev *pci,
81719 struct atiixp **r_chip)
81720 {
81721 - static struct snd_device_ops ops = {
81722 + static const struct snd_device_ops ops = {
81723 .dev_free = snd_atiixp_dev_free,
81724 };
81725 struct atiixp *chip;
81726 diff -urNp linux-2.6.39.2/sound/pci/atiixp_modem.c linux-2.6.39.2/sound/pci/atiixp_modem.c
81727 --- linux-2.6.39.2/sound/pci/atiixp_modem.c 2011-05-19 00:06:34.000000000 -0400
81728 +++ linux-2.6.39.2/sound/pci/atiixp_modem.c 2011-05-22 19:36:35.000000000 -0400
81729 @@ -947,7 +947,7 @@ static int snd_atiixp_capture_close(stru
81730
81731
81732 /* AC97 playback */
81733 -static struct snd_pcm_ops snd_atiixp_playback_ops = {
81734 +static const struct snd_pcm_ops snd_atiixp_playback_ops = {
81735 .open = snd_atiixp_playback_open,
81736 .close = snd_atiixp_playback_close,
81737 .ioctl = snd_pcm_lib_ioctl,
81738 @@ -959,7 +959,7 @@ static struct snd_pcm_ops snd_atiixp_pla
81739 };
81740
81741 /* AC97 capture */
81742 -static struct snd_pcm_ops snd_atiixp_capture_ops = {
81743 +static const struct snd_pcm_ops snd_atiixp_capture_ops = {
81744 .open = snd_atiixp_capture_open,
81745 .close = snd_atiixp_capture_close,
81746 .ioctl = snd_pcm_lib_ioctl,
81747 @@ -1067,7 +1067,7 @@ static int __devinit snd_atiixp_mixer_ne
81748 struct snd_ac97_template ac97;
81749 int i, err;
81750 int codec_count;
81751 - static struct snd_ac97_bus_ops ops = {
81752 + static const struct snd_ac97_bus_ops ops = {
81753 .write = snd_atiixp_ac97_write,
81754 .read = snd_atiixp_ac97_read,
81755 };
81756 @@ -1226,7 +1226,7 @@ static int __devinit snd_atiixp_create(s
81757 struct pci_dev *pci,
81758 struct atiixp_modem **r_chip)
81759 {
81760 - static struct snd_device_ops ops = {
81761 + static const struct snd_device_ops ops = {
81762 .dev_free = snd_atiixp_dev_free,
81763 };
81764 struct atiixp_modem *chip;
81765 diff -urNp linux-2.6.39.2/sound/pci/au88x0/au88x0_pcm.c linux-2.6.39.2/sound/pci/au88x0/au88x0_pcm.c
81766 --- linux-2.6.39.2/sound/pci/au88x0/au88x0_pcm.c 2011-05-19 00:06:34.000000000 -0400
81767 +++ linux-2.6.39.2/sound/pci/au88x0/au88x0_pcm.c 2011-05-22 19:36:35.000000000 -0400
81768 @@ -409,7 +409,7 @@ static snd_pcm_uframes_t snd_vortex_pcm_
81769 }
81770
81771 /* operators */
81772 -static struct snd_pcm_ops snd_vortex_playback_ops = {
81773 +static const struct snd_pcm_ops snd_vortex_playback_ops = {
81774 .open = snd_vortex_pcm_open,
81775 .close = snd_vortex_pcm_close,
81776 .ioctl = snd_pcm_lib_ioctl,
81777 diff -urNp linux-2.6.39.2/sound/pci/aw2/aw2-alsa.c linux-2.6.39.2/sound/pci/aw2/aw2-alsa.c
81778 --- linux-2.6.39.2/sound/pci/aw2/aw2-alsa.c 2011-05-19 00:06:34.000000000 -0400
81779 +++ linux-2.6.39.2/sound/pci/aw2/aw2-alsa.c 2011-05-22 19:36:35.000000000 -0400
81780 @@ -178,7 +178,7 @@ static struct pci_driver driver = {
81781 };
81782
81783 /* operators for playback PCM alsa interface */
81784 -static struct snd_pcm_ops snd_aw2_playback_ops = {
81785 +static const struct snd_pcm_ops snd_aw2_playback_ops = {
81786 .open = snd_aw2_pcm_playback_open,
81787 .close = snd_aw2_pcm_playback_close,
81788 .ioctl = snd_pcm_lib_ioctl,
81789 @@ -190,7 +190,7 @@ static struct snd_pcm_ops snd_aw2_playba
81790 };
81791
81792 /* operators for capture PCM alsa interface */
81793 -static struct snd_pcm_ops snd_aw2_capture_ops = {
81794 +static const struct snd_pcm_ops snd_aw2_capture_ops = {
81795 .open = snd_aw2_pcm_capture_open,
81796 .close = snd_aw2_pcm_capture_close,
81797 .ioctl = snd_pcm_lib_ioctl,
81798 @@ -263,7 +263,7 @@ static int __devinit snd_aw2_create(stru
81799 {
81800 struct aw2 *chip;
81801 int err;
81802 - static struct snd_device_ops ops = {
81803 + static const struct snd_device_ops ops = {
81804 .dev_free = snd_aw2_dev_free,
81805 };
81806
81807 diff -urNp linux-2.6.39.2/sound/pci/azt3328.c linux-2.6.39.2/sound/pci/azt3328.c
81808 --- linux-2.6.39.2/sound/pci/azt3328.c 2011-05-19 00:06:34.000000000 -0400
81809 +++ linux-2.6.39.2/sound/pci/azt3328.c 2011-05-22 19:36:35.000000000 -0400
81810 @@ -822,7 +822,7 @@ snd_azf3328_mixer_new(struct snd_azf3328
81811 {
81812 struct snd_ac97_bus *bus;
81813 struct snd_ac97_template ac97;
81814 - static struct snd_ac97_bus_ops ops = {
81815 + static const struct snd_ac97_bus_ops ops = {
81816 .write = snd_azf3328_mixer_ac97_write,
81817 .read = snd_azf3328_mixer_ac97_read,
81818 };
81819 @@ -2179,7 +2179,7 @@ snd_azf3328_pcm_close(struct snd_pcm_sub
81820
81821 /******************************************************************/
81822
81823 -static struct snd_pcm_ops snd_azf3328_playback_ops = {
81824 +static const struct snd_pcm_ops snd_azf3328_playback_ops = {
81825 .open = snd_azf3328_pcm_playback_open,
81826 .close = snd_azf3328_pcm_close,
81827 .ioctl = snd_pcm_lib_ioctl,
81828 @@ -2190,7 +2190,7 @@ static struct snd_pcm_ops snd_azf3328_pl
81829 .pointer = snd_azf3328_pcm_pointer
81830 };
81831
81832 -static struct snd_pcm_ops snd_azf3328_capture_ops = {
81833 +static const struct snd_pcm_ops snd_azf3328_capture_ops = {
81834 .open = snd_azf3328_pcm_capture_open,
81835 .close = snd_azf3328_pcm_close,
81836 .ioctl = snd_pcm_lib_ioctl,
81837 @@ -2201,7 +2201,7 @@ static struct snd_pcm_ops snd_azf3328_ca
81838 .pointer = snd_azf3328_pcm_pointer
81839 };
81840
81841 -static struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81842 +static const struct snd_pcm_ops snd_azf3328_i2s_out_ops = {
81843 .open = snd_azf3328_pcm_i2s_out_open,
81844 .close = snd_azf3328_pcm_close,
81845 .ioctl = snd_pcm_lib_ioctl,
81846 @@ -2497,7 +2497,7 @@ snd_azf3328_create(struct snd_card *card
81847 {
81848 struct snd_azf3328 *chip;
81849 int err;
81850 - static struct snd_device_ops ops = {
81851 + static const struct snd_device_ops ops = {
81852 .dev_free = snd_azf3328_dev_free,
81853 };
81854 u8 dma_init;
81855 diff -urNp linux-2.6.39.2/sound/pci/bt87x.c linux-2.6.39.2/sound/pci/bt87x.c
81856 --- linux-2.6.39.2/sound/pci/bt87x.c 2011-05-19 00:06:34.000000000 -0400
81857 +++ linux-2.6.39.2/sound/pci/bt87x.c 2011-05-22 19:36:35.000000000 -0400
81858 @@ -542,7 +542,7 @@ static snd_pcm_uframes_t snd_bt87x_point
81859 return (snd_pcm_uframes_t)bytes_to_frames(runtime, chip->current_line * chip->line_bytes);
81860 }
81861
81862 -static struct snd_pcm_ops snd_bt87x_pcm_ops = {
81863 +static const struct snd_pcm_ops snd_bt87x_pcm_ops = {
81864 .open = snd_bt87x_pcm_open,
81865 .close = snd_bt87x_close,
81866 .ioctl = snd_pcm_lib_ioctl,
81867 @@ -720,7 +720,7 @@ static int __devinit snd_bt87x_create(st
81868 {
81869 struct snd_bt87x *chip;
81870 int err;
81871 - static struct snd_device_ops ops = {
81872 + static const struct snd_device_ops ops = {
81873 .dev_free = snd_bt87x_dev_free
81874 };
81875
81876 diff -urNp linux-2.6.39.2/sound/pci/ca0106/ca0106_main.c linux-2.6.39.2/sound/pci/ca0106/ca0106_main.c
81877 --- linux-2.6.39.2/sound/pci/ca0106/ca0106_main.c 2011-05-19 00:06:34.000000000 -0400
81878 +++ linux-2.6.39.2/sound/pci/ca0106/ca0106_main.c 2011-05-22 19:36:35.000000000 -0400
81879 @@ -1103,7 +1103,7 @@ snd_ca0106_pcm_pointer_capture(struct sn
81880 }
81881
81882 /* operators */
81883 -static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81884 +static const struct snd_pcm_ops snd_ca0106_playback_front_ops = {
81885 .open = snd_ca0106_pcm_open_playback_front,
81886 .close = snd_ca0106_pcm_close_playback,
81887 .ioctl = snd_pcm_lib_ioctl,
81888 @@ -1114,7 +1114,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81889 .pointer = snd_ca0106_pcm_pointer_playback,
81890 };
81891
81892 -static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81893 +static const struct snd_pcm_ops snd_ca0106_capture_0_ops = {
81894 .open = snd_ca0106_pcm_open_0_capture,
81895 .close = snd_ca0106_pcm_close_capture,
81896 .ioctl = snd_pcm_lib_ioctl,
81897 @@ -1125,7 +1125,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81898 .pointer = snd_ca0106_pcm_pointer_capture,
81899 };
81900
81901 -static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81902 +static const struct snd_pcm_ops snd_ca0106_capture_1_ops = {
81903 .open = snd_ca0106_pcm_open_1_capture,
81904 .close = snd_ca0106_pcm_close_capture,
81905 .ioctl = snd_pcm_lib_ioctl,
81906 @@ -1136,7 +1136,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81907 .pointer = snd_ca0106_pcm_pointer_capture,
81908 };
81909
81910 -static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81911 +static const struct snd_pcm_ops snd_ca0106_capture_2_ops = {
81912 .open = snd_ca0106_pcm_open_2_capture,
81913 .close = snd_ca0106_pcm_close_capture,
81914 .ioctl = snd_pcm_lib_ioctl,
81915 @@ -1147,7 +1147,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81916 .pointer = snd_ca0106_pcm_pointer_capture,
81917 };
81918
81919 -static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81920 +static const struct snd_pcm_ops snd_ca0106_capture_3_ops = {
81921 .open = snd_ca0106_pcm_open_3_capture,
81922 .close = snd_ca0106_pcm_close_capture,
81923 .ioctl = snd_pcm_lib_ioctl,
81924 @@ -1158,7 +1158,7 @@ static struct snd_pcm_ops snd_ca0106_cap
81925 .pointer = snd_ca0106_pcm_pointer_capture,
81926 };
81927
81928 -static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81929 +static const struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
81930 .open = snd_ca0106_pcm_open_playback_center_lfe,
81931 .close = snd_ca0106_pcm_close_playback,
81932 .ioctl = snd_pcm_lib_ioctl,
81933 @@ -1169,7 +1169,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81934 .pointer = snd_ca0106_pcm_pointer_playback,
81935 };
81936
81937 -static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81938 +static const struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
81939 .open = snd_ca0106_pcm_open_playback_unknown,
81940 .close = snd_ca0106_pcm_close_playback,
81941 .ioctl = snd_pcm_lib_ioctl,
81942 @@ -1180,7 +1180,7 @@ static struct snd_pcm_ops snd_ca0106_pla
81943 .pointer = snd_ca0106_pcm_pointer_playback,
81944 };
81945
81946 -static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81947 +static const struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
81948 .open = snd_ca0106_pcm_open_playback_rear,
81949 .close = snd_ca0106_pcm_close_playback,
81950 .ioctl = snd_pcm_lib_ioctl,
81951 @@ -1223,7 +1223,7 @@ static int snd_ca0106_ac97(struct snd_ca
81952 struct snd_ac97_bus *pbus;
81953 struct snd_ac97_template ac97;
81954 int err;
81955 - static struct snd_ac97_bus_ops ops = {
81956 + static const struct snd_ac97_bus_ops ops = {
81957 .write = snd_ca0106_ac97_write,
81958 .read = snd_ca0106_ac97_read,
81959 };
81960 @@ -1629,7 +1629,7 @@ static int __devinit snd_ca0106_create(i
81961 struct snd_ca0106 *chip;
81962 struct snd_ca0106_details *c;
81963 int err;
81964 - static struct snd_device_ops ops = {
81965 + static const struct snd_device_ops ops = {
81966 .dev_free = snd_ca0106_dev_free,
81967 };
81968
81969 diff -urNp linux-2.6.39.2/sound/pci/ca0106/ca_midi.c linux-2.6.39.2/sound/pci/ca0106/ca_midi.c
81970 --- linux-2.6.39.2/sound/pci/ca0106/ca_midi.c 2011-05-19 00:06:34.000000000 -0400
81971 +++ linux-2.6.39.2/sound/pci/ca0106/ca_midi.c 2011-05-22 19:36:35.000000000 -0400
81972 @@ -255,15 +255,13 @@ static void ca_midi_output_trigger(struc
81973 }
81974 }
81975
81976 -static struct snd_rawmidi_ops ca_midi_output =
81977 -{
81978 +static const struct snd_rawmidi_ops ca_midi_output = {
81979 .open = ca_midi_output_open,
81980 .close = ca_midi_output_close,
81981 .trigger = ca_midi_output_trigger,
81982 };
81983
81984 -static struct snd_rawmidi_ops ca_midi_input =
81985 -{
81986 +static const struct snd_rawmidi_ops ca_midi_input = {
81987 .open = ca_midi_input_open,
81988 .close = ca_midi_input_close,
81989 .trigger = ca_midi_input_trigger,
81990 diff -urNp linux-2.6.39.2/sound/pci/cmipci.c linux-2.6.39.2/sound/pci/cmipci.c
81991 --- linux-2.6.39.2/sound/pci/cmipci.c 2011-05-19 00:06:34.000000000 -0400
81992 +++ linux-2.6.39.2/sound/pci/cmipci.c 2011-05-22 19:36:35.000000000 -0400
81993 @@ -1838,7 +1838,7 @@ static int snd_cmipci_capture_spdif_clos
81994 /*
81995 */
81996
81997 -static struct snd_pcm_ops snd_cmipci_playback_ops = {
81998 +static const struct snd_pcm_ops snd_cmipci_playback_ops = {
81999 .open = snd_cmipci_playback_open,
82000 .close = snd_cmipci_playback_close,
82001 .ioctl = snd_pcm_lib_ioctl,
82002 @@ -1849,7 +1849,7 @@ static struct snd_pcm_ops snd_cmipci_pla
82003 .pointer = snd_cmipci_playback_pointer,
82004 };
82005
82006 -static struct snd_pcm_ops snd_cmipci_capture_ops = {
82007 +static const struct snd_pcm_ops snd_cmipci_capture_ops = {
82008 .open = snd_cmipci_capture_open,
82009 .close = snd_cmipci_capture_close,
82010 .ioctl = snd_pcm_lib_ioctl,
82011 @@ -1860,7 +1860,7 @@ static struct snd_pcm_ops snd_cmipci_cap
82012 .pointer = snd_cmipci_capture_pointer,
82013 };
82014
82015 -static struct snd_pcm_ops snd_cmipci_playback2_ops = {
82016 +static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
82017 .open = snd_cmipci_playback2_open,
82018 .close = snd_cmipci_playback2_close,
82019 .ioctl = snd_pcm_lib_ioctl,
82020 @@ -1871,7 +1871,7 @@ static struct snd_pcm_ops snd_cmipci_pla
82021 .pointer = snd_cmipci_capture_pointer, /* channel B */
82022 };
82023
82024 -static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
82025 +static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
82026 .open = snd_cmipci_playback_spdif_open,
82027 .close = snd_cmipci_playback_spdif_close,
82028 .ioctl = snd_pcm_lib_ioctl,
82029 @@ -1882,7 +1882,7 @@ static struct snd_pcm_ops snd_cmipci_pla
82030 .pointer = snd_cmipci_playback_pointer,
82031 };
82032
82033 -static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
82034 +static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
82035 .open = snd_cmipci_capture_spdif_open,
82036 .close = snd_cmipci_capture_spdif_close,
82037 .ioctl = snd_pcm_lib_ioctl,
82038 @@ -3011,7 +3011,7 @@ static int __devinit snd_cmipci_create(s
82039 {
82040 struct cmipci *cm;
82041 int err;
82042 - static struct snd_device_ops ops = {
82043 + static const struct snd_device_ops ops = {
82044 .dev_free = snd_cmipci_dev_free,
82045 };
82046 unsigned int val;
82047 diff -urNp linux-2.6.39.2/sound/pci/cs4281.c linux-2.6.39.2/sound/pci/cs4281.c
82048 --- linux-2.6.39.2/sound/pci/cs4281.c 2011-05-19 00:06:34.000000000 -0400
82049 +++ linux-2.6.39.2/sound/pci/cs4281.c 2011-05-22 19:36:35.000000000 -0400
82050 @@ -947,7 +947,7 @@ static int snd_cs4281_capture_close(stru
82051 return 0;
82052 }
82053
82054 -static struct snd_pcm_ops snd_cs4281_playback_ops = {
82055 +static const struct snd_pcm_ops snd_cs4281_playback_ops = {
82056 .open = snd_cs4281_playback_open,
82057 .close = snd_cs4281_playback_close,
82058 .ioctl = snd_pcm_lib_ioctl,
82059 @@ -958,7 +958,7 @@ static struct snd_pcm_ops snd_cs4281_pla
82060 .pointer = snd_cs4281_pointer,
82061 };
82062
82063 -static struct snd_pcm_ops snd_cs4281_capture_ops = {
82064 +static const struct snd_pcm_ops snd_cs4281_capture_ops = {
82065 .open = snd_cs4281_capture_open,
82066 .close = snd_cs4281_capture_close,
82067 .ioctl = snd_pcm_lib_ioctl,
82068 @@ -1098,7 +1098,7 @@ static int __devinit snd_cs4281_mixer(st
82069 struct snd_card *card = chip->card;
82070 struct snd_ac97_template ac97;
82071 int err;
82072 - static struct snd_ac97_bus_ops ops = {
82073 + static const struct snd_ac97_bus_ops ops = {
82074 .write = snd_cs4281_ac97_write,
82075 .read = snd_cs4281_ac97_read,
82076 };
82077 @@ -1343,7 +1343,7 @@ static int __devinit snd_cs4281_create(s
82078 struct cs4281 *chip;
82079 unsigned int tmp;
82080 int err;
82081 - static struct snd_device_ops ops = {
82082 + static const struct snd_device_ops ops = {
82083 .dev_free = snd_cs4281_dev_free,
82084 };
82085
82086 @@ -1765,15 +1765,13 @@ static void snd_cs4281_midi_output_trigg
82087 spin_unlock_irqrestore(&chip->reg_lock, flags);
82088 }
82089
82090 -static struct snd_rawmidi_ops snd_cs4281_midi_output =
82091 -{
82092 +static const struct snd_rawmidi_ops snd_cs4281_midi_output = {
82093 .open = snd_cs4281_midi_output_open,
82094 .close = snd_cs4281_midi_output_close,
82095 .trigger = snd_cs4281_midi_output_trigger,
82096 };
82097
82098 -static struct snd_rawmidi_ops snd_cs4281_midi_input =
82099 -{
82100 +static const struct snd_rawmidi_ops snd_cs4281_midi_input = {
82101 .open = snd_cs4281_midi_input_open,
82102 .close = snd_cs4281_midi_input_close,
82103 .trigger = snd_cs4281_midi_input_trigger,
82104 diff -urNp linux-2.6.39.2/sound/pci/cs46xx/cs46xx_lib.c linux-2.6.39.2/sound/pci/cs46xx/cs46xx_lib.c
82105 --- linux-2.6.39.2/sound/pci/cs46xx/cs46xx_lib.c 2011-05-19 00:06:34.000000000 -0400
82106 +++ linux-2.6.39.2/sound/pci/cs46xx/cs46xx_lib.c 2011-05-22 19:36:35.000000000 -0400
82107 @@ -3722,7 +3722,7 @@ int __devinit snd_cs46xx_create(struct s
82108 struct snd_cs46xx_region *region;
82109 struct cs_card_type *cp;
82110 u16 ss_card, ss_vendor;
82111 - static struct snd_device_ops ops = {
82112 + static const struct snd_device_ops ops = {
82113 .dev_free = snd_cs46xx_dev_free,
82114 };
82115
82116 diff -urNp linux-2.6.39.2/sound/pci/cs5530.c linux-2.6.39.2/sound/pci/cs5530.c
82117 --- linux-2.6.39.2/sound/pci/cs5530.c 2011-05-19 00:06:34.000000000 -0400
82118 +++ linux-2.6.39.2/sound/pci/cs5530.c 2011-05-22 19:36:35.000000000 -0400
82119 @@ -107,7 +107,7 @@ static int __devinit snd_cs5530_create(s
82120 void __iomem *mem;
82121 int err;
82122
82123 - static struct snd_device_ops ops = {
82124 + static const struct snd_device_ops ops = {
82125 .dev_free = snd_cs5530_dev_free,
82126 };
82127 *rchip = NULL;
82128 diff -urNp linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio.c linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio.c
82129 --- linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio.c 2011-05-19 00:06:34.000000000 -0400
82130 +++ linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio.c 2011-05-22 19:36:35.000000000 -0400
82131 @@ -150,7 +150,7 @@ static int __devinit snd_cs5535audio_mix
82132 struct snd_ac97_bus *pbus;
82133 struct snd_ac97_template ac97;
82134 int err;
82135 - static struct snd_ac97_bus_ops ops = {
82136 + static const struct snd_ac97_bus_ops ops = {
82137 .write = snd_cs5535audio_ac97_codec_write,
82138 .read = snd_cs5535audio_ac97_codec_read,
82139 };
82140 @@ -277,7 +277,7 @@ static int __devinit snd_cs5535audio_cre
82141 struct cs5535audio *cs5535au;
82142
82143 int err;
82144 - static struct snd_device_ops ops = {
82145 + static const struct snd_device_ops ops = {
82146 .dev_free = snd_cs5535audio_dev_free,
82147 };
82148
82149 diff -urNp linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio_pcm.c linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio_pcm.c
82150 --- linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-19 00:06:34.000000000 -0400
82151 +++ linux-2.6.39.2/sound/pci/cs5535audio/cs5535audio_pcm.c 2011-05-22 19:36:35.000000000 -0400
82152 @@ -380,7 +380,7 @@ static int snd_cs5535audio_capture_prepa
82153 substream->runtime->rate);
82154 }
82155
82156 -static struct snd_pcm_ops snd_cs5535audio_playback_ops = {
82157 +static const struct snd_pcm_ops snd_cs5535audio_playback_ops = {
82158 .open = snd_cs5535audio_playback_open,
82159 .close = snd_cs5535audio_playback_close,
82160 .ioctl = snd_pcm_lib_ioctl,
82161 @@ -391,7 +391,7 @@ static struct snd_pcm_ops snd_cs5535audi
82162 .pointer = snd_cs5535audio_pcm_pointer,
82163 };
82164
82165 -static struct snd_pcm_ops snd_cs5535audio_capture_ops = {
82166 +static const struct snd_pcm_ops snd_cs5535audio_capture_ops = {
82167 .open = snd_cs5535audio_capture_open,
82168 .close = snd_cs5535audio_capture_close,
82169 .ioctl = snd_pcm_lib_ioctl,
82170 diff -urNp linux-2.6.39.2/sound/pci/ctxfi/ctpcm.c linux-2.6.39.2/sound/pci/ctxfi/ctpcm.c
82171 --- linux-2.6.39.2/sound/pci/ctxfi/ctpcm.c 2011-05-19 00:06:34.000000000 -0400
82172 +++ linux-2.6.39.2/sound/pci/ctxfi/ctpcm.c 2011-05-22 19:36:35.000000000 -0400
82173 @@ -370,7 +370,7 @@ ct_pcm_capture_pointer(struct snd_pcm_su
82174 }
82175
82176 /* PCM operators for playback */
82177 -static struct snd_pcm_ops ct_pcm_playback_ops = {
82178 +static const struct snd_pcm_ops ct_pcm_playback_ops = {
82179 .open = ct_pcm_playback_open,
82180 .close = ct_pcm_playback_close,
82181 .ioctl = snd_pcm_lib_ioctl,
82182 @@ -383,7 +383,7 @@ static struct snd_pcm_ops ct_pcm_playbac
82183 };
82184
82185 /* PCM operators for capture */
82186 -static struct snd_pcm_ops ct_pcm_capture_ops = {
82187 +static const struct snd_pcm_ops ct_pcm_capture_ops = {
82188 .open = ct_pcm_capture_open,
82189 .close = ct_pcm_capture_close,
82190 .ioctl = snd_pcm_lib_ioctl,
82191 diff -urNp linux-2.6.39.2/sound/pci/echoaudio/echoaudio.c linux-2.6.39.2/sound/pci/echoaudio/echoaudio.c
82192 --- linux-2.6.39.2/sound/pci/echoaudio/echoaudio.c 2011-05-19 00:06:34.000000000 -0400
82193 +++ linux-2.6.39.2/sound/pci/echoaudio/echoaudio.c 2011-05-22 19:36:35.000000000 -0400
82194 @@ -831,7 +831,7 @@ static snd_pcm_uframes_t pcm_pointer(str
82195
82196
82197 /* pcm *_ops structures */
82198 -static struct snd_pcm_ops analog_playback_ops = {
82199 +static const struct snd_pcm_ops analog_playback_ops = {
82200 .open = pcm_analog_out_open,
82201 .close = pcm_close,
82202 .ioctl = snd_pcm_lib_ioctl,
82203 @@ -842,7 +842,7 @@ static struct snd_pcm_ops analog_playbac
82204 .pointer = pcm_pointer,
82205 .page = snd_pcm_sgbuf_ops_page,
82206 };
82207 -static struct snd_pcm_ops analog_capture_ops = {
82208 +static const struct snd_pcm_ops analog_capture_ops = {
82209 .open = pcm_analog_in_open,
82210 .close = pcm_close,
82211 .ioctl = snd_pcm_lib_ioctl,
82212 @@ -855,7 +855,7 @@ static struct snd_pcm_ops analog_capture
82213 };
82214 #ifdef ECHOCARD_HAS_DIGITAL_IO
82215 #ifndef ECHOCARD_HAS_VMIXER
82216 -static struct snd_pcm_ops digital_playback_ops = {
82217 +static const struct snd_pcm_ops digital_playback_ops = {
82218 .open = pcm_digital_out_open,
82219 .close = pcm_close,
82220 .ioctl = snd_pcm_lib_ioctl,
82221 @@ -867,7 +867,7 @@ static struct snd_pcm_ops digital_playba
82222 .page = snd_pcm_sgbuf_ops_page,
82223 };
82224 #endif /* !ECHOCARD_HAS_VMIXER */
82225 -static struct snd_pcm_ops digital_capture_ops = {
82226 +static const struct snd_pcm_ops digital_capture_ops = {
82227 .open = pcm_digital_in_open,
82228 .close = pcm_close,
82229 .ioctl = snd_pcm_lib_ioctl,
82230 @@ -1945,7 +1945,7 @@ static __devinit int snd_echo_create(str
82231 struct echoaudio *chip;
82232 int err;
82233 size_t sz;
82234 - static struct snd_device_ops ops = {
82235 + static const struct snd_device_ops ops = {
82236 .dev_free = snd_echo_dev_free,
82237 };
82238
82239 diff -urNp linux-2.6.39.2/sound/pci/echoaudio/midi.c linux-2.6.39.2/sound/pci/echoaudio/midi.c
82240 --- linux-2.6.39.2/sound/pci/echoaudio/midi.c 2011-05-19 00:06:34.000000000 -0400
82241 +++ linux-2.6.39.2/sound/pci/echoaudio/midi.c 2011-05-22 19:36:35.000000000 -0400
82242 @@ -292,13 +292,13 @@ static int snd_echo_midi_output_close(st
82243
82244
82245
82246 -static struct snd_rawmidi_ops snd_echo_midi_input = {
82247 +static const struct snd_rawmidi_ops snd_echo_midi_input = {
82248 .open = snd_echo_midi_input_open,
82249 .close = snd_echo_midi_input_close,
82250 .trigger = snd_echo_midi_input_trigger,
82251 };
82252
82253 -static struct snd_rawmidi_ops snd_echo_midi_output = {
82254 +static const struct snd_rawmidi_ops snd_echo_midi_output = {
82255 .open = snd_echo_midi_output_open,
82256 .close = snd_echo_midi_output_close,
82257 .trigger = snd_echo_midi_output_trigger,
82258 diff -urNp linux-2.6.39.2/sound/pci/emu10k1/emu10k1_main.c linux-2.6.39.2/sound/pci/emu10k1/emu10k1_main.c
82259 --- linux-2.6.39.2/sound/pci/emu10k1/emu10k1_main.c 2011-05-19 00:06:34.000000000 -0400
82260 +++ linux-2.6.39.2/sound/pci/emu10k1/emu10k1_main.c 2011-05-22 19:36:35.000000000 -0400
82261 @@ -1722,7 +1722,7 @@ int __devinit snd_emu10k1_create(struct
82262 int is_audigy;
82263 unsigned int silent_page;
82264 const struct snd_emu_chip_details *c;
82265 - static struct snd_device_ops ops = {
82266 + static const struct snd_device_ops ops = {
82267 .dev_free = snd_emu10k1_dev_free,
82268 };
82269
82270 diff -urNp linux-2.6.39.2/sound/pci/emu10k1/emu10k1x.c linux-2.6.39.2/sound/pci/emu10k1/emu10k1x.c
82271 --- linux-2.6.39.2/sound/pci/emu10k1/emu10k1x.c 2011-05-19 00:06:34.000000000 -0400
82272 +++ linux-2.6.39.2/sound/pci/emu10k1/emu10k1x.c 2011-05-22 19:36:35.000000000 -0400
82273 @@ -543,7 +543,7 @@ snd_emu10k1x_pcm_pointer(struct snd_pcm_
82274 }
82275
82276 /* operators */
82277 -static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
82278 +static const struct snd_pcm_ops snd_emu10k1x_playback_ops = {
82279 .open = snd_emu10k1x_playback_open,
82280 .close = snd_emu10k1x_playback_close,
82281 .ioctl = snd_pcm_lib_ioctl,
82282 @@ -689,7 +689,7 @@ snd_emu10k1x_pcm_pointer_capture(struct
82283 return ptr;
82284 }
82285
82286 -static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
82287 +static const struct snd_pcm_ops snd_emu10k1x_capture_ops = {
82288 .open = snd_emu10k1x_pcm_open_capture,
82289 .close = snd_emu10k1x_pcm_close_capture,
82290 .ioctl = snd_pcm_lib_ioctl,
82291 @@ -731,7 +731,7 @@ static int snd_emu10k1x_ac97(struct emu1
82292 struct snd_ac97_bus *pbus;
82293 struct snd_ac97_template ac97;
82294 int err;
82295 - static struct snd_ac97_bus_ops ops = {
82296 + static const struct snd_ac97_bus_ops ops = {
82297 .write = snd_emu10k1x_ac97_write,
82298 .read = snd_emu10k1x_ac97_read,
82299 };
82300 @@ -888,7 +888,7 @@ static int __devinit snd_emu10k1x_create
82301 struct emu10k1x *chip;
82302 int err;
82303 int ch;
82304 - static struct snd_device_ops ops = {
82305 + static const struct snd_device_ops ops = {
82306 .dev_free = snd_emu10k1x_dev_free,
82307 };
82308
82309 @@ -1465,15 +1465,13 @@ static void snd_emu10k1x_midi_output_tri
82310
82311 */
82312
82313 -static struct snd_rawmidi_ops snd_emu10k1x_midi_output =
82314 -{
82315 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_output = {
82316 .open = snd_emu10k1x_midi_output_open,
82317 .close = snd_emu10k1x_midi_output_close,
82318 .trigger = snd_emu10k1x_midi_output_trigger,
82319 };
82320
82321 -static struct snd_rawmidi_ops snd_emu10k1x_midi_input =
82322 -{
82323 +static const struct snd_rawmidi_ops snd_emu10k1x_midi_input = {
82324 .open = snd_emu10k1x_midi_input_open,
82325 .close = snd_emu10k1x_midi_input_close,
82326 .trigger = snd_emu10k1x_midi_input_trigger,
82327 diff -urNp linux-2.6.39.2/sound/pci/emu10k1/p16v.c linux-2.6.39.2/sound/pci/emu10k1/p16v.c
82328 --- linux-2.6.39.2/sound/pci/emu10k1/p16v.c 2011-05-19 00:06:34.000000000 -0400
82329 +++ linux-2.6.39.2/sound/pci/emu10k1/p16v.c 2011-05-22 19:36:35.000000000 -0400
82330 @@ -601,7 +601,7 @@ snd_p16v_pcm_pointer_capture(struct snd_
82331 }
82332
82333 /* operators */
82334 -static struct snd_pcm_ops snd_p16v_playback_front_ops = {
82335 +static const struct snd_pcm_ops snd_p16v_playback_front_ops = {
82336 .open = snd_p16v_pcm_open_playback_front,
82337 .close = snd_p16v_pcm_close_playback,
82338 .ioctl = snd_pcm_lib_ioctl,
82339 @@ -612,7 +612,7 @@ static struct snd_pcm_ops snd_p16v_playb
82340 .pointer = snd_p16v_pcm_pointer_playback,
82341 };
82342
82343 -static struct snd_pcm_ops snd_p16v_capture_ops = {
82344 +static const struct snd_pcm_ops snd_p16v_capture_ops = {
82345 .open = snd_p16v_pcm_open_capture,
82346 .close = snd_p16v_pcm_close_capture,
82347 .ioctl = snd_pcm_lib_ioctl,
82348 diff -urNp linux-2.6.39.2/sound/pci/ens1370.c linux-2.6.39.2/sound/pci/ens1370.c
82349 --- linux-2.6.39.2/sound/pci/ens1370.c 2011-05-19 00:06:34.000000000 -0400
82350 +++ linux-2.6.39.2/sound/pci/ens1370.c 2011-05-22 19:36:35.000000000 -0400
82351 @@ -1225,7 +1225,7 @@ static int snd_ensoniq_capture_close(str
82352 return 0;
82353 }
82354
82355 -static struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82356 +static const struct snd_pcm_ops snd_ensoniq_playback1_ops = {
82357 .open = snd_ensoniq_playback1_open,
82358 .close = snd_ensoniq_playback1_close,
82359 .ioctl = snd_pcm_lib_ioctl,
82360 @@ -1236,7 +1236,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82361 .pointer = snd_ensoniq_playback1_pointer,
82362 };
82363
82364 -static struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82365 +static const struct snd_pcm_ops snd_ensoniq_playback2_ops = {
82366 .open = snd_ensoniq_playback2_open,
82367 .close = snd_ensoniq_playback2_close,
82368 .ioctl = snd_pcm_lib_ioctl,
82369 @@ -1247,7 +1247,7 @@ static struct snd_pcm_ops snd_ensoniq_pl
82370 .pointer = snd_ensoniq_playback2_pointer,
82371 };
82372
82373 -static struct snd_pcm_ops snd_ensoniq_capture_ops = {
82374 +static const struct snd_pcm_ops snd_ensoniq_capture_ops = {
82375 .open = snd_ensoniq_capture_open,
82376 .close = snd_ensoniq_capture_close,
82377 .ioctl = snd_pcm_lib_ioctl,
82378 @@ -1633,7 +1633,7 @@ static int __devinit snd_ensoniq_1371_mi
82379 struct snd_ac97_bus *pbus;
82380 struct snd_ac97_template ac97;
82381 int err;
82382 - static struct snd_ac97_bus_ops ops = {
82383 + static const struct snd_ac97_bus_ops ops = {
82384 .write = snd_es1371_codec_write,
82385 .read = snd_es1371_codec_read,
82386 .wait = snd_es1371_codec_wait,
82387 @@ -2096,7 +2096,7 @@ static int __devinit snd_ensoniq_create(
82388 {
82389 struct ensoniq *ensoniq;
82390 int err;
82391 - static struct snd_device_ops ops = {
82392 + static const struct snd_device_ops ops = {
82393 .dev_free = snd_ensoniq_dev_free,
82394 };
82395
82396 @@ -2331,15 +2331,13 @@ static void snd_ensoniq_midi_output_trig
82397 spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
82398 }
82399
82400 -static struct snd_rawmidi_ops snd_ensoniq_midi_output =
82401 -{
82402 +static const struct snd_rawmidi_ops snd_ensoniq_midi_output = {
82403 .open = snd_ensoniq_midi_output_open,
82404 .close = snd_ensoniq_midi_output_close,
82405 .trigger = snd_ensoniq_midi_output_trigger,
82406 };
82407
82408 -static struct snd_rawmidi_ops snd_ensoniq_midi_input =
82409 -{
82410 +static const struct snd_rawmidi_ops snd_ensoniq_midi_input = {
82411 .open = snd_ensoniq_midi_input_open,
82412 .close = snd_ensoniq_midi_input_close,
82413 .trigger = snd_ensoniq_midi_input_trigger,
82414 diff -urNp linux-2.6.39.2/sound/pci/es1938.c linux-2.6.39.2/sound/pci/es1938.c
82415 --- linux-2.6.39.2/sound/pci/es1938.c 2011-05-19 00:06:34.000000000 -0400
82416 +++ linux-2.6.39.2/sound/pci/es1938.c 2011-05-22 19:36:35.000000000 -0400
82417 @@ -1004,7 +1004,7 @@ static int snd_es1938_playback_close(str
82418 return 0;
82419 }
82420
82421 -static struct snd_pcm_ops snd_es1938_playback_ops = {
82422 +static const struct snd_pcm_ops snd_es1938_playback_ops = {
82423 .open = snd_es1938_playback_open,
82424 .close = snd_es1938_playback_close,
82425 .ioctl = snd_pcm_lib_ioctl,
82426 @@ -1015,7 +1015,7 @@ static struct snd_pcm_ops snd_es1938_pla
82427 .pointer = snd_es1938_playback_pointer,
82428 };
82429
82430 -static struct snd_pcm_ops snd_es1938_capture_ops = {
82431 +static const struct snd_pcm_ops snd_es1938_capture_ops = {
82432 .open = snd_es1938_capture_open,
82433 .close = snd_es1938_capture_close,
82434 .ioctl = snd_pcm_lib_ioctl,
82435 @@ -1598,7 +1598,7 @@ static int __devinit snd_es1938_create(s
82436 {
82437 struct es1938 *chip;
82438 int err;
82439 - static struct snd_device_ops ops = {
82440 + static const struct snd_device_ops ops = {
82441 .dev_free = snd_es1938_dev_free,
82442 };
82443
82444 diff -urNp linux-2.6.39.2/sound/pci/es1968.c linux-2.6.39.2/sound/pci/es1968.c
82445 --- linux-2.6.39.2/sound/pci/es1968.c 2011-05-19 00:06:34.000000000 -0400
82446 +++ linux-2.6.39.2/sound/pci/es1968.c 2011-05-22 19:36:35.000000000 -0400
82447 @@ -1682,7 +1682,7 @@ static int snd_es1968_capture_close(stru
82448 return 0;
82449 }
82450
82451 -static struct snd_pcm_ops snd_es1968_playback_ops = {
82452 +static const struct snd_pcm_ops snd_es1968_playback_ops = {
82453 .open = snd_es1968_playback_open,
82454 .close = snd_es1968_playback_close,
82455 .ioctl = snd_pcm_lib_ioctl,
82456 @@ -1693,7 +1693,7 @@ static struct snd_pcm_ops snd_es1968_pla
82457 .pointer = snd_es1968_pcm_pointer,
82458 };
82459
82460 -static struct snd_pcm_ops snd_es1968_capture_ops = {
82461 +static const struct snd_pcm_ops snd_es1968_capture_ops = {
82462 .open = snd_es1968_capture_open,
82463 .close = snd_es1968_capture_close,
82464 .ioctl = snd_pcm_lib_ioctl,
82465 @@ -2053,7 +2053,7 @@ snd_es1968_mixer(struct es1968 *chip)
82466 struct snd_ctl_elem_id elem_id;
82467 #endif
82468 int err;
82469 - static struct snd_ac97_bus_ops ops = {
82470 + static const struct snd_ac97_bus_ops ops = {
82471 .write = snd_es1968_ac97_write,
82472 .read = snd_es1968_ac97_read,
82473 };
82474 @@ -2627,7 +2627,7 @@ static int __devinit snd_es1968_create(s
82475 int do_pm,
82476 struct es1968 **chip_ret)
82477 {
82478 - static struct snd_device_ops ops = {
82479 + static const struct snd_device_ops ops = {
82480 .dev_free = snd_es1968_dev_free,
82481 };
82482 struct es1968 *chip;
82483 diff -urNp linux-2.6.39.2/sound/pci/fm801.c linux-2.6.39.2/sound/pci/fm801.c
82484 --- linux-2.6.39.2/sound/pci/fm801.c 2011-05-19 00:06:34.000000000 -0400
82485 +++ linux-2.6.39.2/sound/pci/fm801.c 2011-05-22 19:36:35.000000000 -0400
82486 @@ -662,7 +662,7 @@ static int snd_fm801_capture_close(struc
82487 return 0;
82488 }
82489
82490 -static struct snd_pcm_ops snd_fm801_playback_ops = {
82491 +static const struct snd_pcm_ops snd_fm801_playback_ops = {
82492 .open = snd_fm801_playback_open,
82493 .close = snd_fm801_playback_close,
82494 .ioctl = snd_pcm_lib_ioctl,
82495 @@ -673,7 +673,7 @@ static struct snd_pcm_ops snd_fm801_play
82496 .pointer = snd_fm801_playback_pointer,
82497 };
82498
82499 -static struct snd_pcm_ops snd_fm801_capture_ops = {
82500 +static const struct snd_pcm_ops snd_fm801_capture_ops = {
82501 .open = snd_fm801_capture_open,
82502 .close = snd_fm801_capture_close,
82503 .ioctl = snd_pcm_lib_ioctl,
82504 @@ -1236,7 +1236,7 @@ static int __devinit snd_fm801_mixer(str
82505 struct snd_ac97_template ac97;
82506 unsigned int i;
82507 int err;
82508 - static struct snd_ac97_bus_ops ops = {
82509 + static const struct snd_ac97_bus_ops ops = {
82510 .write = snd_fm801_codec_write,
82511 .read = snd_fm801_codec_read,
82512 };
82513 @@ -1396,7 +1396,7 @@ static int __devinit snd_fm801_create(st
82514 {
82515 struct fm801 *chip;
82516 int err;
82517 - static struct snd_device_ops ops = {
82518 + static const struct snd_device_ops ops = {
82519 .dev_free = snd_fm801_dev_free,
82520 };
82521
82522 diff -urNp linux-2.6.39.2/sound/pci/hda/hda_generic.c linux-2.6.39.2/sound/pci/hda/hda_generic.c
82523 --- linux-2.6.39.2/sound/pci/hda/hda_generic.c 2011-05-19 00:06:34.000000000 -0400
82524 +++ linux-2.6.39.2/sound/pci/hda/hda_generic.c 2011-05-22 19:36:35.000000000 -0400
82525 @@ -1038,7 +1038,7 @@ static int generic_check_power_status(st
82526
82527 /*
82528 */
82529 -static struct hda_codec_ops generic_patch_ops = {
82530 +static const struct hda_codec_ops generic_patch_ops = {
82531 .build_controls = build_generic_controls,
82532 .build_pcms = build_generic_pcms,
82533 .free = snd_hda_generic_free,
82534 diff -urNp linux-2.6.39.2/sound/pci/hda/hda_intel.c linux-2.6.39.2/sound/pci/hda/hda_intel.c
82535 --- linux-2.6.39.2/sound/pci/hda/hda_intel.c 2011-06-03 00:04:14.000000000 -0400
82536 +++ linux-2.6.39.2/sound/pci/hda/hda_intel.c 2011-06-03 00:32:08.000000000 -0400
82537 @@ -2459,7 +2459,7 @@ static int __devinit azx_create(struct s
82538 struct azx *chip;
82539 int i, err;
82540 unsigned short gcap;
82541 - static struct snd_device_ops ops = {
82542 + static const struct snd_device_ops ops = {
82543 .dev_free = azx_dev_free,
82544 };
82545
82546 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_ca0110.c linux-2.6.39.2/sound/pci/hda/patch_ca0110.c
82547 --- linux-2.6.39.2/sound/pci/hda/patch_ca0110.c 2011-05-19 00:06:34.000000000 -0400
82548 +++ linux-2.6.39.2/sound/pci/hda/patch_ca0110.c 2011-05-22 19:36:35.000000000 -0400
82549 @@ -389,7 +389,7 @@ static void ca0110_free(struct hda_codec
82550 kfree(codec->spec);
82551 }
82552
82553 -static struct hda_codec_ops ca0110_patch_ops = {
82554 +static const struct hda_codec_ops ca0110_patch_ops = {
82555 .build_controls = ca0110_build_controls,
82556 .build_pcms = ca0110_build_pcms,
82557 .init = ca0110_init,
82558 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_cirrus.c linux-2.6.39.2/sound/pci/hda/patch_cirrus.c
82559 --- linux-2.6.39.2/sound/pci/hda/patch_cirrus.c 2011-05-19 00:06:34.000000000 -0400
82560 +++ linux-2.6.39.2/sound/pci/hda/patch_cirrus.c 2011-05-22 19:36:35.000000000 -0400
82561 @@ -1126,7 +1126,7 @@ static void cs_unsol_event(struct hda_co
82562 }
82563 }
82564
82565 -static struct hda_codec_ops cs_patch_ops = {
82566 +static const struct hda_codec_ops cs_patch_ops = {
82567 .build_controls = cs_build_controls,
82568 .build_pcms = cs_build_pcms,
82569 .init = cs_init,
82570 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_cmedia.c linux-2.6.39.2/sound/pci/hda/patch_cmedia.c
82571 --- linux-2.6.39.2/sound/pci/hda/patch_cmedia.c 2011-05-19 00:06:34.000000000 -0400
82572 +++ linux-2.6.39.2/sound/pci/hda/patch_cmedia.c 2011-05-22 19:36:35.000000000 -0400
82573 @@ -624,7 +624,7 @@ static struct snd_pci_quirk cmi9880_cfg_
82574 {} /* terminator */
82575 };
82576
82577 -static struct hda_codec_ops cmi9880_patch_ops = {
82578 +static const struct hda_codec_ops cmi9880_patch_ops = {
82579 .build_controls = cmi9880_build_controls,
82580 .build_pcms = cmi9880_build_pcms,
82581 .init = cmi9880_init,
82582 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_conexant.c linux-2.6.39.2/sound/pci/hda/patch_conexant.c
82583 --- linux-2.6.39.2/sound/pci/hda/patch_conexant.c 2011-06-03 00:04:14.000000000 -0400
82584 +++ linux-2.6.39.2/sound/pci/hda/patch_conexant.c 2011-06-03 00:32:08.000000000 -0400
82585 @@ -546,7 +546,7 @@ static int conexant_suspend(struct hda_c
82586 }
82587 #endif
82588
82589 -static struct hda_codec_ops conexant_patch_ops = {
82590 +static const struct hda_codec_ops conexant_patch_ops = {
82591 .build_controls = conexant_build_controls,
82592 .build_pcms = conexant_build_pcms,
82593 .init = conexant_init,
82594 @@ -3792,7 +3792,7 @@ static int cx_auto_build_controls(struct
82595 return conexant_build_controls(codec);
82596 }
82597
82598 -static struct hda_codec_ops cx_auto_patch_ops = {
82599 +static const struct hda_codec_ops cx_auto_patch_ops = {
82600 .build_controls = cx_auto_build_controls,
82601 .build_pcms = conexant_build_pcms,
82602 .init = cx_auto_init,
82603 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_hdmi.c linux-2.6.39.2/sound/pci/hda/patch_hdmi.c
82604 --- linux-2.6.39.2/sound/pci/hda/patch_hdmi.c 2011-05-19 00:06:34.000000000 -0400
82605 +++ linux-2.6.39.2/sound/pci/hda/patch_hdmi.c 2011-05-22 19:36:35.000000000 -0400
82606 @@ -1124,7 +1124,7 @@ static void generic_hdmi_free(struct hda
82607 kfree(spec);
82608 }
82609
82610 -static struct hda_codec_ops generic_hdmi_patch_ops = {
82611 +static const struct hda_codec_ops generic_hdmi_patch_ops = {
82612 .init = generic_hdmi_init,
82613 .free = generic_hdmi_free,
82614 .build_pcms = generic_hdmi_build_pcms,
82615 @@ -1465,14 +1465,14 @@ static struct hda_pcm_stream nvhdmi_pcm_
82616 },
82617 };
82618
82619 -static struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82620 +static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
82621 .build_controls = generic_hdmi_build_controls,
82622 .build_pcms = generic_hdmi_build_pcms,
82623 .init = nvhdmi_7x_init,
82624 .free = generic_hdmi_free,
82625 };
82626
82627 -static struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82628 +static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
82629 .build_controls = generic_hdmi_build_controls,
82630 .build_pcms = generic_hdmi_build_pcms,
82631 .init = nvhdmi_7x_init,
82632 @@ -1599,7 +1599,7 @@ static int atihdmi_init(struct hda_codec
82633 return 0;
82634 }
82635
82636 -static struct hda_codec_ops atihdmi_patch_ops = {
82637 +static const struct hda_codec_ops atihdmi_patch_ops = {
82638 .build_controls = generic_hdmi_build_controls,
82639 .build_pcms = generic_hdmi_build_pcms,
82640 .init = atihdmi_init,
82641 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_realtek.c linux-2.6.39.2/sound/pci/hda/patch_realtek.c
82642 --- linux-2.6.39.2/sound/pci/hda/patch_realtek.c 2011-06-25 12:55:23.000000000 -0400
82643 +++ linux-2.6.39.2/sound/pci/hda/patch_realtek.c 2011-06-25 13:00:30.000000000 -0400
82644 @@ -4273,7 +4273,7 @@ static int alc_resume(struct hda_codec *
82645
82646 /*
82647 */
82648 -static struct hda_codec_ops alc_patch_ops = {
82649 +static const struct hda_codec_ops alc_patch_ops = {
82650 .build_controls = alc_build_controls,
82651 .build_pcms = alc_build_pcms,
82652 .init = alc_init,
82653 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_si3054.c linux-2.6.39.2/sound/pci/hda/patch_si3054.c
82654 --- linux-2.6.39.2/sound/pci/hda/patch_si3054.c 2011-05-19 00:06:34.000000000 -0400
82655 +++ linux-2.6.39.2/sound/pci/hda/patch_si3054.c 2011-05-22 19:36:35.000000000 -0400
82656 @@ -263,7 +263,7 @@ static void si3054_free(struct hda_codec
82657 /*
82658 */
82659
82660 -static struct hda_codec_ops si3054_patch_ops = {
82661 +static const struct hda_codec_ops si3054_patch_ops = {
82662 .build_controls = si3054_build_controls,
82663 .build_pcms = si3054_build_pcms,
82664 .init = si3054_init,
82665 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_sigmatel.c linux-2.6.39.2/sound/pci/hda/patch_sigmatel.c
82666 --- linux-2.6.39.2/sound/pci/hda/patch_sigmatel.c 2011-06-03 00:04:14.000000000 -0400
82667 +++ linux-2.6.39.2/sound/pci/hda/patch_sigmatel.c 2011-06-03 00:32:08.000000000 -0400
82668 @@ -4968,7 +4968,7 @@ static int stac92xx_suspend(struct hda_c
82669 }
82670 #endif
82671
82672 -static struct hda_codec_ops stac92xx_patch_ops = {
82673 +static const struct hda_codec_ops stac92xx_patch_ops = {
82674 .build_controls = stac92xx_build_controls,
82675 .build_pcms = stac92xx_build_pcms,
82676 .init = stac92xx_init,
82677 diff -urNp linux-2.6.39.2/sound/pci/hda/patch_via.c linux-2.6.39.2/sound/pci/hda/patch_via.c
82678 --- linux-2.6.39.2/sound/pci/hda/patch_via.c 2011-05-19 00:06:34.000000000 -0400
82679 +++ linux-2.6.39.2/sound/pci/hda/patch_via.c 2011-05-22 19:36:35.000000000 -0400
82680 @@ -2254,7 +2254,7 @@ static int via_check_power_status(struct
82681
82682 /*
82683 */
82684 -static struct hda_codec_ops via_patch_ops = {
82685 +static const struct hda_codec_ops via_patch_ops = {
82686 .build_controls = via_build_controls,
82687 .build_pcms = via_build_pcms,
82688 .init = via_init,
82689 diff -urNp linux-2.6.39.2/sound/pci/ice1712/ice1712.c linux-2.6.39.2/sound/pci/ice1712/ice1712.c
82690 --- linux-2.6.39.2/sound/pci/ice1712/ice1712.c 2011-05-19 00:06:34.000000000 -0400
82691 +++ linux-2.6.39.2/sound/pci/ice1712/ice1712.c 2011-05-22 19:36:35.000000000 -0400
82692 @@ -2541,7 +2541,7 @@ static int __devinit snd_ice1712_create(
82693 {
82694 struct snd_ice1712 *ice;
82695 int err;
82696 - static struct snd_device_ops ops = {
82697 + static const struct snd_device_ops ops = {
82698 .dev_free = snd_ice1712_dev_free,
82699 };
82700
82701 diff -urNp linux-2.6.39.2/sound/pci/ice1712/ice1724.c linux-2.6.39.2/sound/pci/ice1712/ice1724.c
82702 --- linux-2.6.39.2/sound/pci/ice1712/ice1724.c 2011-05-19 00:06:34.000000000 -0400
82703 +++ linux-2.6.39.2/sound/pci/ice1712/ice1724.c 2011-05-22 19:36:35.000000000 -0400
82704 @@ -367,7 +367,7 @@ static void vt1724_midi_output_drain(str
82705 } while (time_after(timeout, jiffies));
82706 }
82707
82708 -static struct snd_rawmidi_ops vt1724_midi_output_ops = {
82709 +static const struct snd_rawmidi_ops vt1724_midi_output_ops = {
82710 .open = vt1724_midi_output_open,
82711 .close = vt1724_midi_output_close,
82712 .trigger = vt1724_midi_output_trigger,
82713 @@ -402,7 +402,7 @@ static void vt1724_midi_input_trigger(st
82714 spin_unlock_irqrestore(&ice->reg_lock, flags);
82715 }
82716
82717 -static struct snd_rawmidi_ops vt1724_midi_input_ops = {
82718 +static const struct snd_rawmidi_ops vt1724_midi_input_ops = {
82719 .open = vt1724_midi_input_open,
82720 .close = vt1724_midi_input_close,
82721 .trigger = vt1724_midi_input_trigger,
82722 @@ -2463,7 +2463,7 @@ static int __devinit snd_vt1724_create(s
82723 {
82724 struct snd_ice1712 *ice;
82725 int err;
82726 - static struct snd_device_ops ops = {
82727 + static const struct snd_device_ops ops = {
82728 .dev_free = snd_vt1724_dev_free,
82729 };
82730
82731 diff -urNp linux-2.6.39.2/sound/pci/intel8x0.c linux-2.6.39.2/sound/pci/intel8x0.c
82732 --- linux-2.6.39.2/sound/pci/intel8x0.c 2011-05-19 00:06:34.000000000 -0400
82733 +++ linux-2.6.39.2/sound/pci/intel8x0.c 2011-05-22 19:36:35.000000000 -0400
82734 @@ -2152,12 +2152,12 @@ static int __devinit snd_intel8x0_mixer(
82735 int err;
82736 unsigned int i, codecs;
82737 unsigned int glob_sta = 0;
82738 - struct snd_ac97_bus_ops *ops;
82739 - static struct snd_ac97_bus_ops standard_bus_ops = {
82740 + const struct snd_ac97_bus_ops *ops;
82741 + static const struct snd_ac97_bus_ops standard_bus_ops = {
82742 .write = snd_intel8x0_codec_write,
82743 .read = snd_intel8x0_codec_read,
82744 };
82745 - static struct snd_ac97_bus_ops ali_bus_ops = {
82746 + static const struct snd_ac97_bus_ops ali_bus_ops = {
82747 .write = snd_intel8x0_ali_codec_write,
82748 .read = snd_intel8x0_ali_codec_read,
82749 };
82750 @@ -2921,7 +2921,7 @@ static int __devinit snd_intel8x0_create
82751 unsigned int i;
82752 unsigned int int_sta_masks;
82753 struct ichdev *ichdev;
82754 - static struct snd_device_ops ops = {
82755 + static const struct snd_device_ops ops = {
82756 .dev_free = snd_intel8x0_dev_free,
82757 };
82758
82759 diff -urNp linux-2.6.39.2/sound/pci/intel8x0m.c linux-2.6.39.2/sound/pci/intel8x0m.c
82760 --- linux-2.6.39.2/sound/pci/intel8x0m.c 2011-05-19 00:06:34.000000000 -0400
82761 +++ linux-2.6.39.2/sound/pci/intel8x0m.c 2011-05-22 19:36:35.000000000 -0400
82762 @@ -826,7 +826,7 @@ static int __devinit snd_intel8x0m_mixer
82763 struct snd_ac97 *x97;
82764 int err;
82765 unsigned int glob_sta = 0;
82766 - static struct snd_ac97_bus_ops ops = {
82767 + static const struct snd_ac97_bus_ops ops = {
82768 .write = snd_intel8x0m_codec_write,
82769 .read = snd_intel8x0m_codec_read,
82770 };
82771 @@ -1116,7 +1116,7 @@ static int __devinit snd_intel8x0m_creat
82772 unsigned int i;
82773 unsigned int int_sta_masks;
82774 struct ichdev *ichdev;
82775 - static struct snd_device_ops ops = {
82776 + static const struct snd_device_ops ops = {
82777 .dev_free = snd_intel8x0m_dev_free,
82778 };
82779 static struct ich_reg_info intel_regs[2] = {
82780 @@ -1265,7 +1265,7 @@ static struct shortname_table {
82781 { 0x5455, "ALi M5455" },
82782 { 0x746d, "AMD AMD8111" },
82783 #endif
82784 - { 0 },
82785 + { 0, },
82786 };
82787
82788 static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
82789 diff -urNp linux-2.6.39.2/sound/pci/korg1212/korg1212.c linux-2.6.39.2/sound/pci/korg1212/korg1212.c
82790 --- linux-2.6.39.2/sound/pci/korg1212/korg1212.c 2011-05-19 00:06:34.000000000 -0400
82791 +++ linux-2.6.39.2/sound/pci/korg1212/korg1212.c 2011-05-22 19:36:35.000000000 -0400
82792 @@ -1682,7 +1682,7 @@ static int snd_korg1212_capture_copy(str
82793 return snd_korg1212_copy_to(korg1212, dst, pos, count, 0, korg1212->channels * 2);
82794 }
82795
82796 -static struct snd_pcm_ops snd_korg1212_playback_ops = {
82797 +static const struct snd_pcm_ops snd_korg1212_playback_ops = {
82798 .open = snd_korg1212_playback_open,
82799 .close = snd_korg1212_playback_close,
82800 .ioctl = snd_korg1212_ioctl,
82801 @@ -1694,7 +1694,7 @@ static struct snd_pcm_ops snd_korg1212_p
82802 .silence = snd_korg1212_playback_silence,
82803 };
82804
82805 -static struct snd_pcm_ops snd_korg1212_capture_ops = {
82806 +static const struct snd_pcm_ops snd_korg1212_capture_ops = {
82807 .open = snd_korg1212_capture_open,
82808 .close = snd_korg1212_capture_close,
82809 .ioctl = snd_korg1212_ioctl,
82810 @@ -2164,7 +2164,7 @@ static int __devinit snd_korg1212_create
82811 struct snd_korg1212 * korg1212;
82812 const struct firmware *dsp_code;
82813
82814 - static struct snd_device_ops ops = {
82815 + static const struct snd_device_ops ops = {
82816 .dev_free = snd_korg1212_dev_free,
82817 };
82818
82819 diff -urNp linux-2.6.39.2/sound/pci/maestro3.c linux-2.6.39.2/sound/pci/maestro3.c
82820 --- linux-2.6.39.2/sound/pci/maestro3.c 2011-05-19 00:06:34.000000000 -0400
82821 +++ linux-2.6.39.2/sound/pci/maestro3.c 2011-05-22 19:36:35.000000000 -0400
82822 @@ -1926,7 +1926,7 @@ snd_m3_capture_close(struct snd_pcm_subs
82823 * create pcm instance
82824 */
82825
82826 -static struct snd_pcm_ops snd_m3_playback_ops = {
82827 +static const struct snd_pcm_ops snd_m3_playback_ops = {
82828 .open = snd_m3_playback_open,
82829 .close = snd_m3_playback_close,
82830 .ioctl = snd_pcm_lib_ioctl,
82831 @@ -1937,7 +1937,7 @@ static struct snd_pcm_ops snd_m3_playbac
82832 .pointer = snd_m3_pcm_pointer,
82833 };
82834
82835 -static struct snd_pcm_ops snd_m3_capture_ops = {
82836 +static const struct snd_pcm_ops snd_m3_capture_ops = {
82837 .open = snd_m3_capture_open,
82838 .close = snd_m3_capture_close,
82839 .ioctl = snd_pcm_lib_ioctl,
82840 @@ -2150,7 +2150,7 @@ static int __devinit snd_m3_mixer(struct
82841 struct snd_ctl_elem_id elem_id;
82842 #endif
82843 int err;
82844 - static struct snd_ac97_bus_ops ops = {
82845 + static const struct snd_ac97_bus_ops ops = {
82846 .write = snd_m3_ac97_write,
82847 .read = snd_m3_ac97_read,
82848 };
82849 @@ -2643,7 +2643,7 @@ snd_m3_create(struct snd_card *card, str
82850 struct snd_m3 *chip;
82851 int i, err;
82852 const struct snd_pci_quirk *quirk;
82853 - static struct snd_device_ops ops = {
82854 + static const struct snd_device_ops ops = {
82855 .dev_free = snd_m3_dev_free,
82856 };
82857
82858 diff -urNp linux-2.6.39.2/sound/pci/mixart/mixart.c linux-2.6.39.2/sound/pci/mixart/mixart.c
82859 --- linux-2.6.39.2/sound/pci/mixart/mixart.c 2011-05-19 00:06:34.000000000 -0400
82860 +++ linux-2.6.39.2/sound/pci/mixart/mixart.c 2011-05-22 19:36:35.000000000 -0400
82861 @@ -887,7 +887,7 @@ static snd_pcm_uframes_t snd_mixart_stre
82862
82863
82864
82865 -static struct snd_pcm_ops snd_mixart_playback_ops = {
82866 +static const struct snd_pcm_ops snd_mixart_playback_ops = {
82867 .open = snd_mixart_playback_open,
82868 .close = snd_mixart_close,
82869 .ioctl = snd_pcm_lib_ioctl,
82870 @@ -898,7 +898,7 @@ static struct snd_pcm_ops snd_mixart_pla
82871 .pointer = snd_mixart_stream_pointer,
82872 };
82873
82874 -static struct snd_pcm_ops snd_mixart_capture_ops = {
82875 +static const struct snd_pcm_ops snd_mixart_capture_ops = {
82876 .open = snd_mixart_capture_open,
82877 .close = snd_mixart_close,
82878 .ioctl = snd_pcm_lib_ioctl,
82879 @@ -1008,7 +1008,7 @@ static int __devinit snd_mixart_create(s
82880 {
82881 int err;
82882 struct snd_mixart *chip;
82883 - static struct snd_device_ops ops = {
82884 + static const struct snd_device_ops ops = {
82885 .dev_free = snd_mixart_chip_dev_free,
82886 };
82887
82888 diff -urNp linux-2.6.39.2/sound/pci/nm256/nm256.c linux-2.6.39.2/sound/pci/nm256/nm256.c
82889 --- linux-2.6.39.2/sound/pci/nm256/nm256.c 2011-05-19 00:06:34.000000000 -0400
82890 +++ linux-2.6.39.2/sound/pci/nm256/nm256.c 2011-05-22 19:36:35.000000000 -0400
82891 @@ -899,7 +899,7 @@ snd_nm256_capture_close(struct snd_pcm_s
82892 /*
82893 * create a pcm instance
82894 */
82895 -static struct snd_pcm_ops snd_nm256_playback_ops = {
82896 +static const struct snd_pcm_ops snd_nm256_playback_ops = {
82897 .open = snd_nm256_playback_open,
82898 .close = snd_nm256_playback_close,
82899 .ioctl = snd_pcm_lib_ioctl,
82900 @@ -914,7 +914,7 @@ static struct snd_pcm_ops snd_nm256_play
82901 .mmap = snd_pcm_lib_mmap_iomem,
82902 };
82903
82904 -static struct snd_pcm_ops snd_nm256_capture_ops = {
82905 +static const struct snd_pcm_ops snd_nm256_capture_ops = {
82906 .open = snd_nm256_capture_open,
82907 .close = snd_nm256_capture_close,
82908 .ioctl = snd_pcm_lib_ioctl,
82909 @@ -1301,7 +1301,7 @@ snd_nm256_mixer(struct nm256 *chip)
82910 struct snd_ac97_bus *pbus;
82911 struct snd_ac97_template ac97;
82912 int err;
82913 - static struct snd_ac97_bus_ops ops = {
82914 + static const struct snd_ac97_bus_ops ops = {
82915 .reset = snd_nm256_ac97_reset,
82916 .write = snd_nm256_ac97_write,
82917 .read = snd_nm256_ac97_read,
82918 @@ -1471,7 +1471,7 @@ snd_nm256_create(struct snd_card *card,
82919 {
82920 struct nm256 *chip;
82921 int err, pval;
82922 - static struct snd_device_ops ops = {
82923 + static const struct snd_device_ops ops = {
82924 .dev_free = snd_nm256_dev_free,
82925 };
82926 u32 addr;
82927 diff -urNp linux-2.6.39.2/sound/pci/oxygen/oxygen_pcm.c linux-2.6.39.2/sound/pci/oxygen/oxygen_pcm.c
82928 --- linux-2.6.39.2/sound/pci/oxygen/oxygen_pcm.c 2011-05-19 00:06:34.000000000 -0400
82929 +++ linux-2.6.39.2/sound/pci/oxygen/oxygen_pcm.c 2011-05-22 19:36:35.000000000 -0400
82930 @@ -606,7 +606,7 @@ static snd_pcm_uframes_t oxygen_pointer(
82931 return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr);
82932 }
82933
82934 -static struct snd_pcm_ops oxygen_rec_a_ops = {
82935 +static const struct snd_pcm_ops oxygen_rec_a_ops = {
82936 .open = oxygen_rec_a_open,
82937 .close = oxygen_close,
82938 .ioctl = snd_pcm_lib_ioctl,
82939 @@ -617,7 +617,7 @@ static struct snd_pcm_ops oxygen_rec_a_o
82940 .pointer = oxygen_pointer,
82941 };
82942
82943 -static struct snd_pcm_ops oxygen_rec_b_ops = {
82944 +static const struct snd_pcm_ops oxygen_rec_b_ops = {
82945 .open = oxygen_rec_b_open,
82946 .close = oxygen_close,
82947 .ioctl = snd_pcm_lib_ioctl,
82948 @@ -628,7 +628,7 @@ static struct snd_pcm_ops oxygen_rec_b_o
82949 .pointer = oxygen_pointer,
82950 };
82951
82952 -static struct snd_pcm_ops oxygen_rec_c_ops = {
82953 +static const struct snd_pcm_ops oxygen_rec_c_ops = {
82954 .open = oxygen_rec_c_open,
82955 .close = oxygen_close,
82956 .ioctl = snd_pcm_lib_ioctl,
82957 @@ -639,7 +639,7 @@ static struct snd_pcm_ops oxygen_rec_c_o
82958 .pointer = oxygen_pointer,
82959 };
82960
82961 -static struct snd_pcm_ops oxygen_spdif_ops = {
82962 +static const struct snd_pcm_ops oxygen_spdif_ops = {
82963 .open = oxygen_spdif_open,
82964 .close = oxygen_close,
82965 .ioctl = snd_pcm_lib_ioctl,
82966 @@ -650,7 +650,7 @@ static struct snd_pcm_ops oxygen_spdif_o
82967 .pointer = oxygen_pointer,
82968 };
82969
82970 -static struct snd_pcm_ops oxygen_multich_ops = {
82971 +static const struct snd_pcm_ops oxygen_multich_ops = {
82972 .open = oxygen_multich_open,
82973 .close = oxygen_close,
82974 .ioctl = snd_pcm_lib_ioctl,
82975 @@ -661,7 +661,7 @@ static struct snd_pcm_ops oxygen_multich
82976 .pointer = oxygen_pointer,
82977 };
82978
82979 -static struct snd_pcm_ops oxygen_ac97_ops = {
82980 +static const struct snd_pcm_ops oxygen_ac97_ops = {
82981 .open = oxygen_ac97_open,
82982 .close = oxygen_close,
82983 .ioctl = snd_pcm_lib_ioctl,
82984 diff -urNp linux-2.6.39.2/sound/pci/pcxhr/pcxhr.c linux-2.6.39.2/sound/pci/pcxhr/pcxhr.c
82985 --- linux-2.6.39.2/sound/pci/pcxhr/pcxhr.c 2011-05-19 00:06:34.000000000 -0400
82986 +++ linux-2.6.39.2/sound/pci/pcxhr/pcxhr.c 2011-05-22 19:36:35.000000000 -0400
82987 @@ -1121,7 +1121,7 @@ static snd_pcm_uframes_t pcxhr_stream_po
82988 }
82989
82990
82991 -static struct snd_pcm_ops pcxhr_ops = {
82992 +static const struct snd_pcm_ops pcxhr_ops = {
82993 .open = pcxhr_open,
82994 .close = pcxhr_close,
82995 .ioctl = snd_pcm_lib_ioctl,
82996 @@ -1184,7 +1184,7 @@ static int __devinit pcxhr_create(struct
82997 {
82998 int err;
82999 struct snd_pcxhr *chip;
83000 - static struct snd_device_ops ops = {
83001 + static const struct snd_device_ops ops = {
83002 .dev_free = pcxhr_chip_dev_free,
83003 };
83004
83005 diff -urNp linux-2.6.39.2/sound/pci/riptide/riptide.c linux-2.6.39.2/sound/pci/riptide/riptide.c
83006 --- linux-2.6.39.2/sound/pci/riptide/riptide.c 2011-05-19 00:06:34.000000000 -0400
83007 +++ linux-2.6.39.2/sound/pci/riptide/riptide.c 2011-05-22 19:36:35.000000000 -0400
83008 @@ -1675,7 +1675,7 @@ static int snd_riptide_capture_close(str
83009 return 0;
83010 }
83011
83012 -static struct snd_pcm_ops snd_riptide_playback_ops = {
83013 +static const struct snd_pcm_ops snd_riptide_playback_ops = {
83014 .open = snd_riptide_playback_open,
83015 .close = snd_riptide_playback_close,
83016 .ioctl = snd_pcm_lib_ioctl,
83017 @@ -1686,7 +1686,7 @@ static struct snd_pcm_ops snd_riptide_pl
83018 .trigger = snd_riptide_trigger,
83019 .pointer = snd_riptide_pointer,
83020 };
83021 -static struct snd_pcm_ops snd_riptide_capture_ops = {
83022 +static const struct snd_pcm_ops snd_riptide_capture_ops = {
83023 .open = snd_riptide_capture_open,
83024 .close = snd_riptide_capture_close,
83025 .ioctl = snd_pcm_lib_ioctl,
83026 @@ -1857,7 +1857,7 @@ snd_riptide_create(struct snd_card *card
83027 struct snd_riptide *chip;
83028 struct riptideport *hwport;
83029 int err;
83030 - static struct snd_device_ops ops = {
83031 + static const struct snd_device_ops ops = {
83032 .dev_free = snd_riptide_dev_free,
83033 };
83034
83035 @@ -1999,7 +1999,7 @@ static int __devinit snd_riptide_mixer(s
83036 struct snd_ac97_bus *pbus;
83037 struct snd_ac97_template ac97;
83038 int err = 0;
83039 - static struct snd_ac97_bus_ops ops = {
83040 + static const struct snd_ac97_bus_ops ops = {
83041 .write = snd_riptide_codec_write,
83042 .read = snd_riptide_codec_read,
83043 };
83044 diff -urNp linux-2.6.39.2/sound/pci/rme32.c linux-2.6.39.2/sound/pci/rme32.c
83045 --- linux-2.6.39.2/sound/pci/rme32.c 2011-05-19 00:06:34.000000000 -0400
83046 +++ linux-2.6.39.2/sound/pci/rme32.c 2011-05-22 19:36:35.000000000 -0400
83047 @@ -1197,7 +1197,7 @@ snd_rme32_capture_fd_pointer(struct snd_
83048 }
83049
83050 /* for halfduplex mode */
83051 -static struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
83052 +static const struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
83053 .open = snd_rme32_playback_spdif_open,
83054 .close = snd_rme32_playback_close,
83055 .ioctl = snd_pcm_lib_ioctl,
83056 @@ -1211,7 +1211,7 @@ static struct snd_pcm_ops snd_rme32_play
83057 .mmap = snd_pcm_lib_mmap_iomem,
83058 };
83059
83060 -static struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
83061 +static const struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
83062 .open = snd_rme32_capture_spdif_open,
83063 .close = snd_rme32_capture_close,
83064 .ioctl = snd_pcm_lib_ioctl,
83065 @@ -1224,7 +1224,7 @@ static struct snd_pcm_ops snd_rme32_capt
83066 .mmap = snd_pcm_lib_mmap_iomem,
83067 };
83068
83069 -static struct snd_pcm_ops snd_rme32_playback_adat_ops = {
83070 +static const struct snd_pcm_ops snd_rme32_playback_adat_ops = {
83071 .open = snd_rme32_playback_adat_open,
83072 .close = snd_rme32_playback_close,
83073 .ioctl = snd_pcm_lib_ioctl,
83074 @@ -1237,7 +1237,7 @@ static struct snd_pcm_ops snd_rme32_play
83075 .mmap = snd_pcm_lib_mmap_iomem,
83076 };
83077
83078 -static struct snd_pcm_ops snd_rme32_capture_adat_ops = {
83079 +static const struct snd_pcm_ops snd_rme32_capture_adat_ops = {
83080 .open = snd_rme32_capture_adat_open,
83081 .close = snd_rme32_capture_close,
83082 .ioctl = snd_pcm_lib_ioctl,
83083 @@ -1250,7 +1250,7 @@ static struct snd_pcm_ops snd_rme32_capt
83084 };
83085
83086 /* for fullduplex mode */
83087 -static struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
83088 +static const struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
83089 .open = snd_rme32_playback_spdif_open,
83090 .close = snd_rme32_playback_close,
83091 .ioctl = snd_pcm_lib_ioctl,
83092 @@ -1262,7 +1262,7 @@ static struct snd_pcm_ops snd_rme32_play
83093 .ack = snd_rme32_playback_fd_ack,
83094 };
83095
83096 -static struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
83097 +static const struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
83098 .open = snd_rme32_capture_spdif_open,
83099 .close = snd_rme32_capture_close,
83100 .ioctl = snd_pcm_lib_ioctl,
83101 @@ -1274,7 +1274,7 @@ static struct snd_pcm_ops snd_rme32_capt
83102 .ack = snd_rme32_capture_fd_ack,
83103 };
83104
83105 -static struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
83106 +static const struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
83107 .open = snd_rme32_playback_adat_open,
83108 .close = snd_rme32_playback_close,
83109 .ioctl = snd_pcm_lib_ioctl,
83110 @@ -1285,7 +1285,7 @@ static struct snd_pcm_ops snd_rme32_play
83111 .ack = snd_rme32_playback_fd_ack,
83112 };
83113
83114 -static struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
83115 +static const struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
83116 .open = snd_rme32_capture_adat_open,
83117 .close = snd_rme32_capture_close,
83118 .ioctl = snd_pcm_lib_ioctl,
83119 diff -urNp linux-2.6.39.2/sound/pci/rme9652/hdsp.c linux-2.6.39.2/sound/pci/rme9652/hdsp.c
83120 --- linux-2.6.39.2/sound/pci/rme9652/hdsp.c 2011-05-19 00:06:34.000000000 -0400
83121 +++ linux-2.6.39.2/sound/pci/rme9652/hdsp.c 2011-05-22 19:36:35.000000000 -0400
83122 @@ -1469,15 +1469,13 @@ static int snd_hdsp_midi_output_close(st
83123 return 0;
83124 }
83125
83126 -static struct snd_rawmidi_ops snd_hdsp_midi_output =
83127 -{
83128 +static const struct snd_rawmidi_ops snd_hdsp_midi_output = {
83129 .open = snd_hdsp_midi_output_open,
83130 .close = snd_hdsp_midi_output_close,
83131 .trigger = snd_hdsp_midi_output_trigger,
83132 };
83133
83134 -static struct snd_rawmidi_ops snd_hdsp_midi_input =
83135 -{
83136 +static const struct snd_rawmidi_ops snd_hdsp_midi_input = {
83137 .open = snd_hdsp_midi_input_open,
83138 .close = snd_hdsp_midi_input_close,
83139 .trigger = snd_hdsp_midi_input_trigger,
83140 @@ -5135,7 +5133,7 @@ static int snd_hdsp_hwdep_ioctl(struct s
83141 return 0;
83142 }
83143
83144 -static struct snd_pcm_ops snd_hdsp_playback_ops = {
83145 +static const struct snd_pcm_ops snd_hdsp_playback_ops = {
83146 .open = snd_hdsp_playback_open,
83147 .close = snd_hdsp_playback_release,
83148 .ioctl = snd_hdsp_ioctl,
83149 @@ -5147,7 +5145,7 @@ static struct snd_pcm_ops snd_hdsp_playb
83150 .silence = snd_hdsp_hw_silence,
83151 };
83152
83153 -static struct snd_pcm_ops snd_hdsp_capture_ops = {
83154 +static const struct snd_pcm_ops snd_hdsp_capture_ops = {
83155 .open = snd_hdsp_capture_open,
83156 .close = snd_hdsp_capture_release,
83157 .ioctl = snd_hdsp_ioctl,
83158 diff -urNp linux-2.6.39.2/sound/pci/rme9652/hdspm.c linux-2.6.39.2/sound/pci/rme9652/hdspm.c
83159 --- linux-2.6.39.2/sound/pci/rme9652/hdspm.c 2011-05-19 00:06:34.000000000 -0400
83160 +++ linux-2.6.39.2/sound/pci/rme9652/hdspm.c 2011-05-22 19:36:35.000000000 -0400
83161 @@ -1773,15 +1773,13 @@ static int snd_hdspm_midi_output_close(s
83162 return 0;
83163 }
83164
83165 -static struct snd_rawmidi_ops snd_hdspm_midi_output =
83166 -{
83167 +static const struct snd_rawmidi_ops snd_hdspm_midi_output = {
83168 .open = snd_hdspm_midi_output_open,
83169 .close = snd_hdspm_midi_output_close,
83170 .trigger = snd_hdspm_midi_output_trigger,
83171 };
83172
83173 -static struct snd_rawmidi_ops snd_hdspm_midi_input =
83174 -{
83175 +static const struct snd_rawmidi_ops snd_hdspm_midi_input = {
83176 .open = snd_hdspm_midi_input_open,
83177 .close = snd_hdspm_midi_input_close,
83178 .trigger = snd_hdspm_midi_input_trigger,
83179 @@ -6172,7 +6170,7 @@ static int snd_hdspm_hwdep_ioctl(struct
83180 return 0;
83181 }
83182
83183 -static struct snd_pcm_ops snd_hdspm_playback_ops = {
83184 +static const struct snd_pcm_ops snd_hdspm_playback_ops = {
83185 .open = snd_hdspm_playback_open,
83186 .close = snd_hdspm_playback_release,
83187 .ioctl = snd_hdspm_ioctl,
83188 @@ -6184,7 +6182,7 @@ static struct snd_pcm_ops snd_hdspm_play
83189 .page = snd_pcm_sgbuf_ops_page,
83190 };
83191
83192 -static struct snd_pcm_ops snd_hdspm_capture_ops = {
83193 +static const struct snd_pcm_ops snd_hdspm_capture_ops = {
83194 .open = snd_hdspm_capture_open,
83195 .close = snd_hdspm_capture_release,
83196 .ioctl = snd_hdspm_ioctl,
83197 diff -urNp linux-2.6.39.2/sound/pci/rme9652/rme9652.c linux-2.6.39.2/sound/pci/rme9652/rme9652.c
83198 --- linux-2.6.39.2/sound/pci/rme9652/rme9652.c 2011-05-19 00:06:34.000000000 -0400
83199 +++ linux-2.6.39.2/sound/pci/rme9652/rme9652.c 2011-05-22 19:36:35.000000000 -0400
83200 @@ -2391,7 +2391,7 @@ static int snd_rme9652_capture_release(s
83201 return 0;
83202 }
83203
83204 -static struct snd_pcm_ops snd_rme9652_playback_ops = {
83205 +static const struct snd_pcm_ops snd_rme9652_playback_ops = {
83206 .open = snd_rme9652_playback_open,
83207 .close = snd_rme9652_playback_release,
83208 .ioctl = snd_rme9652_ioctl,
83209 @@ -2403,7 +2403,7 @@ static struct snd_pcm_ops snd_rme9652_pl
83210 .silence = snd_rme9652_hw_silence,
83211 };
83212
83213 -static struct snd_pcm_ops snd_rme9652_capture_ops = {
83214 +static const struct snd_pcm_ops snd_rme9652_capture_ops = {
83215 .open = snd_rme9652_capture_open,
83216 .close = snd_rme9652_capture_release,
83217 .ioctl = snd_rme9652_ioctl,
83218 diff -urNp linux-2.6.39.2/sound/pci/rme96.c linux-2.6.39.2/sound/pci/rme96.c
83219 --- linux-2.6.39.2/sound/pci/rme96.c 2011-05-19 00:06:34.000000000 -0400
83220 +++ linux-2.6.39.2/sound/pci/rme96.c 2011-05-22 19:36:35.000000000 -0400
83221 @@ -1447,7 +1447,7 @@ snd_rme96_capture_pointer(struct snd_pcm
83222 return snd_rme96_capture_ptr(rme96);
83223 }
83224
83225 -static struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
83226 +static const struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
83227 .open = snd_rme96_playback_spdif_open,
83228 .close = snd_rme96_playback_close,
83229 .ioctl = snd_pcm_lib_ioctl,
83230 @@ -1460,7 +1460,7 @@ static struct snd_pcm_ops snd_rme96_play
83231 .mmap = snd_pcm_lib_mmap_iomem,
83232 };
83233
83234 -static struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
83235 +static const struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
83236 .open = snd_rme96_capture_spdif_open,
83237 .close = snd_rme96_capture_close,
83238 .ioctl = snd_pcm_lib_ioctl,
83239 @@ -1472,7 +1472,7 @@ static struct snd_pcm_ops snd_rme96_capt
83240 .mmap = snd_pcm_lib_mmap_iomem,
83241 };
83242
83243 -static struct snd_pcm_ops snd_rme96_playback_adat_ops = {
83244 +static const struct snd_pcm_ops snd_rme96_playback_adat_ops = {
83245 .open = snd_rme96_playback_adat_open,
83246 .close = snd_rme96_playback_close,
83247 .ioctl = snd_pcm_lib_ioctl,
83248 @@ -1485,7 +1485,7 @@ static struct snd_pcm_ops snd_rme96_play
83249 .mmap = snd_pcm_lib_mmap_iomem,
83250 };
83251
83252 -static struct snd_pcm_ops snd_rme96_capture_adat_ops = {
83253 +static const struct snd_pcm_ops snd_rme96_capture_adat_ops = {
83254 .open = snd_rme96_capture_adat_open,
83255 .close = snd_rme96_capture_close,
83256 .ioctl = snd_pcm_lib_ioctl,
83257 diff -urNp linux-2.6.39.2/sound/pci/sis7019.c linux-2.6.39.2/sound/pci/sis7019.c
83258 --- linux-2.6.39.2/sound/pci/sis7019.c 2011-05-19 00:06:34.000000000 -0400
83259 +++ linux-2.6.39.2/sound/pci/sis7019.c 2011-05-22 19:36:35.000000000 -0400
83260 @@ -1011,7 +1011,7 @@ static int __devinit sis_mixer_create(st
83261 {
83262 struct snd_ac97_bus *bus;
83263 struct snd_ac97_template ac97;
83264 - static struct snd_ac97_bus_ops ops = {
83265 + static const struct snd_ac97_bus_ops ops = {
83266 .write = sis_ac97_write,
83267 .read = sis_ac97_read,
83268 };
83269 @@ -1293,7 +1293,7 @@ static int __devinit sis_chip_create(str
83270 {
83271 struct sis7019 *sis = card->private_data;
83272 struct voice *voice;
83273 - static struct snd_device_ops ops = {
83274 + static const struct snd_device_ops ops = {
83275 .dev_free = sis_dev_free,
83276 };
83277 int rc;
83278 diff -urNp linux-2.6.39.2/sound/pci/sonicvibes.c linux-2.6.39.2/sound/pci/sonicvibes.c
83279 --- linux-2.6.39.2/sound/pci/sonicvibes.c 2011-05-19 00:06:34.000000000 -0400
83280 +++ linux-2.6.39.2/sound/pci/sonicvibes.c 2011-05-22 19:36:35.000000000 -0400
83281 @@ -855,7 +855,7 @@ static int snd_sonicvibes_capture_close(
83282 return 0;
83283 }
83284
83285 -static struct snd_pcm_ops snd_sonicvibes_playback_ops = {
83286 +static const struct snd_pcm_ops snd_sonicvibes_playback_ops = {
83287 .open = snd_sonicvibes_playback_open,
83288 .close = snd_sonicvibes_playback_close,
83289 .ioctl = snd_pcm_lib_ioctl,
83290 @@ -866,7 +866,7 @@ static struct snd_pcm_ops snd_sonicvibes
83291 .pointer = snd_sonicvibes_playback_pointer,
83292 };
83293
83294 -static struct snd_pcm_ops snd_sonicvibes_capture_ops = {
83295 +static const struct snd_pcm_ops snd_sonicvibes_capture_ops = {
83296 .open = snd_sonicvibes_capture_open,
83297 .close = snd_sonicvibes_capture_close,
83298 .ioctl = snd_pcm_lib_ioctl,
83299 @@ -1255,7 +1255,7 @@ static int __devinit snd_sonicvibes_crea
83300 struct sonicvibes *sonic;
83301 unsigned int dmaa, dmac;
83302 int err;
83303 - static struct snd_device_ops ops = {
83304 + static const struct snd_device_ops ops = {
83305 .dev_free = snd_sonicvibes_dev_free,
83306 };
83307
83308 diff -urNp linux-2.6.39.2/sound/pci/trident/trident_main.c linux-2.6.39.2/sound/pci/trident/trident_main.c
83309 --- linux-2.6.39.2/sound/pci/trident/trident_main.c 2011-05-19 00:06:34.000000000 -0400
83310 +++ linux-2.6.39.2/sound/pci/trident/trident_main.c 2011-05-22 19:36:35.000000000 -0400
83311 @@ -3549,7 +3549,7 @@ int __devinit snd_trident_create(struct
83312 int i, err;
83313 struct snd_trident_voice *voice;
83314 struct snd_trident_pcm_mixer *tmix;
83315 - static struct snd_device_ops ops = {
83316 + static const struct snd_device_ops ops = {
83317 .dev_free = snd_trident_dev_free,
83318 };
83319
83320 diff -urNp linux-2.6.39.2/sound/pci/via82xx.c linux-2.6.39.2/sound/pci/via82xx.c
83321 --- linux-2.6.39.2/sound/pci/via82xx.c 2011-05-19 00:06:34.000000000 -0400
83322 +++ linux-2.6.39.2/sound/pci/via82xx.c 2011-05-22 19:36:35.000000000 -0400
83323 @@ -1352,7 +1352,7 @@ static int snd_via8233_playback_close(st
83324
83325
83326 /* via686 playback callbacks */
83327 -static struct snd_pcm_ops snd_via686_playback_ops = {
83328 +static const struct snd_pcm_ops snd_via686_playback_ops = {
83329 .open = snd_via686_playback_open,
83330 .close = snd_via82xx_pcm_close,
83331 .ioctl = snd_pcm_lib_ioctl,
83332 @@ -1365,7 +1365,7 @@ static struct snd_pcm_ops snd_via686_pla
83333 };
83334
83335 /* via686 capture callbacks */
83336 -static struct snd_pcm_ops snd_via686_capture_ops = {
83337 +static const struct snd_pcm_ops snd_via686_capture_ops = {
83338 .open = snd_via82xx_capture_open,
83339 .close = snd_via82xx_pcm_close,
83340 .ioctl = snd_pcm_lib_ioctl,
83341 @@ -1378,7 +1378,7 @@ static struct snd_pcm_ops snd_via686_cap
83342 };
83343
83344 /* via823x DSX playback callbacks */
83345 -static struct snd_pcm_ops snd_via8233_playback_ops = {
83346 +static const struct snd_pcm_ops snd_via8233_playback_ops = {
83347 .open = snd_via8233_playback_open,
83348 .close = snd_via8233_playback_close,
83349 .ioctl = snd_pcm_lib_ioctl,
83350 @@ -1391,7 +1391,7 @@ static struct snd_pcm_ops snd_via8233_pl
83351 };
83352
83353 /* via823x multi-channel playback callbacks */
83354 -static struct snd_pcm_ops snd_via8233_multi_ops = {
83355 +static const struct snd_pcm_ops snd_via8233_multi_ops = {
83356 .open = snd_via8233_multi_open,
83357 .close = snd_via82xx_pcm_close,
83358 .ioctl = snd_pcm_lib_ioctl,
83359 @@ -1404,7 +1404,7 @@ static struct snd_pcm_ops snd_via8233_mu
83360 };
83361
83362 /* via823x capture callbacks */
83363 -static struct snd_pcm_ops snd_via8233_capture_ops = {
83364 +static const struct snd_pcm_ops snd_via8233_capture_ops = {
83365 .open = snd_via82xx_capture_open,
83366 .close = snd_via82xx_pcm_close,
83367 .ioctl = snd_pcm_lib_ioctl,
83368 @@ -1868,7 +1868,7 @@ static int __devinit snd_via82xx_mixer_n
83369 {
83370 struct snd_ac97_template ac97;
83371 int err;
83372 - static struct snd_ac97_bus_ops ops = {
83373 + static const struct snd_ac97_bus_ops ops = {
83374 .write = snd_via82xx_codec_write,
83375 .read = snd_via82xx_codec_read,
83376 .wait = snd_via82xx_codec_wait,
83377 @@ -2340,7 +2340,7 @@ static int __devinit snd_via82xx_create(
83378 {
83379 struct via82xx *chip;
83380 int err;
83381 - static struct snd_device_ops ops = {
83382 + static const struct snd_device_ops ops = {
83383 .dev_free = snd_via82xx_dev_free,
83384 };
83385
83386 diff -urNp linux-2.6.39.2/sound/pci/via82xx_modem.c linux-2.6.39.2/sound/pci/via82xx_modem.c
83387 --- linux-2.6.39.2/sound/pci/via82xx_modem.c 2011-05-19 00:06:34.000000000 -0400
83388 +++ linux-2.6.39.2/sound/pci/via82xx_modem.c 2011-05-22 19:36:35.000000000 -0400
83389 @@ -799,7 +799,7 @@ static int snd_via82xx_pcm_close(struct
83390
83391
83392 /* via686 playback callbacks */
83393 -static struct snd_pcm_ops snd_via686_playback_ops = {
83394 +static const struct snd_pcm_ops snd_via686_playback_ops = {
83395 .open = snd_via82xx_playback_open,
83396 .close = snd_via82xx_pcm_close,
83397 .ioctl = snd_pcm_lib_ioctl,
83398 @@ -812,7 +812,7 @@ static struct snd_pcm_ops snd_via686_pla
83399 };
83400
83401 /* via686 capture callbacks */
83402 -static struct snd_pcm_ops snd_via686_capture_ops = {
83403 +static const struct snd_pcm_ops snd_via686_capture_ops = {
83404 .open = snd_via82xx_capture_open,
83405 .close = snd_via82xx_pcm_close,
83406 .ioctl = snd_pcm_lib_ioctl,
83407 @@ -889,7 +889,7 @@ static int __devinit snd_via82xx_mixer_n
83408 {
83409 struct snd_ac97_template ac97;
83410 int err;
83411 - static struct snd_ac97_bus_ops ops = {
83412 + static const struct snd_ac97_bus_ops ops = {
83413 .write = snd_via82xx_codec_write,
83414 .read = snd_via82xx_codec_read,
83415 .wait = snd_via82xx_codec_wait,
83416 @@ -1105,7 +1105,7 @@ static int __devinit snd_via82xx_create(
83417 {
83418 struct via82xx_modem *chip;
83419 int err;
83420 - static struct snd_device_ops ops = {
83421 + static const struct snd_device_ops ops = {
83422 .dev_free = snd_via82xx_dev_free,
83423 };
83424
83425 diff -urNp linux-2.6.39.2/sound/pci/vx222/vx222.c linux-2.6.39.2/sound/pci/vx222/vx222.c
83426 --- linux-2.6.39.2/sound/pci/vx222/vx222.c 2011-05-19 00:06:34.000000000 -0400
83427 +++ linux-2.6.39.2/sound/pci/vx222/vx222.c 2011-05-22 19:36:35.000000000 -0400
83428 @@ -141,7 +141,7 @@ static int __devinit snd_vx222_create(st
83429 struct vx_core *chip;
83430 struct snd_vx222 *vx;
83431 int i, err;
83432 - static struct snd_device_ops ops = {
83433 + static const struct snd_device_ops ops = {
83434 .dev_free = snd_vx222_dev_free,
83435 };
83436 struct snd_vx_ops *vx_ops;
83437 diff -urNp linux-2.6.39.2/sound/pci/ymfpci/ymfpci_main.c linux-2.6.39.2/sound/pci/ymfpci/ymfpci_main.c
83438 --- linux-2.6.39.2/sound/pci/ymfpci/ymfpci_main.c 2011-05-19 00:06:34.000000000 -0400
83439 +++ linux-2.6.39.2/sound/pci/ymfpci/ymfpci_main.c 2011-05-22 19:36:35.000000000 -0400
83440 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct sn
83441 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
83442 break;
83443 }
83444 - if (atomic_read(&chip->interrupt_sleep_count)) {
83445 - atomic_set(&chip->interrupt_sleep_count, 0);
83446 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83447 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83448 wake_up(&chip->interrupt_sleep);
83449 }
83450 __end:
83451 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct s
83452 continue;
83453 init_waitqueue_entry(&wait, current);
83454 add_wait_queue(&chip->interrupt_sleep, &wait);
83455 - atomic_inc(&chip->interrupt_sleep_count);
83456 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
83457 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
83458 remove_wait_queue(&chip->interrupt_sleep, &wait);
83459 }
83460 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(
83461 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
83462 spin_unlock(&chip->reg_lock);
83463
83464 - if (atomic_read(&chip->interrupt_sleep_count)) {
83465 - atomic_set(&chip->interrupt_sleep_count, 0);
83466 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
83467 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83468 wake_up(&chip->interrupt_sleep);
83469 }
83470 }
83471 @@ -2344,7 +2344,7 @@ int __devinit snd_ymfpci_create(struct s
83472 {
83473 struct snd_ymfpci *chip;
83474 int err;
83475 - static struct snd_device_ops ops = {
83476 + static const struct snd_device_ops ops = {
83477 .dev_free = snd_ymfpci_dev_free,
83478 };
83479
83480 @@ -2363,7 +2363,7 @@ int __devinit snd_ymfpci_create(struct s
83481 spin_lock_init(&chip->reg_lock);
83482 spin_lock_init(&chip->voice_lock);
83483 init_waitqueue_head(&chip->interrupt_sleep);
83484 - atomic_set(&chip->interrupt_sleep_count, 0);
83485 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
83486 chip->card = card;
83487 chip->pci = pci;
83488 chip->irq = -1;
83489 diff -urNp linux-2.6.39.2/sound/pcmcia/pdaudiocf/pdaudiocf.c linux-2.6.39.2/sound/pcmcia/pdaudiocf/pdaudiocf.c
83490 --- linux-2.6.39.2/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-19 00:06:34.000000000 -0400
83491 +++ linux-2.6.39.2/sound/pcmcia/pdaudiocf/pdaudiocf.c 2011-05-22 19:36:35.000000000 -0400
83492 @@ -94,7 +94,7 @@ static int snd_pdacf_probe(struct pcmcia
83493 int i, err;
83494 struct snd_pdacf *pdacf;
83495 struct snd_card *card;
83496 - static struct snd_device_ops ops = {
83497 + static const struct snd_device_ops ops = {
83498 .dev_free = snd_pdacf_dev_free,
83499 };
83500
83501 diff -urNp linux-2.6.39.2/sound/pcmcia/vx/vxpocket.c linux-2.6.39.2/sound/pcmcia/vx/vxpocket.c
83502 --- linux-2.6.39.2/sound/pcmcia/vx/vxpocket.c 2011-05-19 00:06:34.000000000 -0400
83503 +++ linux-2.6.39.2/sound/pcmcia/vx/vxpocket.c 2011-05-22 19:36:35.000000000 -0400
83504 @@ -137,7 +137,7 @@ static int snd_vxpocket_new(struct snd_c
83505 {
83506 struct vx_core *chip;
83507 struct snd_vxpocket *vxp;
83508 - static struct snd_device_ops ops = {
83509 + static const struct snd_device_ops ops = {
83510 .dev_free = snd_vxpocket_dev_free,
83511 };
83512 int err;
83513 diff -urNp linux-2.6.39.2/sound/ppc/pmac.c linux-2.6.39.2/sound/ppc/pmac.c
83514 --- linux-2.6.39.2/sound/ppc/pmac.c 2011-05-19 00:06:34.000000000 -0400
83515 +++ linux-2.6.39.2/sound/ppc/pmac.c 2011-05-22 19:36:35.000000000 -0400
83516 @@ -1186,7 +1186,7 @@ int __devinit snd_pmac_new(struct snd_ca
83517 int i, err;
83518 unsigned int irq;
83519 unsigned long ctrl_addr, txdma_addr, rxdma_addr;
83520 - static struct snd_device_ops ops = {
83521 + static const struct snd_device_ops ops = {
83522 .dev_free = snd_pmac_dev_free,
83523 };
83524
83525 diff -urNp linux-2.6.39.2/sound/ppc/snd_ps3.c linux-2.6.39.2/sound/ppc/snd_ps3.c
83526 --- linux-2.6.39.2/sound/ppc/snd_ps3.c 2011-05-19 00:06:34.000000000 -0400
83527 +++ linux-2.6.39.2/sound/ppc/snd_ps3.c 2011-05-22 19:36:35.000000000 -0400
83528 @@ -773,7 +773,7 @@ static struct snd_kcontrol_new spdif_ctl
83529 },
83530 };
83531
83532 -static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83533 +static const struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
83534 .open = snd_ps3_pcm_open,
83535 .close = snd_ps3_pcm_close,
83536 .ioctl = snd_pcm_lib_ioctl,
83537 diff -urNp linux-2.6.39.2/sound/sh/aica.c linux-2.6.39.2/sound/sh/aica.c
83538 --- linux-2.6.39.2/sound/sh/aica.c 2011-05-19 00:06:34.000000000 -0400
83539 +++ linux-2.6.39.2/sound/sh/aica.c 2011-05-22 19:36:35.000000000 -0400
83540 @@ -441,7 +441,7 @@ static unsigned long snd_aicapcm_pcm_poi
83541 return readl(AICA_CONTROL_CHANNEL_SAMPLE_NUMBER);
83542 }
83543
83544 -static struct snd_pcm_ops snd_aicapcm_playback_ops = {
83545 +static const struct snd_pcm_ops snd_aicapcm_playback_ops = {
83546 .open = snd_aicapcm_pcm_open,
83547 .close = snd_aicapcm_pcm_close,
83548 .ioctl = snd_pcm_lib_ioctl,
83549 diff -urNp linux-2.6.39.2/sound/sh/sh_dac_audio.c linux-2.6.39.2/sound/sh/sh_dac_audio.c
83550 --- linux-2.6.39.2/sound/sh/sh_dac_audio.c 2011-05-19 00:06:34.000000000 -0400
83551 +++ linux-2.6.39.2/sound/sh/sh_dac_audio.c 2011-05-22 19:36:35.000000000 -0400
83552 @@ -246,7 +246,7 @@ snd_pcm_uframes_t snd_sh_dac_pcm_pointer
83553 }
83554
83555 /* pcm ops */
83556 -static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83557 +static const struct snd_pcm_ops snd_sh_dac_pcm_ops = {
83558 .open = snd_sh_dac_pcm_open,
83559 .close = snd_sh_dac_pcm_close,
83560 .ioctl = snd_pcm_lib_ioctl,
83561 @@ -352,7 +352,7 @@ static int __devinit snd_sh_dac_create(s
83562 struct snd_sh_dac *chip;
83563 int err;
83564
83565 - static struct snd_device_ops ops = {
83566 + static const struct snd_device_ops ops = {
83567 .dev_free = snd_sh_dac_dev_free,
83568 };
83569
83570 diff -urNp linux-2.6.39.2/sound/soc/atmel/atmel-pcm.c linux-2.6.39.2/sound/soc/atmel/atmel-pcm.c
83571 --- linux-2.6.39.2/sound/soc/atmel/atmel-pcm.c 2011-05-19 00:06:34.000000000 -0400
83572 +++ linux-2.6.39.2/sound/soc/atmel/atmel-pcm.c 2011-05-22 19:36:35.000000000 -0400
83573 @@ -346,7 +346,7 @@ static int atmel_pcm_mmap(struct snd_pcm
83574 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83575 }
83576
83577 -static struct snd_pcm_ops atmel_pcm_ops = {
83578 +static const struct snd_pcm_ops atmel_pcm_ops = {
83579 .open = atmel_pcm_open,
83580 .close = atmel_pcm_close,
83581 .ioctl = snd_pcm_lib_ioctl,
83582 diff -urNp linux-2.6.39.2/sound/soc/atmel/playpaq_wm8510.c linux-2.6.39.2/sound/soc/atmel/playpaq_wm8510.c
83583 --- linux-2.6.39.2/sound/soc/atmel/playpaq_wm8510.c 2011-05-19 00:06:34.000000000 -0400
83584 +++ linux-2.6.39.2/sound/soc/atmel/playpaq_wm8510.c 2011-05-22 19:36:35.000000000 -0400
83585 @@ -289,7 +289,7 @@ static int playpaq_wm8510_hw_params(stru
83586
83587
83588
83589 -static struct snd_soc_ops playpaq_wm8510_ops = {
83590 +static const struct snd_soc_ops playpaq_wm8510_ops = {
83591 .hw_params = playpaq_wm8510_hw_params,
83592 };
83593
83594 diff -urNp linux-2.6.39.2/sound/soc/atmel/sam9g20_wm8731.c linux-2.6.39.2/sound/soc/atmel/sam9g20_wm8731.c
83595 --- linux-2.6.39.2/sound/soc/atmel/sam9g20_wm8731.c 2011-05-19 00:06:34.000000000 -0400
83596 +++ linux-2.6.39.2/sound/soc/atmel/sam9g20_wm8731.c 2011-05-22 19:36:35.000000000 -0400
83597 @@ -87,7 +87,7 @@ static int at91sam9g20ek_hw_params(struc
83598 return 0;
83599 }
83600
83601 -static struct snd_soc_ops at91sam9g20ek_ops = {
83602 +static const struct snd_soc_ops at91sam9g20ek_ops = {
83603 .hw_params = at91sam9g20ek_hw_params,
83604 };
83605
83606 diff -urNp linux-2.6.39.2/sound/soc/atmel/snd-soc-afeb9260.c linux-2.6.39.2/sound/soc/atmel/snd-soc-afeb9260.c
83607 --- linux-2.6.39.2/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-19 00:06:34.000000000 -0400
83608 +++ linux-2.6.39.2/sound/soc/atmel/snd-soc-afeb9260.c 2011-05-22 19:36:35.000000000 -0400
83609 @@ -81,7 +81,7 @@ static int afeb9260_hw_params(struct snd
83610 return err;
83611 }
83612
83613 -static struct snd_soc_ops afeb9260_ops = {
83614 +static const struct snd_soc_ops afeb9260_ops = {
83615 .hw_params = afeb9260_hw_params,
83616 };
83617
83618 diff -urNp linux-2.6.39.2/sound/soc/au1x/db1200.c linux-2.6.39.2/sound/soc/au1x/db1200.c
83619 --- linux-2.6.39.2/sound/soc/au1x/db1200.c 2011-05-19 00:06:34.000000000 -0400
83620 +++ linux-2.6.39.2/sound/soc/au1x/db1200.c 2011-05-22 19:36:35.000000000 -0400
83621 @@ -67,7 +67,7 @@ out:
83622 return ret;
83623 }
83624
83625 -static struct snd_soc_ops db1200_i2s_wm8731_ops = {
83626 +static const struct snd_soc_ops db1200_i2s_wm8731_ops = {
83627 .startup = db1200_i2s_startup,
83628 };
83629
83630 diff -urNp linux-2.6.39.2/sound/soc/au1x/dbdma2.c linux-2.6.39.2/sound/soc/au1x/dbdma2.c
83631 --- linux-2.6.39.2/sound/soc/au1x/dbdma2.c 2011-05-19 00:06:34.000000000 -0400
83632 +++ linux-2.6.39.2/sound/soc/au1x/dbdma2.c 2011-05-22 19:36:35.000000000 -0400
83633 @@ -303,7 +303,7 @@ static int au1xpsc_pcm_close(struct snd_
83634 return 0;
83635 }
83636
83637 -static struct snd_pcm_ops au1xpsc_pcm_ops = {
83638 +static const struct snd_pcm_ops au1xpsc_pcm_ops = {
83639 .open = au1xpsc_pcm_open,
83640 .close = au1xpsc_pcm_close,
83641 .ioctl = snd_pcm_lib_ioctl,
83642 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.c
83643 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83644 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83645 @@ -244,7 +244,7 @@ static void bf5xx_ac97_cold_reset(struct
83646 #endif
83647 }
83648
83649 -struct snd_ac97_bus_ops soc_ac97_ops = {
83650 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83651 .read = bf5xx_ac97_read,
83652 .write = bf5xx_ac97_write,
83653 .warm_reset = bf5xx_ac97_warm_reset,
83654 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.h linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.h
83655 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
83656 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
83657 @@ -9,7 +9,7 @@
83658 #ifndef _BF5XX_AC97_H
83659 #define _BF5XX_AC97_H
83660
83661 -extern struct snd_ac97_bus_ops bf5xx_ac97_ops;
83662 +extern const struct snd_ac97_bus_ops bf5xx_ac97_ops;
83663 extern struct snd_ac97 *ac97;
83664 /* Frame format in memory, only support stereo currently */
83665 struct ac97_frame {
83666 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97-pcm.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97-pcm.c
83667 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-19 00:06:34.000000000 -0400
83668 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ac97-pcm.c 2011-05-22 19:36:35.000000000 -0400
83669 @@ -297,7 +297,7 @@ static int bf5xx_pcm_copy(struct snd_pcm
83670 }
83671 #endif
83672
83673 -static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83674 +static const struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
83675 .open = bf5xx_pcm_open,
83676 .ioctl = snd_pcm_lib_ioctl,
83677 .hw_params = bf5xx_pcm_hw_params,
83678 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1836.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1836.c
83679 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-19 00:06:34.000000000 -0400
83680 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1836.c 2011-05-22 19:36:35.000000000 -0400
83681 @@ -74,7 +74,7 @@ static int bf5xx_ad1836_hw_params(struct
83682 return 0;
83683 }
83684
83685 -static struct snd_soc_ops bf5xx_ad1836_ops = {
83686 +static const struct snd_soc_ops bf5xx_ad1836_ops = {
83687 .startup = bf5xx_ad1836_startup,
83688 .hw_params = bf5xx_ad1836_hw_params,
83689 };
83690 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad193x.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad193x.c
83691 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-19 00:06:34.000000000 -0400
83692 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad193x.c 2011-05-22 19:36:35.000000000 -0400
83693 @@ -88,7 +88,7 @@ static int bf5xx_ad193x_hw_params(struct
83694 return 0;
83695 }
83696
83697 -static struct snd_soc_ops bf5xx_ad193x_ops = {
83698 +static const struct snd_soc_ops bf5xx_ad193x_ops = {
83699 .startup = bf5xx_ad193x_startup,
83700 .hw_params = bf5xx_ad193x_hw_params,
83701 };
83702 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1980.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1980.c
83703 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-19 00:06:34.000000000 -0400
83704 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad1980.c 2011-05-22 19:36:35.000000000 -0400
83705 @@ -63,7 +63,7 @@ static int bf5xx_board_startup(struct sn
83706 return 0;
83707 }
83708
83709 -static struct snd_soc_ops bf5xx_board_ops = {
83710 +static const struct snd_soc_ops bf5xx_board_ops = {
83711 .startup = bf5xx_board_startup,
83712 };
83713
83714 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad73311.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad73311.c
83715 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-19 00:06:34.000000000 -0400
83716 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ad73311.c 2011-05-22 19:36:35.000000000 -0400
83717 @@ -175,7 +175,7 @@ static int bf5xx_ad73311_hw_params(struc
83718 }
83719
83720
83721 -static struct snd_soc_ops bf5xx_ad73311_ops = {
83722 +static const struct snd_soc_ops bf5xx_ad73311_ops = {
83723 .startup = bf5xx_ad73311_startup,
83724 .hw_params = bf5xx_ad73311_hw_params,
83725 };
83726 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-i2s-pcm.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-i2s-pcm.c
83727 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-19 00:06:34.000000000 -0400
83728 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-i2s-pcm.c 2011-05-22 19:36:35.000000000 -0400
83729 @@ -183,7 +183,7 @@ static int bf5xx_pcm_mmap(struct snd_pcm
83730 return 0 ;
83731 }
83732
83733 -static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83734 +static const struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
83735 .open = bf5xx_pcm_open,
83736 .ioctl = snd_pcm_lib_ioctl,
83737 .hw_params = bf5xx_pcm_hw_params,
83738 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-ssm2602.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-ssm2602.c
83739 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-19 00:06:34.000000000 -0400
83740 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-ssm2602.c 2011-05-22 19:36:35.000000000 -0400
83741 @@ -108,7 +108,7 @@ static int bf5xx_ssm2602_hw_params(struc
83742 return 0;
83743 }
83744
83745 -static struct snd_soc_ops bf5xx_ssm2602_ops = {
83746 +static const struct snd_soc_ops bf5xx_ssm2602_ops = {
83747 .startup = bf5xx_ssm2602_startup,
83748 .hw_params = bf5xx_ssm2602_hw_params,
83749 };
83750 diff -urNp linux-2.6.39.2/sound/soc/blackfin/bf5xx-tdm-pcm.c linux-2.6.39.2/sound/soc/blackfin/bf5xx-tdm-pcm.c
83751 --- linux-2.6.39.2/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-19 00:06:34.000000000 -0400
83752 +++ linux-2.6.39.2/sound/soc/blackfin/bf5xx-tdm-pcm.c 2011-05-22 19:36:35.000000000 -0400
83753 @@ -220,7 +220,7 @@ static int bf5xx_pcm_silence(struct snd_
83754 }
83755
83756
83757 -struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83758 +const struct snd_pcm_ops bf5xx_pcm_tdm_ops = {
83759 .open = bf5xx_pcm_open,
83760 .ioctl = snd_pcm_lib_ioctl,
83761 .hw_params = bf5xx_pcm_hw_params,
83762 diff -urNp linux-2.6.39.2/sound/soc/davinci/davinci-evm.c linux-2.6.39.2/sound/soc/davinci/davinci-evm.c
83763 --- linux-2.6.39.2/sound/soc/davinci/davinci-evm.c 2011-05-19 00:06:34.000000000 -0400
83764 +++ linux-2.6.39.2/sound/soc/davinci/davinci-evm.c 2011-05-22 19:36:35.000000000 -0400
83765 @@ -88,11 +88,11 @@ static int evm_spdif_hw_params(struct sn
83766 return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
83767 }
83768
83769 -static struct snd_soc_ops evm_ops = {
83770 +static const struct snd_soc_ops evm_ops = {
83771 .hw_params = evm_hw_params,
83772 };
83773
83774 -static struct snd_soc_ops evm_spdif_ops = {
83775 +static const struct snd_soc_ops evm_spdif_ops = {
83776 .hw_params = evm_spdif_hw_params,
83777 };
83778
83779 diff -urNp linux-2.6.39.2/sound/soc/davinci/davinci-pcm.c linux-2.6.39.2/sound/soc/davinci/davinci-pcm.c
83780 --- linux-2.6.39.2/sound/soc/davinci/davinci-pcm.c 2011-05-19 00:06:34.000000000 -0400
83781 +++ linux-2.6.39.2/sound/soc/davinci/davinci-pcm.c 2011-05-22 19:36:35.000000000 -0400
83782 @@ -748,7 +748,7 @@ static int davinci_pcm_mmap(struct snd_p
83783 runtime->dma_bytes);
83784 }
83785
83786 -static struct snd_pcm_ops davinci_pcm_ops = {
83787 +static const struct snd_pcm_ops davinci_pcm_ops = {
83788 .open = davinci_pcm_open,
83789 .close = davinci_pcm_close,
83790 .ioctl = snd_pcm_lib_ioctl,
83791 diff -urNp linux-2.6.39.2/sound/soc/davinci/davinci-sffsdr.c linux-2.6.39.2/sound/soc/davinci/davinci-sffsdr.c
83792 --- linux-2.6.39.2/sound/soc/davinci/davinci-sffsdr.c 2011-05-19 00:06:34.000000000 -0400
83793 +++ linux-2.6.39.2/sound/soc/davinci/davinci-sffsdr.c 2011-05-22 19:36:35.000000000 -0400
83794 @@ -75,7 +75,7 @@ static int sffsdr_hw_params(struct snd_p
83795 #endif
83796 }
83797
83798 -static struct snd_soc_ops sffsdr_ops = {
83799 +static const struct snd_soc_ops sffsdr_ops = {
83800 .hw_params = sffsdr_hw_params,
83801 };
83802
83803 diff -urNp linux-2.6.39.2/sound/soc/ep93xx/edb93xx.c linux-2.6.39.2/sound/soc/ep93xx/edb93xx.c
83804 --- linux-2.6.39.2/sound/soc/ep93xx/edb93xx.c 2011-05-19 00:06:34.000000000 -0400
83805 +++ linux-2.6.39.2/sound/soc/ep93xx/edb93xx.c 2011-05-22 19:36:35.000000000 -0400
83806 @@ -74,7 +74,7 @@ static int edb93xx_hw_params(struct snd_
83807 SND_SOC_CLOCK_OUT);
83808 }
83809
83810 -static struct snd_soc_ops edb93xx_ops = {
83811 +static const struct snd_soc_ops edb93xx_ops = {
83812 .hw_params = edb93xx_hw_params,
83813 };
83814
83815 diff -urNp linux-2.6.39.2/sound/soc/ep93xx/ep93xx-ac97.c linux-2.6.39.2/sound/soc/ep93xx/ep93xx-ac97.c
83816 --- linux-2.6.39.2/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
83817 +++ linux-2.6.39.2/sound/soc/ep93xx/ep93xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
83818 @@ -239,7 +239,7 @@ static irqreturn_t ep93xx_ac97_interrupt
83819 return IRQ_HANDLED;
83820 }
83821
83822 -struct snd_ac97_bus_ops soc_ac97_ops = {
83823 +const struct snd_ac97_bus_ops soc_ac97_ops = {
83824 .read = ep93xx_ac97_read,
83825 .write = ep93xx_ac97_write,
83826 .reset = ep93xx_ac97_cold_reset,
83827 diff -urNp linux-2.6.39.2/sound/soc/ep93xx/ep93xx-pcm.c linux-2.6.39.2/sound/soc/ep93xx/ep93xx-pcm.c
83828 --- linux-2.6.39.2/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-19 00:06:34.000000000 -0400
83829 +++ linux-2.6.39.2/sound/soc/ep93xx/ep93xx-pcm.c 2011-05-22 19:36:35.000000000 -0400
83830 @@ -216,7 +216,7 @@ static int ep93xx_pcm_mmap(struct snd_pc
83831 runtime->dma_bytes);
83832 }
83833
83834 -static struct snd_pcm_ops ep93xx_pcm_ops = {
83835 +static const struct snd_pcm_ops ep93xx_pcm_ops = {
83836 .open = ep93xx_pcm_open,
83837 .close = ep93xx_pcm_close,
83838 .ioctl = snd_pcm_lib_ioctl,
83839 diff -urNp linux-2.6.39.2/sound/soc/ep93xx/snappercl15.c linux-2.6.39.2/sound/soc/ep93xx/snappercl15.c
83840 --- linux-2.6.39.2/sound/soc/ep93xx/snappercl15.c 2011-05-19 00:06:34.000000000 -0400
83841 +++ linux-2.6.39.2/sound/soc/ep93xx/snappercl15.c 2011-05-22 19:36:35.000000000 -0400
83842 @@ -55,7 +55,7 @@ static int snappercl15_hw_params(struct
83843 return 0;
83844 }
83845
83846 -static struct snd_soc_ops snappercl15_ops = {
83847 +static const struct snd_soc_ops snappercl15_ops = {
83848 .hw_params = snappercl15_hw_params,
83849 };
83850
83851 diff -urNp linux-2.6.39.2/sound/soc/fsl/fsl_dma.c linux-2.6.39.2/sound/soc/fsl/fsl_dma.c
83852 --- linux-2.6.39.2/sound/soc/fsl/fsl_dma.c 2011-05-19 00:06:34.000000000 -0400
83853 +++ linux-2.6.39.2/sound/soc/fsl/fsl_dma.c 2011-05-22 19:36:35.000000000 -0400
83854 @@ -887,7 +887,7 @@ static struct device_node *find_ssi_node
83855 return NULL;
83856 }
83857
83858 -static struct snd_pcm_ops fsl_dma_ops = {
83859 +static const struct snd_pcm_ops fsl_dma_ops = {
83860 .open = fsl_dma_open,
83861 .close = fsl_dma_close,
83862 .ioctl = snd_pcm_lib_ioctl,
83863 diff -urNp linux-2.6.39.2/sound/soc/fsl/mpc8610_hpcd.c linux-2.6.39.2/sound/soc/fsl/mpc8610_hpcd.c
83864 --- linux-2.6.39.2/sound/soc/fsl/mpc8610_hpcd.c 2011-05-19 00:06:34.000000000 -0400
83865 +++ linux-2.6.39.2/sound/soc/fsl/mpc8610_hpcd.c 2011-05-22 19:36:35.000000000 -0400
83866 @@ -175,7 +175,7 @@ static int mpc8610_hpcd_machine_remove(s
83867 /**
83868 * mpc8610_hpcd_ops: ASoC machine driver operations
83869 */
83870 -static struct snd_soc_ops mpc8610_hpcd_ops = {
83871 +static const struct snd_soc_ops mpc8610_hpcd_ops = {
83872 .startup = mpc8610_hpcd_startup,
83873 };
83874
83875 diff -urNp linux-2.6.39.2/sound/soc/fsl/p1022_ds.c linux-2.6.39.2/sound/soc/fsl/p1022_ds.c
83876 --- linux-2.6.39.2/sound/soc/fsl/p1022_ds.c 2011-05-19 00:06:34.000000000 -0400
83877 +++ linux-2.6.39.2/sound/soc/fsl/p1022_ds.c 2011-05-22 19:36:35.000000000 -0400
83878 @@ -185,7 +185,7 @@ static int p1022_ds_machine_remove(struc
83879 /**
83880 * p1022_ds_ops: ASoC machine driver operations
83881 */
83882 -static struct snd_soc_ops p1022_ds_ops = {
83883 +static const struct snd_soc_ops p1022_ds_ops = {
83884 .startup = p1022_ds_startup,
83885 };
83886
83887 diff -urNp linux-2.6.39.2/sound/soc/imx/eukrea-tlv320.c linux-2.6.39.2/sound/soc/imx/eukrea-tlv320.c
83888 --- linux-2.6.39.2/sound/soc/imx/eukrea-tlv320.c 2011-05-19 00:06:34.000000000 -0400
83889 +++ linux-2.6.39.2/sound/soc/imx/eukrea-tlv320.c 2011-05-22 19:36:35.000000000 -0400
83890 @@ -71,7 +71,7 @@ static int eukrea_tlv320_hw_params(struc
83891 return 0;
83892 }
83893
83894 -static struct snd_soc_ops eukrea_tlv320_snd_ops = {
83895 +static const struct snd_soc_ops eukrea_tlv320_snd_ops = {
83896 .hw_params = eukrea_tlv320_hw_params,
83897 };
83898
83899 diff -urNp linux-2.6.39.2/sound/soc/imx/imx-pcm-dma-mx2.c linux-2.6.39.2/sound/soc/imx/imx-pcm-dma-mx2.c
83900 --- linux-2.6.39.2/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-19 00:06:34.000000000 -0400
83901 +++ linux-2.6.39.2/sound/soc/imx/imx-pcm-dma-mx2.c 2011-05-22 19:36:35.000000000 -0400
83902 @@ -283,7 +283,7 @@ static int snd_imx_close(struct snd_pcm_
83903 return 0;
83904 }
83905
83906 -static struct snd_pcm_ops imx_pcm_ops = {
83907 +static const struct snd_pcm_ops imx_pcm_ops = {
83908 .open = snd_imx_open,
83909 .close = snd_imx_close,
83910 .ioctl = snd_pcm_lib_ioctl,
83911 diff -urNp linux-2.6.39.2/sound/soc/imx/imx-pcm-fiq.c linux-2.6.39.2/sound/soc/imx/imx-pcm-fiq.c
83912 --- linux-2.6.39.2/sound/soc/imx/imx-pcm-fiq.c 2011-05-19 00:06:34.000000000 -0400
83913 +++ linux-2.6.39.2/sound/soc/imx/imx-pcm-fiq.c 2011-05-22 19:36:35.000000000 -0400
83914 @@ -225,7 +225,7 @@ static int snd_imx_close(struct snd_pcm_
83915 return 0;
83916 }
83917
83918 -static struct snd_pcm_ops imx_pcm_ops = {
83919 +static const struct snd_pcm_ops imx_pcm_ops = {
83920 .open = snd_imx_open,
83921 .close = snd_imx_close,
83922 .ioctl = snd_pcm_lib_ioctl,
83923 diff -urNp linux-2.6.39.2/sound/soc/imx/mx27vis-aic32x4.c linux-2.6.39.2/sound/soc/imx/mx27vis-aic32x4.c
83924 --- linux-2.6.39.2/sound/soc/imx/mx27vis-aic32x4.c 2011-05-19 00:06:34.000000000 -0400
83925 +++ linux-2.6.39.2/sound/soc/imx/mx27vis-aic32x4.c 2011-05-22 19:36:35.000000000 -0400
83926 @@ -70,7 +70,7 @@ static int mx27vis_aic32x4_hw_params(str
83927 return 0;
83928 }
83929
83930 -static struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83931 +static const struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
83932 .hw_params = mx27vis_aic32x4_hw_params,
83933 };
83934
83935 diff -urNp linux-2.6.39.2/sound/soc/imx/phycore-ac97.c linux-2.6.39.2/sound/soc/imx/phycore-ac97.c
83936 --- linux-2.6.39.2/sound/soc/imx/phycore-ac97.c 2011-05-19 00:06:34.000000000 -0400
83937 +++ linux-2.6.39.2/sound/soc/imx/phycore-ac97.c 2011-05-22 19:36:35.000000000 -0400
83938 @@ -21,7 +21,7 @@
83939
83940 static struct snd_soc_card imx_phycore;
83941
83942 -static struct snd_soc_ops imx_phycore_hifi_ops = {
83943 +static const struct snd_soc_ops imx_phycore_hifi_ops = {
83944 };
83945
83946 static struct snd_soc_dai_link imx_phycore_dai_ac97[] = {
83947 diff -urNp linux-2.6.39.2/sound/soc/imx/wm1133-ev1.c linux-2.6.39.2/sound/soc/imx/wm1133-ev1.c
83948 --- linux-2.6.39.2/sound/soc/imx/wm1133-ev1.c 2011-05-19 00:06:34.000000000 -0400
83949 +++ linux-2.6.39.2/sound/soc/imx/wm1133-ev1.c 2011-05-22 19:36:35.000000000 -0400
83950 @@ -149,7 +149,7 @@ static int wm1133_ev1_hw_params(struct s
83951 return 0;
83952 }
83953
83954 -static struct snd_soc_ops wm1133_ev1_ops = {
83955 +static const struct snd_soc_ops wm1133_ev1_ops = {
83956 .hw_params = wm1133_ev1_hw_params,
83957 };
83958
83959 diff -urNp linux-2.6.39.2/sound/soc/jz4740/jz4740-pcm.c linux-2.6.39.2/sound/soc/jz4740/jz4740-pcm.c
83960 --- linux-2.6.39.2/sound/soc/jz4740/jz4740-pcm.c 2011-05-19 00:06:34.000000000 -0400
83961 +++ linux-2.6.39.2/sound/soc/jz4740/jz4740-pcm.c 2011-05-22 19:36:35.000000000 -0400
83962 @@ -244,7 +244,7 @@ static int jz4740_pcm_mmap(struct snd_pc
83963 vma->vm_end - vma->vm_start, vma->vm_page_prot);
83964 }
83965
83966 -static struct snd_pcm_ops jz4740_pcm_ops = {
83967 +static const struct snd_pcm_ops jz4740_pcm_ops = {
83968 .open = jz4740_pcm_open,
83969 .close = jz4740_pcm_close,
83970 .ioctl = snd_pcm_lib_ioctl,
83971 diff -urNp linux-2.6.39.2/sound/soc/kirkwood/kirkwood-openrd.c linux-2.6.39.2/sound/soc/kirkwood/kirkwood-openrd.c
83972 --- linux-2.6.39.2/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-19 00:06:34.000000000 -0400
83973 +++ linux-2.6.39.2/sound/soc/kirkwood/kirkwood-openrd.c 2011-05-22 19:36:35.000000000 -0400
83974 @@ -56,7 +56,7 @@ static int openrd_client_hw_params(struc
83975
83976 }
83977
83978 -static struct snd_soc_ops openrd_client_ops = {
83979 +static const struct snd_soc_ops openrd_client_ops = {
83980 .hw_params = openrd_client_hw_params,
83981 };
83982
83983 diff -urNp linux-2.6.39.2/sound/soc/kirkwood/kirkwood-t5325.c linux-2.6.39.2/sound/soc/kirkwood/kirkwood-t5325.c
83984 --- linux-2.6.39.2/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-19 00:06:34.000000000 -0400
83985 +++ linux-2.6.39.2/sound/soc/kirkwood/kirkwood-t5325.c 2011-05-22 19:36:35.000000000 -0400
83986 @@ -44,7 +44,7 @@ static int t5325_hw_params(struct snd_pc
83987
83988 }
83989
83990 -static struct snd_soc_ops t5325_ops = {
83991 +static const struct snd_soc_ops t5325_ops = {
83992 .hw_params = t5325_hw_params,
83993 };
83994
83995 diff -urNp linux-2.6.39.2/sound/soc/mid-x86/sst_platform.c linux-2.6.39.2/sound/soc/mid-x86/sst_platform.c
83996 --- linux-2.6.39.2/sound/soc/mid-x86/sst_platform.c 2011-05-19 00:06:34.000000000 -0400
83997 +++ linux-2.6.39.2/sound/soc/mid-x86/sst_platform.c 2011-05-22 19:36:35.000000000 -0400
83998 @@ -381,7 +381,7 @@ static int sst_platform_pcm_hw_free(stru
83999 return snd_pcm_lib_free_pages(substream);
84000 }
84001
84002 -static struct snd_pcm_ops sst_platform_ops = {
84003 +static const struct snd_pcm_ops sst_platform_ops = {
84004 .open = sst_platform_open,
84005 .close = sst_platform_close,
84006 .ioctl = snd_pcm_lib_ioctl,
84007 diff -urNp linux-2.6.39.2/sound/soc/nuc900/nuc900-pcm.c linux-2.6.39.2/sound/soc/nuc900/nuc900-pcm.c
84008 --- linux-2.6.39.2/sound/soc/nuc900/nuc900-pcm.c 2011-05-19 00:06:34.000000000 -0400
84009 +++ linux-2.6.39.2/sound/soc/nuc900/nuc900-pcm.c 2011-05-22 19:36:35.000000000 -0400
84010 @@ -297,7 +297,7 @@ static int nuc900_dma_mmap(struct snd_pc
84011 runtime->dma_bytes);
84012 }
84013
84014 -static struct snd_pcm_ops nuc900_dma_ops = {
84015 +static const struct snd_pcm_ops nuc900_dma_ops = {
84016 .open = nuc900_dma_open,
84017 .close = nuc900_dma_close,
84018 .ioctl = snd_pcm_lib_ioctl,
84019 diff -urNp linux-2.6.39.2/sound/soc/omap/am3517evm.c linux-2.6.39.2/sound/soc/omap/am3517evm.c
84020 --- linux-2.6.39.2/sound/soc/omap/am3517evm.c 2011-05-19 00:06:34.000000000 -0400
84021 +++ linux-2.6.39.2/sound/soc/omap/am3517evm.c 2011-05-22 19:36:35.000000000 -0400
84022 @@ -88,7 +88,7 @@ static int am3517evm_hw_params(struct sn
84023 return 0;
84024 }
84025
84026 -static struct snd_soc_ops am3517evm_ops = {
84027 +static const struct snd_soc_ops am3517evm_ops = {
84028 .hw_params = am3517evm_hw_params,
84029 };
84030
84031 diff -urNp linux-2.6.39.2/sound/soc/omap/ams-delta.c linux-2.6.39.2/sound/soc/omap/ams-delta.c
84032 --- linux-2.6.39.2/sound/soc/omap/ams-delta.c 2011-05-19 00:06:34.000000000 -0400
84033 +++ linux-2.6.39.2/sound/soc/omap/ams-delta.c 2011-05-22 19:36:35.000000000 -0400
84034 @@ -420,7 +420,7 @@ static int ams_delta_hw_params(struct sn
84035 SND_SOC_DAIFMT_CBM_CFM);
84036 }
84037
84038 -static struct snd_soc_ops ams_delta_ops = {
84039 +static const struct snd_soc_ops ams_delta_ops = {
84040 .hw_params = ams_delta_hw_params,
84041 };
84042
84043 diff -urNp linux-2.6.39.2/sound/soc/omap/igep0020.c linux-2.6.39.2/sound/soc/omap/igep0020.c
84044 --- linux-2.6.39.2/sound/soc/omap/igep0020.c 2011-05-19 00:06:34.000000000 -0400
84045 +++ linux-2.6.39.2/sound/soc/omap/igep0020.c 2011-05-22 19:36:35.000000000 -0400
84046 @@ -72,7 +72,7 @@ static int igep2_hw_params(struct snd_pc
84047 return 0;
84048 }
84049
84050 -static struct snd_soc_ops igep2_ops = {
84051 +static const struct snd_soc_ops igep2_ops = {
84052 .hw_params = igep2_hw_params,
84053 };
84054
84055 diff -urNp linux-2.6.39.2/sound/soc/omap/n810.c linux-2.6.39.2/sound/soc/omap/n810.c
84056 --- linux-2.6.39.2/sound/soc/omap/n810.c 2011-05-19 00:06:34.000000000 -0400
84057 +++ linux-2.6.39.2/sound/soc/omap/n810.c 2011-05-22 19:36:35.000000000 -0400
84058 @@ -141,7 +141,7 @@ static int n810_hw_params(struct snd_pcm
84059 return err;
84060 }
84061
84062 -static struct snd_soc_ops n810_ops = {
84063 +static const struct snd_soc_ops n810_ops = {
84064 .startup = n810_startup,
84065 .hw_params = n810_hw_params,
84066 .shutdown = n810_shutdown,
84067 diff -urNp linux-2.6.39.2/sound/soc/omap/omap2evm.c linux-2.6.39.2/sound/soc/omap/omap2evm.c
84068 --- linux-2.6.39.2/sound/soc/omap/omap2evm.c 2011-05-19 00:06:34.000000000 -0400
84069 +++ linux-2.6.39.2/sound/soc/omap/omap2evm.c 2011-05-22 19:36:35.000000000 -0400
84070 @@ -74,7 +74,7 @@ static int omap2evm_hw_params(struct snd
84071 return 0;
84072 }
84073
84074 -static struct snd_soc_ops omap2evm_ops = {
84075 +static const struct snd_soc_ops omap2evm_ops = {
84076 .hw_params = omap2evm_hw_params,
84077 };
84078
84079 diff -urNp linux-2.6.39.2/sound/soc/omap/omap3beagle.c linux-2.6.39.2/sound/soc/omap/omap3beagle.c
84080 --- linux-2.6.39.2/sound/soc/omap/omap3beagle.c 2011-05-19 00:06:34.000000000 -0400
84081 +++ linux-2.6.39.2/sound/soc/omap/omap3beagle.c 2011-05-22 19:36:35.000000000 -0400
84082 @@ -82,7 +82,7 @@ static int omap3beagle_hw_params(struct
84083 return 0;
84084 }
84085
84086 -static struct snd_soc_ops omap3beagle_ops = {
84087 +static const struct snd_soc_ops omap3beagle_ops = {
84088 .hw_params = omap3beagle_hw_params,
84089 };
84090
84091 diff -urNp linux-2.6.39.2/sound/soc/omap/omap3evm.c linux-2.6.39.2/sound/soc/omap/omap3evm.c
84092 --- linux-2.6.39.2/sound/soc/omap/omap3evm.c 2011-05-19 00:06:34.000000000 -0400
84093 +++ linux-2.6.39.2/sound/soc/omap/omap3evm.c 2011-05-22 19:36:35.000000000 -0400
84094 @@ -70,7 +70,7 @@ static int omap3evm_hw_params(struct snd
84095 return 0;
84096 }
84097
84098 -static struct snd_soc_ops omap3evm_ops = {
84099 +static const struct snd_soc_ops omap3evm_ops = {
84100 .hw_params = omap3evm_hw_params,
84101 };
84102
84103 diff -urNp linux-2.6.39.2/sound/soc/omap/omap3pandora.c linux-2.6.39.2/sound/soc/omap/omap3pandora.c
84104 --- linux-2.6.39.2/sound/soc/omap/omap3pandora.c 2011-05-19 00:06:34.000000000 -0400
84105 +++ linux-2.6.39.2/sound/soc/omap/omap3pandora.c 2011-05-22 19:36:35.000000000 -0400
84106 @@ -218,7 +218,7 @@ static int omap3pandora_in_init(struct s
84107 return snd_soc_dapm_sync(dapm);
84108 }
84109
84110 -static struct snd_soc_ops omap3pandora_ops = {
84111 +static const struct snd_soc_ops omap3pandora_ops = {
84112 .hw_params = omap3pandora_hw_params,
84113 };
84114
84115 diff -urNp linux-2.6.39.2/sound/soc/omap/omap-pcm.c linux-2.6.39.2/sound/soc/omap/omap-pcm.c
84116 --- linux-2.6.39.2/sound/soc/omap/omap-pcm.c 2011-05-19 00:06:34.000000000 -0400
84117 +++ linux-2.6.39.2/sound/soc/omap/omap-pcm.c 2011-05-22 19:36:35.000000000 -0400
84118 @@ -311,7 +311,7 @@ static int omap_pcm_mmap(struct snd_pcm_
84119 runtime->dma_bytes);
84120 }
84121
84122 -static struct snd_pcm_ops omap_pcm_ops = {
84123 +static const struct snd_pcm_ops omap_pcm_ops = {
84124 .open = omap_pcm_open,
84125 .close = omap_pcm_close,
84126 .ioctl = snd_pcm_lib_ioctl,
84127 diff -urNp linux-2.6.39.2/sound/soc/omap/osk5912.c linux-2.6.39.2/sound/soc/omap/osk5912.c
84128 --- linux-2.6.39.2/sound/soc/omap/osk5912.c 2011-05-19 00:06:34.000000000 -0400
84129 +++ linux-2.6.39.2/sound/soc/omap/osk5912.c 2011-05-22 19:36:35.000000000 -0400
84130 @@ -90,7 +90,7 @@ static int osk_hw_params(struct snd_pcm_
84131 return err;
84132 }
84133
84134 -static struct snd_soc_ops osk_ops = {
84135 +static const struct snd_soc_ops osk_ops = {
84136 .startup = osk_startup,
84137 .hw_params = osk_hw_params,
84138 .shutdown = osk_shutdown,
84139 diff -urNp linux-2.6.39.2/sound/soc/omap/overo.c linux-2.6.39.2/sound/soc/omap/overo.c
84140 --- linux-2.6.39.2/sound/soc/omap/overo.c 2011-05-19 00:06:34.000000000 -0400
84141 +++ linux-2.6.39.2/sound/soc/omap/overo.c 2011-05-22 19:36:35.000000000 -0400
84142 @@ -72,7 +72,7 @@ static int overo_hw_params(struct snd_pc
84143 return 0;
84144 }
84145
84146 -static struct snd_soc_ops overo_ops = {
84147 +static const struct snd_soc_ops overo_ops = {
84148 .hw_params = overo_hw_params,
84149 };
84150
84151 diff -urNp linux-2.6.39.2/sound/soc/omap/rx51.c linux-2.6.39.2/sound/soc/omap/rx51.c
84152 --- linux-2.6.39.2/sound/soc/omap/rx51.c 2011-05-19 00:06:34.000000000 -0400
84153 +++ linux-2.6.39.2/sound/soc/omap/rx51.c 2011-05-22 19:36:35.000000000 -0400
84154 @@ -139,7 +139,7 @@ static int rx51_hw_params(struct snd_pcm
84155 SND_SOC_CLOCK_IN);
84156 }
84157
84158 -static struct snd_soc_ops rx51_ops = {
84159 +static const struct snd_soc_ops rx51_ops = {
84160 .startup = rx51_startup,
84161 .hw_params = rx51_hw_params,
84162 };
84163 diff -urNp linux-2.6.39.2/sound/soc/omap/sdp3430.c linux-2.6.39.2/sound/soc/omap/sdp3430.c
84164 --- linux-2.6.39.2/sound/soc/omap/sdp3430.c 2011-05-19 00:06:34.000000000 -0400
84165 +++ linux-2.6.39.2/sound/soc/omap/sdp3430.c 2011-05-22 19:36:35.000000000 -0400
84166 @@ -87,7 +87,7 @@ static int sdp3430_hw_params(struct snd_
84167 return 0;
84168 }
84169
84170 -static struct snd_soc_ops sdp3430_ops = {
84171 +static const struct snd_soc_ops sdp3430_ops = {
84172 .hw_params = sdp3430_hw_params,
84173 };
84174
84175 @@ -130,7 +130,7 @@ static int sdp3430_hw_voice_params(struc
84176 return 0;
84177 }
84178
84179 -static struct snd_soc_ops sdp3430_voice_ops = {
84180 +static const struct snd_soc_ops sdp3430_voice_ops = {
84181 .hw_params = sdp3430_hw_voice_params,
84182 };
84183
84184 diff -urNp linux-2.6.39.2/sound/soc/omap/sdp4430.c linux-2.6.39.2/sound/soc/omap/sdp4430.c
84185 --- linux-2.6.39.2/sound/soc/omap/sdp4430.c 2011-05-19 00:06:34.000000000 -0400
84186 +++ linux-2.6.39.2/sound/soc/omap/sdp4430.c 2011-05-22 19:36:35.000000000 -0400
84187 @@ -62,7 +62,7 @@ static int sdp4430_hw_params(struct snd_
84188 return ret;
84189 }
84190
84191 -static struct snd_soc_ops sdp4430_ops = {
84192 +static const struct snd_soc_ops sdp4430_ops = {
84193 .hw_params = sdp4430_hw_params,
84194 };
84195
84196 diff -urNp linux-2.6.39.2/sound/soc/omap/zoom2.c linux-2.6.39.2/sound/soc/omap/zoom2.c
84197 --- linux-2.6.39.2/sound/soc/omap/zoom2.c 2011-05-19 00:06:34.000000000 -0400
84198 +++ linux-2.6.39.2/sound/soc/omap/zoom2.c 2011-05-22 19:36:35.000000000 -0400
84199 @@ -78,7 +78,7 @@ static int zoom2_hw_params(struct snd_pc
84200 return 0;
84201 }
84202
84203 -static struct snd_soc_ops zoom2_ops = {
84204 +static const struct snd_soc_ops zoom2_ops = {
84205 .hw_params = zoom2_hw_params,
84206 };
84207
84208 @@ -121,7 +121,7 @@ static int zoom2_hw_voice_params(struct
84209 return 0;
84210 }
84211
84212 -static struct snd_soc_ops zoom2_voice_ops = {
84213 +static const struct snd_soc_ops zoom2_voice_ops = {
84214 .hw_params = zoom2_hw_voice_params,
84215 };
84216
84217 diff -urNp linux-2.6.39.2/sound/soc/pxa/corgi.c linux-2.6.39.2/sound/soc/pxa/corgi.c
84218 --- linux-2.6.39.2/sound/soc/pxa/corgi.c 2011-05-19 00:06:34.000000000 -0400
84219 +++ linux-2.6.39.2/sound/soc/pxa/corgi.c 2011-05-22 19:36:35.000000000 -0400
84220 @@ -169,7 +169,7 @@ static int corgi_hw_params(struct snd_pc
84221 return 0;
84222 }
84223
84224 -static struct snd_soc_ops corgi_ops = {
84225 +static const struct snd_soc_ops corgi_ops = {
84226 .startup = corgi_startup,
84227 .hw_params = corgi_hw_params,
84228 .shutdown = corgi_shutdown,
84229 diff -urNp linux-2.6.39.2/sound/soc/pxa/imote2.c linux-2.6.39.2/sound/soc/pxa/imote2.c
84230 --- linux-2.6.39.2/sound/soc/pxa/imote2.c 2011-05-19 00:06:34.000000000 -0400
84231 +++ linux-2.6.39.2/sound/soc/pxa/imote2.c 2011-05-22 19:36:35.000000000 -0400
84232 @@ -56,7 +56,7 @@ static int imote2_asoc_hw_params(struct
84233 return ret;
84234 }
84235
84236 -static struct snd_soc_ops imote2_asoc_ops = {
84237 +static const struct snd_soc_ops imote2_asoc_ops = {
84238 .hw_params = imote2_asoc_hw_params,
84239 };
84240
84241 diff -urNp linux-2.6.39.2/sound/soc/pxa/magician.c linux-2.6.39.2/sound/soc/pxa/magician.c
84242 --- linux-2.6.39.2/sound/soc/pxa/magician.c 2011-05-19 00:06:34.000000000 -0400
84243 +++ linux-2.6.39.2/sound/soc/pxa/magician.c 2011-05-22 19:36:35.000000000 -0400
84244 @@ -258,12 +258,12 @@ static int magician_capture_hw_params(st
84245 return 0;
84246 }
84247
84248 -static struct snd_soc_ops magician_capture_ops = {
84249 +static const struct snd_soc_ops magician_capture_ops = {
84250 .startup = magician_startup,
84251 .hw_params = magician_capture_hw_params,
84252 };
84253
84254 -static struct snd_soc_ops magician_playback_ops = {
84255 +static const struct snd_soc_ops magician_playback_ops = {
84256 .startup = magician_startup,
84257 .hw_params = magician_playback_hw_params,
84258 };
84259 diff -urNp linux-2.6.39.2/sound/soc/pxa/mioa701_wm9713.c linux-2.6.39.2/sound/soc/pxa/mioa701_wm9713.c
84260 --- linux-2.6.39.2/sound/soc/pxa/mioa701_wm9713.c 2011-05-19 00:06:34.000000000 -0400
84261 +++ linux-2.6.39.2/sound/soc/pxa/mioa701_wm9713.c 2011-05-22 19:36:35.000000000 -0400
84262 @@ -156,7 +156,7 @@ static int mioa701_wm9713_init(struct sn
84263 return 0;
84264 }
84265
84266 -static struct snd_soc_ops mioa701_ops;
84267 +static const struct snd_soc_ops mioa701_ops;
84268
84269 static struct snd_soc_dai_link mioa701_dai[] = {
84270 {
84271 diff -urNp linux-2.6.39.2/sound/soc/pxa/poodle.c linux-2.6.39.2/sound/soc/pxa/poodle.c
84272 --- linux-2.6.39.2/sound/soc/pxa/poodle.c 2011-05-19 00:06:34.000000000 -0400
84273 +++ linux-2.6.39.2/sound/soc/pxa/poodle.c 2011-05-22 19:36:35.000000000 -0400
84274 @@ -148,7 +148,7 @@ static int poodle_hw_params(struct snd_p
84275 return 0;
84276 }
84277
84278 -static struct snd_soc_ops poodle_ops = {
84279 +static const struct snd_soc_ops poodle_ops = {
84280 .startup = poodle_startup,
84281 .hw_params = poodle_hw_params,
84282 .shutdown = poodle_shutdown,
84283 diff -urNp linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.c linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.c
84284 --- linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.c 2011-05-19 00:06:34.000000000 -0400
84285 +++ linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.c 2011-05-22 19:36:35.000000000 -0400
84286 @@ -40,7 +40,7 @@ static void pxa2xx_ac97_cold_reset(struc
84287 pxa2xx_ac97_finish_reset(ac97);
84288 }
84289
84290 -struct snd_ac97_bus_ops soc_ac97_ops = {
84291 +const struct snd_ac97_bus_ops soc_ac97_ops = {
84292 .read = pxa2xx_ac97_read,
84293 .write = pxa2xx_ac97_write,
84294 .warm_reset = pxa2xx_ac97_warm_reset,
84295 diff -urNp linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.h linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.h
84296 --- linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.h 2011-05-19 00:06:34.000000000 -0400
84297 +++ linux-2.6.39.2/sound/soc/pxa/pxa2xx-ac97.h 2011-05-22 19:36:35.000000000 -0400
84298 @@ -15,6 +15,6 @@
84299 #define PXA2XX_DAI_AC97_MIC 2
84300
84301 /* platform data */
84302 -extern struct snd_ac97_bus_ops pxa2xx_ac97_ops;
84303 +extern const struct snd_ac97_bus_ops pxa2xx_ac97_ops;
84304
84305 #endif
84306 diff -urNp linux-2.6.39.2/sound/soc/pxa/raumfeld.c linux-2.6.39.2/sound/soc/pxa/raumfeld.c
84307 --- linux-2.6.39.2/sound/soc/pxa/raumfeld.c 2011-06-03 00:04:14.000000000 -0400
84308 +++ linux-2.6.39.2/sound/soc/pxa/raumfeld.c 2011-06-03 00:32:09.000000000 -0400
84309 @@ -145,7 +145,7 @@ static int raumfeld_cs4270_hw_params(str
84310 return 0;
84311 }
84312
84313 -static struct snd_soc_ops raumfeld_cs4270_ops = {
84314 +static const struct snd_soc_ops raumfeld_cs4270_ops = {
84315 .startup = raumfeld_cs4270_startup,
84316 .shutdown = raumfeld_cs4270_shutdown,
84317 .hw_params = raumfeld_cs4270_hw_params,
84318 @@ -221,7 +221,7 @@ static int raumfeld_ak4104_hw_params(str
84319 return 0;
84320 }
84321
84322 -static struct snd_soc_ops raumfeld_ak4104_ops = {
84323 +static const struct snd_soc_ops raumfeld_ak4104_ops = {
84324 .hw_params = raumfeld_ak4104_hw_params,
84325 };
84326
84327 diff -urNp linux-2.6.39.2/sound/soc/pxa/saarb.c linux-2.6.39.2/sound/soc/pxa/saarb.c
84328 --- linux-2.6.39.2/sound/soc/pxa/saarb.c 2011-05-19 00:06:34.000000000 -0400
84329 +++ linux-2.6.39.2/sound/soc/pxa/saarb.c 2011-05-22 19:36:35.000000000 -0400
84330 @@ -106,7 +106,7 @@ static int saarb_i2s_hw_params(struct sn
84331 return ret;
84332 }
84333
84334 -static struct snd_soc_ops saarb_i2s_ops = {
84335 +static const struct snd_soc_ops saarb_i2s_ops = {
84336 .hw_params = saarb_i2s_hw_params,
84337 };
84338
84339 diff -urNp linux-2.6.39.2/sound/soc/pxa/spitz.c linux-2.6.39.2/sound/soc/pxa/spitz.c
84340 --- linux-2.6.39.2/sound/soc/pxa/spitz.c 2011-05-19 00:06:34.000000000 -0400
84341 +++ linux-2.6.39.2/sound/soc/pxa/spitz.c 2011-05-22 19:36:35.000000000 -0400
84342 @@ -169,7 +169,7 @@ static int spitz_hw_params(struct snd_pc
84343 return 0;
84344 }
84345
84346 -static struct snd_soc_ops spitz_ops = {
84347 +static const struct snd_soc_ops spitz_ops = {
84348 .startup = spitz_startup,
84349 .hw_params = spitz_hw_params,
84350 };
84351 diff -urNp linux-2.6.39.2/sound/soc/pxa/tavorevb3.c linux-2.6.39.2/sound/soc/pxa/tavorevb3.c
84352 --- linux-2.6.39.2/sound/soc/pxa/tavorevb3.c 2011-05-19 00:06:34.000000000 -0400
84353 +++ linux-2.6.39.2/sound/soc/pxa/tavorevb3.c 2011-05-22 19:36:35.000000000 -0400
84354 @@ -106,7 +106,7 @@ static int evb3_i2s_hw_params(struct snd
84355 return ret;
84356 }
84357
84358 -static struct snd_soc_ops evb3_i2s_ops = {
84359 +static const struct snd_soc_ops evb3_i2s_ops = {
84360 .hw_params = evb3_i2s_hw_params,
84361 };
84362
84363 diff -urNp linux-2.6.39.2/sound/soc/pxa/tosa.c linux-2.6.39.2/sound/soc/pxa/tosa.c
84364 --- linux-2.6.39.2/sound/soc/pxa/tosa.c 2011-05-19 00:06:34.000000000 -0400
84365 +++ linux-2.6.39.2/sound/soc/pxa/tosa.c 2011-05-22 19:36:35.000000000 -0400
84366 @@ -92,7 +92,7 @@ static int tosa_startup(struct snd_pcm_s
84367 return 0;
84368 }
84369
84370 -static struct snd_soc_ops tosa_ops = {
84371 +static const struct snd_soc_ops tosa_ops = {
84372 .startup = tosa_startup,
84373 };
84374
84375 diff -urNp linux-2.6.39.2/sound/soc/pxa/z2.c linux-2.6.39.2/sound/soc/pxa/z2.c
84376 --- linux-2.6.39.2/sound/soc/pxa/z2.c 2011-05-19 00:06:34.000000000 -0400
84377 +++ linux-2.6.39.2/sound/soc/pxa/z2.c 2011-05-22 19:36:35.000000000 -0400
84378 @@ -187,7 +187,7 @@ err:
84379 return ret;
84380 }
84381
84382 -static struct snd_soc_ops z2_ops = {
84383 +static const struct snd_soc_ops z2_ops = {
84384 .hw_params = z2_hw_params,
84385 };
84386
84387 diff -urNp linux-2.6.39.2/sound/soc/pxa/zylonite.c linux-2.6.39.2/sound/soc/pxa/zylonite.c
84388 --- linux-2.6.39.2/sound/soc/pxa/zylonite.c 2011-05-19 00:06:34.000000000 -0400
84389 +++ linux-2.6.39.2/sound/soc/pxa/zylonite.c 2011-05-22 19:36:35.000000000 -0400
84390 @@ -156,7 +156,7 @@ static int zylonite_voice_hw_params(stru
84391 return 0;
84392 }
84393
84394 -static struct snd_soc_ops zylonite_voice_ops = {
84395 +static const struct snd_soc_ops zylonite_voice_ops = {
84396 .hw_params = zylonite_voice_hw_params,
84397 };
84398
84399 diff -urNp linux-2.6.39.2/sound/soc/s6000/s6000-pcm.c linux-2.6.39.2/sound/soc/s6000/s6000-pcm.c
84400 --- linux-2.6.39.2/sound/soc/s6000/s6000-pcm.c 2011-05-19 00:06:34.000000000 -0400
84401 +++ linux-2.6.39.2/sound/soc/s6000/s6000-pcm.c 2011-05-22 19:36:35.000000000 -0400
84402 @@ -420,7 +420,7 @@ static int s6000_pcm_hw_free(struct snd_
84403 return snd_pcm_lib_free_pages(substream);
84404 }
84405
84406 -static struct snd_pcm_ops s6000_pcm_ops = {
84407 +static const struct snd_pcm_ops s6000_pcm_ops = {
84408 .open = s6000_pcm_open,
84409 .close = s6000_pcm_close,
84410 .ioctl = snd_pcm_lib_ioctl,
84411 diff -urNp linux-2.6.39.2/sound/soc/s6000/s6105-ipcam.c linux-2.6.39.2/sound/soc/s6000/s6105-ipcam.c
84412 --- linux-2.6.39.2/sound/soc/s6000/s6105-ipcam.c 2011-05-19 00:06:34.000000000 -0400
84413 +++ linux-2.6.39.2/sound/soc/s6000/s6105-ipcam.c 2011-05-22 19:36:35.000000000 -0400
84414 @@ -55,7 +55,7 @@ static int s6105_hw_params(struct snd_pc
84415 return 0;
84416 }
84417
84418 -static struct snd_soc_ops s6105_ops = {
84419 +static const struct snd_soc_ops s6105_ops = {
84420 .hw_params = s6105_hw_params,
84421 };
84422
84423 diff -urNp linux-2.6.39.2/sound/soc/samsung/goni_wm8994.c linux-2.6.39.2/sound/soc/samsung/goni_wm8994.c
84424 --- linux-2.6.39.2/sound/soc/samsung/goni_wm8994.c 2011-05-19 00:06:34.000000000 -0400
84425 +++ linux-2.6.39.2/sound/soc/samsung/goni_wm8994.c 2011-05-22 19:36:35.000000000 -0400
84426 @@ -176,7 +176,7 @@ static int goni_hifi_hw_params(struct sn
84427 return 0;
84428 }
84429
84430 -static struct snd_soc_ops goni_hifi_ops = {
84431 +static const struct snd_soc_ops goni_hifi_ops = {
84432 .hw_params = goni_hifi_hw_params,
84433 };
84434
84435 @@ -227,7 +227,7 @@ static struct snd_soc_dai_driver voice_d
84436 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
84437 };
84438
84439 -static struct snd_soc_ops goni_voice_ops = {
84440 +static const struct snd_soc_ops goni_voice_ops = {
84441 .hw_params = goni_voice_hw_params,
84442 };
84443
84444 diff -urNp linux-2.6.39.2/sound/soc/samsung/h1940_uda1380.c linux-2.6.39.2/sound/soc/samsung/h1940_uda1380.c
84445 --- linux-2.6.39.2/sound/soc/samsung/h1940_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84446 +++ linux-2.6.39.2/sound/soc/samsung/h1940_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84447 @@ -136,7 +136,7 @@ static int h1940_hw_params(struct snd_pc
84448 return 0;
84449 }
84450
84451 -static struct snd_soc_ops h1940_ops = {
84452 +static const struct snd_soc_ops h1940_ops = {
84453 .startup = h1940_startup,
84454 .hw_params = h1940_hw_params,
84455 };
84456 diff -urNp linux-2.6.39.2/sound/soc/samsung/jive_wm8750.c linux-2.6.39.2/sound/soc/samsung/jive_wm8750.c
84457 --- linux-2.6.39.2/sound/soc/samsung/jive_wm8750.c 2011-05-19 00:06:34.000000000 -0400
84458 +++ linux-2.6.39.2/sound/soc/samsung/jive_wm8750.c 2011-05-22 19:36:35.000000000 -0400
84459 @@ -92,7 +92,7 @@ static int jive_hw_params(struct snd_pcm
84460 return 0;
84461 }
84462
84463 -static struct snd_soc_ops jive_ops = {
84464 +static const struct snd_soc_ops jive_ops = {
84465 .hw_params = jive_hw_params,
84466 };
84467
84468 diff -urNp linux-2.6.39.2/sound/soc/samsung/neo1973_wm8753.c linux-2.6.39.2/sound/soc/samsung/neo1973_wm8753.c
84469 --- linux-2.6.39.2/sound/soc/samsung/neo1973_wm8753.c 2011-05-19 00:06:34.000000000 -0400
84470 +++ linux-2.6.39.2/sound/soc/samsung/neo1973_wm8753.c 2011-05-22 19:36:35.000000000 -0400
84471 @@ -128,7 +128,7 @@ static int neo1973_hifi_hw_free(struct s
84472 /*
84473 * Neo1973 WM8753 HiFi DAI opserations.
84474 */
84475 -static struct snd_soc_ops neo1973_hifi_ops = {
84476 +static const struct snd_soc_ops neo1973_hifi_ops = {
84477 .hw_params = neo1973_hifi_hw_params,
84478 .hw_free = neo1973_hifi_hw_free,
84479 };
84480 @@ -187,7 +187,7 @@ static int neo1973_voice_hw_free(struct
84481 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0, 0);
84482 }
84483
84484 -static struct snd_soc_ops neo1973_voice_ops = {
84485 +static const struct snd_soc_ops neo1973_voice_ops = {
84486 .hw_params = neo1973_voice_hw_params,
84487 .hw_free = neo1973_voice_hw_free,
84488 };
84489 diff -urNp linux-2.6.39.2/sound/soc/samsung/rx1950_uda1380.c linux-2.6.39.2/sound/soc/samsung/rx1950_uda1380.c
84490 --- linux-2.6.39.2/sound/soc/samsung/rx1950_uda1380.c 2011-05-19 00:06:34.000000000 -0400
84491 +++ linux-2.6.39.2/sound/soc/samsung/rx1950_uda1380.c 2011-05-22 19:36:35.000000000 -0400
84492 @@ -70,7 +70,7 @@ static struct snd_soc_jack_gpio hp_jack_
84493 },
84494 };
84495
84496 -static struct snd_soc_ops rx1950_ops = {
84497 +static const struct snd_soc_ops rx1950_ops = {
84498 .startup = rx1950_startup,
84499 .hw_params = rx1950_hw_params,
84500 };
84501 diff -urNp linux-2.6.39.2/sound/soc/samsung/s3c24xx_simtec.c linux-2.6.39.2/sound/soc/samsung/s3c24xx_simtec.c
84502 --- linux-2.6.39.2/sound/soc/samsung/s3c24xx_simtec.c 2011-05-19 00:06:34.000000000 -0400
84503 +++ linux-2.6.39.2/sound/soc/samsung/s3c24xx_simtec.c 2011-05-22 19:36:35.000000000 -0400
84504 @@ -228,7 +228,7 @@ static int simtec_call_startup(struct s3
84505 return 0;
84506 }
84507
84508 -static struct snd_soc_ops simtec_snd_ops = {
84509 +static const struct snd_soc_ops simtec_snd_ops = {
84510 .hw_params = simtec_hw_params,
84511 };
84512
84513 diff -urNp linux-2.6.39.2/sound/soc/samsung/s3c24xx_uda134x.c linux-2.6.39.2/sound/soc/samsung/s3c24xx_uda134x.c
84514 --- linux-2.6.39.2/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-19 00:06:34.000000000 -0400
84515 +++ linux-2.6.39.2/sound/soc/samsung/s3c24xx_uda134x.c 2011-05-22 19:36:35.000000000 -0400
84516 @@ -210,7 +210,7 @@ static int s3c24xx_uda134x_hw_params(str
84517 return 0;
84518 }
84519
84520 -static struct snd_soc_ops s3c24xx_uda134x_ops = {
84521 +static const struct snd_soc_ops s3c24xx_uda134x_ops = {
84522 .startup = s3c24xx_uda134x_startup,
84523 .shutdown = s3c24xx_uda134x_shutdown,
84524 .hw_params = s3c24xx_uda134x_hw_params,
84525 diff -urNp linux-2.6.39.2/sound/soc/samsung/smartq_wm8987.c linux-2.6.39.2/sound/soc/samsung/smartq_wm8987.c
84526 --- linux-2.6.39.2/sound/soc/samsung/smartq_wm8987.c 2011-05-19 00:06:34.000000000 -0400
84527 +++ linux-2.6.39.2/sound/soc/samsung/smartq_wm8987.c 2011-05-22 19:36:35.000000000 -0400
84528 @@ -92,7 +92,7 @@ static int smartq_hifi_hw_params(struct
84529 /*
84530 * SmartQ WM8987 HiFi DAI operations.
84531 */
84532 -static struct snd_soc_ops smartq_hifi_ops = {
84533 +static const struct snd_soc_ops smartq_hifi_ops = {
84534 .hw_params = smartq_hifi_hw_params,
84535 };
84536
84537 diff -urNp linux-2.6.39.2/sound/soc/samsung/smdk_spdif.c linux-2.6.39.2/sound/soc/samsung/smdk_spdif.c
84538 --- linux-2.6.39.2/sound/soc/samsung/smdk_spdif.c 2011-05-19 00:06:34.000000000 -0400
84539 +++ linux-2.6.39.2/sound/soc/samsung/smdk_spdif.c 2011-05-22 19:36:35.000000000 -0400
84540 @@ -143,7 +143,7 @@ static int smdk_hw_params(struct snd_pcm
84541 return ret;
84542 }
84543
84544 -static struct snd_soc_ops smdk_spdif_ops = {
84545 +static const struct snd_soc_ops smdk_spdif_ops = {
84546 .hw_params = smdk_hw_params,
84547 };
84548
84549 diff -urNp linux-2.6.39.2/sound/soc/samsung/smdk_wm8580.c linux-2.6.39.2/sound/soc/samsung/smdk_wm8580.c
84550 --- linux-2.6.39.2/sound/soc/samsung/smdk_wm8580.c 2011-05-19 00:06:34.000000000 -0400
84551 +++ linux-2.6.39.2/sound/soc/samsung/smdk_wm8580.c 2011-05-22 19:36:35.000000000 -0400
84552 @@ -114,7 +114,7 @@ static int smdk_hw_params(struct snd_pcm
84553 /*
84554 * SMDK WM8580 DAI operations.
84555 */
84556 -static struct snd_soc_ops smdk_ops = {
84557 +static const struct snd_soc_ops smdk_ops = {
84558 .hw_params = smdk_hw_params,
84559 };
84560
84561 diff -urNp linux-2.6.39.2/sound/soc/sh/dma-sh7760.c linux-2.6.39.2/sound/soc/sh/dma-sh7760.c
84562 --- linux-2.6.39.2/sound/soc/sh/dma-sh7760.c 2011-05-19 00:06:34.000000000 -0400
84563 +++ linux-2.6.39.2/sound/soc/sh/dma-sh7760.c 2011-05-22 19:36:35.000000000 -0400
84564 @@ -311,7 +311,7 @@ static snd_pcm_uframes_t camelot_pos(str
84565 return bytes_to_frames(runtime, pos);
84566 }
84567
84568 -static struct snd_pcm_ops camelot_pcm_ops = {
84569 +static const struct snd_pcm_ops camelot_pcm_ops = {
84570 .open = camelot_pcm_open,
84571 .close = camelot_pcm_close,
84572 .ioctl = snd_pcm_lib_ioctl,
84573 diff -urNp linux-2.6.39.2/sound/soc/sh/hac.c linux-2.6.39.2/sound/soc/sh/hac.c
84574 --- linux-2.6.39.2/sound/soc/sh/hac.c 2011-05-19 00:06:34.000000000 -0400
84575 +++ linux-2.6.39.2/sound/soc/sh/hac.c 2011-05-22 19:36:35.000000000 -0400
84576 @@ -227,7 +227,7 @@ static void hac_ac97_coldrst(struct snd_
84577 hac_ac97_warmrst(ac97);
84578 }
84579
84580 -struct snd_ac97_bus_ops soc_ac97_ops = {
84581 +const struct snd_ac97_bus_ops soc_ac97_ops = {
84582 .read = hac_ac97_read,
84583 .write = hac_ac97_write,
84584 .reset = hac_ac97_coldrst,
84585 diff -urNp linux-2.6.39.2/sound/soc/sh/migor.c linux-2.6.39.2/sound/soc/sh/migor.c
84586 --- linux-2.6.39.2/sound/soc/sh/migor.c 2011-05-19 00:06:34.000000000 -0400
84587 +++ linux-2.6.39.2/sound/soc/sh/migor.c 2011-05-22 19:36:35.000000000 -0400
84588 @@ -108,7 +108,7 @@ static int migor_hw_free(struct snd_pcm_
84589 return 0;
84590 }
84591
84592 -static struct snd_soc_ops migor_dai_ops = {
84593 +static const struct snd_soc_ops migor_dai_ops = {
84594 .hw_params = migor_hw_params,
84595 .hw_free = migor_hw_free,
84596 };
84597 diff -urNp linux-2.6.39.2/sound/soc/sh/siu_pcm.c linux-2.6.39.2/sound/soc/sh/siu_pcm.c
84598 --- linux-2.6.39.2/sound/soc/sh/siu_pcm.c 2011-05-19 00:06:34.000000000 -0400
84599 +++ linux-2.6.39.2/sound/soc/sh/siu_pcm.c 2011-05-22 19:36:35.000000000 -0400
84600 @@ -597,7 +597,7 @@ static void siu_pcm_free(struct snd_pcm
84601 dev_dbg(pcm->card->dev, "%s\n", __func__);
84602 }
84603
84604 -static struct snd_pcm_ops siu_pcm_ops = {
84605 +static const struct snd_pcm_ops siu_pcm_ops = {
84606 .open = siu_pcm_open,
84607 .close = siu_pcm_close,
84608 .ioctl = snd_pcm_lib_ioctl,
84609 diff -urNp linux-2.6.39.2/sound/soc/tegra/harmony.c linux-2.6.39.2/sound/soc/tegra/harmony.c
84610 --- linux-2.6.39.2/sound/soc/tegra/harmony.c 2011-05-19 00:06:34.000000000 -0400
84611 +++ linux-2.6.39.2/sound/soc/tegra/harmony.c 2011-05-22 19:36:35.000000000 -0400
84612 @@ -126,7 +126,7 @@ static int harmony_asoc_hw_params(struct
84613 return 0;
84614 }
84615
84616 -static struct snd_soc_ops harmony_asoc_ops = {
84617 +static const struct snd_soc_ops harmony_asoc_ops = {
84618 .hw_params = harmony_asoc_hw_params,
84619 };
84620
84621 diff -urNp linux-2.6.39.2/sound/soc/tegra/tegra_pcm.c linux-2.6.39.2/sound/soc/tegra/tegra_pcm.c
84622 --- linux-2.6.39.2/sound/soc/tegra/tegra_pcm.c 2011-05-19 00:06:34.000000000 -0400
84623 +++ linux-2.6.39.2/sound/soc/tegra/tegra_pcm.c 2011-05-22 19:36:36.000000000 -0400
84624 @@ -277,7 +277,7 @@ static int tegra_pcm_mmap(struct snd_pcm
84625 runtime->dma_bytes);
84626 }
84627
84628 -static struct snd_pcm_ops tegra_pcm_ops = {
84629 +static const struct snd_pcm_ops tegra_pcm_ops = {
84630 .open = tegra_pcm_open,
84631 .close = tegra_pcm_close,
84632 .ioctl = snd_pcm_lib_ioctl,
84633 diff -urNp linux-2.6.39.2/sound/soc/txx9/txx9aclc.c linux-2.6.39.2/sound/soc/txx9/txx9aclc.c
84634 --- linux-2.6.39.2/sound/soc/txx9/txx9aclc.c 2011-05-19 00:06:34.000000000 -0400
84635 +++ linux-2.6.39.2/sound/soc/txx9/txx9aclc.c 2011-05-22 19:36:36.000000000 -0400
84636 @@ -272,7 +272,7 @@ static int txx9aclc_pcm_close(struct snd
84637 return 0;
84638 }
84639
84640 -static struct snd_pcm_ops txx9aclc_pcm_ops = {
84641 +static const struct snd_pcm_ops txx9aclc_pcm_ops = {
84642 .open = txx9aclc_pcm_open,
84643 .close = txx9aclc_pcm_close,
84644 .ioctl = snd_pcm_lib_ioctl,
84645 diff -urNp linux-2.6.39.2/sound/sparc/amd7930.c linux-2.6.39.2/sound/sparc/amd7930.c
84646 --- linux-2.6.39.2/sound/sparc/amd7930.c 2011-05-19 00:06:34.000000000 -0400
84647 +++ linux-2.6.39.2/sound/sparc/amd7930.c 2011-05-22 19:36:36.000000000 -0400
84648 @@ -733,7 +733,7 @@ static int snd_amd7930_hw_free(struct sn
84649 return snd_pcm_lib_free_pages(substream);
84650 }
84651
84652 -static struct snd_pcm_ops snd_amd7930_playback_ops = {
84653 +static const struct snd_pcm_ops snd_amd7930_playback_ops = {
84654 .open = snd_amd7930_playback_open,
84655 .close = snd_amd7930_playback_close,
84656 .ioctl = snd_pcm_lib_ioctl,
84657 @@ -744,7 +744,7 @@ static struct snd_pcm_ops snd_amd7930_pl
84658 .pointer = snd_amd7930_playback_pointer,
84659 };
84660
84661 -static struct snd_pcm_ops snd_amd7930_capture_ops = {
84662 +static const struct snd_pcm_ops snd_amd7930_capture_ops = {
84663 .open = snd_amd7930_capture_open,
84664 .close = snd_amd7930_capture_close,
84665 .ioctl = snd_pcm_lib_ioctl,
84666 @@ -929,7 +929,7 @@ static int snd_amd7930_dev_free(struct s
84667 return snd_amd7930_free(amd);
84668 }
84669
84670 -static struct snd_device_ops snd_amd7930_dev_ops = {
84671 +static const struct snd_device_ops snd_amd7930_dev_ops = {
84672 .dev_free = snd_amd7930_dev_free,
84673 };
84674
84675 diff -urNp linux-2.6.39.2/sound/sparc/cs4231.c linux-2.6.39.2/sound/sparc/cs4231.c
84676 --- linux-2.6.39.2/sound/sparc/cs4231.c 2011-05-19 00:06:34.000000000 -0400
84677 +++ linux-2.6.39.2/sound/sparc/cs4231.c 2011-05-22 19:36:36.000000000 -0400
84678 @@ -1196,7 +1196,7 @@ static int snd_cs4231_capture_close(stru
84679 * XXX the audio AUXIO register...
84680 */
84681
84682 -static struct snd_pcm_ops snd_cs4231_playback_ops = {
84683 +static const struct snd_pcm_ops snd_cs4231_playback_ops = {
84684 .open = snd_cs4231_playback_open,
84685 .close = snd_cs4231_playback_close,
84686 .ioctl = snd_pcm_lib_ioctl,
84687 @@ -1207,7 +1207,7 @@ static struct snd_pcm_ops snd_cs4231_pla
84688 .pointer = snd_cs4231_playback_pointer,
84689 };
84690
84691 -static struct snd_pcm_ops snd_cs4231_capture_ops = {
84692 +static const struct snd_pcm_ops snd_cs4231_capture_ops = {
84693 .open = snd_cs4231_capture_open,
84694 .close = snd_cs4231_capture_close,
84695 .ioctl = snd_pcm_lib_ioctl,
84696 @@ -1789,7 +1789,7 @@ static int snd_cs4231_sbus_dev_free(stru
84697 return snd_cs4231_sbus_free(cp);
84698 }
84699
84700 -static struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84701 +static const struct snd_device_ops snd_cs4231_sbus_dev_ops = {
84702 .dev_free = snd_cs4231_sbus_dev_free,
84703 };
84704
84705 @@ -1955,7 +1955,7 @@ static int snd_cs4231_ebus_dev_free(stru
84706 return snd_cs4231_ebus_free(cp);
84707 }
84708
84709 -static struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84710 +static const struct snd_device_ops snd_cs4231_ebus_dev_ops = {
84711 .dev_free = snd_cs4231_ebus_dev_free,
84712 };
84713
84714 diff -urNp linux-2.6.39.2/sound/sparc/dbri.c linux-2.6.39.2/sound/sparc/dbri.c
84715 --- linux-2.6.39.2/sound/sparc/dbri.c 2011-05-19 00:06:34.000000000 -0400
84716 +++ linux-2.6.39.2/sound/sparc/dbri.c 2011-05-22 19:36:36.000000000 -0400
84717 @@ -2205,7 +2205,7 @@ static snd_pcm_uframes_t snd_dbri_pointe
84718 return ret;
84719 }
84720
84721 -static struct snd_pcm_ops snd_dbri_ops = {
84722 +static const struct snd_pcm_ops snd_dbri_ops = {
84723 .open = snd_dbri_open,
84724 .close = snd_dbri_close,
84725 .ioctl = snd_pcm_lib_ioctl,
84726 diff -urNp linux-2.6.39.2/sound/spi/at73c213.c linux-2.6.39.2/sound/spi/at73c213.c
84727 --- linux-2.6.39.2/sound/spi/at73c213.c 2011-05-19 00:06:34.000000000 -0400
84728 +++ linux-2.6.39.2/sound/spi/at73c213.c 2011-05-22 19:36:36.000000000 -0400
84729 @@ -319,7 +319,7 @@ snd_at73c213_pcm_pointer(struct snd_pcm_
84730 return pos;
84731 }
84732
84733 -static struct snd_pcm_ops at73c213_playback_ops = {
84734 +static const struct snd_pcm_ops at73c213_playback_ops = {
84735 .open = snd_at73c213_pcm_open,
84736 .close = snd_at73c213_pcm_close,
84737 .ioctl = snd_pcm_lib_ioctl,
84738 @@ -882,7 +882,7 @@ static int snd_at73c213_dev_free(struct
84739 static int __devinit snd_at73c213_dev_init(struct snd_card *card,
84740 struct spi_device *spi)
84741 {
84742 - static struct snd_device_ops ops = {
84743 + static const struct snd_device_ops ops = {
84744 .dev_free = snd_at73c213_dev_free,
84745 };
84746 struct snd_at73c213 *chip = get_chip(card);
84747 diff -urNp linux-2.6.39.2/sound/usb/6fire/midi.c linux-2.6.39.2/sound/usb/6fire/midi.c
84748 --- linux-2.6.39.2/sound/usb/6fire/midi.c 2011-05-19 00:06:34.000000000 -0400
84749 +++ linux-2.6.39.2/sound/usb/6fire/midi.c 2011-05-22 19:36:36.000000000 -0400
84750 @@ -134,14 +134,14 @@ static void usb6fire_midi_in_trigger(
84751 spin_unlock_irqrestore(&rt->in_lock, flags);
84752 }
84753
84754 -static struct snd_rawmidi_ops out_ops = {
84755 +static const struct snd_rawmidi_ops out_ops = {
84756 .open = usb6fire_midi_out_open,
84757 .close = usb6fire_midi_out_close,
84758 .trigger = usb6fire_midi_out_trigger,
84759 .drain = usb6fire_midi_out_drain
84760 };
84761
84762 -static struct snd_rawmidi_ops in_ops = {
84763 +static const struct snd_rawmidi_ops in_ops = {
84764 .open = usb6fire_midi_in_open,
84765 .close = usb6fire_midi_in_close,
84766 .trigger = usb6fire_midi_in_trigger
84767 diff -urNp linux-2.6.39.2/sound/usb/caiaq/audio.c linux-2.6.39.2/sound/usb/caiaq/audio.c
84768 --- linux-2.6.39.2/sound/usb/caiaq/audio.c 2011-05-19 00:06:34.000000000 -0400
84769 +++ linux-2.6.39.2/sound/usb/caiaq/audio.c 2011-05-22 19:36:36.000000000 -0400
84770 @@ -322,7 +322,7 @@ snd_usb_caiaq_pcm_pointer(struct snd_pcm
84771 }
84772
84773 /* operators for both playback and capture */
84774 -static struct snd_pcm_ops snd_usb_caiaq_ops = {
84775 +static const struct snd_pcm_ops snd_usb_caiaq_ops = {
84776 .open = snd_usb_caiaq_substream_open,
84777 .close = snd_usb_caiaq_substream_close,
84778 .ioctl = snd_pcm_lib_ioctl,
84779 diff -urNp linux-2.6.39.2/sound/usb/caiaq/midi.c linux-2.6.39.2/sound/usb/caiaq/midi.c
84780 --- linux-2.6.39.2/sound/usb/caiaq/midi.c 2011-05-19 00:06:34.000000000 -0400
84781 +++ linux-2.6.39.2/sound/usb/caiaq/midi.c 2011-05-22 19:36:36.000000000 -0400
84782 @@ -100,15 +100,13 @@ static void snd_usb_caiaq_midi_output_tr
84783 }
84784
84785
84786 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_output =
84787 -{
84788 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_output = {
84789 .open = snd_usb_caiaq_midi_output_open,
84790 .close = snd_usb_caiaq_midi_output_close,
84791 .trigger = snd_usb_caiaq_midi_output_trigger,
84792 };
84793
84794 -static struct snd_rawmidi_ops snd_usb_caiaq_midi_input =
84795 -{
84796 +static const struct snd_rawmidi_ops snd_usb_caiaq_midi_input = {
84797 .open = snd_usb_caiaq_midi_input_open,
84798 .close = snd_usb_caiaq_midi_input_close,
84799 .trigger = snd_usb_caiaq_midi_input_trigger,
84800 diff -urNp linux-2.6.39.2/sound/usb/card.c linux-2.6.39.2/sound/usb/card.c
84801 --- linux-2.6.39.2/sound/usb/card.c 2011-05-19 00:06:34.000000000 -0400
84802 +++ linux-2.6.39.2/sound/usb/card.c 2011-05-22 19:36:36.000000000 -0400
84803 @@ -305,7 +305,7 @@ static int snd_usb_audio_create(struct u
84804 struct snd_usb_audio *chip;
84805 int err, len;
84806 char component[14];
84807 - static struct snd_device_ops ops = {
84808 + static const struct snd_device_ops ops = {
84809 .dev_free = snd_usb_audio_dev_free,
84810 };
84811
84812 diff -urNp linux-2.6.39.2/sound/usb/midi.c linux-2.6.39.2/sound/usb/midi.c
84813 --- linux-2.6.39.2/sound/usb/midi.c 2011-05-19 00:06:34.000000000 -0400
84814 +++ linux-2.6.39.2/sound/usb/midi.c 2011-05-22 19:36:36.000000000 -0400
84815 @@ -1146,14 +1146,14 @@ static void snd_usbmidi_input_trigger(st
84816 clear_bit(substream->number, &umidi->input_triggered);
84817 }
84818
84819 -static struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84820 +static const struct snd_rawmidi_ops snd_usbmidi_output_ops = {
84821 .open = snd_usbmidi_output_open,
84822 .close = snd_usbmidi_output_close,
84823 .trigger = snd_usbmidi_output_trigger,
84824 .drain = snd_usbmidi_output_drain,
84825 };
84826
84827 -static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84828 +static const struct snd_rawmidi_ops snd_usbmidi_input_ops = {
84829 .open = snd_usbmidi_input_open,
84830 .close = snd_usbmidi_input_close,
84831 .trigger = snd_usbmidi_input_trigger
84832 diff -urNp linux-2.6.39.2/sound/usb/misc/ua101.c linux-2.6.39.2/sound/usb/misc/ua101.c
84833 --- linux-2.6.39.2/sound/usb/misc/ua101.c 2011-05-19 00:06:34.000000000 -0400
84834 +++ linux-2.6.39.2/sound/usb/misc/ua101.c 2011-05-22 19:36:36.000000000 -0400
84835 @@ -886,7 +886,7 @@ static snd_pcm_uframes_t playback_pcm_po
84836 return ua101_pcm_pointer(ua, &ua->playback);
84837 }
84838
84839 -static struct snd_pcm_ops capture_pcm_ops = {
84840 +static const struct snd_pcm_ops capture_pcm_ops = {
84841 .open = capture_pcm_open,
84842 .close = capture_pcm_close,
84843 .ioctl = snd_pcm_lib_ioctl,
84844 @@ -899,7 +899,7 @@ static struct snd_pcm_ops capture_pcm_op
84845 .mmap = snd_pcm_lib_mmap_vmalloc,
84846 };
84847
84848 -static struct snd_pcm_ops playback_pcm_ops = {
84849 +static const struct snd_pcm_ops playback_pcm_ops = {
84850 .open = playback_pcm_open,
84851 .close = playback_pcm_close,
84852 .ioctl = snd_pcm_lib_ioctl,
84853 diff -urNp linux-2.6.39.2/sound/usb/mixer.c linux-2.6.39.2/sound/usb/mixer.c
84854 --- linux-2.6.39.2/sound/usb/mixer.c 2011-05-19 00:06:34.000000000 -0400
84855 +++ linux-2.6.39.2/sound/usb/mixer.c 2011-05-22 19:36:36.000000000 -0400
84856 @@ -2201,7 +2201,7 @@ static int snd_usb_mixer_status_create(s
84857 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
84858 int ignore_error)
84859 {
84860 - static struct snd_device_ops dev_ops = {
84861 + static const struct snd_device_ops dev_ops = {
84862 .dev_free = snd_usb_mixer_dev_free
84863 };
84864 struct usb_mixer_interface *mixer;
84865 diff -urNp linux-2.6.39.2/sound/usb/pcm.c linux-2.6.39.2/sound/usb/pcm.c
84866 --- linux-2.6.39.2/sound/usb/pcm.c 2011-05-19 00:06:34.000000000 -0400
84867 +++ linux-2.6.39.2/sound/usb/pcm.c 2011-05-22 19:36:36.000000000 -0400
84868 @@ -844,7 +844,7 @@ static int snd_usb_capture_close(struct
84869 return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
84870 }
84871
84872 -static struct snd_pcm_ops snd_usb_playback_ops = {
84873 +static const struct snd_pcm_ops snd_usb_playback_ops = {
84874 .open = snd_usb_playback_open,
84875 .close = snd_usb_playback_close,
84876 .ioctl = snd_pcm_lib_ioctl,
84877 @@ -857,7 +857,7 @@ static struct snd_pcm_ops snd_usb_playba
84878 .mmap = snd_pcm_lib_mmap_vmalloc,
84879 };
84880
84881 -static struct snd_pcm_ops snd_usb_capture_ops = {
84882 +static const struct snd_pcm_ops snd_usb_capture_ops = {
84883 .open = snd_usb_capture_open,
84884 .close = snd_usb_capture_close,
84885 .ioctl = snd_pcm_lib_ioctl,
84886 diff -urNp linux-2.6.39.2/sound/usb/usx2y/usbusx2yaudio.c linux-2.6.39.2/sound/usb/usx2y/usbusx2yaudio.c
84887 --- linux-2.6.39.2/sound/usb/usx2y/usbusx2yaudio.c 2011-05-19 00:06:34.000000000 -0400
84888 +++ linux-2.6.39.2/sound/usb/usx2y/usbusx2yaudio.c 2011-05-22 19:36:36.000000000 -0400
84889 @@ -919,8 +919,7 @@ static int snd_usX2Y_pcm_close(struct sn
84890 }
84891
84892
84893 -static struct snd_pcm_ops snd_usX2Y_pcm_ops =
84894 -{
84895 +static const struct snd_pcm_ops snd_usX2Y_pcm_ops = {
84896 .open = snd_usX2Y_pcm_open,
84897 .close = snd_usX2Y_pcm_close,
84898 .ioctl = snd_pcm_lib_ioctl,
84899 diff -urNp linux-2.6.39.2/tools/gcc/Makefile linux-2.6.39.2/tools/gcc/Makefile
84900 --- linux-2.6.39.2/tools/gcc/Makefile 1969-12-31 19:00:00.000000000 -0500
84901 +++ linux-2.6.39.2/tools/gcc/Makefile 2011-06-03 01:19:01.000000000 -0400
84902 @@ -0,0 +1,11 @@
84903 +#CC := gcc
84904 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84905 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84906 +GCCPLUGINS_DIR := $(shell $(HOSTCC) -print-file-name=plugin)
84907 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
84908 +
84909 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
84910 +
84911 +hostlibs-y := pax_plugin.so
84912 +always := $(hostlibs-y)
84913 +pax_plugin-objs := pax_plugin.o
84914 diff -urNp linux-2.6.39.2/tools/gcc/pax_plugin.c linux-2.6.39.2/tools/gcc/pax_plugin.c
84915 --- linux-2.6.39.2/tools/gcc/pax_plugin.c 1969-12-31 19:00:00.000000000 -0500
84916 +++ linux-2.6.39.2/tools/gcc/pax_plugin.c 2011-06-03 23:14:36.000000000 -0400
84917 @@ -0,0 +1,242 @@
84918 +/*
84919 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84920 + * Licensed under the GPL v2
84921 + *
84922 + * Note: the choice of the license means that the compilation process is
84923 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84924 + * but for the kernel it doesn't matter since it doesn't link against
84925 + * any of the gcc libraries
84926 + *
84927 + * gcc plugin to help implement various PaX features
84928 + *
84929 + * - track lowest stack pointer
84930 + *
84931 + * TODO:
84932 + * - initialize all local variables
84933 + *
84934 + * BUGS:
84935 + */
84936 +#include "gcc-plugin.h"
84937 +#include "plugin-version.h"
84938 +#include "config.h"
84939 +#include "system.h"
84940 +#include "coretypes.h"
84941 +#include "tm.h"
84942 +#include "toplev.h"
84943 +#include "basic-block.h"
84944 +#include "gimple.h"
84945 +//#include "expr.h" where are you...
84946 +#include "diagnostic.h"
84947 +#include "rtl.h"
84948 +#include "emit-rtl.h"
84949 +#include "function.h"
84950 +#include "tree.h"
84951 +#include "tree-pass.h"
84952 +#include "intl.h"
84953 +
84954 +int plugin_is_GPL_compatible;
84955 +
84956 +static int track_frame_size = -1;
84957 +static const char track_function[] = "pax_track_stack";
84958 +static bool init_locals;
84959 +
84960 +static struct plugin_info pax_plugin_info = {
84961 + .version = "201106030000",
84962 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
84963 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
84964 +};
84965 +
84966 +static bool gate_pax_track_stack(void);
84967 +static unsigned int execute_pax_tree_instrument(void);
84968 +static unsigned int execute_pax_final(void);
84969 +
84970 +static struct gimple_opt_pass pax_tree_instrument_pass = {
84971 + .pass = {
84972 + .type = GIMPLE_PASS,
84973 + .name = "pax_tree_instrument",
84974 + .gate = gate_pax_track_stack,
84975 + .execute = execute_pax_tree_instrument,
84976 + .sub = NULL,
84977 + .next = NULL,
84978 + .static_pass_number = 0,
84979 + .tv_id = TV_NONE,
84980 + .properties_required = PROP_gimple_leh | PROP_cfg,
84981 + .properties_provided = 0,
84982 + .properties_destroyed = 0,
84983 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84984 + .todo_flags_finish = TODO_verify_stmts // | TODO_dump_func
84985 + }
84986 +};
84987 +
84988 +static struct rtl_opt_pass pax_final_rtl_opt_pass = {
84989 + .pass = {
84990 + .type = RTL_PASS,
84991 + .name = "pax_final",
84992 + .gate = gate_pax_track_stack,
84993 + .execute = execute_pax_final,
84994 + .sub = NULL,
84995 + .next = NULL,
84996 + .static_pass_number = 0,
84997 + .tv_id = TV_NONE,
84998 + .properties_required = 0,
84999 + .properties_provided = 0,
85000 + .properties_destroyed = 0,
85001 + .todo_flags_start = 0,
85002 + .todo_flags_finish = 0
85003 + }
85004 +};
85005 +
85006 +static bool gate_pax_track_stack(void)
85007 +{
85008 + return track_frame_size >= 0;
85009 +}
85010 +
85011 +static void pax_add_instrumentation(gimple_stmt_iterator *gsi, bool before)
85012 +{
85013 + gimple call;
85014 + tree decl, type;
85015 +
85016 + // insert call to void pax_track_stack(void)
85017 + type = build_function_type_list(void_type_node, NULL_TREE);
85018 + decl = build_fn_decl(track_function, type);
85019 + DECL_ASSEMBLER_NAME(decl); // for LTO
85020 + call = gimple_build_call(decl, 0);
85021 + if (before)
85022 + gsi_insert_before(gsi, call, GSI_CONTINUE_LINKING);
85023 + else
85024 + gsi_insert_after(gsi, call, GSI_CONTINUE_LINKING);
85025 +}
85026 +
85027 +static unsigned int execute_pax_tree_instrument(void)
85028 +{
85029 + basic_block bb;
85030 + gimple_stmt_iterator gsi;
85031 +
85032 + // 1. loop through BBs and GIMPLE statements
85033 + FOR_EACH_BB(bb) {
85034 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85035 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85036 + tree decl;
85037 + gimple stmt = gsi_stmt(gsi);
85038 +
85039 + if (!is_gimple_call(stmt))
85040 + continue;
85041 + decl = gimple_call_fndecl(stmt);
85042 + if (!decl)
85043 + continue;
85044 + if (TREE_CODE(decl) != FUNCTION_DECL)
85045 + continue;
85046 + if (!DECL_BUILT_IN(decl))
85047 + continue;
85048 + if (DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
85049 + continue;
85050 + if (DECL_FUNCTION_CODE(decl) != BUILT_IN_ALLOCA)
85051 + continue;
85052 +
85053 + // 2. insert track call after each __builtin_alloca call
85054 + pax_add_instrumentation(&gsi, false);
85055 +// print_node(stderr, "pax", decl, 4);
85056 + }
85057 + }
85058 +
85059 + // 3. insert track call at the beginning
85060 + bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85061 + gsi = gsi_start_bb(bb);
85062 + pax_add_instrumentation(&gsi, true);
85063 +
85064 + return 0;
85065 +}
85066 +
85067 +static unsigned int execute_pax_final(void)
85068 +{
85069 + rtx insn;
85070 +
85071 + if (cfun->calls_alloca)
85072 + return 0;
85073 +
85074 + // 1. find pax_track_stack calls
85075 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85076 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
85077 + rtx body;
85078 +
85079 + if (!CALL_P(insn))
85080 + continue;
85081 + body = PATTERN(insn);
85082 + if (GET_CODE(body) != CALL)
85083 + continue;
85084 + body = XEXP(body, 0);
85085 + if (GET_CODE(body) != MEM)
85086 + continue;
85087 + body = XEXP(body, 0);
85088 + if (GET_CODE(body) != SYMBOL_REF)
85089 + continue;
85090 + if (strcmp(XSTR(body, 0), track_function))
85091 + continue;
85092 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85093 + // 2. delete call if function frame is not big enough
85094 + if (get_frame_size() >= track_frame_size)
85095 + continue;
85096 + delete_insn_and_edges(insn);
85097 + }
85098 +
85099 +// print_simple_rtl(stderr, get_insns());
85100 +// print_rtl(stderr, get_insns());
85101 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85102 +
85103 + return 0;
85104 +}
85105 +
85106 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85107 +{
85108 + const char * const plugin_name = plugin_info->base_name;
85109 + const int argc = plugin_info->argc;
85110 + const struct plugin_argument * const argv = plugin_info->argv;
85111 + int i;
85112 + struct register_pass_info pax_tree_instrument_pass_info = {
85113 + .pass = &pax_tree_instrument_pass.pass,
85114 +// .reference_pass_name = "tree_profile",
85115 + .reference_pass_name = "optimized",
85116 + .ref_pass_instance_number = 0,
85117 + .pos_op = PASS_POS_INSERT_AFTER
85118 + };
85119 + struct register_pass_info pax_final_pass_info = {
85120 + .pass = &pax_final_rtl_opt_pass.pass,
85121 + .reference_pass_name = "final",
85122 + .ref_pass_instance_number = 0,
85123 + .pos_op = PASS_POS_INSERT_BEFORE
85124 + };
85125 +
85126 + if (!plugin_default_version_check(version, &gcc_version)) {
85127 + error(G_("incompatible gcc/plugin versions"));
85128 + return 1;
85129 + }
85130 +
85131 + register_callback(plugin_name, PLUGIN_INFO, NULL, &pax_plugin_info);
85132 +
85133 + for (i = 0; i < argc; ++i) {
85134 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85135 + if (!argv[i].value) {
85136 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85137 + continue;
85138 + }
85139 + track_frame_size = atoi(argv[i].value);
85140 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85141 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85142 + continue;
85143 + }
85144 + if (!strcmp(argv[i].key, "initialize-locals")) {
85145 + if (argv[i].value) {
85146 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85147 + continue;
85148 + }
85149 + init_locals = true;
85150 + continue;
85151 + }
85152 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85153 + }
85154 +
85155 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pax_tree_instrument_pass_info);
85156 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pax_final_pass_info);
85157 +
85158 + return 0;
85159 +}
85160 Binary files linux-2.6.39.2/tools/gcc/pax_plugin.so and linux-2.6.39.2/tools/gcc/pax_plugin.so differ
85161 diff -urNp linux-2.6.39.2/tools/perf/builtin-lock.c linux-2.6.39.2/tools/perf/builtin-lock.c
85162 --- linux-2.6.39.2/tools/perf/builtin-lock.c 2011-05-19 00:06:34.000000000 -0400
85163 +++ linux-2.6.39.2/tools/perf/builtin-lock.c 2011-05-22 19:36:36.000000000 -0400
85164 @@ -635,14 +635,14 @@ end:
85165
85166 /* lock oriented handlers */
85167 /* TODO: handlers for CPU oriented, thread oriented */
85168 -static struct trace_lock_handler report_lock_ops = {
85169 +static const struct trace_lock_handler report_lock_ops = {
85170 .acquire_event = report_lock_acquire_event,
85171 .acquired_event = report_lock_acquired_event,
85172 .contended_event = report_lock_contended_event,
85173 .release_event = report_lock_release_event,
85174 };
85175
85176 -static struct trace_lock_handler *trace_handler;
85177 +static const struct trace_lock_handler *trace_handler;
85178
85179 static void
85180 process_lock_acquire_event(void *data,
85181 diff -urNp linux-2.6.39.2/tools/perf/builtin-sched.c linux-2.6.39.2/tools/perf/builtin-sched.c
85182 --- linux-2.6.39.2/tools/perf/builtin-sched.c 2011-05-19 00:06:34.000000000 -0400
85183 +++ linux-2.6.39.2/tools/perf/builtin-sched.c 2011-05-22 19:36:36.000000000 -0400
85184 @@ -845,7 +845,7 @@ replay_fork_event(struct trace_fork_even
85185 register_pid(fork_event->child_pid, fork_event->child_comm);
85186 }
85187
85188 -static struct trace_sched_handler replay_ops = {
85189 +static const struct trace_sched_handler replay_ops = {
85190 .wakeup_event = replay_wakeup_event,
85191 .switch_event = replay_switch_event,
85192 .fork_event = replay_fork_event,
85193 @@ -1183,7 +1183,7 @@ latency_migrate_task_event(struct trace_
85194 nr_unordered_timestamps++;
85195 }
85196
85197 -static struct trace_sched_handler lat_ops = {
85198 +static const struct trace_sched_handler lat_ops = {
85199 .wakeup_event = latency_wakeup_event,
85200 .switch_event = latency_switch_event,
85201 .runtime_event = latency_runtime_event,
85202 @@ -1353,7 +1353,7 @@ static void sort_lat(void)
85203 }
85204 }
85205
85206 -static struct trace_sched_handler *trace_handler;
85207 +static const struct trace_sched_handler *trace_handler;
85208
85209 static void
85210 process_sched_wakeup_event(void *data, struct perf_session *session,
85211 @@ -1719,7 +1719,7 @@ static void __cmd_lat(void)
85212
85213 }
85214
85215 -static struct trace_sched_handler map_ops = {
85216 +static const struct trace_sched_handler map_ops = {
85217 .wakeup_event = NULL,
85218 .switch_event = map_switch_event,
85219 .runtime_event = NULL,
85220 diff -urNp linux-2.6.39.2/usr/gen_init_cpio.c linux-2.6.39.2/usr/gen_init_cpio.c
85221 --- linux-2.6.39.2/usr/gen_init_cpio.c 2011-05-19 00:06:34.000000000 -0400
85222 +++ linux-2.6.39.2/usr/gen_init_cpio.c 2011-05-22 19:36:36.000000000 -0400
85223 @@ -305,7 +305,7 @@ static int cpio_mkfile(const char *name,
85224 int retval;
85225 int rc = -1;
85226 int namesize;
85227 - int i;
85228 + unsigned int i;
85229
85230 mode |= S_IFREG;
85231
85232 @@ -394,9 +394,10 @@ static char *cpio_replace_env(char *new_
85233 *env_var = *expanded = '\0';
85234 strncat(env_var, start + 2, end - start - 2);
85235 strncat(expanded, new_location, start - new_location);
85236 - strncat(expanded, getenv(env_var), PATH_MAX);
85237 - strncat(expanded, end + 1, PATH_MAX);
85238 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
85239 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
85240 strncpy(new_location, expanded, PATH_MAX);
85241 + new_location[PATH_MAX] = 0;
85242 } else
85243 break;
85244 }
85245 diff -urNp linux-2.6.39.2/virt/kvm/kvm_main.c linux-2.6.39.2/virt/kvm/kvm_main.c
85246 --- linux-2.6.39.2/virt/kvm/kvm_main.c 2011-05-19 00:06:34.000000000 -0400
85247 +++ linux-2.6.39.2/virt/kvm/kvm_main.c 2011-05-22 19:36:36.000000000 -0400
85248 @@ -73,7 +73,7 @@ LIST_HEAD(vm_list);
85249
85250 static cpumask_var_t cpus_hardware_enabled;
85251 static int kvm_usage_count = 0;
85252 -static atomic_t hardware_enable_failed;
85253 +static atomic_unchecked_t hardware_enable_failed;
85254
85255 struct kmem_cache *kvm_vcpu_cache;
85256 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
85257 @@ -1594,7 +1594,7 @@ static int kvm_vcpu_release(struct inode
85258 return 0;
85259 }
85260
85261 -static struct file_operations kvm_vcpu_fops = {
85262 +static struct file_operations kvm_vcpu_fops = { /* cannot be const */
85263 .release = kvm_vcpu_release,
85264 .unlocked_ioctl = kvm_vcpu_ioctl,
85265 .compat_ioctl = kvm_vcpu_ioctl,
85266 @@ -2063,7 +2063,7 @@ static int kvm_vm_mmap(struct file *file
85267 return 0;
85268 }
85269
85270 -static struct file_operations kvm_vm_fops = {
85271 +static struct file_operations kvm_vm_fops = { /* cannot be const */
85272 .release = kvm_vm_release,
85273 .unlocked_ioctl = kvm_vm_ioctl,
85274 #ifdef CONFIG_COMPAT
85275 @@ -2161,7 +2161,7 @@ out:
85276 return r;
85277 }
85278
85279 -static struct file_operations kvm_chardev_ops = {
85280 +static struct file_operations kvm_chardev_ops = { /* cannot be const */
85281 .unlocked_ioctl = kvm_dev_ioctl,
85282 .compat_ioctl = kvm_dev_ioctl,
85283 .llseek = noop_llseek,
85284 @@ -2187,7 +2187,7 @@ static void hardware_enable_nolock(void
85285
85286 if (r) {
85287 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
85288 - atomic_inc(&hardware_enable_failed);
85289 + atomic_inc_unchecked(&hardware_enable_failed);
85290 printk(KERN_INFO "kvm: enabling virtualization on "
85291 "CPU%d failed\n", cpu);
85292 }
85293 @@ -2241,10 +2241,10 @@ static int hardware_enable_all(void)
85294
85295 kvm_usage_count++;
85296 if (kvm_usage_count == 1) {
85297 - atomic_set(&hardware_enable_failed, 0);
85298 + atomic_set_unchecked(&hardware_enable_failed, 0);
85299 on_each_cpu(hardware_enable_nolock, NULL, 1);
85300
85301 - if (atomic_read(&hardware_enable_failed)) {
85302 + if (atomic_read_unchecked(&hardware_enable_failed)) {
85303 hardware_disable_all_nolock();
85304 r = -EBUSY;
85305 }
85306 @@ -2509,7 +2509,7 @@ static void kvm_sched_out(struct preempt
85307 kvm_arch_vcpu_put(vcpu);
85308 }
85309
85310 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85311 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85312 struct module *module)
85313 {
85314 int r;
85315 @@ -2572,7 +2572,7 @@ int kvm_init(void *opaque, unsigned vcpu
85316 if (!vcpu_align)
85317 vcpu_align = __alignof__(struct kvm_vcpu);
85318 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
85319 - 0, NULL);
85320 + SLAB_USERCOPY, NULL);
85321 if (!kvm_vcpu_cache) {
85322 r = -ENOMEM;
85323 goto out_free_3;